/*
 *@description:司机应付管理-结算管理
 *@author: hudw
 *@date: 2023-05-04 12:12:51
*/

<template>
  <div class="pages">
    <searchBar ref="searchBar" :title="'司机应付管理-'+$route.meta.title" :options="options" @submit="$searchSubmit"></searchBar>
    <!-- :dataSource="selectMainArr"  -->
    <auditModal :visible.sync="inMoneyVisible" :st="detailsState" :record="detailData" :options="options" :formExtendedField="formExtendedField" @ok="ok" title="结算单信息" />
    <mainTable
      ref="mainTable"
      :rowKey="'id'"
      title="结算单信息"
      :url="mainUrl"
      :options="options"
      :activeID="mainId"
      :tableExtendedField="tableExtendedField"
      :selectedRowKeys.sync="mainsSelectedRowKeys"
      :operation="{ width: 200 }"
      @view="handleView"
      @clickRow="handleRowClick"
    >
      <p-button slot="extra" type="primary" :disabled="mainsSelectedRowKeys.length === 0" @click.stop="handleAudit(mainsSelectedRowKeys)">审核</p-button>
      <a-space slot="operation" slot-scope="slotProps">
        <a href="javascript:;" @click.stop="handleView(slotProps.record)">查看</a>
        <a href="javascript:;" @click.stop="handleUpdate(slotProps.record)" v-if="slotProps.record.status < 2">修改</a>
        <a href="javascript:;" @click.stop="handleAudit([slotProps.record.id])" v-if="slotProps.record.status < 2">审核</a>
        <a href="javascript:;" @click.stop="handleCancellation(slotProps.record.id)" v-if="slotProps.record.status < 2">作废</a>
      </a-space>
    </mainTable>
    <p-card :bordered="false" style="margin-top: 10px" :bodyStyle="{ minHeight: '300px' }">
      <a-tabs style="background-color: #fff" v-model="tabsKey">
        <a-tab-pane :key="3" tab="派车单信息">
          <feeTable ref="childrenTable_3" :options="options" :remoteBefore="loadingBillRemoteBefore" :url="loadingBillUrl" :columns="loadingBillColumns" :isShow="tabsKey === 3" :activeID="childrenId" />
        </a-tab-pane>
        <a-tab-pane :key="0" tab="费用信息">
          <feeTable ref="childrenTable_0" :options="options" :url="feeListUrl" :columns="feeColumns" :isShow="tabsKey === 0" :activeID="childrenId" />
        </a-tab-pane>
        <a-tab-pane :key="1" tab="操作日志">
          <logTable ref="childrenTable_1" :url="findListForLogUrl" :options="options" :isShow="tabsKey === 1" /></a-tab-pane>
      </a-tabs>
    </p-card>
  </div>
</template>
<script>
import useMixin from '@/views/BMS/settlement/$common/mixins/useMixin.js'
import dictionary from '@/views/BMS/settlement/$common/mixins/dictionary.js'
import auditModal from './auditModal/index.auditModal.vue'
import { mainTableInfoUrl, loadingBillUrl,getDetail,cancellationSubmit, updateSubmit, auditSubmit, feeListUrl, findListForLogUrl } from './api.js'
import { resultExtendedField } from '@/blocks/utils'
import feeColumns from './js/feeColumns'
import loadingBillColumns from './js/loadingBillColumns.js'
export default {
  mixins: [useMixin, dictionary],
  components: { auditModal },
  data() {
    return {
      loadingBillUrl,
      loading: false,
      feeListUrl,
      findListForLogUrl,
      feeColumns: feeColumns(this),
      loadingBillColumns:loadingBillColumns(this),
      inMoneyVisible: false,
      tabsKey: 3,
      mainUrl: mainTableInfoUrl,
      selectMainArr: [],
      detailData: null,
      detailsState: 0/**0=不显示,1=查看,2=新建,3=修改,4=复制 */,

      tableExtendedField: [],
      formExtendedField: [],
    }
  },
  watch: {
    tabsKey(value) {
      if (this.mainCurrent) {

        this.handleRowClick(null, this.mainId, this.mainCurrent)
      }
    },
  },
  mounted() {
    let _this = this
    resultExtendedField({ extendedObjectCode: '20' }).then((data) => {
      if (data) {
        _this.tableExtendedField = data.table
        _this.formExtendedField = data.form
      }
    })
  },
  methods: {
    handleUpdate(data) {
      this.inMoneyVisible = true
      this.detailData = data
      this.detailsState = 3

      // getDetail(this,{id:data.id})
    },
    handleView(data) {
     // this.mainCurrent = { ...data };
      this.inMoneyVisible = true
      this.detailData = data
      this.detailsState = 1
      // getDetail(this,{id:data.id})
    },
    handleAudit(arr) {
      auditSubmit(this,arr)
      //  this.inMoneyVisible= true
    },

    handleRowClick(event, key, data) {
      this.clearChildrenTableAll(true)
      this.mainId = key
      if (key) {
        this.mainCurrent = data
        let id = data.id

        this.$nextTick(() => {
          const { childrenTable_0, childrenTable_1 ,childrenTable_3} = this.$refs
          let ref = [childrenTable_0, childrenTable_1,'',childrenTable_3]
          ref = ref[this.tabsKey]
          ref && ref.reload({ data: { id } })
        })
      } else {
        this.currentMainData = null
      }
    },
    handleCancellation(id) {
      cancellationSubmit(this,id)
    },
    loadingBillRemoteBefore(vnode, res) {
     // res.params = res.data
      const { feeIds } = this.mainCurrent
      res.data.includeFeeIdList = feeIds
      delete  res.data.id
    },

    ok(data, clear) {

      updateSubmit(this, data, clear)
    },
  },
}
</script>
<style lang='less'>
</style>
