<!-- @desc:商品档案  @auth:常皓宁  @time:2024-1-31 14:56 -->
<template>
  <div class="main-div" ref="mainDiv">
    <loading :loading="loading" v-if="!modalVisible"></loading>
    <BaseIndexButtonGroup ref="BaseIndexButtonGroup" id="BaseIndexButtonGroup">
      <template #left>
        <!--    查询    -->
        <BaseIndexButton ref="search" name="search"></BaseIndexButton>
        <!--    清空条件    -->
        <BaseIndexButton ref="clear" name="clear"></BaseIndexButton>
        <!--    编辑    -->
        <BaseIndexButton ref="edit" name="edit"></BaseIndexButton>
        <!--    启用    -->
        <BaseIndexButton  ref="enable" name="enable"></BaseIndexButton>
        <!--    停用    -->
        <BaseIndexButton  ref="disable" name="disable"></BaseIndexButton>
      </template>
      <template #right>
        <!--   新建     -->
        <BaseIndexButton ref="add" name="add"></BaseIndexButton>
      </template>
    </BaseIndexButtonGroup>

    <!--  卡片区  -->
    <div class="index-card">
      <!--  查询条件区域  -->
      <div id="search-cond-div" ref="search-cond-div" class="search-cond-class">
        <SearchCond ref="searchCond" v-model="searchCond"
                    @collapse-change="collapseChange" :setFlag="false"
                    :searchContent="searchContent"
        ></SearchCond>
      </div>
      <!--  表格部分  -->
      <div :style="'height: ' + tableHeight + 'px'" class="split-div-class">
        <DkSplit v-model="split">
          <!-- 左边部分   -->
          <DkTable slot="left" ref="leftTable" :data="leftData" :height="tableHeight" :page-flag="false"
                   :page-total-flag="false"  :choose-flag="false" :show-setting-flag="false"
                   @current-change="currentChangeEvent($event)" primaryKey="brandId">
            <DkTableColumn field="brandName" :title="this.$t('brandIds')" />
          </DkTable>

          <!-- 右边部分   -->
          <DkTable slot="right" :id="'table-' + $options.name" ref="table-select" :data="tableData" :pageFlag="true"
                   :page-total="pageInfo.total" :current-page="pageInfo.currentPage" :choose-flag="false"
                   :height="this.tableHeight-30" primaryKey="skuId" @pageChange="pageSizeChange">
            <DkTableColumn field="skuCode"></DkTableColumn>
            <DkTableColumn field="skuName"></DkTableColumn>
            <DkTableColumn field="skuModel"></DkTableColumn>
            <DkTableColumn field="skuSpec"></DkTableColumn>
            <DkTableColumn field="seriesName"></DkTableColumn>
            <DkTableColumn field="brandName"></DkTableColumn>
            <DkTableColumn field="shortName"></DkTableColumn>
            <DkTableColumn field="pricePurchase" dataType="number"></DkTableColumn>
            <DkTableColumn field="priceStandard" dataType="number"></DkTableColumn>
            <DkTableColumn field="priceWholesale" dataType="number"></DkTableColumn>
            <DkTableColumn field="priceLimited" dataType="number"></DkTableColumn>
            <DkTableColumn field="priceOther" dataType="number"></DkTableColumn>
            <DkTableColumn field="remarks"></DkTableColumn>
            <DkTableColumn field="flgValid" type="switch" ></DkTableColumn>
          </DkTable>
        </DkSplit>
      </div>
    </div>

  </div>
</template>

<script>
import {indexMixin} from "@/mixins";

export default {
  name: 'goods-attr',
  mixins: [indexMixin],
  data(){
    let self = this
    return{
      leftData: [],
      tableData: [],
      brandList: [],
      brandId:null,
      split: 0.15,
      minSplit: 0.15,
      searchContent:
        [
          {
            itemCode: 'skuName',
          },
          {
            itemCode: 'skuModel',
          },
          // {
          //   itemCode: 'brandIds',
          //   valueFormat: {
          //     code: 'goodsBrandList',
          //     data: [],
          //     valueKey: 'brandId',
          //     labelKey: 'brandName'
          //   },
          //   valueKind: 'M-CHOICE'
          // },
          self.$config.flgValidSearch
        ],
    }
  },
  methods:{

    /**
     * @desc   : 加载数据
     * @author : 宋扬
     * @date   : 2024/4/7 14:21
     */
    initData(){
      // 查询商品系列数据
      // this.getSeriesData();
      // 查询品牌信息
      this.getGoodsBrand();
    },

    /**
     * @desc   : 品牌
     * @author : 宋扬
     * @date   : 2024/4/8 13:23
     */
    getGoodsBrand(){
      this.excute(this.$service.goodsBrandService, this.$service.goodsBrandService.selectByCond, {}).then(res => {
        if (res.code === this.$config.SUCCESS_CODE) {
          this.leftData = res.data.list;
          let list = this.searchContent.filter(it => it.valueFormat.code == 'goodsBrandList')
          if (list.length > 0) {
            list[0].valueFormat.data = res.data.list
          }
        }
      })
    },

    /**
     * @desc   : 查询数据
     * @author : 宋扬
     * @date   : 2024/4/7 14:30
     */
    getData(params){
      return this.excute(this.$service.goodsService,this.$service.goodsService.selectByCond,params)
    },

    /**
     * @desc   : 查询参数重新赋值
     * @author : 宋扬
     * @date   : 2024/4/9 9:10
     */
    setSearchParams(params){
      params.brandId = this.brandId;
      return params;
    },

    /**
     * @desc   : 获取系列数据
     * @author : 宋扬
     * @date   : 2024/4/7 15:10
     */
    // getSeriesData(){
    //   return this.excute(this.$service.goodsSeriesService, this.$service.goodsSeriesService.getGoodsSeriesList, {}).then(res => {
    //     if (res.code === this.$config.SUCCESS_CODE) {
    //       this.leftData = res.data;
    //     }
    //   })
    // },

    /**
     * @desc   : 右侧列表行变化事件
     * @author : 宋扬
     * @date   : 2024/4/7 15:03
     */
    currentChangeEvent({row}){
      if (row != null){
        this.brandId =  row.brandId;
        //调用查询事件
        this.searchData();
      }
    }

  },
  created() {
    this.primaryKey = 'skuId'  // 设置主键Id
    this.routeObjName = 'goods'  // 设置路由名称
    this.comHandleEnableFlag = true; // 开启启用停用功能
  },
}
</script>

