<template>
    <div class="eibs-tab">
        <c-col :span="24" style="">
            <c-istream-table-docpan :list="stmData.data" :columns="stmData.columns">
            <el-table-column label="报文格式">
                <template slot-scope="scope">
                    <c-select
                        v-model="
                            model.trnmod.trndoc.doceot[scope.row.index].cortyp
                        "
                        style="width: 100%"
                        disabled
                        placeholder="请选择"
                    >
                        <el-option
                            v-for="item in codes.doceotCortyp"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                        >
                        </el-option>
                    </c-select>
                </template>
            </el-table-column>
            <el-table-column label="报文格式">
                <template slot-scope="scope">
                    <c-select
                        v-model="
                            model.trnmod.trndoc.doceot[scope.row.index].docsnf
                        "
                        style="width: 100%"
                        placeholder="请选择"
                        @change="executeDefault('trnmod.trndoc.doccur.docsnf')"
                    >
                        <el-option
                            v-for="item in codes.docsnf"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                        >
                        </el-option>
                    </c-select>
                </template>
            </el-table-column>
            <el-table-column label="语言" width="150%">
                <template slot-scope="scope">
                    <c-select
                        v-model="
                            model.trnmod.trndoc.doceot[scope.row.index].docuil
                        "
                        style="width: 100%"
                        placeholder="请选择"
                    >
                        <el-option
                            v-for="item in codes.uiltxt"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                        >
                        </el-option>
                    </c-select>
                </template>
            </el-table-column>
            <el-table-column label="传送方式">
                <template slot-scope="scope">
                    <c-select
                        v-model="
                            model.trnmod.trndoc.doceot[scope.row.index].apf
                        "
                        disabled
                        style="width: 100%"
                        placeholder="请选择"
                    >
                        <el-option
                            v-for="item in codes.apftxt"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                        >
                        </el-option>
                    </c-select>
                </template>
            </el-table-column>
            <el-table-column label="Or." width="65%">
                <template slot-scope="scope">
                    <c-input
                        v-model="
                            model.trnmod.trndoc.doceot[scope.row.index].apfcpy1
                        "
                        :readonly="true"
                        style="width: 100%"
                        placeholder="请选择"
                    >
                    </c-input>
                </template>
            </el-table-column>
            <el-table-column label="CC" width="65%">
                <template slot-scope="scope">
                    <c-input
                        v-model="
                            model.trnmod.trndoc.doceot[scope.row.index].apfcpy2
                        "
                        style="width: 100%"
                        placeholder="请选择"
                        
                    >
                    </c-input>
                </template>
            </el-table-column>
            <el-table-column label="">
                <template slot-scope="scope">
                    <c-select
                        v-model="
                            model.trnmod.trndoc.doceot[scope.row.index].staflg
                        "
                        style="width: 100%"
                        placeholder="请选择"
                    >
                        <el-option
                            v-for="item in codes.swttlx"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                        >
                        </el-option>
                    </c-select>
                </template>
            </el-table-column>
            <el-table-column label="操作" width="115px" fixed="right">
                <template slot-scope="scope">
                    <c-button
                        type="primary"
                        size="small"
                        :disabled="
                            model.trnmod.trndoc.doceot[scope.row.index]
                                .pandsc == 'MT799' &&
                            model.didgrp.rec.elcflg == 'Y'
                        "
                        @click="handleDisplay(scope.row.index, scope.row,model.trnmod.trndoc.doceot[scope.row.index])"
                        icon="el-icon-search"
                        style="margin-left:0"
                        ></c-button
                    >
                    <c-button
                        size="small"
                        type="primary"
                        icon="el-icon-edit"
                        style="margin-left:0"
                        @click="handleDetail(scope.row.index, scope.row)"
                        ></c-button
                    >
                </template>
            </el-table-column>
        </c-istream-table-docpan>
        </c-col>
        <template>
            <el-dialog
                :title="title"
                :visible.sync="centerDialogVisible"
                width="60%"
                center
            >
                <el-form label-width="100px" :model="dialog">
                    <c-row>
                        <c-col :span="12">
                            <c-col>
                                <el-form-item label="per-medium"
                                    ><el-input disabled v-model="dialog.cortyp"
                                /></el-form-item>
                            </c-col>
                            <c-col>
                                <el-form-item label="Form Set">
                                    <el-input
                                        disabled
                                        v-model="dialog.cortyp"
                                    />
                                </el-form-item>
                            </c-col>
                            <c-col v-if="title != 'elcs.101.001.01'">
                                <el-form-item>
                                    <el-input
                                        disabled
                                        style="width: 150px"
                                        value="Original"
                                    />
                                    <el-input
                                        v-model="dialog.apfcpy1"
                                        style="width: 100px; margin-left: 20px"
                                    />
                                </el-form-item>
                                <el-form-item>
                                    <el-input
                                        disabled
                                        style="width: 150px"
                                        value="Customer Copy"
                                    />
                                    <el-input
                                        v-model="dialog.apfcpy2"
                                        style="width: 100px; margin-left: 20px"
                                    />
                                </el-form-item>
                                <el-form-item>
                                    <el-input
                                        disabled
                                        style="width: 150px"
                                        value="File Copy"
                                    />
                                    <el-input
                                        v-model="dialog.apfcpy3"
                                        style="width: 100px; margin-left: 20px"
                                    />
                                </el-form-item>
                                <el-form-item>
                                    <el-input
                                        disabled
                                        style="width: 150px"
                                        value="Internal Copy"
                                    />
                                    <el-input
                                        v-model="dialog.apfcpy4"
                                        style="width: 100px; margin-left: 20px"
                                    />
                                </el-form-item>
                            </c-col>
                        </c-col>

                        <c-col :span="12">
                            <el-form-item
                                label="Send Message to"
                                label-width="150px"
                            >
                                <el-input disabled v-model="dialog.roladr" />
                            </el-form-item>
                            <el-form-item
                                label-width="30px"
                                v-if="title != 'elcs.101.001.01'"
                            >
                                <el-input
                                    style="width: 250px"
                                    v-model="dialog.rcv.pts.extkey"
                                />
                                <c-button size="small" type="primary" icon="el-icon-search"
                                    ></c-button
                                >
                                <c-button size="small" type="primary">
                                    详情
                                </c-button>
                            </el-form-item>
                            <el-form-item v-else label="BIC">
                                <el-input v-model="dialog.rcv.pts.extkey" />
                            </el-form-item>
                            <el-form-item
                                v-if="title == 'elcs.101.001.01'"
                                label="行联行号"
                            >
                                <el-input v-model="dialog.rcv.pts.bankno" />
                            </el-form-item>
                            <el-form-item label-width="30px">
                                <el-input
                                    :value="
                                        title != 'elcs.101.001.01'
                                            ? dialog.rcv.namelc
                                            : dialog.rcv.pts.jigomc
                                    "
                                    :disabled="title != 'elcs.101.001.01'"
                                    type="textarea"
                                    :rows="2"
                                />
                                <br />
                                <el-input
                                    :value="
                                        title != 'elcs.101.001.01'
                                            ? dialog.rcv.adrelc
                                            : dialog.rcv.pts.dizzhii
                                    "
                                    :disabled="title == 'MT799'"
                                    type="textarea"
                                    :rows="2"
                                />
                            </el-form-item>
                            <el-form-item label="Reference" label-width="100px">
                                <el-input disabled v-model="dialog.adrref" />
                            </el-form-item>
                            <el-form-item label="Medium" label-width="100px">
                                <el-input
                                    disabled
                                    style="width: 40%"
                                    v-model="dialog.cortyp"
                                />
                                <el-input
                                    disabled
                                    v-model="dialog.docuil"
                                    style="width: 40%; margin-left: 20px"
                                />
                            </el-form-item>
                        </c-col>

                        <c-col>&nbsp;</c-col>
                        <c-col :span="12" v-if="title != 'MT799'">
                            <el-form-item
                                label="Adress Amend"
                                label-width="120px"
                            >
                                <el-input
                                    type="textarea"
                                    v-model="dialog.adrblk"
                                    :rows="4"
                                />
                            </el-form-item>
                        </c-col>
                        <c-col :span="12" v-else>
                            <el-form-item label="BIC">
                                <el-input disabled v-model="dialog.adrbic" />
                            </el-form-item>
                            <el-form-item label="Authenticator"
                                ><el-input disabled v-model="dialog.adrbicaut"
                            /></el-form-item>
                            <el-form-item label="Priority"
                                ><el-input disabled v-model="dialog.msgpri"
                            /></el-form-item>
                        </c-col>
                        <c-col :span="12">
                            <el-form-item label-width="30px">
                                <el-table
                                    :data="dialog.rcv.ptyinftxt.rows"
                                    size="mini"
                                    stripe
                                    :border="true"
                                    empty-text=" "
                                    max-height="430px"
                                >
                                    <el-table-column label="Corr.Type" sortable>
                                    </el-table-column>
                                    <el-table-column label="Adressing" sortable>
                                    </el-table-column>
                                    <el-table-column
                                        label="Authentication"
                                        sortable
                                    >
                                    </el-table-column>
                                </el-table>
                            </el-form-item>
                        </c-col>
                        <c-col v-if="title != 'MT799'"
                            ><el-form-item label="Letter Date">
                                <el-date-picker
                                    type="date"
                                    v-model="dialog.docdat"
                                >
                                </el-date-picker
                            ></el-form-item>
                        </c-col>
                        <c-col
                            ><el-form-item label="Contact"
                                ><el-input v-model="dialog.ptcnam"
                            /></el-form-item>
                        </c-col>
                        <c-col :span="22"
                            ><el-form-item
                                :label="
                                    title == 'MT799'
                                        ? 'Sender to Rec. information'
                                        : 'Remark'
                                "
                                ><el-input
                                    type="textarea"
                                    :rows="10"
                                    :disabled="title == 'MT799'"
                                    :v-model="
                                        title == 'MT799'
                                            ? dialog.addtxt
                                            : dialog.remark
                                    "
                            /></el-form-item>
                        </c-col>
                        <c-col :span="2">
                            <c-button size="mini">... </c-button>
                        </c-col>
                    </c-row>
                </el-form>
                <template #footer>
                    <span class="dialog-footer">
                        <c-button type="primary" @click="saveDialog"
                            >确 定</c-button
                        >
                        <c-button @click="centerDialogVisible = false"
                            >取 消</c-button
                        >
                    </span>
                </template>
            </el-dialog>
        </template>
    </div>
