<template>
  <div>
    <el-tabs type="border-card">
      <el-tab-pane label="结算头">
        <el-card :body-style="cardBodyStyle">
          <el-form :model="query" label-width="auto" label-position="right">
            <el-row :gutter="10" style="">
              <el-col :span="5">
                <el-form-item label="结算日期"  style="margin-bottom: 5px;">
                  <el-date-picker
                      style="width: 100%"
                      v-model="query.invDtList"
                      type="daterange"
                      range-separator="-"
                      start-placeholder="开始日期"
                      end-placeholder="结束日期"
                      value-format="YYYY-MM-DD"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="5">
                <el-form-item label="结算单号"  style="margin-bottom: 5px;">
                  <el-input v-model="query.invNo" placeholder="" clearable></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="5">
                <el-form-item label="客户名称"  style="margin-bottom: 5px;">
                  <el-input v-model="query.tradePartnerName" placeholder="" clearable></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="5">
                <el-form-item label="合同号"  style="margin-bottom: 5px;">
                  <el-input v-model="query.contrNo" placeholder="" clearable></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="1">
                <el-button type="primary" link @click="reset">重置</el-button>
              </el-col>
              <el-col :span="2">
                <el-button type="primary" link @click="queryShow = !queryShow">
                  高级查询
                  <el-icon v-if="queryShow">
                    <ArrowUp/>
                  </el-icon>
                  <el-icon v-else>
                    <ArrowDown/>
                  </el-icon>
                </el-button>
              </el-col>
              <el-col :span="5" v-if="queryShow">
                <el-form-item label="结算单类型" style="margin-top: 5px;margin-bottom: 5px;">
                  <el-select v-model="query.payMth">
                    <el-option
                        v-for="item in dicList.COM_PAY_MTH"
                        :key="item.dicCode"
                        :label="item.dicName"
                        :value="item.dicCode"
                    />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="5" v-if="queryShow">
                <el-form-item label="是否被驳回" style="margin-top: 5px;margin-bottom: 5px;">
                  <el-input v-model="queryUserDesc" placeholder="" disabled></el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </el-card>
<!--        <el-card :body-style="cardBodyStyle">-->
<!--          <el-button type="primary" @click="handleSearch" plain>查询</el-button>-->
<!--          <el-button type="success" @click="handleAdd" plain>新增</el-button>-->
<!--          <el-button type="danger" @click="submit" plain>提交</el-button>-->
<!--        </el-card>-->
        <ButtonBar @search="handleSearch"  @add="handleAdd" @download="searchReport"></ButtonBar>

        <el-card :body-style="cardBodyStyle">
          <el-table :data="tableData" border highlight-current-row height="300" @selection-change="handleSelectionChange" @row-click="cellHover">
            <el-table-column type="selection" fixed></el-table-column>
            <el-table-column type="index" label="序号" align="center" width="60">
              <template #default="scope">
                <span>{{ scope.$index + (currentPage - 1) * pageSize + 1 }}</span>
              </template>
            </el-table-column>
            <el-table-column v-if="true" prop="invNo" label="结算单号" width="200" header-align="center"
                             align="center" show-overflow-tooltip>
              <template #default="scope">
                <el-button @click="handleInfo(scope.row)" type="primary" link>{{ scope.row.invNo }}</el-button>
              </template>
            </el-table-column>
            <el-table-column v-if="true" prop="invDt" label="结算日期" width="130" header-align="center"
                             align="center" show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="invTy" label="开票类型" width="140" header-align="center"
                             align="center" show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="payMth" label="结算类型" header-align="center" align="center" width="140"
                             :formatter="formatter"
                             show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="contrNo" label="合同编号" header-align="center" align="center"
                             width="150"
                             show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="khContrNo" label="对方合同编号" header-align="center" align="center"
                             width="110"
                             show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="workModel.flowStatusName" label="流程状态" width="120" header-align="center" align="center"
                             show-overflow-tooltip>
              <template #default="{ row }">
                <div>
                  <el-tag v-if="row.workId !== undefined && row.workModel.flowStatus === '110'">{{ row.workModel.flowStatusName }}</el-tag>
                  <el-tag type="success" v-else-if="row.workId !== undefined && row.workModel.flowStatus === '170'">{{ row.workModel.flowStatusName }}</el-tag>
                  <el-tag type="danger" v-else-if="row.workId !== undefined && (row.workModel.flowStatus === '130' || row.workModel.flowStatus === '180' || row.workModel.flowStatus === '190')">{{ row.workModel.flowStatusName }}</el-tag>
                  <el-tag type="warning" v-else>'---'</el-tag>
                </div>

              </template>
            </el-table-column>
            <el-table-column v-if="true" prop="workModel.flowNode" label="当前节点" width="120" header-align="center" align="center"
                             show-overflow-tooltip>
              <template #default="{ row }">
                <div>
                  <el-tag v-if="row.workId !== undefined && row.workModel.flowStatus === '110'">{{ row.workModel.flowNode }}</el-tag>
                  <el-tag type="success" v-else-if="row.workId !== undefined && row.workModel.flowStatus === '170'">{{ row.workModel.flowNode }}</el-tag>
                  <el-tag type="danger" v-else-if="row.workId !== undefined && (row.workModel.flowStatus === '130' || row.workModel.flowStatus === '180' || row.workModel.flowStatus === '190')">{{ row.workModel.flowNode }}</el-tag>
                  <el-tag type="warning" v-else>'---'</el-tag>
                </div>

              </template>
            </el-table-column>
            <el-table-column v-if="true" prop="tradePartnerCode" label="客户编号" header-align="center" align="center"
                             width="140"
                             show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="tradePartnerName" label="客户名称" header-align="center" align="center"
                             width="140"
                             show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="taxRate" label="税率" header-align="center" align="center" width="140"
                             show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="qty" label="结算重量" header-align="center" align="center" width="140"
                             show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="invAmt" label="结算金额" header-align="center" align="center" width="140"
                             show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="invDesc" label="开票说明" header-align="center" align="center"
                             width="140"
                             show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="stoOutWgt" label="结算对应出库量" header-align="center" align="center"
                             width="140"
                             show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="invFlag" label="结算标识" header-align="center" align="center"
                             :formatter="formatter"
                             width="140"
                             show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="remark" label="备注" header-align="center" align="center" width="140"
                             show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" label="操作" header-align="center" align="center" width="300" fixed="right"
                             show-overflow-tooltip>
              <template #default="scope">
<!--                <el-button plain type="warning" @click="handleEdit(scope.row)">编辑</el-button>-->
<!--                <el-button plain type="danger" @click="handleDelete(scope.row )">删除</el-button>-->

                <el-button plain type="warning" @click="handleEdit(scope.row)" v-show="scope.row.workId === '' || scope.row.workModel.opType === '1'">编辑
                </el-button>
                <el-button plain type="danger" @click="handleDelete(scope.row )" v-show="scope.row.workId === '' || scope.row.workModel.opType === '1'">删除
                </el-button>
                <el-button plain type="success" @click="handleSubmit(scope.row ) "v-show="scope.row.workId === '' || scope.row.workModel.opType === '1'">发起
                </el-button>
                <el-button plain type="primary" @click="handleDetail(scope.row )" v-show="scope.row.workId !== ''">详情</el-button>
                <el-button plain type="info" @click="handleCancel(scope.row )" v-show="scope.row.workId !== '' && scope.row.workModel.opType !== '1' && scope.row.workModel.flowStatus !== '170'">撤回</el-button>

              </template>
            </el-table-column>
          </el-table>
        </el-card>
        <el-card :body-style="cardBodyStyle">
          <el-pagination :current-page="currentPage" :page-size="pageSize" :page-sizes="pageSizes" :total="totalRows"
                         background="background" layout="total, sizes, prev, pager, next, jumper"
                         @size-change="handleSizeChange"
                         @current-change="handleCurrentChange">
          </el-pagination>
        </el-card>
      </el-tab-pane>
    </el-tabs>

    <el-tabs type="border-card">
      <el-tab-pane label="结算行">
        <el-card :body-style="cardBodyStyle" style="margin-top: 10px">
          <el-table :data="tableDataLine" border highlight-current-row height="300">
            <el-table-column type="index" label="序号" align="center" width="60">
              <template #default="scope">
                <span>{{ scope.$index + (currentPageLine - 1) * pageSizeLine + 1 }}</span>
              </template>
            </el-table-column>
            <el-table-column v-if="true" prop="invLine" label="结算单行号" width="150" header-align="center"
                             align="center" show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="stoOutNo" label="出库单号" width="130" header-align="center"
                             align="center" show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="dordNo" label="发货指示号" header-align="center" align="center"
                             width="150"
                             show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="contrNo" label="合同编号" header-align="center" align="center"
                             width="110"
                             show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="khContrNo" label="对方合同编号" header-align="center" align="center"
                             width="140"
                             show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="itemCd" label="物料编码" header-align="center" align="center" width="140"
                             show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="itemNm" label="物料名称" header-align="center" align="center" width="140"
                             show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="qty" label="数量" header-align="center" align="center"
                             width="140"
                             show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="uom" label="计量单位" header-align="center" align="center" width="140" :formatter="formatter"
                             show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="invPrice" label="结算单价" header-align="center" align="center" width="140"
                             show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="invAmt" label="结算金额" header-align="center" align="center" width="140"
                             show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="invDiffRsn" label="结算与发货差额原因或折让原因" header-align="center"
                             align="center" width="140"
                             show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="invDesc" label="开票说明（备注）" header-align="center" align="center"
                             width="140"
                             show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="stoOutWgt" label="结算对应出库量" header-align="center" align="center"
                             width="140"
                             show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="itemNmInv" label="发票物料名称" header-align="center" align="center"
                             width="140"
                             show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="remark" label="备注" header-align="center" align="center" width="140"
                             show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="false" prop="rtnYn" label="是否已退" header-align="center" align="center" width="140"
                             show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="transWaterSci" label="水分" header-align="center" align="center"
                             width="140"
                             show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="transTasteSci" label="品位" header-align="center" align="center"
                             width="140"
                             show-overflow-tooltip>
            </el-table-column>
          </el-table>

