<!--成品维护页面-->
<template>
  <div class="systemBase product_wrap_xb">
    <div>
      <div style="margin-top: 10px; border-bottom: 1px solid #d5d5d5">
        <el-form ref="searchData" :inline="true" :model="searchForm">
          <el-form-item label-width="65px" prop="startTime" label="开始时间">
            <el-date-picker
              v-model="pageForm.startTime"
              clearable
              type="datetime"
              style="width: 180px"
              @change="dateChange(pageForm.startTime, 'startTime', 'search')"
              size="mini"
            ></el-date-picker>
          </el-form-item>
          <el-form-item label-width="65px" prop="endTime" label="结束时间">
            <el-date-picker
              v-model="pageForm.endTime"
              clearable
              type="datetime"
              style="width: 180px"
              @change="dateChange(pageForm.endTime, 'endTime', 'search')"
              size="mini"
            ></el-date-picker>
          </el-form-item>
          <el-form-item label-width="65px" label="产品名称">
            <el-select
              v-model="searchForm.productName"
              clearable
              filterable
              size="mini"
              style="width: 120px"
            >
              <el-option
                v-for="item in productList"
                :key="item.baseCode"
                :value="item.baseName"
                :label="item.baseName"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label-width="65px" label="批号">
            <el-input
              v-model="searchForm.batchNo"
              type="text"
              size="mini"
              style="width: 120px"
              clearable
            ></el-input>
          </el-form-item>
          <el-form-item label-width="65px" label="牌号">
            <el-select
              v-model="searchForm.gradeName"
              clearable
              filterable
              size="mini"
              style="width: 120px"
            >
              <el-option
                v-for="item in gradeList"
                :key="item.baseCode"
                :value="item.baseName"
                :label="item.baseName"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label-width="65px" label="标准">
            <el-select
              v-model="searchForm.standardNo"
              clearable
              filterable
              size="mini"
              style="width: 120px"
            >
              <el-option
                v-for="item in standardList"
                :key="item.baseCode"
                :value="item.baseCode"
                :label="item.baseName"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="计量点">
            <el-select
              v-model="searchForm.baseSpotNo"
              clearable
              size="mini"
              filterable
              style="width: 120px"
            >
              <el-option
                v-for="item in spotNameList"
                :key="item.baseSpotNo"
                :value="item.baseSpotNo"
                :label="item.baseSpotName"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label-width="65px" label="数据状态">
            <el-select
              v-model="searchForm.valueFlag"
              clearable
              size="mini"
              style="width: 120px"
            >
              <el-option
                v-for="item in flagList"
                :key="item.id"
                :value="item.id"
                :label="item.val"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label-width="20px">
            <el-button
              icon="el-icon-search"
              type="primary"
              size="mini"
              @click="queryData(1)"
              v-loading.fullscreen.lock="operateLoading"
              v-privilege="activeMenu + 'QUERY'"
              >查询</el-button
            >
          </el-form-item>
          <el-form-item label-width="20px">
            <el-button
              icon="el-icon-circle-plus-outline"
              type="primary"
              size="mini"
              @click="addData"
              v-loading.fullscreen.lock="operateLoading"
              v-privilege="activeMenu + 'ADD'"
              >新增</el-button
            >
          </el-form-item>
          <el-form-item label-width="20px">
            <el-button
              icon="el-icon-edit"
              type="primary"
              size="mini"
              @click="modifyData"
              v-loading.fullscreen.lock="operateLoading"
              v-privilege="activeMenu + 'PUT'"
              >修改</el-button
            >
          </el-form-item>
          <el-form-item label-width="20px">
            <el-button type="danger" size="mini" @click="discardData"
              >作废</el-button
            >
          </el-form-item>
          <el-form-item label-width="20px">
            <el-button type="primary" size="mini" @click="enableData"
              >启用</el-button
            >
          </el-form-item>
        </el-form>
      </div>
      <el-row>
        <div style="border-right: 1px solid #d5d5d5">
          <div
            style="
              display: flex;
              padding-left: 10px;
              padding-top: 10px;
              margin-bottom: 10px;
              margin-right: 20px;
              border-bottom: 1px solid #d5d5d5;
              height: 45px;
            "
          >
            成品秤计量数据
            <div style="margin-left: 40px">
              <!-- <el-button
                size="mini"
                type="primary"
                icon="el-icon-check"
                @click="enableData"
                v-loading.fullscreen.lock="operateLoading"
                v-privilege="activeMenu + 'RECOVERY'"
                >启用</el-button
              >
              <el-button
                size="mini"
                type="danger"
                plain
                icon="el-icon-remove-outline"
                @click="discardData"
                v-loading.fullscreen.lock="operateLoading"
                v-privilege="activeMenu + 'ABOLISH'"
                >废除</el-button
              > -->
            </div>
          </div>
          <div class="common-table-div">
            <el-table
              v-loading="dataLoading"
              @row-click="rowChange"
              :row-class-name="tableRowClassName"
              ref="dataTable"
              highlight-current-row
              border
              @selection-change="selectChange"
              :height="tableHeight"
              :data="dataList"
              :exchangeFilterMap="{
                storeName: { '1': '顶吹炉', '2': '闪速炉' },
                weightType: {
                  '0': '毛重',
                  '1': '常规皮重',
                  '2': '期限皮重',
                  '3': '历史皮重',
                  '4': '标识皮重',
                  '5': '自重皮重',
                },
              }"
              :icore-filter-flag="icoreFilterFlag"
            >
              <el-table-column
                type="index"
                label="序号"
                fixed="left"
                align="center"
              ></el-table-column>
              <el-table-column
                type="selection"
                width="55"
                fixed="left"
                align="center"
              ></el-table-column>
              <el-table-column
                sortable
                :show-overflow-tooltip="true"
                prop="actualNo"
                label="作业编号"
                min-width="110"
                align="center"
              ></el-table-column>
              <el-table-column
                sortable
                :show-overflow-tooltip="true"
                prop="productName"
                label="产品名称"
                min-width="80"
                align="left"
              ></el-table-column>
              <el-table-column
                sortable
                :show-overflow-tooltip="true"
                prop="batchNo"
                label="批号"
                min-width="80"
                align="left"
              ></el-table-column>
              <el-table-column
                sortable
                :show-overflow-tooltip="true"
                prop="gradeName"
                label="牌号"
                min-width="80"
                align="left"
              ></el-table-column>
              <el-table-column
                sortable
                :show-overflow-tooltip="true"
                prop="standardName"
                label="标准"
                min-width="120"
                align="left"
              ></el-table-column>
              <el-table-column
                sortable
                :show-overflow-tooltip="true"
                prop="packageNo"
                label="包号"
                min-width="80"
                align="left"
              ></el-table-column>
              <el-table-column
                sortable
                :show-overflow-tooltip="true"
                prop="sealNo"
                min-width="80"
                label="铅封号"
                align="left"
              ></el-table-column>
              <el-table-column
                sortable
                :show-overflow-tooltip="true"
                prop="bucketNo"
                min-width="80"
                label="桶号"
                align="left"
              >
              </el-table-column>
              <el-table-column
                sortable
                :show-overflow-tooltip="true"
                prop="blockNum"
                min-width="80"
                label="块数"
                align="left"
              ></el-table-column>
              <el-table-column
                sortable
                :show-overflow-tooltip="true"
                prop="referWeight"
                min-width="80"
                label="副秤重量"
                align="left"
              ></el-table-column>
              <el-table-column
                sortable
                :show-overflow-tooltip="true"
                prop="actualWeight"
                min-width="80"
                label="主秤重量"
                align="left"
              ></el-table-column>
              <el-table-column
                sortable
                :show-overflow-tooltip="true"
                prop="grossWeight"
                min-width="80"
                label="毛重"
                align="left"
              ></el-table-column>
              <el-table-column
                sortable
                :show-overflow-tooltip="true"
                prop="tareWeight"
                min-width="80"
                label="皮重"
                align="left"
              ></el-table-column>
              <el-table-column
                sortable
                :show-overflow-tooltip="true"
                prop="netWeight"
                min-width="80"
                label="净重"
                align="left"
              ></el-table-column>
              <el-table-column
                sortable
                :show-overflow-tooltip="true"
                prop="baseSpotName"
                min-width="80"
                label="计量点"
                align="left"
              ></el-table-column>
              <el-table-column
                sortable
                :show-overflow-tooltip="true"
                prop="createTime"
                min-width="140"
                label="生产日期"
                align="left"
              ></el-table-column>
              <el-table-column
                sortable
                :show-overflow-tooltip="true"
                prop="createManName"
                min-width="80"
                label="创建人"
                align="left"
              >
              </el-table-column>
              <el-table-column
                sortable
                :show-overflow-tooltip="true"
                prop="valueFlag"
                label="状态"
                min-width="100"
                align="center"
              >
                <template slot-scope="scope">
                  <span v-if="scope.row.valueFlag == 0">作废</span>
                  <span v-else-if="scope.row.valueFlag == 1">有效</span>
                </template>
              </el-table-column>
            </el-table>
          </div>
          <div class="common-foot-style">
            <!-- <div class="weight_wrap">
              <span>总车数：{{ wgtObj.sumCarNum }}车 </span>
              <span>总净重：{{ wgtObj.sumNetWgt }}kg </span>
              <span>平均净重：{{ wgtObj.avgWgt }}kg </span>
            </div> -->
            <el-pagination
              v-loading="dataLoading"
              @size-change="pageSizeChange"
              @current-change="pageCurrentChange"
              :current-page="pageForm.pageNum"
              :page-sizes="[50, 100, 200, 400]"
              :page-size="pageForm.pageSize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="pageForm.totalPage"
              style="display: inline-block"
            >
            </el-pagination>
          </div>
          <div
            ref="editTitle"
            class="common-title-div"
            style="margin-top: 20px; border-top: 1px solid #d5d5d5"
          >
            成品秤数据编辑区
          </div>
          <div ref="editDiv" class="commom-edit-div">
            <el-form
              ref="baseData"
              label-width="80px"
              :inline="true"
              :rules="formRules"
              :model="baseData"
              class="grab_edit_wrap"
            >
              <el-form-item prop="productName" label="产品名称">
                <el-select
                  v-model="baseData.productName"
                  clearable
                  filterable
                  size="mini"
                  style="width: 120px"
                  @change="
                    checkChange(
                      'baseData',
                      'productNo',
                      baseData.productName,
                      productList,
                      'baseName',
                      'baseCode'
                    )
                  "
                >
                  <el-option
                    v-for="item in productList"
                    :key="item.baseCode"
                    :value="item.baseName"
                  ></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="批次号" prop="batchNo">
                <el-input
                  v-model="baseData.batchNo"
                  style="width: 120px"
                  type="text"
                  size="mini"
                  clearable
                ></el-input>
              </el-form-item>
              <el-form-item label="牌号" prop="gradeName">
                <el-select
                  v-model="baseData.gradeName"
                  clearable
                  filterable
                  size="mini"
                  style="width: 120px"
                  @change="
                    checkChange(
                      'baseData',
                      'gradeNo',
                      baseData.gradeName,
                      gradeList,
                      'baseName',
                      'baseCode'
                    )
                  "
                >
                  <el-option
                    v-for="item in gradeList"
                    :key="item.baseCode"
                    :value="item.baseName"
                  ></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="标准" prop="standardName">
                <el-select
                  v-model="baseData.standardName"
                  clearable
                  filterable
                  size="mini"
                  style="width: 120px"
                  @change="
                    checkChange(
                      'baseData',
                      'standardNo',
                      baseData.standardName,
                      standardList,
                      'baseName',
                      'baseCode'
                    )
                  "
                >
                  <el-option
                    v-for="item in standardList"
                    :key="item.baseCode"
                    :value="item.baseName"
                  ></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="包号" prop="packageNo">
                <el-input
                  v-model="baseData.packageNo"
                  type="text"
                  size="mini"
                  style="width: 120px"
                  clearable
                ></el-input>
              </el-form-item>
              <el-form-item label="块数" prop="blockNum">
                <el-input
                  v-model="baseData.blockNum"
                  type="text"
                  style="width: 120px"
                  size="mini"
                  clearable
                ></el-input>
              </el-form-item>
              <el-form-item label="铅封号" prop="sealNo">
                <el-input
                  v-model="baseData.sealNo"
                  style="width: 120px"
                  type="text"
                  size="mini"
                  clearable
                ></el-input>
              </el-form-item>
              <el-form-item label="组合包号" prop="bucketNo">
                <el-input
                  v-model="baseData.bucketNo"
                  type="text"
                  style="width: 120px"
                  size="mini"
                  clearable
                ></el-input>
              </el-form-item>
              <el-form-item prop="grossWeight" label="毛重">
                <el-input
                  v-model="baseData.grossWeight"
                  readonly
                  size="small"
                  type="number"
                  style="width: 120px"
                  placeholder="请输入"
                ></el-input>
              </el-form-item>
              <el-form-item prop="tareWeight" label="皮重">
                <el-input
                  v-model="baseData.tareWeight"
                  size="small"
                  readonly
                  type="number"
                  style="width: 120px"
                  placeholder="请输入"
                ></el-input>
              </el-form-item>
              <el-form-item prop="netWeight" label="净重">
                <el-input
                  v-model="baseData.netWeight"
                  size="small"
                  readonly
                  type="number"
                  style="width: 120px"
                  placeholder="请输入"
                ></el-input>
              </el-form-item>
              <!-- <el-form-item prop="actualWeight" label="主秤重量">
                <el-input
                  v-model="baseData.actualWeight"
                  size="small"
                  clearable
                  readonly
                  type="number"
                  style="width: 120px"
                  placeholder="请输入"
                ></el-input>
              </el-form-item>
              <el-form-item prop="referWeight" label="副秤重量">
                <el-input
                  v-model="baseData.referWeight"
                  size="small"
                  clearable
                  readonly
                  type="number"
                  style="width: 120px"
                  placeholder="请输入"
                ></el-input>
              </el-form-item> -->
              <el-form-item prop="baseSpotName" label="计量点">
                <el-select
                  v-model="baseData.baseSpotName"
                  clearable
                  size="mini"
                  filterable
                  style="width: 120px"
                  @change="
                    checkChange(
                      'baseData',
                      'baseSpotNo',
                      baseData.baseSpotName,
                      spotNameList,
                      'baseSpotName',
                      'baseSpotNo'
                    )
                  "
                >
                  <el-option
                    v-for="item in spotNameList"
                    :key="item.baseSpotNo"
                    :value="item.baseSpotName"
                  ></el-option>
                </el-select>
              </el-form-item>
              <!-- <el-form-item prop="productDate" label="计量时间">
                <el-date-picker
                  type="datetime"
                  clearable
                  size="small"
                  style="width: 120px"
                  @change="
                    dateChange(
                      baseData.productDate,
                      'productDate',
                      'productDate'
                    )
                  "
                  v-model="baseData.productDate"
                ></el-date-picker>
              </el-form-item> -->
            </el-form>
          </div>
        </div>
      </el-row>
    </div>
  </div>
