<!-- @desc:采购退货新建  @auth:常皓宁 @time:2024/03/14 14:15 -->
<template>
  <div class="main-div" style="position: relative;">
    <loading :loading="loading" v-if="!modalVisible"></loading>
    <BaseIndexButtonGroup id="BaseIndexButtonGroup">
      <template #left>
        <!--    选择来源单    -->
        <BaseIndexButton ref="choosePurchase" name="choosePurchase"
                         :disabled="choosePurchaseFlag"
                         @click="choosePurchase(true)"/>
      </template>
    </BaseIndexButtonGroup>
    <DkCollapse @on-change="changeCollapse" ref="collapse">
      <DkPanel prop="essentialInformation">
        <!--  单据信息  -->
        <DkForm slot="content" ref="formInline" v-model="formData" style="width:100%">
          <!--供应商-->
          <DkFormItem prop="supId" :label="$t('supplierName')" :required="true">
            <SelectMagnifier v-model="formData.supId" :display-text="formData.supplierName"
                             :type="this.$config.MagnifierType.supplier"
                             :multiple="false"
                             :otherCondition="{supplierType:'供应商类别-采购'}"/>
          </DkFormItem>
          <!--来源单号-->
          <DkFormItem prop="fromNo">
            <InputPop ref="fromNo" v-model="formData.fromNo" :readonly="true"/>
          </DkFormItem>
          <!--收货仓库-->
          <DkFormItem prop="whId" :label="$t('returnWareHouse')" :required="true">
            <SelectPop v-model="formData.whId" ref="whId"
                       :options="warehouseList"
                       :multiple="false"
                       labelKey="whName" valueKey="whId"
                       @on-select="changItemWhId">
            </SelectPop>
          </DkFormItem>
          <!--自动出库库标识-->
          <DkFormItem prop="autoFlag" v-show="flgAutoHandle">
            <template>
              <i-switch v-model="formData.flgAutoHandle":disabled="type === $config.formMode.handle">
                <span slot="open"></span>
                <span slot="close"></span>
              </i-switch>
            </template>
          </DkFormItem>
          <!--备注-->
          <DkFormItem prop="remarks" :span="24">
            <InputPop ref="remarks" v-model="formData.remarks"
                      maxlength=500 textareaFlag/>
          </DkFormItem>
        </DkForm>
      </DkPanel>
      <!--商品信息-->
      <DkPanel prop="goodsInformation">
        <div id="search-cond-div-goods-info" ref="search-cond-div-goods-info" slot="content">
          <EditTable slot="left"
                     ref="detailTable"
                     majorField="itemId"
                     :data="purchaseItemList"
                     :columns="goodsColumns"
                     :height="400"
                     :freeze="false"
                     :show-footer="true"
                     :add-flag="this.addFlag"
                     :delete-flag="this.deleteFlag"
                     @changeValue="changeValue"
          ></EditTable>
        </div>
      </DkPanel>
      <!--附件-->
      <DkPanel prop="files">
        <div id="search-cond-div-files-info" ref="search-cond-div-files-info"
             slot="content">
          <DkPicWall v-model="formData.annexPaths" :disabled="this.allCanNoEdit?true:false"
                     folder="t_order/annex_paths" :accept="$config.uploadFileConfig.acceptPicType"
                     :format="['jpg','jpeg','png']"></DkPicWall>
        </div>
      </DkPanel>
    </DkCollapse>

    <!--      下部分按钮区域-->
    <DkSaveButton ref="saveButton" :loading="loading" @save="save" @close="close"></DkSaveButton>

    <!--选择采购入库单弹窗-->
    <DkModal
      :loading="loading"
      ref="modal_search"
      id="search-data-class"
      class-name="change-class"
      width="1100px"
      v-model="chooseModal"
      :shortcut-flag="false"
      @modalOk="modalOk"
      @modalCancel="modalCancel"
      @on-visible-change="openPurchaseModal"
      :title="modalTitle">
      <BaseIndexButtonGroup id="ButtonGroup">
        <template #left>
          <BaseIndexButton ref="search" name="search" @click="getDataTable"></BaseIndexButton>
          <BaseIndexButton :finalFlag="true" ref="clear" name="clear"
                           @click="$refs['searchCond'].clearCondition()"></BaseIndexButton>
        </template>
      </BaseIndexButtonGroup>
      <SearchCond id="search-cond-div" width="1000px" class="search-cond-class"
                  v-if="searchContent && searchContent.length > 0" ref="searchCond"
                  v-model="searchCond" :setFlag="false" :searchContent="searchContent" :col-count="4"></SearchCond>
      <DkSplit mode="vertical" v-model="split" :height="chooseTableHeight">
        <div slot="top">
          <DkTable
            ref="purTable"
            :data="purList"
            :height="this.chooseTableHeight * split"
            :page-flag="false"
            :show-setting-flag="false"
            :freeze="false"
            :multiple="false"
            :choose-flag="false"
            :clearCheckFlag="false"
            :auto-width-flag="false"
            primaryKey="intoId"
            :showCheckboxHeader="false"
            :chooseCheckFlag="false"
            :showSettingFlag="false"
            @current-change="currentChange($event)">
            <!-- 采购入库单号-->
            <DkTableColumn field="intoNo"></DkTableColumn>
            <!-- 来源单号-->
            <DkTableColumn field="fromNo"></DkTableColumn>
            <!--部门-->
            <DkTableColumn field="orgName"></DkTableColumn>
            <!--员工-->
            <DkTableColumn field="staffName"></DkTableColumn>
            <!--客户-->
            <DkTableColumn field="cusName"></DkTableColumn>
            <!--入库状态-->
            <DkTableColumn field="intoStatusName" :color-cards="['入库中','已入库']"></DkTableColumn>
            <!--已入库数量-->
            <DkTableColumn field="intoQty" :digits="0" sum :title="'已入库数量'"></DkTableColumn>
            <!--已入库金额-->
            <DkTableColumn field="intoAmt" :digits="0" sum :title="'已入库金额'"></DkTableColumn>
            <!--制单人-->
            <DkTableColumn field="makeStaffName"></DkTableColumn>
            <!--制单时间-->
            <DkTableColumn field="makeTime"></DkTableColumn>
            <!--备注-->
            <DkTableColumn field="remarks"></DkTableColumn>
          </DkTable>
        </div>
        <div slot="bottom">
          <!--入库单明细-->
          <DkTable :pageFlag="false"
                   :pageTotalFlag="false"
                   primaryKey="itemId"
                   :id="'table-'+$options.name"
                   :show-footer="true"
                   ref="detail-select"
                   :showSettingFlag="false"
                   :data="tableDataDetail_goodsDetail"
                   :height="this.chooseTableHeight * (1-split)">
            <!-- 来源单号-->
            <DkTableColumn field="fromNo"></DkTableColumn>
            <!-- 商品型号-->
            <DkTableColumn field="skuModel" :filter="false"></DkTableColumn>
            <!-- 商品名称-->
            <DkTableColumn field="skuName"></DkTableColumn>
            <!-- 唯一编码-->
            <DkTableColumn field="skuCode" :filter="false"></DkTableColumn>
            <!-- 品牌-->
            <DkTableColumn field="brandName" :filter="false"></DkTableColumn>
            <!--品牌简称-->
            <DkTableColumn field="shortName" :filter="false"></DkTableColumn>
            <!--非标号-->
            <DkTableColumn field="nonStandardCode"></DkTableColumn>
            <!--已入库数量-->
            <DkTableColumn field="intoQty" :title="'已入库数量'"></DkTableColumn>
            <!--已入库金额-->
            <DkTableColumn field="intoAmt" :title="'已入库金额'"></DkTableColumn>
            <!--包装-->
            <DkTableColumn field="packBox" ></DkTableColumn>
            <!-- 基本单位-->
            <DkTableColumn field="intoBox" :title="$t('box')" dataType="number" :digits="0"/>
            <!-- 包装单位-->
            <DkTableColumn field="intoPiece" :title="$t('piece')" dataType="number" :digits="0"/>
            <!-- 包装数量-->
            <DkTableColumn field="boxPiece" />
            <!--备注-->
            <DkTableColumn field="remarks"></DkTableColumn>
          </DkTable>
        </div>
      </DkSplit>
    </DkModal>
  </div>