<!--          <el-pagination :current-page="currentPageLine" :page-size="pageSizeLine" :page-sizes="pageSizesLine"-->
<!--                         :total="totalRowsLine"-->
<!--                         background="background" layout="total, sizes, prev, pager, next, jumper"-->
<!--                         @size-change="handleSizeChangeLine"-->
<!--                         @current-change="handleCurrentChangeLine">-->
<!--          </el-pagination>-->
        </el-card>
      </el-tab-pane>
    </el-tabs>

    <el-dialog class="diaClass" :close-on-click-modal="false" draggable title="新增" v-model="dialogVisible" fullscreen
               top="5vh" @open="openDialog" @close="diaClose">
      <el-card :body-style="cardBodyStyle">
        <el-divider content-position="left">
          <div style="color: #409EFF">结算信息</div>
        </el-divider>
        <el-form :model="form" label-width="120px" label-position="right" inline ref="ruleFormRef" :rules="rules">
          <el-row>
            <el-col :span="6">
              <el-form-item label="结算单号" prop="invNo" style="width: 100%">
                <el-input v-model="form.invNo" disabled>

                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="结算日期" prop="invDt" style="width: 100%">
                <el-date-picker
                    style="width: 100%"
                    v-model="form.invDt"
                    type="date"
                    value-format="YYYY-MM-DD"
                    placeholder="申请日期"
                />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="合同编号" prop="contrNo" style="width: 100%">
                <el-input v-model="form.contrNo" readonly>
                  <template #append>
                    <el-button :icon="Search" @click="dialogHt()"/>
                  </template>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="对方合同编号" prop="khContrNo">
                <el-input v-model="form.khContrNo" readonly>

                </el-input>
              </el-form-item>
            </el-col>

            <el-col :span="6">
              <el-form-item label="客户名称" prop="tradePartnerName">
                <el-input v-model="form.tradePartnerName" readonly>

                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="定价方式" prop="priceDcnMth">
                <el-select v-model="form.priceDcnMth" placeholder="请选择" clearable style="" disabled>
                  <el-option v-for="item in dicList.PRICE_DCN_MTH" :key="item.dicCode" :label="item.dicName"
                             :value="item.dicCode"/>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="税率" prop="taxRate">
                <el-select v-model="form.taxRateLine">
                  <el-option
                      @click.native="taxRateChange(item)"
                      v-for="item in lineList"
                      :key="item.id"
                      :label="String(item.taxRate)"
                      :value="item.id"
                  >
                    <span style="float: left">{{ item.taxRate }}%</span>
                    <span style="float: right;color: var(--el-text-color-secondary);font-size: 13px;">
                      合同行{{ item.conLine }}
                    </span>
                  </el-option>
                </el-select>
                <!--                <SelectorComponent :optionList="lineList" :value="form.taxRate"-->
                <!--                                   @change="itemTypeDict"/>-->
              </el-form-item>
            </el-col>

            <el-col :span="6">
              <el-form-item label="结算类型" prop="payMth">
                <SelectorComponent :optionList="dicList.COM_PAY_MTH" :value="form.payMth"
                                   @change="payMathSelect"/>
              </el-form-item>
            </el-col>

            <el-col :span="6">
              <el-form-item label="结算重量" prop="qty">
                <el-input v-model="form.qty" readonly>

                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="结算金额" prop="invAmt">
                <el-input v-model="form.invAmt" readonly>

                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="结算标识" prop="invFlag">
                <SelectorComponent :optionList="dicList.INV_FLAG" :value="form.invFlag" :allowSelect="true"
                                   @change="invFlagSelect"/>
              </el-form-item>
            </el-col>

            <el-col :span="6">
              <el-form-item label="开始时间" prop="invStartTime">
                <el-date-picker
                    style="width: 100%"
                    v-model="form.invStartTime"
                    type="datetime"
                    value-format="YYYY-MM-DD HH:mm:ss"
                    format="YYYY-MM-DD HH:mm:ss"
                    placeholder="开始时间"
                />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="结束时间" prop="invEndTime">
                <el-date-picker
                    style="width: 100%"
                    v-model="form.invEndTime"
                    value-format="YYYY-MM-DD HH:mm:ss"
                    format="YYYY-MM-DD HH:mm:ss"
                    type="datetime"
                    placeholder="结束时间"
                />
              </el-form-item>
            </el-col>


            <el-col :span="24">
              <el-form-item label="开票说明">
                <el-input
                    v-model="form.invDesc"
                    :autosize="{ minRows: 2, maxRows: 4 }"
                    type="textarea"
                    placeholder=""
                />
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="备注">
                <el-input
                    v-model="form.remark"
                    :autosize="{ minRows: 2, maxRows: 4 }"
                    type="textarea"
                    placeholder=""
                />
              </el-form-item>
            </el-col>
          </el-row>

        </el-form>

      </el-card>
      <el-card :body-style="cardBodyStyle">
        <el-divider content-position="left">
          <div style="display: flex; text-align: center;align-items: center">
            <span style="color: #409EFF;">
              结算标准
            </span>

            <el-tooltip
                class="box-item"
                effect="dark"
                content="结算标准，用以生成结算单价"
                placement="top"
            >
              <el-icon style="color: #a5a5a5;">
                <InfoFilled/>
              </el-icon>
            </el-tooltip>

          </div>
        </el-divider>
        <div style="display: flex">
          <el-table :data="tableDataSettlement" border highlight-current-row
                    @selection-change="handleSelectionChangeSettlement"
                    height="245">
<!--            <el-table-column type="selection" fixed></el-table-column>-->
            <el-table-column type="index" label="序号" align="center" width="60">
              <template #default="scope">
                <span>{{ scope.$index + (currentPage - 1) * pageSize + 1 }}</span>
              </template>
            </el-table-column>
            <el-table-column v-if="true" prop="settleNo" label="结算项目编码" min-width="100" header-align="center"
                             align="center" show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="settleItem" label="结算项目" min-width="100" header-align="center"
                             align="center" show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="settleValueTo" label="结算项目上限" min-width="100" header-align="center"
                             align="right" show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="settleValueFrom" label="结算项目下限" min-width="100"
                             header-align="center"
                             align="right" show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="referenceValue" label="基准值" min-width="100" header-align="center"
                             align="right" show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="settleSpan" label="结算项目跨度" min-width="100" header-align="center"
                             align="right" show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="settleDiffer" label="结算差额" min-width="100" header-align="center"
                             align="right" show-overflow-tooltip>
            </el-table-column>


          </el-table>
        </div>


      </el-card>
      <el-card :body-style="cardBodyStyle">
        <el-divider content-position="left">
          <div style="display: flex; text-align: center;align-items: center">
            <span style="color: #409EFF;">
              出库数据
            </span>
            <el-tooltip
                class="box-item"
                effect="dark"
                content="选择出库数据，用以计算结算重量。"
                placement="top"
            >
              <el-icon style="color: #a5a5a5;">
                <InfoFilled/>
              </el-icon>
            </el-tooltip>

          </div>
        </el-divider>
        <el-button type="primary" plain @click="queryOutRecord">查询</el-button>

        <el-table :data="tableDataOutRecord" border highlight-current-row height="300"
                  @selection-change="handleSelectionChangeOutRecord">
          <el-table-column type="selection" fixed></el-table-column>
          <el-table-column type="index" label="序号" align="center" width="60">
            <template #default="scope">
              <span>{{ scope.$index + (currentPageOutRecord - 1) * pageSizeOutRecord + 1 }}</span>
            </template>
          </el-table-column>
          <el-table-column v-if="true" prop="stoOutNo" label="出库单号" width="150" header-align="center"
                           align="center" show-overflow-tooltip>
          </el-table-column>
          <el-table-column v-if="true" prop="itemCd" label="物料编码" width="130" header-align="center"
                           align="center" show-overflow-tooltip>
          </el-table-column>
          <el-table-column v-if="true" prop="itemNm" label="物料名称" width="140" header-align="center"
                           align="center" show-overflow-tooltip>
          </el-table-column>
          <el-table-column v-if="true" prop="qty" label="干基量" header-align="center" align="center" width="180"
                           show-overflow-tooltip>
            <template #default="scope">
              <el-input-number v-if="!scope.row.qtyEdit" :min="0"
                               @change="outquantityChange( scope.row ,scope.$index)"
                               v-model="scope.row.qty"></el-input-number>

            </template>
          </el-table-column>
          <el-table-column v-if="true" prop="qtyWet" label="湿基量" header-align="center" align="center" width="140"
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column v-if="true" prop="uom" label="计量单位" header-align="center" align="center" width="140" :formatter="formatter"
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column v-if="true" prop="transTasteSci" label="品位" width="120" header-align="center"
                           align="center"
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column v-if="true" prop="transWaterSci" label="水分" width="120" header-align="center"
                           align="center"
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column v-if="false" prop="itemType" label="物料类型" header-align="center" align="center"
                           width="140"
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column v-if="true" prop="tradePartnerName" label="供应商名称" header-align="center" align="center"
                           width="140"
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column v-if="true" prop="carNo" label="车号" header-align="center" align="center" width="140"
                           show-overflow-tooltip>
          </el-table-column>

          <el-table-column v-if="true" prop="storeCd" label="库房" header-align="center" align="center" width="140"
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column v-if="true" prop="stoOutDt" label="出库业务日期时间" header-align="center" align="center"
                           width="180"
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column v-if="true" prop="contrNo" label="合同编号" header-align="center" align="center"
                           width="140"
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column v-if="true" prop="khContrNo" label="对方合同编号" header-align="center" align="center"
                           width="140"
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column v-if="true" prop="outFlag" label="出库标记" header-align="center" align="center" width="140"
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column v-if="true" prop="billYn" label="是否结算" header-align="center" align="center" width="140"
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column v-if="true" prop="billNo" label="结算单号" header-align="center" align="center" width="140"
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column v-if="true" prop="tmsYn" label="是否出厂" header-align="center" align="center" width="140"
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column v-if="true" prop="syiYn" label="是否检化验" header-align="center" align="center"
                           width="140"
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column v-if="true" prop="tmsNo" label="物流计量业务单号" header-align="center" align="center"
                           width="140"
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column v-if="true" prop="syiNo" label="检化验业务单号" header-align="center" align="center"
                           width="140"
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column v-if="true" prop="remark" label="备注" header-align="center" align="center" width="140"
                           show-overflow-tooltip>
          </el-table-column>

          <el-table-column v-if="true" prop="endPrice" label="结算单价" header-align="center" align="center"
                           fixed="right"
                           width="180"
                           show-overflow-tooltip>
            <template #default="scope">
              <el-input-number v-if="!scope.row.qtyEdit" :min="0"
                               @change="outquantityChangeEndPrice( scope.row ,scope.$index)"
                               v-model="scope.row.endPrice"></el-input-number>
            </template>
          </el-table-column>

        </el-table>
