<!-- @desc:库存冻结  @auth:宋扬  @time:2024/2/19 12:59 -->
<template>
  <div class="main-div">
    <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 v-show="flgUnFreese" ref="unFreeze" name="unFreeze"></BaseIndexButton>
        <!--打印-->
        <BaseIndexButton ref="print" name="print"></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>
      <!--  表格区  -->
      <DkSplit mode="vertical" v-model="split" :height="tableHeight">
        <div slot="top">
          <DkTable slot="top"
                   :id="'table-'+$options.name"
                   ref="table-select"
                   :data="tableData"
                   showFooter
                   :height="this.tableHeight * split - 36 "
                   primaryKey="freezeId"
                   @pageChange="pageSizeChange"
                   :page-total="pageInfo.total"
                   :current-page="pageInfo.currentPage"
                   :choose-flag="false"
                   @current-change="currentChange($event)"
                   :page-size-opts="pageSizeOpts"
                   :page-size="pageInfo.pageSize"
                   name="table">
            <DkTableColumn field="freezeNo" ></DkTableColumn>
            <DkTableColumn field="freezeDate"></DkTableColumn>
            <DkTableColumn field="freezeStatusName"></DkTableColumn>
            <DkTableColumn field="cusName"></DkTableColumn>
            <DkTableColumn field="orgName"></DkTableColumn>
            <DkTableColumn field="staffName"></DkTableColumn>
            <DkTableColumn field="sumQuantity" dataType="number"></DkTableColumn>
            <DkTableColumn field="makeStaffName"></DkTableColumn>
            <DkTableColumn field="autoUnfreezeDate"></DkTableColumn>
            <DkTableColumn field="flgValid" type="switch"/>
            <DkTableColumn field="remarks"/>
          </DkTable>
        </div>
        <div slot="bottom">
          <DkTabs v-model="detailModel" :options="detailOptions" @on-click="detailTabsClick"></DkTabs>
          <!--冻结明细-->
          <div v-show="visGoodsDetailFlag">
            <DkTable :id="'table-'+$options.name" ref="detail-select" :data="goodsDetailData" showFooter
                     :height="this.tableHeight * (1-split)-62" primaryKey="itemId" name="table">
              <!-- 商品型号-->
              <DkTableColumn field="skuModel"/>
              <!-- 商品名称-->
              <DkTableColumn field="skuName"/>
              <!-- 唯一编码-->
              <DkTableColumn field="skuCode"/>
              <!-- 品牌-->
              <DkTableColumn field="shortName"/>
              <!-- 冻结数量-->
              <DkTableColumn field="freezeQty"dataType="number" :sum="true" />
              <!-- 箱-->
              <DkTableColumn field="box" dataType="number" :digits="0"/>
              <!-- 片-->
              <DkTableColumn field="piece" dataType="number" :digits="0"/>
              <!-- 包装数量-->
              <DkTableColumn field="boxPiece" />
              <!-- 解冻数量-->
              <DkTableColumn field="unfreezeQty" dataType="number":sum="true"/>
              <!-- 剩余解冻数量-->
              <DkTableColumn field="surplusQty" dataType="number" :sum="true"/>
              <!-- 仓库-->
              <DkTableColumn field="whName" />
              <DkTableColumn field="remarks" />
            </DkTable>
          </div>
          <!--附件-->
          <div v-show="visFilesDetailFlag">
            <DkTable :pageFlag="false" :pageTotalFlag="false" :id="'table-'+$options.name"
                     name="table" ref="file-select" :data="tableDataDetail_files" :height="this.tableHeight * (1-split)-62">
              <DkTableColumn field="name" :title="$t('fileName')" />
              <DkTableColumn field="path" :imageUrl="$config.imgUrl" type="image" :title="$t('yuLan')"/>
            </DkTable>
          </div>
        </div>
      </DkSplit>
    </div>
    <PrintModal ref="printModal" :doc-name="$config.docCode.ivtFreeze"
                :postName="'freeze'"
                :id="$refs?.['table-select']?.batchRows?.[0]?.freezeId||null"/>
  </div>
</template>

