<!-- @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="edit" name="edit"></BaseIndexButton>
        <!--    启用    -->
        <BaseIndexButton ref="enable" name="enable"></BaseIndexButton>
        <!--    停用    -->
        <BaseIndexButton ref="disable" name="disable"></BaseIndexButton>
      </template>
      <template #right>
        <!--   新建     -->
        <BaseIndexButton ref="add" name="add"></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">
        <DkTable :id="'table-'+$options.name" ref="table-select" :data="tableData"
                 :pageFlag=true @pageChange="pageSizeChange"
                 @current-change="selectChangeTable"
                 :height="this.tableHeight * split - 35" primaryKey="receiptId"
                 :tree-flag="false"
                 name="table">
          <DkTableColumn type="radio" width="60" min-width="60"></DkTableColumn>
          <DkTableColumn :type="$libaray.checkButtonHasRight('receipt-detail')?'link':''" field="receiptNo"
                         @on-link="openDetail"  :treeNode="true" :filter=false></DkTableColumn>
          <DkTableColumn :type="$libaray.checkButtonHasRight('order-edit')?'link':''" field="orderNo"  :filter=false
                         @on-link="openEdit"></DkTableColumn>
          <DkTableColumn field="apvResultTime" :filter=false
                         :title="$t('approvalTime')"></DkTableColumn>
          <!--单据类型-->
          <DkTableColumn field="docCode" :title="$t('receiptDocCode')"
                         :filter=false></DkTableColumn>
          <!--结算方式-->
          <DkTableColumn field="settlementTypeName" :title="$t('settlementTypesName')"
                         :filter=false></DkTableColumn>
          <DkTableColumn field="erpDocNo"></DkTableColumn>
          <DkTableColumn :type="$libaray.checkButtonHasRight('customer-detail')?'link':''" field="customerName"
                         @on-link="openCustomerMessage"></DkTableColumn>
          <DkTableColumn field="customerPhone" :filter=false></DkTableColumn>
          <DkTableColumn field="addressFull" :filter=false></DkTableColumn>
          <DkTableColumn field="staffName" :title="$t('staffId')"
                         :filter=false></DkTableColumn>
          <DkTableColumn field="orgName" :title="$t('orgId')"
                         :filter=false></DkTableColumn>
          <DkTableColumn field="sumAmount" :filter=false></DkTableColumn>
          <!--可用余额-->
          <DkTableColumn field="balanceAmount" :filter=false></DkTableColumn>
          <!--当前审批人-->
          <DkTableColumn field="apvUserIds" :title="$t('apvUserIds')"
                         :filter=false></DkTableColumn>
          <!--审批结果-->
          <DkTableColumn field="apvResult" :filter=false></DkTableColumn>
          <!--原单号-->
          <DkTableColumn field="sreceiptNo" :filter=false></DkTableColumn>
          <!--退款账号-->
          <DkTableColumn field="refundAccount" :filter=false></DkTableColumn>
          <!--退款方式-->
          <DkTableColumn field="refundMethod" :filter=false></DkTableColumn>
          <!--退款原因-->
          <DkTableColumn field="refundReason" :filter=false></DkTableColumn>
          <!--备注-->
          <DkTableColumn field="remarks" :filter=false></DkTableColumn>
          <!--推送状态-->
          <DkTableColumn field="erpPushStatusString" :title="$t('erpPushStatus')"
                         :filter=false></DkTableColumn>
          <!--推送结果-->
          <DkTableColumn field="erpPushResult"></DkTableColumn>
          <!--制单人-->
          <DkTableColumn :title="$t('makingUser')" field="makingUserName"></DkTableColumn>
          <!--制单时间-->
          <DkTableColumn :title="$t('makingData')" field="makingTime"
                         data-type="date"></DkTableColumn>
          <vxe-column :title="$t('files')" field="measureAnnexCount">
            <template #default="{row}">
              <a @click="showFiles(row)">{{ row.measureAnnexCount }}</a>
            </template>
          </vxe-column>
        </DkTable>
      </div>
      <div slot="bottom">
        <DkTabs v-model="detailModel" :options="detailOptions"></DkTabs>
<!--        &lt;!&ndash;审批明细&ndash;&gt;-->
<!--          <ApprovalDetailTable :tableHeight="this.tableHeight * (1-split)" :search-data-flag="searchApprovalflag" :data-id="pryKey"-->
<!--                               :doc-code="approvalValue" @approval-data="approvalData"/>-->
        <!--附件-->
          <DkTable :pageFlag="false" :pageTotalFlag="false" :id="'table-'+$options.name"
                   name="table" ref="file-select" :data="tableDataDetail_files" :height="this.tableHeight * (1-split)">
            <DkTableColumn field="docType"></DkTableColumn>
            <DkTableColumn field="name" :title="$t('fileName')"></DkTableColumn>
            <vxe-column field="createTime" :title="$t('uploadTime')"></vxe-column>
            <vxe-column :title="$t('picture')" class-name="img-column">
              <template #default="{row}">
                <img :src="$config.imgUrl + row.url" v-if="row.type == 'img' || row.type == 'image'"
                     style="width: 100px; height: 100px; cursor: pointer;"
                     @click="openFile(row)"/>
              </template>
            </vxe-column>
            <vxe-column>
              <template #default="{row}">
                <DkButton @click="openFile(row)">
                  <Icon type="md-download"/>
                </DkButton>
              </template>
            </vxe-column>
          </DkTable>
      </div>
    </DkSplit>
  </div>