<!--        <el-pagination :current-page="currentPageOutRecord" :page-size="pageSizeOutRecord"-->
<!--                       :page-sizes="pageSizesOutRecord" :total="totalRowsOutRecord"-->
<!--                       background="background" layout="total, sizes, prev, pager, next, jumper"-->
<!--                       @size-change="handleSizeChangeOutRecord"-->
<!--                       @current-change="handleCurrentChangeOutRecord">-->
<!--        </el-pagination>-->

      </el-card>

      <el-card :body-style="cardBodyStyle">
        <el-affix position="bottom" :offset="20">
          <el-card>
            <h3>

              结算金额= {{ form.gongshi }}

            </h3>
          </el-card>
        </el-affix>
      </el-card>


      <template #footer>
        <div class="dialog-footer">
          <el-button type="success" @click="handleSave(ruleFormRef)" plain>保存</el-button>
          <el-button type="danger" @click="handleCancelSave" plain>取消</el-button>
        </div>
      </template>
    </el-dialog>
    <el-dialog class="diaClass" :close-on-click-modal="false" draggable title="编辑" v-model="dialogVisibleEdit" fullscreen
               top="5vh" @open="openDialog" @close="diaClose">
      <el-card :body-style="cardBodyStyle">
        <el-divider content-position="left">
          <div style="color: #409EFF">结算信息</div>
        </el-divider>
        <el-form :model="form" label-width="120px" label-position="right" inline ref="ruleFormRef" :rules="rules">
          <el-row>
            <el-col :span="6">
              <el-form-item label="结算单号" prop="invNo" style="width: 100%">
                <el-input v-model="form.invNo" disabled>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="结算日期" prop="invDt" style="width: 100%">
                <el-date-picker
                    style="width: 100%"
                    v-model="form.invDt"
                    type="date"
                    placeholder="申请日期"
                />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="合同编号" prop="contrNo" style="width: 100%">
                <el-input v-model="form.contrNo" readonly>
                  <template #append>
                    <el-button :icon="Search" @click="dialogHt()"/>
                  </template>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="对方合同编号" prop="khContrNo">
                <el-input v-model="form.khContrNo" readonly>

                </el-input>
              </el-form-item>
            </el-col>

            <el-col :span="6">
              <el-form-item label="客户名称" prop="tradePartnerName">
                <el-input v-model="form.tradePartnerName" readonly>

                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="定价方式" prop="priceDcnMth">
                <el-select v-model="form.priceDcnMth" placeholder="请选择" clearable style="" disabled>
                  <el-option v-for="item in dicList.PRICE_DCN_MTH" :key="item.dicCode" :label="item.dicName"
                             :value="item.dicCode"/>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="税率" prop="taxRate">
                <el-select v-model="form.taxRateLine" :key="lineKey">
                  <el-option
                      @click.native="taxRateChange(item)"
                      v-for="item in lineList"
                      :key="item.id"
                      :label="String(item.taxRate)"
                      :value="item.id"
                  >
                    <span style="float: left">{{ item.taxRate }}%</span>
                    <span style="float: right;color: var(--el-text-color-secondary);font-size: 13px;">
                      合同行{{ item.conLine }}
                    </span>
                  </el-option>
                </el-select>
                <!--                <SelectorComponent :optionList="lineList" :value="form.taxRate"-->
                <!--                                   @change="itemTypeDict"/>-->
              </el-form-item>
            </el-col>

            <el-col :span="6">
              <el-form-item label="结算类型" prop="payMth">
                <SelectorComponent :optionList="dicList.COM_PAY_MTH" :value="form.payMth"
                                   @change="payMathSelect"/>
              </el-form-item>
            </el-col>

            <el-col :span="6">
              <el-form-item label="结算重量" prop="qty">
                <el-input v-model="form.qty" readonly>

                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="结算金额" prop="invAmt">
                <el-input v-model="form.invAmt" readonly>

                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="结算标识" prop="invFlag">
                <SelectorComponent :optionList="dicList.INV_FLAG" :value="form.invFlag"  :allowSelect="true"
                                   @change="invFlagSelect"/>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="开始时间" prop="invStartTime">
                <el-date-picker
                    style="width: 100%"
                    v-model="form.invStartTime"
                    type="datetime"
                    value-format="YYYY-MM-DD HH:mm:ss"
                    format="YYYY-MM-DD HH:mm:ss"
                    placeholder="开始时间"
                />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="结束时间" prop="invEndTime">
                <el-date-picker
                    style="width: 100%"
                    v-model="form.invEndTime"
                    value-format="YYYY-MM-DD HH:mm:ss"
                    format="YYYY-MM-DD HH:mm:ss"
                    type="datetime"
                    placeholder="结束时间"
                />
              </el-form-item>
            </el-col>


            <el-col :span="24">
              <el-form-item label="开票说明">
                <el-input
                    v-model="form.invDesc"
                    :autosize="{ minRows: 2, maxRows: 4 }"
                    type="textarea"
                    placeholder=""
                />
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="备注">
                <el-input
                    v-model="form.remark"
                    :autosize="{ minRows: 2, maxRows: 4 }"
                    type="textarea"
                    placeholder=""
                />
              </el-form-item>
            </el-col>
          </el-row>

        </el-form>

      </el-card>
      <el-card :body-style="cardBodyStyle">
        <el-divider content-position="left">
          <div style="display: flex; text-align: center;align-items: center">
            <span style="color: #409EFF;">
              结算标准
            </span>

            <el-tooltip
                class="box-item"
                effect="dark"
                content="结算标准，用以生成结算单价"
                placement="top"
            >
              <el-icon style="color: #a5a5a5;">
                <InfoFilled/>
              </el-icon>
            </el-tooltip>

          </div>
        </el-divider>
        <div style="display: flex">
          <el-table :data="tableDataSettlement" border highlight-current-row
                    @selection-change="handleSelectionChangeSettlement"
                    height="245">
<!--            <el-table-column type="selection" fixed></el-table-column>-->
            <el-table-column type="index" label="序号" align="center" width="60">
              <template #default="scope">
                <span>{{ scope.$index + (currentPage - 1) * pageSize + 1 }}</span>
              </template>
            </el-table-column>
            <el-table-column v-if="true" prop="settleNo" label="结算项目编码" min-width="100" header-align="center"
                             align="center" show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="settleItem" label="结算项目" min-width="100" header-align="center"
                             align="center" show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="settleValueTo" label="结算项目上限" min-width="100" header-align="center"
                             align="right" show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="settleValueFrom" label="结算项目下限" min-width="100"
                             header-align="center"
                             align="right" show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="referenceValue" label="基准值" min-width="100" header-align="center"
                             align="right" show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="settleSpan" label="结算项目跨度" min-width="100" header-align="center"
                             align="right" show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="settleDiffer" label="结算差额" min-width="100" header-align="center"
                             align="right" show-overflow-tooltip>
            </el-table-column>


          </el-table>
        </div>


      </el-card>
      <el-card :body-style="cardBodyStyle">
        <el-divider content-position="left">
          <div style="display: flex; text-align: center;align-items: center">
            <span style="color: #409EFF;">
              结算行
            </span>
          </div>
        </el-divider>

        <el-table :data="tableDataLine" border highlight-current-row height="300"
                  @selection-change="handleSelectionChangeOutRecord">
<!--          <el-table-column type="selection" fixed></el-table-column>-->
          <el-table-column type="index" label="序号" align="center" width="60">
            <template #default="scope">
              <span>{{ scope.$index + (currentPageOutRecord - 1) * pageSizeOutRecord + 1 }}</span>
            </template>
          </el-table-column>
          <el-table-column v-if="true" prop="stoOutNo" label="出库单号" width="150" header-align="center"
                           align="center" show-overflow-tooltip>
          </el-table-column>
          <el-table-column v-if="true" prop="invLine" label="结算行号" width="150" header-align="center"
                           align="center" show-overflow-tooltip>
          </el-table-column>
          <el-table-column v-if="true" prop="itemCd" label="物料编码" width="130" header-align="center"
                           align="center" show-overflow-tooltip>
          </el-table-column>
          <el-table-column v-if="true" prop="itemNm" label="物料名称" width="140" header-align="center"
                           align="center" show-overflow-tooltip>
          </el-table-column>
          <el-table-column v-if="true" prop="qty" label="数量" header-align="center" align="center" width="180"
                           show-overflow-tooltip>
