<!-- @desc:日结对账表  @auth:寇珊珊  @time:2024年4月26日10:03:10 -->
<template>
  <div class="main-div" ref="mainDiv">
    <!--按钮区-->
    <BaseIndexButtonGroup ref="BaseIndexButtonGroup" id="BaseIndexButtonGroup">
      <template #left>
        <!--    查询    -->
        <BaseIndexButton ref="search" name="search"></BaseIndexButton>
        <!--    清空条件    -->
        <BaseIndexButton ref="clear" name="clear"></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 :id="'table-'+$options.name"
                   ref="table-select"
                   :data="tableData"
                   primaryKey="itemId"
                   @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"
                   :height="this.tableHeight * split - 36">
            <!-- 客户名称-->
            <DkTableColumn field="cusName"></DkTableColumn>
            <!-- 客户编码-->
            <DkTableColumn field="cusCode"></DkTableColumn>
            <!-- 客户d电话-->
            <DkTableColumn field="cusPhone"></DkTableColumn>
            <!-- 业务部门-->
            <DkTableColumn field="orgName"></DkTableColumn>
            <!-- 业务员-->
            <DkTableColumn field="staffName" width="auto"></DkTableColumn>
            <!-- 订货总额-->
            <DkTableColumn field="totalOrderAmount" :sum="true" :digits="0"></DkTableColumn>
            <!-- 应收总额-->
            <DkTableColumn field="amtShould" :sum="true" :digits="0"></DkTableColumn>
            <!-- 收款总额-->
            <DkTableColumn field="amtRec" :title="$t('amtRecTotal')" :sum="true" :digits="0"></DkTableColumn>
            <!-- 账务日期-->
            <DkTableColumn field="accDate" width="auto" :dataType="$config.columnType.date"></DkTableColumn>
          </DkTable>
        </div>
        <!-- 明细-->
        <div slot="bottom">
          <DkTabs v-model="detailModel" :options="detailOptions" @on-click="detailTabsClick"></DkTabs>
          <!--订货总额-->
          <div v-show="totalOrderAmountFlag">
            <DkTable ref="orderMessage"
                     primaryKey="orderId"
                     :id="'table-'+$options.name"
                     name="table2"
                     :data="orderTableData"
                     :height="this.tableHeight * (1-split)-62"
                     :choose-flag="false"
                     @pageChange="orderPageSizeChange"
                     :page-total="orderPageInfo.total"
                     :current-page="orderPageInfo.currentPage"
                     :page-size-opts="pageSizeOpts"
                     :page-size="orderPageInfo.pageSize"
                     :select-flag="false"
                     show-footer>
              <!-- 订单单号-->
              <DkTableColumn :type="$libaray.checkButtonHasRight('sale-order-edit')?'link':''" field="orderNo"
                             @on-link="handleLink"></DkTableColumn>
              <!-- 客户名称-->
              <DkTableColumn field="cusName" :filter="false"></DkTableColumn>
              <!-- 客户电话-->
              <DkTableColumn field="cusPhone" :filter="false"></DkTableColumn>
              <!-- 客户地址-->
              <DkTableColumn field="addressFull" :filter="false"></DkTableColumn>
              <!-- 合计金额-->
              <DkTableColumn field="sumAmount" :digits="2" dataType="number" sum/>
              <!-- 订单状态-->
              <!--          <DkTableColumn field="intoStatusName" :color-cards="['入库中','已入库']"></DkTableColumn>-->
              <!-- 出库状态-->
              <DkTableColumn field="outStatusName" :color-cards="['出库中','已出库','待出库']"></DkTableColumn>
              <!-- 业务部门-->
              <DkTableColumn field="orgName" :filter="false"></DkTableColumn>
              <!--业余员-->
              <DkTableColumn field="staffName" :filter="false"></DkTableColumn>
              <!-- 账务日期-->
              <DkTableColumn field="makeTime" :dataType="$config.columnType.date"/>
            </DkTable>
          </div>
          <!--应收总额-->
          <div v-show="amtShouldFlag">
            <DkTable ref="outMessage"
                     primaryKey="outId"
                     :id="'table-'+$options.name"
                     name="table3"
                     :data="outTableData"
                     :height="this.tableHeight * (1-split)"
                     :choose-flag="false"
                     @pageChange="outPageSizeChange"
                     :page-total="outPageInfo.total"
                     :current-page="outPageInfo.currentPage"
                     :page-size-opts="pageSizeOpts"
                     :page-size="outPageInfo.pageSize"
                     :select-flag="false"
                     show-footer>
              <!-- 出库单号-->
              <DkTableColumn :type="$libaray.checkButtonHasRight('sale-order-edit')?'link':''" field="outNo"
                             @on-link="handleLink"></DkTableColumn>
              <!-- 客户名称-->
              <DkTableColumn field="cusName" :filter="false"></DkTableColumn>
              <!-- 客户电话-->
              <DkTableColumn field="cusPhone" :filter="false"></DkTableColumn>
              <!-- 客户地址-->
              <DkTableColumn field="addressFull" :filter="false"></DkTableColumn>
              <!-- 合计金额-->
              <DkTableColumn field="outAmt" :title="$t('sumAmount')" :digits="2" dataType="number" sum/>
              <!-- 订单状态-->
              <!--          <DkTableColumn field="intoStatusName" :color-cards="['入库中','已入库']"></DkTableColumn>-->
              <!-- 出库状态-->
              <DkTableColumn field="outStatusName" :color-cards="['出库中','已出库','待出库']"></DkTableColumn>
              <!-- 业务部门-->
              <DkTableColumn field="orgName" :filter="false"></DkTableColumn>
              <!--业余员-->
              <DkTableColumn field="staffName" :filter="false"></DkTableColumn>
              <!-- 账务日期-->
              <DkTableColumn field="makeTime" :dataType="$config.columnType.date"/>
            </DkTable>
          </div>
          <!--收款金额-->
          <div v-show="amtRecTotalFlag">
            <DkTable ref="payMessage"
                     primaryKey="rpId"
                     :id="'table-'+$options.name"
                     name="table4"
                     :data="payTableData"
                     :height="this.tableHeight * (1-split)"
                     :choose-flag="false"
                     @pageChange="payPageSizeChange"
                     :page-total="payPageInfo.total"
                     :current-page="payPageInfo.currentPage"
                     :page-size-opts="pageSizeOpts"
                     :page-size="payPageInfo.pageSize"
                     :select-flag="false"
                     show-footer>
              <!-- 收款单号-->
              <DkTableColumn :title="$t('receiptNo')" :type="$libaray.checkButtonHasRight('order-edit')?'link':''" field="rpNo"
                             @on-link="handleLink" ></DkTableColumn>
              <!-- 客户名称-->
              <DkTableColumn field="cusName" :filter="false"></DkTableColumn>
              <!-- 客户电话-->
              <DkTableColumn field="cusPhone" :filter="false"></DkTableColumn>
              <!-- 客户地址-->
              <DkTableColumn field="addressFull" :filter="false"></DkTableColumn>
              <!-- 收款金额-->
              <DkTableColumn field="sumAmtRec" :digits="2" dataType="number" sum/>
              <!-- 业务部门-->
              <DkTableColumn field="orgName" :filter="false"></DkTableColumn>
              <!--业余员-->
              <DkTableColumn field="staffName" :filter="false"></DkTableColumn>
              <!-- 账务日期-->
              <DkTableColumn field="makeTime" :dataType="$config.columnType.date"/>
            </DkTable>
          </div>
        </div>
      </DkSplit>
    </div>
  </div>
