<template>
  <div>
    <div class="container normal-panel normal-margin" style="display:flex">
      <add type="add" @addSuccess="$refs.list.listData()" :productData="productList" :brandData="brandList" v-if="tool.checkAuth($route.name,'update')"></add>
      <Up type="all" style="margin-left:16px" @upSuccess="onSuccess()" :id="checkboxData.map(item => item.sa_itemgroupid)" v-if="Object.keys(checkboxData).length > 0 && checkboxData[0].isonsale == 0 && tool.checkAuth($route.name,'up_sales')"></Up>
      <Down type="all" style="margin-left:16px" @downSuccess="onSuccess()" :id="checkboxData.map(item => item.sa_itemgroupid)" v-if="Object.keys(checkboxData).length > 0 && checkboxData[0].isonsale == 1 && tool.checkAuth($route.name,'down_sales')"></Down>
    </div>
    <div class="container normal-panel normal-margin">
      <list ref="list" @checkboxCallBack="checkboxCallBack">
        <template v-slot:detail="scope">
          <product_detail :data="scope.data"  :type="'text'"></product_detail>
        </template>
        <template v-slot:edit="scope">
          <add v-if="tool.checkAuth($route.name,'update')" type="edit" @addSuccess="onSuccess()" :productData="productList" :brandData="brandList" :groupData="scope.data"></add>
        </template>
        <template v-slot:del="scope">
          <Del v-if="tool.checkAuth($route.name,'delete') && scope.data.isonsale == 0" type="group" @deleteSuccess="onSuccess()" :id="scope.data.sa_itemgroupid"></Del>
        </template>
        <template v-slot:up="scope">
          <Up type="one" @upSuccess="onSuccess()" :id="[scope.data.sa_itemgroupid]" v-if="scope.data.isonsale == 0 && tool.checkAuth($route.name,'up_sales')"></Up>
        </template>
        <template v-slot:down="scope">
          <Down type="one" @downSuccess="onSuccess()" :id="[scope.data.sa_itemgroupid]" v-if="scope.data.isonsale == 1 && tool.checkAuth($route.name,'down_sales')"></Down>
        </template>
      </list>
    </div>
  </div>
</template>

<script>


import product_detail from './modules/details.vue';

import list from './modules/list'

import add from './modules/add'
import Del from './modules/delete'
import Up from './modules/up'
import Down from './modules/down'


export default {
  name:"index",
  components:{
    list,
    add,
    product_detail,
    Del,
    Up,
    Down,
  },
  data() {
    return {
      /* 商品列表数据 */
      productList:'',
      /* 品牌列表数据 */
      brandList:'',
      checkboxData:{}
    }
  },
  created() {
    this.getProductList()
    this.getBrandList()
  },
  methods: {
    /* 可选择的商品列表 */
    async getProductList() {
      let res = await this.$api.requested({
          "id": "20220923112503",
          "version":1,
          "content": {
            "nocache":true,
            "sa_itemgroupid":0,
            "where":{
                "condition":""
            }
          }
      })
      this.productList = res.data
      console.log(this.productList,'商品');
      
    },
    /* 可选择的品牌列表 */
    async getBrandList() {
      let res = await this.$api.requested({
        "id": "20220922085103",
        "version":1,
        "content": {
          "nocache":true,
          "where":{
              "condition":""
          }
        }
      })
      this.brandList = res.data
      console.log(this.brandList,'品牌');
    },
    checkboxCallBack(data) {
      this.checkboxData = data
    },
    onSuccess () {
      console.log("执行更新")
      this.$refs.list.listData()
    },
  }
}

</script>
<style>
</style>