<!-- 条码打印 -->
<template>
  <div class="main-container order-mc-bg">
    <div class="sale-container">
      <!-- 列表 -->
      <div @click="createSaleOrder" class="sale-page-body">
        <!-- 表头 -->
        <div class="sale-page-table-header" ref="getSaleTableHeader">
          <el-form :inline="true" class="form-row1">
            <el-row class="form-row1">
              <el-col :span="20">
                <el-row :gutter="2">
                  <el-col :span="4">
                    <el-form-item label="采购组织">
                      <el-select clearable filterable placeholder="请选择部门" v-model="search.orgId">
                        <el-option class="f_12" label="全部" value="0"></el-option>
                        <el-option :key="item.name" :label="item.name" :value="item.id" class="f-12"
                          v-for="item in productDeptList"></el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="4">
                    <el-form-item class="Iisshow" label="采购订单">
                      <el-input class="f-12" placeholder="请输入订单号" v-model.trim="search.billNo"></el-input>
                      <div :data-clipboard-text="search.billNo" @click="saleOrderCopy" class="copyBtn">
                        <i class="el-icon-document-copy" />
                      </div>
                    </el-form-item>
                  </el-col>
                  <el-col :span="4">
                    <el-form-item class="Iisshow" label="物料">
                      <el-input class="f-12" placeholder="请输入物料/名称/规格型号" v-model.trim="search.productKey"></el-input>
                      <div :data-clipboard-text="search.productKey" @click="saleOrderCopy" class="copyBtn">
                        <i class="el-icon-document-copy" />
                      </div>
                    </el-form-item>
                  </el-col>
                </el-row>
              </el-col>
              <el-col :span="4" class="form-row-lastcol">
                <el-row :gutter="2">
                  <el-col :span="24">
                    <el-form-item class="form-group1">
                      <el-button @click="searchData" size="small" type="primary">搜索</el-button>
                      <el-button size="small" type="primary">重置</el-button>
                    </el-form-item>
                  </el-col>
                </el-row>
              </el-col>
            </el-row>
          </el-form>
        </div>
        <!-- 列表 -->
        <div class="sale-page-table-body">
          <el-table :data="tableData" :header-cell-class-name="headerRigthMethod" :header-cell-style="headerBg"
            :max-height="heightNum" @selection-change="handleSelectionChange" border class="table-box"
            element-loading-spinner="el-icon-loading" element-loading-text="加载中，请稍后..." ref="tableInfoRef"
            style="width: 100%;font-size:12px" v-loading="isLoading">
            <el-table-column align="left" fixed label="采购组织" prop="purchaseorgName"></el-table-column>
            <el-table-column align="left" fixed label="采购订单号" prop="billNo"></el-table-column>
            <el-table-column align="center" fixed label="确认状态" prop="confirmStatus" width="100"></el-table-column>
            <el-table-column align="center" label="关闭状态" prop="closeStatus" width="100">
              <template #default="scope">
                <span>{{ scope.row.closeStatus === 'A' ? '未关闭' : '已关闭' }}</span>
              </template>
            </el-table-column>
            <el-table-column align="left" label="物料编码" prop="materialNumber" />
            <el-table-column align="left" label="规格型号" prop="specification" />
            <el-table-column align="left" label="物料名称" prop="materialName" />
            <el-table-column align="right" label="采购数量" prop="qtyCount" width="100" />
            <!-- <el-table-column prop="materialName" label="条码打印数" align="left" width="100" /> -->
            <el-table-column align="center" label="操作" prop="specification" width="180">
              <template #default="scope">
                <span @click="getBarCode" class="text-blue">生成条码{{ scope.row.count }}</span>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
      <!-- 底部 -->
      <div class="sale-page-footer">
        <div class="footer-right">
          <el-pagination :currentPage="search.pageNo" :page-size="search.pageSize" :page-sizes="[50, 100, 150]"
            :total="orderTotal" @current-change="handleCurrentChange" @size-change="handleSizeChange"
            layout="slot,sizes,total, prev,pager, next,jumper" popper-class="每页显示">
            <span class="total-select-item">
              共选中
              <text style="text-align:center;color:#4178D5;padding:0 1px;">{{ selectItem }}</text>行
            </span>
          </el-pagination>
        </div>
        <div class="footer-pagination-total-page">
          <span>共{{ Math.ceil(orderTotal / search.pageSize) }}页</span>
        </div>
      </div>
    </div>
    <!-- 操作结果 -->
    <el-dialog title="操作结果" v-model="dialogVisible" width="40%">
      <div class="sale-page-table-body">
        <el-table :data="tableInfo" :header-cell-class-name="headerRigthMethod" border class="table-box" height="300"
          id="tableInfo-table">
          <el-table-column label="序号" prop="date" width="50">
            <template #default="scope">
              <span>{{ scope.$index + 1 }}</span>
            </template>
          </el-table-column>
          <el-table-column label="生产订单号" prop="orderNo" width="200"></el-table-column>
          <el-table-column label="指令" prop="a" width="110">
            <template #default>
              <span>{{ actionType === 'submit' ? '提交' : actionType === 'revoke' ? '撤销' : actionType === 'audit' ?
                '审核' : actionType === 'de-approval' ? '反审' : actionType === 'delet' ? '删除' : actionType === 'finish' ?
                  '完工' : actionType === 'close-case' ? '结案' : actionType === 'de-excute-start' ? '反执行至开工' : actionType ===
                    'de-approval' ? '反审' : actionType === 'delet' ? '删除' : actionType === 'finish' ? '完工' : actionType ===
                      'close-case' ? '结案' : actionType === 'de-excute-finish' ? '反执行至完工' : ''
              }}</span>
            </template>
          </el-table-column>
          <el-table-column label="结果" width="80">
            <template #default="scope">
              <span :style="{ 'txt-Red': scope.row.isSuccess }">{{ scope.row.isSuccess ? '成功' : '失败' }}</span>
            </template>
          </el-table-column>
          <el-table-column label="信息" prop="msg">
            <template #default="scope">
              <span class="txt-Red">{{ scope.row.msg }}</span>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <template #footer>
        <span class="dialog-footer">
          <span class="f-12 ext-black-light" style="margin-right: 25px;">共{{ tableInfo.length }}条</span>
          <el-button @click="handelhtmlToExcel('tableInfo-table', '操作结果'); dialogVisible = false" size="small">导
            出</el-button>
          <el-button @click="dialogVisible = false" size="small" type="primary">关 闭</el-button>
        </span>
      </template>
    </el-dialog>
    <!-- 生产条码抽屉一 -->
    <el-drawer :direction="direction" :with-header="true" size="80%" title="成品条码打印详情" v-if="1" v-model="drawer">
      <!-- 列表 -->
      <div @click="createSaleOrder" class="sale-page-body">
        <!-- 表头 -->
        <div class>
          <el-form :inline="true">
            <el-row>| SN条码生成</el-row>
            <el-row class="form-row1">
              <el-col :span="20">
                <el-row :gutter="2">
                  <el-col :span="4">
                    <el-form-item label="数量">
                      <el-input class="f-12" placeholder="请输入数量" v-model="number"></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="4" class="s-1">
                    <span>已生成 50 个</span>
                  </el-col>
                  <el-col :span="4">
                    <el-button @click="getSNList" size="small" type="primary">生成条码</el-button>
                  </el-col>
                </el-row>
              </el-col>
            </el-row>
          </el-form>
        </div>
        <!-- 列表 -->
        <div class="sale-page-table-body">
          <div>
            <el-form :inline="true">
              <el-row>| SN码明细信息</el-row>
            </el-form>
          </div>
          <div class="form-row1">
            <el-collapse :key="index" v-for="(item, index) in snObj" v-model="activesNames">
              <el-collapse-item name="1" title="Feedback">
                <template #title>
                  SN码数量：{{ item.count }} 生成时间：{{ item.createTime }}
                  <el-button style="margin-left:800px" type="text">一键打印</el-button>
                  <el-button @click="centerDialogVisible = true" type="text">重新生成</el-button>
                </template>
                <div>
                  <el-table :data="item.details" :header-cell-class-name="headerRigthMethod"
                    :header-cell-style="headerBg" :max-height="heightNum" @selection-change="handleSelectionChange"
                    border class="table-box" element-loading-spinner="el-icon-loading" element-loading-text="加载中，请稍后..."
                    style="width: 100%;font-size:12px" v-loading="isLoading">
                    <el-table-column align="center" fixed type="selection" width="40" />
                    <el-table-column align="left" fixed label="物料编码" prop="materialNumber"
                      width="390"></el-table-column>
                    <el-table-column align="left" fixed label="SN码" prop="serialNumber" width="400"></el-table-column>
                    <el-table-column align="left" label="装箱状态" prop="packingStatus" width="283"></el-table-column>
                    <el-table-column align="left" label="打印次数" prop="printCount" width="380" />
                  </el-table>
                </div>
              </el-collapse-item>
            </el-collapse>
          </div>
        </div>
      </div>
      <!-- 列表2 -->
      <div @click="createSaleOrder" class="sale-page-body">
        <!-- 表头 -->
        <div class>
          <el-form :inline="true">
            <el-row class="form-row1">| 箱唛基本信息</el-row>
            <el-row class="form-row1">
              <el-col :span="20">
                <el-row :gutter="2">
                  <el-col :span="4">
                    <el-form-item label="数量">
                      <el-input class="f-12" placeholder="请输入数量" v-model="xm.number"></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="2" class="s-1">
                    <span>已生成 50 个</span>
                  </el-col>
                  <el-col :span="5">
                    <el-form-item label="最小包装数">
                      <el-input class="f-12" placeholder="请输入" v-model="xm.miniPackingNumber"></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="5">
                    <el-form-item label="毛重(kg)">
                      <el-input class="f-12" placeholder="请输入" v-model="xm.roughWeight"></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="5">
                    <el-form-item label="净重(kg)">
                      <el-input class="f-12" placeholder="请输入" v-model.trim="xm.netWeight"></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="6">
                    <el-form-item label="包装尺寸(cm)  长">
                      <el-input class="f-12" placeholder="请输入" v-model.trim="xm.len"></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="4">
                    <el-form-item label="宽">
                      <el-input class="f-12" placeholder="请输入" v-model.trim="xm.width"></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="4">
                    <el-form-item label="高">
                      <el-input class="f-12" placeholder="请输入" v-model.trim="xm.height"></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
              </el-col>
              <el-col :span="4" class="form-row-lastcol">
                <el-row :gutter="2">
                  <el-col :span="24">
                    <el-form-item class="form-group1">
                      <el-button @click="getXMLists" size="small" type="primary">生成条码</el-button>
                      <el-button size="small">重置</el-button>
                    </el-form-item>
                  </el-col>
                </el-row>
              </el-col>
            </el-row>
          </el-form>
        </div>
        <!-- 列表 -->
        <div class="sale-page-table-body">
          <div>
            <el-form :inline="true">
              <el-row>| 箱唛明细信息</el-row>
              <el-row :gutter="2" class="form-row1">
                <el-col :span="6">
                  <el-form-item label="箱唛">
                    <el-input class="f-12" placeholder="请输入数量" v-model.trim="count"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="生成时间">
                    <el-time-select class="f-12" placeholder="选择时间" size="small" v-model="createTime"></el-time-select>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
          </div>
          <div>
            <el-collapse :key="index" v-for="(item, index) in boxObj" v-model="activeNames">
              <el-collapse-item name="2" title="Feedback">
                <template #title>
                  箱数：{{ item.count }} 单箱毛重(kg)：{{ item.roughWeight }} 箱规(cm)：{{ item.cartonSize }} {{ item.createTime }}
                  <el-button style="margin-left:800px" type="text">一键打印</el-button>
                  <el-button @click="dialogFormVisible = true" type="text">重新生成</el-button>
                </template>
                <div>
                  <el-table :data="item.details" :header-cell-class-name="headerRigthMethod"
                    :header-cell-style="headerBg" :max-height="heightNum" @selection-change="handleSelectionChange"
                    border class="table-box" element-loading-spinner="el-icon-loading" element-loading-text="加载中，请稍后..."
                    style="width: 100%;font-size:12px" v-loading="isLoading">
                    <el-table-column align="center" fixed type="selection" width="40" />
                    <el-table-column align="left" fixed label="箱唛" prop="boxNo" width="250"></el-table-column>
                    <el-table-column align="left" fixed label="物料编码" prop="materialNumber"
                      width="250"></el-table-column>
                    <el-table-column align="left" fixed label="物料69码" prop="barCode" width="250"></el-table-column>
                    <el-table-column align="left" label="本箱数量" prop="packingNumber" width="90"></el-table-column>
                    <el-table-column align="left" label="总数" prop="sumNumber" width="90" />
                    <el-table-column align="left" label="是否尾箱数" prop="isTailbox" width="160" />
                    <el-table-column align="left" label="SN起始" prop="snRange" width="185" />
                    <el-table-column align="left" label="打印次数" prop="printCount" width="180" />
                  </el-table>
                </div>
              </el-collapse-item>
            </el-collapse>
          </div>
        </div>
      </div>
      <!-- 底部 -->
      <el-dialog title="重新生成" v-model="dialogFormVisible">
        <el-form>
          <el-row :gutter="2">
            <el-col :span="4">
              <el-form-item label="数量">
                <el-input class="f-12" placeholder="请输入数量" v-model.trim="xm.number"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="5">
              <el-form-item label="最小包装数">
                <el-input class="f-12" placeholder="请输入" v-model.trim="xm.miniPackingNumber"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="5">
              <el-form-item label="毛重(kg)">
                <el-input class="f-12" placeholder="请输入" v-model.trim="xm.roughWeight"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="5">
              <el-form-item label="净重(kg)">
                <el-input class="f-12" placeholder="请输入" v-model.trim="xm.netWeight"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="6">
              <el-form-item label="包装尺寸(cm)  长">
                <el-input class="f-12" placeholder="请输入" v-model.trim="xm.len"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="4">
              <el-form-item label="宽">
                <el-input class="f-12" placeholder="请输入" v-model.trim="xm.width"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="4">
              <el-form-item label="高">
                <el-input class="f-12" placeholder="请输入" v-model.trim="xm.height"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <template #footer>
          <span class="dialog-footer">
            <el-button @click="dialogFormVisible = false">确定</el-button>
            <el-button @click="dialogFormVisible = false" type="primary">取消</el-button>
          </span>
        </template>
      </el-dialog>
    </el-drawer>
  </div>