</template>
<script>
import { formatDate, getCookie } from '@/utils/util.js';
import { cookieUserId, cookieUserName } from '@/config/config.js';
import { recordChange } from '../../../../utils/utils'

let userId = getCookie(cookieUserId)
let userName = getCookie(cookieUserName)
export default {
  data () {
    let numberCheck = (rule, val, callback) => {
      let reg = /^(\d+)(\.\d+)?$/
      if (!reg.test(val)) {
        callback(new Error('计量重量需要为数字'))
      } else {
        callback()
      }
    }
    return {
      pageForm: {
        startTime: formatDate(new Date(), 'yyyy-MM-dd') + ' 00:00:00',
        endTime: formatDate(new Date(), 'yyyy-MM-dd') + ' 23:59:59',
        pageNum: 1,
        pageSize: 100,
        totalPage: 0
      },
      searchForm: {
        productNo: '',
        productName: '',
        batchNo: '',
        gradeNo: '',
        gradeName: '',
        standardNo: '',
        valueFlag: '1',
        baseSpotNo: ''
      },
      dataList: [],
      operateLoading: false,
      dataLoading: false,
      tableHeight: 500,
      icoreFilterFlag: true,
      baseData: {
        productName: '',
        batchNo: '',
        gradeName: '',
        standardName: '',
        packageNo: '',
        blockNum: '',
        grossWeight: 0,
        tareWeight: 0,
        netWeight: 0,
        // actualWeight: 0,
        // referWeight: 0,
        baseSpotName: '',
        baseSpotNo: '',
        productDate: '',
        sealNo: '',
        bucketNo: ''
      },
      baseDataCache: {
        productName: '',
        batchNo: '',
        gradeName: '',
        standardName: '',
        packageNo: '',
        blockNum: '',
        grossWeight: 0,
        tareWeight: 0,
        netWeight: 0,
        // actualWeight: 0,
        // referWeight: 0,
        baseSpotName: '',
        baseSpotNo: '',
        productDate: '',
        sealNo: '',
        bucketNo: ''
      },
      formRules: {
        productName: [{ required: true, message: '产品名称不能为空', trigger: 'blur' }],
        batchNo: [{ required: true, message: '批号不能为空', trigger: 'blur' }],
        packageNo: [{ required: true, message: '包号不能为空', trigger: 'blur' }],
        packageNo: [{ required: true, message: '计量点不能为空', trigger: 'blur' }]
      },
      flagList: [
        {
          id: '0',
          val: '作废'
        },
        {
          id: '1',
          val: '有效'
        }
      ],
      ctrlFlag: false,
      productList: [], // 产品list
      gradeList: [], // 牌号list
      standardList: [], // 标准list
      spotNameList: [], // 计量点list
      batchList: [],
      oldObj: {}
    }
  },
  created () {
    this.tableHeight = (window.innerHeight - 220) / 2 > 300 ? (window.innerHeight - 220) / 2 : 300
    this.activeMenu = window.top.localStorage.getItem('activeMenu')
    this.userNo = getCookie(cookieUserId)
    this.userName = getCookie(cookieUserName)
  },
  mounted () {
    let _this = this
    this.init()
    // // 监听页面的按键事件
    document.onkeydown = function (event) {
      // 判断 Ctrl
      if (event.ctrlKey) {
        if (!_this.ctrlFlag) {
          _this.ctrlFlag = true
          event.preventDefault();//取消默认行为
        }
      }
    }
    document.onkeyup = function (e) {
      if (e.ctrlKey) {
        _this.ctrlFlag = false;
        e.preventDefault();//取消默认行为
      }
    }
  },
  methods: {
    // 初始化
    init () {
      this.queryData();
      this.getProductList();
      this.getGradeList();
      this.getStandardList();
      this.getSpotNameList();
    },
    // 查询
    async queryData (flag = 1) {
      // 时间不能为空
      if (this.pageForm.startTime === '' || this.pageForm.endTime === '') {
        return this.$message.warning('时间不能为空')
      }
      if (this.pageForm.startTime instanceof Date) {
        this.pageForm.startTime = formatDate(this.pageForm.startTime)
      }
      if (this.pageForm.endTime instanceof Date) {
        this.pageForm.endTime = formatDate(this.pageForm.endTime)
      }
      if (flag === 1) {
        this.pageForm.pageNum = 1
      }
      // meterworkstorageactuals
      let paramStr = `pageNum=${this.pageForm.pageNum}&pageSize=${this.pageForm.pageSize}&createTime1=${this.pageForm.startTime}&createTime2=${this.pageForm.endTime}&productName=${this.searchForm.productName}&batchNo=${this.searchForm.batchNo}&gradeName=${this.searchForm.gradeName}&standardNo=${this.searchForm.standardNo}&valueFlag=${this.searchForm.valueFlag}&baseSpotNo=${this.searchForm.baseSpotNo}`
      const { data: res } = await this.axios.get(`pass/systemBase/v1/meterworkstorageactuals/like/?${paramStr}`)
      if (res && res.list) {
        this.dataList = [...res.list]
        this.pageForm.totalPage = res.total
      } else {
        this.dataList = []
        this.pageForm.totalPage = 0
      }
    },
    // 新增
    addData () {
      this.$refs.baseData.validate(async valid => {
        if (!valid) return this.$message.error('请规范填写数据')
        this.baseData.id = ''
        this.baseData.actualNo = ''
        this.baseData.predictionNo = ''
        this.baseData.createManName = userName
        this.baseData.createManNo = userId
        let param = {
          createManNo: userId,
          createManName: userName,
          operationPage: '成品车间计量数据维护页面',
          operationFunction: "新增",
          operationId: '',
          operationPredictionNo: '',
          operationCarnNo: '',
          operationBeforeFix: '',
          operationAfterFix: ''
        }
        const data = await this.axios.post('pass/systemBase/v1/meterworkstorageactuals/doAddWf', this.baseData, { individualType: 'json' })
        if (data.status === 'succeed') {
          param.id = data.data
          const log = await this.axios.post('pass/systemBase/v1/meterbaseoperationlogs/addList', [param], { individualType: 'json' })
          if (!log.succeed) {
            this.$message.error('新增日志保存失败');
          }
          this.queryData()
          this.$message.success('新增成功')
          this.baseData = { ...this.baseDataCache }
        } else {
          this.$message.error(data.message)
        }
      })
    },
    // 修改
    modifyData () {
      this.$refs.baseData.validate(async valid => {
        if (!valid) return this.$message.error('请规范填写数据')
        this.baseData.updateManNo = userId
        this.baseData.updateManName = userName
        // 记录修改的内容
        const { oldStr, newStr } = recordChange(this.oldObj, this.baseData)

        const param = {
          createManNo: userId,
          createManName: userName,
          operationPage: '成品车间计量数据维护页面',
          operationFunction: "修改",
          operationId: this.baseData.id,
          operationPredictionNo: '',
          operationCarnNo: '',
          operationBeforeFix: oldStr,
          operationAfterFix: newStr
        }

        const data = await this.axios.post('pass/systemBase/v1/meterworkstorageactuals/doUpdateWf', [{ ...this.baseData }], { individualType: 'json' })
        if (data.status === 'succeed') {
          const log = await this.axios.post('pass/systemBase/v1/meterbaseoperationlogs/addList', [param], { individualType: 'json' })
          if (!log.succeed) {
            this.$message.error('修改日志保存失败');
          }
          this.queryData()
          this.$message.success('修改成功')
          this.baseData = { ...this.baseDataCache }
        } else {
          this.$message.error(data.message)
        }
      })
    },
    // 作废
    discardData () {
      let flag = false
      if (this.batchList.length === 0) return this.$message.error('请选择要进行作废的数据')
      let ParamList = []
      this.batchList.forEach(item => {
        if (item.valueFlag === '0') {
          flag = true;
        }
        let param = {
          createManNo: userId,
          createManName: userName,
          operationPage: '成品车间计量数据维护页面',
          operationFunction: "作废",
          operationId: item.id,
          operationPredictionNo: item.predictionNo,
          operationCarnNo: '',
          operationBeforeFix: '',
          operationAfterFix: ''
        }
        ParamList.push(param)
      })
      if (flag) {
        this.$message.warning('请选择状态为有效的数据！');
        return false;
      }
      this.batchList.forEach(item => {
        item.valueFlag = '0'
        item.updateManNo = userId
        item.updateManName = userName
      })
      this.$confirm('确认要作废选中数据吗？').then(async () => {
        const data = await this.axios.post(`pass/systemBase/v1/meterworkstorageactuals/doUpdateWf`, [...this.batchList], { individualType: 'json' })
        if (data.status === 'succeed') {
          const res = await this.axios.post('pass/systemBase/v1/meterbaseoperationlogs/addList', ParamList, { individualType: 'json' })
          if (!res.succeed) {
            this.$message.error('记录作废日志失败');
          }
          this.queryData()
          this.$message.success('作废成功')
          this.closeDialog();
        } else {
          this.$message.error(data.message)
        }
      }).catch(() => { })
    },
    // 启用
    enableData (row) {
      if (this.batchList.length === 0) return this.$message.error('请选择要进行启用的数据')
      let flag = false
      let ParamList = []
      this.batchList.forEach(item => {
        if (item.valueFlag === '0') {
          flag = true;
        }
        let param = {
          createManNo: userId,
          createManName: userName,
          operationPage: '成品车间计量数据维护页面',
          operationFunction: "启用",
          operationId: item.id,
          operationPredictionNo: item.predictionNo,
          operationCarnNo: '',
          operationBeforeFix: '',
          operationAfterFix: ''
        }
        ParamList.push(param)
      })
      if (flag) {
        this.$message.warning('请选择状态为无效的数据！');
        return false;
      }

      this.batchList.forEach(item => {
        item.valueFlag = '1'
        item.updateManNo = userId
        item.updateManName = userName
      })
      this.$confirm('确认要启用选中数据吗？').then(async () => {
        const data = await this.axios.post(`pass/systemBase/v1/meterworkstorageactuals/doUpdateWf`, [...this.batchList], { individualType: 'json' })
        console.log(data, '启用返回结果')
        if (data.status === 'succeed') {
          const res = await this.axios.post('pass/systemBase/v1/meterbaseoperationlogs/addList', ParamList, { individualType: 'json' })
          if (!res.succeed) {
            this.$message.error('记录启用日志失败');
          }
          this.queryData()
          this.$message.success('启用成功')
          this.baseData = { ...this.baseDataCache }
        } else {
          this.$message.error(data.message)
        }
      }).catch(() => { })
    },
    selectChange (list) {
      this.batchList = []
      list.forEach(item => {
        this.batchList.push({ ...item })
      })
      // if (this.ctrlFlag) {
      //   this.ctrlFlag = false
      //   list.forEach(item => {
      //     let index = this.dataList.findIndex(iItem => iItem.actualNo === item.actualNo)
      //     if (index >= 0) {
      //       sList.push(index)
      //     }
      //   })
      //   // 数据起始index
      //   let list1 = this.dataList.slice(sList[0], sList[sList.length - 1] + 1)
      //   list1.forEach(item => {
      //     this.$refs.dataTable.toggleRowSelection(item, true)
      //   })
      // }
    },
    // 选择改变
    checkChange (formName, valName, val, list, compareName, getName) {
      let item = list.find(it => it[compareName] === val)
      if (item) {
        if (formName === 'baseData') {
          this.baseData[valName] = item[getName]
          console.log(this.baseData[valName], '编码')
        }
      }
    },
    // 产品
    async getProductList () {
      const { data: res } = await this.axios.get('pass/systemBase/v1/combaseinfos/noPage' + '?pBaseCode=001025' + '&validFlag=1')
      if (res) {
        this.productList = [...res]
      } else {
        this.productList = []
      }
    },
    // 牌号
    async getGradeList () {
      const { data: res } = await this.axios.get('pass/systemBase/v1/combaseinfos/noPage' + '?pBaseCode=001026' + '&validFlag=1')
      if (res) {
        this.gradeList = [...res]
      } else {
        this.gradeList = []
      }
    },
    // 标准
    async getStandardList () {
      const { data: res } = await this.axios.get('pass/systemBase/v1/combaseinfos/noPage' + '?pBaseCode=001027' + '&validFlag=1')
      if (res) {
        this.standardList = [...res]
      } else {
        this.standardList = []
      }
    },
    // 计量点
    async getSpotNameList () {
      this.axios.get('pass/systemBase/v1/meterbasespotinfos/noPage' + '?validFlag=1&spotTypeName=成品秤')
        .then(res => {
          this.spotNameList = [...res.data];
        })
    },
    // 行点击
    rowChange (row) {
      this.baseData = { ...row }
      this.oldObj = { ...row }
      this.$refs.dataTable.toggleRowSelection(row, true);
    },
    // 动态设置行样式
    tableRowClassName ({
      row,
      rowIndex
    }) {
      if (row.valueFlag === '0') {
        return 'error-row2';
      } else if (row.valueFlag === '1') {
        return ''
      }
      return '';
    },
    // 时间改变回调
    dateChange (val, name, model) {
      let time = ''
      if (val) {
        time = formatDate(val, 'yyyy-MM-dd HH:mm:ss')
      }
      if (model === 'productDate') {
        this.baseData[name] = time
      } else if (model === 'search') {
        this.pageForm[name] = time
      }
    },
    // 分页大小变化
    pageSizeChange (size) {
      this.pageForm.pageSize = size
      this.queryData()
    },
    // 分页跳转
    pageCurrentChange (pageNum) {
      this.pageForm.pageNum = pageNum
      this.queryData(0)
    }
  },
  watch: {
    'baseData.grossWeight': {
      handler: function (gross) {
        let reg = /^(-?\d+)(\.\d+)?$/
        if (!reg.test(gross - 0)) {
          this.baseData.grossWeight = 0
          return this.$message.error('毛重需要为数值')
        }
        if (gross - 0 !== 0) {
          this.baseData.netWeight = this.floatComputed(gross - 0, this.baseData.tareWeight - 0, '-')
        }
      }
    },
    'baseData.tareWeight': {
      handler: function (tare) {
        let reg = /^(-?\d+)(\.\d+)?$/
        if (!reg.test(tare - 0)) {
          this.baseData.tareWeight = 0
          return this.$message.error('毛重需要为数值')
        }
        if (tare - 0 !== 0) {
          this.baseData.netWeight = this.floatComputed(this.baseData.grossWeight - 0, tare - 0, '-')
        }
      }
    }
  }
}
</script>
<style>
.product_wrap_xb .el-table td {
  padding: 1px !important;
}

.grab_edit_wrap .el-input--suffix .el-input__inner {
  padding: 8px !important;
}

.weight_wrap {
  display: inline-block;
  text-align: left;
  font-weight: 500;
  font-size: 19px;
}

.exception_wrap .el-dialog__footer {
  text-align: center;
}
</style>