</template>

<script>

import {formMixin} from '@/mixins/form'

export default {
  components: {},
  mixins: [formMixin],
  data() {
    let self = this
    return {
      //编辑来源订单ID
      enterFromId:null,
      addFlag: true ,//商品信息新增
      deleteFlag:true,//商品信息删除
      //选择源单
      choosePurchaseFlag:false,
      fromId:null,//采购入库单来源Id
      //是否显示自动办理入库标识
      flgAutoHandle: true,
      tableHeight: 450,
      tableDataDetail_goodsDetail: [],  // 用于存放入库单明细数据
      split: 0.5,// 分区的默认
      chooseTableHeight: 600,
      purList: [],// 选择采购入库单
      // 查询条件
      searchCond: {},
      // 选择采购入库单弹窗查询条件
      searchContent:
        [
          {
            itemCode: '入库单号-文本',
            itemName: 'intoNo',
            valueFormat: {code: 'intoNo'},
            valueKind: 'STR'
          },
        ],
      //明细明细分页
      detailPageInfo: {
        total: 0,
        pageSize: this.$config.pageSize,
        currentPage: 1
      },
      modalTitle: '选择采购入库单',//选择成型线弹窗名称
      chooseModal: false,
      purItemId: null,
      loading: false,
      allCanNoEdit: false, //是否所有的都不允许编辑
      formData: {
        intoId: null,//入库单Id
        fromId: null,//来源单Id
        fromNo: null,//来源单号
        purId: null,//采购入库单Id
        purNo: null,//采购入库单号
        supId: null,//供应商Id
        supplierName: null,//供应商
        whId: null,//仓库Id
        whName: null,//仓库
        flgAutoHandle: false,//自动出库标识
        remarks: null,
      },
      //明细
      purchaseItemList: [],
      goodsColumns: [
        {
          field: 'skuCode',
          controlId: 'skuId',
          treeNode: true,
          type: 'tableSelect',
          fixed: 'left',
          promotionType: true,
          dataType: self.$config.tableSelectType.goodsForPurchaseReturn,
          tip: self.$t('W_117'),
          fieldUpdate: self.$updateColumns.purchaseReturnColum,
          searchDetailFlag: true
        },
        {
          field: 'skuName',
          controlId: 'skuId',
          type: 'tableSelect',
          fixed: 'left',
          promotionType: true,
          dataType: self.$config.tableSelectType.goodsForPurchaseReturn,
          fieldUpdate: self.$updateColumns.purchaseReturnColum,
          searchDetailFlag: true
        },
        {
          field: 'whId',
          type: 'select',
          options: () => self.warehouseList,
          labelKey: 'whName',
          valueKey: 'whId',
          dataType: self.$config.tableSelectType.warehouse,
          fieldUpdate: [
            {updateField: 'whName', valueFiled: 'whName'},
            {updateField: 'whId', valueFiled: 'whId'},
          ],
          searchDataFlag: false,
        },//仓库名称
        //入库单价
        {
          field: 'priceInto',
          type: 'disabled',
          digits: 2,
          flgUserSensitive: true,
        },
        // 退货数量
        {
          field: 'returnQty',
          title: self.$t('returnQty1'),
          type: 'number',
          digits: 0,
          sum: true,
          negative: () => true,
          formula: {
            returnAmt: ['priceInto*returnQty', 'priceInto', 'returnQty'],
          },
        },
        //可退数量
        {
          field: 'intoQty',
          title: self.$t('可退数量'),
          type: 'disabled',
          digits: 2,
          flgUserSensitive: true,
        },
        //退货金额
        {
          field: 'returnAmt',
          title: self.$t('returnAmt1'),
          type: 'disabled',
          digits: 2,
          flgUserSensitive: true,
        },
        //包装
        {
          field: 'packBox',
          type: 'disabled',
        },
        //箱
        {
          field: 'box',
          type: 'number',
          digits: 0,
          sum: true,
          formula: {
            returnQty: ['box*packBox+piece', 'box', 'packBox' ,'piece'],
          },
        },
        //片
        {
          field: 'piece',
          type: 'number',
          digits: 0,
          sum: true,
          formula: {
            returnQty: ['box*packBox+piece', 'piece','box','packBox'],
            box: ['(box*packBox+piece)/packBox', 'piece', 'box' , 'packBox','packBox'],
            piece: ['(box*packBox+piece)%packBox', 'piece','box', 'packBox', 'packBox'],
          },
        },
        //可退货金额
        // {
        //   field: 'intoAmt',
        //   title: self.$t('可退货金额'),
        //   type: 'disabled',
        //   digits: 2,
        //   flgUserSensitive: true,
        //   formula: {
        //     itemAmt: ['itemAmt/itemQty', 'itemAmt', 'itemQty'],
        //   },
        // },

        {
          field: 'remarks',
        },
      ],
      warehouseList: [],//仓库
    }
  },

  methods: {

    /**
     * @desc   : 总单仓库修改明细仓库
     * @author : 常皓宁
     * @date   : 2024/3/19 9:23
     */
    changItemWhId(){
      let itemData = this.$refs['detailTable'].getTableDataFilter();
      let whName = this.warehouseList.filter(it => it.whId  == this.formData.whId)
      if(itemData && itemData.length > 0){
        itemData.forEach(it =>{
          it.whId = this.formData.whId
          it.whId_Name = whName[0].whName
          it.whName = whName[0].whName
        })
        this.$refs['detailTable'].$refs.xTable.reloadData(itemData)
      }
    },

    /**
     * @desc   : 选择采购入库单
     * @author : 常皓宁
     * @date   : 2024/3/15 13:02
     */
    choosePurchase(modalOpenFlag) {
      if(modalOpenFlag){
        this.chooseModal = true
        this.getDataTable()
      }
    },

    /**
     * @desc   : 打开采购入库单modal
     * @author : 常皓宁
     * @date   : 2024/3/15 13:06
     */
    openPurchaseModal(e) {
      this.$nextTick(() => {
        if (e) {
          this.modalVisible = true;
        } else {
          this.modalVisible = false;
          // 清空列表和查询条件
          this.$refs['searchCond'].clearCondition()
          // 清空数据源
          this.moldlineList = []
        }
      })
    },

    /**
     * @desc   : 清空选择框
     * @author : 周兴
     * @date   : 2023/2/21 15:34
     */
    modalCancel() {
      this.$refs['searchCond'].clearCondition()
      // 清空数据源
      this.moldlineList = []
    },

    /**
     * @desc   : 选择采购入库单确定事件
     * @author : 常皓宁
     * @date   : 2024/3/15 15:23
     */
    modalOk() {
      let batchRows = []
      let itemBatchRows = []
      //包括左侧
      if (this.purList) {
        batchRows = this.$refs['purTable'].batchRows
        itemBatchRows = this.$refs['detail-select'].batchRows
        // 总单
        if (batchRows) {
          this.formData.purId = batchRows[0].fromId
          this.formData.purNo = batchRows[0].fromNo
          this.formData.fromId = batchRows[0].fromId
          this.formData.fromNo = batchRows[0].fromNo
          this.formData.supId = batchRows[0].supId
          this.formData.supplierName = batchRows[0].supplierName
          this.formData.whId = batchRows[0].whId
          this.formData.whName = batchRows[0].whName
        }
        // 明细
        if (itemBatchRows) {
          itemBatchRows.map(row => {
            let item = row
            this.$set(item, 'intoItemId', row['itemId'])
            // 仓库
            this.$set(item, 'whId', this.formData.whId)
            this.$set(item, 'whName', this.formData.whName)
            // 箱（已入库）
            this.$set(item, 'box', row['intoBox'])
            // 片（已入库）
            this.$set(item, 'piece', row['intoPiece'])
            // 不可查询
            this.$set(item, 'readOnly', ['skuCode','skuName'])
          })
          this.purchaseItemList = itemBatchRows
          for (let index = 0; index < this.purchaseItemList.length; index++) {
            this.purchaseItemList[index].returnQty = (this.purchaseItemList[index].intoQty - this.purchaseItemList[index].returnQty) * -1
            this.purchaseItemList[index].returnAmt = (this.purchaseItemList[index].intoAmt - this.purchaseItemList[index].returnAmt) * -1
          }
          //关闭选择弹框
          this.modalCancel() // 清空选择界面
          this.chooseModal = false
          this.addFlag = false
        }
      }
    },

    /**
     * @desc   : 行点击事件
     * @author : 常皓宁
     * @date   : 2024/2/28 15:01
     */
    currentChange({row}) {
      if (row != null) {
        this.intoId = row.intoId
        //查询采购入库单明细
        this.getDetail(1)
      }
    },

    /**
     * @desc   : 获取总单id对应明细
     * @author : 常皓宁
     * @date   : 2024/2/28 15:03
     */
    getDetail(currentPage) {
      if (currentPage) {
        this.detailPageInfo.currentPage = currentPage
      }
      let params = {
        intoId: this.intoId,
        pageSize: this.detailPageInfo.pageSize,
        currentPage: this.detailPageInfo.currentPage
      }
      // 查询数据
      return this.excute(this.$service.purEnterItemService, this.$service.purEnterItemService.selectByCond, params).then(res => {
        if (res.code === this.$config.SUCCESS_CODE) {
          this.tableDataDetail_goodsDetail = res.data.list
          if(this.tableDataDetail_goodsDetail.size() ==0){
            this.tableDataDetail_goodsDetail = []
          }
          // 全选
          this.$nextTick(() => {
            this.$refs['detail-select'].checkAll();
          })
          this.$refs['detail-select'].pageInfo.total = res.data.total
        } else {
          this.tableDataDetail_goodsDetail = []
        }
      })
    },

    /**
     * @desc   : 数据校验
     * @author : 常皓宁
     * @date   : 2024/3/2 9:51
     */
    validData() {
      // 明细必须有数据
      let itemTable = this.$refs['detailTable'].getTableDataFilter();
      if (!itemTable || itemTable.length == 0) {
        this.$Message.warning(this.$t('W_012'))
        return false;
      }
      for (let i = 0; i < itemTable.length; i++) {
        if (itemTable[i].intoQty && (Math.abs(itemTable[i].returnQty) > itemTable[i].intoQty)) {
          this.$message.warning(this.$t('W_008', {'param1': this.$t('sequence') + (i + 1) + this.$t('rowNo') + this.$t('returnQty1'),'param2':this.$t('可退数量')}))
          return false;
        }
      }
      return true
    },

    /**
     * @desc   : 行改变事件
     * @author : 常皓宁
     * @date   : 2024/3/19 10:51
     */
    changeValue(field, row, rowIndex) {
      if(field && (field == 'skuCode' || field == 'skuName')){
        this.choosePurchaseFlag = true
        this.addFlag = true
      }
      // if (!row.whId || row.whId === 0 || row.whId === null) {
      //   this.$set(row, 'whId', this.whId);
      //   this.$set(row, 'whId_Name', this.whName);
      // }
    },

    /**
     *   @desc   : 清空参数
     *   @date   : 2022/12/20 15:33
     *   @author : 常皓宁
     */
    clear() {
      this.formData = {
        fromId: null,//来源单Id
        fromNo: null,//来源单号
        purId: null,
        purNo: null,
        supId: null,
        supName: null,
        whId: null,
        whName: null,
        remarks: null,
      },
        this.purchaseItemList = []
    },

    /**
     * @desc   : 给参数赋值
     * @author : 常皓宁
     * @date   : 2024/2/28 13:41
     */
    setParams() {
      this.params = {...this.formData}
      // 部门
      this.params.orgId = this.$store.state.user.orgId
      // 员工
      this.params.staffId = this.$store.state.user.staffId
      // 制单员
      this.params.makeStaff = this.$store.state.user.staffId
      // 公司
      this.params.cpId = this.$store.state.user.cpId
      // 账务日期
      this.params.intoDate = new Date().format("yyyy-MM-dd")
      // 新建
      if (this.type === this.$config.formMode.add) {
        let tableFilter = this.$refs['detailTable'].getTableDataFilter();
        tableFilter.map(row => {
          let item = row
          // 退货价
          this.$set(item, 'priceReturn', row['priceInto']* -1)
          //是否自动办理入库
          if(this.formData.flgAutoHandle){
            // 箱（已入库）
            this.$set(item, 'intoBox', row['box'])
            // 片（已入库）
            this.$set(item, 'intoPiece', row['piece'])
            // 箱（入库中）
            this.$set(item, 'intoingBox', 0)
            // 片（入库中）
            this.$set(item, 'intoingPiece',0)
          }else{
            // 箱（已入库）
            this.$set(item, 'intoBox', 0)
            // 片（已入库）
            this.$set(item, 'intoPiece', 0)
            // 箱（入库中）
            this.$set(item, 'intoingBox', row['box'])
            // 片（入库中）
            this.$set(item, 'intoingPiece', row['piece'])
          }
          return item
        })
        // 采购退货明细
        this.params.itemList = tableFilter
        // 入库中数量
        this.params.returnQty = tableFilter.sum('returnQty')
        // 入库中金额
        this.params.returnAmt = tableFilter.sum('returnAmt')
      }
      // 入库办理
      if (this.type === this.$config.formMode.handle) {
        let tableFilter = this.$refs['detailTable'].getTableDataFilter();
        // 采购入库明细
        this.params.itemList = tableFilter
      }
    },

    /**
     * @desc   : 提交事件
     * @author : 付斌
     * @date   : 2024-02-19 10:47
     */
    saveData() {
      console.log('this.params', this.params)
      //新建
      if (this.type === this.$config.formMode.add) {
        return this.excute(this.$service.purReturnService, this.$service.purReturnService.insert, this.params)
      }
      //编辑
      if (this.type === this.$config.formMode.edit) {
        return this.excute(this.$service.purReturnService, this.$service.purReturnService.update, this.params)
      }
      //退货办理
      else if (this.type === this.$config.formMode.handle) {
        return this.excute(this.$service.purReturnService, this.$service.purReturnService.returnHandle, this.params)
      }
    },
    /***************************列表及其他事件************************************/

    /***************************设定参数函数************************************/

    /***************************created调用数据接口函数************************************/

    /**
     * @desc   : 获取采购入库数据
     * @author : 常皓宁
     * @date   : 2024/3/15 13:08
     */
    getDataTable() {
      let param = {}
      param.fromId = this.enterFromId
      param.cpId = this.$store.state.user.cpId
      param.intoStatus = this.$config.intoStatus.yiRuKu
      param = Object.assign(param, this.searchCond._value)
      this.loading = true;
      this.excute(this.$service.purEnterService, this.$service.purEnterService.selectByCond, param).then(res => {
        if (res.code === this.$config.SUCCESS_CODE) {
          this.purList = res.data.list
        } else {
          this.$Message.warning(res.message)
          this.purList = []
        }
        this.loading = false;
      })
    },

    /**
     * @desc   : 通过id查询
     * @author : 常皓宁
     * @date   : 2024/2/29 8:49
     */
    detail(id) {
      return this.excuteNoParam(this.$service.purReturnService, this.$service.purReturnService.selectByUpdate, [id])
    },

    /**
     * @desc   : 编辑页面赋值
     * @author : 常皓宁
     * @date   : 2024/2/29 9:49
     */
    setValuesByEdit(data) {
      console.log('data',data)
      this.enterFromId = data.fromId
      this.formData.intoId = data.intoId
      this.formData.fromId = data.fromId
      this.formData.fromNo = data.fromNo
      this.formData.supId = data.supId
      this.formData.supplierName = data.supName
      this.formData.remarks = data.remarks
      this.formData.whId = data.whId
      this.formData.whName = data.whName
      let dataItem = data.goodsList
      dataItem.map(row => {
        let item = row
        // 标价
        this.$set(item, 'priceInto', row['priceInto'])
        // 退货数量
        this.$set(item, 'itemQty', row['itemQty']*-1)
        // 退货金额
        this.$set(item, 'itemAmt', row['itemQty']*row['priceStd'])
        // 可退货数量
        this.$set(item, 'intoQty', row['intoQty'] - row['returnQty'])
        // 可退货金额
        this.$set(item, 'intoAmt', row['intoAmt'] - row['returnAmt'])
        // 不可查询
        this.$set(item, 'readOnly', ['skuCode','skuName'])

        if(row.intoStatus == this.$config.intoStatus.ruKuZhong){
          // 箱
          this.$set(item, 'box', row['intoingBox'])
          // 片
          this.$set(item, 'piece', row['intoingPiece'])
        } else {
          // 箱（已入库）
          this.$set(item, 'box', row['intoBox'])
          // 片（已入库）
          this.$set(item, 'piece', row['intoPiece'])
        }
        return item
      })
      this.purchaseItemList = dataItem
      //大编辑标识
      if(this.type === this.$config.formMode.edit){
        //系统自动办理入库
        if(this.$store.state.user.setting[this.$config.settingCode.IVT001] == 1){
          //已入库未收款可以大编辑
          if(data.paymentFlag){
            this.$refs.detailTable.enabledEdit = false
          }else{
            this.$refs.detailTable.enabledEdit = true
          }
        }
        //手动办理入库
        else{
          //已入库不能大编辑
          if(data.intoStatus == this.$config.intoStatus.yiRuKu){
            this.$refs.detailTable.enabledEdit = false
          }else{
            this.$refs.detailTable.enabledEdit = true
          }
        }
        console.log('asda',this.$refs.detailTable.enabledEdit)
      }
      //办理
      else if(this.type === this.$config.formMode.handle){
        this.deleteFlag = false;
        this.addFlag = false;
      }
    },

    /**
     * @desc   : 获取仓库
     * @author : 常皓宁
     * @date   : 2024/2/28 14:39
     */
    getWareHouseList() {
      let params = {
        cpId: this.$store.state.user.cpId
      }
      this.excute(this.$service.commonService, this.$service.commonService.getWarehouse, params, false).then(res => {//调用api查询方法
        if (res.code === this.$config.SUCCESS_CODE) {
          this.warehouseList = res.data
          //赋值默认仓库 组件需要
          let newList = res.data.filter(it => it.flgDefault)
          this.whId = newList[0].whId
          this.whName = newList[0].whName
        }
      })
    },

    /**
     * @desc   : 加载数据
     * @author : 常皓宁
     * @date   : 2024/2/28 14:37
     */
    initData() {
      this.getWareHouseList();   // 获取仓库数据
    },
  },
  /**
   * @desc   : 在实例创建完成后被立即同步调用
   * @author : 寇珊珊
   * @date   : 2022/3/3 10:32
   */
  created() {
    this.resizeTableFlag = true;  // 计算表格高度
    // 出库办理
    if (this.$route.params.id){
      if (this.type === this.$config.formMode.handle) {
        this.flgAutoHandle = false;
        this.choosePurchaseFlag = true
      }
    }
  },

  activated() {
    console.log('this.$route.query',this.$route.query)
    if (this.$route.params && this.$route.params.row.purId) {
      this.enterFromId = this.$route.params.row.purId
      this.choosePurchase(true)
    }
  },
}
</script>


<style scoped>


/deep/ .ivu-modal-body {
  background: #EAEDF7 !important;
}

</style>