</template>
<script>
import { mapState } from 'vuex'
import { orderCopy } from '@/utils/takeMethods'
import { transformTimestamp, htmlToExcel } from '@/utils/pubulic.js'
export default {
  name: 'SupplierCoordinationCodePrint',
  data () {
    return {
      dialogFormVisible: false,
      activeNames: '1', //手风琴1
      activesNames: true, //手风琴2
      drawer: false,

      //生成sn码
      number: '', //生成数量
      purDetailsId: '', //采购订单明细id
      //生成箱码
      xm: {
        purDetailsId: '', //采购订单明细id
        number: '', //生成数量
        miniPackingNumber: '', //最小装箱数量
        len: '', //尺寸长
        height: '', //尺寸高
        width: '', //尺寸宽
        roughWeight: '', //毛重
        netWeight: '' //净重
      },

      direction: 'rtl',
      // 自定义条件 订单类型 单据状态 供应组织 是否211 是否赠品 关闭状态
      statusForm: {
        customCondition: []
      },
      //条件
      value: '',
      //生成SN码
      sncodes: [
        {
          count: '', //SN码数量
          createTime: '', //生成时间
          details: []
        }
      ],
      //生成SN码明细
      snObj: [
        {
          count: '', //SN码数量
          createTime: '', //生成时间
          details: []
        }
      ],
      //生成箱码
      xmcodes: [
        {
          count: '', //箱码数量
          createTime: '', //生成时间
          roughWeight: '', //毛重
          netWeight: '', //净重
          cartonSize: '', //箱规
          details: []
        }
      ],
      //生成箱码明细
      boxObj: [
        {
          count: '', //箱码数量
          createTime: '', //生成时间
          roughWeight: '', //毛重
          netWeight: '', //净重
          cartonSize: '', //箱规
          details: []
        }
      ],

      CXcheckVal: null, // 查询选择
      dialogCX: false, // 选择查询弹框显示
      upOrDownList: [], // 上查下查弹窗可选数据
      OrdedetailIds: [], // 勾选的明细id集合
      OrderNoNames: [], // 选择的单据订单号集合
      OrderNoNameslist: [], // 上查下查的订单号
      OrderNoNameStr: '', // 上查下查的订单号str
      CXaction: '', // 判断是上查还是下查
      actionType: '', //判断点击的顶部那个按钮
      tableInfo: [], //操作结果
      isLoading: false, //表格加载数据
      documentStatuslist: [], // 单据状态
      pickmtDocumnetList: [], // 领料类型
      ids: [],
      btnType: [
        's-p-t-g1',
        'save',
        'print-aterial-list',
        'push-down',
        'close',
        'de-close',
        'split-order',
        'finish',
        'close-case',
        'de-excute-start',
        'de-excute-finish',
        'down-check'
      ], // 不需要显示的顶部按钮类型
      productDeptList: [], // 生产部门
      Time1: [],
      dialogVisible: false, // 操作弹框显示
      dialogxt: false, // 选择下推单据弹框显示
      // 搜索条件
      search: {
        orgId: '', // 组织id
        billNo: '', // 销售订单号
        number: '', // 领料状态
        is21: '', // 是否211 1 是 0 否
        producePickNo: '', // 领料单号
        pickDocumentType: '', // 生产领料订单类型
        workShopId: '', //生产部门
        documentStatus: '', //单据状态
        product: '', //产品 物料名称/编码/SKU
        orderBeginDate: '', // 下单开始日期
        orderEndDate: '', //下单结束日期
        pageNo: 1, // 页码
        pageSize: 50, // 页数
        purchaseOrgId: '', //采购组织
        productKey: '' //产品
      },
      applyNumber: '', // 生产数量统计
      realNumber: '', // 领套数量统计
      orderTotal: 0, // 未入库数量统计
      tableData: [],
      selectItem: 0,
      rowShow: false,
      heightNum: 0,
      windowHeight: 0,
      isDown: true,
      snCode: '',
      snTime: ''
    }
  },
  computed: {
    ...mapState({
      orgId: state => (state && state.org ? state.org.orgId : null),
      orgIdArr: state => (state && state.user ? state.user.orgIdArr : [])
    }),
    transformTime: function () {
      // 转换时间为 年-月-日
      return function (value) {
        return transformTimestamp(value)
      }
    }
  },
  created () {
    this.customerSel1 = 1
    this.windowHeight = document.documentElement.clientHeight
    this.heightNum = this.windowHeight - (40 + 30 + 54 + 34 + 34 + 34 + 16 + 16)
    this.search.orgId = this.orgId
    this.getProductdept()
    this.Init()
  },
  activated () {
    // 键盘监听事件
    document.addEventListener('keyup', this.keyupFn, false)
  },
  deactivated () {
    document.removeEventListener('keyup', this.keyupFn, false)
  },
  watch: {
    orgId (val) {
      this.search.orgId = val
    }
  },
  methods: {
    keyupFn (e) {
      if (e.keyCode === 13) {
        // enter见搜索
        this.searchData()
      }
    },
    // 初始化
    Init () {
      this.getcheckInfo()
      this.getgysPtrint()
    },
    // 生成条码
    getBarCode () {
      this.drawer = true
      this.$http.get('SupplierBarCode/CreateBarCode', this.search).then(res => { })
    },

    // 订单号 复制按钮
    saleOrderCopy () {
      orderCopy()
    },
    // 操作弹框导出
    handelhtmlToExcel (domid, title) {
      htmlToExcel(domid, title)
    },
    // 上下查数据
    getcheckInfo () {
      if (this.$route.query) {
        this.search.detailsIds = this.$route.query.detailsIds ? JSON.parse(decodeURIComponent(this.$route.query.detailsIds)) : []
        this.CXaction = this.$route.query.actionType === 'up' ? '上查' : '下查'
        let ordNostr = ''
        this.OrderNoNameslist = this.$route.query.OrderNoNames ? JSON.parse(decodeURIComponent(this.$route.query.OrderNoNames)) : []
        if (this.OrderNoNameslist) {
          this.OrderNoNameslist.forEach((it, index) => {
            if (index < 5) {
              ordNostr = ordNostr + it + ','
            }
          })
        }
        this.OrderNoNameStr = ordNostr
      }
    },
    //确定上下查
    submitCX () {
      if (this.CXcheckVal) {
        let pathName = ''
        if (this.CXcheckVal === 1) {
          // 生产订单
          pathName = 'ProductOrder'
        }
        if (pathName) {
          this.$router.push({
            name: pathName,
            query: {
              detailsIds: JSON.stringify(this.upOrDownList[0].detailsIds),
              actionType: 'up',
              actionName: '生产领料单',
              OrderNoNames: JSON.stringify(this.upOrDownList[0].billNos)
            }
          })
          this.dialogCX = false
        }
      } else {
        this.$message.error({ message: '请先选择在确认', showClose: true })
      }
    },
    // 自定义监听数据处理
    setselfChangeValue (customerSel1, customerSel2, customerSel3, key, compKey) {
      if (this[customerSel1] == undefined) {
        this[customerSel1] = key
      }
      if (this[customerSel1] == key) {
        return
      }
      if (this[customerSel1] == this[customerSel2] || this[customerSel1] == this[customerSel3]) {
        this[customerSel1] = key
        this[compKey] += 1
        this.$message.error({ message: '不能重复选择!', showClose: true })
      }
    },
    // 自定义选择赋值结果
    selfResult (result, fieldSale, fieldObj, tempObj) {
      this[fieldSale] = result.currVal
      this[fieldObj] = result.outResult

      if (JSON.stringify(this[fieldObj]) != '{}') {
        this[tempObj] = JSON.parse(JSON.stringify(this[fieldObj]))
        for (const key in this[fieldObj]) {
          this.search[key] = this[fieldObj][key]
        }
      } else {
        for (const key in this[tempObj]) {
          delete this.search[`${key}`]
        }
        this[tempObj] = null
      }

      if (this[fieldSale] == undefined || this[fieldSale] == '') {
        for (const key in this[tempObj]) {
          delete this.search[`${key}`]
        }
        this[tempObj] = null
      }
    },
    // 搜索切换高度
    openRow () {
      this.isDown = !this.isDown
      this.rowShow = !this.rowShow
      if (this.rowShow) {
        this.heightNum = this.heightNum - 80
      } else {
        this.heightNum = this.heightNum + 80
      }
    },
    // 点击生产订单查看或者是编辑
    jump (item) {
      // 只有创建和重新审核的单据才能做修改，其余都是查看
      let typeStr =
        item.documentStatusKey === 'a' ||
          item.documentStatusKey === 'd' ||
          item.documentStatus === '重新审核' ||
          item.documentStatus === '创建'
          ? 'edit'
          : 'see'
      if (typeStr === 'edit') {
        this.$router.push({ name: 'AddProductPickOrder', query: { type: typeStr, productId: item.id } })
      } else {
        this.$router.push({ name: 'AddProductPickOrder', query: { type: typeStr, productId: item.id } })
      }
    },
    // 获取部门数据
    getProductdept () {
      this.$http.post('SysConfig/GetDept/' + this.orgId).then(res => {
        if (res.status === 200) {
          this.productDeptList = res.data
        }
      })
    },
    // 获取获取供应商条码打印列表数据
    getgysPtrint () {
      this.isLoading = true
      this.$http.post('SupplierBarCode/GetList', this.search).then(res => {
        if (res.status === 200) {
          this.isLoading = false
          this.tableData = res.data.list
          this.orderTotal = res.data.totalCount
          console.log('获取生产领料订单数据', res)
        }
      })
    },

    //生成SN
    getSNMa () {
      this.isLoading = true
      this.$http.post('SupplierBarCode/CreateSNCode').then(res => {
        if (res.status === 200) {
          this.isLoading = false
          this.sncodes = res.data
          this.orderTotal = res.data.total
          this.details = res.data.details
          console.log('获取生成的条码', res)
        }
      })
    },
    // 获取获取sn码明细列表数据
    getSNList () {
      this.isLoading = true
      this.$http.post('SupplierBarCode/GetSnDetails').then(res => {
        if (res.status === 200) {
          this.isLoading = false
          this.snObj = res.data
          this.orderTotal = res.data.total
          this.details = res.data.details
          console.log('获取箱码明细列表数据', res)
        }
      })
    },
    //生成箱码
    getXMa () {
      this.isLoading = true
      this.$http.post('SupplierBarCode/CreateBox').then(res => {
        if (res.status === 200) {
          this.isLoading = false
          this.tableData = res.data
          this.orderTotal = res.data.total
          this.details = res.data.details
          console.log('获取生成的箱码', res)
        }
      })
    },
    // 获取获取箱码明细列表数据
    getXMLists () {
      // alert('true one --->', activeNames)
      this.isLoading = true
      this.$http.post('SupplierBarCode/GetBoxDetails', this.xm).then(res => {
        if (res.status === 200) {
          this.isLoading = false
          this.boxObj = res.data
          this.orderTotal = res.data.total
          this.details = res.data.details
          console.log('获取箱码明细列表数据', res)
        }
      })
    },
    // 顶部公共按钮操作
    actionhandel (type) {
      this.actionType = type
      // 点击新增
      if (type === 'add') {
        this.$router.push({ name: 'AddProductPickOrder', query: { type: 'add', id: '' } })
      }
      if (this.multipleSelection && this.multipleSelection.length > 0) {
        let nweArysize = 0
        let newArry = [
          ...new Set(
            this.multipleSelection.map(item => {
              return item.id
            })
          )
        ]
        // 取单据订单号
        let orderNoArry = [
          ...new Set(
            this.multipleSelection.map(item => {
              return item.producePickNo
            })
          )
        ]
        this.OrderNoNames = []
        this.OrderNoNames = orderNoArry
        // 明细id集合 （有去重）
        let detailsIds = [
          ...new Set(
            this.multipleSelection.map(item => {
              return item.detailId
            })
          )
        ]
        this.OrdedetailIds = []
        this.OrdedetailIds = detailsIds
        // 单据id 集合的size
        nweArysize = new Set(
          this.multipleSelection.map(item => {
            return item.id
          })
        ).size
        // 点击复制
        if (type === 'copy') {
          if (nweArysize !== 1 && nweArysize > 0) {
            this.$message.error({ message: '只能克隆单号相同的生产订单', showClose: true })
          } else {
            this.$router.push({
              name: 'EditProductPickOrder',
              query: {
                type: 'copy',
                productId: this.multipleSelection[0].id
              }
            })
          }
        }
        // 点击提交
        if (type === 'submit') {
          // 批量提交 只允许提交状态为创建
          this.toolarFn('ProducePick/CommitList', newArry)
        }
        // 点击撤销
        if (type === 'revoke') {
          this.toolarFn('ProducePick/Revoke', newArry)
        }
        // 点击审核
        if (type === 'audit') {
          this.toolarFn('ProducePick/Check', newArry)
        }
        // 点击反审核
        if (type === 'de-approval') {
          this.toolarFn('ProducePick/NoCheck', newArry)
        }
        // 点击删除
        if (type === 'delet') {
          this.toolarFn('ProducePick/Delete', newArry)
        }
        // 点击查询上查
        if (type === 'up-check') {
          this.$http.post('ProducePick/Upper', { ids: detailsIds }).then(res => {
            if (res.status === 200) {
              this.upOrDownList = res.data
              this.dialogCX = res.data && res.data.length > 0 ? true : false
              this.CXcheckVal = res.data && res.data.length === 1 ? res.data[0].orderType : null //只有一个，就个默认值
            }
            console.log('上查', res)
          })
        }
      } else {
        if (type !== 'add' && type !== 'refresh') {
          this.$message.error({ message: '请先勾选', showClose: true })
        }
      }
      // 点击刷新
      if (type === 'refresh') {
        this.getgysPtrint()
      }
    },
    // 顶部操作方法
    toolarFn (path, newArry, detailsIds) {
      let formdata = detailsIds
        ? {
          ids: newArry,
          detailsIds: detailsIds
        }
        : { ids: newArry }

      this.$http.post(path, formdata).then(res => {
        if (res.status === 200) {
          this.dialogVisible = true
          this.tableInfo = res.data
          this.search.pageNo = 1
          this.getgysPtrint()
        }
      })
    },
    // 下单日期改变
    time1Chang (value) {
      if (value && value.length > 0) {
        this.search.orderBeginDate = value[0]
        this.search.orderEndDate = value[1]
      } else {
        this.search.orderBeginDate = ''
        this.search.orderEndDate = ''
      }
    },
    // 搜索事件
    searchData () {
      this.search.pageNo = 1
      this.getgysPtrint()
    },
    //控制表头颜色
    headerBg ({ row, column, rowIndex, columnIndex }) {
      if (columnIndex === 17 || columnIndex === 18) {
        return `text-align:right!important;`
      }
    },
    headerRigthMethod ({ row, column, rowIndex, columnIndex }) {
      return 'headerRight'
    },
    handleSelectionChange (val) {
      this.multipleSelection = val
    },
    handleSizeChange (val) {
      this.search.pageNo = 1
      this.search.pageSize = val
      this.Init()
    },
    handleCurrentChange (val) {
      this.search.pageNo = val
      this.Init()
    }
  }
}
</script>
<style lang="scss" scoped>
@import '@/assets/style/saleOrder/saleOrderCommon.scss';
@import '@/assets/style/saleOrder/orderList.scss';
@import '@/assets/style/saleOrder/common.scss';

.s-1 {
  font-size: 12px !important;
  line-height: 35px;
}

.form-row1 {
  margin-top: 20px;
}
</style>