<template>
  <!-- 装箱单 新增面料 -->
  <a-modal
    title="参照出运明细"
    v-model="referShipDetailsModVis"
    :confirmLoading="confirmLoading"
    @ok="onSubmit"
    @cancel="handleCancel"
    width="86%"
    style="top:330px;left:100px;"
  >

    <a-spin :spinning="confirmLoading">
      <!-- 查询  -->
      <div class="table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="searchQuery">
          <a-row :gutter="24">
            <a-col :md="6" :sm="8">
              <a-form-item label="发运明细单号">
                <a-input placeholder="请输入发运明细单号" v-model="queryParam.documentNo"></a-input>
              </a-form-item>
            </a-col>

            <a-col :md="6" :sm="8">
              <a-form-item label="发货情况">
               <a-select v-model="queryParam.status" style="width: 200px" placeholder="请选择发货情况" >
                 <a-select-option value="n">超量发货</a-select-option>
                 <a-select-option value="y">正常</a-select-option>
               </a-select>
              </a-form-item>
            </a-col>
            
            <a-col :md="6" :sm="8">
              <a-form-item label="成衣工厂">
                <a-input placeholder="请输入成衣工厂" v-model="queryParam.garmentFactory"></a-input>
              </a-form-item>
            </a-col>


            <template v-if="toggleSearchStatus">
              <a-col :md="6" :sm="8">
               <a-form-item label="订单号">
                 <a-input placeholder="请输入订单号" v-model="queryParam.orderNumber"></a-input>
               </a-form-item>
              </a-col>
              <!-- <a-col :md="6" :sm="8">
               <a-form-item label="客户">
                <j-search-select-tag
                  placeholder="请选择客户"
                  v-model="queryParam.customer"
                  dict="view_customer,customername,customername">
                </j-search-select-tag>
               </a-form-item>
              </a-col> -->
              <a-col :md="6" :sm="8">
               <a-form-item label="出运明细制单人">
                 <a-input placeholder="请输入出运明细制单人" v-model="queryParam.createBy"></a-input>
               </a-form-item>
              </a-col>
              <!-- <a-col :md="6" :sm="8">
               <a-form-item label="预发货日期">
                 <a-range-picker
                  :placeholder="['开始时间', '结束时间']"
                  format="YYYY-MM-DD"
                  style="width: 100%"
                  v-model="preDeliveryDate"
                  @change="onDateChange"
                />
               </a-form-item>
              </a-col> -->

            </template>

            <a-col :md="6" :sm="8">
              <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
                <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
                <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
                <a @click="handleToggleSearch" style="margin-left: 8px">
                  {{ toggleSearchStatus ? '收起' : '展开' }}
                  <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
                </a>
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>

      <!-- table -->
      <a-table
        :columns="referShipDetailsColumns"
        :data-source="referShipDetailsData"
        :loading="loading"
        :pagination="pagination"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
        @change="handleTableChange"
        bordered
        :scroll="{ x: 1500 }"
      >
      </a-table>
    </a-spin>
  </a-modal>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { ACCESS_TOKEN } from "@/store/mutation-types"
