<!--倒短-->
<template>
  <div class="app-container">

    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-row style="display: inline-block;width: 260px">
        <el-col :span="24">
          <el-form-item label="磅点" prop="poundid" label-width="40">
<!--            <el-select v-model="queryParams.poundid" placeholder="请选择磅点" clearable>-->
<!--              <el-option-->
<!--                v-for="dict in dict.type.pound"-->
<!--                :key="dict.value"-->
<!--                :label="dict.label"-->
<!--                :value="dict.value"-->
<!--              />-->
<!--            </el-select>-->
            <search-select v-model="queryParams.poundid"
                           params = "t_data_truepound;id;concat(name,' ',usrcode)"
                           where="poundtype = '3'"
                           orderby="usrcode asc"
            ></search-select>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="类型" prop="poundname" label-width="40">
            <el-select v-model="queryParams.poundclass" placeholder="类型">
              <el-option
                v-for="dict in dict.type.weighttype"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item style="width: 70px;color: #606266;margin: 0 0 0 0;">
        <label  style="margin-left: 10px;">过磅方式</label>
        <el-radio-group v-model="queryParams.weighttype">
          <el-radio v-for="dict in dict.type.weighttype" :key="dict.value" :label="dict.value">{{ dict.label }}</el-radio>
        </el-radio-group>
<!--        <el-button type="primary" size="mini" @click="handleQuery" style="width: 78px">生成榜单</el-button>-->
      </el-form-item>
<!--      <el-form-item label="车号" prop="carno">-->
<!--        <el-input-->
<!--          v-model="queryParams.carno"-->
<!--          placeholder="请输入车号"-->
<!--          style=""-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--        <el-button type="primary" size="mini" @click="handleQuery" style="position: absolute;left: 150px;top: 2px;">刷新</el-button>-->
<!--      </el-form-item>-->
      <el-form-item label="重量" prop="1aaa">
        <el-input
          v-model="queryParams.weight"
          style=""
          clearable
          readonly
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" size="mini" @click="handleGetweight">获取重量</el-button>
      </el-form-item>
      <el-row style="display: inline-block;width: 300px">
        <el-col :span="24">
          <el-form-item label="收货单位" prop="recunitid">
<!--            <el-select v-model="queryParams.recunitid" placeholder="请选择收货单位" clearable>-->
<!--              <el-option-->
<!--                v-for="dict in dict.type.pound"-->
<!--                :key="dict.value"-->
<!--                :label="dict.label"-->
<!--                :value="dict.value"-->
<!--              />-->
<!--            </el-select>-->
            <search-select v-model="queryPageParams.mstBill.recunitid"
                           params = "t_data_pounddata;usrcode;concat(name,' ',usrcode)"
                           where="type = 'receivingCompany'"
                           orderby="usrcode asc"
                           clearable
            ></search-select>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="品名" prop="itmcode">
<!--            <el-input-->
<!--              v-model="queryParams.itmcode"-->
<!--              placeholder="请输入品名"-->
<!--              clearable-->
<!--              @keyup.enter.native="handleQuery"-->
<!--            />-->
            <search-select v-model="queryPageParams.mstBill.itmcode"
                           params = "t_data_pounddata;usrcode;concat(name,' ',usrcode)"
                           where="type = 'productName'"
                           orderby="usrcode asc"
                           clearable
            ></search-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row style="display: inline-block;width: 300px">
        <el-col :span="24">
          <el-form-item label="承运单位" prop="trnunitid">
            <search-select v-model="queryPageParams.mstBill.trnunitid"
                           params = "t_data_pounddata;usrcode;concat(name,' ',usrcode)"
                           where="type = 'teamOrCarrier'"
                           orderby="usrcode asc"
                           clearable
            ></search-select>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="发货单位" prop="sendunitid">
            <search-select v-model="queryPageParams.mstBill.sendunitid"
                           params = "t_data_pounddata;usrcode;concat(name,' ',usrcode)"
                           where="type = 'shippingCompany'"
                           orderby="usrcode asc"
                           clearable
            ></search-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item>
        <el-button type="primary" size="mini" @click="getEmpPoundData">新增皮重</el-button>
      </el-form-item>
    </el-form>

    <!-- 主磅单信息 -->
      <el-card>
        <el-row>
          <el-col :span="24">
            <el-button class="transition-all duration-200" type="primary" size="mini">主磅单信息</el-button>
            <el-button class="transition-all duration-200" size="mini" @click = "getMstBillData">新增</el-button>
            <el-button class="transition-all duration-200" size="mini" @click = "getMstBillDataById">修改</el-button>
            <el-button class="transition-all duration-200" size="mini" @click="handleSearchMstBillFirst">查询</el-button>
            <el-button class="transition-all duration-200" size="mini">完成</el-button>
            <el-button class="transition-all duration-200" size="mini">取消完成</el-button>
            <el-button class="transition-all duration-200" size="mini">主榜单作废</el-button>

            <el-table v-loading="mstBillLoading"
                      :data="mstBillList"
                      border
                      stripe
                      @selection-change="handleMstSelectionChange"
                      ref = "mstBillTable"
                      @row-click="handleMstBillClick"
            >
              <el-table-column type="selection" width="55" align="center" />
