<template>
  <!-- 新增面料 装箱单  -->
  <div id="addFabricDrawer">
    <a-drawer title="详情" width="89%" placement="right" :closable="true" :visible="visible" @close="handleCancel">
      <!-- 主表信息 填写-->
      <a-card :bordered="true">
        <div class="table-page-search-wrapper">
           <a-form-model layout="inline" ref="form" :model="addFabric" :rules="validatorRules">
            <a-row :gutter="24">
              <a-col :md="6" :sm="8">
                <a-form-model-item label="单号" prop="oddNum">
                  {{addFabric.documentNo}}
                  <!-- <a-input placeholder="自动生成" v-model="addFabric.documentNo"></a-input> -->
                </a-form-model-item>
              </a-col>


              <a-col :md="6" :sm="8">
                <a-form-model-item label="集装箱号" prop="containerNumber">
                 {{addFabric.containerNumber}}
                  <!-- <a-input placeholder="请输入集装箱号" v-model="addFabric.containerNumber"></a-input> -->
                </a-form-model-item>
              </a-col>

                 <a-col :md="6" :sm="8">
                <a-form-model-item label="铅分号" prop="plumbumNo">
                  {{addFabric.plumbumNo}}
                  <!-- <a-input placeholder="请输入铅分号" v-model="addFabric.plumbumNo"></a-input> -->
                </a-form-model-item>
              </a-col>

              <a-col :md="6" :sm="8">
                <a-form-model-item label="装柜日期" prop="latestDateOfShipment">
                  {{addFabric.latestDateOfShipment}}
                  <!-- <a-date-picker
                    placeholder="请选择装柜日期"
                    :format="dateFormat"
                    style="width: 100%"
                    v-model="addFabric.latestDateOfShipment"
                  /> -->
                </a-form-model-item>
              </a-col>

              <a-col :md="6" :sm="8">
                <a-form-model-item label="成衣工厂" prop="garmentFactory">
                  {{addFabric.garmentFactory}}
                  <!-- <a-input placeholder="勾选数据自动生成" v-model="addFabric.garmentFactory"></a-input> -->
                </a-form-model-item>
              </a-col>

              <a-col :md="6" :sm="8">
                <a-form-model-item label="外销发票号" prop="exportInvoiceNo">
                  {{addFabric.exportInvoiceNo}}
                  <!-- <a-input placeholder="请输入外销发票号" v-model="addFabric.exportInvoiceNo"></a-input> -->
                </a-form-model-item>
              </a-col>

              <a-col :md="6" :sm="8">
                <a-form-model-item label="托书号" prop="shippingOrderNumber">
                  {{addFabric.shippingOrderNumber}}
                  <!-- <a-input placeholder="请输入托书号" v-model="addFabric.shippingOrderNumber"></a-input> -->
                </a-form-model-item>
              </a-col>
              <a-col :md="6" :sm="8">
                <a-form-model-item label="备注" prop="remarks">
                  {{addFabric.remarks}}
                  <!-- <a-input placeholder="请输入备注" v-model="addFabric.remarks"></a-input> -->
                </a-form-model-item>
              </a-col>

           
            </a-row>
          </a-form-model>
        </div>
      </a-card>

      <!--操作按钮区域 参照发运明细 増行-->
      <a-card :bordered="true" style="margin:10px 0 60px 0;">
        <!-- 子表   -->
        <a-spin :spinning="confirmLoading">
          <a-form-model ref="formRef" :rules="validatorRules">
            <a-table
              bordered
              :columns="addFabricColumns"
              :data-source="addFabricData"
              :loading="loading"
              :pagination="false"
              :scroll="{ x: 1500 ,y: 300}"
              @change="handleTableChange"
            >
           
            </a-table>
          </a-form-model>
        </a-spin>
        <a-col :span="12">
            <a-form-model-item label="附件"  prop="accessory">
              <ul v-for="(item, index) in accessory" :key="index" >
                <li>
                  <a @click="accessoryDownload(item)">{{item}}</a>
                </li>
                
              </ul>
            </a-form-model-item>
          </a-col>
      </a-card>
      <!-- 页面底部提交取消 -->
      <div
        :style="{
          position: 'absolute',
          right: 0,
          bottom: 0,
          width: '100%',
          borderTop: '1px solid #e9e9e9',
          padding: '10px 16px',
          background: '#fff',
          textAlign: 'right',
          zIndex: 1
        }"
      >
        <a-button type="primary" @click="handleCancel">
          关闭
        </a-button>
      </div>
    </a-drawer>
  </div>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import JEllipsis from '@/components/jeecg/JEllipsis'