<!--            <template #default="scope">-->
<!--              <el-input-number v-if="!scope.row.qtyEdit" :min="0"-->
<!--                               @change="outquantityChangeEdit( scope.row ,scope.$index)"-->
<!--                               v-model="scope.row.qty"></el-input-number>-->

<!--            </template>-->
          </el-table-column>
          <el-table-column v-if="true" prop="stoOutWgt" label="湿基量" header-align="center" align="center" width="140"
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column v-if="true" prop="uom" label="计量单位" header-align="center" align="center" width="140" :formatter="formatter"
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column v-if="true" prop="transTasteSci" label="品位" width="120" header-align="center"
                           align="center"
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column v-if="true" prop="transWaterSci" label="水分" width="120" header-align="center"
                           align="center"
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column v-if="false" prop="itemType" label="物料类型" header-align="center" align="center"
                           width="140"
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column v-if="true" prop="contrNo" label="合同编号" header-align="center" align="center"
                           width="140"
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column v-if="true" prop="khContrNo" label="对方合同编号" header-align="center" align="center"
                           width="140"
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column v-if="true" prop="invNo" label="结算单号" header-align="center" align="center" width="140"
                           show-overflow-tooltip>
          </el-table-column>

          <el-table-column v-if="true" prop="tmsNo" label="物流计量业务单号" header-align="center" align="center"
                           width="140"
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column v-if="true" prop="syiNo" label="检化验业务单号" header-align="center" align="center"
                           width="140"
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column v-if="true" prop="remark" label="备注" header-align="center" align="center" width="140"
                           show-overflow-tooltip>
          </el-table-column>

          <el-table-column v-if="true" prop="invPrice" label="结算单价" header-align="center" align="center"
                           fixed="right"
                           width="180"
                           show-overflow-tooltip>
<!--            <template #default="scope">-->
<!--              <el-input-number v-if="!scope.row.qtyEdit" :min="0"-->
<!--                               @change="outquantityChangeInvPrice( scope.row ,scope.$index)"-->
<!--                               v-model="scope.row.invPrice"></el-input-number>-->
<!--            </template>-->
          </el-table-column>
          <el-table-column v-if="true" prop="invAmt" label="结算金额" header-align="center" align="center" width="140"  fixed="right"
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column v-if="true" label="操作" header-align="center" align="center" width="140"  fixed="right"
                           show-overflow-tooltip>
            <template #default="scope">
              <el-button type="danger" plain @click="lineRowDelete(scope.row,scope.$index)">删除</el-button>
            </template>
          </el-table-column>

        </el-table>

      </el-card>
      <el-card :body-style="cardBodyStyle">
        <el-divider content-position="left">
          <div style="display: flex; text-align: center;align-items: center">
            <span style="color: #409EFF;">
              出库数据
            </span>
          </div>
        </el-divider>
        <el-button type="primary" plain @click="queryOutRecord">查询</el-button>
      <el-table :data="tableDataOutRecord" border highlight-current-row height="300"
                @selection-change="handleSelectionChangeOutRecord">
        <el-table-column type="selection" fixed></el-table-column>
        <el-table-column type="index" label="序号" align="center" width="60">
          <template #default="scope">
            <span>{{ scope.$index + (currentPageOutRecord - 1) * pageSizeOutRecord + 1 }}</span>
          </template>
        </el-table-column>
        <el-table-column v-if="true" prop="stoOutNo" label="出库单号" width="150" header-align="center"
                         align="center" show-overflow-tooltip>
        </el-table-column>
        <el-table-column v-if="true" prop="itemCd" label="物料编码" width="130" header-align="center"
                         align="center" show-overflow-tooltip>
        </el-table-column>
        <el-table-column v-if="true" prop="itemNm" label="物料名称" width="140" header-align="center"
                         align="center" show-overflow-tooltip>
        </el-table-column>
        <el-table-column v-if="true" prop="qty" label="数量" header-align="center" align="center" width="180"
                         show-overflow-tooltip>
          <template #default="scope">
            <el-input-number v-if="!scope.row.qtyEdit" :min="0"
                             @change="outquantityChange( scope.row ,scope.$index)"
                             v-model="scope.row.qty"></el-input-number>

          </template>
        </el-table-column>
        <el-table-column v-if="true" prop="qtyWet" label="湿基量" header-align="center" align="center" width="140"
                         show-overflow-tooltip>
        </el-table-column>
        <el-table-column v-if="true" prop="uom" label="计量单位" header-align="center" align="center" width="140" :formatter="formatter"
                         show-overflow-tooltip>
        </el-table-column>
        <el-table-column v-if="true" prop="transTasteSci" label="品位" width="120" header-align="center"
                         align="center"
                         show-overflow-tooltip>
        </el-table-column>
        <el-table-column v-if="true" prop="transWaterSci" label="水分" width="120" header-align="center"
                         align="center"
                         show-overflow-tooltip>
        </el-table-column>
        <el-table-column v-if="false" prop="itemType" label="物料类型" header-align="center" align="center"
                         width="140"
                         show-overflow-tooltip>
        </el-table-column>
        <el-table-column v-if="true" prop="tradePartnerName" label="供应商名称" header-align="center" align="center"
                         width="140"
                         show-overflow-tooltip>
        </el-table-column>
        <el-table-column v-if="true" prop="carNo" label="车号" header-align="center" align="center" width="140"
                         show-overflow-tooltip>
        </el-table-column>

        <el-table-column v-if="true" prop="storeCd" label="库房" header-align="center" align="center" width="140"
                         show-overflow-tooltip>
        </el-table-column>
        <el-table-column v-if="true" prop="stoOutDt" label="出库业务日期时间" header-align="center" align="center"
                         width="180"
                         show-overflow-tooltip>
        </el-table-column>
        <el-table-column v-if="true" prop="contrNo" label="合同编号" header-align="center" align="center"
                         width="140"
                         show-overflow-tooltip>
        </el-table-column>
        <el-table-column v-if="true" prop="khContrNo" label="对方合同编号" header-align="center" align="center"
                         width="140"
                         show-overflow-tooltip>
        </el-table-column>
        <el-table-column v-if="true" prop="outFlag" label="出库标记" header-align="center" align="center" width="140"
                         show-overflow-tooltip>
        </el-table-column>
        <el-table-column v-if="true" prop="billYn" label="是否结算" header-align="center" align="center" width="140"
                         show-overflow-tooltip>
        </el-table-column>
        <el-table-column v-if="true" prop="billNo" label="结算单号" header-align="center" align="center" width="140"
                         show-overflow-tooltip>
        </el-table-column>
        <el-table-column v-if="true" prop="tmsYn" label="是否出厂" header-align="center" align="center" width="140"
                         show-overflow-tooltip>
        </el-table-column>
        <el-table-column v-if="true" prop="syiYn" label="是否检化验" header-align="center" align="center"
                         width="140"
                         show-overflow-tooltip>
        </el-table-column>
        <el-table-column v-if="true" prop="tmsNo" label="物流计量业务单号" header-align="center" align="center"
                         width="140"
                         show-overflow-tooltip>
        </el-table-column>
        <el-table-column v-if="true" prop="syiNo" label="检化验业务单号" header-align="center" align="center"
                         width="140"
                         show-overflow-tooltip>
        </el-table-column>
        <el-table-column v-if="true" prop="remark" label="备注" header-align="center" align="center" width="140"
                         show-overflow-tooltip>
        </el-table-column>

        <el-table-column v-if="true" prop="endPrice" label="结算单价" header-align="center" align="center"
                         fixed="right"
                         width="180"
                         show-overflow-tooltip>
          <template #default="scope">
            <el-input-number v-if="!scope.row.qtyEdit" :min="0"
                             @change="outquantityChangeEndPrice( scope.row ,scope.$index)"
                             v-model="scope.row.endPrice"></el-input-number>
          </template>
        </el-table-column>

      </el-table>

      </el-card>

      <el-card :body-style="cardBodyStyle">
        <el-affix position="bottom" :offset="20">
          <el-card>
            <h3>
              <!--          结算单价 = 单价 + ((检化验的量 - 基础值)/ 项目跨度 * 结算差额 )-->
              <!--          <br>-->
              <!--          当前结算单价 = {{form.price}}-->
              结算金额= {{ form.gongshi }}

            </h3>
          </el-card>
        </el-affix>
      </el-card>


      <template #footer>
        <div class="dialog-footer">
          <el-button type="success" @click="handleSaveEdit(ruleFormRef)" plain>保存</el-button>
          <el-button type="danger" @click="dialogVisibleEdit = false" plain>取消</el-button>
        </div>
      </template>
    </el-dialog>
    <el-dialog class="diaClass" :close-on-click-modal="false" draggable title="查看" v-model="dialogVisibleInfo" fullscreen width="1200"
               top="5vh" @open="openDialog" @close="diaClose">
      <el-card :body-style="cardBodyStyle">
        <el-divider content-position="left">
          <div style="color: #409EFF">结算信息</div>
        </el-divider>
        <el-form :model="form" label-width="110px" label-position="right" inline ref="ruleFormRef" :rules="rules">
          <el-row>
            <el-col :span="6">
              <el-form-item label="结算单号" prop="invNo" style="width: 100%">
                <el-input v-model="form.invNo" disabled>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="结算日期" prop="invDt" style="width: 100%">
                <el-date-picker
                    disabled
                    style="width: 100%"
                    v-model="form.invDt"
                    type="date"
                    value-format="YYYY-MM-DD"
                    placeholder="申请日期"
                />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="合同编号" prop="contrNo" style="width: 100%">
                <el-input v-model="form.contrNo" readonly>
