<template>
  <div>
    <!--      列设置-->
    <el-dialog title="提示" :visible.sync="showSetting" width="700px" v-dialogDrag append-to-body>
      <template slot="title">
        <div class="avue-crud__dialog__header">
          <span class="el-dialog__title">
            <span
              style="display:inline-block;width:3px;height:20px;margin-right:5px; float: left;margin-top:2px"></span>
          </span>
        </div>
      </template>
      <div>配置排序列数据（拖动调整顺序）</div>
      <div style="margin-left: 17px">
        <el-checkbox v-model="allCheck" label="全选" @change="allChecked"></el-checkbox>
      </div>
      <div style="padding: 4px; display: flex; justify-content: center">
        <draggable v-model="setRowList" group="site" animation="300" @start="onStart" @end="onEnd"
          handle=".indraggable">
          <transition-group>
            <div v-for="item in setRowList" :key="item.surface" class="listStyle">
              <div style="width: 500px" class="indraggable">
                <div class="progress" :style="{ width: item.width + 'px' }">
                  <el-checkbox :label="item.name" v-model="item.checked" :true-label="0" :false-label="1">{{ item.name
                  }}
                  </el-checkbox>
                </div>
              </div>
              <el-input-number v-model.number="item.width" controls-position="right" :min="1" :max="500" size="mini">
              </el-input-number>
            </div>
          </transition-group>
        </draggable>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="showSetting = false">取 消</el-button>
        <el-button @click="delRow" type="danger">重 置</el-button>
        <el-button type="primary" @click="save()">确 定</el-button>
      </span>
    </el-dialog>

    <div class="dialogTableTitle flex a-center jlr" style="
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin: 10px 0;
      ">
      <div>
        <el-button type="primary" :disabled="browseStatus" @click.prevent="addpayment()" size="small">新行
        </el-button>
        <el-button type="primary" size="small" @click="saveForm" :disabled="browseStatus">保 存</el-button>
        <el-button type="danger" size="small" @click.prevent="handleSelect(1)">作业费协议</el-button>
        <el-button type="info" size="small" @click.prevent="printCr" v-if="isShowInvoice == 0">请款单
        </el-button>
        <el-button size="small" type="primary" @click="feesConfirm" v-if="isShowFeesConfirm == 0">请款单</el-button>
        <el-button type="primary" size="small" v-if="browseStatus" @click="feeChange">
          费用变更
        </el-button>
      </div>
      <div style="margin: 0 10px;float: right">
        <el-button v-if="true" icon="el-icon-setting" size="mini" circle @click="showSetting = !showSetting">
        </el-button>
      </div>
    </div>
    <el-table :data="warehouseCrList" ref="table" tooltip-effect="dark" border stripe show-summary
      :summary-method="warehouseDrSummaries" @selection-change="SelectCr">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" type="index" width="80"> </el-table-column>
      <el-table-column v-for="(item, index) in getRowList" :key="index" :label="item.name" :width="item.width"
        :prop="item.label" align="center" :fixed="item.fixed" :show-overflow-tooltip="true" sortable>
        <template slot-scope="scope">
          <span v-if="item.label == 'fCorpid'">
            <el-select v-model="scope.row.fCorpid" filterable clearable placeholder="客户名称"
              :disabled="browseStatus || scope.row.fBillstatus == 6">
              <el-option v-for="(item, index) in fMblnoOptions" :key="index.fId" :label="item.fName" :value="item.fId">
              </el-option>
            </el-select>
          </span>
          <span v-else-if="item.label == 'fFeeid'">
            <el-select v-model="scope.row.fFeeid" clearable filterable placeholder="费用名称"
              :disabled="browseStatus || scope.row.fBillstatus == 6" @change="feeChoice(scope.row)">
              <el-option v-for="(item, index) in fCNameOptions" :key="index.fId" :label="item.fName" :value="item.fId">
              </el-option>
            </el-select>
          </span>
          <span v-else-if="item.label == 'fBusinessType'">
            <el-select style="width: 80%" v-model="scope.row.fBusinessType" filterable disabled>
              <el-option v-for="(item, index) in businessTypeOption" :key="index.dictValue" :label="item.dictLabel"
                :value="item.dictValue"></el-option>
            </el-select>
          </span>
          <span v-else-if="item.label == 'fFeeUnitid'">
            <el-select v-model="scope.row.fFeeUnitid" placeholder="请选择计价单位" clearable
              :disabled="browseStatus || scope.row.fBillstatus == 6" @change="changeFeeUnit(scope.row)">
              <el-option v-for="(item, index) in fFeetUnitOptions" :key="index.dictValue" :label="item.dictLabel"
                :value="item.dictValue" />
            </el-select>
          </span>
          <span v-else-if="item.label == 'fQty'">
            <el-input
              oninput='this.value=this.value.replace(/[^0-9.]/g,"").replace(/^(\-)*(\d+)\.(\d\d\d).*$/,"$1$2.$3")'
              v-model="scope.row.fQty" :disabled="browseStatus || scope.row.fBillstatus == 6"
              @change="changeContractAmt(scope.row)" placeholder="数量" show-word-limit />
          </span>
          <span v-else-if="item.label == 'fUnitprice'">
            <el-input
              oninput='this.value=this.value.replace(/[^\-?\d.]/g,"").replace(/^(\-)*(\d+)\.(\d\d\d).*$/, "$1$2.$3")'
              v-model="scope.row.fUnitprice" :disabled="browseStatus || scope.row.fBillstatus == 6"
              @change="changeContractAmt(scope.row)" placeholder="单价" show-word-limit />
          </span>
          <span v-else-if="item.label == 'fAmount'">
            <el-input disabled
              oninput='this.value=this.value.replace(/[^\-?\d.]/g,"").replace(/^(\-)*(\d+)\.(\d\d\d).*$/, "$1$2.$3")'
              v-model="scope.row.fAmount" placeholder="金额" show-word-limit />
          </span>
          <span v-else-if="item.label == 'fStltypeid'">
            <el-select v-model="scope.row.fStltypeid" placeholder="请选择结算表票结、月结"
              :disabled="browseStatus || scope.row.fBillstatus == 6">
              <el-option v-for="(item, index) in fStltypeOptions" :key="index.dictValue" :label="item.dictLabel"
                :value="item.dictValue"></el-option>
            </el-select>
          </span>
          <span v-else-if="item.label == 'fCurrency'">
            <el-input v-model="scope.row.fCurrency" :disabled="browseStatus || scope.row.fBillstatus == 6"
              placeholder="币别" show-word-limit />
          </span>
          <span v-else-if="item.label == 'fExrate'">
            <el-input v-model="scope.row.fExrate" :disabled="browseStatus || scope.row.fBillstatus == 6"
              placeholder="汇率" show-word-limit />
          </span>
          <span v-else-if="item.label == 'fTaxrate'">
            <el-input v-model="scope.row.fTaxrate" :disabled="browseStatus || scope.row.fBillstatus == 6"
              placeholder="税率" show-word-limit />
          </span>
          <span v-else-if="item.label == 'fMblno'">
            <el-input v-model="scope.row.fMblno" :disabled="browseStatus || scope.row.fBillstatus == 6"
              placeholder="提单号" show-word-limit />
          </span>
          <span v-else-if="item.label == 'fProductName'">
            <el-input v-model="scope.row.fProductName" :disabled="browseStatus || scope.row.fBillstatus == 6"
              placeholder="品名" show-word-limit />
          </span>
          <span v-else-if="item.label == 'fMarks'">
            <el-input v-model="scope.row.fMarks" :disabled="browseStatus || scope.row.fBillstatus == 6" placeholder="品牌"
              show-word-limit />
          </span>
          <span v-else-if="item.label == 'fSrcTypeId'">
            <span v-if="scope.row.fSrcTypeId === 0">录入</span>
            <span v-if="scope.row.fSrcTypeId == 1">协议</span>
            <span v-if="scope.row.fSrcTypeId == 10">变更</span>
          </span>
          <span v-else-if="item.label == 'remark'">
            <el-input v-model="scope.row.remark" :disabled="browseStatus || scope.row.fBillstatus == 6" placeholder="备注"
              show-word-limit />
          </span>
        </template>
      </el-table-column>
      <!--      <el-table-column-->
      <!--        prop="fCorpid"-->
      <!--        header-align="center"-->
      <!--        align="center"-->
      <!--        width="300px"-->
      <!--        label="客户名称"-->
      <!--      >-->
      <!--        <template slot-scope="scope">-->
      <!--          <el-select-->
      <!--            v-model="scope.row.fCorpid"-->
      <!--            filterable-->
      <!--            clearable-->
      <!--            placeholder="客户名称"-->
      <!--            :disabled="browseStatus || scope.row.fBillstatus == 6"-->
      <!--          >-->
      <!--            <el-option-->
      <!--              v-for="(item, index) in fMblnoOptions"-->
      <!--              :key="index.fId"-->
      <!--              :label="item.fName"-->
      <!--              :value="item.fId"-->
      <!--            ></el-option>-->
      <!--          </el-select>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <!--      <el-table-column-->
      <!--        prop="fFeeid"-->
      <!--        header-align="center"-->
      <!--        align="center"-->
      <!--        width="240px"-->
      <!--        label="费用名称"-->
      <!--      >-->
      <!--        <template slot-scope="scope">-->
      <!--          <el-select-->
      <!--            v-model="scope.row.fFeeid"-->
      <!--            clearable-->
      <!--            filterable-->
      <!--            placeholder="费用名称"-->
      <!--            :disabled="browseStatus || scope.row.fBillstatus == 6"-->
      <!--          >-->
      <!--            <el-option-->
      <!--              v-for="(item, index) in fCNameOptions"-->
      <!--              :key="index.fId"-->
      <!--              :label="item.fName"-->
      <!--              :value="item.fId"-->
      <!--            ></el-option>-->
      <!--          </el-select>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <!--      <el-table-column-->
      <!--        prop="fBusinessType"-->
      <!--        header-align="center"-->
      <!--        align="center"-->
      <!--        width="180px"-->
      <!--        label="作业类型"-->
      <!--      >-->
      <!--        <template slot-scope="scope">-->
      <!--          <el-select-->
      <!--            style="width: 80%"-->
      <!--            v-model="scope.row.fBusinessType"-->
      <!--            filterable-->
      <!--            disabled-->
      <!--          >-->
      <!--            <el-option-->
      <!--              v-for="(item, index) in businessTypeOption"-->
      <!--              :key="index.dictValue"-->
      <!--              :label="item.dictLabel"-->
      <!--              :value="item.dictValue"-->
      <!--            ></el-option>-->
      <!--          </el-select>-->
      <!--        </template>-->
      <!--      </el-table-column>-->

      <!--      <el-table-column-->
      <!--        prop="fFeeUnitid"-->
      <!--        header-align="center"-->
      <!--        align="center"-->
      <!--        width="180px"-->
      <!--        label="计价单位"-->
      <!--      >-->
      <!--        <template slot-scope="scope">-->
      <!--          <el-select-->
      <!--            v-model="scope.row.fFeeUnitid"-->
      <!--            placeholder="请选择计价单位"-->
      <!--            clearable-->
      <!--            :disabled="browseStatus || scope.row.fBillstatus == 6"-->
      <!--            @change="changeFeeUnit(scope.row)"-->
      <!--          >-->
      <!--            <el-option-->
      <!--              v-for="(item, index) in fFeetUnitOptions"-->
      <!--              :key="index.dictValue"-->
      <!--              :label="item.dictLabel"-->
      <!--              :value="item.dictValue"-->
      <!--            />-->
      <!--          </el-select>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <!--      <el-table-column-->
      <!--        prop="fQty"-->
      <!--        header-align="center"-->
      <!--        align="center"-->
      <!--        width="150px"-->
      <!--        label="数量"-->
      <!--      >-->
      <!--        <template slot-scope="scope">-->
      <!--          <el-input-->
      <!--            oninput='this.value=this.value.replace(/[^0-9.]/g,"").replace(/^(\-)*(\d+)\.(\d\d\d).*$/,"$1$2.$3")'-->
      <!--            v-model="scope.row.fQty"-->
      <!--            :disabled="browseStatus || scope.row.fBillstatus == 6"-->
      <!--            @change="changeContractAmt(scope.row)"-->
      <!--            placeholder="数量"-->
      <!--            show-word-limit-->
      <!--          />-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <!--      <el-table-column-->
      <!--        prop="fUnitprice"-->
      <!--        header-align="center"-->
      <!--        align="center"-->
      <!--        width="150px"-->
      <!--        label="单价"-->
      <!--      >-->
      <!--        <template slot-scope="scope">-->
      <!--          <el-input-->
      <!--            oninput='this.value=this.value.replace(/[^\-?\d.]/g,"").replace(/^(\-)*(\d+)\.(\d\d).*$/, "$1$2.$3")'-->
      <!--            v-model="scope.row.fUnitprice"-->
      <!--            :disabled="browseStatus || scope.row.fSrcTypeId !== 0 || scope.row.fBillstatus == 6"-->
      <!--            @change="changeContractAmt(scope.row)"-->
      <!--            placeholder="单价"-->
      <!--            show-word-limit-->
      <!--          />-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <!--      <el-table-column-->
      <!--        prop="fAmount"-->
      <!--        header-align="center"-->
      <!--        align="center"-->
      <!--        width="150px"-->
      <!--        label="金额"-->
      <!--      >-->
      <!--        <template slot-scope="scope">-->
      <!--          <el-input-->
      <!--            disabled-->
      <!--            oninput='this.value=this.value.replace(/[^\-?\d.]/g,"").replace(/^(\-)*(\d+)\.(\d\d).*$/, "$1$2.$3")'-->
      <!--            v-model="scope.row.fAmount"-->
      <!--            placeholder="金额"-->
      <!--            show-word-limit-->
      <!--          />-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <!--      <el-table-column-->
      <!--        prop="fStltypeid"-->
      <!--        header-align="center"-->
      <!--        align="center"-->
      <!--        width="130px"-->
      <!--        label="结算方式"-->
      <!--      >-->
      <!--        <template slot-scope="scope">-->
      <!--          <el-select-->
      <!--            v-model="scope.row.fStltypeid"-->
      <!--            placeholder="请选择结算表票结、月结"-->
      <!--            :disabled="browseStatus || scope.row.fBillstatus == 6"-->
      <!--          >-->
      <!--            <el-option-->
      <!--              v-for="(item, index) in fStltypeOptions"-->
      <!--              :key="index.dictValue"-->
      <!--              :label="item.dictLabel"-->
      <!--              :value="item.dictValue"-->
      <!--            ></el-option>-->
      <!--          </el-select>-->
      <!--        </template>-->
      <!--      </el-table-column>-->

      <!--      <el-table-column-->
      <!--        prop="fCurrency"-->
      <!--        header-align="center"-->
      <!--        align="center"-->
      <!--        width="150px"-->
      <!--        label="币别"-->
      <!--      >-->
      <!--        <template slot-scope="scope">-->
      <!--          <el-input-->
      <!--            v-model="scope.row.fCurrency"-->
      <!--            :disabled="browseStatus || scope.row.fBillstatus == 6"-->
      <!--            placeholder="币别"-->
      <!--            show-word-limit-->
      <!--          />-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <!--      <el-table-column-->
      <!--        prop="fExrate"-->
      <!--        header-align="center"-->
      <!--        align="center"-->
      <!--        width="150px"-->
      <!--        label="汇率"-->
      <!--      >-->
      <!--        <template slot-scope="scope">-->
      <!--          <el-input-->
      <!--            v-model="scope.row.fExrate"-->
      <!--            :disabled="browseStatus || scope.row.fBillstatus == 6"-->
      <!--            placeholder="汇率"-->
      <!--            show-word-limit-->
      <!--          />-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <!--      <el-table-column-->
      <!--        prop="fTaxrate"-->
      <!--        header-align="center"-->
      <!--        align="center"-->
      <!--        width="150px"-->
      <!--        label="税率"-->
      <!--      >-->
      <!--        <template slot-scope="scope">-->
      <!--          <el-input-->
      <!--            v-model="scope.row.fTaxrate"-->
      <!--            :disabled="browseStatus || scope.row.fBillstatus == 6"-->
      <!--            placeholder="税率"-->
      <!--            show-word-limit-->
      <!--          />-->
      <!--        </template>-->
      <!--      </el-table-column>-->

      <!--      <el-table-column-->
      <!--        prop="fMblno"-->
      <!--        header-align="center"-->
      <!--        align="center"-->
      <!--        width="130px"-->
      <!--        label="提单号"-->
      <!--      >-->
      <!--        <template slot-scope="scope">-->
      <!--          <el-input-->
      <!--            v-model="scope.row.fMblno"-->
      <!--            :disabled="browseStatus || scope.row.fBillstatus == 6"-->
      <!--            placeholder="提单号"-->
      <!--            show-word-limit-->
      <!--          />-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <!--      <el-table-column-->
      <!--        prop="fProductName"-->
      <!--        header-align="center"-->
      <!--        align="center"-->
      <!--        width="140px"-->
      <!--        label="品名"-->
      <!--      >-->
      <!--        <template slot-scope="scope">-->
      <!--          <el-input-->
      <!--            v-model="scope.row.fProductName"-->
      <!--            :disabled="browseStatus || scope.row.fBillstatus == 6"-->
      <!--            placeholder="品名"-->
      <!--            show-word-limit-->
      <!--          />-->
      <!--        </template>-->
      <!--      </el-table-column>-->

      <!--      <el-table-column-->
      <!--        prop="fMarks"-->
      <!--        header-align="center"-->
      <!--        align="center"-->
      <!--        width="130px"-->
      <!--        label="品牌"-->
      <!--      >-->
      <!--        <template slot-scope="scope">-->
      <!--          <el-input-->
      <!--            v-model="scope.row.fMarks"-->
      <!--            :disabled="browseStatus || scope.row.fBillstatus == 6"-->
      <!--            placeholder="品牌"-->
      <!--            show-word-limit-->
      <!--          />-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <!--      <el-table-column-->
      <!--        prop="fSrcTypeId"-->
      <!--        header-align="center"-->
      <!--        align="center"-->
      <!--        width="130px"-->
      <!--        label="来源"-->
      <!--      >-->
      <!--        <template slot-scope="scope">-->
      <!--          <span v-if="scope.row.fSrcTypeId === 0">录入</span>-->
      <!--          <span v-if="scope.row.fSrcTypeId == 1">协议</span>-->
      <!--          <span v-if="scope.row.fSrcTypeId == 10">变更</span>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <!--      <el-table-column-->
      <!--        prop="remark"-->
      <!--        header-align="center"-->
      <!--        align="center"-->
      <!--        width="150px"-->
      <!--        label="备注"-->
      <!--      >-->
      <!--        <template slot-scope="scope">-->
      <!--          <el-input-->
      <!--            v-model="scope.row.remark"-->
      <!--            :disabled="browseStatus || scope.row.fBillstatus == 6"-->
      <!--            placeholder="备注"-->
      <!--            show-word-limit-->
      <!--          />-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <el-table-column header-align="center" align="center" width="200px" label="操作" fixed="right">
        <template slot-scope="scope">
          <!-- <el-button size="small">审核费用</el-button> -->
          <el-button @click.native.prevent="deleteRow(scope.$index, warehouseCrList)" size="small"
            :disabled="browseStatus || scope.row.fBillstatus == 6">移除</el-button>
          <el-button size="small" @click="listCheck(scope.row)" v-if="scope.row.fBillstatus < 6"
            :disabled="browseStatus">请核</el-button>
          <el-button size="small" @click="revokeListCheck(scope.row)" v-if="scope.row.fBillstatus == 6"
            :disabled="browseStatus">撤销请核</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 选择作业费协议数据 -->
    <el-dialog v-dialogDrag title="作业费协议" :close-on-click-modal="false" :modal="false"
      style="box-shadow: 0 1px 3px rgba(0, 0, 0, 0) !important" :visible.sync="warehousingagreements" width="70%">
      <template slot="作业费协议">
        <div class="avue-crud__dialog__header">
          <span class="el-dialog__title">
            <span style="
                display: inline-block;
                width: 3px;
                height: 20px;
                margin-right: 5px;
                float: left;
                margin-top: 2px;
              "></span>
          </span>
        </div>
      </template>
      <el-menu :default-active="activeIndex" v-if="Navigation === true" class="el-menu-demo" mode="horizontal"
        @select="handleSelect">
        <el-menu-item index="1">车队作业费</el-menu-item>
        <el-menu-item index="2">劳务作业费</el-menu-item>
      </el-menu>

      <el-table :data="tasklegList" ref="table" tooltip-effect="dark" width="100%" border stripe
        @selection-change="whgenlegSelectionChange">
        <el-table-column type="selection" width="55"> </el-table-column>
        <el-table-column label="行号" type="index" width="80">
        </el-table-column>
        <el-table-column prop="fCorpname" header-align="center" align="center" label="客户名称" />
        <el-table-column prop="fName" header-align="center" align="center" label="费用名称" />
        <el-table-column prop="fFeeUnitid" header-align="center" align="center" width="180px" label="计价单位">
          <template slot-scope="scope">
            <el-select v-model="scope.row.fFeeUnitid" placeholder="请选择计价单位" @change="changeFeeUnit(scope.row)" disabled
              clearable>
              <el-option v-for="(dict, index) in fFeetUnitOptions" :key="index.dictValue" :label="dict.dictLabel"
                :value="dict.dictValue" />
            </el-select>
          </template>
        </el-table-column>
        <el-table-column prop="fPrice" header-align="center" align="center" label="单价" width="100px" />
        <el-table-column prop="remark" header-align="center" align="center" label="备注" />
      </el-table>

      <pagination v-show="whgenlegTotal > 0" :total="whgenlegTotal" :page.sync="pageNum" :limit.sync="pageSize"
        @pagination="getWhgenlegList" />
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="zhgenlegData" :disabled="browseStatus">导 入</el-button>
        <el-button @click="
          warehousingagreements = false;
        Navigation = false;
        ">取 消</el-button>
      </div>
    </el-dialog>
    <!--    付款信息作业单-->
    <el-dialog :visible.sync="print_Cr" width="70%" :close-on-click-modal="false" :modal="false">
      <div id="print_Cr" class="print-div">
        <div class="print-title" style="
            display: flex;
            justify-content: center;
            font-size: 24px;
            margin-bottom: 5px;
          ">
          {{ company }}请款单
        </div>
        <div style="
            display: flex;
            justify-content: center;
            font-size: 18px;
            margin-bottom: 5px;
          "></div>
        <div style="
            display: flex;
            justify-content: space-between;
            margin-bottom: 5px;
          " class="print_form">
          <div style="display: flex; flex-direction: column;">
            <!--            <div>请款单号：</div>-->
            <div>源业务编码：{{ form.fBillno }}</div>
            <div>委托单位：{{ form.fCorpid | fMblnoFormat(fMblnoOptions) }}</div>
          </div>
          <div style="display: flex; flex-direction: column;margin-right: 15px;width: 150px">
            <div style="">请款日期：</div>
          </div>
        </div>
        <div class="print_table" style="display: flex">
          <table border="0" cellspacing="0" cellpadding="0" style="width: 100%; line-height: 30px">
            <tr>
              <td>结算单位</td>
              <td>提单号</td>
              <!--              <td>源业务编码</td>-->
              <td>业务日期</td>
              <td>数量</td>
              <td>单价</td>
              <td>费用</td>
              <td>人民币</td>
              <td>美元</td>
            </tr>
            <tr v-for="(item, index) in PrintingCrlist" :key="index">
              <td>{{ item.fCorpid | fMblnoFormat(fMblnoOptions) }}</td>
              <td>{{ form.fMblno }}</td>
              <!--              <td>{{ form.fBillno }}</td>-->
              <td>{{ form.fBsdate | fBsdateFormat }}</td>
              <td>{{ item.fQty }}</td>
              <td>{{ item.fUnitprice }}</td>
              <td>{{ item.fFeeid | fFeetFormat(fCNameOptions) }}</td>
              <td>{{ item.fAmount }}</td>
              <td></td>
            </tr>
            <tr>
              <td>合计</td>
              <td></td>
              <td></td>
              <td>{{ allCrfQty }}</td>
              <td></td>
              <td></td>
              <td>{{ allCrfAmount }}</td>
              <td></td>
            </tr>
          </table>
        </div>
        <div style="display: flex; justify-content: space-between; font-size: 12px">
          <div>领款人：</div>
          <div>业务经理：</div>
          <div>财务：</div>
          <div style="width: 150px">经理：</div>
        </div>
      </div>
      <span lot="footer" class="dialog-footer">
        <el-button type="primary" size="mini" @click="
          print_Cr = false;
        addprint('crzyd');
        ">打印
        </el-button>
        <el-button @click="print_Cr = false" size="mini">取消 </el-button>
      </span>
    </el-dialog>

    <!--    费用确认单-->
    <el-dialog :visible.sync="print_fyqr" width="70%" :close-on-click-modal="false" :modal="false">
      <div id="print_fyqr" class="print-div">
        <div class="print-title" style="
            display: flex;
            justify-content: center;
            font-size: 28px;
            margin-bottom: 5px;
          ">
          <!--          {{ company }}-->
        </div>
        <div style="
            display: flex;
            justify-content: center;
            margin-bottom: 5px;
          ">
          <div style="font-size: 24px;letter-spacing: 3px;">请款单</div>
        </div>
        <div style="display: flex;justify-content: space-between;">
          <div>
            <div>业务编号：{{ form.fBillno }}</div>
            <div>客户名称：{{ form.fCorpidName }}</div>
            <div>提单号：{{ form.fMblno }}</div>
            <div>结算单位: {{ form.chargeUnit }}</div>
          </div>
          <div>
            <div>制单日期：{{ form.createTime | fBsdateFormat }}</div>
            <div>仓库名称：{{ form.fWarehouseid | warehouseFormat(warehouseOptions) }}</div>
            <div>箱型/箱量：{{ form.fCntval }}</div>
          </div>
          <div>
            <div>制单人：{{ form.createBy }}</div>
            <div>打印日期：{{ nowTime | fBsdateFormat }}</div>
            <div>品名：{{ form.fGoodsid | goodsFormat(goodsOptions) }}</div>
          </div>
        </div>
        <div class="print_table" style="display: flex">
          <table border="0" cellspacing="0" cellpadding="0" style="width: 100%; line-height: 30px">
            <tr>
              <td>序号</td>
              <td>费用项目</td>
              <td>计价单位</td>
              <td>数量</td>
              <td>单价</td>
              <td>是否含税</td>
              <td>税率</td>
              <td>不含税金额</td>
              <td>税额</td>
              <td>应付金额</td>
              <td>备注</td>
            </tr>
            <tr v-for="(item, index) in PrintingCrlist" :key="index">
              <td>{{ index + 1 }}</td>
              <td>{{ item.fFeeid | fFeetFormat(fCNameOptions) }}</td>
              <td>{{ item.fFeeUnitid | fFeetUnitFormat(fFeetUnitOptions) }}</td>
              <td>{{ item.fQty }}</td>
              <td>{{ item.fUnitprice }}</td>
              <td>{{ item.fTaxrate != 0 ? '√' : '×' }}</td>
              <td>{{ item.fTaxrate }}</td>
              <td>{{ item.taxAmount }}</td>
              <td>{{ item.exclTax }}</td>
              <td>{{ item.fAmount }}</td>
              <td>{{ item.remark }}</td>
            </tr>
            <tr>
              <td colspan="7">合计</td>
              <td>{{ allTaxAmount }}</td>
              <td>{{ allExclTax }}</td>
              <td>{{ allDrAmount }}</td>
              <td></td>
            </tr>
          </table>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="
          addprint('fyqrd');
        print_fyqr = false;
        ">打印
        </el-button>
        <el-button @click="print_fyqr = false">取消 </el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { operationAgreement } from "@/api/agreement/agreement";
