<template>
  <el-dialog
    :title="title"
    :visible.sync="showDialog"
    width="80%"
    @close="handleClose"
    :close-on-click-modal="false"
  >
    <span>
      <el-form ref="form" :model="form" :rules="rules" label-width="110px">
        <el-row>
          <el-col :span="6">
            <el-form-item label="客户名称" prop="corpId">
              <el-select
                v-model="form.corpId"
                placeholder="请输入客户名称"
                :clearable="true"
                filterable
                disabled
                size="mini"
                style="width: 100%"
              >
                <el-option
                  v-for="(dict, index) in fMblnoOptions"
                  :key="index.fId"
                  :label="dict.fName"
                  :value="dict.fId"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="业务类型" prop="billType">
              <el-select
                v-model="form.billType"
                placeholder="请选择业务类型"
                disabled
                size="mini"
                style="width: 100%"
              >
                <el-option
                  v-for="(dict, index) in billTypeList"
                  :key="index.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="运输方式" prop="transType">
              <el-select
                v-model="form.transType"
                placeholder="请选择运输方式"
                disabled
                size="mini"
                style="width: 100%"
              >
                <el-option
                  v-for="(dict, index) in transTypeList"
                  :key="index.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="提单号" prop="mblno">
              <el-input
                v-model="form.mblno"
                placeholder="请输入提单号"
                disabled
                size="mini"
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item
              v-if="form.transType != 3"
              label="提箱地点"
              prop="loadAddr"
            >
              <el-input
                v-model="form.loadAddr"
                placeholder="请输入提箱地点"
                disabled
                size="mini"
                style="width: 100%"
              />
            </el-form-item>
            <el-form-item v-else label="装货地点" prop="loadAddr">
              <el-input
                v-model="form.loadAddr"
                placeholder="请输入装货地点"
                disabled
                size="mini"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item
              v-if="form.billType == 1 && form.transType != 3"
              label="卸货地点"
              prop="mdLoadAddr"
            >
              <el-input
                v-model="form.mdLoadAddr"
                placeholder="请输入装卸货地点"
                disabled
                size="mini"
                style="width: 100%"
              />
            </el-form-item>
            <el-form-item
              v-if="form.billType == 2 && form.transType != 3"
              label="装货地点"
              prop="mdLoadAddr"
            >
              <el-input
                v-model="form.mdLoadAddr"
                placeholder="请输入装货地点"
                disabled
                size="mini"
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
          <el-col v-if="form.transType != 3" :span="6">
            <el-form-item label="卸箱地点" prop="unLoadAddr">
              <el-input
                v-model="form.unLoadAddr"
                placeholder="请输入卸箱地点"
                disabled
                size="mini"
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
          <el-col v-else :span="6">
            <el-form-item label="卸货地点" prop="unLoadAddr">
              <el-input
                v-model="form.unLoadAddr"
                placeholder="请输入卸箱地点"
                disabled
                size="mini"
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="装车时间" prop="loadDate">
              <el-date-picker
                clearable
                size="mini"
                style="width: 100%"
                v-model="form.loadDate"
                type="datetime"
                placeholder="请选择装车时间"
                disabled
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="6" v-if="form.billType == 1 || form.billType == 2">
            <el-form-item label="装货联系人" prop="mdLoadAttn">
              <el-input
                v-model="form.mdLoadAttn"
                placeholder="请输入装卸货联系人"
                disabled
                size="mini"
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6" v-if="form.billType == 1 || form.billType == 2">
            <el-form-item label="装货联系电话" prop="mdLoadAttnTel">
              <el-input
                v-model="form.mdLoadAttnTel"
                placeholder="请输入装卸货联系电话"
                disabled
                v-input-limit="0"
                size="mini"
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-show="detailsHidden">
          <el-col :span="6">
            <el-form-item label="运输性质" prop="transProp">
              <el-select
                v-model="form.transProp"
                placeholder="请选择运输方式"
                disabled
                size="mini"
                style="width: 100%"
              >
                <el-option
                  v-for="(dict, index) in transPropList"
                  :key="index.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="货品名称" prop="goodsId">
              <el-select
                v-model="form.goodsId"
                placeholder="请输入货品名称"
                disabled
                clearable
                filterable
                size="mini"
                style="width: 100%"
              >
                <el-option
                  v-for="(dict, index) in goodsOptions"
                  :key="index.fId"
                  :label="dict.fName"
                  :value="dict.fId"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="计划件数" prop="qtyPlan">
              <el-input
                v-model="form.qtyPlan"
                placeholder="请输入计划件数"
                disabled
                v-input-limit="2"
                size="mini"
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="重量(吨)" prop="weightPlan">
              <el-input
                v-model="form.weightPlan"
                placeholder="请输入计划重量"
                disabled
                v-input-limit="2"
                size="mini"
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="船名" prop="ysl">
              <el-input
                v-model="form.ysl"
                placeholder="请输入船名"
                disabled
                size="mini"
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="航次" prop="voy">
              <el-input
                v-model="form.voy"
                placeholder="请输入航次"
                disabled
                size="mini"
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="起运港" prop="polId">
              <el-select
                v-model="form.polId"
                placeholder="请输入起运港"
                :clearable="true"
                filterable
                disabled
                size="mini"
                style="width: 100%"
              >
                <el-option
                  v-for="(dict, index) in polList"
                  :key="index.fId"
                  :label="dict.fName"
                  :value="dict.fId"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="目的港" prop="podId">
              <el-select
                v-model="form.podId"
                placeholder="请输入目的港"
                :clearable="true"
                filterable
                disabled
                size="mini"
                style="width: 100%"
              >
                <el-option
                  v-for="(dict, index) in podList"
                  :key="index.fId"
                  :label="dict.fName"
                  :value="dict.fId"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="装车联系人" prop="loadAttn">
              <el-input
                v-model="form.loadAttn"
                placeholder="请输入装车联系人"
                disabled
                size="mini"
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="装车联系电话" prop="loadAttntel">
              <el-input
                v-model="form.loadAttntel"
                placeholder="请输入装车联系电话"
                disabled
                v-input-limit="0"
                size="mini"
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
          <el-col
            :span="6"
            v-if="
              (form.billType == 1 || form.billType == 2) && form.transType != 3
            "
          >
            <el-form-item label="装卸时间" prop="mdLoadDate">
              <el-date-picker
                clearable
                size="mini"
                style="width: 100%"
                v-model="form.mdLoadDate"
                type="datetime"
                placeholder="选择计划装卸货时间"
                disabled
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="卸车时间" prop="unLoadDate">
              <el-date-picker
                clearable
                size="mini"
                style="width: 100%"
                v-model="form.unLoadDate"
                type="datetime"
                placeholder="选择计划卸车时间"
                disabled
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="卸车联系人" prop="unLoadAttn">
              <el-input
                v-model="form.unLoadAttn"
                placeholder="请输入卸车联系人"
                disabled
                size="mini"
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="联系电话" prop="unLoadAttnTel">
              <el-input
                v-model="form.unLoadAttnTel"
                placeholder="请输入卸车联系电话"
                disabled
                v-input-limit="0"
                size="mini"
                style="width:100%"
              />
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item label="线路描述" prop="routeDesc">
              <el-input
                type="textarea"
                :rows="2"
                v-model="form.routeDesc"
                placeholder="请输入线路描述"
                disabled
                size="mini"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col>
            <el-form-item label="备注" prop="remarks">
              <el-input
                type="textarea"
                :rows="2"
                v-model="form.remarks"
                placeholder="请输入备注"
                disabled
                size="mini"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <div
          style="display: flex; justify-content: flex-end; margin-bottom: 10px"
        >
          <el-button
            @click="
              detailsHidden ? (detailsHidden = false) : (detailsHidden = true)
            "
            >{{ detailsHidden ? "隐藏" : "更多" }}
          </el-button>
        </div>
        <el-collapse v-model="collapses2">
          <el-collapse-item v-if="userType == '00'" name="1">
            <template slot="title">
              <i class="header-icon el-icon-circle-plus" style="font-size: 16px"
                ><span
                  style="font-size: 16px; font-weight: bolder; margin-left: 5px"
                  >调度安排</span
                >
              </i>
            </template>
            <div>
              <div
                style="
                  display: flex;
                  justify-content: space-between;
                  margin: 10px 0;
                "
              >
                <div>
                  <el-button
                    type="primary"
                    icon="el-icon-plus"
                    size="mini"
                    @click="addschedulingRow(schedulingList)"
                    disabled
                    >添加</el-button
                  >
                </div>
              </div>
              <el-table :data="schedulingList">
                <el-table-column label="箱型" align="center" prop="cntrId">
                  <template slot-scope="scope">
                    <el-select
                      v-model="scope.row.cntrId"
                      placeholder="请选择箱型"
                      disabled
                    >
                      <el-option
                        v-for="(dict, index) in cntrIdList"
                        :key="index.dictValue"
                        :label="dict.dictLabel"
                        :value="dict.dictValue"
                        :disabled="dict.noOption"
                      />
                    </el-select>
                  </template>
                </el-table-column>

                <el-table-column
                  label="车队名称"
                  align="center"
                  prop="carcorPid"
                >
                  <template slot-scope="scope">
                    <el-select
                      v-model="scope.row.carcorPid"
                      placeholder="请输入车队名称"
                      :clearable="true"
                      filterable
                      disabled
                    >
                      <el-option
                        v-for="(dict, index) in companyList"
                        :key="index.fId"
                        :label="dict.fName"
                        :value="dict.fId"
                      />
                    </el-select>
                  </template>
                </el-table-column>

                <el-table-column
                  label="调度安排货量"
                  align="center"
                  prop="cntrQty"
                  disabled
                >
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.cntrQty"
                      placeholder="调度安排货量"
                      v-input-limit="2"
                      disabled
                    />
                  </template>
                </el-table-column>
                <el-table-column
                  label="已派车货量"
                  align="center"
                  prop="carQty"
                >
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.carQty"
                      placeholder="已派车货量"
                      :disabled="true"
                    />
                  </template>
                </el-table-column>
                <el-table-column
                  label="应付运价"
                  align="center"
                  prop="freightPriceCr"
                >
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.freightPriceCr"
                      placeholder="应付运价"
                      disabled
                    />
                  </template>
                </el-table-column>
                <el-table-column
                  label="运输性质"
                  align="center"
                  prop="freightPriceCr"
                >
                  <template slot-scope="scope">
                    <el-select
                      v-model="scope.row.transProp"
                      placeholder="请选择运输性质"
                      disabled
                      size="mini"
                    >
                      <el-option
                        v-for="(dict, index) in transPropList"
                        :key="index.dictValue"
                        :label="dict.dictLabel"
                        :value="dict.dictValue"
                      />
                    </el-select>
                  </template>
                </el-table-column>
                <el-table-column label="备注" align="center" prop="remarks">
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.remarks"
                      placeholder="备注"
                      disabled
                    />
                  </template>
                </el-table-column>
              </el-table>
            </div>
          </el-collapse-item>
          <el-collapse-item name="2">
            <template slot="title">
              <i class="header-icon el-icon-circle-plus" style="font-size: 16px"
                ><span
                  style="font-size: 16px; font-weight: bolder; margin-left: 5px"
                  >车辆安排</span
                >
              </i>
            </template>
            <div>
              <div
                style="
                  display: flex;
                  justify-content: space-between;
                  margin: 10px 0;
                "
              >
                <div>
                  <el-button
                    type="primary"
                    icon="el-icon-plus"
                    size="mini"
                    @click="addRow2(vehicleList)"
                    :disabled="disabled"
                    v-hasPermi="['fleet:ftmsorderbillscars:edit']"
                    >添加</el-button
                  >
                </div>
              </div>
              <el-table :data="vehicleList">
                <el-table-column
                  label="箱型"
                  align="center"
                  prop="cntrId"
                  width="120"
                >
                  <template slot-scope="scope">
                    <el-select
                      v-model="scope.row.cntrId"
                      placeholder="请选择箱型"
                      disabled
                      @change="checkPid(scope.row)"
                    >
                      <el-option
                        v-for="(dict, index) in cntrIdList"
                        :key="index.dictValue"
                        :label="dict.dictLabel"
                        :value="dict.dictValue"
                      />
                    </el-select>
                  </template>
                </el-table-column>

                <el-table-column
                  label="货量"
                  align="center"
                  prop="cntrQty"
                  width="100"
                >
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.cntrQty"
                      v-input-limit="0"
                      placeholder="货量"
                      :disabled="
                        scope.row.billStatus >= 6 || scope.row.billStatus == 3
                      "
                    />
                  </template>
                </el-table-column>

                <el-table-column
                  label="箱号"
                  align="center"
                  prop="cntrNo"
                  width="145"
                >
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.cntrNo"
                      placeholder="箱号"
                      :disabled="
                        scope.row.billStatus >= 6 || scope.row.billStatus == 3
                      "
                    />
                  </template>
                </el-table-column>
                <el-table-column
                  label="车号"
                  align="center"
                  prop="carregNo"
                  width="130"
                >
                  <template slot-scope="scope">
                    <el-select
                      v-model="scope.row.carregNo"
                      placeholder="车号"
                      :disabled="
                        scope.row.billStatus >= 6 || scope.row.billStatus == 3
                      "
                      :clearable="true"
                      filterable
                      @change="carChange(scope.row)"
                    >
                      <el-option
                        v-for="(dict, index) in carManages"
                        :key="index"
                        :label="dict.carNum"
                        :value="dict.carNum"
                      />
                    </el-select>
                  </template>
                </el-table-column>
                <el-table-column
                  label="司机姓名"
                  align="center"
                  prop="driverName"
                  width="100"
                >
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.driverName"
                      placeholder="司机姓名"
                      :disabled="
                        scope.row.billStatus >= 6 || scope.row.billStatus == 3
                      "
                    />
                  </template>
                </el-table-column>
                <el-table-column
                  label="联系电话"
                  align="center"
                  prop="driverTel"
                  width="145"
                >
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.driverTel"
                      placeholder="联系电话"
                      v-input-limit="2"
                      :disabled="
                        scope.row.billStatus >= 6 || scope.row.billStatus == 3
                      "
                    />
                  </template>
                </el-table-column>
                <el-table-column
                  label="应付运价"
                  align="center"
                  prop="freightPriceCr"
                >
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.freightPriceCr"
                      placeholder="应付运价"
                      disabled
                    />
                  </template>
                </el-table-column>
                <el-table-column
                  label="运单号"
                  align="center"
                  prop="orderNo"
                  width="100"
                />
                <el-table-column
                  label="单据类型"
                  align="center"
                  prop="billKind"
                  width="100"
                >
                  <template slot-scope="scope">
                    <span v-if="scope.row.billKind === 'NN'">直单</span>
                    <span v-if="scope.row.billKind === 'MM'">主单</span>
                    <span v-if="scope.row.billKind === 'MH'">从单</span>
                  </template>
                </el-table-column>
                <el-table-column
                  label="主单号"
                  align="center"
                  prop="mBillNo"
                  width="100"
                />
                <el-table-column label="备注" align="center" prop="remarks">
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.remarks"
                      placeholder="备注"
                      :disabled="
                        scope.row.billStatus >= 6 || scope.row.billStatus == 3
                      "
                    />
                  </template>
                </el-table-column>
                <el-table-column
                  label="跟踪状态"
                  align="center"
                  class-name="small-padding fixed-width"
                  width="100"
                  prop="orderStatus"
                >
                  <template slot-scope="scope">
                    <div v-if="scope.row.billStatus == 2">已暂存</div>
                    <div v-if="scope.row.billStatus == 3">已撤销</div>
                    <div v-if="scope.row.billStatus >= 6">已提交</div>
                  </template>
                </el-table-column>
                <el-table-column
                  label="操作"
                  align="center"
                  class-name="small-padding fixed-width"
                  width="240"
                  fixed="right"
                >
                  <template slot-scope="scope">
                    <el-button
                      size="mini"
                      type="text"
                      icon="el-icon-delete"
                      @click.native.prevent="
                        delscarsRow(scope.$index, vehicleList, scope.row)
                      "
                      :disabled="
                        scope.row.billStatus == 6 || scope.row.billStatus == 5
                      "
                      v-hasPermi="['fleet:ftmsorderbillscars:edit']"
                      >删除</el-button
                    >
                    <el-button
                      size="mini"
                      type="text"
                      icon="el-icon-document-checked"
                      @click.native.prevent="addscarsRow(scope.row)"
                      :disabled="
                        scope.row.billStatus >= 6 || scope.row.billStatus == 3
                      "
                      v-hasPermi="['fleet:ftmsorderbillscars:edit']"
                      >提交</el-button
                    >
                    <el-button
                      size="mini"
                      type="text"
                      icon="el-icon-document-delete"
                      @click.native.prevent="
                        revokescarsRow(scope.$index, vehicleList, scope.row)
                      "
                      :disabled="
                        scope.row.billStatus < 6 || !scope.row.billStatus
                      "
                      v-hasPermi="['fleet:ftmsorderbillscars:edit']"
                      >撤销</el-button
                    >
                    <el-button
                      size="mini"
                      type="text"
                      icon="el-icon-document-delete"
                      @click.native.prevent="changescarsRow(scope.row)"
                      :disabled="
                        scope.row.billStatus < 6 || !scope.row.billStatus
                      "
                      v-hasPermi="['fleet:ftmsorderbillscars:edit']"
                      >变更</el-button
                    >
                    <el-button
                      size="mini"
                      type="text"
                      icon="el-icon-document-checked"
                      @click.native.prevent="selectStowage(scope.row)"
                      v-if="
                        schedulingList[0].transProp == '1' &&
                        scope.row.billStatus >= 6
                      "
                      :disabled="scope.row.billKind != 'NN'"
                      v-hasPermi="['fleet:ftmsorderbillscars:edit']"
                      >配载</el-button
                    >
                    <el-button
                      size="mini"
                      type="text"
                      icon="el-icon-document-delete"
                      @click.native.prevent="changeStowageRow(scope.row)"
                      v-if="
                        schedulingList[0].transProp == '1' &&
                        scope.row.billStatus >= 6
                      "
                      :disabled="!scope.row.mBillNo"
                      v-hasPermi="['fleet:ftmsorderbillscars:edit']"
                      >撤销配载</el-button
                    >
                  </template>
                </el-table-column>
              </el-table>
            </div>
          </el-collapse-item>
          <el-collapse-item
            v-hasPermi="['fleet:ftmsorderbillscars:edit']"
            name="3"
          >
            <template slot="title">
              <i class="header-icon el-icon-circle-plus" style="font-size: 16px"
                ><span
                  style="font-size: 16px; font-weight: bolder; margin-left: 5px"
                  >收款信息</span
                >
              </i>
            </template>
            <div>
              <div
                style="
                  display: flex;
                  justify-content: space-between;
                  margin: 10px 0;
                "
              >
                <div>
                  <el-button
                    type="primary"
                    icon="el-icon-plus"
                    size="mini"
                    @click="addDListRow(DList)"
                    :disabled="disabled"
                    >添加</el-button
                  >
                </div>
              </div>
              <el-table :data="DList">
                <el-table-column label="结算单位" align="center" prop="fCorpid">
                  <template slot-scope="scope">
                    <el-select
                      v-model="scope.row.fCorpid"
                      placeholder="结算单位"
                      :clearable="true"
                      filterable
                      :disabled="disabled"
                    >
                      <el-option
                        v-for="(dict, index) in fMblnoOptions"
                        :key="index.fId"
                        :label="dict.fName"
                        :value="dict.fId"
                      />
                    </el-select>
                  </template>
                </el-table-column>

                <el-table-column label="费用名称" align="center" prop="fFeeid">
                  <template slot-scope="scope">
                    <el-select
                      v-model="scope.row.fFeeid"
                      placeholder="费用名称"
                      clearable
                      filterable
                      :disabled="disabled"
                    >
                      <el-option
                        v-for="(dict, index) in fWbuOptions"
                        :key="index.fId"
                        :label="dict.fName"
                        :value="dict.fId"
                      />
                    </el-select>
                  </template>
                </el-table-column>
                <el-table-column
                  label="计费单位"
                  align="center"
                  prop="fFeeunitid"
                >
                  <template slot-scope="scope">
                    <el-select
                      v-model="scope.row.fFeeunitid"
                      placeholder="计费单位"
                      :disabled="disabled"
                    >
                      <el-option
                        v-for="(dict, index) in ffeeunitidList"
                        :key="index.dictValue"
                        :label="dict.dictLabel"
                        :value="dict.dictValue"
                      />
                    </el-select>
                  </template>
                </el-table-column>
                <el-table-column label="计费数量" align="center" prop="fQty">
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.fQty"
                      placeholder="计费数量"
                      v-input-limit="0"
                      :disabled="disabled"
                      @input="total(scope.row)"
                    />
                  </template>
                </el-table-column>
                <el-table-column label="单价" align="center" prop="fUnitprice">
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.fUnitprice"
                      placeholder="单价"
                      v-input-limit="2"
                      :disabled="disabled"
                      @input="total(scope.row)"
                    />
                  </template>
                </el-table-column>
                <el-table-column label="币种" align="center" prop="fCurrency">
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.fCurrency"
                      placeholder="RMB"
                      :disabled="true"
                    />
                  </template>
                </el-table-column>
                <el-table-column label="汇率" align="center" prop="fExrate">
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.fExrate"
                      placeholder="汇率"
                      v-input-limit="2"
                      :disabled="disabled"
                    />
                  </template>
                </el-table-column>
                <el-table-column label="金额" align="center" prop="fAmount">
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.fAmount"
                      placeholder="金额"
                      v-input-limit="2"
                      :disabled="true"
                    />
                  </template>
                </el-table-column>
                <el-table-column label="税率" align="center" prop="fTaxrate">
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.fTaxrate"
                      placeholder="税率"
                      v-input-limit="2"
                      :disabled="disabled"
                    />
                  </template>
                </el-table-column>

                <el-table-column label="备注" align="center" prop="remarks">
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.remarks"
                      placeholder="备注"
                      :disabled="disabled"
                    />
                  </template>
                </el-table-column>

                <el-table-column
                  label="操作"
                  align="center"
                  class-name="small-padding fixed-width"
                  width="100"
                >
                  <template slot-scope="scope">
                    <el-button
                      size="mini"
                      type="text"
                      icon="el-icon-delete"
                      @click.native.prevent="deleteRow(scope.$index, DList)"
                      :disabled="disabled"
                      >删除</el-button
                    >
                  </template>
                </el-table-column>
              </el-table>
            </div>
          </el-collapse-item>
          <el-collapse-item
            v-hasPermi="['fleet:ftmsorderbillscars:edit']"
            name="4"
          >
            <template slot="title">
              <i class="header-icon el-icon-circle-plus" style="font-size: 16px"
                ><span
                  style="font-size: 16px; font-weight: bolder; margin-left: 5px"
                  >付款信息</span
                >
              </i>
            </template>
            <div>
              <div
                style="
                  display: flex;
                  justify-content: space-between;
                  margin: 10px 0;
                "
              >
                <div>
                  <el-button
                    type="primary"
                    icon="el-icon-plus"
                    size="mini"
                    @click="addDListRow(CList)"
                    :disabled="disabled"
                    >添加</el-button
                  >
                </div>
              </div>
              <el-table :data="CList">
                <el-table-column label="结算单位" align="center" prop="fCorpid">
                  <template slot-scope="scope">
                    <el-select
                      v-model="scope.row.fCorpid"
                      placeholder="结算单位"
                      :clearable="true"
                      filterable
                      :disabled="disabled"
                    >
                      <el-option
                        v-for="(dict, index) in fMblnoOptions"
                        :key="index.fId"
                        :label="dict.fName"
                        :value="dict.fId"
                      />
                    </el-select>
                  </template>
                </el-table-column>

                <el-table-column label="费用名称" align="center" prop="fFeeid">
                  <template slot-scope="scope">
                    <el-select
                      v-model="scope.row.fFeeid"
                      placeholder="费用名称"
                      clearable
                      filterable
                      :disabled="disabled"
                    >
                      <el-option
                        v-for="(dict, index) in fWbuOptions"
                        :key="index.fId"
                        :label="dict.fName"
                        :value="dict.fId"
                      />
                    </el-select>
                  </template>
                </el-table-column>
                <el-table-column
                  label="计费单位"
                  align="center"
                  prop="fFeeunitid"
                >
                  <template slot-scope="scope">
                    <el-select
                      v-model="scope.row.fFeeunitid"
                      placeholder="计费单位"
                      :disabled="disabled"
                    >
                      <el-option
                        v-for="(dict, index) in ffeeunitidList"
                        :key="index.dictValue"
                        :label="dict.dictLabel"
                        :value="dict.dictValue"
                      />
                    </el-select>
                  </template>
                </el-table-column>
                <el-table-column label="计费数量" align="center" prop="fQty">
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.fQty"
                      placeholder="计费数量"
                      v-input-limit="0"
                      :disabled="disabled"
                      @input="total(scope.row)"
                    />
                  </template>
                </el-table-column>
                <el-table-column label="单价" align="center" prop="fUnitprice">
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.fUnitprice"
                      placeholder="单价"
                      v-input-limit="2"
                      :disabled="disabled"
                      @input="total(scope.row)"
                    />
                  </template>
                </el-table-column>
                <el-table-column label="币种" align="center" prop="fCurrency">
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.fCurrency"
                      placeholder="RMB"
                      :disabled="true"
                    />
                  </template>
                </el-table-column>
                <el-table-column label="汇率" align="center" prop="fExrate">
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.fExrate"
                      placeholder="汇率"
                      v-input-limit="2"
                      :disabled="disabled"
                    />
                  </template>
                </el-table-column>
                <el-table-column label="金额" align="center" prop="fAmount">
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.fAmount"
                      placeholder="金额"
                      v-input-limit="2"
                      :disabled="true"
                    />
                  </template>
                </el-table-column>
                <el-table-column label="税率" align="center" prop="fTaxrate">
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.fTaxrate"
                      placeholder="税率"
                      v-input-limit="2"
                      :disabled="disabled"
                    />
                  </template>
                </el-table-column>

                <el-table-column label="备注" align="center" prop="remarks">
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.remarks"
                      placeholder="备注"
                      :disabled="disabled"
                    />
                  </template>
                </el-table-column>

                <el-table-column
                  label="操作"
                  align="center"
                  class-name="small-padding fixed-width"
                  width="100"
                >
                  <template slot-scope="scope">
                    <el-button
                      size="mini"
                      type="text"
                      icon="el-icon-delete"
                      @click.native.prevent="deleteRow(scope.$index, DList)"
                      :disabled="disabled"
                      >删除</el-button
                    >
                  </template>
                </el-table-column>
              </el-table>
            </div>
          </el-collapse-item>

          <el-collapse-item name="5">
            <template slot="title">
              <i class="header-icon el-icon-circle-plus" style="font-size: 16px"
                ><span
                  style="font-size: 16px; font-weight: bolder; margin-left: 5px"
                  >附件上传</span
                >
              </i>
            </template>
            <div>
              <div
                style="
                  display: flex;
                  justify-content: space-between;
                  margin: 10px 0;
                "
              >
                <div>
                  <el-button
                    type="primary"
                    icon="el-icon-plus"
                    size="mini"
                    @click="addRelevt"
                    :disabled="disabled"
                    >添加</el-button
                  >
                </div>
              </div>
              <el-table
                :data="relevantAttachments"
                tooltip-effect="dark"
                border
                stripe
                style="width: 100%"
                height="150"
              >
                <el-table-column label="序号" type="index" width="80">
                </el-table-column>
                <el-table-column
                  prop="attachName"
                  header-align="center"
                  align="center"
                  label="附件名称"
                >
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.attachName"
                      placeholder="附件名称"
                      show-word-limit
                      :disabled="disabled"
                    />
                  </template>
                </el-table-column>
                <el-table-column
                  prop="createBy "
                  header-align="center"
                  align="center"
                  label="上传人"
                >
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.createBy"
                      placeholder="上传人"
                      show-word-limit
                      :disabled="disabled"
                    />
                  </template>
                </el-table-column>
                <el-table-column
                  prop="createTime"
                  header-align="center"
                  align="center"
                  label="上传时间"
                >
                  <template slot-scope="scope">
                    <el-date-picker
                      v-model="scope.row.createTime"
                      type="datetime"
                      disabled
                      placeholder="上传时间"
                    ></el-date-picker>
                  </template>
                </el-table-column>
                <el-table-column
                  prop="attachUrl"
                  header-align="center"
                  align="center"
                  label="上传附件"
                >
                  <template slot-scope="scope">
                    <div style="display: flex; justify-content: center">
                      <el-upload
                        class="upload-demo"
                        :action="uploadImgUrl"
                        :on-success="
                          (res, file) => {
                            handleSucces(scope, res, file);
                          }
                        "
                        :headers="headers"
                        :disabled="disabled"
                        :show-file-list="false"
                        :limit="1"
                      >
                        <el-button size="small" type="text" :disabled="disabled"
                          >点击上传</el-button
                        >
                      </el-upload>
                      <el-button
                        size="small"
                        type="text"
                        @click="checkFile(scope)"
                        :disabled="disabled"
                        style="margin-left: 10px"
                        >查看</el-button
                      >
                      <el-button
                        size="small"
                        type="text"
                        :disabled="disabled"
                        @click="deleteFile(scope)"
                        >删除</el-button
                      >
                    </div>
                  </template>
                </el-table-column>
                <el-table-column
                  header-align="center"
                  align="center"
                  label="操作"
                  width="130PX"
                >
                  <template slot-scope="scope">
                    <el-button
                      size="mini"
                      type="text"
                      icon="el-icon-delete"
                      @click.native.prevent="
                        deleteRow(scope.$index, relevantAttachments)
                      "
                      :disabled="disabled"
                      >删除</el-button
                    >
                  </template>
                </el-table-column>
              </el-table>
            </div>
          </el-collapse-item>
        </el-collapse>
      </el-form>
    </span>
    <span slot="footer" class="dialog-footer">
      <el-button
        type="primary"
        @click="submitForm"
        :disabled="disabled"
        v-hasPermi="['fleet:ftmsorderbillscars:edit']"
        >提 交</el-button
      >
      <!-- <el-button type="success" @click="submitFix">修改</el-button> -->
      <!-- <el-button type="success" @click="submitAllowChanges">修 改</el-button> -->
      <el-button
        type="info"
        @click="submitSave"
        :disabled="disabled"
        v-hasPermi="['fleet:ftmsorderbillscars:edit']"
        >保 存</el-button
      >
      <!-- <el-button type="warning" @click="submitRetreat">撤 回</el-button> -->
      <el-button @click="showDialog = false">取 消</el-button>
    </span>
    <el-dialog
      width="70%"
      title="配载表"
      :visible.sync="stowageDialog"
      append-to-body
    >
      <span>
        <el-table
          :data="stowageList"
          style="width: 100%"
          @selection-change="handleSelectionChange"
          ref="multipleTable"
          @row-click="handleRowClick"
        >
          <el-table-column type="selection" width="55" />
          <el-table-column prop="mblno" label="提单号" />
          <el-table-column prop="orderNo" label="运单号" />
          <el-table-column prop="carregNo" label="车牌号" />
          <el-table-column prop="loadAddr" label="提箱地点" />
          <el-table-column prop="loadDate" label="提箱时间" />
        </el-table>
      </span>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="stowageForm">确认</el-button>
        <el-button @click="stowageDialog = false">取 消</el-button>
      </span>
    </el-dialog>
  </el-dialog>
