<!-- @desc:其它收入单  @auth:付斌  @time:2024/02/20 15:15 -->
<template>
  <div class="main-div">
    <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="invalid" name="invalid"></BaseIndexButton>
      </template>
      <template #right>
        <BaseIndexButton ref="add" name="add"></BaseIndexButton>
      </template>
    </BaseIndexButtonGroup>

    <!--  查询条件区域  -->
    <div id="search-cond-div" ref="search-cond-div" style="margin-top: 1px;padding: 0">
      <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;">
        <DkTable slot="top"
                 :id="'table-'+$options.name"
                 ref="table-select"
                 :data="tableData"
                 showFooter
                 :height="this.tableHeight * split - 35"
                 primaryKey="receivableId"
                 @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 :type="$libaray.checkButtonHasRight('receivable-edit')?'link':''" field="receivableNo"
                         :tree-node="true" @on-link="edit"/>
          <DkTableColumn field="cusName"/>
          <DkTableColumn field="cusPhone"/>
          <DkTableColumn field="contactName"/>
          <DkTableColumn field="sumAmtReceivable" :digits="2" dataType="number" sum/>
          <DkTableColumn field="accDate" data-type="date"/>
          <DkTableColumn field="orgName"/>
          <DkTableColumn field="staffName"/>
          <DkTableColumn field="makeStaffName"/>
          <DkTableColumn field="makeTime" data-type="dateTime"/>
          <DkTableColumn field="flgValid" type="switch"/>
          <DkTableColumn field="remarks"/>
        </DkTable>
      </div>
      <div slot="bottom">
        <div v-show="visItemFlag">
          <DkTabs v-model="detailModel" :options="detailOptions" @on-click="detailTabsClick"></DkTabs>
          <!--其他收入单明细-->
          <DkTable :id="'table-'+$options.name" ref="detail-select" :data="tableDataDetail_otherReceivableItem"
                   showFooter
                   :height="this.tableHeight * (1-split)" primaryKey="itemId" name="table">
            <DkTableColumn field="receivableTypeName"/>
            <DkTableColumn field="qtyReceivable" dataType="number" sum/>
            <DkTableColumn field="amtReceivable" :title="$t('shouRuAmt')" :digits="2" dataType="number" sum/>
            <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'

