<template>
  <div class="invoice-detail">
    <el-dialog title="合并发票" :visible.sync="showMergeInvoiceDialog" @close="onClose">
      <div class="bold title">已选择{{ ids.length }}个订单</div>
      <div style="margin-top: 20px">
        <div class="bold">发票号码</div>
        <el-input placeholder="请输入发票号码" style="margin-top: 15px" v-model="fapiaoNo" />
      </div>
      <div style="margin-top: 20px">
        <div class="bold">发票备注</div>
        <el-input
          style="margin-top: 15px"
          placeholder="请输入发票备注"
          type="textarea"
          :autosize="{ minRows: 3 }"
          :show-word-limit="true"
          v-model="remark"
        />
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="onClose">取 消</el-button>
        <el-button type="primary" @click="confirmInvoice">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { editInvoiceApi } from '@/api/finance';

export default {
  props: ['showMergeInvoiceDialog', 'ids'],

  data() {
    return {
      fapiaoNo: '',
      remark: '',
    };
  },

  methods: {
    onClose() {
      this.$emit('closeMergeInvoiceDialog');
    },

    confirmInvoice() {
      let params = {
        fapiaoNo: this.fapiaoNo,
        remark: this.remark,
        ids: this.ids,
      };

      if (!params.fapiaoNo) {
        this.$message({
          message: '发票号码不能为空',
          type: 'warning',
          showClose: true,
        });

        return;
      }

      editInvoiceApi(params).then((res) => {
        this.$message({
          message: '开票成功',
          type: 'success',
          showClose: true,
        });
        this.onClose();
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.invoice-detail {
  .bold {
    font-weight: bold;
  }

  .title {
    border-bottom: 1px solid #eeeeee;
    padding-bottom: 10px;
  }

  .item {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    margin-top: 15px;

    .sub-item {
      flex: 1;
    }
  }
}
</style>
