<template>
    <div>
        <div class="customer-head">
            <div class="customer-back">
                <el-button type="danger" style="border: none;background: none;color: red" icon="el-icon-arrow-left"
                    @click="backToList(0)">返回列表
                </el-button>
            </div>
            <div class="add-customer-btn">
                <el-button class="el-button&#45;&#45;small-yh" style="margin-left: 6px;" type="primary" size="small"
                    v-if="form.id && editButton" :disabled="form.issueStatus != 'I'" @click="inEdit">编 辑
                </el-button>
                <el-button class="el-button--small-yh" style="margin-left: 6px;" type="primary" size="small"
                    v-if="!editButton" @click="submit">保 存
                </el-button>
                <el-button type="success" size="small" v-if="form.id && form.issueStatus == 'I'"
                    @click="subApplication">放单完成</el-button>
            </div>
        </div>
        <div style="margin-top: 50px">
            <trade-card title="基础信息">
                <avue-form :option="optionForm" v-model="form" ref="form">
                    <tempalte slot="corpCnName" slot-scope="{ row }">
                        <search-query :datalist="corpData" :selectValue="form.corpCnName" :clearable="true"
                            :buttonIf="false" :filterable="true" :remote="true" :disabled="editButton" placeholder="请选择客户"
                            :forParameter="{ key: 'id', label: 'cnName', value: 'cnName' }"
                            @corpFocus="getRemote($event, 'corpCnName')" @remoteMethod="getRemote($event, 'corpCnName')"
                            @corpChange="selectChange($event, 'corpCnName')">
                        </search-query>
                    </tempalte>
                    <tempalte slot="carrierCnName" slot-scope="{ row }">
                        <search-query :datalist="carrierData" :selectValue="form.carrierCnName" :clearable="true"
                            :buttonIf="false" :filterable="true" :remote="true" :disabled="editButton" placeholder="请选择船公司"
                            :forParameter="{ key: 'id', label: 'cnName', value: 'cnName' }"
                            @corpFocus="getRemote($event, 'carrierCnName')"
                            @remoteMethod="getRemote($event, 'carrierCnName')"
                            @corpChange="selectChange($event, 'carrierCnName')">
                        </search-query>
                    </tempalte>
                    <tempalte slot="vesselCnName" slot-scope="{ row }">
                        <search-query :datalist="vesselData" :selectValue="form.vesselCnName" :clearable="true"
                            :buttonIf="false" :filterable="true" :remote="true" :disabled="editButton" placeholder="请选择船名"
                            :forParameter="{ key: 'id', label: 'cnName', value: 'cnName' }"
                            @corpFocus="getRemote($event, 'vesselCnName')" @remoteMethod="getRemote($event, 'vesselCnName')"
                            @corpChange="selectChange($event, 'vesselCnName')">
                        </search-query>
                    </tempalte>
                    <tempalte slot="polCnName" slot-scope="{ row }">
                        <search-query :datalist="polData" :selectValue="form.polCnName" :clearable="true" :buttonIf="false"
                            :filterable="true" :remote="true" :disabled="editButton" placeholder="请选择起运港"
                            :forParameter="{ key: 'id', label: 'cnName', value: 'cnName' }"
                            @corpFocus="getRemote($event, 'polCnName')" @remoteMethod="getRemote($event, 'polCnName')"
                            @corpChange="selectChange($event, 'polCnName')">
                        </search-query>
                    </tempalte>
                    <tempalte slot="podCnName" slot-scope="{ row }">
                        <search-query :datalist="podData" :selectValue="form.podCnName" :clearable="true" :buttonIf="false"
                            :filterable="true" :remote="true" :disabled="editButton" placeholder="请选择目的港"
                            :forParameter="{ key: 'id', label: 'cnName', value: 'cnName' }"
                            @corpFocus="getRemote($event, 'podCnName')" @remoteMethod="getRemote($event, 'podCnName')"
                            @corpChange="selectChange($event, 'podCnName')">
                        </search-query>
                    </tempalte>
                    <tempalte slot="runnerName" slot-scope="{ row }">
                        <search-query :datalist="runnerData" :selectValue="form.runnerName" :clearable="true"
                            :buttonIf="false" :filterable="true" :remote="true" :disabled="editButton" placeholder="请选择跑单"
                            :forParameter="{ key: 'id', label: 'name', value: 'name' }"
                            @corpFocus="getRemote($event, 'runnerName')" @remoteMethod="getRemote($event, 'runnerName')"
                            @corpChange="selectChange($event, 'runnerName')">
                        </search-query>
                    </tempalte>
                    <template slot="unreleaseBillsLabel">
                        <el-button type="primary" size="small" plain
                            :disabled="!form.id || form.issueStatus != 'I' || editButton"
                            @click="subsequentAb">后续有货</el-button>
                    </template>
                </avue-form>
                <div style="display: flex;justify-content: flex-end;">
                    <el-button type="primary" size="small" :disabled="editButton || form.releaseBillList.length > 0"
                        @click="queryDetails">检索</el-button>
                    <el-button plain size="small" :disabled="editButton || form.id" @click="reset">重置</el-button>
                    <el-button type="danger" size="small" :disabled="editButton || selectionList.length == 0"
                        @click="del">删除</el-button>
                </div>
            </trade-card>
            <trade-card title="明细信息">
                <avue-crud :option="optionContacts" :data="form.releaseBillList" v-model="formContacts"
                    @selection-change="selectionChange"></avue-crud>
            </trade-card>
        </div>
    </div>
