<!-- @desc:供应商往来账查询  @auth:宋扬  @time:2024-05-09 16:28 -->
<template>
  <div class="main-div" ref="mainDiv">
    <!--加载中-->
    <loading :loading="loading" v-if="!modalVisible"></loading>
    <BaseIndexButtonGroup id="BaseIndexButtonGroup">
      <template #left>
        <!--    查询    -->
        <BaseIndexButton right-button="user-select" 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="bottom">
        <DkTabs v-model="detailModel" :options="detailOptions" @on-click="detailTabsClick"></DkTabs>
        <div v-show="visSupplierFlag">
          <DkTable :id="'table-'+$options.name"
                   ref="table-select"
                   :data="tableData"
                   showFooter
                   :height="this.tableHeight-60"
                   primaryKey="objectId"
                   @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="supCode" />
            <DkTableColumn field="supName"/>
            <DkTableColumn field="contactPhone"/>
            <DkTableColumn field="contactName"/>
            <DkTableColumn field="orgName" />
            <DkTableColumn field="payOpening"dataType="number" :sum="true" />
            <DkTableColumn field="payHandleOpening"dataType="number" :sum="true" />
            <DkTableColumn field="payCurrent" dataType="number" type="link" @on-link="currentPayRights()" :sum="true"></DkTableColumn>
            <DkTableColumn field="payHandleCurrent" dataType="number" type="link" @on-link="currentHandleRights()" :sum="true"></DkTableColumn>
            <DkTableColumn field="payEnding"dataType="number" :sum="true" />
            <DkTableColumn field="payHandleEnding"dataType="number" :sum="true" />
          </DkTable>
        </div>
        <div v-show="visSupPayFlag">
          <DkTable :id="'table-'+$options.name" ref="detail-select" :data="payDetailData" showFooter
                   :height="this.tableHeight-35"
                   primaryKey="objectId"
                   @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="supName"/>
            <DkTableColumn field="contactPhone"/>
            <DkTableColumn field="contactName" />
            <DkTableColumn field="orgName" />
            <DkTableColumn field="accDate" width="auto" :dataType="$config.columnType.date"/>
            <!-- 来源类型-->
            <DkTableColumn field="biznistypename" :title="$t('biznisTypeName')"/>
            <!-- 来源单号-->
            <DkTableColumn field="biznisNo" />
            <!-- 应付金额-->
            <DkTableColumn field="amtPay" :sum="true" dataType="number" ></DkTableColumn>
            <!-- 核销金额-->
            <DkTableColumn field="amtHandle" :sum="true" dataType="number"></DkTableColumn>
            <!--制单人-->
            <DkTableColumn field="makestaffname" :title="$t('makeStaffName')"></DkTableColumn>
          </DkTable>
        </div>
        <div v-show="visSupPayHandleFlag">
          <DkTable :id="'table-'+$options.name" ref="detail-select" :data="handleDetailData" showFooter
                   :height="this.tableHeight -35"
                   primaryKey="objectId"
                   @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="supName"/>
            <DkTableColumn field="contactPhone"/>
            <DkTableColumn field="contactName" />
            <DkTableColumn field="orgName" />
            <DkTableColumn field="accDate" width="auto" :dataType="$config.columnType.date"/>
            <!-- 来源类型-->
            <DkTableColumn field="biznistypename" :title="$t('biznisTypeName')"/>
            <!-- 来源单号-->
            <DkTableColumn field="biznisNo" />
            <!-- 应收金额-->
            <DkTableColumn field="amtShould" :sum="true" dataType="number" ></DkTableColumn>
            <!-- 核销金额-->
            <DkTableColumn field="amtHandle" :sum="true" dataType="number"></DkTableColumn>
            <!-- 剩余金额-->
            <DkTableColumn field="amtResidue" :sum="true" dataType="number"></DkTableColumn>
            <!-- 优惠金额-->
            <DkTableColumn field="amtWaive" :sum="true" dataType="number"></DkTableColumn>
            <!--制单人-->
            <DkTableColumn field="makestaffname" :title="$t('makeStaffName')"></DkTableColumn>
          </DkTable>
        </div>
      </div>
    </div>

  </div>
</template>