import Vue from 'vue'
import JEllipsis from '@/components/jeecg/JEllipsis'
import { referenceList} from '@api/document/packing-list/packinglist-fabrics'
import moment from 'moment'
export default {
  name: 'ReferShipmentDetailsModal',
  mixins: [JeecgListMixin],
  components: { JEllipsis, moment },

  data() {
    let ellipsis = (v, l = 20) => <j-ellipsis value={v} length={l} /> // 省略
    return {
      headers: {},
      config:null,
      selectedRowKeys: [], // 勾选航
      selectedRows:[],
      loading: false, // 表格加载
      preDeliveryDate:[],
      // 表头
      referShipDetailsColumns: [
        {
          title: '单据号',
          dataIndex: 'documentNo',
          width: 140,
          // fixed: 'left',
          ellipsis: true,
          customRender: t => ellipsis(t),
          className: 'replacecolor'
        },
        {
          title: '销售订单号',
          dataIndex: 'orderNumber',
          width: 140,
          // fixed: 'left',
          ellipsis: true,
          customRender: t => ellipsis(t),
          className: 'replacecolor'
        },
         {
          title: '款号',
          dataIndex: 'itemNumber',
          width: 130,
          ellipsis: true,
          className: 'replacecolor'
        },
        {
          title: '成衣工厂',
          dataIndex: 'garmentFactory',
          width: 130,
          ellipsis: true,
          className: 'replacecolor'
        },

        {
          title: '客户简称',
          dataIndex: 'customerAbbreviation',
          customRender: t => ellipsis(t),
          width: 130,
          ellipsis: true,
          className: 'replacecolor'
        },
        {
          title: '部门',
          dataIndex: 'pushState',
          width: 120,
          ellipsis: true,
          className: 'replacecolor'
        },
        {
          title: '业务员',
          dataIndex: 'salesman',
          width: 120,
          ellipsis: true,
          className: 'replacecolor'
        },

        // {
        //   title: '小po',
        //   dataIndex: 'smallPo',
        //   width: 120,
        //   className: 'replacecolor'
        // },
        // {
        //   title: 'Pack Id',
        //   dataIndex: 'packId',
        //   width: 120,
        //   className: 'replacecolor'
        // },
        // {
        //   title: '分销点',
        //   dataIndex: 'distributionPoint',
        //   width: 120,
        //   className: 'replacecolor'
        // },
       
        //         {
        //   title: '创建时间',
        //   dataIndex: 'createTime',
        //   align: 'center',
        //   sorter: true,
        //   customRender: text => {
        //     return moment(text).format('YYYY-MM-DD')
        //   }
        // },
        // {
        //   title: '预发货日期',
        //   dataIndex: 'preDeliveryDate',
        //   width: 120,
        //   className: 'replacecolor'
        // },

        // {
        //   title: '计划到货日期',
        //   dataIndex: 'preCompletionDate',
        //   width: 120,
        //   className: 'replacecolor'
        // },
        {
          title: '存货名称',
          dataIndex: 'inventoryName',
          ellipsis: true,
          width: 180,
          className: 'replacecolor'
        },
        {
          title: '数量(合计)',
          dataIndex: 'shipmentQuantity',
          width: 120,
          ellipsis: true,
          className: 'replacecolor'
        },

        // {
        //   title: '单价(销售)',
        //   dataIndex: 'salesUnitPrice',
        //   width: 120,
        //   className: 'replacecolor'
        // },
        {
          title: '采购/委外订单号',
          dataIndex: 'purOrSubOrder',
          // width: 120,
          ellipsis: true,
          className: 'replacecolor'
        },
         {
          title: '制单人',
          dataIndex: 'createBy',
          // width: 120,
          ellipsis: true,
          className: 'replacecolor'
        },
        // {
        //   title: '订单类型',
        //   dataIndex: 'orderType',
        //   width: 120,
        //   className: 'replacecolor'
        // },
        // {
        //   title: '工厂单价(采购/委外单价)',
        //   dataIndex: 'factoryUnitPrice',
        //   width: 120,
        //   className: 'replacecolor'
        // },
        // {
        //   title: '申报要素(单证维护)',
        //   dataIndex: 'declarationElements',
        //   width: 140,
        //   customRender: t => ellipsis(t),
        //   className: 'replacecolor'
        // },

        // {
        //   title: '套装件数(存货自定义项)',
        //   dataIndex: 'numberOfSets',
        //   width: 120,

        //   className: 'replacecolor'
        // },
        // {
        //   title: '是否TC',
        //   dataIndex: 'isTC',
        //   width: 90,
        //   className: 'replacecolor'
        // },
        // {
        //   title: 'HScode',
        //   dataIndex: 'hsCode',
        //   width: 120,
        //   className: 'replacecolor'
        // },

        // {
        //   title: '中文品名',
        //   dataIndex: 'chineseName',
        //   width: 120,
        //   className: 'replacecolor'
        // },
        // {
        //   title: '英文品名',
        //   dataIndex: 'englishProductName',
        //   width: 120,
        //   className: 'replacecolor'
        // },
        // {
        //   title: '报关单价',
        //   dataIndex: 'customsDeclarationUnitPrice',
        //   width: 120,
        //   className: 'replacecolor'
        // }
      ],
      referShipDetailsData: [],
      confirmLoading: false,
      referShipDetailsModVis: false,

      // 查询条件
      queryParam: {
        pageNo: '', // 初始页
        status:'y'
      },
      pagination: {}
    }
  },
  // 接收父组件 方法
  props: {
    father: {
      type: Function,
      default: null
    }
  },
  created() {
  },
  methods: {
    getReferenceList() {
      this.$nextTick(() => {
        referenceList(this.queryParam).then(res => {
          if (res.success) {
            this.referShipDetailsData = res.result.records;
            this.pagination = {
              total: res.result.total,
              current: res.result.current,
              pageSize: res.result.size
            }
          }else{
              this.$message.error(res.message);
          }
        })
      })
    },
    // 弹框查询按钮
    searchQuery() {
       this.queryParam.pageNo = ''
       this.getReferenceList()
    },
    // 重置
    searchReset() {
      this.queryParam = {
        status:'y'
      }
      this.preDeliveryDate = []
      this.getReferenceList()
      // this.getShipmentList()
    },
    // 弹框确定
    onSubmit() {
       if (this.selectedRowKeys.length == 0) {
        this.$message.error('请选择数据');
      } else{
        this.$emit('callback', this.selectedRows);
        this.referShipDetailsModVis = false;
        var msg = "选中记录后，会清除编辑的内容。";
        this.$message.info(msg);        
        this.selectedRowKeys = [];
        this.selectedRows = []
      }
    },
    close() {
      this.$emit('close')
      this.queryParam = {
        status:'y'
      }
      this.preDeliveryDate = []
      this.referShipDetailsModVis = false
    },
    handleCancel() {
      this.selectedRowKeys = []
      this.close()
    },
    // 选中行
    onSelectChange(keys, rows) {
      var garmentFactoryArr = []
      rows.map(item =>garmentFactoryArr.push(item.garmentFactory) )
      garmentFactoryArr = [...new Set(garmentFactoryArr)]
      if(garmentFactoryArr.length>1){
        this.$message.info('必须选择相同成衣工厂，请重新选择！');        
        this.selectedRowKeys = []
        this.selectedRows = []
      }else{
        this.selectedRowKeys = keys
        this.selectedRows = rows
      }

    },
    handleTableChange(pagination, filters, sorter) {
      this.queryParam.pageNo = pagination.current
      this.getReferenceList()
    },
     onDateChange(value, dateString) {
      this.queryParam.startDate = dateString[0]
      this.queryParam.endDate = dateString[1]
    },
  },
  computed: {
    // 选中项
    rowSelection() {
      return {
        onChange: (selectedRowKeys, selectedRows) => {
          console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows)
        },
        getCheckboxProps: record => ({
          props: {
            disabled: record.title === 'Disabled User',
            // Column configuration not to be checked
            title: record.title
          }
        })
      }
    }
  }
}
</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>
