<template>
  <c-row class="eibs-tab">
    <c-col :span="24" style="z-index:99">
      <el-table :data="model.docpan.doceot">
        <el-table-column label="角色" width="110">
          <template slot-scope="scope">
            <c-input :readonly="true" placeholder="请输入" style="width: 100%;" v-model="scope.row.role">
            </c-input>
          </template>
        </el-table-column>
        <el-table-column label="描述" width="300">
          <template slot-scope="scope">
            <c-input :readonly="true" placeholder="请输入" style="width: 100%;" v-model="scope.row.pandsc">
            </c-input>
          </template>
        </el-table-column>
        <el-table-column label="类型" width="150px">
          <template slot-scope="scope">
            <el-form-item :prop="'docpan.doceot.' + scope.$index + '.cortyp'" label-width="0">
              <c-select :isFixed="true" dbCode="doceotCortyp" disabled placeholder="请选择" style="width: 100%" v-model="scope.row.cortyp">
              </c-select>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column label="报文格式" width="150px">
          <template slot-scope="scope">
            <!-- @change="executeDefault('docpan.doccur.docsnf')" -->
            <c-input :disabled="scope.row.cortyp !== 'LET'" placeholder="请选择" style="width: 100%" v-if="scope.row.cortyp !== 'LET'" v-model="scope.row.docsnf">
            </c-input>
            <c-select :isFixed="true" v-else v-model="scope.row.docsnf" :disabled="scope.row.cortyp !== 'LET'" @change="customAddModify(scope.row, 'docsnf')" :customModifykey="'docpan.doceot.' + scope.$index + '.docsnf'" dbCode="docsnf" placeholder="请选择" :filterKey="scope.row.cortyp === 'LET'?['LET','LETAML','LETCOU']:undefined" style="width: 100%">
            </c-select>
          </template>
        </el-table-column>
        <!-- <el-table-column label="语言" width="150px">
					<template slot-scope="scope">
							<c-select
								@change="customAddModify(scope.row, 'docuil')"
								:customModifykey="'docpan.doceot.' + scope.$index + '.docuil'"
								dbCode="uiltxt1"
								placeholder="请选择"
								style="width: 100%"
								v-model="scope.row.docuil">
							</c-select>
					</template>
				</el-table-column> -->
        <el-table-column label="传送方式" width="110px">
          <template slot-scope="scope">
            <el-form-item :prop="'docpan.doceot.' + scope.$index + '.apf'" label-width="0">
              <c-select :isFixed="true" @change="customAddModify(scope.row, 'apf')" :customModifykey="'docpan.doceot.' + scope.$index + '.apf'" dbCode="apftxt" disabled placeholder="请选择" style="width: 100%" v-model="scope.row.apf">
              </c-select>
            </el-form-item>
          </template>
        </el-table-column>
        <!-- <el-table-column label="发送份数" width="70">
						<template slot-scope="scope">
							<c-input :readonly="true" placeholder="请选择" style="width: 100%" v-model="scope.row.apfcpy1">
							</c-input>
						</template>
				</el-table-column>
				<el-table-column label="抄送份数" width="70">
					<template slot-scope="scope">
						<c-input @change="customAddModify(scope.row, 'apfcpy2')" :customModifykey="'docpan.doceot.' + scope.$index + '.apfcpy2'"
											placeholder="请选择" style="width: 100%" v-model="scope.row.apfcpy2">
						</c-input>
					</template>
				</el-table-column> -->
        <el-table-column label="报文加押标志" width="" header-align="left">
          <template slot-scope="scope">
            <el-form-item :prop="'docpan.doceot.' + scope.$index + '.staflg'" label-width="0" style="width:300px">
              <c-select :isFixed="true" @change="customAddModify(scope.row, 'staflg')" :customModifykey="'docpan.doceot.' + scope.$index + '.staflg'" :disabled="scope.row.docsnf !=='SWT999' " :filterKey="['M']" dbCode="swttlx" placeholder="请选择" style="width: 100%" uil="EN" v-model="scope.row.staflg">
              </c-select>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="240px">
          <template slot-scope="scope">
            <div style="text-align:left">
              <el-button :disabled="scope.row.delflg==='D'" @click="handleDisplay(scope.$index, scope.row)" size="small" type="primary">
                预览
              </el-button>
              <el-button :disabled="scope.row.delflg==='D' || noPrint" @click="printContent(scope.$index, scope.row)" size="small" style="margin-left: 10px;" type="primary">
                打印
              </el-button>
              <c-button @click="active(scope.$index, scope.row)" size="small" :style="{'margin-left': '10px','border-bottom':showButtonColor(scope.row)}" :type="scope.row.delflg==='D'?'primary':''">
                {{scope.row.delflg==='D' ? "启用":"屏蔽"}}
              </c-button>
              <el-button :disabled="scope.row.delflg==='D' || isDispaly" v-if="scope.row.cortyp === 'LET'" @click="handleLETDetail(scope.$index, scope.row)" size="small" style="margin-left: 10px;" type="primary">
                详情
              </el-button>
              <el-button :disabled="scope.row.delflg==='D' || isDispaly" v-if="scope.row.cortyp === 'SWT'" @click="handleSWTDetail(scope.$index, scope.row)" size="small" style="margin-left: 10px;" type="primary">
                详情
              </el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
    </c-col>
    <c-col :span="24" style="margin-top:20px">
      <c-collapse v-model="activeNames">
        <el-collapse-item title="关联报文/面函" name="fft">
          <smh-message :objtyp="smhObjtyp" :objinr="smhObjinr" :smhinr="getSmhinr"></smh-message>
        </el-collapse-item>
        <el-collapse-item title="LOA/NOA报文" name="fftmsg" v-if="isVisibledFftBund">
          <fft-message :objtyp="smhObjtyp" :objinr="smhObjinr" :ownref="getOwnref" :bpdinr="getBpdinr" :ordinr="getOrdinr"></fft-message>
        </el-collapse-item>
      </c-collapse>
    </c-col>
    <!-- 预览弹框 -->
    <message-view ref="msgView" :model="model" :ownref="objInfo.ownref"></message-view>
    <!-- 详情弹框 -->
    <!-- <docpan-dialog :docpanDialog="docpanDialog" @docpanQueryFunc="docpanQueryFunc" ref="docpanDialog" /> -->

    <!-- SWT详情弹框 -->
    <swift-dialog :docpanDialog="docpanDialog" @docpanQueryFunc="docpanQueryFunc" ref="swtDocpanDialog" />
    <letter-dialog :docpanDialog="docpanDialog" @docpanQueryFunc="docpanQueryFunc" ref="letDocpanDialog" />

  </c-row>