</template>
<script>
import CommonProcess from "~/mixin/CommonProcess";
import Api from "~/service/Api";
import Utils from "~/utils/index";
import DocUtils from '~/utils/DocUtils'
export default {
    inject: ['root'],
    props: ["model", "codes"],
    mixins: [CommonProcess],
    data() {
        return {
            index: 0,
            title: "",
            dialog: {
                rcv: {
                    pts: {},
                    ptyinftxt: {},
                },
            },
            centerDialogVisible: false,
            stmData: {
                columns: [
                    //注释的已改成静态
                    "role 收报人 80px",
                    "pandsc 描述 260px",
                    //"cortyp 类型",
                    //"docsnf 报文格式",
                    //"docuil 语言",
                    //"apf 传送方式"
                ],
                data: [],
            },
        };
    },
    watch: {
        "model.trnmod.trndoc.doceot": {
            handler(val, oldVal) {
                var stm = [];
                let k = 0;
                for (let i = 0; i < val.length; i++) {
                    if (val[i].role != "") {
                        stm[k++] = val[i];
                    }
                }
                this.stmData.data = stm
            },
            immediate: true
        }
    },
    methods: {
        saveDialog() {
            this.centerDialogVisible = false;
            console.log(this.model);
            this.model.trnmod.trndoc.doceot.splice(this.index, 1, this.dialog);
            this.executeRule("trnmod.trndoc.doccur.butaddok").then(res => {
                if(res.data.respCode==SUCCESS){
                    //TODO

                }else{
                    this.$notify.error({ title: '错误', message: '服务请求失败！' });
                }
            })
        },
        async handleDisplay(index, row,doceot){
            //后续要根据快照模式切换请求方式
            let cortyp = row.cortyp
            let docnam = doceot.docnam||'';
            docnam = docnam.substr(docnam.indexOf("\\")+1).toLowerCase().replaceAll("\\","_");
            let rtnmsg
            if (cortyp == 'SWT' || cortyp == 'FMT' || cortyp == 'CMT') {
                this.model.setmod.msgmod.doccod = row.id
                rtnmsg = await Api.post(`${this.declareParams.trnName}/msgmod_butshw`, this.wrapper())
            } else {
                this.model.trnmod.trndoc.doccod = row.id
                this.model.trnmod.trndoc.cortyp = cortyp
                const params = {
                    index: index
                }
                rtnmsg = await Api.post(`${this.declareParams.trnName}/executeDocpan`, this.wrapper(params))
            }
            if (rtnmsg.respCode == SUCCESS) {
                if (cortyp == 'SWT' || cortyp == 'FMT' || cortyp == 'CMT') {
                    let viewurl = rtnmsg.data.setmod_msgmod_docpth;
                    this.viewurl = viewurl
                    this.title = "报文"
                    //window.open(viewurl, 'newwindow', 'height=1200,width=800,top=100,left=100,toolbar=no,resizable=no,menubar=no,location=no, status=no');
                }
                else if (cortyp == 'ELC') {
                    Modal.info({
                        title: '电证报文', content: <div style={{ height: 400, overflow: 'auto' }}><ELCMessage mty={row.id} message={rtnmsg.data["\\trnmod\\trndoc\\docinf"]} /></div>,
                        width: 1000,
                    })
                }
                else {
                    // let url = rtnmsg.data.trnmod_trndoc_smh_docpth;
                    this.title = "面函"
                    let viewurl = "/#/docpan/show";
                    let XMLdata;
                    if (row.pandsc.startsWith("elcs.")) {
                        window.sessionStorage.docXML = ''
                        window.sessionStorage.docTXT = ''
                        rtnmsg.data.trnmod_trndoc_doceot[index].doctxt.rows.forEach(element => {
                            window.sessionStorage.docTXT += element + "\r\n"
                        });
                    }
                    else if (row.pandsc == "MT799") {
                        window.sessionStorage.docTXT = ''
                        XMLdata = rtnmsg.data.litbenl1blk
                    }
                    else{
                        //参考后台Doceot.butshw order=1000
                        let execution = 'P', structure = 'l'
                        let attr = DocUtils.getDocAttribute(docnam,structure,execution)
                        window.sessionStorage.docTXT = ''
                        window.sessionStorage.docXML = rtnmsg.data[attr];
                    }
                    // console.log( window.sessionStorage.docTXT);
                    // console.log( window.sessionStorage.docXML);
                    window.open(viewurl, 'newwindow', 'height=1200,width=800,top=100,left=100,toolbar=no,resizable=no,menubar=no,location=no, status=no');
                }
                this.dialogOpen = true
            }
            else {
                this.$notify.error({ title: '错误', message: '服务请求失败！' })
            }
        },
        async handleDetail(index, row) {
            const params = {
                index: index
            }
            let rtnmsg = await Api.post(`${this.declareParams.trnName}/executeDocpanDetail`, this.wrapper(params))
            if (rtnmsg.respCode == SUCCESS) {
                this.title = row.pandsc
                this.centerDialogVisible = true,
                this.dialog = rtnmsg.data.trnmod_trndoc_doceot[index]
                this.index = index
            }
        }
    },
    created: function () {},
};
</script>
<style>
</style>
