<template>
  <div>
    <div class="container normal-panel normal-margin" style="display:flex">
      <add-group type="add" @addSuccess="$refs.list.listData()" :productData="productList" :brandData="brandList" v-if="tool.checkAuth($route.name,'update')"></add-group>
      <Up type="all" style="margin-left:16px" @upSuccess="$refs.list.listData()" :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="$refs.list.listData()" :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:groupDetail="scope">
          <add-group-detail :rowData="scope.data"/>
        </template>
        <template v-slot:edit="scope">
          <edit-group v-if="tool.checkAuth($route.name,'update')" type="edit" @addSuccess="$refs.list.listData()" :productData="productList" :brandData="brandList" :groupData="scope.data"></edit-group>
        </template>
        <template v-slot:del="scope">
          <Del v-if="tool.checkAuth($route.name,'delete')" 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 addGroup from './modules/add'
import editGroup from './modules/edit'
import Del from './modules/delete'
import Up from './modules/up'
import Down from './modules/down'
import detail from './modules/details.vue'
import addGroupDetail from './modules/addGroupDetail'
export default {
  name:"index",
  components:{
    list,
    addGroup,
    editGroup,
    detail,
    Del,
    Up,
    Down,
    addGroupDetail,
    product_detail
  },
  data() {
    return {
      /* 商品列表数据 */
      productList:'',
      /* 品牌列表数据 */
      brandList:'',
      checkboxData:{}
    }
  },
  created() {
    this.getProductList()
    this.getBrandList()
  },
  provide() {
    return {
      productList: () => this.productList
    }
  },
  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>