<template>
  <!-- 装箱单-成衣 -->
  <div id="clothesList">
    <!-- 查询 -->
    <a-card :bordered="false">
      <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-input placeholder="请输入订单号" v-model="queryParam.orderNumber"></a-input>
              </a-form-item>
            </a-col>

            <a-col :md="6" :sm="8">
              <a-form-item label="预托书号">
                <a-input placeholder="请输入预托书号" v-model="queryParam.depositaryReceiptNo"></a-input>
              </a-form-item>
            </a-col> 

            
            <a-col :md="6" :sm="8">
              <a-form-item label="分销点">
                <!-- <a-input placeholder="请输入分销点" v-model="queryParam.distributionPoint"></a-input> -->
                  <j-search-select-tag
                  placeholder="请选择分销点"
                  v-model="queryParam.distributionPoint"
                  dict="view_distributionpoint,distributionpoint,distributionpoint">
                </j-search-select-tag>
              </a-form-item>
            </a-col>
           
            
            <template v-if="toggleSearchStatus">
              <a-col :md="5" :sm="8">
                <a-form-model-item label="是否被参照">
                  <a-select v-model="queryParam.isReference">
                    <a-select-option value="">请选择</a-select-option>
                    <a-select-option value="1">是</a-select-option>
                    <a-select-option value="0">否</a-select-option>
                  </a-select>
                </a-form-model-item>
              </a-col>
              <a-col :md="6" :sm="8">
              <a-form-item label="账套号">
                 <j-search-select-tag
                  placeholder="请选择账套号"
                  v-model="queryParam.acSetNo"
                  dict="view_account,account,account">
                </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.shippingOrderNumber"></a-input>
                </a-form-item>
              </a-col>
             <!-- <a-col :md="6" :sm="8">
              <a-form-item label="品名">
                <a-input placeholder="请输入品名" v-model="queryParam.productName"></a-input>
              </a-form-item>
            </a-col> -->
               <a-col :md="6" :sm="8">
              <a-form-item label="小po">
                <a-input placeholder="请输入小po" v-model="queryParam.smallPo"></a-input>
              </a-form-item>
            </a-col>
            
            <a-col :md="6" :sm="8">
              <a-form-item label="款号">
                <a-input placeholder="请输入款号" v-model="queryParam.itemNumber"></a-input>
              </a-form-item>
            </a-col>
            
            <a-col :md="6" :sm="8">
              <a-form-item label="供应商">
                <!-- <a-input placeholder="请输入供应商" v-model="queryParam.garmentFactory"></a-input> -->
                <j-search-select-tag
                  placeholder="请选择供应商"
                  v-model="queryParam.garmentFactory"
                  dict="view_supplier,supplier,supplier">
                </j-search-select-tag>
              </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>
              <a-col :md="6" :sm="8">
                <a-form-item label="是否提交">
                  <a-select v-model="queryParam.status">
                    <a-select-option value="">请选择</a-select-option>
                    <a-select-option value="0">否</a-select-option>
                    <a-select-option value="1">是</a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="8">
                <a-form-model-item label="推送状态">
                  <a-select v-model="pushState" mode="multiple"  @change = "handleChange">
                    <a-select-option value="0">未推送</a-select-option>
                    <a-select-option value="1">推送成功</a-select-option>
                    <a-select-option value="2">推送失败</a-select-option>
                    <a-select-option value="3">推送中</a-select-option>
                    <a-select-option value="4">不在推送</a-select-option>
                  </a-select>
                </a-form-model-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>
    </a-card>

    <!-- 操作按钮区域 推送 导入 新增-->
    <a-card :bordered="false" style="marginTop:10px;">
      <div class="table-operator">
        <!-- <a-button type="primary" @click="openClothesAdd" icon="plus">新增</a-button> -->
        <a-button type="primary" @click="referadvancePackingList" icon="ordered-list">参照预装箱单</a-button>
        <!-- <a-button type="primary" @click="push" icon="export">推送</a-button> -->
        <a-button type="primary" @click="bitchSubmit" icon="check">批量提交</a-button>
        <a-button type="primary" @click="bitchCanelSubmit" icon="close">批量取消提交</a-button>
        <a-button type="primary" icon="download" @click="handleExportXls('装箱单-成衣')">装箱单成衣导出</a-button>
        <a-upload  name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl"  @change="handleImportExcel" :customRequest="uploadFlie">
          <a-button type="primary" icon="import">导入-来源预装箱单</a-button>
        </a-upload>
        <a-button type="primary" icon="download" @click="majorityDelet">批量删除</a-button>
        <a-button type="primary" icon="download" @click="majorityPush">批量推送</a-button>
      </div>

      <!-- table  rowKey="id"-->
      <a-table
        bordered
        :columns="clothesListColumns"
        :data-source="clothesListData"
        :loading="loading"
        :pagination="ipagination"
        :row-key="record => record.id"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
        @change="handleTableChange"
        :scroll="{ x: 1500, y: 600 }"
      >
        <!-- 集装箱号 输入框-->
        <!-- <a-form-model
          slot="containerNo"
          slot-scope="text, record"
          :ref="record.index"
          :model="record"
          style="width:100%;height:40px"
        >
          <a-form-model-item prop="containerNo">
            <a-input style="width:100%" v-model="record.containerNo" />
          </a-form-model-item>
        </a-form-model> -->

        <!-- 预托书号 -->
        <!-- <a-form-model
          slot="preBookNum"
          slot-scope="text, record"
          :ref="record.index"
          :model="record"
          style="width:100%;height:40px"
        >
          <a-form-model-item prop="preBookNum">
            <a-input style="width:100%" v-model="record.preBookNum" readOnly/>
          </a-form-model-item>
        </a-form-model> -->

        <!-- 状态 -->
        <!-- slot-scope="text, record" -->
        <span slot="stateSlot" slot-scope="text, record">
          <!-- v-if="record.isRelease == '0'" -->
           <a-tag color="orange" v-if="record.status == '0' || record.status == null">未提交</a-tag>
           <a-tag color="green" v-if="record.status == '1'">已提交</a-tag>
          <!-- <a-tag color="#87d068" v-else>已提交</a-tag> -->
        </span>

        <!-- 推送状态 -->
        <span slot="pushState" slot-scope="text, record" >
          <!-- v-if="record.isRelease == '0'" -->
          <a-tag color="#f50" v-if="record.pushState =='0'">未推送</a-tag>
          <a-tag color="green" v-if="record.pushState =='1'">推送成功</a-tag>
          <a-tag color="red" v-if="record.pushState =='2'">推送失败</a-tag>
          <a-tag color="blue" v-if="record.pushState == '3'">推送中</a-tag>
          <a-tag color="#B7B7B7" v-if="record.pushState == '4'">不再推送</a-tag>
          <!-- <a-tag color="#87d068" v-else>已提交</a-tag> -->
        </span>

        <!-- 发票推送状态 -->
        <span slot="timeStuta" slot-scope="text, record">
          <a-tag color="#f50" v-if="record.timeStuta == '0'">可推送</a-tag>
          <a-tag color="blue" v-if="record.timeStuta == '1'">推送中</a-tag>
          <a-tag color="red" v-if="record.timeStuta == '3'">推送失败</a-tag>
          <a-tag color="green" v-if="record.timeStuta == '2'">推送成功</a-tag>
          <a-tag color="B7B7B7" v-if="record.timeStuta == '4'">不可推送</a-tag>
        </span>

        <!-- 推送状态 -->
        <span slot="whetherCloudFactoryPush" slot-scope="text, record" :title ="record.cause">
           <span v-if="record.whetherCloudFactoryPush == '0'">否</span>
           <span v-if="record.whetherCloudFactoryPush == '1'">是</span>
        </span>

        <!-- 单据状态 -->
        <!-- <span slot="documentState"> -->
          <!-- v-if="record.isRelease == '0'" -->
          <!-- <a-tag color="#f50">提交</a-tag> -->
          <!-- <a-tag color="#87d068" v-else>已提交</a-tag> -->
        <!-- </span> -->

        <!-- 操作 -->
        <span slot="operationSlot" slot-scope="text, record">
          <a-upload  name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader"  :action="enclosureUrl"  @change="handleImportExcel" :data="{id:record.id}" >
            <a  style="color:green;" >附件上传</a>
        </a-upload>
          <a-divider type="vertical" />
          <!-- 未提交 -->
          <a-dropdown>
            <a class="ant-dropdown-link">更多<a-icon type="down"/></a>
            <a-menu slot="overlay" v-if="record.status == '0' || record.status == null">
              <!-- <a-menu-item><a @click="submit(record)">提交</a></a-menu-item> -->
              <a-menu-item><a @click="details(record)">详情</a></a-menu-item>
              <a-menu-item><a @click="edit(record)">编辑</a></a-menu-item>
              <!-- <a-menu-item><a @click="itemXls(record)">导出</a></a-menu-item> -->
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" ok-text="是" cancel-text="否" @confirm="handleDelete(record.id)">
                  <a href="javascript:void(0);" style="color:red;">删除</a>
                </a-popconfirm>
              </a-menu-item>
              <a-menu-item v-if="record.pushState!=='4'"><a @click="pushU8(record)">推送U8</a></a-menu-item>
              <a-menu-item v-if="record.pushState!=='4'"><a  @click="stopPush(record)">关闭推送</a></a-menu-item>
              <a-menu-item v-if="record.pushState  =='4'"><a  @click="stopPush(record)">取消关闭推送</a></a-menu-item>
            </a-menu>

            <!-- 已提交 -->
            <a-menu slot="overlay" v-if="record.status == '1'">
              <a-menu-item>
                <a @click="details(record)">详情</a>
              </a-menu-item>
              <a-menu-item v-if="record.pushState!=='4'"><a @click="pushU8(record)">推送U8</a></a-menu-item>
              <a-menu-item v-if="record.pushState!=='4'"><a @click="stopPush(record)">关闭推送</a></a-menu-item>
              <a-menu-item v-if="record.pushState =='4'"><a @click="stopPush(record)">取消关闭推送</a></a-menu-item>
              <!-- <a-menu-item><a @click="itemXls(record)">导出</a></a-menu-item> -->


              <!-- <a-menu-item>
                <a-popconfirm title="确定取消提交吗?" ok-text="是" cancel-text="否" @confirm="cancelSubmit(record)">
                  <a href="javascript:void(0);" style="color:red;">取消提交</a>
                </a-popconfirm>
              </a-menu-item> -->
              <!-- <a-menu-item>
                <a-popconfirm title="确定推送吗?" ok-text="是" cancel-text="否" @confirm="push(record)">
                  <a href="javascript:void(0);" style="color:green;">推送</a>
                </a-popconfirm>
              </a-menu-item> -->
            </a-menu>
          </a-dropdown>
        </span>
      </a-table>
       <span style="position: absolute;bottom: 4%;">共勾选{{selectedNumber}}条数</span>
    </a-card>

    <!-- 子表 -->

    <!-- 抽屉 -->
    <div>
      <clothesAdd-drawer ref="clothesAddDrawer" :fatherList="getSpltList" @ok="modalFormOk"></clothesAdd-drawer>
      <detailsClothes-drawer ref="detailsClothesDrawer" :father="bb" @ok="modalFormOk"></detailsClothes-drawer>
      <reference-pre-packlist ref="ReferencePrePacklist" @callback='referCallback'  @ok="modalFormOk"></reference-pre-packlist>
      <!-- <editClothes-drawer ref="editClothesDrawer" :father="cc" @ok="modalFormOk"></editClothes-drawer> -->
    </div>
    <!-- 导入确认框 -->
    <div>
      <a-modal :visible="visible" title="是否继续导入" @ok="handleOk" @cancel="handleCancel">
         <template #footer>
          <a-button  @click="handleCancel" style="margin-left: 8px;">取消</a-button>
          <a-button  type="primary"  @click="handleOk" :disabled="handleOkButton">确定</a-button>
        </template>
        <ul>
          <li v-for="(item,index) in message" :key="index">{{item}}</li>
        </ul>
      </a-modal>
    </div>
  </div>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { downFile } from '@/api/manage'