export default {
  name: 'receivable',
  mixins: [indexMixin],
  data() {
    let self = this
    return {
      tableData: [],
      tableDataDetail_otherReceivableItem: [],  // 用于存放其他收入单明细数据
      tableDataDetail_files: null,
      detailModel: 'otherReceivableDetail',
      detailOptions: [
        {label: self.$t('otherReceivableDetail'), name: 'otherReceivableDetail'},//收款明细
        {label: this.$t('filesDetail'), name: 'filesDetail'}
      ],
      visItemFlag: true,
      visFilesDetailFlag: false,
      searchContent: [
        {
          itemCode: '其他收入单单号-文本',
          itemName: 'receivableNo',
          valueFormat: {code: 'receivableNo'},
          valueKind: 'STR'
        },
        {
          itemCode: '客户名称-文本',
          itemName: 'cusName',
          valueFormat: {code: 'cusName'},
          valueKind: 'STR'
        },
        {
          itemCode: '客户电话-文本',
          itemName: 'cusPhone',
          valueFormat: {code: 'cusPhone'},
          valueKind: 'STR'
        },
        {
          itemCode: '业务部门-文本',
          itemName: 'orgId',
          valueFormat: {
            code: 'orgIdList',
            data: [],
            valueKey: 'orgId',
            labelKey: 'orgName',
          },
          valueKind: 'M-CHOICE'
        },
        {
          itemCode: '业务员-文本',
          itemName: 'staffId',
          valueFormat: {
            code: 'staffIdList',
            data: [],
            valueKey: 'staffId',
            labelKey: 'staffCodeName',
          },
          valueKind: 'M-CHOICE'
        },
        {
          itemCode: '制单时间-时间',
          itemName: 'makeTime',
          valueFormat: {
            code: 'makeTime',
            default: [new Date().addMonths(-1).format('yyyy-MM-dd'), new Date().format('yyyy-MM-dd')]
          },
          valueKind: 'DATE_RANGE',
          // required: true,
        },
        self.$config.flgValidSearch
      ],
    }
  },

  methods: {
    /**
     * @desc   : 加载数据
     * @author : 付斌
     * @date   : 2024-02-20 15:53
     */
    initData() {
      //查询业务部门
      this.getOrg()
      //查询业务员
      this.getStaff()
    },
    /**
     * @desc   : 查询业务部门
     * @author : 付斌
     * @date   : 2024-02-26 14:27
     */
    getOrg() {
      this.excute(this.$service.commonService, this.$service.commonService.getOrg, {}).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-02-26 14:27
     */
    getStaff() {
      this.excute(this.$service.commonService, this.$service.commonService.getStaff, {}).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-02-20 15:53
     */
    getData(params) {
      this.tableData = [];
      this.tableDataDetail_otherReceivableItem = [];
      return this.excute(this.$service.otherReceivableService, this.$service.otherReceivableService.selectByCond, params)
    },

    /**
     * @desc   : 行改变事件
     * @author : 付斌
     * @date   : 2024-02-28 11:06
     */
    currentChange({row}) {
      this.loading = true
      this.excuteNoParam(this.$service.otherReceivableService, this.$service.otherReceivableService.selectOtherReceivableInfoById, [row.receivableId], false).then(res => {
        if (res.code === this.$config.SUCCESS_CODE) {
          this.tableDataDetail_otherReceivableItem = res.data.otherReceivableItem;
        }
        this.loading = false
      })
      this.tableDataDetail_files = row.annexPaths
    },
    /**
     * @desc   : 作废
     * @author : 付斌
     * @date   : 2024-03-05 8:56
     */
    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.otherReceivableService, this.$service.otherReceivableService.invalid, [rows[0].receivableId], 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   : 明细tab切换事件
     * @author : 付斌
     * @date   : 2023/8/31 14:58
     */
    detailTabsClick(val) {
      if (val === 'otherReceivableDetail') {
        this.visItemFlag = true
        this.visFilesDetailFlag = false
      } else if (val === 'filesDetail') {
        this.visItemFlag = false
        this.visFilesDetailFlag = true
      }
    },
    /**
     * @desc   :校验按钮
     * @author : 付斌
     * @date   : 2024-03-09 16:58
     */
    openValidData(btnName, rows) {
      if (btnName === 'edit') {
        if (rows && rows.length > 0) {
          if (rows[0].businessType === 0) {
            this.$Message.warning(this.$t('W_007', {'param': this.$t('W_121')}));
            return false;
          } else if (!rows[0].flgValid) {
            this.$Message.warning(this.$t('W_007', {'param': this.$t('W_122')}));
            return false;
          }
        }
      } else if (btnName === 'invalid') {
        if (rows && rows.length > 0) {
          if (rows[0].businessType === 0) {
            this.$Message.warning(this.$t('W_007', {'param': this.$t('W_121')}));
            return false;
          } else if (!rows[0].flgValid) {
            this.$Message.warning(this.$t('W_007', {'param': this.$t('W_122')}));
            return false;
          }
        }
      }
      return true;
    },
    /***************************设定参数函数************************************/
  },
  /**
   * @desc   : 在实例创建完成后被立即同步调用
   * @author : 付斌
   * @date   : 2022/3/3 10:32
   */
  created() {
    // console.log('this.$store.state.user.cpId',this.$store.state.user)
    this.primaryKey = 'receivableId'  // 设置主键Id
    this.routeObjName = 'otherReceivable'  // 设置路由名称
  },
}
</script>