<!--              <el-table-column label="打印次数" align="center" prop="id" />-->
              <el-table-column label="单号" align="center" prop="usrcode" width="180"/>
              <el-table-column label="榜单日期" align="center" prop="bsndt" width="180">
                <template slot-scope="scope">
                  <span>{{ parseTime(scope.row.bsndt, '{y}-{m}-{d}') }}</span>
                </template>
              </el-table-column>
              <el-table-column label="品名" align="center" prop="itmcode" width="200px">
                <template slot-scope="scope">
                  <search-select
                    :disabled = "true"
                    v-model="scope.row.itmcode"
                    params = "t_data_pounddata;usrcode;concat(name,' ',usrcode)"
                    where="type = 'productName'"
                    orderby="usrcode asc"
                    class="search-select-custom-disabled"
                  ></search-select>
                </template>
              </el-table-column>
              <el-table-column label="规格" align="center" prop="specification" />
              <el-table-column label="材质" align="center" prop="" />
              <el-table-column label="直供商" align="center" prop="zgsId" />
              <el-table-column label="单位" align="center" prop="msrunit" />
              <el-table-column label="发货单位" align="center" prop="sendunitid" width="200px">
                <template slot-scope="scope">
                <search-select
                  :disabled = "true"
                  v-model="scope.row.sendunitid"
                  params = "t_data_pounddata;usrcode;concat(name,' ',usrcode)"
                  where="type = 'shippingCompany'"
                  orderby="usrcode asc"
                  class="search-select-custom-disabled"
                ></search-select>
                </template>
              </el-table-column>
              <el-table-column label="收货单位" align="center" prop="recunitid" width="200px" >
                <template slot-scope="scope">
                <search-select
                  :disabled = "true"
                  v-model="scope.row.recunitid"
                  params = "t_data_pounddata;usrcode;concat(name,' ',usrcode)"
                  where="type = 'receivingCompany'"
                  orderby="usrcode asc"
                  class="search-select-custom-disabled"
                ></search-select>
                </template>
              </el-table-column>
              <el-table-column label="承运单位" align="center" prop="trnunitid" width="200px" >
                <template slot-scope="scope">
                <search-select
                  :disabled = "true"
                  v-model="scope.row.trnunitid"
                  params = "t_data_pounddata;usrcode;concat(name,' ',usrcode)"
                  where="type = 'teamOrCarrier'"
                  orderby="usrcode asc"
                  class="search-select-custom-disabled"
                ></search-select>
                </template>
              </el-table-column>
              <el-table-column label="备注" align="center" prop="remark" />

            </el-table>
            <pagination
              v-show="queryPageParams.mstBill.total>0"
              :total="queryPageParams.mstBill.total"
              :page.sync="queryPageParams.mstBill.pageNum"
              :limit.sync="queryPageParams.mstBill.pageSize"
              @pagination="handleSearchMstBill"
            />
          </el-col>
        </el-row>
      </el-card>

    <!-- 底部列表区域 -->
      <el-card>
        <el-row>
          <el-col :span="16"
                  v-show="activeTab === 'weighingRequest'">
            <el-button v-for="tab in tabs"
                       :key="tab.name"
                       :type="activeTab === tab.name ? 'primary' : 'default'"
                       @click="activeTab = tab.name"
                       size="mini"
            > {{ tab.label }}
            </el-button>
              <el-table
                        v-loading="poundBillDetailLoading"
                        :data="poundBillDetailList"
                        border
                        stripe
                        ref="poundBillTable"
                        @selection-change="handlePoundBillDetailSelectionChange"
                        height="500"
                        @row-click="handlePoundBillClick"
              >
                <el-table-column type="selection" width="55" align="center" />