</template>

<script>
  import {indexMixin} from '@/mixins'
  export default {
    name: 'daily-check-report',
    mixins: [indexMixin],
    data() {
      let self = this
      return {
        //明细模式切换值
        detailModel: 'totalOrderAmount',
        detailOptions: [
          {label: self.$t('totalOrderAmount'), name: 'totalOrderAmount'}, //订货总额
          {label: self.$t('amtShould'), name: 'amtShould'},//应收总额
          {label: self.$t('amtRecTotal'), name: 'amtRecTotal'},//收款总额
        ],
        totalOrderAmountFlag: true, //订货总额
        amtShouldFlag: false,//应收总额
        amtRecTotalFlag: false,//收款总额
        tableData: [], //总单数据
        orderTableData: [],//订货总额数据
        outTableData: [],//应收总额数据
        payTableData: [],//收款总额数据
        //查询条件
        searchContent: [
          {
            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: 'accDate',
            valueFormat: {
              code: 'accDate',
              default: [new Date().addMonths(-1).format('yyyy-MM-dd'), new Date().format('yyyy-MM-dd')]
            },
            valueKind: 'DATE_RANGE'
          },
        ],
        //订货总额分页
        orderPageInfo: {
          pageSize: 10,
          currentPage: 1,
          total: 0
        },
        //应收总额分页
        outPageInfo: {
          pageSize: 10,
          currentPage: 1,
          total: 0
        },
        //收款总额分页
        payPageInfo: {
          pageSize: 10,
          currentPage: 1,
          total: 0
        },
      }
    },
    methods: {
      /**
       *   @desc   : 初始化查询
       *   @date   : 2024/4/26 14:59
       *   @author : 寇珊珊
       */
      initData() {
        //查询业务部门
        this.getOrg()
        //查询业务员
        this.getStaff()
      },
      /**
       *   @desc   : 查询业务部门
       *   @date   : 2024/4/26 14:20
       *   @author : 寇珊珊
       */
      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   : 查询业务员
       *   @date   : 2024/4/26 14:20
       *   @author : 寇珊珊
       */
      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   : 订货总额分页
       *   @date   : 2024/4/26 14:59
       *   @author : 寇珊珊
       */
      orderPageSizeChange(pageInfo) {
        this.orderPageInfo = pageInfo
        this.getDetail()
      },
      /**
       *   @desc   : 应收总额分页
       *   @date   : 2024/4/26 14:59
       *   @author : 寇珊珊
       */
      outPageSizeChange(pageInfo) {
        this.outPageInfo = pageInfo
        this.getDetail()
      },
      /**
       *   @desc   : 收款总额分页
       *   @date   : 2024/4/26 14:59
       *   @author : 寇珊珊
       */
      payPageSizeChange(pageInfo) {
        this.payPageInfo = pageInfo
        this.getDetail()
      },
      /**
       *   @desc   : 获取数据
       *   @date   : 2024/3/12 16:19
       *   @author : 寇珊珊
       */
      getData(params) {
        //入库类型
        this.tableData = []
        this.orderTableData = []
        this.outTableData = []
        this.payTableData = []
        let excute = this.excute(this.$service.detailReportService, this.$service.detailReportService.getDailyReconciliationReport, params)
        excute.then(res => {
          if (res.code === this.$config.SUCCESS_CODE) {
            this.tableData = res.data.list
            if (this.tableData.length == 0) {
              this.orderTableData = []
              this.outTableData = []
              this.payTableData = []
            }
          }
        })
        return excute;
      },
      /**
       *   @desc   : 明细赋值查询条件
       *   @date   : 2024/4/26 16:37
       *   @author : 寇珊珊
       */
      setDetailParams(params){
        if(this.searchParams &&this.searchParams.accDateStart){
          params.accDateStart = this.searchParams.accDateStart
        }
        if(this.searchParams &&this.searchParams.accDateEnd){
          params.accDateEnd = this.searchParams.accDateEnd
        }
        if(this.searchParams &&this.searchParams.cusName){
          params.cusName = this.searchParams.cusName
        }
        if(this.searchParams &&this.searchParams.cusPhone){
          params.cusPhone = this.searchParams.cusPhone
        }
        if(this.searchParams && this.searchParams.orgIdList && this.searchParams.orgIdList.length>0){
          params.orgIdList = this.searchParams.orgIdList
        }
        if(this.searchParams && this.searchParams.staffIdList && this.searchParams.staffIdList.length>0){
          params.staffIdList = this.searchParams.staffIdList
        }
        return  params
      },
      /**
       *   @desc   : 行改变事件
       *   @date   : 2024/3/9 15:35
       *   @author : 寇珊珊
       */
      currentChange({row}) {
        this.loading = true
        let params = {
          currentPage: this.orderPageInfo.currentPage,
          pageSize: this.orderPageInfo.pageSize,
        }
        //明细赋值查询条件
        params = this.setDetailParams(params)
        let excute = this.excute(this.$service.detailReportService, this.$service.detailReportService.getDailyReconciliationReportByOrder, params)
        this.loading = false
        excute.then(res => {
          if (res.code === this.$config.SUCCESS_CODE) {
            this.orderTableData = res.data.list
            this.orderPageInfo.total = res.data.total
          }
        })
        return excute;
      },
      /**
       *   @desc   : 明细点击Tab进行切换
       *   @date   : 2024/3/12 14:03
       *   @author : 寇珊珊
       */
      detailTabsClick(val) {
        //订货总额
        if (val == 'totalOrderAmount') {
          this.totalOrderAmountFlag = true
          this.amtShouldFlag = false
          this.amtRecTotalFlag = false
          this.getDetail(val)
        }
        //应收总额
        else if (val == 'amtShould') {
          this.totalOrderAmountFlag = false
          this.amtShouldFlag = true
          this.amtRecTotalFlag = false
          this.getDetail(val)
        }
        //收款总额
        else if (val == 'amtRecTotal') {
          this.totalOrderAmountFlag = false
          this.amtShouldFlag = false
          this.amtRecTotalFlag = true
          this.getDetail(val)
        }
      },
      /**
       *   @desc   : 获取明细
       *   @date   : 2024/3/12 14:06
       *   @author : 寇珊珊
       */
      getDetail(val) {
        this.detailModel = val
        //订货总额
        if (val == 'totalOrderAmount') {
          this.loading = true
          let params = {
            currentPage: this.orderPageInfo.currentPage,
            pageSize: this.orderPageInfo.pageSize,
          }
          //明细赋值查询条件
          params = this.setDetailParams(params)
          let excute = this.excute(this.$service.detailReportService, this.$service.detailReportService.getDailyReconciliationReportByOrder, params)
          excute.then(res => {
            if (res.code === this.$config.SUCCESS_CODE) {
              this.orderTableData = res.data.list
              this.orderPageInfo.total = res.data.total
            }
          })
          return excute;
        }
        //应收总额
        else if (val == 'amtShould') {
          this.loading = true
          let params = {
            currentPage: this.outPageInfo.currentPage,
            pageSize: this.outPageInfo.pageSize,
          }
          //明细赋值查询条件
          params = this.setDetailParams(params)
          let excute = this.excute(this.$service.detailReportService, this.$service.detailReportService.getDailyReconciliationReportByOut, params)
          excute.then(res => {
            if (res.code === this.$config.SUCCESS_CODE) {
              this.outTableData = res.data.list
              this.outPageInfo.total = res.data.total
            }
          })
          return excute;
        }
        //收款金额
        else if (val == 'amtRecTotal') {
          this.loading = true
          let params = {
            currentPage: this.payPageInfo.currentPage,
            pageSize: this.payPageInfo.pageSize,
          }
          //明细赋值查询条件
          params = this.setDetailParams(params)
          let excute = this.excute(this.$service.detailReportService, this.$service.detailReportService.getDailyReconciliationReportByPay, params)
          excute.then(res => {
            if (res.code === this.$config.SUCCESS_CODE) {
              this.payTableData = res.data.list
              this.payPageInfo.total = res.data.total
            }
          })
          return excute;
        }
      },
    },
    created() {
      this.primaryKey = 'itemId'  // 设置主键Id
      this.routeObjName = 'detailReport'  // 设置路由名称
    }
  }
</script>

<style scoped>

</style>
