<template>
    <!--<div class="app-container">-->
    <div>
        <div>
            <el-row class="row-bg">
                <el-col :span="24">
                    <div class="grid-content content">航班信息</div>
                </el-col>
                <el-col :span="24">
                    <div class="grid-content co">
                        <el-col :span="1">
                            <div class="grid-content"></div>
                        </el-col>
                        <el-col :span="20">
                            <div class="grid-content">
                                <span class="titleSpan">航班号:{{this.loadingQuery.carrier}}{{this.loadingQuery.flightno}}</span>
                                <span class="titleSpan">航班日期:{{this.loadingQuery.flightdate}}</span>
                                <span class="titleSpan">航段:{{this.loadingQuery.originstation}}-{{this.loadingQuery.destinationstation}}</span>
                            </div>
                        </el-col>
                    </div>
                </el-col>
                <el-col :span="24">
                    <div class="grid-content content">出港装载查询</div>
                </el-col>
                <el-col :span="24">
                    <div class="grid-content co">
                        <el-col :span="1">
                            <div class="grid-content"></div>
                        </el-col>
                        <el-col :span="22">
                            <div class="grid-content">
                                <el-col :span="4">
                                    <div class="grid-content">
                                        <el-input clearable v-model="loadingQuery.awba" placeholder="请输入主单号">
                                            <template slot="prepend">主单号</template>
                                        </el-input>
                                    </div>
                                </el-col>
                                <div class="el-btn">
                                    <el-button type="primary" icon="el-icon-search" size="mini" @click="handleSearch">查&emsp;&emsp;询</el-button>
                                    <el-button v-if="loadingQuery.flightno === undefined && loadingData.length <1"
                                               type="success" icon="el-icon-plus" size="mini" @click="handleAddLoading">新增装载
                                    </el-button>
                                </div>
                            </div>
                        </el-col>
                    </div>
                </el-col>
                <el-col :span="24">
                    <div class="grid-content content" style="margin-top: 6px">出港装载明细</div>
                </el-col>
            </el-row>
            <el-table v-loading="listLoading" :data="loadingData" stripe style="font-size: 12px"
                      border @selection-change="handleSelectionChange">
                <el-table-column type="selection" width="60"></el-table-column>
                <el-table-column label="主单号" width="160" align="center">
                    <template slot-scope="scope">
                        <a type="text" style="color: #409eff;text-decoration: underline" class="tableInline" @click="handleEdit(scope.row)">{{scope.row.awba}}</a>
                    </template>
                </el-table-column>
                <el-table-column label="航班号" width="100" align="center">
                    <template slot-scope="scope">
                        <span>{{scope.row.carrier}}{{scope.row.flightno}}</span>
                    </template>
                </el-table-column>
                <el-table-column label="航班日期" width="130" align="center">
                    <template slot-scope="scope">
                        <span>{{scope.row.flightdate}}</span>
                    </template>
                </el-table-column>
                <el-table-column label="运载件数" width="70" align="center">
                    <template slot-scope="scope">
                        <span>{{scope.row.lodingpiece}}</span>
                    </template>
                </el-table-column>
                <el-table-column label="运载重量" width="70" align="center">
                    <template slot-scope="scope">
                        <span>{{scope.row.lodingweight}}</span>
                    </template>
                </el-table-column>
                <el-table-column label="货物描述" width="120" align="center" show-overflow-tooltip>
                    <template slot-scope="scope">
                        <span>{{scope.row.goodsname}}</span>
                    </template>
                </el-table-column>
                <el-table-column label="装载时间" width="150" align="center">
                    <template slot-scope="scope">
                        <span>{{scope.row.loadingtime}}</span>
                    </template>
                </el-table-column>
                <el-table-column label="状态" width="200" align="center">
                    <template slot-scope="scope">
                        <span v-if="scope.row.status ==='01'">接受申报</span>
                        <span v-if="scope.row.status ==='02'">待人工审核</span>
                        <span v-if="scope.row.status ==='03'">退单</span>
                        <span v-if="scope.row.status ==='05'">舱单报退单</span>
                        <span v-if="scope.row.status ==='06'">舱单转人工</span>
                        <span v-if="scope.row.status ==='07'">舱单报申报成功</span>
                        <span v-if="scope.row.status ==='08'">已发舱单删除报</span>
                        <span v-if="scope.row.status ==='09'">舱单删除报退单</span>
                        <span v-if="scope.row.status ==='10'">舱单删除报转人工</span>
                        <span v-if="scope.row.status ==='11'">放行</span>
                        <span v-if="scope.row.status ==='12'">拒装</span>
                        <span v-if="scope.row.status ==='13'">禁卸</span>
                        <span v-if="scope.row.status ==='14'">舱单修改报转人工</span>
                        <span v-if="scope.row.status ==='15'">舱单修改报成功</span>
                        <span v-if="scope.row.status ==='16'">海关已存在</span>
                        <span v-if="scope.row.status ==='21'">可自动发送</span>
                        <span v-if="scope.row.status ==='22'">未发送</span>
                        <span v-if="scope.row.status ==='23'">已发送新增报</span>
                        <span v-if="scope.row.status ==='24'">已发送删除报</span>
                        <span v-if="scope.row.status ==='25'">已发送修改报</span>
                    </template>
                </el-table-column>
                <el-table-column label="回执信息" width="220" align="center" show-overflow-tooltip>
                    <template slot-scope="scope">
                        <el-tag v-if="scope.row.status=='01' || scope.row.status=='11'" type="success">
                            {{scope.row.ext5}}
                        </el-tag>
                        <el-tag v-else-if="scope.row.status=='02' || scope.row.status=='03'" type="warning">
                            {{scope.row.ext5}}
                        </el-tag>
                        <el-tag v-else-if="scope.row.status=='12' || scope.row.status=='13'" type="danger">
                            {{scope.row.ext5}}
                        </el-tag>
                        <el-tag v-else>
                            {{scope.row.ext5}}
                        </el-tag>
                    </template>
                </el-table-column>
                <el-table-column label="操作" align="center" width="330px" fixed="right">
                    <template slot-scope="scope">
                        <el-row type="flex" justify="space-between">
                            <el-button size="mini" icon="el-icon-view" @click="handleSend(scope.row)">收发明细</el-button>
                            <el-button size="mini" icon="el-icon-edit" type="warning" @click="handleAwbStatus(scope.row)"
                                       :disabled="scope.row.status ==='22'">更改状态
                            </el-button>
                            <el-button size="mini" icon="el-icon-delete" type="danger" v-if="isAdmin" @click="handleAwbDelete(scope.row)">删除运单
                            </el-button>
                        </el-row>
                        <el-row type="flex" justify="space-between">
                            <el-button size="mini" type="primary" icon="el-icon-plus" @click="handleSendAwb(scope.row)"
                                       :disabled="scope.row.status ==='23'">装载申报
                            </el-button>
                            <el-button size="mini" icon="el-icon-delete" type="danger" @click="handleSendDelete(scope.row)"
                                       :disabled="scope.row.status ==='24'">删除申报
                            </el-button>
                        </el-row>
                    </template>
                </el-table-column>
            </el-table>
            <div class="btnFoot">
                <el-row>
                    <el-button type="success" icon="el-icon-plus" size="mini"
                               v-if="loadingQuery.flightno !== undefined || loadingData.length >0"
                               @click="handelAddLoadingInfo">新增装载
                    </el-button>
                    <el-button type="primary" icon="el-icon-back" size="mini"
                               v-if="loadingQuery.flightno !== undefined || loadingData.length>0"
                               @click="handelBackStep">返&emsp;&emsp;回
                    </el-button>
                </el-row>
            </div>
            <pagination v-show="total>0" :total="total" :page.sync="loadingQuery.pageSize" :limit.sync="loadingQuery.limitSize"
                        @pagination="getList"/>

            <el-dialog :title="dialogMap[dialogStatus]" :visible.sync="dialogFormVisible">
                <el-form ref="loadingFormData" :model="loadingModel" :rules="loadingRoles" label-position="right"
                         label-width="90px">
                    <div class="grid-content content">
                        <span>航班信息</span>
                    </div>
                    <el-row>
                        <el-col :span="7.5">
                            <el-form-item label="主单号" prop="awba">
                                <el-input v-model="loadingModel.awba" :disabled="dialogStatus ==='update'"></el-input>
                            </el-form-item>
                        </el-col>