<script>
import {indexMixin} from '@/mixins'
import Config from "@/config";
export default {
  name: "supplier-current-account-report",
  mixins: [indexMixin],
  data() {
    let self = this
    return {
      detailModel: 'paySupDetail',
      detailOptions: [
        {label: self.$t('paySupDetail'), name: 'paySupDetail'}, //供应商账款
        {label: self.$t('payDetail'), name: 'payDetail'}, //预付明细
        {label: self.$t('payHandle'), name: 'handleDetail'}, //应付明细
      ],
      tableData:[],           // 供应商账款
      payDetailData:[],       // 预付明细
      handleDetailData: [],   // 应付明细
      visSupplierFlag: true,
      visSupPayHandleFlag: false,
      visSupPayFlag: false,
      searchContent:
        [
          {
            itemCode: 'supName',
          },
          {
            itemCode: 'accDate',
            valueFormat: {
              code: 'accDate',
              default: [new Date().addMonths(-1).format('yyyy-MM-dd'), new Date().format('yyyy-MM-dd')]
            },
            valueKind: 'DATE_RANGE',
          },
          {
            itemCode: 'isOrgFlag',
            valueFormat: {code: 'isOrgFlag', default: false},
            valueKind: 'SWITCH'
          },
          {
            itemCode: 'isNoCurrentFilter',
            valueFormat: {code: 'isNoCurrentFilter', default: false},
            valueKind: 'SWITCH'
          },
        ],
    }
  },
  methods: {
    /**
     * @desc   : 查询数据
     * @author : 宋扬
     * @date   : 2024/3/13 10:42
     */
    getData(params) {
      // 清空数据
      this.tableData = [];
      this.payDetailData = [];
      this.handleDetailData = [];
      // 自动显示收发存数据
      this.visSupplierFlag = true
      this.visSupPayHandleFlag = false
      this.visSupRecFlag = false
      this.detailModel = 'paySupDetail'
      return this.excute(this.$service.detailReportService, this.$service.detailReportService.getMacPayCurrentReport, params)
    },

    /**
     * @desc   : 点击Tab进行切换
     * @author : 宋扬
     * @date   : 2024/4/3 16:24
     */
    detailTabsClick(val) {
      if (val === 'paySupDetail') {
        this.detailModel = val
        this.visSupplierFlag = true
        this.visSupPayHandleFlag = false
        this.visSupPayFlag = false
      } else if (val === 'payDetail' && this.payDetailData.length > 0) {
        this.detailModel = val
        this.visSupplierFlag = false
        this.visSupPayHandleFlag = false
        this.visSupPayFlag = true
      }else if (val === 'handleDetail' && this.handleDetailData .length > 0) {
        this.detailModel = val
        this.visSupplierFlag = false
        this.visSupPayHandleFlag = true
        this.visSupPayFlag = false
      }
    },
    /**
     * @desc   : 赋值查询条件
     * @author : 宋扬
     * @date   : 2024/4/23 10:44
     */
    setSearchParams(params){
      // 赋值JSON查询条件
      let skuquerys = {}
      if(this.searchCond && this.searchCond._value){
        Object.assign(skuquerys,this.searchCond._value)
      }
      let skuQuerystr = JSON.stringify(skuquerys);
      if(skuQuerystr && skuQuerystr !='{}'){
        params['querys']= skuQuerystr;
      }
      return params;
    },

    /**
     * @desc   : 付款点击跳转事件
     * @author : 宋扬
     * @date   : 2024/4/23 13:22
     */
    currentPayRights(row){
      this.payDetailData = [];
      if (!row) {
        row = [this.$refs['table-select'].getCurrentRow()]
      }
      let searchParams = {...this.searchParams};
      let params={}
      if (row != null) {
        // 赋值入库查询条件
        params = {
          objectId:row[0].objectId,
          macType:1,
          accDateStart:searchParams.accDateStart,
          accDateEnd:searchParams.accDateEnd,
          currentPage:searchParams.currentPage,
          pageSize:searchParams.pageSize
        }
      }
      // 查询入库明细
      this.excute(this.$service.detailReportService, this.$service.detailReportService.getMacPayCurrentItemReport, params).then(res => {
        if (res.code === this.$config.SUCCESS_CODE) {
          this.payDetailData = res.data.list;
          // 显示收款明细信息页面
          this.detailModel = 'payDetail'
          this.visSupplierFlag = false
          this.visSupPayHandleFlag = false
          this.visSupPayFlag = true
        }
      })
    },

    /**
     * @desc   : 应付点击跳转事件
     * @author : 宋扬
     * @date   : 2024/4/23 13:22
     */
    currentHandleRights(row){
      this.handleDetailData = [];
      if (!row) {
        row = [this.$refs['table-select'].getCurrentRow()]
      }
      let searchParams = {...this.searchParams};
      let params={}
      if (row != null) {
        // 赋值出库查询条件
        params = {
          objectId:row[0].objectId,
          macType:0,
          accDateStart:searchParams.accDateStart,
          accDateEnd:searchParams.accDateEnd,
          currentPage:searchParams.currentPage,
          pageSize:searchParams.pageSize
        }
      }
      // 查询出库明细
      this.excute(this.$service.detailReportService, this.$service.detailReportService.getMacPayCurrentItemReport, params).then(res => {
        if (res.code === this.$config.SUCCESS_CODE) {
          this.handleDetailData = res.data.list;
          // 显示出库明细信息页面
          this.detailModel = 'handleDetail'
          this.visSupplierFlag = false
          this.visSupPayHandleFlag = true
          this.visSupPayFlag = false
        }
      })
    },

  },
  created() {
    this.primaryKey = 'objectId'  // 设置主键Id
    this.routeObjName = 'detailReport'  // 设置路由名称
  }
}
</script>


