<?php

/* ========================================================================
 * $Id: index.php 2846 2020-07-09 00:51:59Z onez $
 * 
 * Email: www@onez.cn
 * QQ: 6200103
 * HomePage: http://www.onez.cn
 * ========================================================================
 * Copyright 2016-2017 佳蓝科技.
 * 
 * ======================================================================== */

!defined('IN_ONEZ') && exit('Access Denied');
# 产品
# products
#请求数据
if($MODE=='$post'){
  $action=onez()->gp('action');
  if($action=='data'){
    #商业源码
    $xxx='';
    $kw=onez()->gp('kw');
    if($kw){
      $xxx.=" and key1 like '%$kw%'";
    }
    $T2=$G['this']->data()->open('categorys')->record("1 order by step desc,id");
    $categorys=array();
    foreach($T2 as $rs){
      $T3=$G['this']->data()->open('products')->record("upid='$rs[id]'$xxx order by step desc,id desc");
      $products=array();
      foreach($T3 as $r){
        !$r['icon'] && $r['icon']='http://cdn.onez.cn/icons/2020/0627/2020062717291039510001.svg';
        $item=array(
          'name'=>$r['name'],
          'thumb'=>$r['thumb'],
          'url'=>'/index/view.php?id='.$r['id'],
          'price'=>$r['price'],
        );
        $products[]=$item;
      }
      $categorys[]=array(
        'name'=>$rs['name'],
        'products'=>$products,
      );
    }
    $A['pagedata']['categorys']=$categorys;
    
    $T2=$G['this']->data()->open('slide')->record("1 order by step desc,id");
    $slides=array();
    foreach($T2 as $rs){
      $slides[]=array(
        'name'=>$rs['name'],
        'link'=>$rs['link'],
        'pic'=>$rs['pic'],
      );
    }
    $A['pagedata']['slides']=$slides;
    $A['pagedata']['ready']=true;
  }
  return;
}
?>
<template v-if="$pagedata && $pagedata.ready">
<?php 
onez('bs.app.shipments')->slot('/www/index/first');
?>
<div class="headBox">
<van-swipe :autoplay="3000" v-if="pagedata.slides && pagedata.slides.length>0">
  <van-swipe-item v-for="(item, index) in pagedata.slides" :key="index">
    <a :href="item.link" islink target="_blank"><img :src="item.pic" /></a>
  </van-swipe-item>
</van-swipe>
<?php 
onez('bs.app.shipments')->slot('/www/index/second');
?>
</div>
<template v-if="is_mobile">
<div class="mainBox">
  <van-sidebar v-model="activeKey">
    <van-sidebar-item :title="cat.name" v-for="cat in pagedata.categorys" />
  </van-sidebar>
  <div class="proList">
    <template v-for="(cat,index) in pagedata.categorys">
      <template v-if="cat.products.length>0">
        <onez-index-product v-if="activeKey==index" :data="product" islink v-for="product in cat.products" />
      </template>
    </template>
  </div>
</div>
</template>
<template v-else>
<div class="searchBox">
  <van-search v-model="kw" show-action placeholder="请输入您要搜索的关键词" @search="onSearch">
    <template #action>
      <van-button plain type="info" @click="onSearch">搜索</van-button>
    </template>
  </van-search>
</div>
<dl class="products" v-for="cat in pagedata.categorys">
  <dt>{{cat.name}}</dt>
  <dd>
    <template v-if="cat.products.length>0">
      <onez-index-product :data="product" islink v-for="product in cat.products" />
    </template>
  </dd>
</dl>
</template>
</template>