import { downFile } from '@/api/manage'
export default {
  name: 'AddFabricDrawer', //  新增 装箱单 -面料
  mixins: [JeecgListMixin],
  computed: {},
  components: { JEllipsis}, // 参照发运明细 弹框
  data() {
    let ellipsis = (v, l = 20) => <j-ellipsis value={v} length={l} />
    return {
      // 表头
      addFabricColumns: [
        {
          title: '业务员 Merchandiser',
          dataIndex: 'salesman',
          width: 120,
          // fixed: 'left',
          className: 'replacecolor',
          ellipsis: true,
        },
        {
          title: '计划单号',
          dataIndex: 'planLotNumber',
          width: 160,
          // fixed: 'left',
          className: 'replacecolor',
          ellipsis: true,
        },
        {
          title: '款号/Kimball',
          dataIndex: 'itemNumber',
          width: 120,
          className: 'replacecolor',
          ellipsis: true,
        },
        {
          title: '缸号/Batch no.',
          dataIndex: 'dyelotNumber',
          // scopedSlots: { customRender: 'dyelotNumber' },
          width: 120,
          className: 'replacecolor',
          ellipsis: true,
        },
        {
          title: '颜色/Color',
          dataIndex: 'colour',
          width: 120,
          className: 'replacecolor',
          ellipsis: true,
        },

        {
          title: '项目/Item(存货编码)',
          dataIndex: 'inventoryCode',
          width: 120,
          className: 'replacecolor',
          ellipsis: true,
        },
        {
          title: '存货名称(辅料名称)',
          dataIndex: 'inventoryName',
          width: 160,
          className: 'replacecolor',
          ellipsis: true,
        },

        {
          title: '报关品名',
          dataIndex: 'declarationName',
          width: 120,
          className: 'replacecolor',
          ellipsis: true,
        },

        {
          title: '成分/Composition',
          dataIndex: 'composition',
          // scopedSlots: { customRender: 'composition' },
          width: 150,
          className: 'replacecolor',
          ellipsis: true,
        },

        {
          title: '门幅/Width',
          dataIndex: 'width',
          // scopedSlots: { customRender: 'width' },
          width: 140,
          className: 'replacecolor',
          ellipsis: true,
        },
        {
          title: '匹数/Rolls',
          dataIndex: 'rolls',
          // scopedSlots: { customRender: 'rolls' },
          width: 120,
          className: 'replacecolor',
          ellipsis: true,
        },
        {
          title: '毛重/GW/kg',
          dataIndex: 'grossWeight',
          // scopedSlots: { customRender: 'grossWeight' },
          width: 120,
          className: 'replacecolor',
          ellipsis: true,
        },
        {
          title: '净重/NW/kg',
          // scopedSlots: { customRender: 'netWeight' },
          dataIndex: 'netWeight',
          width: 120,
          className: 'replacecolor',
          ellipsis: true,
        },

        {
          title: '染后重',
          dataIndex: 'afterHeavy',
          // scopedSlots: { customRender: 'afterHeavy' },
          width: 90,
          className: 'replacecolor',
          ellipsis: true,
        },
        {
          title: '拷布重',
          dataIndex: 'kaoClothWeight',
          // scopedSlots: { customRender: 'kaoClothWeight' },
          width: 120,
          className: 'replacecolor',
          ellipsis: true,
        },
        {
          title: '米数/Length/m',
          dataIndex: 'meter',
          width: 130,
          className: 'replacecolor',
          ellipsis: true,
        },
        // {
        //   title: '价格',
        //   dataIndex: 'price',
        //   width: 120,
        //   className: 'replacecolor'
        // },
        {
          title: '克重/G',
          dataIndex: 'gramWeight',
          width: 120,
          className: 'replacecolor',
          ellipsis: true,
        },
        {
          title: '供应商编码(染厂)',
          dataIndex: 'supplierCodeDyeingPlant',
          // scopedSlots: { customRender: 'supplierCodeDyeingPlant' },
          width: 120,
          className: 'replacecolor',
          ellipsis: true,
        },
        {
          title: '供应商(染厂)',
          dataIndex: 'supplierDyeingPlant',
          // scopedSlots: { customRender: 'supplierDyeingPlant' },
          width: 120,
          className: 'replacecolor',
          ellipsis: true,
        },
        {
          title: '供应商编码(印厂)',
          // scopedSlots: { customRender: 'supplierCodePrintingPlant' },
          dataIndex: 'supplierCodePrintingPlant',
          width: 120,
          className: 'replacecolor',
          ellipsis: true,
        },
        {
          title: '供应商(印厂)',
          dataIndex: 'supplierPrintingPlant',
          // scopedSlots: { customRender: 'supplierPrintingPlant' },
          width: 120,
          className: 'replacecolor',
          ellipsis: true,
        },
        {
          title: '包装方式',
          dataIndex: 'mannerOfPacking',
          // scopedSlots: { customRender: 'mannerOfPacking' },
          width: 120,
          className: 'replacecolor',
          ellipsis: true,
        },
        {
          title: '处理方式',
          // scopedSlots: { customRender: 'treatmentMethod' },
          dataIndex: 'treatmentMethod',
          width: 120,
          className: 'replacecolor',
          ellipsis: true,
        },
        {
          title: '是否手册纱',
          dataIndex: 'manualYarnFlag',
          // scopedSlots: { customRender: 'manualYarnFlag' },
          width: 120,
          className: 'replacecolor',
          ellipsis: true,
        },
        {
          title: '手册纱单价',
          dataIndex: 'manualYarnUnitPrice',
          // scopedSlots: { customRender: 'manualYarnUnitPrice' },
          width: 120,
          className: 'replacecolor',
          ellipsis: true,
        },
        {
          title: '手册纱占比%',
          dataIndex: 'manualYarnProportion',
          // scopedSlots: { customRender: 'manualYarnProportion' },
          width: 120,
          className: 'replacecolor',
          ellipsis: true,
        },
        {
          title: '柜号',
          dataIndex: 'containerNumber',
          // scopedSlots: { customRender: 'containerNumber' },
          width: 120,
          className: 'replacecolor',
          ellipsis: true,
        },

        {
          title: '规格型号',
          dataIndex: 'specificationAndModel',
          width: 120,
          className: 'replacecolor',
          ellipsis: true,
        },
        {
          title: '实际报关数量',
          dataIndex: 'actualDeclaredQuantity',
          // scopedSlots: { customRender: 'actualDeclaredQuantity' },
          width: 120,
          className: 'replacecolor',
          ellipsis: true,
        },
        {
          title: '超发',
          dataIndex: 'excessQuantity',
          width: 120,
          className: 'replacecolor',
          ellipsis: true,
        },
        {
          title: '单位',
          dataIndex: 'masterMetering',
          width: 80,
          className: 'replacecolor',
          ellipsis: true,
        },
        {
          title: '价格',
          dataIndex: 'price',
          width: 100,
          className: 'replacecolor',
          ellipsis: true,
        },
        {
          title: '总价',
          dataIndex: 'totalPrice',
          width: 100,
          className: 'replacecolor',
          ellipsis: true,
        },
        {
          title: '备注(U8)',
          dataIndex: 'remarks2',
          width: 160,
          ellipsis: true,
          // fixed: 'right',
          // scopedSlots: { customRender: 'remarks2' },          
          className: 'replacecolor'
        },
      ],
      accessory:[],
      addFabricData: [],
      loading: false, // 表格加载
      addFabric: {},
      visible: false,
      confirmLoading: false,
      validatorRules: { },
      dateFormat: 'YYYY-MM-DD'
    }
  },
  created() {},
  mounted() {},
  methods: {
    // 抽屉 取消
    handleCancel() {
      console.log('点击抽屉取消')
      this.close()
    },
     judageCloumn(){
      this.addFabricColumns.map(item => {
        if(item.title ==  "匹数/Rolls"){
          item.title = '箱数'
        }
      })
      var obj = {
          title: '尺码',
          dataIndex: 'size',
          width: 120,
          className: 'replacecolor'
      }
      this.addFabricColumns.splice(30,0,obj)
   },
 

    // -------------------------------------
    close() {
      this.$emit('close')
      this.visible = false
      this.addFabric = {}
      this.addFabricData = []
      this.addFabricColumns = this.addFabricColumns.filter(item => item.title !== '尺码')
      this.addFabricColumns.map(item => {
        if(item.title ==  "箱数"){
          item.title = '匹数/Rolls'
        }
      })
    },
    accessoryDownload(name){
       downFile(`/sys/common/static/${name}`).then(data => {
        if (!data) {
          this.$message.warning('文件下载失败')
          return
        }
        if (typeof window.navigator.msSaveBlob !== 'undefined') {
          window.navigator.msSaveBlob(new Blob([data], { type: 'application/vnd.ms-excel' }), fileName + '.xls')
        } 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', name + '.xls')
          document.body.appendChild(link)
          link.click()
          document.body.removeChild(link) // 下载完成移除元素
          window.URL.revokeObjectURL(url) // 释放掉blob对象
        }
      })
    },

     // 分页、排序、筛选变化时触发
    // handleTableChange(pagination, filters, sorter) {
    //   // console.log('当前页信息>>>>',pagination)
    //   this.queryParam.pageNo = pagination.current
    //   this.getAnnList()
    // }
  }
}
</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;
// }

// 抽屉里的card样式
/deep/ .ant-drawer-content {
  background-color: #f0f2f5;
}
/deep/ .ant-drawer-body {
  padding: 10px;
}
</style>
