<!-- @desc:客户收款  @auth:常皓宁  @time:2024/2/21 14:06 -->
<template>
  <div class="main-div" ref="mainDiv">
    <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="receipt" name="receipt" :isMustChooseFlag="false"></BaseIndexButton>
        <BaseIndexButton ref="refund" name="refund" :isMustChooseFlag="false"></BaseIndexButton>
        <BaseIndexButton ref="edit" name="edit"></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="rpId"
                   @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="rpNo" :title="$t('receiptNo')"
                           :type="$libaray.checkButtonHasRight('cus-receipt-edit')?'link':''" @on-link="handleLink"/>
            <DkTableColumn field="biznisNo"/>
            <DkTableColumn field="rpTypeName" :title="$t('receiptTypeName')"/>
            <DkTableColumn field="cusName"/>
            <DkTableColumn field="cusPhone"/>
            <DkTableColumn field="addressFull"/>
            <DkTableColumn field="sumAmtRec" :digits="2" dataType="number" sum/>
            <DkTableColumn field="accDate" :title="$t('receiptDate')"/>
            <DkTableColumn field="orgName"/>
            <DkTableColumn field="staffName"/>
            <DkTableColumn field="makeStaffName"/>
            <DkTableColumn field="makeTime" data-type="dateTime"/>
            <DkTableColumn field="remarks"/>
          </DkTable>
        </div>
        <div slot="bottom">
          <DkTabs v-model="detailModel" :options="detailOptions" @on-click="detailTabsClick"></DkTabs>
          <div v-show="visRpItemFlag">
            <DkTable :id="'table-'+$options.name" ref="detail-select" :data="tableDataDetail_rpItem" showFooter
                     :height="this.tableHeight * (1-split)-62" primaryKey="itemId" name="table">
              <DkTableColumn field="macName"/>
              <DkTableColumn field="amtRec" :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)-62">
              <DkTableColumn field="name" :title="$t('fileName')"/>
              <DkTableColumn field="path" :imageUrl="$config.imgUrl" type="image" :title="$t('yuLan')"/>
            </DkTable>
          </div>
        </div>
      </DkSplit>
    </div>
  </div>
</template>

<script>
import {indexMixin} from "@/mixins";

export default {
  name: 'cus-receipt',
  mixins: [indexMixin],
  data() {
    let self = this
    return {
      tableData: null,
      tableDataDetail_rpItem: null,
      tableDataDetail_files: null,
      detailModel: 'collectionDetail',
      detailOptions: [
        {label: self.$t('collectionDetail'), name: 'collectionDetail'},//收款明细
        {label: this.$t('filesDetail'), name: 'filesDetail'}
      ],
      visRpItemFlag: true,
      visFilesDetailFlag: false,
      searchContent: [
        {
          itemCode: '收款单号-文本',
          itemName: 'receiptNo',
          valueFormat: {code: 'receiptNo'},
          valueKind: 'STR'
        },
        {
          itemCode: '客户名称-文本',
          itemName: 'cusName',
          valueFormat: {code: 'cusName'},
          valueKind: 'STR'
        },
        {
          itemCode: '客户电话-文本',
          itemName: 'cusPhone',
          valueFormat: {code: 'cusPhone'},
          valueKind: 'STR'
        },
        {
          itemCode: '详细地址-文本',
          itemName: 'addressFull',
          valueFormat: {code: 'addressFull'},
          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: 'receiptType',
          valueFormat: {
            code: 'receiptTypeList',
            data: [
              {receiptType: '收款类型-收款', receiptTypeName: '收款'},
              {receiptType: '收款类型-退款', receiptTypeName: '退款'}],
            valueKey: 'receiptType',
            labelKey: 'receiptTypeName',
            default: []
          },
          valueKind: 'M-CHOICE'
        },
        {
          itemCode: '资金账户-文本',
          itemName: 'receiptMac',
          valueFormat: {
            code: 'receiptMacList',
            data: [],
            valueKey: 'macId',
            labelKey: 'macName',
          },
          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,
        },
      ],
    }
  },
  methods: {
    /**
     * @desc   : 加载数据
     * @author : 付斌
     * @date   : 2024-02-20 15:53
     */
    initData() {
      //查询业务部门
      this.getOrg()
      //查询业务员
      this.getStaff()
      // //查询资金账户
      // this.getMac()
    },
    /**
     * @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-26 14:27
    //  */
    // getMac() {
    //   this.excute(this.$service.commonService, this.$service.commonService.getMac, {}).then(res => {
    //     if (res.code === this.$config.SUCCESS_CODE) {
    //       let list = this.searchContent.filter(it => it.valueFormat.code == 'receiptMacList')
    //       if (list.length > 0) {
    //         list[0].valueFormat.data = res.data
    //       }
    //     }
    //   })
    // },
    /**
     * @desc   : 查询数据
     * @author : 付斌
     * @date   : 2024-02-20 15:53
     */
    getData(params) {
      this.tableData = null;
      this.tableDataDetail_rpItem = null;
      return this.excute(this.$service.cusReceiptService, this.$service.cusReceiptService.selectByCond, params)
    },
    /**
     * @desc   : 行改变事件
     * @author : 付斌
     * @date   : 2024-02-28 11:06
     */
    currentChange({row}) {
      this.loading = true
      this.tableDataDetail_rpItem = null;
      this.excuteNoParam(this.$service.cusReceiptService, this.$service.cusReceiptService.selectRpInfoById, [row.rpId], false).then(res => {
        if (res.code === this.$config.SUCCESS_CODE) {
          this.tableDataDetail_rpItem = res.data.recPayItem;
        }
        this.loading = false
      })
      this.tableDataDetail_files = row.annexPaths
    },
    /**
     * @desc   : 明细tab切换事件
     * @author : 付斌
     * @date   : 2023/8/31 14:58
     */
    detailTabsClick(val) {
      if (val === 'collectionDetail') {
        this.visRpItemFlag = true
        this.visFilesDetailFlag = false
      } else if (val === 'filesDetail') {
        this.visRpItemFlag = 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].biznisId) {
            this.$Message.warning(this.$t('W_007', {'param': this.$t('W_124')}));
            return false;
          }
        }
      }
      return true;
    },
  },
  /**
   * @desc   : 在实例创建完成后被立即同步调用
   * @author : 付斌
   * @date   : 2022/3/3 10:32
   */
  created() {
    this.primaryKey = 'rpId'  // 设置主键Id
    this.routeObjName = 'cusReceipt'  // 设置路由名称
  },
}
</script>

<style scoped>

</style>
