<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="120px">

      <el-form-item label="航次号" prop="voyageNo">
        <el-input v-model="queryParams.voyageNo" placeholder="请输入航次号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="船舶名称" prop="vesselName">
        <el-input v-model="queryParams.vesselName" placeholder="请输入船舶名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="国籍" prop="nationality">
        <el-select filterable v-model="queryParams.nationality" placeholder="请选择国籍" clearable>
          <el-option v-for="dict in dict.type.sys_nationality" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>

      <el-form-item label="动态类型" prop="dynType">
        <el-select v-model="queryParams.dynType" placeholder="请选择动态类型" clearable>
          <el-option v-for="dict in dict.type.sys_ship_dynamic_type" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="船舶动态" prop="shipDyn">
        <el-select v-model="queryParams.shipDyn" placeholder="请选择船舶动态" clearable>
          <el-option v-for="dict in dict.type.sys_ship_dynamic" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="所属港口公司" prop="deptId">
        <treeselect v-model="queryParams.deptId" :options="deptOptions" :show-count="true" style="width:205px"
          placeholder="请选择所属港口公司" />
      </el-form-item>

      <el-form-item label="泊位名称" prop="berthName">
        <el-input v-model="queryParams.berthName" placeholder="请输入泊位名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="来港目的" prop="opType">
        <el-select v-model="queryParams.opType" placeholder="请选择来港目的" clearable>
          <el-option v-for="dict in dict.type.sys_port_objective" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="代理" prop="agency">
        <el-select v-model="queryParams.agency" placeholder="请选择代理" clearable>
          <el-option v-for="dict in dict.type.sys_agent" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="靠泊时间" prop="queryTime">
        <el-date-picker clearable size="small" v-model="queryTime" :picker-options="pickerOptions" end-placeholder="结束日期"
          placeholder="靠泊时间" range-separator="-" start-placeholder="开始日期" type="daterange" value-format="yyyy-MM-dd">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['jxc:bmvoyage:add']">新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['jxc:bmvoyage:edit']">修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['jxc:bmvoyage:remove']">删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['jxc:bmvoyage:export']">导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="bmvoyageList" highlight-current-row @sort-change="handleSortChange"
      @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />

      <el-table-column label="船舶信息" align="center">
        <el-table-column label="航次号" align="center" prop="voyageNo" sortable='custom' width="100" />
        <el-table-column label="船舶名称" align="center" prop="vesselName" sortable='custom' width="100" />
        <el-table-column label="靠泊时间" align="center" prop="berthTime" width="180" sortable='custom'>
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.berthTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="净吨" align="center" prop="netTon" sortable='custom' />
        <el-table-column label="国籍" align="center" prop="nationality">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.sys_nationality" :value="scope.row.nationality" />
          </template>
        </el-table-column>

        <el-table-column label="船长" align="center" prop="vesselLength" sortable='custom' />
        <el-table-column label="吃水" align="center" prop="vesselDraft" sortable='custom' />
        <el-table-column label="载重吨" align="center" prop="dwt" sortable='custom' width="100" />
        <el-table-column label="动态类型" align="center" prop="dynType" width="100">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.sys_ship_dynamic_type" :value="scope.row.dynType" />
          </template>
        </el-table-column>
        <el-table-column label="船舶动态" align="center" prop="shipDyn">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.sys_ship_dynamic" :value="scope.row.shipDyn" />
          </template>
        </el-table-column>
        <el-table-column label="所属港口公司" align="center" prop="deptId" sortable='custom' width="100"
          :formatter="deptFormatter" />
      </el-table-column>
      <el-table-column label="泊位信息" align="center">
        <!--              <el-table-column label="泊位ID" align="center" prop="berthId" sortable='custom' />-->
        <el-table-column label="泊位名称" align="center" prop="berthName" sortable='custom' width="100" />
        <el-table-column label="来港目的" align="center" prop="opType" sortable='custom' width="100">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.sys_port_objective" :value="scope.row.opType" />
          </template>
        </el-table-column>
        <el-table-column label="装卸计划量" align="center" prop="cargoDesc" sortable='custom' width="140" />
        <el-table-column label="起运港" align="center" prop="departurePort">
          <template slot-scope="scope">
            <span>{{ selectPortLabel(scope.row.departurePort) }}</span>
          </template>
        </el-table-column>
        <el-table-column label="到达港" align="center" prop="arrivalPort">
          <template slot-scope="scope">
            <span>{{ selectPortLabel(scope.row.arrivalPort) }}</span>
          </template>
        </el-table-column>
        <el-table-column label="在泊时" align="center" prop="onBerth" sortable='custom' width="100" />
        <el-table-column label="进引" align="center" prop="inPilot">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.sys_introduction" :value="scope.row.inPilot" />
          </template>
        </el-table-column>
        <el-table-column label="移引" align="center" prop="rePilot">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.sys_diversion" :value="scope.row.rePilot" />
          </template>
        </el-table-column>
        <el-table-column label="离引" align="center" prop="unPilot">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.sys_diversion" :value="scope.row.unPilot" />
          </template>
        </el-table-column>

        <el-table-column label="代理" align="center" prop="agency" sortable='custom'>
          <template slot-scope="scope">
            <dict-tag :options="dict.type.sys_agent" :value="scope.row.agency" />
          </template>
        </el-table-column>
      </el-table-column>


      <el-table-column fixed="right" label="操作" align="center" class-name="small-padding fixed-width" width="120px">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['jxc:bmvoyage:edit']">修改
          </el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['jxc:bmvoyage:remove']">删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改船舶航次对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="80%" append-to-body :close-on-click-modal="false">
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">


        <el-collapse v-model="activeName">
          <el-collapse-item name="1">
            <template slot="title">
              <span style="color:#409EFF ; font-size: 18px;">船舶信息</span>
            </template>
            <el-row>
              <el-col :span="6">
                <el-form-item label="航次号" prop="voyageNo">
                  <el-input v-model="form.voyageNo" placeholder="请输入航次号" />
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="船舶名称" prop="vesselName">
                  <el-select v-model="form.vesselId" filterable placeholder="请输入船舶名称" style="width: 100%" clearable
                    @change="setVesselDetail">
                    <el-option v-for="item in vesselList" :key="item.id" :label="item.vesselName" :value="item.id">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="所属港口公司" prop="deptId">
                  <treeselect style="width: 100%;" v-model="form.deptId" :options="deptOptions" :show-count="true"
                    placeholder="请选择所属港口公司" @select="deptChange" />
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="净吨(吨)" prop="netTon">
                  <el-input v-model="form.netTon" placeholder="请输入净吨" type="number" disabled />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="6">
                <el-form-item label="国籍" prop="nationality">
                  <el-select v-model="form.nationality" placeholder="请输入国籍" clearable style="width: 100%" disabled>
                    <el-option v-for="dict in dict.type.sys_nationality" :key="dict.value" :label="dict.label"
                      :value="dict.value" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="船长(米)" prop="vesselLength">
                  <el-input v-model="form.vesselLength" placeholder="请输入船长" type="number" disabled />
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="吃水(米)" prop="vesselDraft">
                  <el-input v-model="form.vesselDraft" placeholder="请输入吃水" type="number" />
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="载重吨(吨)" prop="dwt">
                  <el-input v-model="form.dwt" placeholder="请输入载重吨" type="number" disabled />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="6">
                <el-form-item label="动态类型" prop="dynType">
                  <el-select v-model="form.dynType" placeholder="请选择动态类型" clearable style="width: 100%">
                    <el-option v-for="dict in dict.type.sys_ship_dynamic_type" :key="dict.value" :label="dict.label"
                      :value="dict.value"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="船舶动态" prop="shipDyn">
                  <el-select v-model="form.shipDyn" placeholder="请输入船舶动态" clearable style="width: 100%">
                    <el-option v-for="dict in dict.type.sys_ship_dynamic" :key="dict.value" :label="dict.label"
                      :value="dict.value" />
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
            </el-row>
          </el-collapse-item>
          <el-collapse-item name="2">
            <template slot="title">
              <span style="color:#409EFF ; font-size: 18px;">泊位信息</span>
            </template>
            <el-row>
              <el-col :span="6">
                <el-form-item label="泊位名称" prop="berthName">
                  <el-select v-model="form.berthId" filterable placeholder="请输入泊位名称" style="width: 100%" clearable
                    @change="setBerthDetail">
                    <el-option v-for="item in filterBerthList" :key="item.id" :label="item.berthName" :value="item.id">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="来港目的" prop="opType">
                  <el-select v-model="form.opType" placeholder="请选择来港目的" style="width: 100%">
                    <el-option v-for="dict in dict.type.sys_port_objective" :key="dict.value" :label="dict.label"
                      :value="dict.value"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="靠泊时间" prop="berthTime">
                  <el-date-picker style="width: 100%;" clearable v-model="form.berthTime" type="datetime"
                    value-format="yyyy-MM-dd HH:mm:ss" placeholder="请选择靠泊时间">
                  </el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="起运港" prop="departurePort">
                  <el-select v-model="form.departurePort" filterable placeholder="请输入起运港" style="width: 100%" clearable>
                    <el-option v-for="item in portList" :key="item.id" :label="item.portName" :value="item.id">
                    </el-option>
                  </el-select>

                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="6">
                <el-form-item label="到达港" prop="arrivalPort">
                  <el-select v-model="form.arrivalPort" filterable placeholder="请输入到达港" style="width: 100%" clearable>
                    <el-option v-for="item in portList" :key="item.id" :label="item.portName" :value="item.id">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="进引" prop="inPilot">
                  <el-select v-model="form.inPilot" placeholder="请输入进引" clearable style="width: 100%">
                    <el-option v-for="dict in dict.type.sys_introduction" :key="dict.value" :label="dict.label"
                      :value="dict.value" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="移引" prop="rePilot">
                  <el-select v-model="form.rePilot" placeholder="请输入移引" clearable style="width: 100%">
                    <el-option v-for="dict in dict.type.sys_diversion" :key="dict.value" :label="dict.label"
                      :value="dict.value" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="离引" prop="unPilot">
                  <el-select v-model="form.unPilot" placeholder="请输入离引" clearable style="width: 100%">
                    <el-option v-for="dict in dict.type.sys_dissociation" :key="dict.value" :label="dict.label"
                      :value="dict.value" />
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="6">
                <el-form-item label="在泊时（小时）" prop="onBerth">
                  <el-input v-model="form.onBerth" placeholder="请输入在泊时（小时）" />
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="代理" prop="agency">
                  <el-select v-model="form.agency" placeholder="请选择代理" style="width: 100%">
                    <el-option v-for="dict in dict.type.sys_agent" :key="dict.value" :label="dict.label"
                      :value="dict.value"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
            </el-row>
            <el-row>
              <el-col :span="24">
                <el-form-item label="装卸计划量(吨)" prop="cargoDesc">
                  <el-input v-model="form.cargoDesc" type="textarea" placeholder="请输入内容" />
                </el-form-item>
              </el-col>
            </el-row>
          </el-collapse-item>
        </el-collapse>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { pageListBmvoyage, getBmvoyage, delBmvoyage, addBmvoyage, updateBmvoyage } from "@/api/jxc/bmvoyage";