<!--                  <template #append>-->
<!--                    <el-button :icon="Search" @click="dialogHt()"/>-->
<!--                  </template>-->
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="对方合同编号" prop="khContrNo">
                <el-input v-model="form.khContrNo" readonly>

                </el-input>
              </el-form-item>
            </el-col>

            <el-col :span="6">
              <el-form-item label="客户名称" prop="tradePartnerName">
                <el-input v-model="form.tradePartnerName" readonly>

                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="定价方式" prop="priceDcnMth">
                <el-select v-model="form.priceDcnMth" placeholder="请选择" clearable style="" disabled>
                  <el-option v-for="item in dicList.PRICE_DCN_MTH" :key="item.dicCode" :label="item.dicName"
                             :value="item.dicCode"/>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="税率" prop="taxRate">
                <el-input v-model="form.taxRate" readonly>

                </el-input>
              </el-form-item>
            </el-col>

            <el-col :span="6">
              <el-form-item label="结算类型" prop="payMth">
                <SelectorComponent :optionList="dicList.COM_PAY_MTH" :value="form.payMth" :allow-select="true"
                                   @change="payMathSelect"/>
              </el-form-item>
            </el-col>

            <el-col :span="6">
              <el-form-item label="结算重量" prop="qty">
                <el-input v-model="form.qty" readonly>

                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="结算金额" prop="invAmt">
                <el-input v-model="form.invAmt" readonly>

                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="结算标识" prop="invFlag">
                <SelectorComponent :optionList="dicList.INV_FLAG" :value="form.invFlag" :allow-select="true"  :allowSelect="true"
                                   @change="invFlagSelect"/>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="开始时间" prop="invStartTime">
                <el-date-picker
                    style="width: 100%"
                    v-model="form.invStartTime"
                    type="datetime"
                    value-format="YYYY-MM-DD HH:mm:ss"
                    format="YYYY-MM-DD HH:mm:ss"
                    placeholder="开始时间"
                    readonly
                />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="结束时间" prop="invEndTime">
                <el-date-picker
                    readonly
                    style="width: 100%"
                    v-model="form.invEndTime"
                    value-format="YYYY-MM-DD HH:mm:ss"
                    format="YYYY-MM-DD HH:mm:ss"
                    type="datetime"
                    placeholder="结束时间"
                />
              </el-form-item>
            </el-col>


            <el-col :span="24">
              <el-form-item label="开票说明">
                <el-input
                    readonly
                    v-model="form.invDesc"
                    :autosize="{ minRows: 2, maxRows: 4 }"
                    type="textarea"
                    placeholder=""
                />
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="备注">
                <el-input
                    readonly
                    v-model="form.remark"
                    :autosize="{ minRows: 2, maxRows: 4 }"
                    type="textarea"
                    placeholder=""
                />
              </el-form-item>
            </el-col>
          </el-row>

        </el-form>

      </el-card>
      <el-card :body-style="cardBodyStyle">
        <el-divider content-position="left">
          <div style="display: flex; text-align: center;align-items: center">
            <span style="color: #409EFF;">
              结算标准
            </span>

            <el-tooltip
                class="box-item"
                effect="dark"
                content="选择要结算的结算标准，用以生成结算单价"
                placement="top"
            >
              <el-icon style="color: #a5a5a5;">
                <InfoFilled/>
              </el-icon>
            </el-tooltip>

          </div>
        </el-divider>
        <div style="display: flex">
          <el-table :data="tableDataSettlement" border highlight-current-row
                    @selection-change="handleSelectionChangeSettlement"
                    height="245">
            <!--            <el-table-column type="selection" fixed></el-table-column>-->
            <el-table-column type="index" label="序号" align="center" width="60">
              <template #default="scope">
                <span>{{ scope.$index + (currentPage - 1) * pageSize + 1 }}</span>
              </template>
            </el-table-column>
            <el-table-column v-if="true" prop="settleNo" label="结算项目编码" min-width="100" header-align="center"
                             align="center" show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="settleItem" label="结算项目" min-width="100" header-align="center"
                             align="center" show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="settleValueTo" label="结算项目上限" min-width="100" header-align="center"
                             align="right" show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="settleValueFrom" label="结算项目下限" min-width="100"
                             header-align="center"
                             align="right" show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="referenceValue" label="基准值" min-width="100" header-align="center"
                             align="right" show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="settleSpan" label="结算项目跨度" min-width="100" header-align="center"
                             align="right" show-overflow-tooltip>
            </el-table-column>
            <el-table-column v-if="true" prop="settleDiffer" label="结算差额" min-width="100" header-align="center"
                             align="right" show-overflow-tooltip>
            </el-table-column>


          </el-table>
        </div>


      </el-card>
      <el-card :body-style="cardBodyStyle">
        <el-divider content-position="left">
          <div style="display: flex; text-align: center;align-items: center">
            <span style="color: #409EFF;">
              结算行
            </span>
          </div>
        </el-divider>

        <el-table :data="tableDataLine" border highlight-current-row height="300"
                  @selection-change="handleSelectionChangeOutRecord">
<!--          <el-table-column type="selection" fixed></el-table-column>-->
          <el-table-column type="index" label="序号" align="center" width="60">
            <template #default="scope">
              <span>{{ scope.$index + (currentPageOutRecord - 1) * pageSizeOutRecord + 1 }}</span>
            </template>
          </el-table-column>
          <el-table-column v-if="true" prop="stoOutNo" label="出库单号" width="150" header-align="center"
                           align="center" show-overflow-tooltip>
          </el-table-column>
          <el-table-column v-if="true" prop="invLine" label="结算行号" width="150" header-align="center"
                           align="center" show-overflow-tooltip>
          </el-table-column>
          <el-table-column v-if="true" prop="itemCd" label="物料编码" width="130" header-align="center"
                           align="center" show-overflow-tooltip>
          </el-table-column>
          <el-table-column v-if="true" prop="itemNm" label="物料名称" width="140" header-align="center"
                           align="center" show-overflow-tooltip>
          </el-table-column>
          <el-table-column v-if="true" prop="qty" label="数量" header-align="center" align="center" width="180"
                           show-overflow-tooltip>
<!--            <template #default="scope">-->
<!--              <el-input-number v-if="!scope.row.qtyEdit" :min="0"-->
<!--                               @change="outquantityChangeEdit( scope.row ,scope.$index)"-->
<!--                               v-model="scope.row.qty"></el-input-number>-->

<!--            </template>-->
          </el-table-column>
          <el-table-column v-if="true" prop="stoOutWgt" label="湿基量" header-align="center" align="center" width="140"
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column v-if="true" prop="transTasteSci" label="品位" header-align="center" align="center" width="140"
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column v-if="true" prop="transWaterSci" label="水分" header-align="center" align="center" width="140"
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column v-if="true" prop="uom" label="计量单位" header-align="center" align="center" width="140" :formatter="formatter"
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column v-if="true" prop="transTasteSci" label="品位" width="120" header-align="center"
                           align="center"
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column v-if="true" prop="transWaterSci" label="水分" width="120" header-align="center"
                           align="center"
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column v-if="false" prop="itemType" label="物料类型" header-align="center" align="center"
                           width="140"
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column v-if="true" prop="contrNo" label="合同编号" header-align="center" align="center"
                           width="140"
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column v-if="true" prop="khContrNo" label="对方合同编号" header-align="center" align="center"
                           width="140"
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column v-if="true" prop="invNo" label="结算单号" header-align="center" align="center" width="140"
                           show-overflow-tooltip>
          </el-table-column>

          <el-table-column v-if="true" prop="tmsNo" label="物流计量业务单号" header-align="center" align="center"
                           width="140"
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column v-if="true" prop="syiNo" label="检化验业务单号" header-align="center" align="center"
                           width="140"
                           show-overflow-tooltip>
          </el-table-column>
          <el-table-column v-if="true" prop="remark" label="备注" header-align="center" align="center" width="140"
                           show-overflow-tooltip>
          </el-table-column>

          <el-table-column v-if="true" prop="invPrice" label="结算单价" header-align="center" align="center"
                           fixed="right"
                           width="180"
                           show-overflow-tooltip>
<!--            <template #default="scope">-->
<!--              <el-input-number v-if="!scope.row.qtyEdit" :min="0"-->
<!--                               @change="outquantityChangeInvPrice( scope.row ,scope.$index)"-->
<!--                               v-model="scope.row.invPrice"></el-input-number>-->
<!--            </template>-->
          </el-table-column>
          <el-table-column v-if="true" prop="invAmt" label="结算金额" header-align="center" align="center" width="140"  fixed="right"
                           show-overflow-tooltip>
          </el-table-column>

        </el-table>

      </el-card>



      <template #footer>
        <div class="dialog-footer">
          <el-button type="danger" @click="dialogVisibleInfo = false" plain>取消</el-button>
        </div>
      </template>
    </el-dialog>



    <PopupCot ref="PopupRefHT" :params="contrTyStr" @receive-from-child="retu"></PopupCot>

    <el-dialog :close-on-click-modal="false" draggable v-model="reportDialogVisible" width="900px" top="5vh">
      <fine-report ref="finereport" :reportPath="reportPath"></fine-report>
    </el-dialog>
  </div>
</template>

<script setup>
/*销售结算*/
import {
  ref,
  reactive,
  onMounted,
  getCurrentInstance
} from 'vue'
import {Search} from '@element-plus/icons-vue'
import dayjs from 'dayjs'

const {
  proxy
} = getCurrentInstance()


import style from '@/tools/style'

const cardBodyStyle = ref(style.card)

