<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="88px"
    >
      <el-form-item label="屠宰时间" prop="produceTime">
        <el-date-picker
          clearable
          v-model="queryParams.produceTime"
          type="date"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
          placeholder="请选择屠宰时间"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="血码" prop="slaughterCode">
        <el-input
          v-model="queryParams.slaughterCode"
          placeholder="请输入血码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="检疫证号" prop="animalCertNo">
        <el-input
          v-model="queryParams.animalCertNo"
          placeholder="请输入检疫证号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['app:porkSideProduce:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['app:porkSideProduce:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-refresh"
          size="mini"
          @click="handleCleanBind"
          v-hasPermi="['app:hookBind:clean']"
          >取消吊钩绑定</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="porkSideProduceList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="ID" align="center" prop="id" width="80" /> -->
      <el-table-column label="产品名称" align="center" prop="productName" width="120" />
      <el-table-column
        label="屠宰时间"
        align="center"
        prop="produceTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.produceTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="吊钩号" align="center" prop="hookNo" width="120" />
      <el-table-column label="血码" align="center" prop="slaughterCode" width="120" />
      <el-table-column label="检疫证号" align="center" prop="animalCertNo" width="150" />
      <el-table-column label="供应商" align="center" prop="supplierName" width="120" />
      <el-table-column label="肉商" align="center" prop="purchaserName" width="120" />
      <el-table-column label="吊钩类型" align="center" prop="hookName" width="120">
        <template slot-scope="scope">
          <span>{{ showValue(scope.row.hookName) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="吊钩扣重(kg)" align="center" prop="hookWeight" width="120">
        <template slot-scope="scope">
          <span>{{ showValue(scope.row.hookWeight) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="干损重量(kg)" align="center" prop="dryLossWeight" width="120">
        <template slot-scope="scope">
          <span>{{ showValue(scope.row.dryLossWeight) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="宰后重量(kg)" align="center" prop="finalWeight" width="120">
        <template slot-scope="scope">
          <span>{{ showValue(scope.row.finalWeight) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="识别器" align="center" prop="deviceName" width="160">
      </el-table-column>
      <el-table-column
        label="操作"
        fixed="right"
        width="180"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleView(scope.row)"
            >查看</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['app:porkSideProduce:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['app:porkSideProduce:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 血码对应多个批次选择 -->
    <el-dialog
      :title="'当前血码存在' + distributeList.length + '个可选择的批次'"
      :visible.sync="selectBatch"
      width="800px"
    >
      <el-row :gutter="20" style="height: 600px; overflow-y: scroll">
        <el-col :span="12" v-for="(item, i) in distributeList" :key="item">
          <el-descriptions
            :title="'信息-' + (i + 1)"
            direction="vertical"
            :column="4"
            border
          >
            <template slot="extra">
              <el-button type="primary" size="small" @click="selectThisBatch(i)"
                >选择</el-button
              >
            </template>
            <el-descriptions-item label="供应商">{{
              item.supplierName
            }}</el-descriptions-item>
            <el-descriptions-item label="肉商">{{
              item.purchaserName
            }}</el-descriptions-item>
            <el-descriptions-item label="血码" :span="2">{{
              item.slaughterCode
            }}</el-descriptions-item>
            <el-descriptions-item label="入场批次ID">
              {{ item.entranceBatchId }}
            </el-descriptions-item>
            <el-descriptions-item label="检疫证号">{{
              item.animalCertNo
            }}</el-descriptions-item>
          </el-descriptions>
        </el-col>
      </el-row>
    </el-dialog>
    <!-- 添加或修改白条生产记录对话框 -->
    <el-dialog :title="title" :visible.sync="open"  width="800px" append-to-body @close="closeDialog">
      <el-form
        ref="form"
        :model="form"
        :rules="rules"
        :disabled="isView"
        label-width="120px"
      >
        <el-row :gutter="20">
          <el-col :span="24">
            <el-form-item label="称重产线" prop="deviceSerial" v-if="!this.form.id">
              <el-radio-group v-model="deviceSerial" @input="selectLine">
                <el-radio
                  v-for="(item, i) in NFIDReaders"
                  :key="i"
                  :label="item.deviceSerial"
                  border
                  >{{ item.deviceName }}</el-radio
                >
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="产品名称" prop="productName">
              <el-input
                v-model="form.productName"
                placeholder="请输入产品名称"
                disabled
                style="width: 240px"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="生产时间" prop="produceTime">
              <el-date-picker
                clearable
                v-model="form.produceTime"
                type="datetime"
                format="yyyy-MM-dd HH:mm:ss"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="请选择生产时间"
                style="width: 240px"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>

        <el-form-item label="吊钩号" prop="hookNo">
          <el-input
            v-model="form.hookNo"
            placeholder="请输入吊钩号"

            class="large-input"
            style="width: 630px"
          />
        </el-form-item>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="血码" prop="slaughterCode">
              <el-select
                v-model="form.slaughterCode"
                filterable
                placeholder="请选择血码"
                @change="getDistribute()"
                style="width: 240px"
              >
                <el-option
                  v-for="item in slaughterRelationOptions"
                  :key="item.slaughterCode"
                  :label="item.slaughterCode"
                  :value="item.slaughterCode"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="检疫证号" prop="animalCertNo">
              <el-input
                v-model="form.animalCertNo"
                placeholder=""
                style="width: 240px"
                disabled
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="肉商" prop="purchaserName">
              <el-input
                v-model="form.purchaserName"
                placeholder=""
                style="width: 240px"
                disabled
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="供应商" prop="supplierName">
              <el-input
                v-model="form.supplierName"
                placeholder=""
                style="width: 240px"
                disabled
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="24">
            <el-form-item label="吊钩类型" prop="hookName">
              <el-radio-group v-model="form.hookName" @input="getHookType">
                <el-radio
                  v-for="(item, i) in hookOptions"
                  :key="i"
                  :label="item.hookName"
                  border
                  >{{ item.hookName }}</el-radio
                >
              </el-radio-group>
              <!-- <el-select
                v-model="form.hookName"
                filterable
                placeholder="请选择吊钩类型"
                @change="getHookType"
                style="width: 240px;"
              >
                <el-option
                  v-for="item in hookOptions"
                  :key="item.hookName"
                  :label="item.hookName"
                  :value="item.hookName"
                ></el-option>
              </el-select> -->
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="吊钩扣重(kg)" prop="hookWeight">
              <el-input
                v-model="form.hookWeight"
                placeholder="请输入吊钩扣重"
                @change="caclutateWeight"
                style="width: 240px"
                disabled
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="干损重量(kg)" prop="dryLossWeight">
              <el-input
                v-model="form.dryLossWeight"
                disabled
                style="width: 240px"
              />
              <span style="color: #f00; margin-left: 20px"
                >【当前干损比为：{{ this.dryLossRatio }}%】</span
              >
            </el-form-item>
          </el-col>
        </el-row>

        <SerialInput
          :inputVal="form.scaleWeight"
          :type="1"
          ref="SerialInputRef"
          :disabled="isView"
          @confirm="confirmWeight"
        />

        <el-form-item label="宰后重量(kg)" prop="finalWeight">
          <el-input
            v-model="form.finalWeight"
            class="large-input"
            style="width: 240px"
            disabled
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer" v-show="!isView">
        <el-button type="primary" size="large" @click="submitForm">确 定</el-button>
        <el-button size="large" @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listPorkSideProduce,
  getPorkSideProduce,
  delPorkSideProduce,
  addPorkSideProduce,
  updatePorkSideProduce,
} from "@/api/app/porkSideProduce";
import { listAllNFIDReader } from "@/api/app/NFIDReader";
import { unsubscribeRead } from "@/api/app/nfidReadRecord";
import { getHookBindDetail, cleanBind } from "@/api/app/hookBind";
import { getValidDistributeBatch } from "@/api/app/distributeBatch";
import { getAllHook } from "@/api/app/hook";
import { getAllSlaughterRelation } from "@/api/app/slaughterRelation";
import { getNowRatio } from "@/api/app/dryLossRatio";
import SerialInput from "@/components/weightSerial/index.vue";
import { getRandomString } from "@/utils/str";
import { isEmpty } from "@/utils/validate";
export default {
  name: "PorkSideProduce",
  components: {
    SerialInput,
  },
  data() {
    var validateNumber = (str) => {
      const regex =
        /^(?!0+\.00$)(?!.*\.\d{3,})(?:0?\.[1-9]\d?|0?\.0[1-9]|[1-9]\d{0,4}(?:\.\d{1,2})?)$/;
      const num = parseFloat(str);
      return regex.test(str) && num >= 0.01 && num <= 99999.99;
    };
    var valiWeight = (rule, value, callback) => {
      //包含小数的数字
      var msg = "范围(0.01~99999.99),两位小数";
      if (value && !validateNumber(value)) {
        callback(new Error(msg));
      } else {
        callback();
      }
    };
    return {
      //SSE
      emitter:null,
      clientId:"",
      deviceSerial:null,
      //串口信息
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 白条生产记录表格数据
      porkSideProduceList: [],
      hookOptions: [],
      slaughterRelationOptions: [],
      NFIDReaders: [],
      distributeList: [],
      dryLossRatio: 0,
      regexRule:
        /^(?!0+\.00$)(?!.*\.\d{3,})(?:0?\.[1-9]\d?|0?\.0[1-9]|[1-9]\d{0,4}(?:\.\d{1,2})?)$/,
      // 弹出层标题
      title: "",
      isView: false,
      // 是否显示弹出层
      open: false,
      selectBatch: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        animalCertNo: null,
        produceTime: null,
        slaughterCode: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        productName: [
          { required: true, message: "产品名称不能为空", trigger: "blur" },
        ],
        produceTime: [
          { required: true, message: "屠宰时间不能为空", trigger: "change" },
        ],
        hookNo: [
          { required: true, message: "吊钩号不能为空", trigger: "blur" },
        ],
        slaughterCode: [
          { required: true, message: "血码不能为空", trigger: "change" },
        ],
        supplierName: [
          { required: true, message: "供应商不能为空", trigger: "change" },
        ],
        purchaserName: [
          { required: true, message: "肉商不能为空", trigger: "change" },
        ],
        animalCertNo: [
          { required: true, message: "检疫证号不能为空", trigger: "change" },
        ],
        hookName: [
          { required: true, message: "吊钩类型不能为空", trigger: "change" },
        ],
        hookWeight: [
          { required: true, message: "吊钩类型不能为空", trigger: "change" },
        ],
        scaleWeight: [
          {
            required: true,
            message: "称显重量不能为空",
            trigger: "blur",
          },
          { validator: valiWeight, trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.getList();
    this.getHookOptions();
    this.getAllNFIDReader();
    this.getSlaughterRelationOptions();
  },
  mounted() {
    // 监听全局键盘事件
    document.addEventListener("keydown", this.handleGlobalKeyDown);
  },
  beforeDestroy() {
    // 组件销毁时移除监听
    document.removeEventListener("keydown", this.handleGlobalKeyDown);
  },
  methods: {
    handleGlobalKeyDown(event) {
      if (event.key === "Enter") {
        event.preventDefault(); // 阻止默认行为
        if(this.open && !this.isView){
          //弹窗已打开,并且是新增或修改的操作
          this.$refs.SerialInputRef.stopReader().then(()=>{
            this.submitForm();
          })
        }
      }

    },
    //选择识别的产线
    selectLine(){
      this.unSubNFIDRecord();
      this.subNFIDRecord();
    },
    //订阅识别记录
    subNFIDRecord(){
      console.log("订阅识别记录")
      if(isEmpty(this.clientId)){
        this.clientId = getRandomString(12);
      }

      let url = process.env.VUE_APP_BASE_API + "/app/NFIDReadRecord/subscribe/"+this.deviceSerial+"/"+this.clientId;
      this.emitter = new EventSource(url);

      this.emitter.onmessage = (event) => {
        console.log(event.data);
      };

      this.emitter.addEventListener(this.deviceSerial, (event) => {
        console.log(`[自定义事件] ${event.data}`);
        const data = JSON.parse(event.data);
       // this.form.produceTime = data.produceTime;
        this.form.deviceSerial = data.deviceSerial;
        this.form.hookNo = data.hookNo;
        this.form.slaughterCode = data.slaughterCode;
        this.form.entranceBatchId = data.entranceBatchId;
        this.form.distributeBatchId = data.distributeBatchId;
        this.form.supplierName = data.supplierName;
        this.form.purchaserName = data.purchaserName;
        this.form.animalCertNo = data.animalCertNo;

      });

      this.emitter.onerror = (error) => {
        console.error("SSE 错误:", error);
      };
    },
    //取消订阅
    unSubNFIDRecord(){
      console.log("取消订阅")
      if (this.emitter) {
        this.emitter.close();
        this.emitter = null;
        unsubscribeRead(this.deviceSerial,this.clientId )
      }
    },
    closeDialog(){
      this.unSubNFIDRecord();
      this.deviceSerial = null;
      this.clientId = null;
    },
    //获取全部白条产线
    getAllNFIDReader() {
      let param = {
        deviceSpot: "weight",
      };
      listAllNFIDReader(param).then((response) => {
        this.NFIDReaders = response.data;
      });
    },
    //空值显示 -
    showValue(value) {
      return value != null ? value : "-";
    },
    handleSerialRead(str) {
      console.log(str);
    },
    handleSerialLog(data) {
      console.log(data);
    },
    handleStatusMsg(data) {
      this.serialMsg = data;
    },
    //确认重量，接入串口数据，确定该数据
    confirmWeight(val) {
      this.form.scaleWeight = val;
      this.caclutateWeight();
    },
    //首次需要选择默认产线
    setDefaultDevice() {
      if(isEmpty(this.form.deviceSerial)){
        this.$set(this.form, "deviceSerial", this.NFIDReaders && this.NFIDReaders.length > 0
            ? this.NFIDReaders[0].deviceSerial
            : null,);
      }
    },
    //设置默认吊钩
    setDefaultHook() {
      this.hookOptions.forEach((item) => {
        if (item.defaultFlag) {
          console.log(item);
          this.$set(this.form, "hookName", item.hookName);
          this.$set(this.form, "hookWeight", item.hookWeight);
          this.caclutateWeight();
        }
      });
    },
    //计算数量
    caclutateWeight() {
      console.log("计算数量");
      let finalWeight =
        this.form.scaleWeight - this.form.hookWeight > 0
          ? this.form.scaleWeight - this.form.hookWeight
          : 0; //称的重量-挂钩重量
      let dryLossWeight = (finalWeight * this.dryLossRatio) / 100; //（称的重量-挂钩重量）*干损比例
      this.form.dryLossWeight = dryLossWeight.toFixed(2);
      //（称的重量-挂钩重量）-（称的重量-挂钩重量）*干损比例
      finalWeight =
        finalWeight - this.form.dryLossWeight > 0
          ? finalWeight - this.form.dryLossWeight
          : 0; //减去干损重量
      this.form.finalWeight = finalWeight.toFixed(2);
    },
    //获取当前干损比
    getRatio() {
      getNowRatio().then((response) => {
        if (response.data) {
          this.dryLossRatio = response.data.dryLossRatio
            ? response.data.dryLossRatio
            : 0;
        }
      });
    },
    getDistribute() {
      this.$set(this.form, "distributeBatchId", null);
      this.$set(this.form, "entranceBatchId", null);
      this.$set(this.form, "purchaserName", null);
      this.$set(this.form, "supplierName", null);
      this.$set(this.form, "animalCertNo", null);

      if (!this.form.slaughterCode) {
        return;
      }
      let param = {
        slaughterCode: this.form.slaughterCode,
      };
      getValidDistributeBatch(param).then((response) => {
        this.distributeList = response.data ? response.data : [];
        if (this.distributeList.length == 1) {
          this.selectThisBatch(0);
        } else if (this.distributeList.length > 1) {
          this.selectBatch = true;
        }
      });
    },
    selectThisBatch(i) {
      let res = this.distributeList[i];
      if (res) {
        this.$set(this.form, "distributeBatchId", res.id);
        this.$set(this.form, "purchaserName", res.purchaserName);
        this.$set(this.form, "supplierName", res.supplierName);
        this.$set(this.form, "animalCertNo", res.animalCertNo);
        this.$set(this.form, "entranceBatchId", res.entranceBatchId);
      }
      this.selectBatch = false;
    },
    getHookType(value) {
      let select = this.hookOptions.find((item) => item.hookName === value);
      //console.log(value);
      this.$set(this.form, "hookWeight", select ? select.hookWeight : null);
      this.caclutateWeight();
    },
    //使用失焦事件模拟识别的吊钩
    fillInput() {
      this.$set(this.form, "distributeBatchId", null);
      this.$set(this.form, "entranceBatchId", null);
      this.$set(this.form, "purchaserName", null);
      this.$set(this.form, "supplierName", null);
      this.$set(this.form, "animalCertNo", null);
      this.$set(this.form, "slaughterCode", null);
      if (!this.form.hookNo) {
        return;
      }
      getHookBindDetail(this.form.hookNo).then((response) => {
        if (response.data) {
          let data = response.data;
          this.$set(this.form, "distributeBatchId", data.distributeBatchId);
          this.$set(this.form, "entranceBatchId", data.entranceBatchId);
          this.$set(this.form, "purchaserName", data.purchaserName);
          this.$set(this.form, "supplierName", data.supplierName);
          this.$set(this.form, "animalCertNo", data.animalCertNo);
          this.$set(this.form, "slaughterCode", data.slaughterCode);
        }
      });
    },
    //血码清单
    getSlaughterRelationOptions() {
      getAllSlaughterRelation({}).then((response) => {
        this.slaughterRelationOptions = response.data;
      });
    },
    /** 查询吊钩清单 */
    getHookOptions() {
      getAllHook().then((response) => {
        this.hookOptions = response.data;
      });
    },
    /** 查询白条生产记录列表 */
    getList() {
      this.loading = true;
      listPorkSideProduce(this.queryParams).then((response) => {
        this.porkSideProduceList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        productName: "白条",
        produceTime: this.parseTime(new Date()),
        deviceSerial:null,
        hookNo: null,
        slaughterCode: null,
        supplierName: null,
        purchaserName: null,
        animalCertNo: null,
        distributeBatchId: null,
        entranceBatchId: null,
        hookName: null,
        hookWeight: null,
        scaleWeight: null,
        dryLossWeight: null,
        finalWeight: null,
      };
      this.resetForm("form");
      this.setDefaultHook();
      //this.setDefaultDevice();
      this.getRatio();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.isView = false;
      this.title = "添加白条生产记录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getPorkSideProduce(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.isView = false;
        this.title = "修改白条生产记录";
        //是否需要设置默认吊钩
        if (this.form.hookName == null && this.form.hookWeight == null) {
          this.setDefaultHook();
        }
      });
    },
    /** 查看按钮操作 */
    handleView(row) {
      this.reset();
      const id = row.id || this.ids;
      getPorkSideProduce(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.isView = true;
        this.title = "查看白条生产记录";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(async (valid) => {
        //检查重量是否输入
        const sonValid = this.$refs.SerialInputRef
          ? await this.$refs.SerialInputRef.validateForm()
          : true;
        if (valid && sonValid) {
          if (this.form.id != null) {
            updatePorkSideProduce(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPorkSideProduce(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.reset();
              //重新启动串口重量数据
              this.$refs.SerialInputRef.startReader();
              //this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除白条生产记录编号为"' + ids + '"的数据项？')
        .then(function () {
          return delPorkSideProduce(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    //清除吊钩绑定关系
    handleCleanBind() {
      cleanBind().then((response) => {
        this.$modal.msgSuccess("清除成功");
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "app/porkSideProduce/export",
        {
          ...this.queryParams,
        },
        `porkSideProduce_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
<style>
/* 样式保持不变 */
.large-input {
  font-size: 32px;
  width: 300px;
}
.large-input > .el-input__inner {
  height: 60px;
  line-height: 60px;
}
</style>
