<!-- @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 ref="invalid" name="invalid"></BaseIndexButton>
        <!--关闭-->
        <BaseIndexButton ref="close" name="close"></BaseIndexButton>
      </template>
      <template #right>
        <!--   新建     -->
        <BaseIndexButton ref="addWh" name="addWh"></BaseIndexButton>
        <BaseIndexButton ref="addNsc" name="addNsc"></BaseIndexButton>
      </template>
    </BaseIndexButtonGroup>

    <!--  查询条件区域  -->
    <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" style="margin-left: 5px;">
        <!--批号调整Tbale-->
        <DkTable slot="top"
                 :id="'table-'+$options.name"
                 ref="table-select"
                 :data="tableData"
                 showFooter
                 :height="this.tableHeight * split - 35 "
                 primaryKey="transferId"
                 @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="transferNo" />
          <DkTableColumn field="transferStatusName"/>
          <DkTableColumn field="transferOrg"/>
          <DkTableColumn field="transferStaff" />
          <DkTableColumn field="transferDate" />
<!--          <DkTableColumn field="oWhName" />
          <DkTableColumn field="whName" />
          <DkTableColumn field="oNonStdCode" />
          <DkTableColumn field="nonStdCode" />-->
          <DkTableColumn field="makeStaffName"/>
          <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 * split" primaryKey="itemId" name="table">
          <!-- 商品型号-->
          <DkTableColumn field="skuModel"/>
          <!-- 商品名称-->
          <DkTableColumn field="skuName"/>
          <!-- 唯一编码-->
          <DkTableColumn field="skuCode"/>
          <!-- 品牌-->
          <DkTableColumn field="shortName"/>
          <!-- 调整数量-->
          <DkTableColumn field="transferQty" dataType="number"/>
          <!-- 原仓库-->
          <DkTableColumn field="oWhName" />
          <!-- 目标仓库-->
          <DkTableColumn field="whName" />
          <!--源批号-->
          <DkTableColumn field="oNonStdCode" />
          <!--目标批号-->
          <DkTableColumn field="nonStdCode" />
          <DkTableColumn field="flgValid" type="switch"/>
          <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)">
            <DkTableColumn field="name" :title="$t('fileName')" />
            <DkTableColumn field="path" :imageUrl="$config.imgUrl" type="image" :title="$t('yuLan')"/>
          </DkTable>
        </div>
      </div>
    </DkSplit>
  </div>
</template>


<script>
import {indexMixin} from "@/mixins";
import Config from "@/config";
export default {
  name: 'ivt-transfer',
  mixins: [indexMixin],
  data() {
    let self = this
    return {
      detailModel: 'goodsDetailData',
      detailOptions: [{label: self.$t('freezeGoodsDetail'), name: 'freezeGoodsDetail'}, //货物明细
        {label: self.$t('filesDetail'), name: 'filesDetail'}, //附件明细
      ],
      tableData: [],
      goodsDetailData: [],
      tableDataDetail_files: [],  // 用于存放附件
      visGoodsDetailFlag: true,
      visFilesDetailFlag: false,
      searchContent:
        [
          {
            itemCode: 'transferNo',
          },
          {
            itemCode: 'transferStatusList',
            itemName: self.$t('transferStatusName'),
            valueFormat: {
              code: 'transferStatusList',
              data: [],
              valueKey: 'id',
              labelKey: 'kindName',
            },
            valueKind: 'M-CHOICE'
          },
          // 调整日期
          {
            itemCode: 'transferDate',
            valueFormat: {
              code: 'transferDate',
              default: [new Date().addMonths(-1).format('yyyy-MM-dd'), new Date().format('yyyy-MM-dd')]
            },
            valueKind: 'DATE_RANGE'
          },
          // 业务部门
          {
            itemCode: 'transferOrg',
            valueFormat: {
              code: 'orgIdList',
            },
            magnifierType: Config.MagnifierType.org,
            valueKind: 'M-SEARCH'
          },
          // 业务员
          {
            itemCode: 'transferStaff',
            valueFormat: {
              code: 'staffIdList',
            },
            magnifierType: Config.MagnifierType.staff,
            valueKind: 'M-SEARCH'
          },
          self.$config.flgValidSearch
        ],
    }
  },
  methods: {

    /**
     * @desc   : 加载数据
     * @author : 宋扬
     * @date   : 2024/3/30 15:44
     */
    initData() {
      // 调整状态
      this.getTransferStatus();
      //查询业务部门
      this.getOrg();
      //查询业务员
      this.getStaff();
    },

    /**
     * @desc   : 调整状态
     * @author : 宋扬
     * @date   : 2024/3/30 15:45
     */
    getTransferStatus() {
      // 读取系统字典
      let dataKindList =this.$store.state.user.dataKindList
      let data = dataKindList.filter(it=>it.kindType == this.$config.kindType.transferStatus)
      let list = this.searchContent.filter(it =>  it.valueFormat && it.valueFormat.code == 'transferStatusList')
      if (list.length > 0) {
        list[0].valueFormat.data = data
      }
    },

    /**
     * @desc   : 部门条件
     * @author : 宋扬
     * @date   : 2024/3/30 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/30 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/30 15:52
     */
    getData(params) {
      this.tableData = [];
      this.goodsDetailData = [];
      return this.excute(this.$service.transferService, this.$service.transferService.selectByCond, params)
    },

    /**
     * @desc   : 切换行查询明细
     * @author : 宋扬
     * @date   : 2024/3/30 15:57
     */
    currentChange({row}) {
      this.loading = true
      // 赋值freezeId
      let params = {}
      if (row != null) {
        params = {
          transferId:row.transferId,
        }
      }
      // 查询调整明细
      this.excute(this.$service.transferItemService, this.$service.transferItemService.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/15 13:08
     */
    invalid(rows) {
      if (rows && rows.length > 0) {
        this.$IBMessage({content: this.$t('Q_002', {'param': this.$v('invalid')}), title: this.$t('systemQuestion')},
          {
            ok: () => {
              this.loading = true
              this.excuteNoParam(this.$service.transferService, this.$service.transferService.invalid, [rows[0].transferId], false).then(res => {
                if (res.code === this.$config.SUCCESS_CODE) {
                  this.$Message.success(this.$t('I_001', {'param': this.$t('invalid')}))
                } else {
                  this.$Message.warning(res.message)
                }
                this.loading = false
              })
            },
          })
      }
    },

    /**
     * @desc   : 打开附件
     * @author : 宋扬
     * @date   : 2024/4/3 16:25
     */
    openFile(row) {
      window.open(this.$config.imgUrl + row.url)
    },
  },
  created() {
    this.primaryKey = 'transferId'  // 设置主键Id
    this.routeObjName = 'transfer'  // 设置路由名称
  }
}
</script>