</template>

<script>
import {
    getDetails,
    submit,
    releaseApplication,
    getListByType,
    getBvessels,
    getBports,
    getRunner,
    itemsRemove,
    application,
    revokeApplication,
    signcomplete,
    revokeSigncomplete,
    subsequentAvailability
} from "@/api/iosBasicData/release/releaseManagement";
import reportDialog from "@/components/report-dialog/main";
import { dateFormat } from "@/util/date";
import checkSchedule from "@/components/checkL/checkSchedule";
import check from "@/components/checkL/check";
// import commodityxsho from '../../configuration/commodityxsho.json'
import SearchQuery from "@/components/iosbasic-data/searchquery.vue";
import _ from "lodash";
export default {
    name: "detailsPage",

    data() {
        return {
            selectionList: [],
            runnerData: [],
            podData: [],
            polData: [],
            vesselData: [],
            carrierData: [],
            corpData: [],
            reportName: '轮胎商城-销售退货', // 打印传的名字
            SelectSearch: {}, // 添加商品检索
            // 编辑还是保存
            mingxibaocun: true,
            // 批次号请求到的数据
            picihaolist: [],
            // 添加商品弹窗
            dialogVisible: false,
            // 弹窗高度
            rowHeight: '',
            // 左侧选择搜索
            treeDataGoods: [],
            treeDeptId: '',
            page: {
                pageSize: 10,
                currentPage: 1,
                total: 0,
                pageSizes: [10, 50, 100, 300, 500]
            },
            // 表格需要的配置
            // optionTwo: commodityxsho,
            loading: false,
            // 商品列表数据合计
            goodsListShow: [],
            // 商品列表暂存
            goodsListSave: [],
            saveLoading: false,
            commodityData: false,
            surplusRouteQuantityOption: [],
            tableData: [],
            // tabs切换
            activeNameTabs: 'searchList',
            data: [],
            inventory: 0,
            isStatus: 1,
            goodsIdoptions: [],
            dataList: [],
            dicUrlWithCustomId: '',
            sharedCompanyId: 0,
            isAddBtn: true, // 添加商品的是否禁用
            isSaveBtn: false, // 大保存的是否禁用
            viewDisabled: false, // 大审批的是否禁用
            isAdd: false, // 表格按钮的是否点击
            editButton: false, // 大编辑大隐藏显示
            isEditButton: false, // 大编辑是否禁用
            goods: [],
            isDisabled: false, // 表格删除的是否禁用
            isDisabledTask: false, // 撤销任务和生成任务的是否禁用
            contactsOption: [],
            isContacts: false, // 表单的联系人是否禁用
            checkData: {},
            buttonText: '生成任务',  // 生成任务和撤销任务文本
            buttonColor: 'success', // 初始颜色为success  生成任务和撤销任务颜色状态
            checkScheduleDialog: false,  // 审批进度的弹窗开启关闭
            isApplySettlement: true,  // 申请退款的是否禁用
            isConfirmRefundBtn: true, // 确认退款的是否禁用
            isExamineBtn: true, // 审批是否禁用
            isRevocationRequest: true, // 撤销审核是否禁用
            checkDialog: false, // 审核弹窗的开启关闭
            checkId: '',
            batchNo: '',
            switchDialog: false, // 打印弹窗的开启和关闭
            activeName: "sale_detail",
            disabled: false, // 表格按钮的禁用
            key: 0,
            form: {
                createUser: JSON.parse(localStorage.getItem("saber-userInfo")) ? JSON.parse(localStorage.getItem("saber-userInfo")).content.user_id : null,
                createUserName: JSON.parse(localStorage.getItem("saber-userInfo")) ? JSON.parse(localStorage.getItem("saber-userInfo")).content.user_name : null,
                corpCnName: null,
                carrierCnName: null,
                vesselCnNam: null,
                polCnName: null,
                podCnName: null,
                runnerName: null,
                workType: 'RELEASE',
                businessType: 'SE',
                // issueStatus: 'N',
                isSwtich: 0,
                releaseBillList: []
            },
            customerData: [], // 客户数据
            optionForm: {
                menuBtn: false,
                span: 6,
                labelWidth: 120,
                disabled: false,
                column: [
                    {
                        label: '单据编号',
                        prop: "billNo",
                        disabled: true,
                        span: 5
                    },
                    {
                        label: '单据日期',
                        prop: "billDate",
                        disabled: true,
                        type: "datetime",
                        value: dateFormat(new Date(), 'yyyy-MM-dd hh:mm:ss'),
                        format: "yyyy-MM-dd HH:mm:ss",
                        valueFormat: "yyyy-MM-dd HH:mm:ss",
                        span: 5
                    },
                    {
                        label: "制单人",
                        prop: "createUserName",
                        disabled: true,
                        span: 5
                    },
                    {
                        label: '放单时间',
                        prop: "releaseTime",
                        type: "datetime",
                        format: "yyyy-MM-dd HH:mm",
                        valueFormat: "yyyy-MM-dd HH:mm",
                        span: 5
                    },
                    {
                        label: '工作类型',
                        prop: "workType",
                        type: "select",
                        disabled: true,
                        dicData: [{
                            id: "RELEASE",
                            name: "放单",
                        }],
                        props: {
                            label: "name",
                            value: "id",
                        },
                        span: 4
                    },
                    // {
                    //     label: '状态',
                    //     prop: "issueStatus",
                    //     type: "select",
                    //     disabled: true,
                    //     dicData: [{
                    //         id: 'N',
                    //         name: "新建",
                    //     }, {
                    //         id: 'S',
                    //         name: "提交",
                    //     }, {
                    //         id: 'I',
                    //         name: "跑单中",
                    //     }, {
                    //         id: 'O',
                    //         name: "操作确认",
                    //     }, {
                    //         id: 'D',
                    //         name: "调度确认",
                    //     }, {
                    //         id: 'T',
                    //         name: "放单",
                    //     }, {
                    //         id: 'B',
                    //         name: "退回",
                    //     }],
                    //     props: {
                    //         label: "name",
                    //         value: "id",
                    //     },
                    //     span: 4
                    // },
                    {
                        label: '客户',
                        prop: "corpCnName",
                        overHidden: true,
                        formslot: true,
                        rules: [{
                            required: true,
                            message: " ",
                            trigger: "blur"
                        }],
                        span: 6
                    },
                    {
                        label: '是否VIP',
                        prop: "vip",
                        type: 'select',
                        disabled: true,
                        filterable: true,
                        dicData: [{
                            label: '否',
                            value: 0
                        }, {
                            label: '是',
                            value: 1
                        }],
                        props: {
                            label: 'label',
                            value: 'value',
                        },
                        span: 6
                    },
                    {
                        label: '业务类型',
                        prop: "businessType",
                        type: "select",
                        dicData: [{
                            id: "SE",
                            name: "海运出口",
                        }, {
                            id: "SI",
                            name: "海运进口",
                        }],
                        props: {
                            label: "name",
                            value: "id",
                        },
                        rules: [{
                            required: true,
                            message: " ",
                            trigger: "blur"
                        }],
                        span: 6
                    },
                    {
                        label: '提单号',
                        prop: "mblno",
                    },
                    {
                        label: '信誉等级',
                        prop: "vipLevel",
                        type: 'select',
                        disabled: true,
                        filterable: true,
                        remote: true,
                        props: {
                            label: 'dictValue',
                            value: 'dictKey',
                            res: 'data'
                        },
                        dicUrl: '/api/blade-system/dict-biz/dictionary?code=bcorps-credit-level',
                        span: 6
                    },
                    {
                        label: '结算方式',
                        prop: "stlMode",
                        type: "select",
                        dicData: [{
                            id: 0,
                            name: "票结",
                        }, {
                            id: 1,
                            name: "月结",
                        }],
                        props: {
                            label: "name",
                            value: "id",
                        },
                        span: 6
                    },
                    {
                        label: '船公司',
                        prop: "carrierCnName",
                        overHidden: true,
                        formslot: true,
                        disabled: false,
                        span: 12
                        // type: 'select',
                        // filterable: true,
                        // remote: true,
                        // dicUrl: "/api/blade-los/bcorps/listByType?cnName={{key}}",
                        // props: {
                        //     label: 'cnName',
                        //     value: 'id',
                        //     res: 'data.records'
                        // },
                    },
                    {
                        label: '协议生效日期',
                        prop: "effectiveDate",
                        type: "datetime",
                        format: "yyyy-MM-dd HH:mm",
                        valueFormat: "yyyy-MM-dd HH:mm",
                        span: 6
                    },
                    {
                        label: '协议失效期限',
                        prop: "expiringDate",
                        type: "datetime",
                        format: "yyyy-MM-dd HH:mm",
                        valueFormat: "yyyy-MM-dd HH:mm",
                        span: 6
                    },
                    {
                        label: 'ETD开始日期',
                        prop: "dateFrom",
                        type: "datetime",
                        format: "yyyy-MM-dd",
                        valueFormat: "yyyy-MM-dd 00:00",
                        span: 4
                    },
                    {
                        label: 'ETD结束日期',
                        prop: "dateTo",
                        type: "datetime",
                        format: "yyyy-MM-dd",
                        valueFormat: "yyyy-MM-dd 23:59",
                        span: 6
                    },
                    {
                        label: 'RMB限额',
                        prop: "amountCny",
                        span: 6
                    },
                    {
                        label: 'USD限额',
                        prop: "amountUsd",
                        span: 6
                    },
                    {
                        label: '船名',
                        prop: "vesselCnName",
                        overHidden: true,
                        formslot: true,
                        disabled: false,
                        // type: 'select',
                        // filterable: true,
                        // remote: true,
                        // dicUrl: "/api/blade-los/bvessels/list?cnName={{key}}",
                        // props: {
                        //     label: 'cnName',
                        //     value: 'id',
                        //     res: 'data.records'
                        // },
                    },
                    {
                        label: '船次',
                        prop: "voyageNo",
                        span: 6
                    },
                    {
                        label: 'RMB未收',
                        prop: "unstlDrCny",
                        span: 6
                    },
                    {
                        label: 'USD未收',
                        prop: "unstlDrUsd",
                        span: 6
                    },
                    {
                        label: '起运港',
                        prop: "polCnName",
                        overHidden: true,
                        formslot: true,
                        disabled: false,
                        // type: 'select',
                        // filterable: true,
                        // remote: true,
                        // dicUrl: "/api/blade-los/bports/list?enName?cnName={{key}}",
                        // props: {
                        //     label: 'cnName',
                        //     value: 'id',
                        //     res: 'data.records'
                        // },
                    },
                    {
                        label: '目的港',
                        prop: "podCnName",
                        overHidden: true,
                        formslot: true,
                        disabled: false,
                        // filterable: true,
                        // remote: true,
                        // dicUrl: "/api/blade-los/bports/list?enName?cnName={{key}}",
                        // props: {
                        //     label: 'cnName',
                        //     value: 'id',
                        //     res: 'data.records'
                        // }
                    },
                    {
                        label: '限额合计',
                        prop: "amountTotal",
                        span: 6
                    },
                    {
                        label: '合计未收',
                        prop: "unstlDrTotal",
                        span: 6
                    },
                    {
                        label: '已生成账单未放单',
                        prop: "unplacedOrders",
                        type: 'select',
                        disabled: true,
                        filterable: true,
                        dicData: [{
                            label: '否',
                            value: 0
                        }, {
                            label: '是',
                            value: 1
                        }],
                        props: {
                            label: 'label',
                            value: 'value',
                        },
                        span: 6
                    },
                    {
                        label: '换签',
                        prop: "isSwtich",
                        type: 'select',
                        disabled: false,
                        filterable: true,
                        dicData: [{
                            label: '否',
                            value: 0
                        }, {
                            label: '是',
                            value: 1
                        }],
                        props: {
                            label: 'label',
                            value: 'value',
                        },
                    },
                    {
                        label: '协议编号',
                        prop: "agreementNo",
                        span: 6
                    },
                    {
                        label: '款已到账',
                        prop: "isAmountReceived",
                        type: 'select',
                        disabled: false,
                        filterable: true,
                        dicData: [{
                            label: '否',
                            value: 0
                        }, {
                            label: '是',
                            value: 1
                        }],
                        props: {
                            label: 'label',
                            value: 'value',
                        },
                    },
                    {
                        label: '单票限额',
                        prop: "limitAmountPerBill",
                        span: 6
                    },
                    {
                        label: '放单方式',
                        prop: "releaseType",
                        type: 'select',
                        disabled: false,
                        filterable: true,
                        dicData: [{
                            label: '自取',
                            value: 0
                        }, {
                            label: '送单',
                            value: 1
                        }, {
                            label: '寄送,',
                            value: 2
                        }],
                        props: {
                            label: 'label',
                            value: 'value',
                        },
                    },
                    {
                        label: '单票超额业务',
                        prop: "overLimitBills",
                        type: 'textarea',
                        disabled: false,
                        span: 12,
                        minRows: 2
                    },
                    {
                        label: '后续有货',
                        prop: "unreleaseBills",
                        type: 'textarea',
                        disabled: false,
                        span: 12,
                        minRows: 2
                    }]
            },
            formContacts: {},
            optionContacts: {
                disabled: false,
                border: true,
                align: 'center',
                index: true,
                refreshBtn: false,
                addBtn: false,
                // 航编辑开启
                cellBtn: true,
                span: 8,
                height: 500,
                addRowBtn: false,
                editBtn: false,
                delBtn: false,
                menuWidth: 120,
                menu: false,
                tip: false,
                showSummary: true,
                selection: true,
                column: [
                    {
                        label: '放单信息',
                        overHidden: true,
                        disabled: false,
                        children: [{
                            label: '业务编号',
                            prop: 'billNo',
                            overHidden: true,
                            display: false
                        }, {
                            label: 'MBL NO',
                            prop: 'mblno',
                            overHidden: true,
                            display: false
                        }, {
                            label: 'HBL NO',
                            prop: 'hblno',
                            overHidden: true,
                            display: false
                        },
                        {
                            label: '提单份数',
                            prop: 'numberOfObl',
                            overHidden: true,
                            display: false
                        }, {
                            label: '签单',
                            prop: '',
                            overHidden: true,
                            display: false
                        }, {
                            label: '放单',
                            prop: '',
                            overHidden: true,
                            display: false
                        }]
                    },
                    {
                        label: '有船公司账单',
                        prop: '',
                        width: 160,
                        disabled: false,
                        remote: true,
                        overHidden: true,
                    },
                    {
                        label: '产生账单',
                        prop: 'isAccbill',
                        width: 120,
                        disabled: false,
                        remote: true,
                        overHidden: true,
                        dicData: [{
                            label: '否',
                            value: 0
                        }, {
                            label: '是',
                            value: 1
                        }],
                    },
                    {
                        label: 'RMB',
                        overHidden: true,
                        disabled: false,
                        children: [{
                            label: '应收',
                            prop: 'amountDrCny',
                            overHidden: true,
                            display: false
                        }, {
                            label: '签收',
                            prop: 'signForCny',
                            overHidden: true,
                            display: false
                        }, {
                            label: '未收',
                            prop: 'unstlDrCny',
                            overHidden: true,
                            display: false
                        }]
                    },
                    {
                        label: 'USD',
                        overHidden: true,
                        disabled: false,
                        children: [{
                            label: '应收',
                            prop: 'amountDrUsd',
                            overHidden: true,
                            display: false
                        }, {
                            label: '签收',
                            prop: 'signForUsd',
                            overHidden: true,
                            display: false
                        }, {
                            label: '未收',
                            prop: 'unstlDrUsd',
                            overHidden: true,
                            display: false
                        }]
                    },
                    {
                        label: '合计',
                        overHidden: true,
                        disabled: false,
                        children: [{
                            label: '应收',
                            prop: 'amountDrTotal',
                            overHidden: true,
                            display: false
                        }, {
                            label: '未收',
                            prop: 'unstlDrTotal',
                            overHidden: true,
                            display: false
                        }]
                    },
                    // {
                    //     label: '发票号*',
                    //     prop: '',
                    //     disabled: false,
                    //     remote: true,
                    //     overHidden: true,
                    // },
                    {
                        label: '单票超额费用',
                        overHidden: true,
                        disabled: false,
                        children: [{
                            label: '是否',
                            prop: 'isOverLimit',
                            overHidden: true,
                            display: false,
                            dicData: [{
                            label: '否',
                            value: 0
                        }, {
                            label: '是',
                            value: 1
                        }],
                        }, {
                            label: '金额',
                            prop: 'overAmountDr',
                            overHidden: true,
                            display: false
                        }]
                    },
                    {
                        label: '业务信息',
                        overHidden: true,
                        disabled: false,
                        children: [
                            {
                                label: '客户简称',
                                prop: 'corpCnName',
                                overHidden: true,
                            }, {
                                label: '船公司',
                                prop: 'carrierCnName',
                                overHidden: true,
                                display: false
                            }, {
                                label: 'ETD',
                                prop: 'etd',
                                overHidden: true,
                                display: false
                            }, {
                                label: 'VSL',
                                prop: 'vesselCnName',
                                overHidden: true,
                                display: false
                            }, {
                                label: 'VOY',
                                prop: 'voyageNo',
                                overHidden: true,
                                display: false
                            }]
                    },
                    {
                        label: '备注',
                        prop: 'remarks',
                        width: 100,
                        disabled: false,
                        remote: true,
                        overHidden: true,
                    },
                    {
                        label: '签单信息',
                        overHidden: true,
                        disabled: false,
                        children: [{
                            label: '要求时间',
                            prop: 'requireTime',
                            overHidden: true,
                            display: false
                        }, {
                            label: '完成时间',
                            prop: 'releaseTime',
                            overHidden: true,
                            display: false
                        }, {
                            label: '紧急程度',
                            prop: 'itemLevel',
                            overHidden: true,
                            width: 120,
                            dicData: [{
                                label: '普通',
                                value: 0
                            }, {
                                label: '一级',
                                value: 1
                            }, {
                                label: '二级',
                                value: 2
                            }, {
                                label: '三级',
                                value: 3
                            }],
                        }]
                    },
                    {
                        label: '换签次数',
                        prop: 'swtichCount',
                        width: 100,
                        disabled: false,
                        remote: true,
                        overHidden: true,
                    },
                    {
                        label: '换签原因',
                        prop: 'swtichReason',
                        width: 100,
                        disabled: false,
                        remote: true,
                        overHidden: true,
                    },
                    {
                        label: '单据类型',
                        prop: 'billType',
                        width: 100,
                        disabled: false,
                        remote: true,
                        overHidden: true,
                        dicData: [{
                            label: '直单',
                            value: 'DD'
                        }, {
                            label: '主单',
                            value: 'MM'
                        }, {
                            label: '主分单',
                            value: 'MH'
                        }, {
                            label: '从分单',
                            value: 'HH'
                        }],
                    },


                ]
            },
            selectionMultilist: [], // 多选数据
        }
    },
    components: { SearchQuery, reportDialog, check, checkSchedule },
    props: {
        onLoad: Object,
        detailData: Object
    },
    async created() {
        if (this.detailData.id) {
            this.editButton = true
            this.optionForm.disabled = true
            this.getDetail(this.detailData.id)
        }
    },
    methods: {
        selectionChange(list) {
            this.selectionList = list
        },
        selectChange(val, name) {
            console.log(val, name)
            if (val) {
                if (name == 'corpCnName') {
                    this.corpData.forEach(e => {
                        if (e.cnName == val) {
                            this.form.corpId = e.id
                            this.form.corpCnName = e.cnName
                            this.form.corpEnName = e.enName
                            this.form.vip = e.vip
                            this.form.vipLevel = e.creditLevel
                        }
                    })
                }
                if (name == 'carrierCnName') {
                    this.carrierData.forEach(e => {
                        if (e.cnName == val) {
                            this.form.carrierId = e.id
                            this.form.carrierCnName = e.cnName
                            this.form.carrierEnName = e.enName
                        }
                    })
                }
                if (name == 'vesselCnName') {
                    this.vesselData.forEach(e => {
                        if (e.cnName == val) {
                            this.form.vesselId = e.id
                            this.form.vesselCnName = e.cnName
                            this.form.vesselEnName = e.enName
                        }
                    })
                }
                if (name == 'polCnName') {
                    this.polData.forEach(e => {
                        if (e.cnName == val) {
                            this.form.polId = e.id
                            this.form.polCnName = e.cnName
                            this.form.polEnName = e.enName
                        }
                    })
                }
                if (name == 'podCnName') {
                    this.podData.forEach(e => {
                        if (e.cnName == val) {
                            this.form.podId = e.id
                            this.form.podCnName = e.cnName
                            this.form.podEnName = e.enName
                        }
                    })
                }
                if (name == 'runnerName') {
                    this.runnerData.forEach(e => {
                        if (e.name == val) {
                            this.form.runnerId = e.id
                            this.form.runnerName = e.name

                        }
                    })
                }
            } else {
                if (name == 'corpCnName') {
                    this.form.corpId = null
                    this.form.corpCnName = null
                    this.form.corpEnName = null
                    this.form.vip = null
                    this.form.vipLevel = null
                }
                if (name == 'carrierCnName') {
                    this.form.carrierId = null
                    this.form.carrierCnName = null
                    this.form.carrierEnName = null
                }
                if (name == 'vesselCnName') {
                    this.form.vesselId = null
                    this.form.vesselCnName = null
                    this.form.vesselEnName = null
                }
                if (name == 'polCnName') {
                    this.form.polId = null
                    this.form.polCnName = null
                    this.form.polEnName = null
                }
                if (name == 'podCnName') {
                    this.form.podId = null
                    this.form.podCnName = null
                    this.form.podEnName = null
                }
                if (name == 'runnerName') {
                    this.form.runnerId = null
                    this.form.runnerName = null
                }
            }

        },
        getRemote(val, name) {
            if (name == 'corpCnName') {
                getListByType({ current: 1, size: 10, cnName: val ? val : null }).then(res => {
                    this.corpData = res.data.data.records
                })
            }
            if (name == 'carrierCnName') {
                getListByType({ current: 1, size: 10, cnName: val ? val : null }).then(res => {
                    this.carrierData = res.data.data.records
                })
            }
            if (name == 'vesselCnName') {
                getBvessels({ current: 1, size: 10, cnName: val ? val : null }).then(res => {
                    this.vesselData = res.data.data.records
                })
            }
            if (name == 'polCnName') {
                getBports({ current: 1, size: 10, cnName: val ? val : null }).then(res => {
                    this.polData = res.data.data.records
                })
            }
            if (name == 'podCnName') {
                getBports({ current: 1, size: 10, cnName: val ? val : null }).then(res => {
                    this.podData = res.data.data.records
                })
            }
            if (name == 'runnerName') {
                getRunner({ roles: '跑单员', name: val ? val : null }).then(res => {
                    this.runnerData = res.data.data
                })
            }
        },
        queryDetails() {
            this.$refs["form"].validate((valid, done) => {
                done();
                if (valid) {
                    const loading = this.$loading({
                        lock: true,
                        text: '加载中',
                        spinner: 'el-icon-loading',
                        background: 'rgba(255,255,255,0.7)'
                    });
                    let obj = {}
                    this.form.releaseBillList = []
                    if (this.form.businessType == 'SE') {
                        obj = {
                            businessType: this.form.businessType,
                            mblno: this.form.mblno,
                            carrierId: this.form.carrierId,
                            vesselId: this.form.vesselId,
                            voyageNo: this.form.voyageNo,
                            polId: this.form.polId,
                            podId: this.form.podId,
                            corpId: this.form.corpId,
                            bookingNo: this.form.bookingNo,
                            dateFrom: this.form.dateFrom,
                            dateTo: this.form.dateTo,
                            isSwtich: this.form.isSwtich
                        }
                    } else if (this.form.businessType == 'SI') {
                        obj = {
                            businessType: this.form.businessType,
                            mblno: this.form.mblno,
                            carrierId: this.form.carrierId,
                            vesselId: this.form.vesselId,
                            voyageNo: this.form.voyageNo,
                            polId: this.form.polId,
                            podId: this.form.podId,
                            corpId: this.form.corpId,
                            bookingNo: this.form.bookingNo,
                            dateFrom: this.form.dateFrom,
                            dateTo: this.form.dateTo,
                            isSwtich: this.form.isSwtich
                        }
                    }

                    releaseApplication(obj).then(res => {
                        this.form.releaseBillList = res.data.data
                        this.$message.success("查询成功");
                    }).finally(() => {
                        loading.close();
                    });
                } else {
                    return false;
                }
            });
        },
        reset() {
            this.form = this.$options.data().form
        },
        del() {
            if (this.form.id) {
                let ids = []
                this.selectionList.forEach(e => {
                    ids.push(e.id)
                })
                console.log(ids.join(','))
                itemsRemove({ ids: ids.join(',') }).then(res => {
                    this.form.releaseBillList = this.form.releaseBillList.filter(e => !this.selectionList.includes(e))
                    this.selectionList = []
                    this.$message.success("删除成功");
                })
            } else {
                this.form.releaseBillList = this.form.releaseBillList.filter(e => !this.selectionList.includes(e))
                this.selectionList = []
                this.$message.success("删除成功");
            }
        },
        //表头编辑
        inEdit() {
            this.editButton = false
            this.optionForm.disabled = false
        },
        subsequentAb() {
            this.$confirm('是否继续操作?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                subsequentAvailability(this.form).then(res => {
                    if (Object.keys(res.data.data).length) {
                        this.form.unreleaseBills = '票数:' + res.data.data.number + '\n' + res.data.data.text
                    }
                })
            }).catch(() => {
            });

        },
        //修改提交触发
        submit() {
            this.$refs["form"].validate((valid, done) => {
                done();
                if (valid) {
                    const loading = this.$loading({
                        lock: true,
                        text: '加载中',
                        spinner: 'el-icon-loading',
                        background: 'rgba(255,255,255,0.7)'
                    });
                    let obj = {}
                    let val = 0
                    val = this.form.releaseBillList.filter(e => e.preleaseId)
                    if (val.length > 0) {
                        obj = {
                            billNoFormat: 'FD',
                            businessTypeCode: 'FD',
                            ...this.form,
                            billType: "R"
                        }
                        submit(obj).then(res => {
                            this.form = res.data.data
                            this.$message.success("保存成功");
                            this.editButton = true;
                            this.optionForm.disabled = true
                        }).finally(() => {
                            loading.close();
                        });
                    } else {
                        if (this.selectionList.length > 0) {
                            if (this.selectionList.length > 0) {
                                this.form.releaseBillList = this.selectionList
                                obj = {
                                    billNoFormat: 'FD',
                                    businessTypeCode: 'FD',
                                    ...this.form,
                                    billType: "R"
                                }
                                submit(obj).then(res => {
                                    this.form = res.data.data
                                    this.$message.success("保存成功");
                                    this.editButton = true;
                                    this.optionForm.disabled = true
                                }).finally(() => {
                                    loading.close();
                                });
                            } else {
                                loading.close();
                                this.$message.error("请选择明细");
                            }
                        } else {
                            obj = {
                                billNoFormat: 'FD',
                                businessTypeCode: 'FD',
                                ...this.form,
                                billType: "R"
                            }
                            submit(obj).then(res => {
                                this.form = res.data.data
                                this.$message.success("保存成功");
                            }).finally(() => {
                                loading.close();
                            });
                        }

                    }
                } else {
                    return false;
                }
            });
        },
        subApplication() {
            this.$refs["form"].validate((valid, done) => {
                done();
                if (valid) {
                    const loading = this.$loading({
                        lock: true,
                        text: '加载中',
                        spinner: 'el-icon-loading',
                        background: 'rgba(255,255,255,0.7)'
                    });
                    application(this.form).then(res => {
                        this.form = res.data.data
                        this.$message.success("提交成功");
                        this.editButton = true;
                        this.optionForm.disabled = true
                        this.getDetail(this.form.id)
                    }).finally(() => {
                        loading.close();
                    });
                } else {
                    return false;
                }
            });
        },
        revokeApp() {
            this.$refs["form"].validate((valid, done) => {
                done();
                if (valid) {
                    const loading = this.$loading({
                        lock: true,
                        text: '加载中',
                        spinner: 'el-icon-loading',
                        background: 'rgba(255,255,255,0.7)'
                    });
                    revokeApplication(this.form).then(res => {
                        this.form = res.data.data
                        this.$message.success("撤销成功");
                        this.getDetail(this.form.id)
                    }).finally(() => {
                        loading.close();
                    });
                } else {
                    return false;
                }
            });
        },
        submitSign() {
            this.$refs["form"].validate((valid, done) => {
                done();
                if (valid) {
                    const loading = this.$loading({
                        lock: true,
                        text: '加载中',
                        spinner: 'el-icon-loading',
                        background: 'rgba(255,255,255,0.7)'
                    });
                    signcomplete(this.form).then(res => {
                        this.form = res.data.data
                        this.$message.success("签单成功");
                        this.getDetail(this.form.id)
                    }).finally(() => {
                        loading.close();
                    });
                } else {
                    return false;
                }
            });
        },
        revokeSign() {
            this.$refs["form"].validate((valid, done) => {
                done();
                if (valid) {
                    const loading = this.$loading({
                        lock: true,
                        text: '加载中',
                        spinner: 'el-icon-loading',
                        background: 'rgba(255,255,255,0.7)'
                    });
                    revokeSigncomplete(this.form).then(res => {
                        this.form = res.data.data
                        this.$message.success("取消成功");
                        this.getDetail(this.form.id)
                    }).finally(() => {
                        loading.close();
                    });
                } else {
                    return false;
                }
            });
        },
        getDetail(id, type) {
            const loading = this.$loading({
                lock: true,
                text: '加载中',
                spinner: 'el-icon-loading',
                background: 'rgba(255,255,255,0.7)'
            })
            getDetails({ id: id }).then(res => {
                this.form = res.data.data
                loading.close();
            }).catch(() => {
                loading.close();
            })
        },
        //自定义列保存
        async saveColumnTwo(ref, option, optionBack, code) {
            /**
             * 已定义全局方法，直接使用，saveColumnData保存列数据方法,参数传值(表格名称，当前表格的option数据)
             * 已定义全局方法，直接使用，getColumnName方法用来获取枚举值，参数根据自己定义的code值获取中文名
             * 一定要执行异步操作，要等接口成功返回，才能执行下一行代码
             */
            const inSave = await this.saveColumnData(this.getColumnName(code), this[option]);
            if (inSave) {
                this.$message.success("保存成功");
                //关闭窗口
                this.$refs[ref].$refs.dialogColumn.columnBox = false;
            }
        },
        //自定义列重置
        async resetColumnTwo(ref, option, optionBack, code) {
            this[option] = this[optionBack];
            const inSave = await this.delColumnData(this.getColumnName(code), this[optionBack]);
            if (inSave) {
                this.$message.success("重置成功");
                this.$refs[ref].$refs.dialogColumn.columnBox = false;
            }
        },
        backToList(type) {
            this.$emit("backToList", type);
        },

        // 弹框的重置
        resetCrud() {
            this.$message.success("重置成功");
        },
        // 弹窗的保存
        saveCrud() {
            this.$message.success("保存成功");
        }
    }
}
</script>

<style lang="scss" scoped>
::v-deep .el-form-item {
    margin-bottom: 8px !important;
}
</style>