<!--                        <el-col :span="7.5">-->
<!--                            <el-form-item label="承运人" prop="carrier">-->
<!--                                <el-input v-model="carrier" :disabled="dialogStatus ==='update'"></el-input>-->
<!--                            </el-form-item>-->
<!--                        </el-col>-->
                        <el-col :span="7.5">
                            <el-form-item label="航班号" prop="flightno">
                                <el-input v-model="flightno" :disabled="dialogStatus ==='update'"></el-input>
                            </el-form-item>
                        </el-col>

                    </el-row>
                    <el-row>

                        <el-col :span="7.5">
                            <el-form-item label="起始站" prop="originstation">
                                <el-select filterable clearable placeholder="请选择起始站" :remote-method="remoteMethodAirport"
                                           allow-create v-model="originstation" remote :disabled="dialogStatus ==='update'">
                                    <el-option v-for="item in airportCode"
                                               :key="item.airportid" :label="item.airportid"
                                               :value="item.airportid" :disabled="dialogStatus === 'update'">
                                        <span style="float: left">{{ item.airportdescchn }}</span>
                                        <span style="float: right; color: #8492a6; font-size: 13px">{{ item.airportid }}</span>
                                    </el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="7.5">
                            <el-form-item label="目的站" prop="destinationstation">
                                <el-select filterable clearable placeholder="请选择起始站" :remote-method="remoteMethodAirport"
                                           allow-create v-model="destinationstation" remote :disabled="dialogStatus ==='update'">
                                    <el-option v-for="item in airportCode"
                                               :key="item.airportid" :label="item.airportid"
                                               :value="item.airportid" :disabled="dialogStatus === 'update'">
                                        <span style="float: left">{{ item.airportdescchn }}</span>
                                        <span style="float: right; color: #8492a6; font-size: 13px">{{ item.airportid }}</span>
                                    </el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="7.5">
                            <el-form-item label="航班日期" prop="flightdate">
                                <el-date-picker v-model="loadingModel.flightdate" value-format="yyyy-MM-dd" type="date"
                                                placeholder="请输入" :disabled="dialogStatus ==='update'"></el-date-picker>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <div class="grid-content content">
                        <span>货物信息</span>
                    </div>
                    <el-row>
                        <el-col :span="7.5">
                            <el-form-item label="装载件数" prop="lodingpiece">
                                <el-input v-model.number="loadingModel.lodingpiece"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="7.5">
                            <el-form-item label="装载重量" prop="lodingweight">
                                <el-input v-model="loadingModel.lodingweight"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="7.5">
                            <el-form-item label="装载时间" prop="loadingtime">
                                <el-date-picker v-model="loadingModel.loadingtime" value-format="yyyy-MM-dd HH:mm:ss"
                                                type="datetime"
                                                placeholder="请输入"></el-date-picker>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="7.5">
                            <el-form-item label="运单件数" prop="awbprice">
                                <el-input v-model.number="loadingModel.awbprice"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="7.5">
                            <el-form-item label="运单重量" prop="awbweight">
                                <el-input v-model="loadingModel.awbweight"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="7.5">
                            <el-form-item label="海关关区" prop="customcode">
                                <el-select v-model="loadingModel.customcode"  placeholder="请选择关区代码"
                                           filterable clearable remote :remote-method="remoteMethodCustomCode" :loading="customLoading"
                                           allow-create
                                           default-first-option>
                                    <el-option v-for="item in customCodeList" :key="item.customcode" :label="item.customcode"
                                               :value="item.customcode">
                                        <span style="float: left">{{ item.customcode }}</span>
                                        <span style="float: right; color: #8492a6; font-size: 13px">{{ item.customname }}</span>
                                    </el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="7.5">
                            <el-form-item label="特货代码" prop="specialgoods">
                                <el-input v-model="loadingModel.specialgoods"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="7.5">
                            <el-form-item label="货物描述" prop="goodsname">
                                <el-input v-model="goodsname" placeholder="请输入"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-form>
                <div slot="footer" class="dialog-footer">
                    <el-button @click="dialogFormVisible = false">取消</el-button>
                    <el-button type="primary" @click="dialogStatus==='create'?createData():updateData()">保存</el-button>
                </div>
            </el-dialog>
            <el-dialog title="收发明细" :visible.sync="dialogTableVisible">
                <el-table :data="detailData" border>
                    <el-table-column label="操作时间" width="180">
                        <template slot-scope="scope">
                            {{scope.row.busdate}}
                        </template>
                    </el-table-column>
                    <el-table-column label="航班号" width="80">
                        <template slot-scope="scope">
                            {{scope.row.carrier}}{{scope.row.flightno}}
                        </template>
                    </el-table-column>
                    <el-table-column label="航班日期" width="100">
                        <template slot-scope="scope">
                            {{scope.row.flightdate}}
                        </template>
                    </el-table-column>
                    <el-table-column label="件数" width="70">
                        <template slot-scope="scope">
                            {{scope.row.buspiece}}
                        </template>
                    </el-table-column>
                    <el-table-column label="重量" width="70">
                        <template slot-scope="scope">
                            {{scope.row.busweight}}
                        </template>
                    </el-table-column>
                    <el-table-column label="回执信息" width="">
                        <template slot-scope="scope">
                            {{scope.row.cusrestext}}
                        </template>
                    </el-table-column>
                    <el-table-column label="操作类型" width="100">
                        <template slot-scope="scope">
                            {{scope.row.opertype}}
                        </template>
                    </el-table-column>
                    <el-table-column label="操作人" width="100">
                        <template slot-scope="scope">
                            {{scope.row.operusername}}
                        </template>
                    </el-table-column>
                </el-table>
            </el-dialog>
            <el-dialog title="删除原因" :visible.sync="dialogDeleteVisible" width="50%">