import { listVessel, } from "@/api/jxc/vessel";
import { listBerth, } from "@/api/jxc/berth";
import { listCust, } from "@/api/jxc/cust";
import { listPort, } from "@/api/jxc/port";

import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import { deptTreeSelect } from "@/api/system/user";
import Treeselect from "@riophae/vue-treeselect";
import { listDept } from "../../../api/system/dept";


export default {
  name: "Bmvoyage",
  components: { Treeselect },

  dicts: ['sys_ship_dynamic', 'sys_agent', 'sys_port_objective', 'sys_ship_dynamic_type', 'sys_nationality', 'sys_introduction', 'sys_dissociation', 'sys_diversion'],
  data() {
    return {
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
            picker.$emit('pick', [start, end]);
          }
        }]
      },
      activeName: ['1', '2', '3'],

      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 选中名字
      names: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 部门名称
      deptName: "",
      // 部门树选项
      deptOptions: [],
      deptList: [],
      // 靠泊时间
      queryTime: [],
      // 到达港表格数据
      portList: [],
      // 客户表格数据
      custList: [],
      // 船舱表格数据
      vesselList: [],
      // 泊位表格数据
      berthList: [],
      // 船舶航次表格数据
      bmvoyageList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        voyageNo: null,
        vesselId: null,
        vesselName: null,
        netTon: null,
        nationality: null,
        vesselLength: null,
        vesselDraft: null,
        dwt: null,
        dynType: null,
        shipDyn: null,
        berthId: null,
        berthName: null,
        opType: null,
        cargoDesc: null,
        berthTime: null,
        departurePort: null,
        arrivalPort: null,
        onBerth: null,
        inPilot: null,
        rePilot: null,
        unPilot: null,
        agency: null,
        deptId: null,
        beginDate: null,
        endDate: null,
        orderByColumn: 'berthTime',
        isAsc: 'desc'
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        // vesselDraft: [
        //   { required: true, message: "吃水不能为空", trigger: "blur" },
        // ],
        deptId: [
          { required: true, message: "所属港口公司不能为空", trigger: "blur" },
        ],
        voyageNo: [
          { required: true, message: "航次号不能为空", trigger: "blur" },
        ],
        vesselName: [
          { required: true, message: "船舶名称不能为空", trigger: "blur" },
        ],
        dynType: [
          { required: true, message: "动态类型不能为空", trigger: "blur" },
        ],
        berthName: [
          { required: true, message: "泊位名称不能为空", trigger: "blur" },
        ],
        shipDyn: [
          { required: true, message: "船舶动态不能为空", trigger: "blur" },
        ],
        opType: [
          { required: true, message: "来港目的不能为空", trigger: "blur" },
        ],
        departurePort: [
          { required: true, message: "起运港不能为空", trigger: "blur" },
        ],
        arrivalPort: [
          { required: true, message: "到达港不能为空", trigger: "blur" },
        ],
        // onBerth: [
        //   { required: true, message: "在泊时不能为空", trigger: "blur" },
        // ],
        // inPilot: [
        //   { required: true, message: "进引不能为空", trigger: "blur" },
        // ],
        // rePilot: [
        //   { required: true, message: "移引不能为空", trigger: "blur" },
        // ],
        // unPilot: [
        //   { required: true, message: "离引不能为空", trigger: "blur" },
        // ],
        cargoDesc: [
          { required: true, message: "货物装卸计划量不能为空", trigger: "blur" },
        ],

      },
      seletcedDept: {},
    };
  },
  computed: {
    filterBerthList() {
      if (this.berthList && this.seletcedDept.id) {
        return this.berthList.filter(val => {
          const findDept = (dept) => {
            if (dept.id == val.companyId) {
              return true;
            } else if (dept.children && dept.children.length) {
              for (let index = 0; index < dept.children.length; index++) {
                const element = dept.children[index];
                if (findDept(element)) {
                  return true;
                }
              }
            }
            return false;
          }
          return findDept(this.seletcedDept);
        });
      }
      return this.berthList || [];
    }
  },
  created() {
    this.getList();
    this.getVesselList();
    this.getBerthList();
    this.getCustList();
    this.getPortList()
    this.getDeptTree();
    listDept({}).then(response => {
      this.deptList = response.data;
    });

  },
  methods: {
    /** 查询部门下拉树结构 */
    getDeptTree() {
      deptTreeSelect().then(response => {
        this.deptOptions = response.data;
      });
    },
    deptChange(value) {
      this.form.berthId = null;
      this.seletcedDept = value;
    },
    deptFormatter(row, column, cellValue, index) {
      //console.log("dept", this.deptOptions);
      const obj = this.deptList.find((obj) => obj.deptId === cellValue)
      return obj ? obj.deptName : cellValue
    },
    getPortList() {
      let param = {};
      listPort(param).then(response => {
        this.portList = response.data;
      }).catch(e => {
      });
    },

    //客户
    setCustDetail(custId) {

      this.custList.forEach(ele => {
        if (ele.id == custId) {

          this.form.custName = ele.custName;
          this.form.custCode = ele.custCode;

        }
      })
    },

    getCustList() {
      let param = {};
      listCust(param).then(response => {
        this.custList = response.data;
      }).catch(e => {
      });
    },

    //船舶
    setVesselDetail(vesselId) {
      //console.log(vesselId);
      this.vesselList.forEach(ele => {
        if (ele.id == vesselId) {
          console.log("aa:", ele.vesselName);
          this.form.vesselName = ele.vesselName;
          this.form.nationality = ele.nationality;
          this.form.netTon = ele.netTon;
          this.form.vesselLength = ele.vesselLength;
          this.form.vesselDraft = ele.vesselDraft;
          this.form.dwt = ele.dwt;


        }
      })
    },

    getVesselList() {
      let param = {};
      listVessel(param).then(response => {
        this.vesselList = response.data;
      }).catch(e => {
      });
    },

    getBerthList() {
      let param = {};
      listBerth(param).then(response => {
        this.berthList = response.data;
      }).catch(e => {
      });
    },

    setBerthDetail(berthId) {
      //console.log(berthId);
      this.berthList.forEach(ele => {
        if (ele.id == berthId) {
          this.form.berthName = ele.berthName;
        }
      })
    },


    /** 查询船舶航次列表 */
    getList() {
      this.loading = true;
      if (this.queryTime != null) {
        this.queryParams.beginDate = this.queryTime[0];
        this.queryParams.endDate = this.queryTime[1];
      } else {
        this.queryParams.beginDate = null;
        this.queryParams.endDate = null;
      }
      pageListBmvoyage(this.queryParams).then(response => {
        this.bmvoyageList = response.rows;
        this.total = response.total;
        this.loading = false;
      }).catch(e => {
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        voyageNo: null,
        vesselId: null,
        vesselName: null,
        netTon: null,
        nationality: null,
        vesselLength: null,
        vesselDraft: null,
        dwt: null,
        dynType: null,
        shipDyn: null,
        berthId: null,
        berthName: null,
        opType: null,
        cargoDesc: null,
        berthTime: null,
        departurePort: null,
        arrivalPort: null,
        onBerth: null,
        inPilot: null,
        rePilot: null,
        unPilot: null,
        agency: null,
        deptId: null,
        remark: null,
        // custId:null,
      };
      this.resetForm("form");
    },
    //排序
    handleSortChange(col) {
      this.$sortBy(col, this.queryParams);
      this.getList();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryTime = [];
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id);
      this.names = selection.map(item => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加船舶航次";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getBmvoyage(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改船舶航次";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateBmvoyage(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addBmvoyage(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      const names = row.id || this.names;
      this.$modal.confirm('是否确认删除"' + row.voyageNo + "-" + row.vesselName + '"的数据项？').then(function () {
        return delBmvoyage(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('jxc/bmvoyage/export', {
        ...this.queryParams
      }, `船舶航次_${new Date().getTime()}.xlsx`)
    },
    selectPortLabel(portId) {
      let portName;
      this.portList.some(item => {
        if (item.id === portId) {
          portName = item.portName;
        }
      })
      return portName;
    }
  }
};
</script>
