<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    switchFullscreen
    @ok="handleOk"
    :okButtonProps="{ class: { 'jee-hidden': disableSubmit } }"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <a-table
      :columns="columns"
      :data-source="feesList"
      :pagination="false"
      :scroll="{ y: 160 }"
      rowKey="id">
      <template slot="subjectType" slot-scope="text">
        {{ getSubjectTypeText(text) }}
      </template>
      <template slot="money" slot-scope="text, record">
        <a-input-number v-model=record.money @blur="handleBlur()"></a-input-number>
      </template>
    </a-table>
  </j-modal>
</template>

<script>
import { postAction } from '@api/manage'

const columns = [
  // {
  //     title: "",
  //     dataIndex: "key",
  //     width: 20,
  //   },
  {
    title: '费项',
    dataIndex: 'subjectType',
    width: 100,
    scopedSlots: { customRender: 'subjectType' }
  },
  {
    title: '日期',
    dataIndex: 'dayTime',
    width: 100
  },
  {
    title: '金额',
    dataIndex: 'oldPrice',
    width: 60
  },
  {
    title: '冲账金额',
    dataIndex: 'money',
    width: 60,
    scopedSlots: { customRender: 'money'}
  },
  ]
export default {
  name: 'StrikeBalanceModel',
  components: {
  },
  data() {
    return {
      title: '',
      width: 800,
      visible: false,
      disableSubmit: false,
      showYinshou: true,
      columns: columns,
      feesList: []
    }
  },
  methods: {

    edit(record) {
      this.visible = true
      console.log(record)
      this.feesList = record
      this.feesList.forEach(e => {
        e.oldPrice = e.money
      })
    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    handleOk() {
      let num = 0
      this.feesList.forEach(e => {
        if (e.money > e.oldPrice) {
          e.money = e.oldPrice
          num++
        }
      })
      if (num > 0) {
        this.$message.warning('冲账金额不能超过原金额')
        return
      }
      postAction('/business/busOrderFee/strike-balance', this.feesList).then(resp => {
        if (resp.result === true) {
          this.$message.success('冲账成功')
          this.$emit('ok')
          this.visible = false
        } else {
          this.$message.warning('冲账失败')
        }
      });
    },
    submitCallback() {

    },
    handleCancel() {
      this.close()
    },
    getSubjectTypeText(text) {
      var msg = ''
      if (text === 1) {
        msg = '押金'
      } else if (text === 2) {
        msg = '预收房费'
      } else if (text === 3) {
        msg = '每日房费'
      } else if (text === 4) {
        msg = '优惠金额'
      } else if (text === 5) {
        msg = '结账收款'
      } else if (text === 6) {
        msg = '商品'
      } else if (text === 7) {
        msg = '点餐'
      } else if (text === 8) {
        msg = '夜审房费'
      } else if (text === 9) {
        msg = '会议室'
      } else if (text === 10) {
        msg = '手工房费'
      } else if (text === 11) {
        msg = '水电煤抄表'
      } else if (text === 12) {
        msg = '赔偿费'
      } else if (text === 13) {
        msg = '退单结账'
      }
      return msg
    },
    handleBlur() {
      this.$forceUpdate()
    }

  }
}
</script>
