<template>
  <div class="main-div" ref="mainDiv">
    <!--加载中-->
    <loading :loading="loading" v-if="!modalVisible"></loading>
    <DkPageButton :total="editKeys?editKeys.length:0"
                  :current="editIndex"
                  v-if="editKeys && editKeys.length > 1"
                  @pageChange="editPageChange"></DkPageButton>
    <DkCollapse @on-change="changeCollapse" ref="collapse">
      <DkPanel prop="baseAttribute">
        <!--  基础属性  -->
        <DkForm slot="content" ref="formInline" v-model="formData" :labelMaxWords=5>
          <!--商品编码-->
          <DkFormItem prop="skuCode">
            <InputPop ref="skuCode" v-model="formData.skuCode" :readonly="true"/>
          </DkFormItem>
          <!--商品型号-->
          <DkFormItem prop="skuModel" :required="true">
            <InputPop ref="skuModel" v-model="formData.skuModel" />
          </DkFormItem>
          <!--商品名称-->
          <DkFormItem prop="skuName" :required="true">
            <InputPop ref="skuName" v-model="formData.skuName"/>
          </DkFormItem>
        </DkForm>
      </DkPanel>
      <DkPanel prop="goodsAttribute">
        <!--  商品属性  -->
        <DkForm slot="content" ref="formInline" v-model="formData" :labelMaxWords=5>
          <!--  品牌  -->
          <DkFormItem prop="brandId" :label="$t('brandIds')" :required="true">
            <SelectMagnifier v-model="formData.brandId" :display-text="formData.brandName"
                             :type="this.$config.MagnifierType.brand"
                             :multiple="false"></SelectMagnifier>
          </DkFormItem>
          <!--商品种类-->
          <DkFormItem prop="categoryId" :label="$t('category')" :required="true">
            <SelectPop v-model="formData.categoryId" :multiple="false"
                       :options="categoryList"
                       labelKey="catName"
                       valueKey=catId>
            </SelectPop>
          </DkFormItem>
          <!--商品系列-->
          <DkFormItem prop="seriesId" :label="$t('series')" :required="true">
            <SelectPop v-model="formData.seriesId" :multiple="false" :options="seriesList"
                       labelKey="seriesName"
                       valueKey=seriesId>
            </SelectPop>
          </DkFormItem>
          <!--计量单位-->
          <DkFormItem prop="unitId" :label="$t('unit')" :required="true">
            <SelectPop v-model="formData.unitId" :multiple="false" :options="unitList"
                       labelKey="unitName"
                       valueKey="unitId">
            </SelectPop>
          </DkFormItem>
          <!--辅助单位-->
          <DkFormItem prop="subUnitId" :label="$t('subUnit')">
            <SelectPop v-model="formData.subUnitId" :multiple="false" :options="subUnitList"
                       labelKey="unitName"
                       valueKey="unitId">
            </SelectPop>
          </DkFormItem>
          <!--商品规格-->
          <DkFormItem prop="skuSpec">
            <InputPop ref="skuSpec" v-model="formData.skuSpec"/>
          </DkFormItem>
          <!--单位换算-->
          <DkFormItem prop="conversionFactor">
            <InputNumberPop ref="conversionFactor" v-model="formData.conversionFactor"/>
          </DkFormItem>
        </DkForm>
      </DkPanel>
      <DkPanel prop="priceItem">
        <DkForm slot="content" ref="formInline" v-model="formData">
          <!--采购价-->
          <DkFormItem prop="pricePurchase">
            <InputNumberPop ref="pricePurchase" v-model="formData.pricePurchase" />
          </DkFormItem>
          <!--零售价-->
          <DkFormItem prop="priceStandard">
            <InputNumberPop ref="priceStandard" v-model="formData.priceStandard" />
          </DkFormItem>
          <!--批发价-->
          <DkFormItem prop="priceWholesale">
            <InputNumberPop ref="priceWholesale" v-model="formData.priceWholesale"/>
          </DkFormItem>
          <!--销售售价-->
          <DkFormItem prop="priceLimited">
            <InputNumberPop ref="priceLimited" v-model="formData.priceLimited"/>
          </DkFormItem>
        </DkForm>
      </DkPanel>
      <DkPanel prop="invInto" v-show="false">
        <DkForm slot="content" ref="formInline" v-model="formData">
        <!--  仓库名称  -->
        <DkFormItem prop="whId">
          <SelectMagnifier v-model="formData.whId" :display-text="formData.whName"
                           :type="this.$config.MagnifierType.warehouse"
                           :multiple="false"></SelectMagnifier>
        </DkFormItem>
        <!--非标号-->
        <DkFormItem prop="nonStdCode">
          <InputPop ref="nonStdCode" v-model="formData.nonStdCode"/>
        </DkFormItem>
        </DkForm>
      </DkPanel>
      <DkPanel prop="remarks">
        <DkForm slot="content" ref="formInline" v-model="formData">
          <DkFormItem prop="remarks" :span="12">
            <InputPop ref="remarks" v-model="formData.remarks"
                      maxlength=500 textareaFlag/>
          </DkFormItem>
        </DkForm>
      </DkPanel>
      <DkPanel prop="skuImages">
        <div id="search-cond-div-files-info" ref="search-cond-div-files-info" slot="content">
          <DkPicWall v-model="formData.skuImages"
                     :table="$config.tables.sku" :accept="$config.uploadFileConfig.acceptPicType"></DkPicWall>
        </div>
      </DkPanel>

    </DkCollapse>

    <!--      下部分按钮区域-->
    <DkSaveButton ref="saveButton" :loading="loading" @save="save" @close="close"
                  v-if="type !== 'edit-staff'"></DkSaveButton>
  </div>
