<template>
  <modal v-model="modal" class-name="vertical-center-modal" width="500px">
    <div class="title" slot="header">{{ data.purchaseBillNo }}</div>
    <div class="sub-content">
      <div class="row">
        <div class="col">
          <div class="label">合同金额：</div>
          <div class="value">{{ data.totalAmount || 0 }}元</div>
        </div>
        <div class="col">
          <div class="label">发票金额：</div>
          <div class="value">{{ data.invoiceAmount || 0 }}元</div>
        </div>
      </div>
      <div class="row">
        <div class="col">
          <div class="label">质检金额：</div>
          <div class="value">{{ data.adjustAmount || 0 }}元</div>
        </div>
        <div class="col">
          <div class="label">未付金额：</div>
          <div class="value">{{ (data.adjustAmount - data.hisPayAmount) || 0 }}元</div>
        </div>
      </div>
      <div class="row">
        <div class="col">
          <div class="label">已付金额：</div>
          <div class="value">{{ data.hisPayAmount || 0 }}元</div>
        </div>
        <div class="col">
          <div class="label">退货冲抵：</div>
          <div class="value">{{ data.backAmount || 0 }}元</div>
        </div>
      </div>
      <div class="row">
        <div class="col">
          <div class="label">运费冲抵：</div>
          <div class="value">{{ data.expressAmount || 0 }}元</div>
        </div>
        <div class="col"></div>
      </div>
      <div class="row" style="justify-content: center">
        <div class="col" style="flex: none">
          <div class="label">申请支付：</div>
          <div class="value">
            <Input v-model="data.payAmount" disabled style="width: 120px;"/>
          </div>
          <span style="padding: 0 10px">元</span>
        </div>
      </div>
      <div class="row" style="justify-content: center">
        <div class="col" style="flex: none">
          <div class="label">其他冲抵：</div>
          <div class="value">
            <Input v-model="data.totalBalance" style="width: 120px;"/>
          </div>
          <span style="padding: 0 10px">元</span>
        </div>
      </div>
      <div class="row" style="justify-content: center;height: 32px;line-height: 32px">
        <div class="col" style="flex: none">
          <div class="label">实际支付金额：</div>
          <div class="value">
            <div style="width: 95px;color: red;">{{(data.payAmount * 100 - data.backAmount* 100 - data.expressAmount* 100 - data.totalBalance * 100)/100}}元</div>
          </div>
          <span style="padding: 0 10px">&nbsp;&nbsp;&nbsp;&nbsp;</span>
        </div>
      </div>
      <div class="row">
        <div class="col" style="align-items: flex-start">
          <div class="label" style="width: 60px;">备注：</div>
          <div class="value">{{ data.payAccount || '' }}</div>
        </div>
      </div>
      <div class="row">
        <div class="col" style="align-items: flex-start">
          <div class="label">审批意见：</div>
          <div class="value">
            <Input v-model="remark" type="textarea" />
          </div>
        </div>
      </div>
    </div>
    <div class="footer" slot="footer">
      <Button @click="cfm" class="btn" type="primary">审批通过</Button>
    </div>
  </modal>
</template>

<script>
import { ApprovalBillFlow } from '@/api/applyPurchase'

export default {
  name: 'pass_modal',
  data () {
    return {
      modal: false,
      remark: ''
    }
  },
  props: {
    value: {
      type: Boolean,
      default: false,
      require: true
    },
    data: {
      type: Object,
      default () {
        return {}
      }
    }
  },
  computed: {
    // payAmount () {
    //   return this.data.payAmount
    // },
    // totalBalance () {
    //   return this.data.totalBalance
    // }
  },
  watch: {
    // payAmount () {
    //   this.$set(this.data, 'actAmount', (this.data.payAmount - this.data.totalBalance).toFixed(2))
    // },
    // totalBalance () {
    //   this.$set(this.data, 'actAmount', (this.data.payAmount - this.data.totalBalance).toFixed(2))
    // },
    value: {
      handler (n) {
        this.modal = n
      },
      immediate: true
    },
    modal (n) {
      this.$emit('input', n)
    }
  },
  methods: {
    cfm () {
      console.log(this.data)
      // let obj = {
      //   purchaseBillNo: this.data.purchaseBillNo,
      //   payAmount: this.data.payAmount,
      //   hisPayAmount: this.data.hisPayAmount,
      //   backAmount: this.data.backAmount,
      //   balanceAmount: this.data.totalBalance,
      //   expressAmount: this.data.expressAmount,
      //   actAmount: this.data.actAmount,
      //   bankAccout: this.data.bankAccout,
      //   bankAccoutName: this.data.bankAccoutName,
      //   openBank: this.data.openBank
      // }
      // console.log(obj)
      ApprovalBillFlow({
        linkCheckId: [this.data.flowCheckId],
        updateAction: 0,
        applyPayAmount: this.data.payAmount,
        balanceAmount: this.data.totalBalance,
        suggestions: this.remark
      }).then(res => {
        if (res.code === 0) {
          this.$Message.info(res.msg || '操作成功！')
          this.$emit('getlist')
          this.cancel()
        }
      })
    },
    cancel () {
      this.remark = ''
      this.modal = false
    }
  }
}
</script>

<style lang="less" scoped>
.row {
  margin-bottom: 10px;
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  &:last-child {
    margin-bottom: 0;
  }
  .col {
    flex: 1;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .value {
      flex: 1;
      overflow: hidden;
    }
  }
}
/deep/ .ivu-modal-mask {
  background-color: rgba(55, 55, 55, 0.2);
}
</style>
