<template>
    <div>
      <drag-modal :title="dialogTitle" :width="dialogWidth" :visible="visible" :isFooter="operateBizBtn.length > 0 ? true : false" :confirmLoading="confirmLoading" @ok="handleOk" @cancel="handleClose" :canClickMask="canClickMask" :leftPosition="leftPosition" :topPosition="topPosition" :initPosition="initPosition" okText="保存" cancelText="关闭" wrapClassName="ant-modal-cust-warp" style="top: 5%; height: 70%; overflow-y: hidden" >
      <a-spin :spinning="confirmLoading" size="large">
        <a-config-provider :locale="locale">
          <a-form class="k-form-build-9136076486841527" layout="horizontal" :hideRequiredMark="false" :form="form" @submit="handleSubmit" >
            <div class="build-block" >
              <!-- batch_1627292117731 - 批量修改 -->
              <a-form-item label="" :label-col="{}" :wrapper-col="{}" :style="{}" >
                <KBatch v-if="!data_ifcsumTemp_record.options.hidden" ref="KBatch" style="width:100%" v-bind="data_ifcsumTemp_record.options" :recordKey="data_ifcsumTemp_record.key" :optionsKey="data_ifcsumTemp_record.options.key" :baseColumnConfigList="data_ifcsumTemp_BaseColumnList" :model="'ifcsumTemp'" :config="config" :parentDisabled="disabled" :dynamicData="dynamicData" :selectMode="selectMode" :selectDeferred="selectDeferred" :excelName="excelName" :pageId="pageId" @invokeGetFormData="invokeGetFormData" @change="handleChange($event, 'ifcsumTemp')" @logEvent="logEvent($event, 'ifcsumTemp', data_ifcsumTemp_record)" v-decorator="[ 'ifcsumTemp', { }, ]" />
              </a-form-item>
            </div>
          </a-form>
        </a-config-provider>
      </a-spin>
      <template slot="footer">
        <a-button v-for="(item, index) in operateBizBtn" :key="index" :type="item.type ? item.type : 'primary'" :icon="item.icon" @click="handleBusiness(item.operation, item)" >{{ item.label }}</a-button >
      </template>
    </drag-modal>
    </div>
    </template>
    
      <script>
      import baseModalMixin from './baseModalMixin'
      import formBuildMixin from './formBuildMixin'
    
      export default {
        mixins: [formBuildMixin, baseModalMixin],
        data() {
          return {
            pageId: 'MANIFEST_MAINTENANCE_BATCH_UPDATE',
            operateBizBtn: [{'hidden':false,'icon':'','hotKey':'','permission':'','label':'关闭','operationMethod':'','sort':0,'params':[],'operation':'close','displayTab':'','displayMode':'flat','direction':'right'},{'hidden':false,'icon':'','hotKey':'','permission':'','label':'修改','operationMethod':'','sort':1,'type':'primary','params':[],'operation':'save','displayTab':''}],
            dialogTitle: '舱单维护_详情',
            dialogServiceName: '',
            dialogWidth: '60%',
            dialogBaseCodeType: '',
            dialogModalType: 'dialog',
            dialogUrl: {'add':'save','update':'updateById'},
    
            data_ifcsumTemp_record: {"label":"批量修改","type":"batch","options":{"mode":"cell","hasPaging":false,"adding":false,"selectType":"none","key":"key","height":"80px","editable":true,"lazyNoPaging":true,"noSerial":true,"deleting":false,"filterPanel":true},"model":"ifcsumTemp","key":"batch_1627292117731"},
            data_ifcsumTemp_BaseColumnList: [{"options":{"type":"text","width":"150","placeholder":"请输入"},"rules":[{"message":"必填项","required":false}],"model":"billNbr","label":"提单号","type":"input","key":"input_1635752952960"},{"options":{"options":[],"dynamic":1,"placeholder":"请选择","dynamicKey":"CompanyOwner,/,owner,owner,,10,,","width":"120px"},"model":"ctnOwner","label":"营运人","type":"select","key":"select_16"},{"options":{"options":[],"dynamic":2,"placeholder":"请选择","dynamicKey":"TRANSFER","width":"120px"},"model":"transferId","label":"中转","type":"select","key":"select_1661764121460"},{"icon":"icon-xiala","options":{"options":[],"dynamic":1,"placeholder":"请选择","dynamicKey":"BasPort,-,ePortNam|portCod,portCod,,50000,,","width":"120","customClass":""},"model":"transPortCod","label":"中转港代码","type":"select","key":"select_1652165232283"},{"icon":"icon-xiala","options":{"options":[],"dynamic":1,"placeholder":"请选择","dynamicKey":"BasPort,-,ePortNam|portCod,ePortNam,,50000,,","width":"120","customClass":""},"model":"transPortNam","label":"中转港","type":"select","key":"select_1661764452760"},{"icon":"icon-xiala","options":{"options":[],"dynamic":1,"placeholder":"请选择","dynamicKey":"BasPort,-,ePortNam|portCod,portCod,,50000,,","width":"120","customClass":""},"model":"loadPortCod","label":"装货港代码","type":"select","key":"select_1661764410473"},{"icon":"icon-xiala","options":{"options":[],"dynamic":1,"placeholder":"请选择","dynamicKey":"BasPort,-,ePortNam|portCod,ePortNam,,50000,,","width":"120","customClass":""},"model":"loadPortNam","label":"装货港","type":"select","key":"select_1658386288771"},{"icon":"icon-xiala","options":{"options":[],"dynamic":1,"placeholder":"请选择","dynamicKey":"BasPort,-,ePortNam|portCod,portCod,,50000,,","width":"120","customClass":""},"model":"dischrgPortCod","label":"卸货港代码","type":"select","key":"select_1652165653818"},{"icon":"icon-xiala","options":{"options":[],"dynamic":1,"placeholder":"请选择","dynamicKey":"BasPort,-,ePortNam|portCod,ePortNam,,50000,,","width":"120","customClass":""},"model":"dischrgPortNam","label":"卸货港","type":"select","key":"select_1658386816916"},{"icon":"icon-xiala","options":{"options":[],"dynamic":1,"placeholder":"请选择","dynamicKey":"BasPort,-,ePortNam|portCod,portCod,,50000,,","width":"120","customClass":""},"model":"destPortCod","label":"目的港代码","type":"select","key":"select_1652165655371"},{"icon":"icon-xiala","options":{"options":[],"dynamic":1,"placeholder":"请选择","dynamicKey":"BasPort,-,ePortNam|portCod,ePortNam,,50000,,","width":"120","customClass":""},"model":"destPortNam","label":"目的港","type":"select","key":"select_1658386842835"},{"icon":"icon-write","rules":[{"message":"必填项","required":false}],"label":"卸船地点","type":"input","options":{"type":"text","width":"120px","placeholder":"请输入"},"model":"placeCode","key":"input_1652177357459"},{"icon":"icon-xiala","options":{"options":[],"dynamic":3,"placeholder":"请选择","dynamicKey":"payWayIdList","width":"120px"},"model":"payWayId","label":"付款方式","type":"select","key":"select_1635753023421"},{"icon":"icon-xiala","options":{"options":[],"dynamic":1,"placeholder":"请选择","dynamicKey":"BasJfType,/,content,content,,200,,","width":"120","customClass":""},"model":"traficModStr","label":"交付方式","type":"select","key":"select_1652173036022"},{"icon":"icon-number","options":{"precision":0,"placeholder":"请输入","width":"120px"},"model":"pieceNum","label":"件数","type":"number","key":"number_1635754654138"},{"icon":"icon-number","options":{"precision":3,"width":"120px","placeholder":"请输入"},"model":"gvolNum","label":"体积","type":"number","key":"number_1635754658177"},{"icon":"icon-number","options":{"precision":3,"width":"120px","placeholder":"请输入"},"model":"gweightTon","label":"毛重","type":"number","key":"number_1635754656246"},{"icon":"icon-xiala","options":{"options":[],"dynamic":1,"placeholder":"请选择","dynamicKey":"BasCargoKind,/,cargoKindCod,cargoKindCod|CARGO_KIND_E_NAM,,200,,","width":"120px"},"model":"cargoKindCod","label":"货类代码","type":"select","key":"select_1635754639093"},{"icon":"icon-write","rules":[{"message":"必填项","required":false}],"label":"英文货名","type":"input","options":{"type":"text","width":"120px","placeholder":"请输入"},"model":"eCargoNam","key":"input_1635754383277"},{"options":{"type":"text","width":"120px","placeholder":"请输入"},"rules":[{"message":"必填项","required":false}],"model":"dangUnNo","label":"联合国编号","type":"input","key":"input_1626163154918"},{"icon":"icon-write","options":{"type":"text","width":"120px","placeholder":"请输入"},"rules":[{"message":"必填项","required":false}],"model":"dangClassNam","label":"危品类别","type":"input","key":"input_1635754724598"},{"icon":"icon-write","rules":[{"message":"必填项","required":false}],"label":"应急联系人","type":"input","options":{"type":"text","width":"120px","placeholder":"请输入"},"model":"dangConactMan","key":"input_1635755086134"},{"options":{"type":"text","width":"120px","placeholder":"请输入"},"rules":[{"message":"必填项","required":false}],"model":"dangTeStr","label":"联系电话","type":"input","key":"input_1635755097703"},{"options":{"type":"text","width":"120px","placeholder":"请输入"},"rules":[{"message":"必填项","required":false}],"model":"eShipperNam","label":"发货人","type":"input","key":"input_1626159714946"},{"options":{"type":"text","width":"120px","placeholder":"请输入"},"rules":[{"message":"必填项","required":false}],"model":"eConsigneeNam","label":"收货人","type":"input","key":"input_1626159714946"},{"options":{"type":"text","width":"120px","placeholder":"请输入"},"rules":[{"message":"必填项","required":false}],"model":"eNotifyNam","label":"通知方","type":"input","key":"input_1626159714946"}]
          }
        },
        methods: {
          callInMountedCustom(ctos3CommonApi, packageRpcParam){
        this.loadPortNam = undefined
        this.loadPortCod = undefined
        this.dischrgPortCod = undefined
        this.dischrgPortNam = undefined
        this.destPortCod = undefined
        this.destPortNam = undefined
        setTimeout(function () {
            this.setData({
                'ifcsumTemp': [{
                    'key': '1',
                }]
            })
            console.log(" this.checkIds", this.checkIds)
        }, 200);
    },
    handleBusinessCustom(operation){
            if (operation == 'close') {
            this.visible = false
            console.log(" this.checkIds", this.checkIds)
        }
            if (operation == 'save') {
            this.$confirm({
                title: '请确认',
                content: '确定要修改吗？',
                okText: '确认',
                cancelText: '取消',
                onOk() {
                    setTimeout(function () {
                        this.getData().then((res) => {
                            const updateObj = []
                            const ifcsumTemp = JSON.parse(JSON.stringify(res.ifcsumTemp[
                                0]))
                            if (ifcsumTemp.placeCode) {
                                ifcsumTemp.placeCod = ifcsumTemp.placeCode;
                            }
                            if (ifcsumTemp.destPortCod) {
                                ifcsumTemp.destPortNam = ifcsumTemp.destPortCod.split(
                                    "-")[0];
                                ifcsumTemp.destPortCod = ifcsumTemp.destPortCod.split(
                                    "-")[1];
                            }
                            if (ifcsumTemp.dischrgPortCod) {
                                ifcsumTemp.dischrgPortNam = ifcsumTemp.dischrgPortCod
                                    .split("-")[0];
                                ifcsumTemp.dischrgPortCod = ifcsumTemp.dischrgPortCod
                                    .split("-")[1];
                            }
                            if (ifcsumTemp.loadPortCod) {
                                ifcsumTemp.loadPortNam = ifcsumTemp.loadPortCod.split(
                                    "-")[0];
                                ifcsumTemp.loadPortCod = ifcsumTemp.loadPortCod.split(
                                    "-")[1];
                            }
                            if (ifcsumTemp.transPortCod) {
                                ifcsumTemp.transPortNam = ifcsumTemp.transPortCod.split(
                                    "-")[0];
                                ifcsumTemp.transPortCod = ifcsumTemp.transPortCod.split(
                                    "-")[1];
                            }
                            if (ifcsumTemp.packageStr2) {
                                ifcsumTemp.packageStr = ifcsumTemp.packageStr2.split("-")[
                                    0];
                                ifcsumTemp.packageCod = ifcsumTemp.packageStr2.split("-")[
                                    1];
                            }
                            delete ifcsumTemp.key
                            ifcsumTemp.shareId = ifcsumTemp.shareId2 ? '1' : '0'
                            this.confirmLoading = true
                            this.checkIds.forEach(item => {
                                ifcsumTemp.id = item
                                updateObj.push(JSON.parse(JSON.stringify(
                                    ifcsumTemp)))
                            })
                            this.ctos3CommonApi('ifcsumTempService',
                                'batchUpdateIfcsumTemp', [
                                    updateObj
                                ]).then((result) => {
                                if (result.responseData.statusCode === 0) {
                                    this.$message.success('提单信息修改成功')
                                    this.$emit('ok', operation)
                                    this.confirmLoading = false
                                    this.visible = false
                                }
                            }).catch(res => {
                                this.confirmLoading = false
                            })
                        })
                    }, 50);
                },
                onCancel() {},
            })
        }
    },
    handleChangeCustom(value, key){
        if (key == "loadPortCod") {
            if (value && value.indexOf('-') != -1) {
                this.setData({
                    loadPortNam: value.split("-")[0]
                })
            }
        }
        if (key == "dischrgPortCod") {
            if (value && value.indexOf('-') != -1) {
                this.setData({
                    dischrgPortNam: value.split("-")[0]
                })
            }
        }
        if (key == "destPortCod") {
            if (value && value.indexOf('-') != -1) {
                this.setData({
                    destPortNam: value.split("-")[0]
                })
            }
        }
        if (key == "transPortCod") {
            if (value && value.indexOf('-') != -1) {
                this.setData({
                    transPortNam: value.split("-")[0]
                })
            }
        }
        if (key == "packageStr") {
            if (value && value.indexOf('-') != -1) {
                this.setData({
                    packageCod: value.split("-")[1]
                })
            }
        }
        if (key == "changeReasonOne") {
            this.setData({
                changeReasonDesc: value.split("/")[1]
            })
        }
        if (key == "shareId2") {
            if (value.length == 0) {
                this.disable(['shareMarksStr'])
            } else {
                this.enable(['shareMarksStr'])
            }
        }
    },
    logEventCustom(value, key){
        if (value.event == "saved" && key=='ifcsumTemp') {
            if (value.changes[0].data.loadPortNam && this.loadPortNam != value.changes[0].data.loadPortNam) {
                this.loadPortNam = value.changes[0].data.loadPortNam
                this.loadPortCod = value.changes[0].data.loadPortNam
                value.changes[0].data.loadPortCod = value.changes[0].data.loadPortNam
            }
            if (value.changes[0].data.loadPortCod && this.loadPortCod != value.changes[0].data.loadPortCod) {
                this.loadPortCod = value.changes[0].data.loadPortCod
                this.loadPortNam = value.changes[0].data.loadPortCod
                value.changes[0].data.loadPortNam = value.changes[0].data.loadPortCod
            }
               if (value.changes[0].data.dischrgPortNam && this.dischrgPortNam != value.changes[0].data.dischrgPortNam) {
                this.dischrgPortNam = value.changes[0].data.dischrgPortNam
                this.dischrgPortCod = value.changes[0].data.dischrgPortNam
                value.changes[0].data.dischrgPortCod = value.changes[0].data.dischrgPortNam
            }
            if (value.changes[0].data.dischrgPortCod && this.dischrgPortCod != value.changes[0].data.dischrgPortCod) {
                this.dischrgPortCod = value.changes[0].data.dischrgPortCod
                this.dischrgPortNam = value.changes[0].data.dischrgPortCod
                value.changes[0].data.dischrgPortNam = value.changes[0].data.dischrgPortCod
            }
             if (value.changes[0].data.destPortNam && this.destPortNam != value.changes[0].data.destPortNam) {
                this.destPortNam = value.changes[0].data.destPortNam
                this.destPortCod = value.changes[0].data.destPortNam
                value.changes[0].data.destPortCod = value.changes[0].data.destPortNam
            }
            if (value.changes[0].data.destPortCod && this.destPortCod != value.changes[0].data.destPortCod) {
                this.destPortCod = value.changes[0].data.destPortCod
                this.destPortNam = value.changes[0].data.destPortCod
                value.changes[0].data.destPortNam = value.changes[0].data.destPortCod
            }
        }
    },
    dynamicFuncCustom(operation){
        if (operation == "test") {
            if (this.showSign == "0") {
                this.show(["shoufatong"])
                console.log("shoufatong", this.resultData1)
                setTimeout(() => {
                    this.setData(this.resultData1)
                }, 200)
                this.showSign = "1"
            } else {
                this.hide(["shoufatong"])
                this.showSign = "0"
            }
        }
            if (operation == "goodsInfoTemp") {
            this.$emit('ok', operation)
        }
    },
    handleBlurCustom(value, key){
    console.log("wenben",value,key)
    },
    handleDialogBusinessCustom(operation){
    
    }
        }
      }
      </script>