<!--                <div style="">-->
<!--                    <el-button type="success" @click="historyList()">选择历史消息</el-button>-->
<!--                </div>-->
                <el-form ref="loadingDeleteForm" :model="respModel" :rules="loadingDeleteRules"
                         label-width="120px" style="margin-right: 50px">
                    <el-form-item label="删除原因" prop="reason">
                        <el-input v-model="respModel.reason" placeholder="删除原因"></el-input>
                    </el-form-item>
                    <el-form-item label="删除操作人" prop="contactName">
                        <el-input v-model="respModel.contactName" placeholder="操作人姓名"></el-input>
                    </el-form-item>
                    <el-form-item label="操作人Tel" prop="contactTel">
                        <el-input v-model="respModel.contactTel" placeholder="删除操作人联系方式"></el-input>
                    </el-form-item>
                    <el-form-item label="备注">
                        <el-input v-model="respModel.content" type="textarea"></el-input>
                    </el-form-item>
                </el-form>
                <div slot="footer" class="dialog-footer">
                    <el-button @click="dialogDeleteVisible = false">取消</el-button>
                    <el-button type="primary" @click="sendLoadingDelete()">发送</el-button>
                </div>
            </el-dialog>
            <el-dialog title="历史信息" :visible.sync="historyDialog" width="50%">
                <el-table v-loading="listLoading" :data="historyData" stripe style="font-size: 12px"
                          border >

                        <el-table-column prop="operperson" label="删除原因" />
                        <el-table-column prop="operreason" label="删除操作人" />
                        <el-table-column prop="opertel" label="操作人Tel"/>
                    <el-table-column label="操作">
                    <template slot-scope="scope">
                        <el-button type="success" @click="historyEcho(scope.row)">选择</el-button>
                    </template>
                    </el-table-column>
                </el-table>
                <pagination background layout="total, prev, pager, next" v-show="historyTotal>0" :total="historyTotal" :page.sync="historyQuery.pageSize" :limit.sync="historyQuery.limitSize"
                            @pagination="historyList()"/>
            </el-dialog>

        </div>
    </div>
