<template>
  <!-- 面料 转入数量 成本分配统计表   -->
  <a-modal
    title="面料 - 转入数量"
    v-model="fabInQuaModVis"
    :confirmLoading="confirmLoading"
    width="86%"
    style="top:330px;left:100px;"
    :footer="null"
  >
    <!-- tabel  -->
    <a-spin :spinning="confirmLoading">
      <a-table :loading="loading" bordered :columns="columns" :data-source="data" :pagination="false"> 
        <span slot="unitCost" slot-scope="text,record">
              <a-input placeholder="请输入" v-model="record.unitCost"  @change="changeUnitCost(record)"/>
          </span>
      </a-table>
      <!-- 导出 打印 返回  -->
      <a-row style="marginTop:20px;">
        <a-col :md="24" :sm="12">
          <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="cancel" icon="rollback">取消</a-button>
          </span>
        </a-col>
      </a-row>
    </a-spin>
  </a-modal>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import JEllipsis from '@/components/jeecg/JEllipsis'
import moment from 'moment'

import { downFile,downFile1 } from '@/api/manage'

export default {
  name: 'FabInQuaModal', // 面料 转入数量 弹框
  mixins: [JeecgListMixin],
  components: { JEllipsis, moment },
  data() {
    return {
      // 面料 - 转入数量 表头
      columns: [
        {
          title: '存货名称',
          dataIndex: 'goodsName',
          width: 120,
          className: 'replacecolor'
        },
        {
          title: '颜色',
          dataIndex: 'color',
          width: 120,
          className: 'replacecolor'
        },
        {
          title: '计划单号',
          dataIndex: 'planCode',
          width: 120,
          className: 'replacecolor'
        },
        {
          title: '转入数量',
          dataIndex: 'number',
          width: 120,
          className: 'replacecolor',
          customRender: (text, record, index) => {
            var re =  Number(text).toFixed(4)
            return re
         }
        },
        {
          title: '单位成本',
          dataIndex: 'unitCost',
          width: 120,
          className: 'replacecolor',
          scopedSlots: { customRender: 'unitCost' },
        //    customRender: (text, record, index) => {
        //     var re =  Number(text).toFixed(3)
        //     return re
        //  }
        },
        {
          title: '总成本',
          dataIndex: 'cost',
          width: 120,
          className: 'replacecolor',
           customRender: (text, record, index) => {
            var re =  Number(text).toFixed(2)
            return re
         }
        }
      ],
      data: [],
      loading: false,
      confirmLoading: false,
      planNum:'',
      fabInQuaModVis: false
    }
  },
  // 接收父组件 方法
  props: {
    father: {
      type: Function,
      default: null
    },
    planNum:{
      type: String,
      default: null
    }

  },

  methods: {
    // 导出
    handleExportXls(fileName) {
      console.log('需导出的fileName:', fileName)
      const params = {
        planNum:this.planNum,
        syTransfer :this.data,
        sheetName:"面料转入"
      }
      console.log('导出参数', params)
      // var json = JSON.stringify(params)
      // debugger
      downFile1('/cost/syCostAllocation/exportXlsSyCostAllocation', params).then(data => {
        console.log('888')
        if (!data) {
          this.$message.warning('文件下载失败')
          return
        }
        if (typeof window.navigator.msSaveBlob !== 'undefined') {
          window.navigator.msSaveBlob(new Blob([data], { type: 'application/vnd.ms-excel' }),this.planNum+'-'+fileName + '.xlsx')
        } else {
          let url = window.URL.createObjectURL(new Blob([data], { type: 'application/vnd.ms-excel' }))
          let link = document.createElement('a')
          link.style.display = 'none'
          link.href = url
          link.setAttribute('download', this.planNum+'-'+fileName + '.xlsx')
          document.body.appendChild(link)
          link.click()
          document.body.removeChild(link) // 下载完成移除元素
          window.URL.revokeObjectURL(url) // 释放掉blob对象
        }
      })
    },
    changeUnitCost(record){
      record.cost = record.unitCost*record.number
    },
    // 打印
    print() {},

    cancel() {
      console.log('返回成本分配统计表')
      this.fabInQuaModVis = false
    }
  }
}
</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>