const tableStatus = reactive({
  tableRowEditIndex: undefined,
  tableColumnEditIndex: undefined,
})
import SearchBar from '@/components/SearchBar.vue';
import PopupMenuTree from '@/components/PopupMenuTree.vue'
import ButtonBar from "@/components/ButtonBar.vue";
import Selector_component from "@/views/sal/components/Selector_component.vue";
import PopupCot from "@/views/cot/components/PopupCot.vue";
import SelectorComponent from "@/views/sal/components/Selector_component.vue";
import tools from "@/tools";
import {workflowCancel, workflowSubmit} from "@/tools/workflow.js";

const searchBarRef = ref(null)
const formItem = ref([
  {
    prop: 'birthDate',
    type: 'input',
    label: '订单号'
  },
  {
    prop: 'age',
    type: 'input',
    label: '客户名称',
    searchButton: true,
    searchCallback: 'showPop'
  }

])

const tableTwoUpShow = ref(false)
const dialogVisible = ref(false)
const dialogVisibleEdit = ref(false)
const dialogVisibleInfo = ref(false)

const tableTwoUpShowFunc = () => {
  tableTwoUpShow.value = !tableTwoUpShow.value
}

const searchForm = (val) => {
  query.value = searchBarRef.value.form
  console.log(JSON.stringify(query.value))
}

/**
 *   查询
 */

const query = ref({
  invDtList: ['', ''],
  invNo: '',
  tradePartnerName: '',
  contrNo: '',
})
// 首 列表
const tableData = ref([])

const tableDataLine = ref([])
const tableDataOutRecord = ref([])


const getTableData = () => {
  var url = 'sal/InvHead/query'
  var param = {
    page: currentPage.value,
    rows: pageSize.value,
    params: JSON.stringify(query.value)
  }
  proxy.$axios.get(url, param).then(response => {
    if (response.data.code == '0') {
      tableData.value = response.data.data.records
      totalRows.value = response.data.data.total
    } else {
      ElMessage.error('操作失败！' + response.data.msg)
    }
  })
}
/**
 *   查询
 */
/**
 * 分页
 */
const currentPage = ref(1)
const currentPageOutRecord = ref(1)
const currentPageLine = ref(1)
const totalRows = ref(0)
const totalRowsOutRecord = ref(0)
const totalRowsLine = ref(0)
const pageSizes = ref([5, 10, 20, 30, 40])
const pageSizesOutRecord = ref([5, 10, 20, 30, 40])
const pageSizesLine = ref([5, 10, 20, 30, 40])
const pageSize = ref(5)
const pageSizeOutRecord = ref(5)
const pageSizeLine = ref(5)
const handleSizeChange = (val) => {
  pageSize.value = val
  getTableData()
}
const handleSizeChangeOutRecord = (val) => {
  pageSizeOutRecord.value = val
}
const handleSizeChangeLine = (val) => {
  pageSizeLine.value = val
  getTableDataLine()
}
const handleCurrentChange = (val) => {
  currentPage.value = val
  getTableData()
}

const handleCurrentChangeOutRecord = (val) => {
  currentPageOutRecord.value = val
}

const handleCurrentChangeLine = (val) => {
  currentPageLine.value = val
  getTableDataLine()
}


const PopupMenuTreeRef = ref(null)
const showPop = () => {
  console.log('showPop')
  PopupMenuTreeRef.value.show()
}
/**
 * 新增表单form
 */
const form = ref({
  id: '',
  contrNo: '',
  khContrNo: '',
  tradePartnerId: '',
  tradePartnerName: '',
  tradePartnerCOde: '',
  invflag: '1',
  invStartTime:'',
  invEndTime:proxy.$dayjs(),

})


// 校验
const rules = reactive({
  contrNo: [
    {required: true, message: '不允许为空', trigger: 'blur' | 'change'},
  ],
  taxRate: [
    {required: true, message: '不允许为空', trigger: 'blur' | 'change'},
  ],
  payMth: [
    {required: true, message: '不允许为空', trigger: 'blur' | 'change'},
  ],
  invStartTime: [
    {required: true, message: '不允许为空', trigger: 'blur' | 'change'},
  ],
  invEndTime: [
    {required: true, message: '不允许为空', trigger: 'blur' | 'change'},
  ],

})

// 首-列表 编辑
const handleEdit = (row) => {
  form.value = {}
  form.value = row
  form.value.invFlag = String(form.value.invFlag)
  form.value.edit = true
  tableDataOutRecord.value  = []
  tableDataSettlement.value  = []

  conLine(row.contrNo)


  querySettlement.value = {
    contrId: row.contrId,
    conLineId: row.taxRateLine,
  }

  getTableDataSettlement()


  dialogVisibleEdit.value = true

  multipleSelection.value = []


  setTimeout(() => {
    jisuan()
  }, 1000);
}

const handleDelete = (row) => {
  ElMessageBox.confirm(
      '确定删除本条记录?',
      '提示', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning',
        draggable: true,
      }
  )
      .then(() => {
        var url = 'sal/InvHead/remove'
        var param = {
          id: row.id
        }
        proxy.$axios.get(url, param).then(response => {
          if (response.data.code == '0') {
            console.log(response.data.data)
            ElMessage({
              type: 'success',
              message: '删除成功！',
            });
            getTableData()
            getTableDataLine({id:''})
          } else {
            ElMessage.error('操作失败！' + response.data.msg)
          }
        })
      })
      .catch(() => {
        ElMessage({
          type: 'info',
          message: '已取消',
        })
      })
}



const handleSearch = () => {
  currentPage.value = 1
  getTableData()
  getTableDataLine({id:''})
}

const handleAdd = () => {
  form.value = {
    invDt: proxy.$dayjs().format('YYYY-MM-DD'),
    invStartTime: proxy.$dayjs().format('YYYY-MM-DD') + " 00:00:00",
    invEndTime:proxy.$dayjs().format('YYYY-MM-DD HH:mm:ss'),
    invFlag: "1",
  }
  dialogVisible.value = true
  tableDataOutRecord.value = []
  tableDataSettlement.value = []
  tableDataLine.value = []


}

const dicList = ref([])
//获取字典集合
const getDicList = () => {
  tools.dic.getDicList(['MEASURING_UNIT', 'COM_PAY_MTH', 'INV_FLAG', 'PRICE_DCN_MTH']).then((response => {

    dicList.value = response.data.data
  }))
}

const handleCancelSave = () => {
  dialogVisible.value = false
}
const handleCancelSaveInfo = () => {
  dialogVisibleInfo.value = false
}
const PopupRefHT = ref(null)
const dialogHt = (val) => {
  PopupRefHT.value.open()
}
const retu = (val) => {
  form.value.taxRate = ''
  tableDataOutRecord.value = []
  console.log("vla", val)
  form.value.contrNo = val.contrNo
  form.value.khContrNo = val.khContrNo
  form.value.tradePartnerId = val.supplierId
  form.value.tradePartnerCode = val.supplierCd
  form.value.tradePartnerName = val.supplierNm

  form.value.taxRateLine = ''

  form.value.priceDcnMth = val.priceDcnMth
  form.value.contrId = val.id

  conLine(val.contrNo)
}

const contrTyStr = ref({
  contrTy: '10',
  supplierCd: ''
})

const lineList = ref([])
const lineKey = ref()
const conLine = (val) => {
  lineList.value = []
  var url = 'cot/Line/query'
  var param = {
    page: 1,
    rows: 999999,
    params: JSON.stringify({contrNo: val})
  }
  proxy.$axios.get(url, param).then(response => {
    if (response.data.code == '0') {
      lineKey.value = new Date().getTime()
      console.log(response.data.data.records)
      // var arr = []
      // for(var i = 0 ; i < response.data.data.records.length ; i++){
      // arr.push(response.data.data.records[i].taxRate)
      // }
      // let uniqueArr = [...new Set(arr)];

      lineList.value = response.data.data.records
      if (form.value.taxRateLine != null && form.value.taxRateLine != ''){
        for(var i =0 ; i < lineList.value.length ; i++){
          if (lineList.value[i].id == form.value.taxRateLine){
            form.value.taxPriceBill = lineList.value[i].taxPriceBill
            form.value.taxPriceCash = lineList.value[i].taxPriceCash
            break;
          }
        }
      }



    } else {
      ElMessage.error('操作失败！' + response.data.msg)
    }
  })

}
const queryShow = ref(false)
const show = () => {
  queryShow.value = true
}

const taxRateChange = (val) => {
  form.value.taxRate = val.taxRate
  tableDataOutRecord.value = []
  querySettlement.value = {
    contrId: form.value.contrId,
    conLineId: val.id,
  }
  getTableDataSettlement()
  form.value.taxPriceBill = val.taxPriceBill
  form.value.taxPriceCash = val.taxPriceCash
  // if (Number(val.taxPriceBill) != 0) {
  //   form.value.price = val.taxPriceBill
  // } else {
  //   form.value.price = val.taxPriceCash
  // }
  form.value.taxRateLine = val.id
  // console.log(val)
  form.value.transTasteSci = val.specType
  // if (form.value.priceDcnMth != '10'){
  // 取最新定价，
  // getNewPrice(val.itemCd)
  // }
}


const payMathSelect = (val) => {
  form.value.payMth = val
  console.log(val)
  tableDataOutRecord.value = []
  // queryOutRecord()
}
const invFlagSelect = (val) => {
  form.value.invFlag = val
  console.log(val)
}