</template>

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

export default {
  name: 'receipt',
  mixins:[indexMixin],
  data(){
    let self = this
    return{
      //审批
      approvalValue: self.$config.docCode.customerCollection,
      pryKey:null,
      searchApprovalflag: false,
      //明细
      detailModel: 'approvalDetail',
      detailOptions: [
        {label: self.$t('approvalDetail'), name: 'approvalDetail'}, //审批明细
        {label: self.$t('filesDetail'), name: 'filesDetail'}, //附件明细
      ],
      tableData: [],
      //附件
      tableDataDetail_files: [],  // 用于存放订单附件
      searchContent: [
        {
          itemCode: '客户电话-文本',
          itemName: 'customerPhone',
          valueFormat: {code: 'customerPhone'},
          valueKind: 'STR'
        },
        {
          itemCode: '客户名称-文本',
          itemName: 'customerName',
          valueFormat: {code: 'customerName'},
          valueKind: 'STR'
        },
        {
          itemCode: '业务部门-文本',
          itemName: 'orgId',
          valueFormat: {
            code: 'orgId',
            data: self.orgList,
            valueKey: 'orgId',
            labelKey: 'orgName',
          },
          valueKind: 'M-CHOICE'
        },
        {
          itemCode: '业务员-文本',
          itemName: 'staffId',
          valueFormat: {
            code: 'staffId',
            data: self.staffList,
            valueKey: 'userId',
            labelKey: 'userName',
          },
          valueKind: 'M-CHOICE'
        },
        {
          itemCode: '收款单-文本',
          itemName: '收款单号',
          valueFormat: {code: 'receiptNo'},
          valueKind: 'STR'
        },
        {
          itemCode: '订单单号-文本',
          itemName: 'orderNo',
          valueFormat: {code: 'orderNo'},
          valueKind: 'STR'
        },
        {
          itemCode: '小区名称-文本',
          itemName: 'addressName',
          valueFormat: {code: 'addressName'},
          valueKind: 'STR'
        },
        {
          itemCode: '详细地址-文本',
          itemName: 'addressFull',
          valueFormat: {code: 'addressFull'},
          valueKind: 'STR'
        },
        {
          itemCode: '结算方式-文本',
          itemName: 'typeName',
          valueFormat: {
            code: 'settlementTypeSearchList',
            data: self.settlementTypeSearchList,
            valueKey: 'typeId',
            labelKey: 'typeName',
          },
          valueKind: 'M-CHOICE'
        },
        {
          itemCode: '制单日期-时间',
          itemName: 'makingTime',
          valueFormat: {code: 'opCreateTime', default: [new Date().addMonths(-1).format('yyyy-MM-dd'), new Date().format('yyyy-MM-dd')]},
          valueKind: 'DATE_RANGE',
          required:true,
        },
        {
          itemCode: '单据类型-下拉',
          itemName: 'receiptDocCode',
          valueFormat: {
            code: 'docCodeList',
            data: [
              {valueKey: '客户收款', flgValid: '客户收款'},
              {valueKey: '客户取款', flgValid: '客户取款'},
              {valueKey: '使用收款', flgValid: '使用收款'}],
            valueKey: 'valueKey',
            labelKey: 'flgValid',
            default: [ '客户收款','客户取款'
            ]
          },
          valueKind: 'M-CHOICE'
        },
      ],
    }
  },
  methods:{
    /**
     * @desc   : 打开明细
     * @author : 周兴
     * @date   : 2022/8/31 8:46
     */
    openDetail(row) {
      this.$router.push('/sale/receipt/receipt-detail?receiptId=' + row.receiptId)
    },

    /**
     * @desc   : 进入编辑页面
     * @author : 周兴
     * @date   : 2022/8/9 10:29
     */
    openEdit(row) {
      this.$router.push('/sale/order/edit/' + row.orderId)
    },

    /**
     *   @desc   : 进入客户页面
     *   @date   : 2022/5/31 15:38
     *   @author : 寇珊珊
     */
    openCustomerMessage(row) {
      this.$router.push('/sale/customer/detail/' + row['customerId'])
    },

    /**
     *   @desc   : 总单行点击事件
     *   @date   : 2022/9/13 11:24
     *   @author : 寇珊珊
     */
    selectChangeTable(e) {
      //定义一个页面id 用于调用审批使用
      //退款单
      if (e && e.row && e.row.refundId) {
        this.pryKey = e.row.refundId
        this.approvalValue= this.$config.docCode.orderRefund
        // 查询审批明细
        this.searchApprovalflag = true;
      }
      //收款单
      else if (e && e.row && e.row.receiptId) {
        this.pryKey = e.row.receiptId
        this.approvalValue= this.$config.docCode.customerCollection
        // 查询审批明细
        this.searchApprovalflag = true;
      }
      setTimeout(() => {
        this.searchApprovalflag = false;
      }, 100)
      if (e && e.row && e.row.receiptId && e.row.docCode != '销售退款') {
        this.receiptId = e.row.receiptId
        //订单附件
        this.tableDataDetail_files = e.row.annexPaths
      }
    },
  },
}
</script>

<style scoped>

</style>