import JEllipsis from '@/components/jeecg/JEllipsis'
import ReferencePrePacklist from '@views/packing-list/packinglist-clothes/referencePrePacklist'
import clothesAddDrawer from '@views/packing-list/packinglist-clothes/clothesAddDrawer.vue'
import detailsClothesDrawer from '@views/packing-list/packinglist-clothes/detailsClothesDrawer.vue'
import editClothesDrawer from '@views/packing-list/packinglist-clothes/editClothesDrawer.vue'
import {bitchPush,cancelPush, spltList,deleteSpltList,spltListId,SubmitList,cancelSubmitList,bitchSubmitList,bitchCancelSubmitList,fileDetail,upload,pushOrderData,batchDelete} from '@api/document/packing-list/packinglist-clothes'


export default {
  name: 'ClothesList', // 装箱单-成衣
  mixins: [JeecgListMixin],
  components: { JEllipsis, clothesAddDrawer, detailsClothesDrawer, editClothesDrawer,ReferencePrePacklist,pushOrderData },
  data() {
    // let ellipsis = (v, l = 20) => <j-ellipsis value={v} length={l} /> // 省略

    return {
      // 表头
      clothesListColumns: [
         {
          title: '预托书号',
          dataIndex: 'depositaryReceiptNo',
          width: 150,
          ellipsis: true,
          fixed:'left',
          // scopedSlots: { customRender: 'preBookNum' },
          className: 'replacecolor'
        },
          {
          title: '托书号',
          dataIndex: 'shippingOrderNumber',
          width: 150,
          ellipsis: true,
          fixed:'left',
          className: 'replacecolor'
        }, 
        // {
        //   title: '集装箱代号',
        //   dataIndex: 'containerCode',
        //   width: 120,
        //   ellipsis: true,
        //   className: 'replacecolor'
        // },
        {
          title: '集装箱号',
          dataIndex: 'containerNumber',
          width: 100,
          ellipsis: true,
          // scopedSlots: { customRender: 'containerNo' },
          className: 'replacecolor'
        },
       
         {
          title: '订单号',
          dataIndex: 'orderNumber',
          width: 100,
          ellipsis: true,
          // fixed: 'left',
          className: 'replacecolor'
        },
         {
          title: '款号',
          ellipsis: true,
          dataIndex: 'itemNumber',
          width: 100,
          // fixed: 'left',
          className: 'replacecolor'
        },
        {
          title: '客户简称',
          dataIndex: 'customerAbbreviation',
          width: 100,
          ellipsis: true,
          // fixed: 'left',
          className: 'replacecolor'
        },
        {
          title: '预发货日期',
          dataIndex: 'hod',
          width: 120,
          ellipsis: true,
          className: 'replacecolor'
        },
        {
          title: '小po',
          dataIndex: 'smallPo',
          width: 120,
          ellipsis: true,
          className: 'replacecolor'
        },
        {
          title: '分销点',
          dataIndex: 'distributionPoint',
          width: 100,
          ellipsis: true,
          className: 'replacecolor'
        },
          {
          title: '数量',
          dataIndex: 'total',
          width: 80,
          ellipsis: true,
          className: 'replacecolor'
        },

        {
          title: '箱数',
          dataIndex: 'totalBoxes',
          width: 70,
          ellipsis: true,
          className: 'replacecolor'
        },
        {
          title: '总净重',
          dataIndex: 'totalNetWeight',
          width: 80,
          ellipsis: true,
          className: 'replacecolor'
        },
        {
          title: '总毛重',
          dataIndex: 'totalGrossWeight',
          width: 80,
          ellipsis: true,
          className: 'replacecolor'
        },

        {
          title: '总体积',
          dataIndex: 'totalVolume',
          width: 80,
          ellipsis: true,
          className: 'replacecolor'
        },

        // {
        //   title: '存货名称',
        //   dataIndex: 'inventoryName',
        //   width: 120,
        //   className: 'replacecolor'
        // },
        // {
        //   title: '颜色',
        //   dataIndex: 'colour',
        //   width: 120,
        //   className: 'replacecolor'
        // },
        {
          title: '采购/委外订单号',
          dataIndex: 'purchase',
          width: 140,
          ellipsis: true,
          className: 'replacecolor'
        },
        {
          title: '成衣工厂',
          dataIndex: 'garmentFactory',
          width: 100,
          ellipsis: true,
          // customRender: t => ellipsis(t),
          className: 'replacecolor'
        },
        // {
        //   title: '订单类型',
        //   dataIndex: 'orderType',
        //   width: 120,
        //   className: 'replacecolor'
        // },
        // {
        //   title: '工厂单价',
        //   dataIndex: 'factoryUnitPrice',
        //   width: 120,
        //   className: 'replacecolor'
        // },
      

        // {
        //   title: '总价',
        //   dataIndex: 'totalPrice',
        //   width: 120,
        //   className: 'replacecolor'
        // },

       

       

       

        // {
        //   title: '单据状态',
        //   dataIndex: 'theDocumentsState',
        //   width: 90,
        //   scopedSlots: { customRender: 'documentState' },
        //   className: 'replacecolor'
        // },
        // {
        //   title: '原因',
        //   dataIndex: 'cause',
        //   width: 180,
        //   customRender: t => ellipsis(t),
        //   className: 'replacecolor'
        // },

      
      

        {
          title: '外销发票号',
          dataIndex: 'exportInvoiceNo',
          width: 120,
          ellipsis: true,
          className: 'replacecolor'
        },
        
        {
          title: '单据号',
          dataIndex: 'documentNo',
          width: 140,
          ellipsis: true,
          className: 'replacecolor'
        },
        {
          title: '发票推送状态',
          dataIndex: 'timeStuta',
          width: 120,
          scopedSlots: { customRender: 'timeStuta' },
          className: 'replacecolor'
        },
        {
          title: '推送状态',
          dataIndex: 'pushState',
          width: 95,
          fixed: 'right',
          scopedSlots: { customRender: 'pushState' },
          className: 'replacecolor'
        },
        // {
        //   title: '云工厂',
        //   dataIndex: 'whetherCloudFactoryPush ',
        //   width: 85,
        //   fixed: 'right',
        //   scopedSlots: { customRender: 'whetherCloudFactoryPush' },
        //   className: 'replacecolor'
        // },

        {
          title: '单据状态',
          dataIndex: 'status',
          width: 95,
          fixed: 'right',
          scopedSlots: { customRender: 'stateSlot' },
          className: 'replacecolor'
        },

        {
          title: '操作',
          dataIndex: 'operation',
          scopedSlots: { customRender: 'operationSlot' },
          width: 160,
          fixed: 'right',
          className: 'replacecolor'
        }
      ],

      clothesListData: [],
      pushState:[],
      selectedNumber:0,//已选择条数
      selectedRowKeys: [], // 勾选航
      loading: false, // 表格加载
      visible:false,
      message:[],//导入文件信息
      file:{},//导入文件
      // 查询条件
      queryParam: {
        isReference:'0',
        pageSize:50,
        pageNo: '' // 初始页
      },
      preDeliveryDate:[],
      handleOkButton:false,
      url: {
        // syncUser: '/act/process/extActProcess/doSyncUser',
        list: '/sys/user/list',
        // delete: '/sys/user/delete',
        // deleteBatch: '/sys/user/deleteBatch',
        exportXlsUrl: '/sys/user/exportXls', // 导出
        importExcelUrl: '/splt/syPackingListTailoring/importExcel3' ,// 导入
        enclosureUrl:'splt/syPackingListTailoring/upload' //附件上传
      }
    }
  },
  created() {
    this.getSpltList()
  },
  watch:{
    selectedRowKeys(newVal){
       this.selectedNumber =newVal.length
    }
  },
  methods: {
    //分页查询
    getSpltList() {
     var that = this;
      this.$nextTick(() => {
        // this.queryParam.pageSize=50
         this.loading = true
        spltList(this.queryParam).then(res => {
           this.loading = false
          if (res.success) {
            that.clothesListData = res.result.records;
            that.clothesListData.map(item => {
              var str =item.hod
              var n=str.split(" ");
              item.hod = n[0]
        })
        this.selectedRowKeys = []
            that.ipagination = {
              total: res.result.total,
              current: res.result.current,
              pageSizeOptions: ["50", "100", "150"],
              pageSize: res.result.size
            }
          }else{
              that.$message.error(res.message);
          }
        })
      })
    },

    // 查询按钮
    searchQuery() {
       this.toggleSearchStatus = false
       this.queryParam.pageNo = ''
       this.getSpltList()
    },
    searchReset() {
      // console.log('>>>>重置')
      var dd = this.queryParam
      this.queryParam = {
        isReference:'0',
        pageSize:dd.pageSize
      }
      this.preDeliveryDate = []
      this.pushState = []
      this.getSpltList()
    },
    handleChange(data){
      this.pushState = data
      this.queryParam.pushState =data.length!==0? data.join():''
    },
    // 推送
    push() {},
     // 导入
    uploadFlie(file) {
      const formData = new FormData()
      formData.append('file', file.file)
      fileDetail(formData).then(res => {
        this.loading = false
        if (res.success) {
          this.visible = true
          this.message = res.message.split('；').filter((element) => {
             return element !== ""; 
          });
          this.file = file
        }else{
          this.$message.error(res.message);
        }
      })},
      //继续导入
      handleOk(){
        this.handleOkButton = true
         const formData = new FormData()
         formData.append('file', this.file.file)
         upload(formData).then(res => {
           this.visible = false
           if (res.success) {
             this.getSpltList()
             this.$message.success('导入成功')
             this.handleOkButton = false
           }else{
            this.$message.error(res.message);
            this.handleOkButton = false
        }
      })
      },
      //取消导入
      handleCancel(){
        this.visible = false
        this.loading = false
      },

    //批量提交
    bitchSubmit(){
      //  for(var i =0;i<this.selectedRows.length;i++){
      //       var tickRow = this.selectedRows[i]
      //       if(tickRow.status === '1'){
      //          this.$message.error("部分数据是已提交，请勿重复提交！");
      //           return
      //        }
      //  }
      var ids = this.selectedRowKeys.toString()
       bitchSubmitList({ids : ids}).then(res =>{
        if (res.success) {
            this.getSpltList()
            this.selectedRowKeys = []
            this.$message.success('提交成功');
          }else{
            this.$message.error(res.message);
          }
     })
    },

    //批量取消提交
    bitchCanelSubmit(){
      // for(var i =0;i<this.selectedRows.length;i++){
      //       var tickRow = this.selectedRows[i]
      //       if(tickRow.status === '0'){
      //          this.$message.error("含未提交数据，请重新选择！");
      //           return
      //        }
      //  }
      var ids = this.selectedRowKeys.toString()
       bitchCancelSubmitList({ids : ids}).then(res =>{
        if (res.success) {
            this.getSpltList()
            this.selectedRowKeys = []
            this.$message.success('取消提交成功');
          }else{
            this.$message.error(res.message);
          }
     })

    },
    majorityDelet(){
      var ids = this.selectedRowKeys.toString()
      batchDelete({ ids: ids }).then(res => {
          if (res.success) {
            this.$message.success('批量删除成功');
            this.getSpltList()
          }else {
            this.$message.error(res.message);
          }
        })
        this.selectedRowKeys = []
    },
     //批量推送
     majorityPush(){
      if(this.selectedRowKeys.length==0){
        this.$message.error('请勾选数据');
      }else{
      var ids = this.selectedRowKeys.toString()
      bitchPush({ids : ids}).then(res =>{
        this.clothesListData.map(item=>{
          this.selectedRowKeys.map(event=>{
            if(item.pushState!=='4'&&item.pushState!=='3'&&item.id==event){
              item.pushState = '3'
            }
          })
        })
        if (res.success) {
            this.getSpltList()
            this.selectedRowKeys = []
            this.$message.success(res.message);
          }else{
            this.getSpltList()
            this.$message.error(res.message);
          }
     })
    }
    },

    stopPush(record){
      cancelPush({id : record.id}).then(res =>{
        if (res.success) {
            this.getSpltList()
            this.$message.success('关闭推送成功');
          }else{
            this.$message.error(res.message);
          }
     })
    },
    pushU8(record){
      pushOrderData({ids : record.id}).then(res =>{
        if (res.success) {
            this.getSpltList()
            this.$message.success('推送U8成功成功');
          }else{
            this.getSpltList()
            this.$message.error(res.message);
          }
     })
    },
    // 导入
    importData() {},
    // 新增
    openClothesAdd() {
      console.log('新增-装箱单 成衣')
      this.$refs.clothesAddDrawer.visible = true
    },
    // --------------------------------------
    // 操作 附件上传
    accessoryUpload() {},

    // 列表导出
    handleExportXls(fileName) {
      var obj ={}
      if(this.selectedRowKeys.length == this.ipagination.pageSize || this.selectedRowKeys.length==this.clothesListData.length){
          obj=this.queryParam
          obj.selectAll = '1'
      }else{
        var arr =[]
        this.clothesListData.map(item=>{
          this.selectedRowKeys.map(e=>{
            if(item.id == e){
              arr.push(item.id)
            }
          })
        })
        obj.ids = arr.toString()
        obj.selectAll = '2'
      }
      downFile('/splt/syPackingListTailoring/exportXls',obj).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 + '.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', fileName + '.xlsx')
          document.body.appendChild(link)
          link.click()
          document.body.removeChild(link) // 下载完成移除元素
          window.URL.revokeObjectURL(url) // 释放掉blob对象
        }
      })
    },

     // 操作 单条数据导出
    itemXls(record) {
       downFile('/splt/syPackingListTailoring/exportXls',{id:record.id}).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' }), item + '.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', '装箱单' + '.xlsx')
          document.body.appendChild(link)
          link.click()
          document.body.removeChild(link) // 下载完成移除元素
          window.URL.revokeObjectURL(url) // 释放掉blob对象
        }
       })
    },

    // 操作 提交
    submit(record) {
     SubmitList({id:record.id}).then(res =>{
        if (res.success) {
            record.status=1;
            this.$message.success('提交成功');
          }else{
            this.$message.error(res.message);
          }
     })
    },

    //操作 取消提交
    cancelSubmit(record){
     cancelSubmitList({id:record.id}).then(res =>{
        if (res.success) {
            record.status=0;
            this.$message.success('取消提交成功');
          }else{
            this.$message.error(res.message);
          }
     })
    },
    // 操作 详情
    details(record) {
        spltListId({id:record.id}).then(res => {
           if (res.success) {
             var editData = res.result
             this.$refs.detailsClothesDrawer.visible = true
             this.$refs.detailsClothesDrawer.editDecide = 'edit';
             this.$refs.detailsClothesDrawer.dynamicColumns(editData.sizeTables)
             this.$refs.detailsClothesDrawer.clothesAdd = {
                orderNum:editData.orderNumber,
                styleNum:editData.itemNumber,
                name:editData.productName,
                englishProductName:editData.englishProductName,
                sizeRange:editData.sizeRange,
                customer:editData.customer,
                containerCode:editData.containerCode,
                containerNo:editData.containerNumber,
                note:editData.u8Remarks,
                clothesFactory:editData.garmentFactory,
                exportInvoiceNo:editData.exportInvoiceNo,
                bookNum:editData.shippingOrderNumber,
                id:editData.id,
                totalBoxes:editData.totalBoxes,
                totalGrossWeight:editData.totalGrossWeight,
                totalNetWeight:editData.totalNetWeight,
                totalVolume:editData.totalVolume,
                totalPrice:editData.totalPrice,
                depositaryReceiptNo:editData.depositaryReceiptNo,
                total:editData.total,
                recordingError:editData.recordingError 
            };
            this.$refs.detailsClothesDrawer.accessory = (editData.accessory!=='' && editData.accessory) ? (editData.accessory.split(",")) :[]
             this.$refs.detailsClothesDrawer.recordingCode = (editData.recordingCode!=='' && editData.recordingCode) ? (editData.recordingCode.split(";")) :[]
            this.$refs.detailsClothesDrawer.clothesAddData = editData.syPackingListTailoringItemList
             for (var i=0; i<res.result.syPackingListTailoringItemList.length;i++){
                 var row = res.result.syPackingListTailoringItemList[i];
                 var sizeTables = row.sizeTables;
                 for (var j=0; j<sizeTables.length;j++){
                  row['size-'+sizeTables[j].size] = sizeTables[j].proportion;
                 }
          }
           }
       })
    },
    // 操作 编辑
    edit(record) {
      console.log('编辑')
       spltListId({id:record.id}).then(res => {
           if (res.success) {
             var editData = res.result
             this.$refs.clothesAddDrawer.visible = true
             this.$refs.clothesAddDrawer.editDecide = 'edit';
             this.$refs.clothesAddDrawer.dynamicColumns(editData.sizeTables)
             this.$refs.clothesAddDrawer.clothesAdd = {
                orderNum:editData.orderNumber,
                styleNum:editData.itemNumber,
                name:editData.productName,
                englishProductName:editData.englishProductName,
                sizeRange:editData.sizeRange,
                customer:editData.customer,
                containerCode:editData.containerCode,
                containerNo:editData.containerNumber,
                note:editData.u8Remarks,
                clothesFactory:editData.garmentFactory,
                exportInvoiceNo:editData.exportInvoiceNo,
                bookNum:editData.shippingOrderNumber,
                id:editData.id, 
                totalBoxes:editData.totalBoxes,
                totalGrossWeight:editData.totalGrossWeight,
                totalNetWeight:editData.totalNetWeight,
                totalVolume:editData.totalVolume,
                totalPrice:editData.totalPrice,
                depositaryReceiptNo:editData.depositaryReceiptNo,
                total:editData.total
            };
            this.$refs.clothesAddDrawer.clothesAddData = editData.syPackingListTailoringItemList
             for (var i=0; i<res.result.syPackingListTailoringItemList.length;i++){
                 var row = res.result.syPackingListTailoringItemList[i];
                 var sizeTables = row.sizeTables;
                 for (var j=0; j<sizeTables.length;j++){
                  row['size-'+sizeTables[j].size] = sizeTables[j].proportion;
                 }
          }
           }
       })
      
    },
    // 操作 删除
    handleDelete(record) {
       console.log('点击删除项id:', record)
       this.$nextTick(() => {
         if(this.queryParam.pageNo > 1 && this.clothesListData.length === 1){
          this.queryParam.pageNo = this.queryParam.pageNo -1
        }
        deleteSpltList({ id: record }).then(res => {
          if (res.success) {
            this.getSpltList()
            this.$message.success('删除成功')
          } else {
            this.$message.error(res.message)
          }
       
        })
      })
    },
    onDateChange(value, dateString) {
      this.queryParam.stratDate = dateString[0]
      this.queryParam.endDate = dateString[1]
    },
      // 参照预装箱单
    referadvancePackingList() {
      console.log('打开参照订单数据')
      // 打开订单数据弹框
      this.$refs.ReferencePrePacklist.referencePrePacklist = true
      this.$refs.ReferencePrePacklist.queryParam = {}
      this.$refs.ReferencePrePacklist.advancePackingListData=[]
    },
    referCallback(){
      this.getSpltList()
    },
    // --------------------------------------
    // ??
    modalFormOk() {},
    // 选中行
    onSelectChange(keys, rows) {
      this.selectedRowKeys = keys
      this.selectedRows = rows
    },
    // --------------------------------------
    aa() {},
    bb() {},
    cc() {},
    // 分页、排序、筛选变化时触发
    handleTableChange(pagination, filters, sorter) {
      // console.log('当前页信息>>>>',pagination)
      this.queryParam.pageNo = pagination.current
      this.queryParam.pageSize = pagination.pageSize
      this.getSpltList()
    }
  },
  computed: {
    // 导入
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
    // 导入
    enclosureUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.enclosureUrl}`
    },
    // 选中项
    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
          }
        })
      }
    }
  },
  mounted() {}
}
</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;
// }
/deep/ .ant-table-tbody .ant-table-row td{
    padding-top: 8px;
    padding-bottom: 8px;
}
/deep/.ant-card-body{
padding-top: 10px !important;
padding-bottom: 0px !important;
}
/deep/.table-operator .ant-btn{
  margin: 0 8px 3px 0;
}
/deep/.table-page-search-wrapper .ant-form-inline .ant-form-item{
  margin-bottom: 10px;
}
/deep/.table-page-search-wrapper .table-page-search-submitButtons{
 margin-bottom: 10px;
}
/deep/ thead.ant-table-thead>tr{
      height: 0 !important;
}
/deep/ .ant-table-thead > tr > th, .ant-table-tbody > tr > td{
  padding: 9px 16px
}
/deep/ .ant-table-fixed-left table,.ant-table-fixed-right table{
  width: min-content;
}
</style>
