<!-- @desc:资金日记账  @auth:常皓宁  @time:2024/4/26 15:15 -->
<template>
  <div class="main-div">
    <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>
      <!--  表格部分  -->
      <div slot="top">
        <DkTabs v-model="detailModel" :options="detailOptions" @on-click="detailTabsClick"></DkTabs>
        <!--  表格部分  -->
        <div v-show="isMacFlag">
        <DkTable :data="tableData"
                 :page-flag="true"
                 :page-total-flag="true"
                 :height="tableHeight-30"
                 primaryKey="itemId"
                 :pageFlag="true"
                 @pageChange="pageSizeChange"
                 :page-total="pageInfo.total"
                 :current-page="pageInfo.currentPage"
                 ref="table-select"
                 :sortable="false"
                 :showCheckboxHeader="false"
                 :choose-flag="false">
          <DkTableColumn field="macName" :title="$t('macname')"></DkTableColumn>
          <DkTableColumn field="initAmt" :digits="2" dataType="number"></DkTableColumn>
          <DkTableColumn field="amtInflow" :digits="2" dataType="number"></DkTableColumn>
          <DkTableColumn field="balance" :title="$t('amtBalance')" :digits="2" dataType="number"></DkTableColumn>
          <DkTableColumn field="cusName" :tree-node="true"></DkTableColumn>
          <DkTableColumn field="cusPhone" :tree-node="true"></DkTableColumn>
          <DkTableColumn field="accDate" :title="$t('accDate')"/>
          <DkTableColumn field="amtRes" dataType="number" :digits="2" type="link" @on-link="currentIntoRights()"
                         sum/>
        </DkTable>
      </div>
        <div v-show="isMacDetailFlag">
          <DkTable :id="'table-'+$options.name" ref="detail-select" :data="macDetailData" showFooter
                   :height="this.tableHeight -35"
                   primaryKey="invId"
                   @pageChange="pageSizeChange"
                   :page-total="pageInfo.total"
                   :current-page="pageInfo.currentPage"
                   :choose-flag="false"
                   :page-size-opts="pageSizeOpts"
                   :page-size="pageInfo.pageSize"
                   name="table">
            <DkTableColumn field="macName" :title="$t('macname')"></DkTableColumn>
            <DkTableColumn field="accDate" :title="$t('accDate')"/>
            <DkTableColumn field="amtRec" dataType="number" :digits="2"/>
            <DkTableColumn field="makeTime" data-type="dateTime"/>
            <DkTableColumn field="remarks"/>
          </DkTable>
        </div>
      </div>
    </div>
  </div>
</template>

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

export default {
  name: 'supplier-account-report',
  mixins: [indexMixin],
  data() {
    let self = this
    return {
      detailModel: 'macCusDetail',
      detailOptions: [
        {label: self.$t('macCusDetail'), name: 'macCusDetail'}, //资金日记账
        {label: self.$t('macRpDetail'), name: 'macRpDetail'}, //账款详情
      ],
      tableData: [],         // 资金账户
      macDetailData: [],    // 账款明细
      isMacFlag: true,
      isMacDetailFlag: false,
      searchContent: [
        {
          itemCode: '资金账户-下拉',
          itemName: 'macname',
          valueFormat: {
            code: 'macIds',
            data: [],
            valueKey: 'macId',
            labelKey: 'macName',
          },
          required: true,
          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'
        },
      ],
    }
  },
  methods: {
    /**
     * @desc   : 加载数据
     * @author : 姜宁
     * @date   : 2024/7/19 16:10
     */
    initData() {
      this.getMacData();
    },
    /**
     * @desc   : 查询数据
     * @author : 常皓宁
     * @date   : 2024/4/25 13:09
     */
    getData(params) {
      // 清空数据
      this.tableData = [];
      this.macDetailData = [];
      // 自动显示收发存数据
      this.detailModel = 'macCusDetail'
      this.isMacFlag = true
      this.isMacDetailFlag = false
      params.cpId = this.$store.state.user.cpId
      return this.excute(this.$service.detailReportService, this.$service.detailReportService.getFundReportWeb, params)
    },

    /**
     * @desc   : 点击Tab进行切换
     * @author : 姜宁
     * @date   : 2024/7/19 16:40
     */
    detailTabsClick(val) {
      if (val === 'macCusDetail') {
        this.detailModel = val
        this.isMacFlag = true
        this.isMacDetailFlag = false
      } else if (val === 'macRpDetail' && this.macDetailData.length > 0) {
        this.detailModel = val
        this.isMacFlag = false
        this.isMacDetailFlag = true
      }
    },

    /**
     * @desc   : 获取资金账户
     * @author : 姜宁
     * @date   : 2024/7/19 16:08
     */
    getMacData() {
      let params = {
        'dictCode': this.$config.kindCode.basicIncome,
      }
      this.excute(this.$service.commonService, this.$service.commonService.getMac, params, false).then(res => {
        if (res.code === this.$config.SUCCESS_CODE) {
          let list = this.searchContent.filter(it =>  it.valueFormat && it.valueFormat.code == 'macIds')
          if (list.length > 0) {
            list[0].valueFormat.data = res.data
          }
        }
      })
    },
    /**
     * @desc   : 获取发生明细
     * @author : 姜宁
     * @date   : 2024/7/19 16:16
     */
    currentIntoRights(row) {
      this.macDetailData = [];
      if (!row) {
        row = [this.$refs['table-select'].getCurrentRow()]
      }
      this.excuteNoParam(this.$service.paymentService, this.$service.paymentService.selectRpInfoById, [row[0].rpId], false).then(res => {
        if (res.code === this.$config.SUCCESS_CODE) {
          // 显示入库明细信息页面
          this.detailModel = 'macRpDetail'
          this.isMacFlag = false
          this.isMacDetailFlag = true
          this.macDetailData = res.data.recPayItem;
          // this.tableDataDetail_rpItem = res.data.recPayItem;
          // this.tableDataDetail_recPayHandleItem = res.data.recPayHandleItem;
        }
        this.loading = false
      })
    },
  },
  created() {
    this.primaryKey = 'itemId'  // 设置主键Id
    this.routeObjName = 'detailReport'  // 设置路由名称
  }
}
</script>

<style scoped>

</style>