<script>
import {indexMixin} from "@/mixins";
import PrintModal from '_c/business/print/modal'
import Config from "@/config";
export default {
  name: 'ivt-freeze',
  mixins: [indexMixin],
  components: {PrintModal},
  data() {
    let self = this
    return {
      detailModel: 'goodsDetailData',
      detailOptions: [{label: self.$t('freezeGoodsDetail'), name: 'freezeGoodsDetail'}, //货物明细
        {label: self.$t('filesDetail'), name: 'filesDetail'}, //附件明细
      ],
      tableData:[],
      goodsDetailData:[],
      tableDataDetail_files: [],  // 用于存放附件
      // 是否显示解冻按钮
      flgUnFreese: true,
      visGoodsDetailFlag: true,
      visFilesDetailFlag: false,
      searchContent:
        [
          {
            itemCode: 'freezeNo',
          },
          {
            itemCode: 'freezeStatusList',
            itemName: self.$t('freezeStatusName'),
            valueFormat: {
              code: 'freezeStatusList',
              data: [],
              valueKey: 'id',
              labelKey: 'kindName',
            },
            valueKind: 'M-CHOICE'
          },
          {
            itemCode: 'cusName',
            valueFormat: {code: 'cusName'},
            valueKind: 'STR'
          },
          // 业务部门
          {
            itemCode: 'orgId',
            valueFormat: {
              code: 'orgIdList',
            },
            magnifierType: Config.MagnifierType.org,
            valueKind: 'M-SEARCH'
          },
          // 业务员
          {
            itemCode: 'staffId',
            valueFormat: {
              code: 'staffIdList',
            },
            magnifierType: Config.MagnifierType.staff,
            valueKind: 'M-SEARCH'
          },
          // 冻结日期
          {
            itemCode: 'freezeDate',
            valueFormat: {
              code: 'freezeDate',
              default: [new Date().addMonths(-1).format('yyyy-MM-dd'), new Date().format('yyyy-MM-dd')]
            },
            valueKind: 'DATE_RANGE'
          },
          {
            itemCode: 'autoUnfreezeDate',
            valueFormat: {
              code: 'autoUnfreezeDate',
              default: [new Date().addMonths(-1).format('yyyy-MM-dd'), new Date().format('yyyy-MM-dd')]
            },
            valueKind: 'DATE_RANGE',
          },
          self.$config.flgValidSearch
        ],
    }
  },
  methods: {

    /**
     * @desc   : 选择模板、打印机
     * @author : 洪旭东
     * @date   : 2023-04-10 13:45
     */
    print() {
      this.$refs.printModal.showChooseTemplate = true
    },

    /**
     * @desc   : 加载数据
     * @author : 宋扬
     * @date   : 2024/3/14 11:16
     */
    initData() {
      // 获取冻结状态
      this.getFreezeStatus();
      //查询业务部门
      this.getOrg()
      //查询业务员
      this.getStaff()
    },

    /**
     * @desc   : 获取冻结状态
     * @author : 宋扬
     * @date   : 2024/3/14 16:33
     */
    getFreezeStatus() {
      // 读取系统字典
      let dataKindList =this.$store.state.user.dataKindList
      let data = dataKindList.filter(it=>it.kindType == this.$config.kindType.freezeStatus)
      let list = this.searchContent.filter(it =>  it.valueFormat && it.valueFormat.code == 'freezeStatusList')
      if (list.length > 0) {
        list[0].valueFormat.data = data
      }
    },
    /**
     * @desc   : 部门条件
     * @author : 宋扬
     * @date   : 2024/3/14 13:43
     */
    getOrg() {
      let params = {
        cpId: this.$store.state.user.cpId,
        flgValid: true
      }
      this.excute(this.$service.commonService, this.$service.commonService.getOrg, params).then(res => {
        if (res.code === this.$config.SUCCESS_CODE) {
          let list = this.searchContent.filter(it => it.valueFormat.code == 'orgIdList')
          if (list.length > 0) {
            list[0].valueFormat.data = res.data
          }
        }
      })
    },
    /**
     * @desc   : 业务员
     * @author : 宋扬
     * @date   : 2024/3/14 13:43
     */
    getStaff() {
      let params = {
        cpId: this.$store.state.user.cpId,
        flgValid: true
      }
      this.excute(this.$service.commonService, this.$service.commonService.getStaff, params).then(res => {
        if (res.code === this.$config.SUCCESS_CODE) {
          let list = this.searchContent.filter(it => it.valueFormat.code == 'staffIdList')
          if (list.length > 0) {
            list[0].valueFormat.data = res.data
          }
        }
      })
    },
    /**
     * @desc   : 查询数据
     * @author : 宋扬
     * @date   : 2024/3/13 10:42
     */
    getData(params) {
      this.tableData = [];
      this.goodsDetailData = [];
      return this.excute(this.$service.freezeService, this.$service.freezeService.selectByCond, params)
    },

    /**
     * @desc   : 切换行查询明细
     * @author : 宋扬
     * @date   : 2024/3/13 15:51
     */
    currentChange({row}) {
      this.loading = true
      // 赋值freezeId
      let params = {}
      if (row != null) {
        params = {
          freezeId:row.freezeId,
        }
        if(row.freezeStatus === this.$config.freezeStatus.allUnFreeze){
          this.flgUnFreese = false;
        }
        else{
          this.flgUnFreese = true;
        }
      }

      // 查询冻结明细
      this.excute(this.$service.freezeItemService, this.$service.freezeItemService.selectByCond, params).then(res => {
        if (res.code === this.$config.SUCCESS_CODE) {
          this.goodsDetailData = res.data.list;
        }
      })
      //附件
      this.tableDataDetail_files = row.annexPaths
      this.loading = false
    },

    /**
     * @desc   : 点击Tab进行切换
     * @author : 宋扬
     * @date   : 2024/4/3 16:24
     */
    detailTabsClick(val) {
      if (val === 'freezeGoodsDetail') {
        this.visGoodsDetailFlag = true
        this.visFilesDetailFlag = false
      } else if (val === 'filesDetail') {
        this.visGoodsDetailFlag = false
        this.visFilesDetailFlag = true
      }
    },

    /**
     * @desc   : 打开附件
     * @author : 宋扬
     * @date   : 2024/4/3 16:25
     */
    openFile(row) {
      window.open(this.$config.imgUrl + row.url)
    },

  },
  created() {
    this.primaryKey = 'freezeId'  // 设置主键Id
    this.routeObjName = 'freeze'  // 设置路由名称
  }
}
</script>


