<template>
  <a-modal
    title="发票数量"
    v-model="invoiceQuantityModVis"
    :confirmLoading="confirmLoading"
    width="86%"
    :footer="null"
  >
    <!-- tabel 加载 -->
    <a-spin :spinning="confirmLoading">
      <!-- table -->
      <div style="marginTop:30px;">
        <a-table
          :loading="loading"
          :columns="invoiceQuantityColumns"
          :data-source="invoiceQuantityData"
          :pagination="false"
          bordered
          :scroll="{ y: 500 }"
          :footer="showTotal"
        >
        </a-table>

        <!-- 导出 打印 返回  -->
        <a-row>
          <a-col :md="24" :sm="12" style="marginTop:20px;">
            <span style="float: right;" class="table-operator">
              <a-button type="primary" icon="download" @click="handleExportXls('采购数量')">导出</a-button>
              <a-button type="primary" @click="print" icon="printer" style="margin:0 10px;">打印</a-button>
              <a-button type="primary" @click="backFabricLossTable" icon="rollback">返回</a-button>
            </span>
          </a-col>
        </a-row>
      </div>
    </a-spin>
  </a-modal>
</template>

<script>
export default {
  name: 'InvoiceQuantityModal', // 发票数量 弹框
  components: {},
  data() {
    return {
      // 表头
      invoiceQuantityColumns: [
        {
          title: '序号',
          width:80,
           customRender: (text, record, index) => {
            if (record.cinvName == "合计")
              return "合计";
            else
              return index + 1;
           }
        },
        {
          title: '开票数',
          dataIndex: 'iquantityInvoice',
          width: 120,
          key: '',
          className: 'replacecolor'
        },
        {
          title: '未开票数',
          dataIndex: 'iquantityInvoiceN',
          width: 120,
          key: '',
          className: 'replacecolor'
        },
        {
          title: '结算数量',
          dataIndex: 'iquantitySettle',
          width: 120,
          key: '',
          className: 'replacecolor'
        },
        {
          title: '未结算数量',
          dataIndex: 'iquantitySettleN',
          width: 120,
          key: '',
          className: 'replacecolor'
        }
      ],
      invoiceQuantityData: [],
      allDataList:[],
      size: 'small', // 查询按钮变小
      loading: false, // 表格加载
      // orderDataform: this.$form.createForm(this),
      confirmLoading: false,
      invoiceQuantityModVis: false
    }
  },
  // 接收父组件 方法
  props: {
    father: {
      type: Function,
      default: null
    }
  },
  created() {},
  computed: {
    // 合计展示
    totalDataSource(){
      // 开票成本-衬衣 合计
      var item = {
        "cinvName":"合计"
      };
      var iquantityInvoice = 0,iquantityInvoiceN = 0, iquantitySettle=0, iquantitySettleN=0;
      for (let row of this.invoiceQuantityData){
        iquantityInvoice += row.iquantityInvoice*1;
        iquantityInvoiceN += row.iquantityInvoiceN*1;
        iquantitySettle += row.iquantitySettle*1;
        iquantitySettleN += row.iquantitySettleN*1;
      }
      
      item.iquantityInvoice= parseFloat(iquantityInvoice.toFixed(4));
      item.iquantityInvoiceN= parseFloat(iquantityInvoiceN.toFixed(4));
      item.iquantitySettle= parseFloat(iquantitySettle.toFixed(4));
      item.iquantitySettleN= parseFloat(iquantitySettleN.toFixed(4));
      return [item];

    }
  },
  methods: {
    // 第一行 导出
    handleExportXls() {},
    // 打印
    print() {},
    // 返回
    backFabricLossTable() {
      console.log('返回到面料损耗表')
      // this.$router.push('fabricLoss-table')
      // this.invoiceQuantityModVis = false
      this.close()
    },

    close() {
      this.$emit('close')
      this.invoiceQuantityModVis = false
    },
    showTotal(data) {
      return (
        <a-table
          rowKey={Math.random}
          bordered={false}
          pagination={false}
          columns={this.invoiceQuantityColumns}
          dataSource={this.totalDataSource || []}
          showHeader={false}
        ></a-table>
      )
    },
  }
}
</script>
<style lang="less" scoped>
@import '~@assets/less/common.less';
@import '~@assets/less/overwriter.less';
/deep/ .ant-table-thead > tr > th {
  text-align: center;
  // font-weight: 700;
}

/deep/ .ant-table-tbody {
  text-align: center;
}

// /deep/ th.replacecolor {
//   background-color: #ccc;
// }
</style>