</template>
<script>
import Api from "~/service/Api";
import commonDepend from "~/mixin/commonDepend.js";
// import DocpanDialog from "./DocpanDialog.vue";
import SwiftDialog from "./SwiftDialog";
import LetterDialog from "./LetterDialog";

import { cloneDeep } from "lodash";
import MessageView from "./MessageView";
import SmhMessage from "./SmhMessage";
import FftBundMessage from "./FftBundMessage";
import Print from "print-js";
import { setTimeout, setInterval, clearInterval } from "timers";
import event from "../event";

export default {
  inject: ["root"],
  mixins: [commonDepend, event],
  components: {
    MessageView,
    SmhMessage,
    SwiftDialog,
    LetterDialog,
    "fft-message": FftBundMessage
  },
  props: ["model", "codes"],
  data() {
    return {
      index: 0,
      docpanIndex: 0,
      docpanDialog: {},
      centerDialogVisible: true,
      activeNames: ["fft", "fftmsg"]
    };
  },
  computed: {
    isDispaly() {
      return this.$store.state.Status.mode === "display";
    },
    objInfo() {
      return this.root.buildCommonData(this.model, this.root.transName).rec;
    },
    noPrint() {
      return this.isDispaly && this.$route.query.noPrint == "Y";
    },
    smhObjtyp() {
      //如果子业务新开,则取父业务的
      //兼容一期保函
      if (this.objInfo.objinr == "" && this.objInfo.gidinr) {
        return "GID";
      }
      if (this.objInfo.objinr == "" && this.objInfo.nidinr) {
        return "NID";
      }
      //二期新开,取父业务
      if (this.objInfo.objinr == "" && this.objInfo.pnttyp) {
        return this.objInfo.pnttyp;
      }
      return this.objInfo.objtyp;
    },
    smhObjinr() {
      //如果子业务新开,则取父业务的
      //兼容一期保函
      if (this.objInfo.objinr == "" && this.objInfo.gidinr) {
        return this.objInfo.gidinr;
      }
      if (this.objInfo.objinr == "" && this.objInfo.nidinr) {
        return this.objInfo.nidinr;
      }
      //二期新开,取父业务
      if (this.objInfo.objinr == "" && this.objInfo.pntinr) {
        return this.objInfo.pntinr;
      }
      return this.objInfo.objinr;
    },
    getSmhinr() {
      //当前交易来报smhinr
      return this.model.spt ? this.model.spt.smhinr : "";
    },
    getOrdinr() {
      //当前交易来报smhinr
      return this.model.spt ? this.model.spt.ordinr : "";
    },
    getOwnref() {
      return this.model.bpdgrp.rec.ownref ? this.model.bpdgrp.rec.ownref : "";
    },
    getBpdinr() {
      return this.model.bpdgrp.rec.inr ? this.model.bpdgrp.rec.inr : "";
    },
    isVisibledFftBund() {
      if (this.model.bpdgrp && this.model.bpdgrp.rec.fortyp === "2") {
        return true;
      } else {
        return false;
      }
    }
  },
  methods: {
    handleDisplay(index, row) {
      this.$refs.msgView.handleDisplay(index, row);
    },
    printContent(index, row) {
      this.$refs.msgView.printContent(index, row);
    },
    // 详情
    handleSWTDetail(index, row) {
      this.docpanIndex = index;
      this.$refs.swtDocpanDialog.centerDialogVisible = true;
      this.docpanDialog = cloneDeep(row);
      this.$nextTick(() => {
        this.$refs.swtDocpanDialog.init();
      });
    },
    // 详情
    handleLETDetail(index, row) {
      this.docpanIndex = index;
      this.$refs.letDocpanDialog.centerDialogVisible = true;
      this.docpanDialog = cloneDeep(row);
      this.$nextTick(() => {
        this.$refs.letDocpanDialog.init();
      });
    },
    //详情回调
    docpanQueryFunc(val) {
      if (val.modifySet) {
        val.modifySet.forEach(element => {
          this.customAddModify(this.model.docpan.doceot[this.docpanIndex], element);
        });
      }
      this.$set(this.model.docpan.doceot[this.docpanIndex], "addtxt", val.addtxt);
      this.$set(this.model.docpan.doceot[this.docpanIndex], "addstr", val.addstr);
      this.$set(this.model.docpan.doceot[this.docpanIndex], "adrblk", val.adrblk);
      this.$set(this.model.docpan.doceot[this.docpanIndex], "tag79z", val.tag79z);
      if (val.cortyp === 'SWT') {
         if (this.model.docpan.doceot[this.docpanIndex].ptainr !== val.ptainr) {
           this.$set(this.model.docpan.doceot[this.docpanIndex], "ptainr", val.ptainr);
           //重新试算报文面函
           this.processTrndoc();
         }
      }
    },
    active(index, row) {
      if (row.delflg == "D") {
        row.delflg = " ";
      } else {
        row.delflg = "D";
      }
      this.customAddModify(row, "mdtflg");
      this.customAddModify(row, "delflg");
    },
    showButtonColor(tempObj){
      if(!this.isDispaly){
        return undefined
      }
      let propKey = 'delflg'
      if (tempObj.markSet && tempObj.markSet.length > 0 && tempObj.markSet.includes(propKey)) {
						return '3px solid red'
			}
			if (tempObj.markSetX && tempObj.markSetX.length > 0 && tempObj.markSetX.includes(propKey)) {
						return '3px solid green'
			}
    }
  },
  created() {}
};
</script>