<!--                <el-table-column label="按钮1" align="center" prop="id" />-->
                <el-table-column label="主榜单号" align="center" prop="appliid" width="200px">
                  <template slot-scope="scope">
                    <search-select
                      :disabled = "true"
                      v-model="scope.row.appliid"
                      params = "t_data_poundmst;id;usrcode"
                      where=""
                      orderby="usrcode asc"
                      class="search-select-custom-disabled"
                    ></search-select>
                  </template>
                </el-table-column>
                <el-table-column label="榜单号" align="center" prop="usrcode" width="200px"/>

                <el-table-column label="发货单位" align="center" prop="sendunitid" width="200px">
                  <template slot-scope="scope">
                    <search-select
                      :disabled = "true"
                      v-model="scope.row.sendunitid"
                      params = "t_data_pounddata;usrcode;concat(name,' ',usrcode)"
                      where="type = 'shippingCompany'"
                      orderby="usrcode asc"
                      class="search-select-custom-disabled"
                    ></search-select>
                  </template>
                </el-table-column>
                <el-table-column label="收货单位" align="center" prop="recunitid" width="200px">
                  <template slot-scope="scope">
                    <search-select
                      :disabled = "true"
                      v-model="scope.row.recunitid"
                      params = "t_data_pounddata;usrcode;concat(name,' ',usrcode)"
                      where="type = 'receivingCompany'"
                      orderby="usrcode asc"
                      class="search-select-custom-disabled"
                    ></search-select>
                  </template>
                </el-table-column>
                <el-table-column label="品名" align="center" prop="itmcode" width="200px">
                  <template slot-scope="scope">
                    <search-select
                      :disabled = "true"
                      v-model="scope.row.itmcode"
                      params = "t_data_pounddata;usrcode;concat(name,' ',usrcode)"
                      where="type = 'productName'"
                      orderby="usrcode asc"
                      class="search-select-custom-disabled"
                    ></search-select>
                  </template>
                </el-table-column>
                <el-table-column label="车号" align="center" prop="carno"/>
                <el-table-column label="司机" align="center" prop="cardriver"/>
                <el-table-column label="毛重" align="center" prop="wghmqty"/>
                <el-table-column label="皮重" align="center" prop="empmqty"/>
                <el-table-column label="净重" align="center" prop="netmqty"/>
                <el-table-column label="过毛时间" align="center" prop="wghdt">
                  <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.wghdt, '{y}-{m}-{d}') }}</span>
                  </template>
                </el-table-column>
                <el-table-column label="过毛司磅员" align="center" prop="wghdtoprname"/>
                <el-table-column label="过皮时间" align="center" prop="empdt">
                  <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.empdt, '{y}-{m}-{d}') }}</span>
                  </template>
                </el-table-column>
                <el-table-column label="过皮司磅员" align="center" prop="empdtoprname"/>

              </el-table>
            <pagination
              v-show="queryPageParams.poundBillDetail.total>0"
              :total="queryPageParams.poundBillDetail.total"
              :page.sync="queryPageParams.poundBillDetail.pageNum"
              :limit.sync="queryPageParams.poundBillDetail.pageSize"
              @pagination="queryPoundBillDetail"
            />
          </el-col>
          <el-col :span="activeTab === 'tareRequest'? 24 : 16"
                  v-show="activeTab === 'tareRequest'">
            <el-button v-for="tab in tabs"
                       :key="tab.name"
                       :type="activeTab === tab.name ? 'primary' : 'default'"
                       @click="activeTab = tab.name"
                       size="mini"
            > {{ tab.label }}
            </el-button>
            <el-form :model="queryParams" v-show="activeTab === 'tareRequest'" ref="queryForm" size="small" :inline="true" label-width="68px">
              <el-form-item label="起始日期" prop="lstedtdt">
                <el-date-picker clearable
                                v-model="queryPageParams.poundBillFull.queryStart"
                                type="date"
                                value-format="yyyy-MM-dd"
                                placeholder=""
                                @keyup.enter.native="handleQueryPoundBillFullListFirst">
                </el-date-picker>
              </el-form-item>
              <el-form-item label="截止日期" prop="lstedtdt">
                <el-date-picker clearable
                                v-model="queryPageParams.poundBillFull.queryEnd"
                                type="date"
                                value-format="yyyy-MM-dd"
                                placeholder=""
                                @keyup.enter.native="handleQueryPoundBillFullListFirst">
                </el-date-picker>
              </el-form-item>
              <el-form-item label="车号" prop="carno" label-width="40">
                <el-input
                  v-model="queryPageParams.poundBillFull.carno"
                  placeholder="请输入车号"
                  clearable
                  @keyup.enter.native="handleQueryPoundBillFullListFirst"
                />
              </el-form-item>
              <el-form-item label="磅单号" prop="usrcode" label-width="40">
                <el-input
                  v-model="queryPageParams.poundBillFull.usrcode"
                  placeholder="请输入磅单号"
                  clearable
                  @keyup.enter.native="handleQueryPoundBillFullListFirst"
                />
              </el-form-item>
              <el-button class="transition-all duration-200" type="primary" size="mini" @click="handleQueryPoundBillFullListFirst">查询磅单</el-button>
            </el-form>
              <el-table
                        v-loading="poundBillFullLoading"
                        :data="poundBillFullList"
                        border
                        stripe
                        height="500"
              >
                <el-table-column type="selection" width="55" align="center" />
                <el-table-column label="主榜单号" align="center" prop="appliid" width="200px">
                  <template slot-scope="scope">
                    <search-select
                      :disabled = "true"
                      v-model="scope.row.appliid"
                      params = "t_data_poundmst;id;usrcode"
                      where=""
                      orderby="usrcode asc"
                      class="search-select-custom-disabled"
                    ></search-select>
                  </template>
                </el-table-column>
                <el-table-column label="榜单号" align="center" prop="usrcode" width="200px"/>

                <el-table-column label="发货单位" align="center" prop="sendunitid" width="200px">
                  <template slot-scope="scope">
                    <search-select
                      :disabled = "true"
                      v-model="scope.row.sendunitid"
                      params = "t_data_pounddata;usrcode;concat(name,' ',usrcode)"
                      where="type = 'shippingCompany'"
                      orderby="usrcode asc"
                      class="search-select-custom-disabled"
                    ></search-select>
                  </template>
                </el-table-column>
                <el-table-column label="收货单位" align="center" prop="recunitid" width="200px">
                  <template slot-scope="scope">
                    <search-select
                      :disabled = "true"
                      v-model="scope.row.recunitid"
                      params = "t_data_pounddata;usrcode;concat(name,' ',usrcode)"
                      where="type = 'receivingCompany'"
                      orderby="usrcode asc"
                      class="search-select-custom-disabled"
                    ></search-select>
                  </template>
                </el-table-column>
                <el-table-column label="承运单位" align="center" prop="trnunitid" width="200px">
                  <template slot-scope="scope">
                    <search-select
                      :disabled = "true"
                      v-model="scope.row.trnunitid"
                      params = "t_data_pounddata;usrcode;concat(name,' ',usrcode)"
                      where="type = 'teamOrCarrier'"
                      orderby="usrcode asc"
                      class="search-select-custom-disabled"
                    ></search-select>
                  </template>
                </el-table-column>
                <el-table-column label="品名" align="center" prop="itmcode" width="200px">
                  <template slot-scope="scope">
                    <search-select
                      :disabled = "true"
                      v-model="scope.row.itmcode"
                      params = "t_data_pounddata;usrcode;concat(name,' ',usrcode)"
                      where="type = 'productName'"
                      orderby="usrcode asc"
                      class="search-select-custom-disabled"
                    ></search-select>
                  </template>
                </el-table-column>
                <el-table-column label="车号" align="center" prop="carno"/>
                <el-table-column label="司机" align="center" prop="cardriver"/>
                <el-table-column label="毛重" align="center" prop="wghmqty"/>
                <el-table-column label="皮重" align="center" prop="empmqty"/>
                <el-table-column label="净重" align="center" prop="netmqty"/>
                <el-table-column label="过毛时间" align="center" prop="wghdt">
                  <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.wghdt, '{y}-{m}-{d}') }}</span>
                  </template>
                </el-table-column>
                <el-table-column label="过毛司磅员" align="center" prop="wghdtoprname"/>
                <el-table-column label="过皮时间" align="center" prop="empdt">
                  <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.empdt, '{y}-{m}-{d}') }}</span>
                  </template>
                </el-table-column>
                <el-table-column label="过皮司磅员" align="center" prop="empdtoprname"/>
                <el-table-column label="备注" align="center" prop="remark" width="200px"/>
              </el-table>
            <pagination
              v-show="queryPageParams.poundBillFull.total>0 && activeTab === 'tareRequest'"
              :total="queryPageParams.poundBillFull.total"
              :page.sync="queryPageParams.poundBillFull.pageNum"
              :limit.sync="queryPageParams.poundBillFull.pageSize"
              @pagination="handleQueryPoundBillFullList"
            />
          </el-col>
          <el-col :span="4" v-show="activeTab === 'weighingRequest'">
                  <el-button class="transition-all duration-200" type="primary" size="mini" @click="">历史皮重</el-button>
                  <el-table v-loading="historyPoundLoading"
                            :data="historyPoundList"
                            border
                            stripe
                            height="500"
                  >