</template>
<script>
    import Pagination from '@/components/Pagination'
    import {getCustomCode,getAirportCode} from "@/api/country";
    import {
        getMt4201ListForParam, deleteByIsDelete, updateStatus,
        updateMT4201, addMt4201, sendCreateMt4201, sendDeleteMt4201, test
    } from '@/api/exitLoading'
    import {getHistoryList} from '@/api/history/history';
    import {Message} from "element-ui"
    import {loginedUserInfo} from "../../api/user";
    import {
        validAwb,
        validAlphabets,
        validAlphabetsAndNum,
        validAlphabetsAndSpanceKey,
        validatorNum,
        validatorCustomsNum
    } from "@/utils/validate"
    import {getResponseForParam} from '@/api/responseDetail'
    export default {
        name: "ExitLoading",
        components: { Pagination},
        inject: ['reload'],
        data() {
            const validatorAwb = (rule, value, callback) => {
                if (!validAwb(value)) {
                    callback("请正确书写主单号格式为xxx-xxxxxxxx")
                }
                callback()
            }
            const validatorAwbh = (rule, value, callback) => {
                if (!validAlphabetsAndNum(value)) {
                    callback("只能输入字母和数字")
                }
                callback()
            }
            const validatorAlphabets = (rule, value, callback) => {
                if (!validAlphabets(value)) {
                    callback("只能输入字母")
                }
                callback()
            }
            const validAlphabetsSpanceKey = (rule, value, callback) => {
                if (!validAlphabetsAndSpanceKey(value)) {
                    callback("只能输入字母、数字、空格")
                }
                callback()
            }
            const validatorNums = (rule, value, callback) => {
                if (!validatorNum(value)) {
                    callback("只能输入数字,并且小数位最多两位")
                }
                callback()
            }
            const validatorCustomsNums = (rule, value, callback) => {
                if (!validatorCustomsNum(value)) {
                    callback(new Error("只能输入4位数字"))
                }
                callback()
            }
            return {
                total: 0,
                historyTotal: 0,
                isAdmin: false,
                dialogMap: {
                    update: '编辑出港装载',
                    create: '添加出港装载',
                },
                customCodeList: [],
                airportCode:[],
                historyData: [],
                dialogStatus: undefined,
                dialogTableVisible: false,
                dialogFormVisible: false,
                dialogDeleteVisible: false,
                historyDialog: false,
                customLoading: false,
                listLoading: false,
                loadingQuery: {
                    pageSize: 1,
                    limitSize: 10,
                    awba: undefined,
                    carrier: undefined,
                    flightno: undefined,
                    flightdate: undefined,
                    originstation: undefined,
                    destinationstation: undefined,
                    customcode: undefined,
                    messageType: undefined
                },
                historyQuery: {
                    pageSize: 1,
                    limitSize: 5,
                },
                loadingRoles: {
                    awba: [{required: true, trigger: 'blur', validator: validatorAwb}],
                    awbh: [{required: true, trigger: 'blur', validator: validatorAwbh}],
                    goodsname: [{required: true, trigger: 'blur', validator: validAlphabetsSpanceKey}],
                    carrier: [{required: true, trigger: 'blur', validator: validatorAwbh}],
                    flightno: [{required: true, trigger: 'blur', validator: validatorAwbh}],
                    flightdate: [{required: true, trigger: 'blur', message:'请选择航班时间'}],
                    loadingtime: [{required: true, trigger: 'blur', message:'请选择装载时间'}],
                    originstation: [{required: true, trigger: 'blur', validator: validatorAlphabets}],
                    destinationstation: [{required: true, trigger: 'blur', validator: validatorAlphabets}],
                    lodingpiece: [{type: 'number',required: true, trigger: 'change', message: '只能输入数字'}],
                    lodingweight: [{required: true, trigger: 'change', message: '只能输入数字,并且小数位最多两位',validator: validatorNums}],
                    customcode: [
                        {required: true, message: '关区号不能为空'},
                        {validator: validatorCustomsNums,trigger: 'change',message: '关区号为4位整数'}
                    ]
                },
                loadingData: [],
                detailData: [],
                loadingModel: {
                    carrier: undefined,
                    flightno: undefined,
                    flightdate: undefined,
                    originstation: undefined,
                    destinationstation: undefined,
                    awba: undefined,
                    lodingpiece: undefined,
                    lodingweight: undefined,
                    goodsname: undefined,
                    customcode: undefined,
                    specialgoods: undefined,
                    loadingtime: undefined,
                    messageType: 'MT4201',
                    awbprice: undefined,
                    awbweight: undefined,
                    reason: undefined,
                    contactName: undefined,
                    contactTel: undefined,
                    content: undefined,
                    user: {
                        username : loginedUserInfo().username
                    }
                },
                respModel: {
                    uuid: undefined,
                    reason: undefined,
                    contactName: undefined,
                    contactTel: undefined,
                    content: '',
                    flightNo: undefined,
                    awba: undefined,
                    customCode: undefined,
                    flightDate: undefined,
                    awbh: '',
                },
                loadingDeleteRules: {
                    reason:[{required:true,message:'原因不能为空',trigger:'blur'}],
                    contactName:[{required:true,message:'操作人不能为空',trigger:'blur'}],
                    contactTel:[
                        { required: true, message: '手机号不能为空', trigger: 'blur' },
                        { type: 'number', message: '手机号格式不正确', trigger: 'blur',
                            transform(value){
                                var phone = 11 && /^((13|14|15|16|17|18|19)[0-9]{1}\d{8})$/
                                if (!phone.test(value)){
                                    return false;
                                }else {
                                    return Number(value);
                                }
                            }}
                    ],
                },
            }
        },
        activated() {
            if (this.$route.params.flightData !== undefined) {
                // 给查询条件赋值
                if (this.$route.params.flightData.awba !== undefined && this.$route.params.flightData.awba !== '') {
                    this.loadingQuery.awba = this.$route.params.flightData.awba.substring(0, 3) + '-' + this.$route.params.flightData.awba.substring(3)
                }
                this.loadingQuery.carrier = this.$route.params.flightData.flightno.substring(0, 2)
                this.loadingQuery.flightno = this.$route.params.flightData.flightno.substring(2)
                this.loadingQuery.flightdate = this.$route.params.flightData.flightdate
                this.loadingQuery.originstation = this.$route.params.flightData.originstation
                this.loadingQuery.destinationstation = this.$route.params.flightData.destinationstation
                this.getList()
            }else {
                this.loadingQuery= {
                    pageSize: 1,
                    limitSize: 10,
                    awba: undefined,
                    messageType: 'MT4201'
                }
            }
            let username = loginedUserInfo().username
            if (username === 'admin') {
                this.isAdmin = true
            }
        },
        computed: {
            carrier: {
                get: function () {
                    return this.loadingModel.carrier
                },
                set: function (val) {
                    this.loadingModel.carrier = val.toUpperCase().trim()
                }
            },
            goodsname: {
                get: function () {
                    return this.loadingModel.goodsname
                },
                set: function (val) {
                    this.loadingModel.goodsname = val.toUpperCase().trim()
                }
            },
            flightno: {
                get: function () {
                    return this.loadingModel.flightno
                },
                set: function (val) {
                    this.loadingModel.flightno = val.toUpperCase().trim()
                }
            },
            originstation: {
                get: function () {
                    return this.loadingModel.originstation
                },
                set: function (val) {
                    this.loadingModel.originstation = val.toUpperCase().trim()
                }
            },
            destinationstation: {
                get: function () {
                    return this.loadingModel.destinationstation
                },
                set: function (val) {
                    this.loadingModel.destinationstation = val.toUpperCase().trim()
                }
            }
        },
        methods: {



            getList() {
                this.listLoading = true
                if (this.loadingQuery.awba !== undefined && this.loadingQuery.awba !== '') {
                    getMt4201ListForParam(this.loadingQuery).then(res => {
                        this.loadingData = res.data.data.list
                        this.total = res.data.data.total
                        if (res.data.data.total > 0) {
                            this.loadingQuery.carrier = this.loadingData[0].carrier
                            this.loadingQuery.flightno = this.loadingData[0].flightno
                            this.loadingQuery.flightdate = this.loadingData[0].flightdate
                            this.loadingQuery.originstation = this.loadingData[0].originstation
                            this.loadingQuery.destinationstation = this.loadingData[0].destinationstation
                            this.loadingQuery.customcode = this.loadingData[0].customcode
                        }
                        setTimeout(() => {
                            this.listLoading = false
                        }, 1.5 * 1000)
                    })
                } else {
                    getMt4201ListForParam(this.loadingQuery).then(res => {
                        this.loadingData = res.data.data.list
                        this.total = res.data.data.total
                        setTimeout(() => {
                            this.listLoading = false
                        }, 1.5 * 1000)
                    })
                }

            },
            // 多选
            handleSelectionChange() {

            },
            // 查询
            handleSearch() {
                // this.loadingQuery.carrier = undefined
                // this.loadingQuery.flightno = undefined
                // this.loadingQuery.originstation = undefined
                // this.loadingQuery.flightdate = undefined
                // this.loadingQuery.destinationstation = undefined
                this.getList()
            },
            // 收发明细
            handleSend(row) {
                const resQuery = {
                    carrier: row.carrier,
                    flightNo: row.flightno,
                    flightDate: row.flightdate,
                    opertype: row.opertype,
                    awba: row.awba,
                    awbh: row.awbh,
                    messageType: 'MT4201'
                }
                this.dialogTableVisible = true
                getResponseForParam(resQuery).then(res => {
                    this.detailData = res.data
                })
            },
            // 编辑 弹框
            handleEdit(row) {
                this.loadingModel = Object.assign({}, row)
                this.loadingModel.flightno = row.carrier+row.flightno
                this.dialogStatus = 'update'
                this.dialogFormVisible = true
                this.$nextTick(() => {
                    this.$refs.loadingFormData.clearValidate()
                })
            },
            // 更新数据
            updateData() {
                let _this = this;
                this.$refs.loadingFormData.validate(valid => {
                    if (valid) {
                        _this.loadingModel.user= {
                            username : loginedUserInfo().username
                        }
                        this.loadingModel.carrier = this.loadingModel.flightno.substring(0,2);
                        this.loadingModel.flightno = this.loadingModel.flightno.substring(2);
                        updateMT4201(this.loadingModel).then(res => {
                            if (res.data.count > 0) {
                                this.dialogFormVisible = false
                                Message.success("数据更新成功")
                                this.getList()
                            } else {
                                Message.error("数据更新失败,请检查数据")
                            }
                        })
                    }
                })
            },

            // 发送舱单报
            handleSendAwb(row) {

                this.$confirm("是否发送", "确认消息", {
                    distinguishCancelAndClose: true,
                    confirmButtonText: '发送',
                    cancelButtonText: '取消'
                }).then(() => {
                    if(row.awbh === null || row.awbh === undefined){
                        row.awbh = ''
                    }
                    row.user = {
                        username : loginedUserInfo().username
                    }
                    sendCreateMt4201(row).then(res => {
                        if (res.data.count > 0) {
                            Message.success(res.data.respMessage)
                            this.getList()
                        }else {
                            Message.success(res.data.respMessage)
                        }
                    })
                }).catch(error =>{
                    Message.error(error.message)
                })
            },

            // 查询删除报历史消息
            historyList(){
                this.historyDialog = true;
                this.listLoading = true;
                getHistoryList(this.historyQuery).then(res => {
                    this.historyData = res.data.data.list
                    this.historyTotal = res.data.data.total
                    if (res.data.data.total > 0) {
                    }
                    setTimeout(() => {
                        this.listLoading = false
                    }, 1.5 * 1000)
                })
            },
            // 回显删除报历史消息
            historyEcho(val){
                this.respModel.reason = val.operperson;
                this.respModel.contactName = val.operreason;
                this.respModel.contactTel = val.opertel;
                this.historyDialog = false;
            },
            // 发送删除报
            handleSendDelete(row) {
                this.respModel = {
                    carrier: undefined,
                    reason: undefined,
                    contactName: undefined,
                    contactTel: undefined,
                    content: '',
                    flightNo: undefined,
                    awba: undefined,
                    customCode: undefined,
                    flightDate: undefined,
                    awbh: '',
                    username: loginedUserInfo().username,
                }
                this.dialogDeleteVisible = true
                this.respModel.carrier = row.carrier
                this.respModel.flightNo = row.flightno
                this.respModel.awba = row.awba
                this.respModel.customCode = row.customcode
                this.respModel.flightDate = row.flightdate
                if(row.awbh ===null){
                    this.respModel.awbh = ''
                }else {
                    this.respModel.awbh = row.awbh
                }
                this.$nextTick(() => {
                    this.$refs.loadingDeleteForm.clearValidate()
                })
            },

            sendLoadingDelete() {
                this.$refs.loadingDeleteForm.validate(valid => {
                    if (valid) {
                        sendDeleteMt4201(this.respModel).then(res => {
                            if (res.data.count > 0) {
                                Message.success(res.data.respMessage)
                                this.dialogDeleteVisible = false
                                this.getList()
                            } else {
                                Message.success(res.data.respMessage)
                            }
                        })
                    }
                })
            },
            // 删除
            handleAwbDelete(row) {
                row.user = {
                    username : loginedUserInfo().username
                }
                this.$confirm("是否删除", "确认消息", {
                    distinguishCancelAndClose: true,
                    confirmButtonText: '删除',
                    cancelButtonText: '取消'
                }).then(() => {
                    deleteByIsDelete(row).then(res => {
                        if (res.data.code == "200") {
                            this.$message({
                                type: 'success',
                                message: res.data.msg
                            })
                            this.getList()
                        } else {
                            this.$message({
                                type: 'danger',
                                message: res.data.msg
                            })
                        }
                    })
                }).catch(action => {
                    this.$message({
                        type: 'info',
                        message: action === 'cancel'
                            ? '取消删除'
                            : '删除取消'
                    })
                })
            },
            // 更改当前运单发送状态
            handleAwbStatus(row) {
                this.$confirm("是否发送更改状态", "确认消息", {
                    distinguishCancelAndClose: true,
                    confirmButtonText: '确认更改',
                    cancelButtonText: '取消更改'
                }).then(() => {
                    if (row.status!==22){
                        row.status =22;
                    }
                    // updateStatus(row).then(res => {
                    //     if (res.data.count > 0) {
                    //         this.$message({
                    //             type: 'success',
                    //             message: '当前运单状态已更改'
                    //         })
                    //         this.getList()
                    //     } else {
                    //         this.$message({
                    //             type: 'error',
                    //             message: '状态更改失败,请稍后重试'
                    //         })
                    //     }
                    // })

                }).catch(action => {
                    this.$message({
                        type: 'info',
                        message: action === 'cancel'
                            ? '取消状态更改'
                            : '状态更改取消'
                    })
                })
            },
            // 重置实体
            restModel() {
                this.loadingModel = {
                    carrier: undefined,
                    flightno: undefined,
                    flightdate: undefined,
                    originstation: undefined,
                    destinationstation: undefined,
                    awba: undefined,
                    lodingpiece: undefined,
                    lodingweight: undefined,
                    goodsname: undefined,
                    customcode: undefined,
                    specialgoods: undefined,
                    loadingtime: undefined,
                    messageType: 'MT4201',
                    awbprice: undefined,
                    awbweight: undefined,
                    user: {
                        username : loginedUserInfo().username,
                    }
                }
            },
            // 新增出港装载 弹框
            handelAddLoadingInfo() {
                this.restModel()
                // 给model赋值,所使用数据是以单独单号查询数据所得
                // this.loadingModel.carrier = this.loadingQuery.carrier
                this.loadingModel.flightdate = this.loadingQuery.flightdate
                if ( this.loadingQuery.carrier != undefined){
                    this.loadingModel.flightno = this.loadingQuery.carrier + this.loadingQuery.flightno
                }
                this.loadingModel.originstation = this.loadingQuery.originstation
                this.loadingModel.destinationstation = this.loadingQuery.destinationstation
                this.loadingModel.customcode = this.loadingQuery.customcode
                this.dialogStatus = 'create'
                this.dialogFormVisible = true

                this.$nextTick(() => {
                    this.$refs.loadingFormData.clearValidate()
                })
            },
            // 新增出港装载 请求
            createData() {
                this.$refs.loadingFormData.validate(valid => {
                    if (valid) {
                        this.loadingModel.carrier = this.loadingModel.flightno.substring(0,2);
                        this.loadingModel.flightno = this.loadingModel.flightno.substring(2);
                        addMt4201(this.loadingModel).then(res => {
                            if (res.data.count > 0) {
                                this.dialogFormVisible = false
                                Message.success("新增出港装载成功")
                                this.getList()
                            } else {
                                Message.error("数据新增失败,请检查数据")
                            }
                        })
                    }
                })
            },
            //获取机场三字码
            remoteMethodAirport(query){
                this.airportCode = []
                if (query !== '') {
                    this.listLoading = true
                    getAirportCode({airportid: query}).then(res => {
                        if(res !== null){
                            setTimeout(() => {
                                this.listLoading = false
                                this.airportCode = res.data.data
                            }, 200)
                        }
                    })
                } else {
                    this.airportCode = []
                }
            },
            //关区代码
            remoteMethodCustomCode(query){
                this.customCodeList = []
                if (query !== '') {
                    this.customLoading = true
                    getCustomCode({customcode: query}).then(res => {
                        if(res !== null){
                            setTimeout(() => {
                                this.customLoading = false
                                this.customCodeList = res.data.data
                            }, 200)
                        }
                    })
                } else {
                    this.airportCode = []
                }
            },
            handleAddLoading() {
                const row = {
                    'messageType': 'MT4201'
                }
                this.$router.push({name: '出港航班信息', params: {scopeRow: row}})
            },
            handelBackStep() {
                this.loadingQuery.messageType = 'MT4201'
                this.$router.push({name: '出港航班信息', params: {scopeRow: this.loadingQuery}})
            }
        }
    }

</script>
<style>
    .grid-content {
        height: 36px;
        line-height: 36px;
    }

    .content {
        border-left: 4px #409EFF solid;
        padding-left: 10px;
        background-color: #f9fafc;
        margin-bottom: 2px
    }

    .row-bg, .co {
        background-color: white;
    }

    .titleSpan {
        font-weight: bold;
        margin-right: 35px;
    }

    .el-row {
        margin-top: 10px;
        margin-bottom: 0px;
    }

    .btnFoot {
        margin-top: 10px;
    }

    .el-table td, .el-table th {
        text-align: center
    }

    .el-btn {
        margin-left: 10px;
        display: inline-block;
    }
</style>