<!-- 供应商---采购订单管理 -->
<template>
  <div class="main-container order-mc-bg">
    <prtMoled :printData="{ tableData: multipleSelection, orderName: '采购订单管理' }" :theadDate="theadDate" v-show="false">
    </prtMoled>
    <div class="sale-container">
      <!-- 顶部按钮组 -->
      <toolBtn :btnType="btnType" @actionhandel="actionhandel"></toolBtn>
      <!-- 列表 -->
      <div class="sale-page-body">
        <!-- 表头 -->
        <div class="sale-page-table-header" ref="getSaleTableHeader">
          <el-form :inline="true">
            <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.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 label="确认状态">
                      <el-select @change="searchData" placeholder="请选择" v-model="search.confirmStatus">
                        <el-option label="全部" value></el-option>
                        <el-option :value="0" label="未确认"></el-option>
                        <el-option :value="1" label="已确认"></el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="4">
                    <el-form-item label="关闭状态">
                      <el-select @change="searchData" placeholder="请选择" v-model="search.closeStatus">
                        <el-option label="全部" value></el-option>
                        <el-option label="正常" value="a"></el-option>
                        <el-option label="已关闭" value="b"></el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="4">
                    <el-form-item label="产品">
                      <el-input class="f-12" placeholder="请输入物料名称/编码/SKU" style="width:200px"
                        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-col :span="4">
                    <el-form-item label="采购日期">
                      <el-date-picker @change="time1Chang" class="f-12" end-placeholder="结束时间" start-placeholder="开始时间"
                        type="daterange" v-model="Time1" value-format="YYYY-MM-DD"></el-date-picker>
                    </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="resetSearch" size="small">重置</el-button>
                      <el-button @click="searchData" 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" :max-height="heightNum"
            :row-class-name="tableRowClassName" @selection-change="handleSelectionChange" border class="table-box"
            ref="tableInfoRef" style="width: 100%;font-size:12px">
            <el-table-column align="center" fixed="left" type="selection" width="40" />
            <el-table-column align="left" label="采购组织" prop="purchaseorgName" width="172"></el-table-column>
            <el-table-column align="left" label="采购订单号" prop="billNo" width="187"></el-table-column>
            <el-table-column align="center" label="确认状态" prop="confirmStatus" width="72"></el-table-column>
            <el-table-column align="center" label="关闭状态" prop="mrpCloseStatus" width="72" />
            <el-table-column align="left" label="采购日期" prop="date" width="83" />
            <el-table-column align="left" label="期望交期" prop="deliveryDate" width="83" />
            <el-table-column align="left" label="物料编码" prop="materialNumber" width="172" />
            <el-table-column align="left" label="规格型号(SKU)" prop="specification" width="280" />
            <el-table-column align="left" label="物料名称" prop="materialName" width="150" />
            <el-table-column align="right" label="采购数量" prop="qtyCount" width="100" />
            <el-table-column align="right" label="累计已通知" prop="notified" width="100"></el-table-column>
            <el-table-column align="right" label="可通知" prop="notifiable" width="100" />
            <el-table-column align="right" label="已生产" prop="producedCount" width="100"></el-table-column>
            <el-table-column align="right" label="未生产" prop="notProducedCount" width="100"></el-table-column>
            <el-table-column align="right" label="已送货" prop="deliveredCount" width="100" />
            <el-table-column align="right" label="已收货" prop="stockinQtyCount" width="100" />
            <el-table-column align="right" label="未交" prop="remainStockinQtyCount" width="100" />
            <el-table-column align="right" label="可送货" prop="deliverableCount" width="100" />
            <el-table-column align="center" label="单位" prop="unitName" width="72" />
            <el-table-column align="right" label="含税单价" prop="taxPrice" width="100"></el-table-column>
            <el-table-column align="right" label="税率%" prop="taxRate" width="100">
              <template #default="scope">{{ (scope.row.taxRate = scope.row.taxRate === null ? 0 : scope.row.taxRate)
              }}</template>
            </el-table-column>
            <el-table-column align="right" label="价税合计（本位币)" prop="localCurrAllAmount" width="126"></el-table-column>
            <el-table-column align="left" label="付款条件" prop="paymentConditionName" width="120"></el-table-column>
            <el-table-column align="left" label="仓库" prop="stockName" width="120"></el-table-column>
            <el-table-column align="left" label="送货备注" prop="deliveryNote" width="280"></el-table-column>
            <el-table-column align="left" label="销售订单备注" prop="note" width="280"></el-table-column>
            <el-table-column align="left" label="确认日期" prop="confirmeDate" width="83"></el-table-column>
            <el-table-column align="left" label="供应商" prop="supplierName" width="172"></el-table-column>
            <el-table-column align="center" fixed="right" label="订单下载" width="150">
              <template #default="scope">
                <span :class="{ 'text-blue': scope.row.contractId, 'text-gray ': !scope.row.contractId }"
                  @click="orderdownload(scope.row.contractId)" v-if="scope.row.confirmStatus === '已确认'">订单下载{{
                    scope.row.downloadsTotal ? '(' + scope.row.downloadsTotal + ')' : null
                  }}</span>
              </template>
            </el-table-column>
            <!-- <el-table-column label="条码打印" align="center" width="150" fixed="right">
              <template #default="scope">
                <span class="text-blue" v-if="scope.row.confirmStatus ==='已确认'">条码打印</span>
              </template>
            </el-table-column>-->
          </el-table>
        </div>
      </div>
      <!-- 底部 -->
      <div class="sale-page-footer">
        <div class="footer-left">
          <div>
            <span>采购数量:</span>
            <span class="sale-number-color">{{ qtyTotal }}</span>
          </div>
          <div>
            <span>已生产:</span>
            <span class="sale-number-color">{{ producedTotal }}</span>
          </div>
          <div>
            <span>已送货:</span>
            <span class="sale-number-color">{{ deliverableTotal }}</span>
          </div>
          <div>
            <span>已收货:</span>
            <span class="sale-number-color">{{ stockinQtyTotal }}</span>
          </div>
          <div>
            <span>可送货:</span>
            <span class="sale-number-color">{{ deliverableTotal }}</span>
          </div>
          <div>
            <span>价税合计(本位币):</span>
            <span class="sale-number-color">{{ allAmountTotal }}</span>
          </div>
        </div>
        <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;">{{
                multipleSelection?
              multipleSelection.length : 0
              }}</text>行
            </span>
          </el-pagination>
        </div>
        <div class="footer-pagination-total-page">
          <span>共{{ Math.ceil(orderTotal / search.pageSize) }}页</span>
        </div>
      </div>
    </div>
    <!-- 操作结果 -->
    <el-dialog :title="modelTitle" v-model="dialogVisible" width="85%">
      <div class="sale-page-table-body">
        <el-table :data="tableInfo.slice((modelPageNo - 1) * 10, modelPageNo * 10)"
          :header-cell-class-name="headerRigthMethod" border class="table-box" id="tableInfo-table"
          @cell-click="getRowCol" :cell-class-name="tableCellClassName" ref="tableInfoRef1" max-height="600">
          <el-table-column label="采购组织" prop="purchaseorgName" width="200"></el-table-column>
          <el-table-column label="采购订单号" prop="billNo" width="200"></el-table-column>
          <el-table-column label="物料编码" prop="materialNumber" width="180"></el-table-column>
          <el-table-column label="规格型号" prop="specification"></el-table-column>
          <el-table-column label="物料名称" prop="materialName" width="250"></el-table-column>
          <el-table-column label="采购数量" prop="qtyCount" v-if="actionType !== 'songhuo'" width="150"></el-table-column>
          <el-table-column label="期望交期" prop="deliveryDate" v-if="actionType === 'querenorder'" width="150">
          </el-table-column>
          <el-table-column label="已生产" prop="producedCount" v-if="actionType === 'scruku'"
            width="150"></el-table-column>
          <el-table-column prop="qty" v-if="actionType === 'scruku'" width="150">
            <template #header>
              <span class="iconfont icon-bianji1 iconfont-mg"></span>本次生产
            </template>
            <template #default="scope">
              <el-input :maxlength="11" v-if="scope.row.isqty" :id="'qty' + scope.$index"
                @blur="numberChage(scope.row.qty, scope.$index, scope.row, 'qty')"
                v-model.lazy="scope.row.qty"></el-input>
              <span v-else>{{ scope.row.qty }}</span>
            </template>
          </el-table-column>
          <el-table-column label="可送货" prop="deliverableCount" v-if="actionType === 'songhuo'" width="150">
          </el-table-column>
          <el-table-column prop="qty" v-if="actionType === 'songhuo'" width="100">
            <template #header>
              <span class="iconfont icon-bianji1 iconfont-mg"></span>本次送货
            </template>
            <template #default="scope">
              <el-input :maxlength="11" v-if="scope.row.isqty" :id="'qty' + scope.$index"
                @blur="numberChage(scope.row.qty, scope.$index, scope.row, 'qty')"
                v-model.lazy="scope.row.qty"></el-input>
              <span v-else>{{ scope.row.qty }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="readyQty" v-if="actionType === 'songhuo'" width="100">
            <template #header>
              <span class="iconfont icon-bianji1 iconfont-mg"></span>备品
            </template>
            <template #default="scope">
              <el-input :maxlength="11" v-if="scope.row.isreadyQty" :id="'readyQty' + scope.$index"
                @blur="numberChage(scope.row.readyQty, scope.$index, scope.row, 'readyQty')"
                v-model.lazy="scope.row.readyQty"></el-input>
              <span v-else>{{ scope.row.readyQty }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="remark" v-if="actionType === 'songhuo'" width="255">
            <template #header>
              <span class="iconfont icon-bianji1 iconfont-mg"></span>备注
            </template>
            <template #default="scope">
              <el-input :maxlength="2000" v-if="scope.row.isremark" :id="'remark' + scope.$index"
                v-model.lazy="scope.row.remark"
                @blur="numberChage(scope.row.remark, scope.$index, scope.row, 'remark')">
              </el-input>
              <span v-else>{{ scope.row.remark }}</span>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <template #footer>
        <div style="display:flex;justify-content: space-between;">
          <span class="dialog-footer">
            <!-- <el-button @click="handelhtmlToExcel('tableInfo-table',modelTitle);dialogVisible = false" size="small">导出</el-button> -->
            <el-button @click="dialogVisible = false" size="small" type="primary">关 闭</el-button>
            <!-- <el-button size="small" @click="dialogVisible = false">打印</el-button> -->
          </span>
          <span class="dialog-footer" style=" display: flex;align-items: center;">
            <el-pagination :currentPage="modelPageNo" :page-size="10" :total="tableInfo.length"
              @current-change="modelPageNoChange" layout="prev, pager, next, jumper,total" size="small"
              v-if="tableInfo.length > 10">
              <span class="total-select-item">
                共
                <text style="text-align:center;color:#4178D5;padding:0 1px;">{{ tableInfo.length }}</text>行
              </span>
            </el-pagination>
            <span class="total-select-item" style="font-size: 12px;margin-right: 20px;" v-else>
              共
              <text style="text-align:center;color:#4178D5;padding:0 1px; font-size:12px">{{ tableInfo.length }}</text>行
            </span>
            <el-button @click="modeMakeSure('querenorder')" size="small" type="primary"
              v-if="actionType === 'querenorder'">确认接收订单</el-button>
            <el-button @click="modeMakeSure('scruku')" size="small" type="primary" v-if="actionType === 'scruku'">确认生产入库
            </el-button>
            <el-button @click=" modeMakeSure('songhuo')" size="small" type="primary"
              v-if="actionType === 'songhuo'">确认送货
            </el-button>
          </span>
        </div>
      </template>
    </el-dialog>
  </div>
</template>
<script>
import { mapState } from 'vuex'
import { countMethodsUnitNumber } from '@/utils/count.js'
import { orderCopy } from '@/utils/takeMethods'
import { transformTimestamp, exporthandel, htmlToExcel, orderDownload, dateData, newprintPreview } from '@/utils/pubulic.js'
import { purchaseOrderMangePrint } from '@/utils/printPagekey.js'
export default {
  name: 'SupplierPurchaseOrderMange',
  data () {
    return {
      theadDate: JSON.parse(JSON.stringify(purchaseOrderMangePrint)), // 打印要的字段表
      modelTotal: 0, // 弹框分页
      modelTitle: '', // 弹框标题
      modelPageNo: 1, // 确认弹框的分页
      OrdeIds: [], // 勾选的id集合
      OrdedetailIds: [], // 勾选的明细id集合
      OrderNoNames: [], // 选择的单据订单号集合
      multipleSelection: [], // 列表选中
      actionType: '', //判断点击的顶部那个按钮
      tableInfo: [], //操作结果
      btnType: ['s-p-t-g1', 's-p-t-g2', 's-p-t-g3', 's-p-t-g4', 's-p-t-g6', 's-p-t-g11', 's-p-t-g12'], // 不需要显示的顶部按钮类型
      Time1: [],
      dialogVisible: false, // 操作弹框显示
      // 搜索条件
      search: {
        orgId: '', // 组织ID
        billNo: '', // 采购订单号
        confirmStatus: '', //确认状态
        closeStatus: '', //订单关闭状态： A 是未关闭,B 是已关闭
        productKey: '', //产品 物料名称/编码/SKU
        beginDate: '', // 下单开始日期
        endDate: '', //下单结束日期
        pageNo: 1, // 页码
        pageSize: 50 // 页数
      },
      salePrecisionNumber: [],
      isPrecision: [],
      isCount: [],
      unitData: [],
      qtyTotal: 0, //采购数量
      producedTotal: 0, //已生产
      deliveredTotal: 0, //已送货
      stockinQtyTotal: 0, //已收货
      deliverableTotal: 0, // 可送货
      allAmountTotal: 0, // 价税合计(本位币)
      orderTotal: 0, // 未入库数量统计
      tableData: [],
      selectItem: 0,
      rowShow: false,
      heightNum: 0,
      windowHeight: 0,
      isDown: true
    }
  },
  computed: {
    ...mapState({
      userInfo: state => (state && state.user && state.user.userInfo ? state.user.userInfo : {}),
      orgId: state => (state && state.org && state.org.orgId ? state.org.orgId : null)
    }),
    transformTime: function () {
      return function (value) {
        return transformTimestamp(value)
      }
    }
  },
  created () {
    this.windowHeight = document.documentElement.clientHeight
    this.heightNum = this.windowHeight - (40 + 30 + 54 + 34 + 34 + 34 + 16 + 16)
    this.search.orgId = this.userInfo.identity === 2 ? 0 : this.orgId
    this.Init()
  },
  activated () {
    // 键盘监听事件
    document.addEventListener('keyup', this.keyupFn, false)
  },
  deactivated () {
    document.removeEventListener('keyup', this.keyupFn, false)
  },
  watch: {
    dialogVisible (value) {
      if (!value) {
        this.tableInfo.forEach((it, index) => {
          Object.assign(it, { isqty: false, isreadyQty: false, isremark: false })
        })
      }
    },
    orgId (val) {
      if (val) {
        this.search.orgId = this.userInfo.identity === 2 ? 0 : val
        this.getPurchaseOrderMange()
      }
    }
  },
  methods: {
    keyupFn (e) {
      if (e.keyCode === 13) {
        // enter见搜索
        this.searchData()
      }
    },
    // 初始
    Init () {
      this.getUnit()
      this.getPurchaseOrderMange()
      this.getStatus()
    },
    tableCellClassName ({ row, column, rowIndex, columnIndex }) {
      row.index = rowIndex
      column.index = columnIndex
    },
    getRowCol (row, column, cell, event) {
      // 处理表格下拉框输入框显示隐藏
      this.tableInfo.forEach((it, index) => {
        Object.assign(it, { isqty: false, isreadyQty: false, isremark: false })
      })
      var showtagarry = ['isqty', 'isreadyQty', 'isremark']
      var parentshowtagarry = ['qty', 'readyQty', 'remark']
      showtagarry.forEach((k, idx) => {
        if (column.property == parentshowtagarry[idx]) {
          this.tableInfo[row.index][k] = true
          this.$nextTick(_ => {
            if (document.getElementById(column.property + row.index)) {
              document.getElementById(column.property + row.index).focus()
            }
          })
        }
      })
    },
    // 订单号 复制按钮
    saleOrderCopy () {
      orderCopy()
    },
    // 获取计量单位
    getUnit () {
      this.$http.get('SysConfig/GetUnitAllProperty').then(r => {
        if (r.status === 200) {
          this.unitData = r.data
        }
      })
    },
    numberPrecisionMethods (index, unit, S, P, C) {
      if (this.tableInfo[index][unit]) {
        let tempList = this.unitData.filter(it => it.id === this.tableInfo[index][unit])
        tempList[0].precision == 0 ? (this[P][index] = true) : (this[P][index] = false)
        tempList[0].precision == 0 ? (this[S][index] = 0) : (this[S][index] = tempList[0].precision)
      }
      this[P][index] = this[P][index] ? this[P][index] : false
      this[S][index] = this[S][index] || this[S][index] == 0 ? this[S][index] : 10
      if (!this[C][index]) {
        this[C][index] = 1
      }
    },
    // 数量改变时
    numberChage (val, index, item, key) {
      const _this = this
      // 判断条件 单位
      this.numberPrecisionMethods(index, 'unitId', 'salePrecisionNumber', 'isPrecision', 'isCount')
      if (val) {
        if (_this.isPrecision[index]) {
          if (val.toString().indexOf('.') !== -1 && _this.salePrecisionNumber[index] != 0) {
            _this.tableInfo[index][key] = Number(val).toFixed(0)
          }
          _this.tableInfo[index][key] = _this.tableInfo[index][key].toString().replace(/\D/g, '')
        } else {
          if (val.toString().indexOf('.') !== -1) {
            let tempList = _this.unitData.filter(it => it.id === _this.tableInfo[index].unitId)
            if (tempList && tempList.length > 0) {
              tempList[0].roundoffType = 2
            }
            let result = countMethodsUnitNumber(
              tempList,
              val,
              _this.tableInfo[index][key],
              _this.isCount[index],
              _this.salePrecisionNumber[index],
              true
            )
            _this.tableInfo[index][key] = result.value
            _this.isCount[index] = result.isDefault
          }

          let numD = ''
          let count = '\\d'
          for (let ind = 0; ind < _this.salePrecisionNumber[index]; ind++) {
            numD = numD + count
          }
          let reg = '/^(-)*(\\d+)\\.(' + numD + ').*$/'
          _this.tableInfo[index][key] = _this.tableInfo[index][key]
            .toString()
            .replace(/[^\d^\\.]+/g, '')
            .replace('.', '$#$')
            .replace(/\./g, '')
            .replace('$#$', '.')
            .replace(eval(reg), '$1$2.$3')
        }
      }
      let tempList = _this.unitData.filter(it => it.id === _this.tableInfo[index].unitId)
      let result = countMethodsUnitNumber(
        tempList,
        _this.tableInfo[index][key],
        _this.tableInfo[index][key],
        _this.isCount[index],
        _this.salePrecisionNumber[index],
        true
      )
      _this.tableInfo[index][key] = result.value
      _this.isCount[index] = result.isDefault
    },
    // 操作弹框导出
    handelhtmlToExcel (domid, title) {
      htmlToExcel(domid, title)
    },
    //重置
    resetSearch () {
      this.search = {
        orgId: this.userInfo.identity === 2 ? 0 : val, // 组织ID
        billNo: '', // 采购订单号
        confirmStatus: '', //确认状态
        closeStatus: '', //订单关闭状态： A 是未关闭,B 是已关闭
        productKey: '', //产品 物料名称/编码/SKU
        beginDate: '', // 下单开始日期
        endDate: '', //下单结束日期
        pageNo: 1, // 页码
        pageSize: 50 // 页数
      }
      this.Time1 = []
      this.getPurchaseOrderMange()
    },
    // 订单下载
    orderdownload (contractId) {
      orderDownload('SupplierPurchase/OrderDownload/', contractId, '采购订单.pdf')
    },
    // 确认弹框
    modeMakeSure (type) {
      // querenorder songhuo scruku
      let idsarry = []
      this.multipleSelection.forEach(it => {
        idsarry.push(it.id)
      })
      if (this.actionType === 'querenorder') {
        if (idsarry.length > 0) {
          this.$http.post('SupplierPurchase/confirm', { ids: idsarry }).then(res => {
            if (res.status === 200) {
              this.dialogVisible = false
              this.search.pageNo = 1
              this.modelPageNo = 1
              this.getPurchaseOrderMange()
              this.$message.success({ message: '确认成功', showClose: true })
            }
          })
        }
      }
      let idsarry2 = []
      this.multipleSelection.forEach(it => {
        if (it.qty) {
          idsarry2.push({
            detailsId: it.detailsId,
            qty: it.qty
          })
        }
      })
      if (this.actionType === 'scruku') {
        if (idsarry2.length > 0) {
          this.$http.post('SupplierPurchase/produce', { data: idsarry2 }).then(res => {
            if (res.status === 200) {
              this.dialogVisible = false
              this.search.pageNo = 1
              this.modelPageNo = 1
              this.getPurchaseOrderMange()
              this.$message.success({ message: '确认成功', showClose: true })
            }
          })
        } else {
          this.$message.error({ message: '请先填写必要信息，在确认', showClose: true })
        }
      }
      let idsarry3 = []
      var tagsure = true
      this.multipleSelection.forEach(it => {
        if (it.qty == '' || it.qty == undefined || it.qty == null || it.readyQty == '' || it.readyQty == undefined || it.readyQty == null || ((it.readyQty ? it.readyQty : 0) > (it.qty ? it.qty : 0))) {
          if (((it.qty == null || it.qty == "") || it.readyQty == null || it.readyQty == "") && it.qty !== 0 && it.readyQty !== 0) {
            tagsure = false
          }
        }
        idsarry3.push({
          detailsId: it.detailsId,
          qty: it.qty,
          readyQty: it.readyQty,
          remark: it.remark
        })
      })
      if (this.actionType === 'songhuo') {
        if (!tagsure) {
          this.$message.error({ message: '本次送货和备品数量不能为空且备品数量不能大于本次送货数量', showClose: true })
        } else {
          this.$http.post('SupplierPurchase/delivery', { data: idsarry3 }).then(res => {
            if (res.status === 200) {
              this.dialogVisible = false
              this.search.pageNo = 1
              this.modelPageNo = 1
              this.getPurchaseOrderMange(idsarry3)
              this.$message.success({ message: '确认成功', showClose: true })
            }
          })
        }
      }
    },
    // 红色
    tableRowClassName ({ row, rowIndex }) {
      if (row.confirmStatus === '未确认') {
        return 'success-row'
      }
      return ''
    },
    //跳转打印
    toCodePrint () {
      this.$router.push({ path: '/supplier/coordination/codePrint' })
    },

    // 搜索切换高度
    openRow () {
      this.isDown = !this.isDown
      this.rowShow = !this.rowShow
      if (this.rowShow) {
        this.heightNum = this.heightNum - 80
      } else {
        this.heightNum = this.heightNum + 80
      }
    },
    // 获取需要状态列表---[单据状态，领料状态，业务状态]
    getStatus () {
      this.$http.get('ProduceOrder/GetStatus').then(r => {
        if (r.status === 200) {
          this.documentStatuslist = r.data.documentStatus
          this.pickmtStatuslist = r.data.pickmtStatus
          this.produceBusinessStatuslist = r.data.produceBusinessStatus
        }
      })
    },
    // 获取采购订单数据
    getPurchaseOrderMange (idsarry) {
      this.$http.post('SupplierPurchase/list', this.search).then(res => {
        if (res.status === 200) {
          if (idsarry && idsarry.length > 0) {
            // 送货备注显示， 不存数据库
            idsarry.forEach(it => {
              res.data.list.forEach(el => {
                if (it.detailsId === el.detailsId) {
                  el.deliveryNote = it.remark
                }
              })
            })
          }
          this.tableData = res.data.list
          this.orderTotal = res.data.totalCount
          this.qtyTotal = res.data.qtyTotal
          this.producedTotal = res.data.producedTotal
          this.deliveredTotal = res.data.deliveredTotal
          this.stockinQtyTotal = res.data.stockinQtyTotal
          this.deliverableTotal = res.data.deliverableTotal
          this.allAmountTotal = res.data.allAmountTotal
        }
      })
    },
    // 获取确认订单列表
    getmakeSurelist (newArry) {
      //弹框要显示勾选明细所属采购订单下的所有明细
      this.$http.post('SupplierPurchase/confirm/list', { ids: newArry, pageSize: 9999, pageNo: this.modelPageNo }).then(res => {
        if (res.status === 200) {
          res.data.forEach(it => {
            it.qtyCount = it.qty
          })
          this.tableInfo = res.data
        }
      })
    },
    // 顶部公共按钮操作
    actionhandel (type) {
      this.actionType = type
      if (this.multipleSelection && this.multipleSelection.length > 0) {
        let nweArysize = 0
        // 单据id集合 （有去重）
        let newArry = [
          ...new Set(
            this.multipleSelection.map(item => {
              return item.id
            })
          )
        ]
        this.OrdeIds = newArry
        // 取单据订单号
        let orderNoArry = [
          ...new Set(
            this.multipleSelection.map(item => {
              return item.produceNo
            })
          )
        ]
        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
        //按列表确认底单

        // 后台对接查询列表接口
        let tables = []
        let tables2 = []
        this.multipleSelection.forEach(it => {
          it.qty = null
          it.readyQty = ''
          it.remark = ''
          it.qtyCount = JSON.parse(JSON.stringify(it.qtyCount))
          if (it.confirmStatus === '未确认') {
            tables.push(it)
          } else {
            tables2.push(it)
          }
        })
        // 点击生产入库
        if (type === 'songhuo' || type === 'scruku') {
          if (tables2.length > 0) {
            if (type === 'scruku') {
              this.modelTitle = '采购订单列表：生产入库'
              this.dialogVisible = false
              this.dialogVisible = true
            }
            if (type === 'songhuo') {
              this.modelTitle = '采购订单列表：送货'
              this.dialogVisible = false
              this.dialogVisible = true
            }
            this.tableInfo = tables2
          } else {
            this.$message.error({
              message:
                type === 'scruku'
                  ? '已确认的订单才能生产入库，请重新选择后再试！'
                  : type === 'songhuo'
                    ? '已确认的订单才能送货，请重新选择后再试！'
                    : '',
              showClose: true
            })
          }
        }
        if (type === 'querenorder') {
          if (tables.length > 0) {
            // 确认订单
            this.modelTitle = '采购订单列表：未确认'
            this.dialogVisible = false
            this.dialogVisible = true
            this.tableInfo = this.multipleSelection
            this.getmakeSurelist(this.OrdeIds)
            // 点击生产入库
          } else {
            this.$message.error({ message: '只能确认未确认的订单，请重新选择后再试！', showClose: true })
          }
        }
        if (type === 'dayin') {
          this.multipleSelection = this.multipleSelection.sort(dateData('date', false))
          const newList = []
          for (const t of this.multipleSelection) {
            if (newList.find(c => c.purchaseorgName === t.purchaseorgName)) {
              continue
            }
            newList.push(t)
          }
          if (newList.length == 1) {
            setTimeout(() => {
              newprintPreview('采购订单管理')
            }, 200)
          } else {
            this.$message.error({ message: '只能选择同一组织的单据明细打印！', showClose: true })
          }
        }
      } else {
        //按列表字段导出,点击全部导出
        if (type !== 'add' && type !== 'refresh' && type !== 'daochu') {
          this.$message.error({ message: '请先勾选', showClose: true })
        }
      }
      if (type === 'daochu') {
        exporthandel('SupplierPurchase/Export', this.search)
      }
      // 点击刷新
      if (type === 'refresh') {
        this.getPurchaseOrderMange()
      }
    },
    // 下单日期改变
    time1Chang (value) {
      if (value && value.length > 0) {
        this.search.beginDate = value[0]
        this.search.endDate = value[1]
      } else {
        this.search.beginDate = ''
        this.search.endDate = ''
      }
      this.searchData()
    },
    // 搜索事件
    searchData () {
      this.search.pageNo = 1
      this.getPurchaseOrderMange()
    },

    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()
    },
    modelPageNoChange (val) {
      this.modelPageNo = val
    },
  }
}
</script>
<style lang="scss" scoped>
@import '@/assets/style/saleOrder/saleOrderCommon.scss';
@import '@/assets/style/saleOrder/orderList.scss';
@import '@/assets/style/saleOrder/common.scss';
</style>