<!--                    <el-table-column type="selection" width="55" align="center" />-->
                    <el-table-column label="皮重" align="center" prop="emptycarqty" />
                    <el-table-column label="称重时间" align="center" prop="weighdt" width="180">
                      <template slot-scope="scope">
                        <span>{{ parseTime(scope.row.weighdt, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
                      </template>
                    </el-table-column>
                    <el-table-column label="车号" align="center" prop="carno" width="120" />
                    <el-table-column label="使用状态" align="center" prop="isused">
                      <template slot-scope="scope">
                        <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.isused"/>
                      </template>
                    </el-table-column>
                  </el-table>
            <pagination
              v-show="queryPageParams.historyPound.total>0"
              :total="queryPageParams.historyPound.total"
              :page.sync="queryPageParams.historyPound.pageNum"
              :limit.sync="queryPageParams.historyPound.pageSize"
              @pagination="handleSearchHistoryPound"
            />
          </el-col>

          <el-col :span="4" v-show="activeTab === 'weighingRequest'">
                  <el-button type="primary" size="mini" @click="">操作</el-button>
                  <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
                    <el-row>
                      <el-col :span="6">
                        <el-form-item prop="poundid" label-width="40">
                          <p></p>
                        </el-form-item>
                      </el-col>
                      <el-col :span="18">
                        <el-form-item prop="poundid" label-width="40">
                          <el-button type="info" style="width: 200px;font-size: 20px" @click = "addPoundBillDetail">增明细</el-button>
                        </el-form-item>
                      </el-col>
                    </el-row>
                    <el-row>
                      <el-col :span="6">
                        <el-form-item prop="poundid" label-width="40">
                          <span style="font-size: 20px">车号</span>
                        </el-form-item>
                      </el-col>
                      <el-col :span="18">
                        <el-form-item prop="carno" label-width="40">
<!--                          <el-select v-model="queryParams.carno" placeholder="请选择磅点" clearable style="width: 200px">-->
<!--                            <el-option-->
<!--                              v-for="dict in dict.type.pound"-->
<!--                              :key="dict.value"-->
<!--                              :label="dict.label"-->
<!--                              :value="dict.value"-->
<!--                            />-->
<!--                          </el-select>-->
                          <search-select v-model="queryParams.carno"
                                         params = "t_data_pounddata;usrcode;usrcode"
                                         where="type = 'plateNumber'"
                                         orderby="usrcode asc"
                          ></search-select>
                        </el-form-item>
                      </el-col>
                    </el-row>
                    <el-row>
                      <el-col :span="6">
                        <el-form-item prop="poundid" label-width="40">
                          <span style="font-size: 20px">司机</span>
                        </el-form-item>
                      </el-col>
                      <el-col :span="18">
                        <el-form-item prop="poundname" label-width="40">
<!--                          <el-input-->
<!--                            v-model="queryParams.cardriver" style="width: 200px"-->
<!--                            placeholder="请输入类型"-->
<!--                            clearable-->
<!--                            @keyup.enter.native="handleQuery"-->
<!--                          />-->
                          <search-select v-model="queryParams.cardriver"
                                         params = "t_data_pounddata;usrcode;usrcode"
                                         where="type = 'driverName'"
                                         orderby="usrcode asc"
                          ></search-select>
                        </el-form-item>
                      </el-col>
                    </el-row>
                    <el-row>
                      <el-col :span="6">
                        <el-form-item prop="poundid" label-width="40">
                          <p></p>
                        </el-form-item>
                      </el-col>
                      <el-col :span="18">
                        <el-form-item prop="poundname" label-width="40">
                          <el-button type="info" style="width: 200px;font-size: 20px" @click = "updatePoundBillDetail">称皮重</el-button>
                        </el-form-item>
                      </el-col>
                    </el-row>
                  </el-form>
          </el-col>
        </el-row>
      </el-card>
<!--    皮重承重界面-->
    <!-- 添加或修改皮重库对话框 -->
    <el-dialog :title="empPoundFormData.empPoundTitle" :visible.sync="empPoundFormData.empPoundOpen" width="500px" append-to-body>
      <el-form ref="empPoundFormData.empPoundForm" :model="empPoundFormData.empPoundForm" :rules="empPoundFormData.empPoundRules" label-width="80px">
        <el-form-item label="车牌号" prop="carno">
          <el-input v-model="empPoundFormData.empPoundForm.carno" placeholder="" readonly/>
        </el-form-item>
        <el-form-item label="皮重" prop="emptycarqty">
          <el-input v-model="empPoundFormData.empPoundForm.emptycarqty" readonly/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="EmpPoundFormSubmit">确 定</el-button>
        <el-button @click="EmpPoundFormCancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改主榜单信息对话框 -->
    <el-dialog :title="mstBillFormData.mstBillTitle" :visible.sync="mstBillFormData.mstBillOpen" width="1500px" append-to-body>
      <el-form ref="mstBillFormData.mstBillForm" :model="mstBillFormData.mstBillForm" :rules="mstBillFormData.mstBillRules" label-width="80px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="主榜单编号" prop="usrcode" readonly>
              <el-input v-model="mstBillFormData.mstBillForm.usrcode" placeholder="请输入主榜单编号" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="业务日期" prop="bsndt">
              <el-date-picker clearable
                              v-model="mstBillFormData.mstBillForm.bsndt"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择业务日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="业务磅点" prop="poundid">
              <search-select
                v-model="mstBillFormData.mstBillForm.poundid"
                params="t_data_buspound;id;concat(name,' ',usrcode)"
                where = ""
                orderby="usrcode asc"
                :clearable = "true"
                :disabled = "true"
              ></search-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="16">
            <el-form-item label="发货单位" prop="sendunitid">
            <search-select v-model="mstBillFormData.mstBillForm.sendunitid"
                           params = "t_data_pounddata;usrcode;concat(name,' ',usrcode)"
                           where="type = 'shippingCompany'"
                           orderby="usrcode asc"
                           clearable
            ></search-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="品名" prop="itmcode">
            <search-select v-model="mstBillFormData.mstBillForm.itmcode"
                           params = "t_data_pounddata;usrcode;concat(name,' ',usrcode)"
                           where="type = 'productName'"
                           orderby="usrcode asc"
                           clearable
            ></search-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="16">
            <el-form-item label="收货单位" prop="recunitid">
            <search-select v-model="mstBillFormData.mstBillForm.recunitid"
                           params = "t_data_pounddata;usrcode;concat(name,' ',usrcode)"
                           where="type = 'receivingCompany'"
                           orderby="usrcode asc"
                           clearable
            ></search-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="炉次" prop="boilerno">
              <el-input v-model="mstBillFormData.mstBillForm.boilerno" placeholder="请输入炉次" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="16">
            <el-form-item label="承运单位" prop="trnunitid">
              <search-select v-model="mstBillFormData.mstBillForm.trnunitid"
                             params = "t_data_pounddata;usrcode;concat(name,' ',usrcode)"
                             where="type = 'teamOrCarrier'"
                             orderby="usrcode asc"
                             clearable
              ></search-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="计量单位" prop="msrunit">
              <el-input v-model="mstBillFormData.mstBillForm.msrunit" placeholder="请输入计量单位" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="备注" prop="usrcode">
              <el-input v-model="mstBillFormData.mstBillForm.remark" placeholder="请输入备注" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="mstBillFormSubmit">确 定</el-button>
        <el-button @click="mstBillFormCancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改榜单信息对话框 -->
    <el-dialog :title="poundBillDetailFormData.poundBillDetailTitle" :visible.sync="poundBillDetailFormData.poundBillDetailOpen" width="1500px" append-to-body>
      <el-form ref="poundBillDetailFormData.poundBillDetailForm" :model="poundBillDetailFormData.poundBillDetailForm" :rules="poundBillDetailFormData.poundBillDetailRules" label-width="80px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="主榜单编号" prop="usrcode" readonly>
<!--              <el-input v-model="mstBillFormData.mstBillForm.usrcode" placeholder="请输入主榜单编号" />-->
              <search-select v-model="poundBillDetailFormData.poundBillDetailForm.appliid"
                             params = "t_data_poundmst;id;usrcode"
                             where=""
                             orderby="usrcode asc"
                             disabled
                             class="search-select-custom-disabled"
              ></search-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="明细号" prop="usrcode">
              <el-input v-model="poundBillDetailFormData.poundBillDetailForm.usrcode" placeholder="" readonly/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="发货单位" prop="sendunitid">
              <search-select v-model="poundBillDetailFormData.poundBillDetailForm.sendunitid"
                             params = "t_data_pounddata;usrcode;concat(name,' ',usrcode)"
                             where="type = 'shippingCompany'"
                             orderby="usrcode asc"
              ></search-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="16">
            <el-form-item label="收货单位" prop="recunitid">
              <search-select v-model="poundBillDetailFormData.poundBillDetailForm.recunitid"
                             params = "t_data_pounddata;usrcode;concat(name,' ',usrcode)"
                             where="type = 'receivingCompany'"
                             orderby="usrcode asc"
              ></search-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="品名" prop="itmcode">
              <search-select v-model="poundBillDetailFormData.poundBillDetailForm.itmcode"
                             params = "t_data_pounddata;usrcode;concat(name,' ',usrcode)"
                             where="type = 'productName'"
                             orderby="usrcode asc"
              ></search-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="16">
            <el-form-item label="车号" prop="carno">
              <el-input v-model="poundBillDetailFormData.poundBillDetailForm.carno" placeholder="" readonly/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="司机" prop="cardriver">
              <el-input v-model="poundBillDetailFormData.poundBillDetailForm.cardriver" placeholder="" readonly/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="毛重" prop="wghmqty">
              <el-input v-model="poundBillDetailFormData.poundBillDetailForm.wghmqty" placeholder="" readonly/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="皮重" prop="empmqty">
              <el-input v-model="poundBillDetailFormData.poundBillDetailForm.empmqty" placeholder="" readonly/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="净重" prop="netmqty">
              <el-input v-model="poundBillDetailFormData.poundBillDetailForm.netmqty" placeholder="" readonly/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="poundBillDetailFormWght" v-show = "poundBillDetailFormData.isWght">称毛重</el-button>
        <el-button type="primary" @click="poundBillDetailFormEmp" v-show = "!poundBillDetailFormData.isWght">称皮重</el-button>
        <el-button @click="poundBillDetailFormCancel">取 消</el-button>
      </div>
    </el-dialog>



  </div>
</template>

<script>
import { listShortdispound, getShortdispound, delShortdispound, addShortdispound, updateShortdispound } from "@/api/measurement/operation/shortdispound"
import Decimal from "decimal.js";
import SearchSelect from "@/components/SearchSelect/index.vue";
//导入物理磅的方法
import { listTruepound, getTruepound, delTruepound, addTruepound, updateTruepound } from "@/api/measurement/basedata/truepound"
import {mulToString} from "@/api/tool/util";
import {addEmpwgtdata, getCarnoEmpwgtData, listEmpwgtdata} from "@/api/measurement/basedata/empwgtdata";
//引入主榜单相关数据
import { listPoundmst,getNumber, getPoundmst, delPoundmst, addPoundmst, updatePoundmst } from "@/api/measurement/bill/poundmst"
//引入榜单信息方法
import {
  listPoundbill,
  getNumber as getPoundBillNumber,
  addTransPoundbill,
  getPoundbill,
  updateTransPoundbill,
} from "@/api/measurement/bill/poundbill"
export default {
  name: "Shortdispound",
  components: {SearchSelect},
  dicts: ['pound_status', 'pound', 'sys_yes_no','weighttype'],
  data() {
    return {
      // 遮罩层
      loading: false,
      // 历史皮重遮罩层
      historyPoundLoading: false,
      //主榜单遮罩层
      mstBillLoading:false,
      //过磅明细遮罩层
      poundBillDetailLoading:false,
      //完成磅单遮罩层
      poundBillFullLoading:false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 倒短磅表格数据
      operationpoundList: [],
      //主榜单数据列表
      mstBillList:[],
      //过磅明细数据列表
      poundBillDetailList:[],
      //完成磅单数据列表
      poundBillFullList:[],
      //历史皮重数据列表
      historyPoundList:[],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        weight:0,
        poundid:"",
        weighttype:  "2",//过磅方式
        poundtype: "",//磅点类型,用来存储出厂或入厂磅等。根据此存在不同的查询逻辑。
        poundclass:"",//磅点种类，只做展示，无实际作用。
        timeoutId:null,//存储定时器，用来校验车号输入后的2秒再自动执行历史皮重查询。

      },
      queryPageParams:{
        mstBill: {
          total: 0,
          pageNum: 1,
          pageSize: 10,
          isinuse:"Y",
          recunitid:"",//收货单位
          itmcode:"",//物料编码
          trnunitid:"",//运输单位
          sendunitid:"",//发货单位
          poundid:"",//业务磅点,java对象中存储为该字段。
        },
        poundBillDetail: {
          total: 0,
          pageNum: 1,
          pageSize: 10
        },
        poundBillFull: {
          total: 0,
          pageNum: 1,
          pageSize: 10,
          poundid: "",
          queryStart: "",
          queryEnd: "",
          carno: "",
          usrcode: "",
        },
        historyPound:{
          total:0,
          pageNum:1,
          pageSize:10,

        },
      },
      tabs: [
        { name: 'weighingRequest', label: '过磅明细' },
        { name: 'tareRequest', label: '完成磅单' },
      ],
      activeTab: 'weighingRequest',
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      //存储物理磅点的相关参数
      truepoundData:{},
      //皮重相关界面参数
      empPoundFormData:{
        empPoundForm:{},
        empPoundRules:{
          carno: [
            { required: true, message: "车号不能为空", trigger: "blur" }
          ],
        },
        empPoundTitle:"称皮重",
        empPoundOpen:false,
      },
      //主榜单相关界面参数
      mstBillFormData:{
        selectedIds:[],
        mstBillForm:{},
        mstBillRules:{},
        mstBillTitle:"主榜单信息",
        mstBillOpen:false,
        thisSelectedRow:{},
      },
      //榜单明细相关界面参数
      poundBillDetailFormData:{
        selectedIds:[],
        poundBillDetailForm:{
          carno: null,
        },
        poundBillDetailRules:{
          //车号是必填项
          carno: [
            { required: true, message: "车号不能为空", trigger: "blur" }
          ],
        },
        poundBillDetailTitle:"榜单明细信息",
        poundBillDetailOpen:false,
        thisSelectedRow:{},
        isWght:true,
      },
    }
  },
  created() {
    // this.getList()
  },
watch: {
  //监听磅点变化
  'queryParams.poundid': function(newVal, oldVal) {
    if(newVal!= null && newVal!== ""){
      //如果磅点不为空，则根据id查询数据库，获取值将磅单种类赋值到poundtype
      getTruepound(newVal).then(response => {
        console.log(response.data);
        this.queryParams.poundtype = response.data.poundtype;
        this.queryParams.poundclass = response.data.poundclass;
        //将获取到的物理磅点所有数据存储下来
        this.truepoundData = response.data;
        //触发查询主榜单的逻辑。
        this.handleSearchMstBillFirst();
      });

    }else {
      this.queryParams.poundtype = "";
      this.queryParams.poundclass = "";
      this.truepoundData = {};
    }
  },
  'queryParams.carno': function(newValue, oldValue) {
    // 清除之前的定时器
    if (this.queryParams.timeoutId) clearTimeout(this.queryParams.timeoutId);

    // 设置新定时器，延迟1秒执行
    this.queryParams.timeoutId = setTimeout(() => {
      // 字段变化后持续1秒执行的逻辑
      this.handleSearchHistoryPoundFirst();
    }, 1000);
  }
},
  methods: {
    /** 查询倒短磅列表 */
    getList() {
      this.loading = true
      listShortdispound(this.queryParams).then(response => {
        this.queryPageParams.mstBill.total = response.total;
        this.operationpoundList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 主榜单表单重置
    resetMstBillForm() {
      this.mstBillFormData.mstBillForm = {
        id: null,
        bsndt: null,
        poundid: null,
        sendunitid: null,
        itmcode: null,
        recunitid: null,
        boilerno: null,
        trnunitid: null,
        msrunit: null,
        usrcode: null,
      }
      this.resetForm("mstBillFormData.mstBillForm");
    },
    // 榜单明细表单重置
    resetPoundBillDetailForm() {
      this.poundBillDetailFormData.poundBillDetailForm = {
        id: null,
        appliid: null,
        usrcode: null,
        sendunitid: null,
        recunitid: null,
        itmcode: null,
        carno: null,
        cardriver: null,
        wghmqty: null,
        empmqty: null,
        netmqty: null,
      }
      this.resetForm("poundBillDetailFormData.poundBillDetailForm")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 主榜单多选框选中数据
    handleMstSelectionChange(selection) {
      if (selection.length > 0){
      this.mstBillFormData.selectedIds = selection.map(item => item.id)
        this.queryPoundBillDetailFirst();
      }else {
        this.mstBillFormData.selectedIds = [];
      }
    },
    // 过磅明细多选框选中数据
    handlePoundBillDetailSelectionChange(selection) {
      this.poundBillDetailFormData.selectedIds = selection.map(item => item.id)
    },
    // 获取重量，生成随机重量（两位小数，避免精度问题）
    handleGetweight() {
      //检查是否选中磅点。
      if (!this.checkPoundSelected())return;
      // 生成 100 到 10000 的整数（代表 1.00 到 100.00）
      const randomInt = Math.floor(Math.random() * 9900 + 100);

      // 转换为两位小数，内存中是有限小数
      this.queryParams.weight = new Decimal(randomInt / 100);
    },
    //新增皮重，将当前重量上的数据赋值到重量中，并且打开皮重弹窗
    getEmpPoundData(){
      this.empPoundFormData.empPoundForm = {
        carno:"null",
        emptycarqty:0,
      }
      this.empPoundFormData.empPoundForm.carno = this.queryParams.carno;
      this.empPoundFormData.empPoundForm.emptycarqty = this.queryParams.weight;
      this.empPoundFormData.empPoundOpen = true;
    },
    //称皮重界面，点击确定。
    EmpPoundFormSubmit(){
      this.$refs["empPoundFormData.empPoundForm"].validate(valid => {
        if (valid) {
          //赋值物理磅点id和业务磅点id
          //设置物理磅点iD
          this.empPoundFormData.empPoundForm.ttsid = this.queryParams.poundid;
          //设置业务磅点ID
          this.empPoundFormData.empPoundForm.poundid = this.truepoundData.buspoundid;
          addEmpwgtdata(this.empPoundFormData.empPoundForm).then(response => {
            this.$message.success("称皮成功！");
            this.handleSearchHistoryPound();
            this.empPoundFormData.empPoundOpen = false;
          })
        }
      })
    },
    //关闭称皮重弹窗
    EmpPoundFormCancel(){
      this.empPoundFormData.empPoundOpen = false;
    },
    //分页查询历史皮重时，自动跳转到第一页
    handleSearchHistoryPoundFirst(){
      this.queryPageParams.historyPound.pageNum = 1;
      this.handleSearchHistoryPound();
    },
    //根据车号查询历史皮重
    handleSearchHistoryPound() {
      this.historyPoundLoading = true
      var thisqueryParams = {
        carno:"",
        isinuse:"Y"
      };
      thisqueryParams.carno = this.queryParams.carno;
      thisqueryParams.pageNum = this.queryPageParams.historyPound.pageNum;
      thisqueryParams.pageSize = this.queryPageParams.historyPound.pageSize;
      listEmpwgtdata(thisqueryParams).then(response => {
        this.queryPageParams.historyPound.total = response.total;
        this.historyPoundList = response.rows;
        this.historyPoundLoading = false;
      })
    },
    //查询主榜单数据,分页设置为1
    handleSearchMstBillFirst(){
      //如果没有选中磅点
      if (!this.checkPoundSelected())return;
      this.queryPageParams.mstBill.pageNum = 1;
      this.handleSearchMstBill();
    },
    //查询主榜单数据
    handleSearchMstBill(){
      this.mstBillLoading = true
      this.queryPageParams.mstBill.poundid = this.truepoundData.buspoundid;
      listPoundmst(this.queryPageParams.mstBill).then(response => {
        this.queryPageParams.mstBill.total = response.total;
        this.mstBillList = response.rows;
        this.mstBillLoading = false;
      })
    },
    //检查是否选中磅点。
    checkPoundSelected() {
      if (this.queryParams.poundid == null || this.queryParams.poundid === "") {
        this.$message.error("请选择磅点！");
        return false;
      }
      return true;
    },
    //新增主榜单，将当前重量上的数据赋值到重量中，并且打开弹窗
    getMstBillData(){
      //如果没有选中磅点
      if (!this.checkPoundSelected())return;
      this.resetMstBillForm();
      getNumber().then(response => {
        this.mstBillFormData.mstBillForm.usrcode = response.data.number;
        this.mstBillFormData.mstBillForm.bsndt = response.data.date;
        //将业务磅点进行赋值
        this.mstBillFormData.mstBillForm.poundid = this.truepoundData.buspoundid;
        this.mstBillFormData.mstBillForm.mstBillTitle = '新增主榜单';
        //打开弹窗界面
        this.mstBillFormData.mstBillOpen = true;

      });
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    //修改主榜单
    getMstBillDataById(){
      debugger;
      const id = this.mstBillFormData.selectedIds[0];
      //如果id为空或null
      if (id == null || id === "") {
        this.$message.error("请选择主榜单！");
        return;
      }
      this.resetMstBillForm();
      getPoundmst(id).then(response => {
        this.mstBillFormData.mstBillForm = response.data;
        this.mstBillFormData.mstBillTitle = '新增主榜单';
        this.mstBillFormData.mstBillOpen = true;
      })
    },
    //主榜单界面，点击确定。
    mstBillFormSubmit(){
      this.$refs["mstBillFormData.mstBillForm"].validate(valid => {
        if (valid) {
          //设置业务磅点ID
          this.mstBillFormData.mstBillForm.poundid = this.truepoundData.buspoundid;
          if (this.mstBillFormData.mstBillForm.id == null){
          addPoundmst(this.mstBillFormData.mstBillForm).then(response => {
            this.$message.success("新增主榜单成功！");
            this.mstBillFormData.mstBillOpen = false;
            //查询主榜单数据
            this.handleSearchMstBillFirst();
          })
          }else{
            updatePoundmst(this.mstBillFormData.mstBillForm).then(response => {
              this.$message.success("修改主榜单成功！");
              this.mstBillFormData.mstBillOpen = false;
              //查询主榜单数据
              this.handleSearchMstBillFirst();
            })
          }
        }
      })
    },
    //关闭称主榜单弹窗
    mstBillFormCancel(){
      this.mstBillFormData.mstBillOpen = false;
    },
    //单击主榜单进行单选。
    //主榜单单击选中，并将车号进行赋值。（单选）
    handleMstBillClick(row) {
      // 清空之前的选择
      this.$refs.mstBillTable.clearSelection();
      // 设置当前行为选中状态
      this.$refs.mstBillTable.toggleRowSelection(row, true);
      this.mstBillFormData.thisSelectedRow = row;

    },
    //过磅明细单击选中，并将车号进行赋值。（单选）
    handlePoundBillClick(row) {
      // 清空之前的选择
      this.$refs.poundBillTable.clearSelection();
      // 设置当前行为选中状态
      this.$refs.poundBillTable.toggleRowSelection(row, true);
      this.poundBillDetailFormData.thisSelectedRow = row;

    },
    //查询过磅明细并设置页数为1
    queryPoundBillDetailFirst(){
      this.queryPageParams.poundBillDetail.pageNum = 1;
      this.queryPoundBillDetail();
    },
    //根据主榜单ID查询过磅明细。
    queryPoundBillDetail(){
      // 校验是否选中主榜单
      if (this.mstBillFormData.selectedIds.length === 0) {
        this.$message.error("请先选择主榜单！");
        return;
      }
      this.poundBillDetailLoading = true;
      var thisQueryParams = {
        billstate:"1",
        isinuse:"Y"
      }
      thisQueryParams.appliid = this.mstBillFormData.selectedIds[0];
      listPoundbill(thisQueryParams).then(response => {
        this.queryPageParams.poundBillDetail.total = response.total;
        this.poundBillDetailList = response.rows;
        this.poundBillDetailLoading = false;
      })
    },
    //点击增明细，打开榜单明细弹窗。
    async addPoundBillDetail() {
      this.poundBillDetailFormData.isWght = true;
      // 校验是否选中主榜单
      if (this.mstBillFormData.selectedIds.length === 0) {
        this.$message.error("请先选择主榜单！");
        return;
      }
      //清空表单中数据
      this.resetPoundBillDetailForm();
      try {
        // 获取榜单编码
        const response = await getPoundBillNumber();
        this.poundBillDetailFormData.poundBillDetailForm.usrcode = response.data.number;

        // 主榜单赋值
        const mainRow = this.mstBillFormData.thisSelectedRow;
        const form = this.poundBillDetailFormData.poundBillDetailForm;
        form.appliid = this.mstBillFormData.selectedIds[0];
        form.sendunitid = mainRow.sendunitid;
        form.recunitid = mainRow.recunitid;
        form.trnunitid = mainRow.trnunitid;

        // 设置车号、司机、毛重
        form.carno = this.queryParams.carno;
        form.cardriver = this.queryParams.cardriver;
        form.wghmqty = this.queryParams.weight;
        //设置磅点信息
        // 磅点信息
        form.poundid = this.truepoundData.id;
        form.poundname = this.truepoundData.name;
        //配置物料信息
        form.itmname = mainRow.itmname;
        form.itmcode = mainRow.itmcode;
        //配置计量单位
        form.msrname = mainRow.msrunit;

        // 获取皮重
        const empwgtResponse = await getCarnoEmpwgtData(this.queryParams.carno);
        if (empwgtResponse.data != null) {
          debugger
          //获取皮重重量
          form.empmqty = empwgtResponse.data.emptycarqty;
          //获取皮重id
          form.empsysid = empwgtResponse.data.id;
          //获取皮重单号
          form.empusrcode = empwgtResponse.data.usrcode;
          //过皮重时间
          form.empdt = empwgtResponse.data.weighdt;
          //过皮中司磅员
          form.empdtoprname = empwgtResponse.data.crtopr;
          debugger
          // 计算净重
          const gross = new Decimal(form.wghmqty);
          const tare = new Decimal(form.empmqty);
          form.netmqty = gross.minus(tare);
        }else {
          //清空皮重和净重数据
          form.empmqty = null;
          form.netmqty = null;
        }
        // 展示弹窗
        this.poundBillDetailFormData.poundBillDetailOpen = true;
      } catch (error) {
        console.error("新增明细失败：", error);
        this.$message.error("新增明细失败，请稍后重试！");
      }
    },
    //点击确定（称毛重），新增榜单明细。
    poundBillDetailFormWght() {
      this.$refs["poundBillDetailFormData.poundBillDetailForm"].validate(valid => {
        if (valid) {
          //如果不存在皮重数据，则提示，不存在可用皮重数据是否继续保存，点击确定则执行保存逻辑。
          if (this.poundBillDetailFormData.poundBillDetailForm.empmqty == null) {
            this.$confirm("当前车辆没有可用皮重数据，是否继续保存？", "提示", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning"
            }).then(() => {
              addTransPoundbill(this.poundBillDetailFormData.poundBillDetailForm).then(response => {
                this.$message.success("新增榜单明细成功！");
                this.poundBillDetailFormData.poundBillDetailOpen = false;
                //查询榜单明细数据
                this.queryPoundBillDetailFirst();
              })
            }).catch(() => {});
          } else {
            addTransPoundbill(this.poundBillDetailFormData.poundBillDetailForm).then(response => {
              this.$message.success("新增榜单明细成功！");
              this.poundBillDetailFormData.poundBillDetailOpen = false; //关闭榜单明细弹窗
          });
          }
        }
      })
    },
    //点击取消，关闭榜单明细弹窗。
    poundBillDetailFormCancel() {
      this.poundBillDetailFormData.poundBillDetailOpen = false;
    },
  //点击称皮重，打开榜单明细弹窗。
  async updatePoundBillDetail() {
    this.poundBillDetailFormData.isWght = false;
    // 校验是否选中过磅明细
    if (this.poundBillDetailFormData.selectedIds.length === 0) {
      this.$message.error("请先选择过磅明细！");
      return;
    }
    //如果重量为空
    if (this.queryParams.weight == null || this.queryParams.weight === "") {
      this.$message.error("请先获取重量！");
      return;
    }
    //清空表单中数据
    this.resetPoundBillDetailForm();

    try {
      //通过选中的过磅明细id获取过磅明细数据
      getPoundbill(this.poundBillDetailFormData.selectedIds[0]).then(response => {
        this.poundBillDetailFormData.poundBillDetailForm = response.data;
        const form = this.poundBillDetailFormData.poundBillDetailForm;
        //获取重量数据中的数据作为皮重数据。
        form.empmqty = this.queryParams.weight;
        // 计算净重
        const gross = new Decimal(form.wghmqty);
        const tare = new Decimal(form.empmqty);
        form.netmqty = gross.minus(tare);
        // 展示弹窗
        this.poundBillDetailFormData.poundBillDetailOpen = true;
      })
    } catch (error) {
      console.error("称皮重：", error);
      this.$message.error("新增明细失败，请稍后重试！");
    }
  },
    //点击确定（称皮重），新增榜单明细。
    poundBillDetailFormEmp() {
      this.$refs["poundBillDetailFormData.poundBillDetailForm"].validate(valid => {
        if (valid) {

          this.poundBillDetailFormData.poundBillDetailForm.params = {};
          this.poundBillDetailFormData.poundBillDetailForm.params.ttsid = this.queryParams.poundid;
          this.poundBillDetailFormData.poundBillDetailForm.params.buspoundid = this.truepoundData.buspoundid;
          //如果不存在皮重数据，则提示，不存在可用皮重数据是否继续保存，点击确定则执行保存逻辑。
          if (this.poundBillDetailFormData.poundBillDetailForm.empmqty == null) {
            this.$confirm("当前车辆没有可用皮重数据，是否继续保存？", "提示", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning"
            }).then(() => {
              updateTransPoundbill(this.poundBillDetailFormData.poundBillDetailForm).then(response => {
                this.$message.success("榜单明细称皮重成功！");
                this.poundBillDetailFormData.poundBillDetailOpen = false;
                //查询榜单明细数据
                this.queryPoundBillDetailFirst();
              })
            }).catch(() => {});
          } else {
            updateTransPoundbill(this.poundBillDetailFormData.poundBillDetailForm).then(response => {
              this.$message.success("榜单明细称皮重成功！");
              this.poundBillDetailFormData.poundBillDetailOpen = false; //关闭榜单明细弹窗
              //查询榜单明细数据
              this.queryPoundBillDetailFirst();
            });
          }
        }
      })
    },
    //点击查询磅单按钮，设置页数为1

    handleQueryPoundBillFullListFirst(){
      this.queryPageParams.poundBillFull.pageNum = 1;
      this.handleQueryPoundBillFullList();
    },
    //查询完成的榜单数据
    handleQueryPoundBillFullList(){
      //是否选中磅点
      if (!this.checkPoundSelected())return;
      //是否选中主榜单
      if (this.mstBillFormData.selectedIds.length === 0) {
        this.$message.error("请先选择主榜单！");
        return;
      }
      this.poundBillFullLoading = true;
      var thisqueryParams = {
        billstate:"2",
        isinuse:"Y"
      }
      //设置物理磅点作为查询条件
      thisqueryParams.poundid = this.truepoundData.id;
      //设置主榜单ID作为查询条件
      thisqueryParams.appliid = this.mstBillFormData.selectedIds[0];
      thisqueryParams.carno = this.queryPageParams.poundBillFull.carno;
      thisqueryParams.usrcode = this.queryPageParams.poundBillFull.usrcode;
      thisqueryParams.params = {};
      thisqueryParams.params.queryStart = this.queryPageParams.poundBillFull.queryStart;
      thisqueryParams.params.queryEnd = this.queryPageParams.poundBillFull.queryEnd;
      thisqueryParams.pageNum = this.queryPageParams.poundBillFull.pageNum;
      thisqueryParams.pageSize = this.queryPageParams.poundBillFull.pageSize;
      listPoundbill(thisqueryParams).then(response => {
        this.queryPageParams.poundBillFull.total = response.total;
        this.poundBillFullList = response.rows;
        this.poundBillFullLoading = false;
      })
    }
  }
}
</script>
