/*
 *@description:费用录入
 *@author: hudw
 *@date: 2022-03-14 10:40:55
*/

<template>
  <a-modal class="model-table" v-model="sVisible" v-bind="modalConfig" :confirmLoading="confirmLoading" @ok="handleOk">
    <p-card title="新增费用" :bodyStyle="{ padding: 0, margin: '-1px', minHeight: '300px' }" style="margin-bottom: 10px">
      <a-space slot="extra">
        <p-button type="primary" @clickSync="add_item" icon="plus">新增</p-button>
      </a-space>
      <p-table-edit-pro
        :id="$route.meta.menuId + '_details_table'"
        :autoLoad="false"
        ref="editTable"
        rowKey="_row_count"
        :rowSelectType="false"
        :columns="mx_columns"
        :pagination="false"
        :dataSource.sync="details"
        :scroll="{ x: true }"
        dragle
      >
      </p-table-edit-pro>
    </p-card>
    <p-card title="派车单信息" :bodyStyle="{ padding: 0, margin: '-1px' }">
      <t-table
        :scroll="{ x: true }"
        bordered
        :autoLoad="false"
        :vScrollX="{enabled:false}"
        :vScrollY="{enabled:true,rows:4}"
        autoColWidth
        ref="table"
        rowKey="id"
        :rowSelectType="false"
        :columns="columns.filter((item) => item.dataIndex)"
        :dataSource.sync="dataSource"
        :pagination="false"
        dragle
      />
    </p-card>
  </a-modal>
</template>
<script>
import inExpenseTableCol from '@/views/BMS/$common/tableConfig/inExpenseTableCol.js'
import { setMainColumns as loadingBillColumns } from '../mainTable/tableConfig'
import { getComputedParameter } from '@/blocks/utils/index.js'
export default {
  name: 'inMoneyModal',
  props: {
    options: {
      type: Object,
      default: () => {},
    },
    /**0=不显示, 1=新建，2=修改 ，3=查看 */
    view: 0,
    title: '',
    visible: false,
    targetKeys: [],
    dataSource: [],
    mode: {
      type: null,
      default: 1,
    },
  },

  computed: {
    modalConfig() {
      const { title } = this
      return { title, width: 1200, destroyOnClose: true, okButtonProps: { props: { disabled: this.details.length === 0 } } }
    },
  },
  data() {
    this.mx_columns = inExpenseTableCol(this)
    this.mx_columns[2].remoteBefore = (vonde, res) => {
      res.data.expenseClassify = 2
    };
    return {
      bizId: '',
      confirmLoading: false,
      details: [],
      sVisible: this.visible,
      columns:loadingBillColumns(this,'支出'),
    }
  },

  watch: {
    visible(value) {
      this.details = []
      this.sVisible = value
      if (value) {

      }

    },

    sVisible(value) {
      this.confirmLoading = false
      if (value && this.view > 0) {
      } else {
      }
      this.$emit('update:visible', value)
    },
  },
  mounted() {},
  methods: {
    add_item() {
      this.details.push({})
      //  this.$refs.table.createRow()
    },
    handleMoney(key, record) {
      //是否含税                    //税点
         //是否含税                               //税点
         let { isPreTax, taxAmt, noTaxAmt, tax, taxPoint, amount } = record
         let bit = 10 ** ~~this.options.sysParams.costPrecision
       //税点百分比
       let _tax = taxPoint / 100
       console.log(_tax,amount)

      //未税金额=含税金额 /（1 + 税点）
      record.noTaxAmt = getComputedParameter(amount / (1 + _tax), 'cost')
      //税额
      record.tax = parseFloat(this.BigJs(amount).minus(record.noTaxAmt))
      //金额
      record.taxAmt = amount
    },
    remoteBefore(vonde, res) {
      res.data= this.dataSource

    },
    handleOk() {
      let _this= this
      this.$refs.editTable.validateFields((errors, values) => {
        if (errors) return
        // let data = {
        //   detailList: values,
        //   shipbillNo: this.dataSource.map((item) => item.shipbillNo),
        // }
        let idList = this.dataSource.map((item) => {
          return item.id
        })

        this.confirmLoading = true
        this.$emit('ok', { idList,detailAddVOList:values }, () => {
          this.confirmLoading = false
        })
      })
    },
  },
}
</script>

<style  lang="less" scoped>
.model-table {
  /deep/.ant-table-placeholder {
    border-bottom: 0;
  }
}
</style>