</template>

<script>
import {
  addFtmsorderbills,
  RetreatFtmsorderbills,
  allowChangesFtmsorderbills,
  updateFtmsorderbills,
} from "@/api/fleet/ftmsorderbills";
import {
  singleaddFtmsorderbillscars,
  revokeFtmsorderbillscars,
  removeFtmsorderbillscars,
  saveFtmsorderbillscars,
  changeFtmsorderbillscars,
  addFtmsorderbillscars,
  singleChangeFtmsorderbillscars,
  selectStowage,
  addStowage,
  revokeStowage,
} from "@/api/fleet/ftmsorderbillscars";
import { getBasicInformation } from "@/api/kaihe/basicdata/container";
import { company } from "@/api/fleet/carManage";
import { listFtmsorderbillss } from "@/api/fleet/carManage";
import { driverList } from "@/api/fleet/driverMsg";
import { listGoods } from "@/api/basicdata/goods";
import { listCorps } from "@/api/basicdata/corps";
import { listFees } from "@/api/basicdata/fees";
import UploadFile from "@/components/Uploadfile";
import Cookies from "js-cookie";
import { getToken } from "@/utils/auth";
export default {
  name: "plans",
  props: {
    addOrUpdateVisible: {
      type: Boolean,
      default: false,
    },
    title: {
      type: String,
      required: "",
    },
    form: Object,
    disabled: {
      type: Boolean,
      default: false,
    },
    DList: {
      type: Array,
      default: [],
    },
    CList: {
      type: Array,
      default: [],
    },
    schedulingList: {
      type: Array,
      default: [],
    },
    vehicleList: {
      type: Array,
      default: [],
    },
    collapses: {
      type: Array,
      default: [],
    },
    relevantAttachments: {
      type: Array,
      default: [],
    },
  },
  components: {
    UploadFile,
  },
  data() {
    return {
      multipleSelection: [],
      companyList: [],
      lbStatus: {},
      dcList: [
        {
          value: "D",
          label: "收款",
        },
        {
          value: "C",
          label: "付款",
        },
      ],
      currencyList: [
        {
          value: "RMB",
          label: "RMB",
        },
      ],
      // 控制弹出框显示隐藏
      showDialog: false,
      // 表单校验
      rules: {
        corpId: [
          { required: true, message: "请输入客户名称", trigger: "blur" },
        ],
        billType: [
          { required: true, message: "请选择业务类型", trigger: "blur" },
        ],
        transType: [
          { required: true, message: "请选择运输方式", trigger: "blur" },
        ],
        loadAddr: [
          { required: true, message: "请输入提箱地点", trigger: "blur" },
        ],
        loadAttntel: [
          {
            pattern: /^((0\d{2,3}-\d{7,8})|(1[0123456789]\d{9}))$/,
            message: "请正确输入手机号",
            trigger: "blur",
          },
        ],
        mdLoadAttnTel: [
          {
            pattern: /^((0\d{2,3}-\d{7,8})|(1[0123456789]\d{9}))$/,
            message: "请正确输入手机号",
            trigger: "blur",
          },
        ],
        unLoadAttnTel: [
          {
            pattern: /^((0\d{2,3}-\d{7,8})|(1[0123456789]\d{9}))$/,
            message: "请正确输入手机号",
            trigger: "blur",
          },
        ],
      },
      billTypeList: [],
      transTypeList: [],
      transPropList: [],
      goodsLossTypeList: [],
      cntrIdList: [],
      priceTypeList: [],
      userType: null,
      username: null,
      fMblnoOptions: [],
      goodsOptions: [],
      fWbuOptions: [],
      ffeeunitidList: [],
      carManages: [],
      stowageList: [],
      stowageDialog: false,
      disabled2: false,
      polList: [],
      podList: [],
      collapses2: [],
      stowageSelection: [],
      uploadImgUrl: process.env.VUE_APP_BASE_API + "/common/upload", // 上传的图片服务器地址
      headers: {
        Authorization: "Bearer " + getToken(),
      },
      addStowagData: "",
      detailsHidden: false,
    };
  },
  created() {
    this.getDicts("data_billType").then((response) => {
      this.billTypeList = response.data;
    });
    this.getDicts("data_transType").then((response) => {
      this.transTypeList = response.data;
    });
    this.getDicts("data_transProp").then((response) => {
      this.transPropList = response.data;
    });
    this.getDicts("data_goodsLossType").then((response) => {
      this.goodsLossTypeList = response.data;
    });
    this.getDicts("data_cntrId").then((response) => {
      response.data.map((e) => (e.noOption = false));
      this.cntrIdList = response.data;
    });
    this.getDicts("data_priceType").then((response) => {
      this.priceTypeList = response.data;
    });
    this.getDicts("data_ffeeunitid").then((response) => {
      this.ffeeunitidList = response.data;
    });
    getBasicInformation({
      fTypes: 1,
      fStatus: "T",
    }).then((response) => {
      this.polList = response;
      this.podList = response;
    });
    listCorps().then((response) => {
      this.fMblnoOptions = response.rows;
    });
    listGoods().then((response) => {
      this.goodsOptions = response.rows;
    });
    listFees().then((response) => {
      this.fWbuOptions = response.rows;
    });
    listFtmsorderbillss().then((response) => {
      this.carManages = response;
    });
    company({
      fStatus: 0,
    }).then((response) => {
      this.companyList = response.rows;
    });
    this.userType = Cookies.get("userType");
    this.username = Cookies.get("userName");
  },
  methods: {
    changeStowageRow(row) {
      revokeStowage(row.id).then((response) => {
        if (response.code == 200) {
          this.msgSuccess("配载撤销成功");
          response.data.map((e, index) => {
            this.$set(this.vehicleList, index, e);
          });
        }
      });
    },
    handleSelectionChange(val) {
      if (val.length > 1) {
        this.$refs.multipleTable.clearSelection();
        this.$refs.multipleTable.toggleRowSelection(val.pop());
      } else {
        this.addStowagData = val[0];
      }
    },
    handleRowClick(row) {
      this.$refs.multipleTable.toggleRowSelection(row);
    },
    stowageForm() {
      if (this.addStowagData) {
        addStowage({
          mBillNo: this.addStowagData.orderNo,
          id: this.addStowagData.id,
        }).then((response) => {
          if (response.code == 200) {
            this.msgSuccess("配载成功");
            this.stowageDialog = false;
            let row = response.data;

            response.data.map((e, index) => {
              this.$set(this.vehicleList, index, e);
            });
            this.addStowagData = "";
          }
        });
      } else {
        this.$message.error("请选择一条配载信息");
      }
    },
    carChange(row) {
      let arr = [];
      arr = this.carManages.filter((e) => e.carNum == row.carregNo);
      this.$set(row, "driverName", arr[0].driverName);
      this.$set(row, "driverTel", arr[0].driverTel);
      this.$set(row, "driverUserId", arr[0].driverId);
    },
    //选中时赋值pid
    checkPid(row) {
      let arr = this.schedulingList;
      let arr2 = arr.filter((e) => e.cntrId == row.cntrId);
      row["pid"] = arr2[0].id;
    },
    noMorecntrId(e) {
      this.cntrIdList.forEach((item) => (item.noOption = false));
      let arrIds = e.map((item) => item.cntrId);
      this.cntrIdList
        .filter((item) => arrIds.indexOf(item.dictValue) > -1)
        .forEach((item) => (item.noOption = true));
    },
    showSure(val) {
      let pidList = val.filter((e) => e.pid != null);
      let arr1 = pidList;
      let arr1Ids = arr1.map((item) => item.cntrId);
      arr1Ids = [...new Set(arr1Ids)];
      let arr2 = this.cntrIdList;
      this.cntrId2List = arr2.filter(
        (item) => arr1Ids.indexOf(item.dictValue) > -1
      );
    },
    // 新增附件上传
    addRelevt() {
      this.relevantAttachments.push({
        attachUrl: null,
        attachName: null,
        createBy: this.username,
        createTime: Date.parse(new Date()),
      });
    },
    //附件删除
    deleteFile(scope) {
      this.relevantAttachments[scope.$index].attachName = "";
      this.relevantAttachments[scope.$index].attachUrl = "";
      if (this.relevantAttachments[scope.$index].attachUrl === "") {
        this.$message.success("删除成功");
      } else {
        this.$message.error("未知错误，删除失败");
      }
    },
    //附件查看
    checkFile(scope) {
      if (this.relevantAttachments[scope.$index].attachUrl) {
        window.open(this.relevantAttachments[scope.$index].attachUrl);
      } else {
        this.$message.error("请上传附件");
      }
    },
    //附件上传
    handleSucces(scope, res, file) {
      this.relevantAttachments[scope.$index].attachName = res.fileName;
      this.relevantAttachments[scope.$index].attachUrl = res.url;
      if (this.relevantAttachments[scope.$index].attachUrl === "") {
        this.$message.error("上传失败");
      } else {
        this.$message.success("上传成功");
      }
    },
    // 添加行
    addRow(tableData, event) {
      var obj = {};
      tableData.push(obj);
      this.showSure(this.schedulingList);
    },
    // 添加行
    addRow2(tableData, event) {
      tableData.push({
        cntrId: this.schedulingList[0].cntrId,
        pId: this.schedulingList[0].id,
        carcorPid: this.schedulingList[0].carcorPid,
        freightPriceDr: this.schedulingList[0].freightPriceDr,
        freightPriceCr: this.schedulingList[0].freightPriceCr,
      });
      this.showSure(this.schedulingList);
      listFtmsorderbillss({
        fleetCompanyId: this.schedulingList[0].carcorPid,
      }).then((response) => {
        this.carManages = response;
      });
    },
    //删除行
    deleteRow(index, rows) {
      rows.splice(index, 1);
    },
    deleteplansRow(index, rows, row) {
      let arr = this.schedulingList;
      let arr2 = arr.filter((e) => e.cntrId == row.cntrId && e.cntrId != null);
      if (arr2.length != 0) {
        this.$message.error("调度安排已插入此箱型数据，不能删除");
      } else {
        this.cntrIdList
          .filter((item) => item.dictValue == row.cntrId)
          .forEach((item) => (item.noOption = false));
        rows.splice(index, 1);
      }
    },
    addDListRow(tableData, event) {
      var obj = { fcorpid: this.form.corpId, fcurrency: "RMB", fExrate: "1" };
      tableData.push(obj);
    },
    // 上传成功返回数据
    showFile(row) {
      for (let list in this.relevantAttachments) {
        this.$set(this.relevantAttachments[list], "attachUrl", row.url);
        this.$set(this.relevantAttachments[list], "attachName", row.fileName);
      }
    },
    // 弹出框关闭后触发
    handleClose() {
      // 子组件调用父组件方法，并传递参数
      this.$emit("changeShow", "false");
      this.cntrIdList.forEach((item) => (item.noOption = false));
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (!this.vehicleList.length) {
            return this.$message.error("车辆安排不能为空");
          }
          if (this.schedulingList[0].cntrQty != this.schedulingList[0].carQty) {
            return this.$message.error("调度安排存在未安排的货量");
          }
          this.DList.map((e) => {
            return (e.fDc = "D");
          });
          this.DList.map((e) => {
            return (e.fcurrency = "RMB");
          });
          this.CList.map((e) => {
            return (e.fDc = "C");
          });
          this.CList.map((e) => {
            return (e.fcurrency = "RMB");
          });
          this.vehicleList.map((e) => {
            return (e.carcorPid = this.schedulingList[0].carcorPid);
          });
          let num = 0;
          this.vehicleList.map((e) => {
            num += parseInt(e.cntrQty);
          });
          for (let li in this.vehicleList) {
            if (
              this.vehicleList[li].billStatus < 6 &&
              this.vehicleList[li].billStatus != 3
            ) {
              return this.$message.error("车辆安排存在未提交的数据");
            }
          }
          if (num > this.schedulingList[0].cntrQty) {
            return this.$message.error("车辆安排货量已超过计划货量");
          }
          let arr2 = [];
          let arr = this.vehicleList.filter((e) => e.billStatus == 6);
          arr.map((a) => {
            arr2.push(a.carregNo);
          });
          this.schedulingList[0]["carnolist"] = [...new Set(arr2)].join("/");
          let formData = new window.FormData();
          formData.append("cars", JSON.stringify(this.vehicleList));
          formData.append("attachs", JSON.stringify(this.relevantAttachments));
          formData.append(
            "fees",
            JSON.stringify(this.DList.concat(this.CList))
          );
          formData.append("plans", JSON.stringify(this.schedulingList[0]));
          addFtmsorderbillscars(formData).then((response) => {
            this.msgSuccess("提交成功");
            this.$parent.getList();
            this.showDialog = false;
          });
        }
      });
    },
    //修改
    submitFix() {
      // this.$refs["form"].validate((valid) => {
      //   if (valid) {
      //     if (this.form.id != null) {
      //       this.DList.map((e) => {
      //         return (e.fDc = "D");
      //       });
      //       this.DList.map((e) => {
      //         return (e.fcurrency = "RMB");
      //       });
      //       this.CList.map((e) => {
      //         return (e.fDc = "C");
      //       });
      //       this.CList.map((e) => {
      //         return (e.fcurrency = "RMB");
      //       });
      //       let formData = new window.FormData();
      //       formData.append("tmsorder", JSON.stringify(this.form));
      //       formData.append(
      //         "attachs",
      //         JSON.stringify(this.relevantAttachments)
      //       );
      //       formData.append(
      //         "fees",
      //         JSON.stringify(this.DList.concat(this.CList))
      //       );
      //       formData.append("plans", JSON.stringify(this.schedulingList));
      //       updateFtmsorderbills(formData).then((response) => {
      //         this.msgSuccess("修改成功");
      //         this.$parent.getList();
      //         this.showDialog = false;
      //       });
      //     }
      //   }
      // });
    },
    //保存
    submitSave() {
      this.DList.map((e) => {
        return (e.fDc = "D");
      });
      this.DList.map((e) => {
        return (e.fcurrency = "RMB");
      });
      this.CList.map((e) => {
        return (e.fDc = "C");
      });
      this.CList.map((e) => {
        return (e.fcurrency = "RMB");
      });
      this.vehicleList.map((e) => {
        return (e.carcorPid = this.schedulingList[0].carcorPid);
      });
      let arr2 = [];
      let arr = this.vehicleList.filter((e) => e.billStatus == 6);
      arr.map((a) => {
        arr2.push(a.carregNo);
      });
      this.schedulingList[0]["carnolist"] = [...new Set(arr2)].join("/");
      let formData = new window.FormData();
      formData.append("cars", JSON.stringify(this.vehicleList));
      formData.append("attachs", JSON.stringify(this.relevantAttachments));
      formData.append("fees", JSON.stringify(this.DList.concat(this.CList)));
      formData.append("plans", JSON.stringify(this.schedulingList[0]));
      saveFtmsorderbillscars(formData).then((response) => {
        if (response.code == 200) {
          this.msgSuccess("保存成功");
          this.$parent.getList();
          this.$parent.getSave(response);
        }
      });
    },
    //撤回
    submitRetreat() {
      const id = { id: this.form.id };
      RetreatFtmsorderbills(id).then((response) => {
        if (response.code == 200) {
          this.msgSuccess("撤回成功");
          this.$parent.getList();
          this.$emit("fixDisabled", "false");
        }
      });
    },
    //修改
    submitAllowChanges() {
      // if (this.schedulingList.billStatus > 6) {
      //   this.$emit("fixDisabled", "false");
      //   this.msgSuccess("允许修改");
      // }
      // const id = this.form.id;
      // allowChangesFtmsorderbills(id).then((response) => {
      //   if (response == false) {
      //     this.msgSuccess("不允许修改");
      //   } else {
      //     this.$emit("fixDisabled", "false");
      //     this.msgSuccess("允许修改");
      //   }
      // });
    },
    //单条订单调度提交
    addscarsRow(row) {
      if (row.billStatus == 5) {
        singleChangeFtmsorderbillscars(row).then((response) => {
          if (response.code == 200) {
            this.msgSuccess("成功提交");
            this.$set(row, "billStatus", 6);
            this.$set(
              this.schedulingList[0],
              "carQty",
              response.data.plan.carQty
            );
            this.$set(row, "orderStatus", response.data.cars.orderStatus);
            this.$set(row, "billKind", response.data.cars.billKind);
            this.$set(row, "mBillNo", response.data.cars.mBillNo);
            this.$set(row, "orderNo", response.data.cars.orderNo);
            this.$set(row, "orgId", response.data.cars.orgId);
            this.$set(row, "id", response.data.cars.id);
            this.$set(row, "mblno", response.data.cars.mblno);
          }
        });
      } else if (row.billStatus != 6) {
        singleaddFtmsorderbillscars(row).then((response) => {
          this.msgSuccess("成功提交");
          if (response.code == 200) {
            this.$set(row, "billStatus", 6);
            this.$set(
              this.schedulingList[0],
              "carQty",
              response.data.plan.carQty
            );
            this.$set(row, "orderStatus", response.data.cars.orderStatus);
            this.$set(row, "billKind", response.data.cars.billKind);
            this.$set(row, "mBillNo", response.data.cars.mBillNo);
            this.$set(row, "orderNo", response.data.cars.orderNo);
            this.$set(row, "orgId", response.data.cars.orgId);
            this.$set(row, "id", response.data.cars.id);
            this.$set(row, "mblno", response.data.cars.mblno);
          }
        });
      } else {
        this.$message.error("请勿重复提交");
      }
    },
    delscarsRow(index, rows, row) {
      if (row.billStatus != 6 && row.id != null) {
        removeFtmsorderbillscars(row).then((response) => {
          if (response.code == 200) {
            rows.splice(index, 1);
            this.msgSuccess("成功删除");
            this.$set(
              this.schedulingList[0],
              "carQty",
              response.data.plan.carQty
            );
          }
        });
      } else {
        rows.splice(index, 1);
      }
    },
    revokescarsRow(index, rows, row) {
      if (row.billStatus == 6) {
        revokeFtmsorderbillscars(row).then((response) => {
          if (response.code == 200) {
            this.msgSuccess("成功撤回");
            this.$set(row, "billStatus", 3);
            this.$set(row, "orderStatus", response.data.cars.orderStatus);
            this.$set(row, "orgId", response.data.cars.orgId);
            this.$set(row, "id", response.data.cars.id);
            this.$set(
              this.schedulingList[0],
              "carQty",
              response.data.plan.carQty
            );
          }
        });
      } else {
        this.$message.error("此条数据没有提交，不能申请撤回");
      }
    },
    // 查询可配载数据
    selectStowage(row) {
      selectStowage(row).then((response) => {
        this.stowageDialog = true;
        if (response.rows) {
          this.stowageList = response.rows;
        }
      });
    },
    changescarsRow(row) {
      if (row.billStatus == 6) {
        changeFtmsorderbillscars(row.id).then((response) => {
          if (response.code == 200) {
            this.msgSuccess("允许变更");
            this.$set(row, "billStatus", 5);
          }
        });
      } else if (row.billStatus == 5) {
        this.$message.error("请勿重复变更");
      } else {
        this.msgSuccess("允许变更");
        this.$set(row, "billStatus", 5);
      }
    },
    total(row) {
      if (row.fQty && row.fUnitprice) {
        this.$set(row, "fAmount", (row.fQty * row.fUnitprice).toFixed(2));
      } else {
        this.$set(row, "fAmount", 0);
      }
    },
  },
  watch: {
    // 监听 addOrUpdateVisible 改变
    addOrUpdateVisible(oldVal, newVal) {
      this.showDialog = this.addOrUpdateVisible;
    },
    schedulingList(val) {
      this.showSure(val);
    },
    collapses() {
      this.collapses2 = this.collapses;
    },
  },
};
</script>