const ruleFormRef = ref(null)
const handleSave = (ruleFormRef) => {
  if (!ruleFormRef) return
  ruleFormRef.validate((valid) => {
    if (valid) {
      // form.value.invLineList = multipleSelection.value
      var url = 'sal/InvHead/save'
      var param = {
        json: JSON.stringify(form.value),
        lines: JSON.stringify(multipleSelection.value),
      }
      proxy.$axios.post(url, param).then(response => {
        if (response.data.code == 0) {
          ElMessage({
            message: '保存成功',
            type: 'success',
          })
          getTableData()
          getTableDataLine(response.data.data)
          dialogVisible.value = false
        } else {
          // ElMessage.error('操作失败！' + response.data.msg)
          ElMessage({
            type: 'error',
            message: '操作失败' + response.data.msg
          })
        }
      });
    } else {
      console.log('error submit!')
      return false
    }

  })
}
const handleSaveEdit = (ruleFormRef) => {
  if (!ruleFormRef) return
  ruleFormRef.validate((valid) => {
    if (valid) {
      // form.value.invLineList = multipleSelection.value
      multipleSelection.value
      for (var i = 0; i < tableDataLine.value.length ; i++){
        multipleSelection.value.push(tableDataLine.value[i])
      }

      var url = 'sal/InvHead/save'
      var param = {
        json: JSON.stringify(form.value),
        lines: JSON.stringify(multipleSelection.value),
      }
      proxy.$axios.post(url, param).then(response => {
        if (response.data.code == 0) {
          ElMessage({
            message: '保存成功',
            type: 'success',
          })
          getTableData()
          getTableDataLine(response.data.data)
          dialogVisibleEdit.value = false
        } else {
          // ElMessage.error('操作失败！' + response.data.msg)
          ElMessage({
            type: 'error',
            message: '操作失败' + response.data.msg
          })
        }
      });
    } else {
      console.log('error submit!')
      return false
    }

  })
}

const handleInfo = (row) => {
  var url = 'sal/InvHead/queryByPK'
  var param = {
    id: row.id,
  }
  proxy.$axios.get(url, param).then(response => {
    if (response.data.code == '0') {
      form.value = {}
      form.value = response.data.data
      form.value.invFlag = String(response.data.data.invFlag)
      querySettlement.value = {
        contrId: response.data.data.contrId,
        conLineId: response.data.data.taxRateLine,
      }

      getTableDataSettlement()
      dialogVisibleInfo.value = true
    } else {
      ElMessage.error('操作失败！' + response.data.msg)
    }
  })
}

const closeDialog = (row) => {

  form.value = {}

}

const formatter = (row, column, cellValue, index) => {
  if (!cellValue || cellValue == null || cellValue == '') {
    return cellValue
  }
  switch (column.property) {
    case 'payMth':
      cellValue = dicList.value && Array.isArray(dicList.value.COM_PAY_MTH)
          ? dicList.value.COM_PAY_MTH.find(item => item.dicCode == cellValue)?.dicName
          : undefined
      break
    case 'invFlag':
      cellValue = dicList.value && Array.isArray(dicList.value.INV_FLAG)
          ? dicList.value.INV_FLAG.find(item => item.dicCode == cellValue)?.dicName
          : undefined
      break
    case 'uom':
      cellValue = dicList.value && Array.isArray(dicList.value.MEASURING_UNIT)
          ? dicList.value.MEASURING_UNIT.find(item => item.dicCode == cellValue)?.dicName
          : undefined
      break;
  }
  return cellValue

}

const reset = () => {
  query.value = {
    invDtList: ['', ''],
    invNo: '',
    tradePartnerName: '',
    contrNo: '',
  }
}

const submit = () => {
  ElMessage({
    type: 'info',
    message: '暂不支持提交！'
  })
}
const cellId = ref('')
const cellHover = (row) => {
  if (cellId.value != row.id){
    tableDataLine.value = []
    cellId.value = row.id
    getTableDataLine(row)
  }


}
const getTableOutRecord = (row) => {
  var url = 'sal/StoOutRecord/recordByContrNoAndTaxRate'
  var ifTrue = false
  if (form.value.priceDcnMth == '10') {
    ifTrue = true
  }
  var obj = {
    contrNo: row.contrNo,
    taxRate: row.taxRate,
    ifTrue: ifTrue,
    payMth: row.payMth,
    taxPriceCash: row.taxPriceCash,
    taxPriceBill: row.taxPriceBill,
    invStartTime: row.invStartTime,
    invEndTime: row.invEndTime,
    specType: row.specType,
  }

  if (row.payMth == "A"){
    form.value.contrLineNoPrice = row.taxPriceCash
  } else {
    form.value.contrLineNoPrice = row.taxPriceBill
  }

  var param = {
    page: currentPageOutRecord.value,
    rows: pageSizeOutRecord.value,
    jsons: JSON.stringify(obj)
  }
  proxy.$axios.get(url, param).then(response => {
    if (response.data.code == '0') {
      tableDataOutRecord.value = response.data.data.records
      totalRowsOutRecord.value = response.data.data.total
      // if (form.value.priceDcnMth != '10') {
        for (var i = 0; i < response.data.data.records.length; i++) {
          tableDataOutRecord.value[i].invPriceBase = tableDataOutRecord.value[i].price
          if (response.data.data.records[i].transIdSci != null && response.data.data.records[i].transIdSci != ''){
            transIdSci(response.data.data.records[i], i)
          }
        }
      // }

    } else {
      ElMessage.error('操作失败！' + response.data.msg)
    }
  })
}
const getTableDataLine = (row) => {
  var url = 'sal/InvLine/query'
  var param = {
    page: currentPageLine.value,
    rows: pageSizeLine.value,
    params: JSON.stringify({fId : row.id})
  }
  proxy.$axios.get(url, param).then(response => {
    if (response.data.code == '0') {
      tableDataLine.value = response.data.data.records
      totalRowsLine.value = response.data.data.total
      // jisuan()
    } else {
      ElMessage.error('操作失败！' + response.data.msg)
    }
  })
}

const multipleSelection = ref([])
const handleSelectionChangeOutRecord = (val) => {
  multipleSelection.value = val
  jisuan()
}

const jisuan = () => {

  var qty = 0
  for (var i = 0; i < multipleSelection.value.length; i++) {
    qty += multipleSelection.value[i].qty
  }
  if (form.value.edit){

    for (var i = 0; i < tableDataLine.value.length; i++) {
      qty += tableDataLine.value[i].qty
    }
  }
  form.value.qty = qty
  console.log(multipleSelection.value)

  var invAmt = 0

  // var gongshi = '重量 ( 0 ) ' + '*' + '结算单价 ( 0 )'
  var gongshi = ''

  if (form.value.edit){
    // 编辑
    var s = ''

    for (var i = 0; i < tableDataLine.value.length; i++) {
      s += ' 重量 ( ' + (tableDataLine.value[i].qty) + ' ) * ' + '结算单价 ( ' + (tableDataLine.value[i].invPrice) + ' )'
      if ((i + 1) != tableDataLine.value.length) {
        s += ' + '
      }
      var amt = tableDataLine.value[i].qty * tableDataLine.value[i].invPrice
      tableDataLine.value[i].invAmt = amt
      invAmt += amt
    }
    gongshi += s
  }
  if (multipleSelection.value.length > 0) {
    var s = ''
    if (tableDataLine.value.length > 0){
      s += ' + '
    }
    for (var i = 0; i < multipleSelection.value.length; i++) {
      s += ' 重量 ( ' + (multipleSelection.value[i].qty) + ' ) * ' + '结算单价 ( ' + (multipleSelection.value[i].endPrice) + ' )'
      if ((i + 1) != multipleSelection.value.length) {
        s += ' + '
      }

      var amt = multipleSelection.value[i].qty * multipleSelection.value[i].endPrice
      invAmt += amt
      multipleSelection.value[i].invPrice = multipleSelection.value[i].endPrice
      multipleSelection.value[i].invAmt = amt
      multipleSelection.value[i].stoOutWgt = multipleSelection.value[i].qty
    }
    gongshi += s
  }
  if (gongshi == ''){
    gongshi = '重量 ( 0 ) ' + '*' + '结算单价 ( 0 )'
  }

  form.value.invAmt = parseFloat(invAmt.toFixed(2))
  form.value.gongshi = gongshi + ' = ' + form.value.invAmt


}


const multipleSelectionSettlement = ref([])
const handleSelectionChangeSettlement = (val) => {
  multipleSelectionSettlement.value = val
}
const querySettlement = ref({
  contrId: '',
  conLineId: ''
})
const tableDataJianHuaYan = ref([])
const tableDataSettlement = ref([])
const getTableDataSettlement = () => {
  var url = 'cot/Settlement/queryByContrIdAndConLineId'
  var param = {
    params: JSON.stringify(querySettlement.value)
  }
  proxy.$axios.post(url, param).then(response => {
    if (response.data.code == '0') {
      tableDataSettlement.value = response.data.data
      // totalRowsSettlement.value = response.data.data.total
    } else {
      ElMessage.error('操作失败！' + response.data.msg)
    }
  })
}
const transIdSci = (row, index) => {
  var url = 'sci/JkJlxx/queryHyjg'
  var param = {
    zph: row.transIdSci
  }
  proxy.$axios.post(url, param).then(response => {
    if (response.data.code == '0') {
      console.log(response.data.data)
      var endPrice = Number(row.price)
      for (var i = 0; i < tableDataSettlement.value.length; i++) {
        for (var j = 0; j < response.data.data.length; j++) {
          if (tableDataSettlement.value[i].settleItem == response.data.data[j].xiangmuMc) {
            if (Number(response.data.data[j].xiangmuXyz) <= Number(tableDataSettlement.value[i].settleValueTo ) && Number(response.data.data[j].xiangmuXyz) >=  Number(tableDataSettlement.value[i].settleValueFrom)){
              var pr = (Number(response.data.data[j].xiangmuXyz) - Number(tableDataSettlement.value[i].referenceValue)) / Number(tableDataSettlement.value[i].settleSpan) * Number(tableDataSettlement.value[i].settleDiffer)
              endPrice += Math.round(pr * 100)/100
              // if (Number(tableDataSettlement.value[i].settleSpan) > 0){
              //   var pr = (Number(response.data.data[j].xiangmuXyz) - Number(tableDataSettlement.value[i].referenceValue)) / Number(tableDataSettlement.value[i].settleSpan) * Number(tableDataSettlement.value[i].settleDiffer)
              //   endPrice += Math.round(pr * 100)/100
              // } else {
              //   var pr = (Number(response.data.data[j].xiangmuXyz) - Number(tableDataSettlement.value[i].referenceValue)) * (-1) / Number(tableDataSettlement.value[i].settleSpan) * Number(tableDataSettlement.value[i].settleDiffer)
              //   endPrice += Math.round(pr * 100)/100
              // }
            }
          }
        }
      }
      tableDataOutRecord.value[index].endPrice = endPrice

    } else {
      ElMessage.error('操作失败！' + response.data.msg)
    }
  })
}