</template>

<script>
import {formMixin} from "@/mixins/form";
import {button, columns, formTitle, loginTitle, messages, others} from "@/locale/lang/zh-CN";

export default {
  components: {},
  mixins: [formMixin],
  data() {
    return {
      categoryList:[],
      seriesList:[],
      unitList:[],
      subUnitList:[],
      formData:{
        skuCode: null,
        skuModel: null,
        skuName: null,
        brandId: null,//商品品牌
        brandName:null,
        categoryId: null,//商品种类
        seriesId: null,//商品系列
        unitId: null,//计量单位
        skuSpec: null,//商品规格
        subUnitId: null,//辅助计量单位
        conversionFactor: null, //单位换算
        nonStdCode:null,
        whId:null,
        whName:null,
        pricePurchase : null, //采购价
        priceStandard : null, //零售价
        priceWholesale : null,//批发价
        priceLimited : null, //销售售价
        remarks: null,
      },
    }
  },
  methods: {

    /**
     * @desc   : 加载数据
     * @author : 宋扬
     * @date   : 2024/4/8 15:12
     */
    initData() {
      // 获取商品种类
      this.getGoodsCategory();
      // 获取商品系列
      this.getGoodsSeries();
      // 获取计量单位
      this.getGoodsUnit();
    },

    /**
     * @desc   : 获取商品种类
     * @author : 宋扬
     * @date   : 2024/4/8 15:13
     */
    getGoodsCategory() {
      this.excute(this.$service.goodsCategoryService, this.$service.goodsCategoryService.selectByCond, {}).then(res => {
        if (res.code === this.$config.SUCCESS_CODE) {
          this.categoryList = res.data.list;
        }
      })
    },

    /**
     * @desc   : 获取商品系列
     * @author : 宋扬
     * @date   : 2024/4/8 15:18
     */
    getGoodsSeries() {
      this.excute(this.$service.goodsSeriesService, this.$service.goodsSeriesService.selectByCond, {}).then(res => {
        if (res.code === this.$config.SUCCESS_CODE) {
          this.seriesList = res.data.list;
        }
      })
    },

    /**
     * @desc   : 获取计量单位
     * @author : 宋扬
     * @date   : 2024/4/8 15:20
     */
    getGoodsUnit() {
      this.excute(this.$service.unitService, this.$service.unitService.selectByCond, {}).then(res => {
        if (res.code === this.$config.SUCCESS_CODE) {
          this.unitList = res.data.list;
          this.subUnitList=this.unitList.copy();
        }
      })
    },

    /**
     * @desc   : 赋值信息
     * @author : 宋扬
     * @date   : 2024/4/8 16:41
     */
    setParams(){
      this.params = {...this.formData}
    },

    /**
     * @desc   : desc
     * @author : 宋扬
     * @date   : 2024/4/9 15:29
     */
    setValuesByEdit(data) {
      if (data) {
        this.formData = data;
      }
    },

    /**
     * @desc   : 通过id查询
     * @author : 宋扬
     * @date   : 2024/4/9 15:31
     */
    detail(id) {
      return this.excuteNoParam(this.$service.goodsService, this.$service.goodsService.selectById, [id], false);
    },

    /**
     * @desc   : 保存数据
     * @author : 宋扬
     * @date   : 2024/4/8 16:30
     */
    saveData() {
      if (this.type === this.$config.formMode.add) {
        return this.excute(this.$service.goodsService, this.$service.goodsService.insert, this.params);
      } else if (this.type === this.$config.formMode.edit) {
        return this.excute(this.$service.goodsService, this.$service.goodsService.update, this.params);
      }
    },

  },

  /**
   * @desc   : 在实例创建完成后被立即同步调用
   * @author : 宋扬
   * @date   : 2024/4/9 15:30
   */
  created() {
    this.focusItem = 'skuId';    // 给第一个组件赋值，可以在混入中自动去聚焦
    this.primaryKey = 'skuId'  // 设置主键Id
  },
}
</script>