import { feesCheck, revokefeeCheck } from "@/api/warehouseBusiness/warehouseInStock";
import Cookies from "js-cookie";
import { addSet, resetModule, select } from '@/api/system/set';
import draggable from "vuedraggable";
import print from "print-js";
import {
  listWarehouse,
  treeselect,
  listWarehousesss,
  deliveryDetails
} from "@/api/basicdata/warehouse";
import { getFees } from "@/api/basicdata/fees";

export default {
  name: 'payMoney',
  props: {
    browseStatus: {
      type: Boolean,
      default: false,
    },
    warehouseCrList: {
      type: Array,
      default: [],
    },
    businessTypeOption: {
      type: Array,
      default: [],
    },
    fMblnoOptions: {
      type: Array,
      default: [],
    },
    fCNameOptions: {
      type: Array,
      default: [],
    },
    fFeetUnitOptions: {
      type: Array,
      default: [],
    },
    fStltypeOptions: {
      type: Array,
      default: [],
    },
    fGrossweight: {
      type: Number,
      default: null,
    },
    fQty: {
      type: Number,
      default: null,
    },
    fNetweight: {
      type: Number,
      default: null,
    },
    fCntqty: {
      type: Number,
      default: null,
    },
    form: {
      type: Object,
      default: null,
    },
    goodsOptions: {
      type: Array,
      default: [],
    },
    CntrTable: {
      type: Array,
      default: [],
    },
    cntrList: {
      type: Array,
      default: [],
    },
    tableName: {
      type: String,
      default: '入库付费',
    },
  },
  components: {
    draggable
  },
  data() {
    return {
      warehousingagreements: false,
      dialogWhgenlegList: [],
      whgenlegTotal: 0,
      Navigation: false,
      tasklegList: [],
      // dialogWhgenlegList: [],
      pageNum: 1,
      pageSize: 10,
      warehouseOptions: [],
      // 收款信息明细
      PrintingCrlist: [],
      allCrfAmount: 0,
      allCrfQty: 0,
      // Cr打印弹窗是否开启
      print_Cr: false,
      company: '',
      nowTime: '',
      // 税额总数
      allTaxAmount: 0,
      // 不含税金额总数
      allExclTax: 0,
      // 收款金额合计
      allDrAmount: 0,
      print_fyqr: false,
      // 识别号
      Identifier: '',
      // 地址
      address: '',
      // 电话
      phone: '',
      // 开户行
      bank: '',
      // 银行账户
      bankAccount: '',
      // 是否启用请款单
      isShowInvoice: null,
      // 是否启用费用确认单
      isShowFeesConfirm: null,
      activeIndex: '1',

      // 设置列开关
      showSetting: false,
      setRowList: [],
      getRowList: [],
      //自定义列宽
      allCheck: false,
      drag: false,
      tableDate: [
        {
          surface: "1",
          label: "fCorpid",
          name: "客户名称",
          checked: 0,
          width: 300,
        },
        {
          surface: "2",
          label: "fFeeid",
          name: "费用名称",
          checked: 0,
          width: 240,
        },
        {
          surface: "3",
          label: "fFeeUnitid",
          name: "计价单位",
          checked: 0,
          width: 130,
        },
        {
          surface: "4",
          label: "fQty",
          name: "数量",
          checked: 0,
          width: 80,
        },
        {
          surface: "5",
          label: "fUnitprice",
          name: "单价",
          checked: 0,
          width: 80,
        },
        {
          surface: "6",
          label: "fAmount",
          name: "金额",
          checked: 0,
          width: 130,
        },
        {
          surface: "7",
          label: "fStltypeid",
          name: "结算方式",
          checked: 0,
          width: 100,
        },
        {
          surface: "8",
          label: "fCurrency",
          name: "币别",
          checked: 0,
          width: 100,
        },
        {
          surface: "9",
          label: "fExrate",
          name: "汇率",
          checked: 0,
          width: 80,
        },
        {
          surface: "10",
          label: "fTaxrate",
          name: "税率",
          checked: 0,
          width: 80,
        },
        {
          surface: "11",
          label: "fBusinessType",
          name: "作业类型",
          checked: 0,
          width: 180,
        },
        {
          surface: "12",
          label: "fMblno",
          name: "提单号",
          checked: 0,
          width: 150,
        },
        {
          surface: "13",
          label: "fProductName",
          name: "品名",
          checked: 0,
          width: 140,
        },
        {
          surface: "14",
          label: "fMarks",
          name: "品牌",
          checked: 0,
          width: 130,
        },
        {
          surface: "15",
          label: "fSrcTypeId",
          name: "来源",
          checked: 0,
          width: 130,
        },
        {
          surface: "16",
          label: "fAccamount",
          name: "对账金额",
          checked: 0,
          width: 130,
        },
        {
          surface: "17",
          label: "fStlamount",
          name: "结算金额",
          checked: 0,
          width: 130,
        },
        {
          surface: "18",
          label: "fStlamountDate",
          name: "结算日期",
          checked: 0,
          width: 130,
        },
        {
          surface: "19",
          label: "remark",
          name: "备注",
          checked: 0,
          width: 150,
        },
      ],
      handleKey:0,
    };
  },
  created() {
    this.setRowList = this.tableDate;
    this.getRowList = this.tableDate;
    this.company = Cookies.get("companyName")
    this.getConfigKey("taxpayer.identification.number").then((response) => {
      this.Identifier = response.msg;
    });
    this.getConfigKey("print.address").then((response) => {
      this.address = response.msg;
    });
    this.getConfigKey("print.phone").then((response) => {
      this.phone = response.msg;
    });
    this.getConfigKey("print.bank").then((response) => {
      this.bank = response.msg;
    });
    this.getConfigKey("print.bank.account").then((response) => {
      this.bankAccount = response.msg;
    });
    this.getConfigKey("warehouse.show.invoice").then((response) => {
      this.isShowInvoice = response.msg;
    });
    this.getConfigKey("warehouse.show.feesConfirm").then((response) => {
      this.isShowFeesConfirm = response.msg;
    });
    listWarehousesss({ fStatus: 0, delFlag: 0 }).then((response) => {
      this.warehouseOptions = response.rows;
    });
    this.getRow();
  },
  filters: {
    fMblnoFormat(row, fMblnoOptions) {
      let name;
      fMblnoOptions.map((e) => {
        if (row == e.fId) {
          name = e.fName;
        }
      });
      return name;
    },
    fBsdateFormat(row) {
      if (row) {
        const dateMat = new Date(row);
        const year = dateMat.getFullYear();
        const month = dateMat.getMonth() + 1;
        const day = dateMat.getDate();
        const timeFormat = year + "-" + month + "-" + day;
        return timeFormat;
      }
    },
    fFeetFormat(row, fCNameOptions) {
      let name;
      fCNameOptions.map((e) => {
        if (row == e.fId) {
          name = e.fName;
        }
      });
      return name;
    },
    warehouseFormat(row, warehouseOptions) {
      let warehouse;
      warehouseOptions.map((e) => {
        if (row == e.fId) {
          warehouse = e.fName;
        }
      });
      return warehouse;
    },
    goodsFormat(row, goodsOptions) {
      let goods;
      goodsOptions.map((e) => {
        if (row == e.fId) {
          goods = e.fName;
        }
      });
      return goods;
    },
    fFeetUnitFormat(row, fFeetUnitOptions) {
      let name;
      fFeetUnitOptions.map((e) => {
        if (row == e.dictValue) {
          name = e.dictLabel;
        }
      });
      return name;
    },
  },
  methods: {
    feeChange() {
      this.$emit("feeChangeC", 'C');
    },
    saveForm() {
      this.$emit("chiSave");
    },
    addpayment() {
      this.$emit("chiAdd");
    },
    // 付款合计
    warehouseDrSummaries(param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = "合计";
          return;
        }
        const values = data.map((item) => Number(item[column.property]));
        if (
          column.property === "fAmount"
          // column.property === "fUnitprice" ||
          // column.property === "fAmount" ||
          // column.property === "fQty"
        ) {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr);
            if (!isNaN(value)) {
              return prev + curr;
            } else {
              return prev;
            }
          }, 0);
          sums[index] = sums[index].toFixed(2);
        }
      });
      return sums;
    },
    deleteRow(index, rows) {
      rows.splice(index, 1);
    },
    // 变更计价单位
    changeFeeUnit(row) {
      if (!row.fFeeUnitid) {
        return false;
      }
      if (row.fFeeUnitid === "2") {
        this.$set(row, "fQty", (this.fGrossweight / 1000).toFixed(3));
      } else if (row.fFeeUnitid === "1") {
        this.$set(row, "fQty", this.fQty.toFixed(2));
      } else if (row.fFeeUnitid === "3") {
        this.$set(row, "fQty", (this.fNetweight / 1000).toFixed(3));
      } else if (row.fFeeUnitid === "7") {
        this.$set(row, "fQty", this.fCntqty);
      } else if (row.fFeeUnitid === "8") {
        this.$set(row, "fQty", 1);
      } else {
        this.$set(row, "fQty", 0);
      }
      if (row.fUnitprice) {
        this.$set(
          row,
          "fAmount",
          parseFloat(Number(row.fUnitprice) * Number(row.fQty)).toFixed(2)
        );
      }
    },
    // 数量计算
    changeContractAmt(row) {
      let fQty = 0;
      let fUnitprice = 0;
      if (row.fUnitprice) {
        fUnitprice = row.fUnitprice;
      }
      if (row.fQty) {
        fQty = row.fQty;
      }
      this.$set(row, "fAmount", Number(fUnitprice) * Number(fQty)).toFixed(2);
    },
    handleSelect(key) {
      if (!this.form.fCorpid) {
        this.$message({
          message: "请维护客户",
          type: "warning",
        });
      } else if (this.form.fProductName == undefined) {
        this.$message({
          message: "请维护入库明细品名",
          type: "warning",
        });
      } else {
        this.pageNum = 1;
        this.pageSize = 10;
        this.dialogWhgenlegList = [];
        this.whgenlegTotal = 0;
        this.warehousingagreements = true;
        this.handleKey = key
        this.getWhgenlegList();
      }
    },
    // 查询作业费信息
    getWhgenlegList() {
      let data = {};
      this.Navigation = true;
        data = {
          pageNum: this.pageNum,
          pageSize: this.pageSize,
          fTaskType:this.handleKey,
          fFleet: this.form.fFleet,
        };
      operationAgreement(data).then((response) => {
        response.rows.map((e) => {
          if (e.fFeeUnitid) {
            e.fFeeUnitid = e.fFeeUnitid.toString();
          }
        });
        this.tasklegList = response.rows;
        this.whgenlegTotal = response.total;
      });
    },
    // 库存总账多选框
    whgenlegSelectionChange(selection) {
      this.dialogWhgenlegList = selection;
    },
    //导入收付款信息明细
    zhgenlegData() {
      if (this.dialogWhgenlegList.length === 0) {
        this.$message({
          message: "请选择需要导入的数据",
          type: "warning",
        });
      } else {
        this.dialogWhgenlegList.map((e) => {
          let qty = 1;
          if (e.fFeeUnitid == 1) {
            qty = this.fQty;
          } else if (e.fFeeUnitid == 2) {
            qty = (this.fGrossweight / 1000).toFixed(2);
          } else if (e.fFeeUnitid == 3) {
            qty = (this.fNetweight / 1000).toFixed(2);
          } else if (e.fFeeUnitid == 7) {
            qty = this.fCntqty;
          }
          let fAmount = 0;
          fAmount = e.fPrice * qty;
          this.warehouseCrList.push({
            fQty: qty,
            fCorpid: e.fCorpid,
            fFeeid: e.feeFId,
            fFeeUnitid: e.fFeeUnitid,
            fUnitprice: e.fPrice,
            fCurrency: "RMB",
            fExrate: 1,
            fAmount: fAmount,
            fTaxrate: '0',
            fMblno: this.form.fMblno,
            fProductName: this.form.fProductName,
            fMarks: this.form.fMarks,
            fBusinessType: this.form.fBusinessType,
            fSrcTypeId: 1,
            fStltypeid: '1',
          });
        });
        this.Navigation = false;
        this.warehousingagreements = false;
      }
    },
    // 费用明细请核
    listCheck(row) {
      this.$confirm("是否发起费用明细请核?", "提示", {
        confirmButtonText: "确认",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        feesCheck(row.fId).then(res => {
          this.$message.success('请核成功')
          res.data.fFeeUnitid = res.data.fFeeunitid.toString();
          res.data.fStltypeid = res.data.fStltypeid.toString();
          if (res.data.fDc == 'D') {
            let index = this.warehouseDrList.findIndex(item => item.fId == res.data.fId)
            this.warehouseDrList.splice(index, 1, res.data)
          } else {
            let index = this.warehouseCrList.findIndex(item => item.fId == res.data.fId)
            this.warehouseCrList.splice(index, 1, res.data)
          }
        })
      });
    },
    // 费用明细撤销请核
    revokeListCheck(row) {
      this.$confirm("是否撤销请核?", "提示", {
        confirmButtonText: "确认",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        revokefeeCheck(row.fId).then(res => {
          this.$message.success('操作成功')
          res.data.fFeeUnitid = res.data.fFeeunitid.toString();
          res.data.fStltypeid = res.data.fStltypeid.toString();
          if (res.data.fDc == 'D') {
            let index = this.warehouseDrList.findIndex(item => item.fId == res.data.fId)
            this.warehouseDrList.splice(index, 1, res.data)
          } else {
            let index = this.warehouseCrList.findIndex(item => item.fId == res.data.fId)
            this.warehouseCrList.splice(index, 1, res.data)
          }
        })
      });
    },
    // 付款明细多选
    SelectCr(selection) {
      this.PrintingCrlist = selection;
    },
    // 付款信息打印准备
    printCr() {
      if (this.PrintingCrlist.length > 0) {
        for (let item in this.PrintingCrlist) {
          if (!this.PrintingCrlist[item].fId) {
            return this.$message.error("请先保存!");
          }
        }
        this.allCrfAmount = 0;
        this.allCrfQty = 0;
        this.PrintingCrlist.forEach(item => {
          this.allCrfAmount = this.allCrfAmount + item.fAmount
          this.allCrfQty += item.fQty
        })
        this.print_Cr = true;
      } else {
        this.$message.error("请选择需要打印的明细!");
      }
    },
    // 打印
    addprint(status) {
      const style =
        "@page {  } " +
        "@media print { .print-div{ padding:8px;background-color:#cccccc;} .print-title{display:flex;justify-content: center;font-size:24px} .print_form{font-size:12px} .print_table table {border-right: 1px solid #000;border-bottom: 1px solid #000;font-size:12px} .print_table table td {border-left: 1px solid #000;border-top: 1px solid #000;padding:2px;vertical-align:middle;text-align: center;}";
      switch (status) {
        case "crzyd":
          print({
            printable: "print_Cr",
            type: "html",
            style: style, // 亦可使用引入的外部css;
            scanStyles: false,
          });
          break;
        case "fyqrd":
          print({
            printable: "print_fyqr",
            type: "html",
            style: style, // 亦可使用引入的外部css;
            scanStyles: false,
          });
          break;
      }
    },
    // 打印费用确认单准备
    feesConfirm() {
      if (this.PrintingCrlist.length > 0) {
        for (let item in this.PrintingCrlist) {
          if (!this.PrintingCrlist[item].fId) {
            return this.$message.error("请先保存!");
          }
        }
        if (this.CntrTable.length > 0) {
          let arr = [];
          this.CntrTable.map((e) => {
            this.cntrList.map((item) => {
              if (item.fId == e.fCntrid) {
                arr.push(item.fName + "X" + e.fCntrcount);
              }
            });
          });
          arr = [...new Set(arr)];
          this.form.fCntval = arr.join(",");
        } else {
          this.form.fCntval = null;
        }
        this.allTaxAmount = 0;
        this.allExclTax = 0;
        this.allDrAmount = 0;
        this.PrintingCrlist.forEach(item => {
          // 税额
          this.$set(item, 'taxAmount', Number(item.fAmount) / (1 + Number(Number(item.fTaxrate) / 100)))
          item.taxAmount = item.taxAmount.toSuperFixed(2)
          // 不含税金额
          this.$set(item, 'exclTax', Number(item.fAmount) - Number(item.taxAmount))
          item.exclTax = item.exclTax.toSuperFixed(2)
          this.allTaxAmount = Number(this.allTaxAmount) + Number(item.taxAmount)
          this.allExclTax = Number(this.allExclTax) + Number(item.exclTax)
          this.allDrAmount = Number(this.allDrAmount) + Number(item.fAmount)
          this.allTaxAmount = this.allTaxAmount.toSuperFixed(2)
          this.allExclTax = this.allExclTax.toSuperFixed(2)
          this.allDrAmount = this.allDrAmount.toSuperFixed(2)
        })
        this.nowTime = new Date().toLocaleDateString()
        for (let corp in this.fMblnoOptions) {
          if (this.form.fCorpid === this.fMblnoOptions[corp].fId) {
            this.$set(
              this.form,
              "fCorpidName",
              this.fMblnoOptions[corp].fName
            );
          }
          if (this.PrintingCrlist[0].fCorpid === this.fMblnoOptions[corp].fId) {
            this.$set(
              this.form,
              "chargeUnit",
              this.fMblnoOptions[corp].fName
            );
          }
        }
        this.print_fyqr = true;
      } else {
        this.$message.error("请选择需要打印的明细!");
      }
    },
    feeChoice(row) {
      getFees(row.fFeeid).then(res => {
        row.fFeeUnitid = (res.data.fFeeunitid).toString()
        this.changeFeeUnit(row)
      })
    },

    //列设置全选
    allChecked() {
      if (this.allCheck == true) {
        this.setRowList.map((e) => {
          return (e.checked = 0);
        });
      } else {
        this.setRowList.map((e) => {
          return (e.checked = 1);
        });
      }
    },
    //开始拖拽事件
    onStart() {
      this.drag = true;
    },
    //拖拽结束事件
    onEnd() {
      this.drag = false;
    },
    //重置列表
    delRow() {
      this.data = {
        tableName: this.tableName,
        userId: Cookies.get("userName"),
      };
      resetModule(this.data).then((res) => {
        if (res.code == 200) {
          this.showSetting = false;
          this.setRowList = this.tableDate;
          console.log(this.setRowList)
          this.getRowList = this.tableDate;
        }
      });
    },
    //保存列设置
    save() {
      this.showSetting = false;
      this.data = {
        tableName: this.tableName,
        userId: Cookies.get("userName"),
        sysTableSetList: this.setRowList,
      };
      addSet(this.data).then((res) => {
        this.getRowList = this.setRowList.filter((e) => e.checked == 0);
      });
    },
    //查询列数据
    getRow() {
      let that = this;
      this.data = {
        tableName: this.tableName,
        userId: Cookies.get("userName"),
      };
      select(this.data).then((res) => {
        if (res.data.length != 0) {
          this.getRowList = res.data.filter((e) => e.checked == 0);
          this.setRowList = res.data;
          this.setRowList = this.setRowList.reduce((res, item) => {
            res.push({
              surface: item.surface,
              label: item.label,
              name: item.name,
              checked: item.checked,
              width: item.width,
              fixed: item.fixed,
            });
            return res;
          }, []);
        }
      });
    },
  },
  watch: {
    browseStatus(val) {
      this.browseStatus = val;
    },
    warehouseCrList(val) {
      this.warehouseCrList = val;
    },
  },
};
</script>

<style scoped lang="scss">
.print_table {
  table {
    border-right: 1px solid #000;
    border-bottom: 1px solid #000;
    font-size: 12px;
    margin-bottom: 5px;
  }

  table td {
    border-left: 1px solid #000;
    border-top: 1px solid #000;
    vertical-align: middle;
    padding: 2px;
    text-align: center;
  }
}

.print_form {
  font-size: 12px;
}
</style>