// 获取最新定价
const getNewPrice = (val) => {

  var url = 'sal/UpriceLine/selectNewDateByItemCd'
  var param = {
    itemCd: val
  }
  proxy.$axios.get(url, param).then(response => {
    if (response.data.code == '0') {
      form.value.price = response.data.data.priceBill


    }
  })
}
const queryOutRecord = () => {
  console.log(form.value)
  var obj = {
    contrNo: form.value.contrNo,
    taxRate: form.value.taxRate,
    payMth: form.value.payMth,
    taxPriceCash: form.value.taxPriceCash,
    taxPriceBill: form.value.taxPriceBill,
    invStartTime: form.value.invStartTime,
    invEndTime: form.value.invEndTime,
    specType: form.value.transTasteSci,
  }
  if ( !form.value.contrNo){
      ElMessage({
        type: 'warning',
        message: '请先选择合同!'
      })
    return
  }
  if ( !form.value.taxRate){
      ElMessage({
        type: 'warning',
        message: '请先选择税率!'
      })
    return
  }
  if ( !form.value.payMth){
      ElMessage({
        type: 'warning',
        message: '请先选择结算类型!'
      })
    return
  }
  getTableOutRecord(obj)
  jisuan()
  // if (multipleSelectionSettlement.value.length > 0) {

    // form.value.gongshi = '重量 ( 0 ) ' + '*' + '结算单价 ( 0 ) = 0 '
    // jisuan()
  // } else {
  //   ElMessage({
  //     type: 'warning',
  //     message: '结算标准勾选数据至少有一条!'
  //   })
    // return
  // }
}

const recordQtyEdit = (row, index) => {
  tableDataOutRecord.value[index].qtyEdit = true
}


const outquantityChange = (row, index) => {
  console.log(typeof row.qty)
  if (typeof row.qty === 'number') {
    jisuan()
  } else {
    tableDataOutRecord.value[index].qty = 0
    ElMessage({
      type: 'error',
      message: '请输入数字!'
    })
    jisuan()
  }

}
const outquantityChangeEdit = (row, index) => {
  console.log(typeof row.qty)
  if (typeof row.qty === 'number') {
    jisuan()
  } else {
    tableDataLine.value[index].qty = 0
    ElMessage({
      type: 'error',
      message: '请输入数字!'
    })
    jisuan()
  }

}
const outquantityChangeEndPrice = (row, index) => {

  if (typeof row.endPrice === 'number') {
    jisuan()
  } else {
    tableDataOutRecord.value[index].endPrice = 0
    ElMessage({
      type: 'error',
      message: '请输入数字!'
    })
    jisuan()
  }

}
const outquantityChangeInvPrice = (row, index) => {

  if (typeof row.invPrice === 'number') {
    jisuan()
  } else {
    tableDataLine.value[index].invPrice = 0
    ElMessage({
      type: 'error',
      message: '请输入数字!'
    })
    jisuan()
  }

}

const diaClose = () =>{
  form.value = {}
  tableDataOutRecord.value = []
  tableDataSettlement.value = []
  lineList.value = []
}

const lineRowDelete = (row, index)=>{
  var url = 'sal/InvLine/removeLineAndStoOutRecord'
  var param = {
    id: row.id
  }
  proxy.$axios.get(url, param).then(response => {
    if (response.data.code == '0') {
      ElMessage({
        type: 'success',
        message: '删除成功！'
      })
      var obj = {
        contrNo: form.value.contrNo,
        taxRate: form.value.taxRate,
        payMth: form.value.payMth,
        taxPriceCash: form.value.taxPriceCash,
        taxPriceBill: form.value.taxPriceBill,
        invStartTime: form.value.invStartTime,
        invEndTime: form.value.invEndTime,
        specType: form.value.transTasteSci,
      }
      var par = {
        fId : form.value.id
      }
      tableDataLine.value.splice(index, 1);
      jisuan()
      // getTableDataLine(par)
      getTableOutRecord(obj)

    } else {
      ElMessage.error('操作失败！' + response.data.msg)
    }
  })
}
const flowId = ref('SalResultFinance')
const handleSubmit = (row) => {
  ElMessageBox.confirm(
      '确定提交流程?',
      '提示', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning',
        draggable: true,
      }
  ).then(() => {
    var obj = {
      id : row.id
    }
    return workflowSubmit(
        flowId.value,
        '销售结算审批流程',
        '初始化提交',
        JSON.stringify(obj),
        row.workId,
        row.trackId)
  }).then((result) => {
    if(result.status === 'success'){

      console.log(result)
      // 将结果返回的workId和trackId保存
      var url = 'sal/InvHead/submitFq'
      var process = {
        'id': row.id,
        'workId': result.workId,
        'trackId': result.trackId,
      }
      var param = {
        json: JSON.stringify(process),
      }
      proxy.$axios.post(url, param).then(response => {
        if (response.data.code === 0) {
          // form.value = response.data.data
          ElMessage({
            type: 'success',
            message: '提交审批成功',
          })
          getTableData()
        }
      })
    }
    else{
      ElMessage({
        type: 'error',
        message: '提交审批失败' + response.data.msg
      });
    }
  }).catch(() => {
    ElMessage({
      type: 'info',
      message: '已取消提交',
    })
  })
}

const handleDetail = (row) => {
  if(row.workId === null){
    ElMessage({
      type: 'info',
      message: '无法查看',
    })
  }else {

    sessionStorage.setItem('workflowQuery', JSON.stringify({
      flowId: flowId.value,
      workId: row.workId,
      trackId: row.trackId,
      date:new Date().getTime()
    }))

    proxy.$router.push({
      path: '/workflow/detail',
    })

  }
}

const handleCancel = (row) => {
  ElMessageBox.confirm(
      '确定撤回审批?',
      '提示', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning',
        draggable: true,
      }
  ).then(() => {
    return workflowCancel(row.workId, row.trackId);
  }).then((result) => {
    if(result.status === 'success'){
      ElMessage({
        type: 'success',
        message: '撤回审批成功',
      })
      getTableData()
    }else {
      ElMessage({
        type: 'error',
        message: '撤回审批失败，' + result.msg
      });
    }
  }).catch(() => {
    ElMessage({
      type: 'info',
      message: '已取消提交',
    })
  })
}
const pDate = ref('')
const pReportDate = ref('')
import FineReport from '@/components/report/FineReport.vue'
const reportPath = ref('')
const finereport = ref(null)
const reportDialogVisible = ref(false);
const searchReport = () => {
  var date = proxy.$dayjs().format('YYYY年MM月DD日')
  console.log(date)
  if (checkRow.value.length == 1){
    if (checkRow.value[0].processInstanceStatus == '170'){
      var list = []
      var url = 'workflow/process/history'
      var param = {
        workId: checkRow.value[0].workId
      }
      proxy.$axios.post(url, param).then(response => {
        if (response.data.code == '0') {
          list = response.data.data.records
          var kezhang = ""
          var lingdao = ""
          console.log("list ", list)
          for (let i = list.length - 1; i >= 0; i--) {
            if (list[i].nodeid === 'Node2') {
              kezhang = list[i].username;
              break;
            }
          }
          for (let i = list.length - 1; i >= 0; i--) {
            if (list[i].nodeid === 'Node3') {
              lingdao = list[i].username;
              break;
            }
          }
          console.log("kezhang ", kezhang)
          console.log("lingdao ", lingdao)
          reportPath.value = 'jlyypt/salResult.cpt&para1='+ date +'&para2='+String(localStorage.getItem('userDesc')) + "&id=" + checkRow.value[0].id +"&kezhang="+kezhang + "&lingdao=" +lingdao
          reportDialogVisible.value = true
          finereport.value.refresh()
        } else {
          ElMessage.error('操作失败！' + response.data.msg)
        }
      })
    } else {
      reportPath.value = 'jlyypt/salResult.cpt&para1='+date+'&para2='+String(localStorage.getItem('userDesc')) + "&id=" + checkRow.value[0].id
      reportDialogVisible.value = true
      finereport.value.refresh()
    }

    // pDate.value = monthQuery.value.monthValue.getFullYear() + String(monthQuery.value.monthValue.getMonth() + 1).padStart(2, '0')
    // pReportDate.value = formatDateToYYYYMMDD(new Date())

  } else {
    ElMessage({
      type: 'warning',
      message: '请选择一条数据！',
    })
  }

}
// 选中行
const checkRow = ref([])
const handleSelectionChange = (val) => {
  checkRow.value = val
}


onMounted(() => {
  getDicList()
  getTableData()
  console.log(`the component is now mounted.`)
})
</script>

<style scoped>
::v-deep .diaClass .el-form-item {
  width: 100%
}

.el-form-item {
  width: 100%
}

::v-deep .el-dialog__body {
  background-color: #F2F6FC;
}

</style>
