<template>
 <el-dialog v-dialogDrag width="80%" title="分行业务详情" v-if="parentsVisiable" :visible.sync="parentsVisiable" :append-to-body="true" :modal-append-to-body="false" :before-close="handleClose" destroy-on-close>
	<div class="eContainer">
		<c-page title="分行业务详情">
			<c-content :height="120">
				<div class="eibs-tab">
					<el-form :model="model" ref="modelForm" tokenKey="modelForm" :validate-on-rule-change="false" label-width="150px" size="small">
						<div>
							<c-content>
								<c-col :span="24" style="height: 24px">
									<el-form-item label="基本信息" class="messageLabel">
									</el-form-item>
								</c-col>
								<c-col :span="24" style="height: 10px; margin-bottom: 10px">
									<el-divider></el-divider>
								</c-col>
								<!-- ==================  基础信息  ============ -->
								<!-- ========================= Left ========================= -->
								<c-col :span="11">
									<c-col :span="24">
										<el-form-item label="业务编号">
											<c-input v-model="trn.ownref" maxlength="16" disabled ></c-input>
										</el-form-item>
									</c-col>

									<c-col :span="24">
										<el-form-item label="交易代码">
											<c-input v-model="trn.inifrm" maxlength="6" disabled ></c-input>
										</el-form-item>
									</c-col>

									<c-col :span="24">
										<c-col :span="13">
											<el-form-item label="业务金额">
												<c-input v-model="trn.reloricur" maxlength="3" disabled></c-input>
											</el-form-item>
										</c-col>
										<c-col :span="11">
											<el-form-item label="" label-width="8px">
												<c-input v-model="trn.reloriamt" disabled ></c-input>
											</el-form-item>
										</c-col>
									</c-col>

									<c-col :span="24">
										<el-form-item label="经办柜员">
											<c-input v-model="trn.usr" maxlength="8" disabled ></c-input>
										</el-form-item>
									</c-col>
								</c-col>

								<!-- ========================= Right ========================= -->
								<c-col :span="11" :offset="1">
									<c-col :span="24">
										<el-form-item label="交易名称">
											<c-input v-model="trn.inifrmname" maxlength="6" disabled ></c-input>
										</el-form-item>
									</c-col>

									<c-col :span="24">
										<el-form-item label="摘要信息">
											<c-input v-model="trn.objnam" maxlength="40" disabled placeholder="请输入"></c-input>
										</el-form-item>
									</c-col>

									<c-col :span="24">
										<el-form-item label="业务状态">
											<c-select v-model="trn.relflg" dbCode="relsta" style="width: 100%" disabled>
											</c-select>
										</el-form-item>
									</c-col>
                  <c-col :span="24">
											<el-form-item label="创建时间">
												<c-input v-model="trn.inidattim" disabled placeholder="请输入时间戳"></c-input>
											</el-form-item>
									</c-col>
								</c-col>

                	<!-- =====================document======================== -->
								<c-col :span="24" style="height: 24px">
									<el-form-item label="面函/报文" class="messageLabel">
									</el-form-item>
								</c-col>
								<c-col :span="24" style="height: 0px; margin-top: -5px">
									<el-divider></el-divider>
								</c-col>
								<c-col :span="24">
                    <el-table :data="smhList.data" :columns="smhList.columns" :highlight-current-row="true" :paginationShow="false" style="width: 100%">
											<el-table-column label="序号" width="80px">
												<template slot-scope="scope">
													{{ scope.$index+1 }}
												</template>
											</el-table-column>
											<el-table-column v-for="(item, index) in smhList.columns" :label="item.label" :prop="item.prop" :key="index" :width="item.width">
											</el-table-column>
										<el-table-column label="操作" width="200px" fixed="right">
											<template slot-scope="scope">
												<c-button type="primary" size="small"  @click="showMsg(scope.row)" disabled style="margin-right: 10px">显示</c-button>
											</template>
										</el-table-column>
									</el-table>
								</c-col>

                	<!-- 经办复核 -->
								<c-col :span="24" style="height: 24px; margin-top: 20px">
									<el-form-item label="经办/复核" class="messageLabel">
									</el-form-item>
								</c-col>
								<c-col :span="24" style="height: 0px; margin-top: -5px">
									<el-divider></el-divider>
								</c-col>
								<c-col :span="24">
									<c-col :span="24" :offset="0">
										<el-table :data="trsList.data" :columns="trsList.columns" :highlight-current-row="true" :paginationShow="false" style="width: 100%">
											<el-table-column label="序号" width="80px">
												<template slot-scope="scope">
													{{ scope.$index+1 }}
												</template>
											</el-table-column>
											<el-table-column v-for="(item, index) in trsList.columns" :label="item.label" :prop="item.prop" :key="index" :width="item.width">
											</el-table-column>
										</el-table>
									</c-col>
								</c-col>

 								<div v-if="wfeList.data && wfeList.data.length>0">
                
								<!-- ============  workflow =============  -->
								<c-col :span="24" style="height: 24px; margin-top: 20px">
									<el-form-item label="工作流服务" class="messageLabel">
									</el-form-item>
								</c-col>
								<c-col :span="24" style="height: 0px; margin-top: -5px">
									<el-divider></el-divider>
								</c-col>
								<c-col :span="24">
									<c-col :span="24" :offset="0">
										<el-table :data="wfeList.data" :highlight-current-row="true" :paginationShow="false" style="width: 100%">
                      	<el-table-column label="序号" width="80px">
												<template slot-scope="scope">
													{{ scope.$index+1 }}
												</template>
											</el-table-column>
											<el-table-column v-for="(item, index) in wfeList.columns" :label="item.label" :prop="item.prop" :key="index" :width="item.width">
												<template slot-scope="scope">
                          	<span v-if="item.prop==='srv'">
														{{ getCodelabel(scope.row[item.prop],"srvtxt") }}
													</span>
													<span v-else-if="item.prop==='sta'">
														{{ formatter(scope.row[item.prop]) }}
													</span>
													<span v-else>
														{{ scope.row[item.prop] }}
													</span>
												</template>
											</el-table-column>
										</el-table>
									</c-col>
								</c-col>
                </div>

                <!-- =====================分录======================== -->
                <div v-if="gleData.data && gleData.data.length>0">
								<c-col :span="24" style="height: 24px">
									<el-form-item label="分录" class="messageLabel">
									</el-form-item>
								</c-col>
								<c-col :span="24" style="height: 0px; margin-top: -5px">
									<el-divider></el-divider>
								</c-col>
								<c-col :span="24">
                  	<el-table :data="gleData.data" :columns="gleData.columns" :highlight-current-row="true" :paginationShow="false" style="width: 100%">
											<el-table-column label="序号" width="80px">
												<template slot-scope="scope">
													{{ scope.$index+1 }}
												</template>
											</el-table-column>
											<el-table-column v-for="(item, index) in gleData.columns" :label="item.label" :prop="item.prop" :key="index" :width="item.width">
											</el-table-column>
										</el-table>
                </c-col> 
                	<!-- -------------------会计传票------------------- -->
								<c-col :span="24" style="height: 24px; margin-top: 20px">
									<el-form-item label="会计传票" class="messageLabel">
									</el-form-item>
								</c-col>
								<c-col :span="24" style="height: 0px; margin-top: -5px">
									<el-divider></el-divider>
								</c-col>
								<c-col :span="24">
                  	<el-table :data="bookData.data" :columns="bookData.columns" :highlight-current-row="true" :paginationShow="false" style="width: 100%">
											<el-table-column label="序号" width="80px">
												<template slot-scope="scope">
													{{ scope.$index+1 }}
												</template>
											</el-table-column>
											<el-table-column v-for="(item, index) in bookData.columns" :label="item.label" :prop="item.prop" :key="index" :width="item.width">
											</el-table-column>
                      	<el-table-column label="操作" width="140px" fixed="right">
                            <template slot-scope="scope">
                              <c-button type="primary" size="small" 
                                @click="showPz(scope.row)" style="margin-right: 10px">显示</c-button>
                            </template>
										</el-table-column>
										</el-table>
                </c-col> 
                 </div>   
							</c-content>
						</div>
					</el-form>
					<div class="btn-wrap">
						<c-button size="small" type="primary" style="margin-left: 12" @click="handleDisplay">分行交易快照</c-button>
            <!-- <c-button	size="small"  type="primary" style="margin-left: 12"	@click="onNodeStatus">交易节点</c-button> -->
						<c-button size="small" @click="handleClose" type="primary" style="margin-left: 10px">返回</c-button>
					</div>
				</div>
			</c-content>
		</c-page>
	</div>
 </el-dialog>
</template>
    
<script>
import Trnrel from "../model";
import Api from "~/service/Api";
import event from "../event";
import commonFunctions from "~/mixin/commonFunctions.js";
import MtView from "~/components/business/MtView";
import { log } from "util";
import { display } from "~/service/business/file";

export default {
  provide() {
    return {
      root: this
    };
  },
  name: "parentsDetail",
  props: {
		parentsVisiable: {
			type: Boolean,
			default: false
    },
    parentsInfo: {
      type: Object,
      default: () => {}
    },
	},
  mixins: [event, commonFunctions],
  components: { MtView},
  data() {
    return {
      model: new Trnrel().data,
      previewDetailVisible:false,
      trninr:"",
      inifrm:"",
      trn: {},
       gleData: {
        columns: [
          { label: "账号", prop: "act",width:"210px" },
          { label: "借/贷", prop: "dbtcdt",width: "60px" },
          { label: "币种", prop: "cur",width:"110px" },
          { label: "金额", prop: "amt",width:"210px" },
          { label: "牌价类型", prop: "status" ,width:"110px"},
          { label: "牌价", prop: "rat",width:"210px"},
          { label: "客户编号", prop: "cliextkey",width:"110px"},
          { label: "收入", prop: "income"}
        ],
        data: []
      },
       bookData: {
        columns: [
          { label: "传票类型", prop: "pzName",width:"140px" },
          // { label: "客户号", prop: "ptyExtkey",width: "140px" },
          // { label: "客户名称", prop: "ptyName",width:"160px" },
          { label: "账号", prop: "ptyAct",width:"160px" },
          { label: "科目", prop: "trmcod" ,width:"110px"},
          { label: "币种", prop: "cur",width:"110px"},
          { label: "金额", prop: "amt",width:"140px"},
          { label: "创建日期", prop: "createDt",width:"160px"},
           { label: "摘要", prop: "gleRemark"}
        ],
        data: []
      },
      smhList: {
        columns: [
          { label: "角色", prop: "name",width:"110px" },
          { label: "描述", prop: "extkey",width:"210px" },
          { label: "介质", prop: "cortyp",width:"110px" },
          { label: "报文格式", prop: "docsnf",width:"110px" },
          { label: "传送方式", prop: "apf" }
        ],
        data: []
      },
      trsList: {
        columns: [
          { label: "类型", prop: "sigidx" ,width:"110px" },
          { label: "用户", prop: "nam" ,width:"160px" },
          { label: "工号", prop: "usr" ,width:"180px" },
          { label: "日期/时间", prop: "dattim" }
        ],
        data: []
      },
      wfeList: {
        columns: [
          { label: "服务", prop: "wfssub" ,width:"110px" },
          { label: "名称", prop: "srv" ,width:"110px" },
          { label: "交易状态", prop: "sta" ,width:"110px" },
          { label: "最新更新", prop: "dattim" ,width:"180px" },
          { label: "重试", prop: "retdur" ,width:"110px" },
          {label: "目标时间",prop: "tardattim",width:"180px" },
          { label: "备注1", prop: "txt" ,width:"310px" },
          { label: "备注2", prop: "txt2"  }
        ],
        data: []
      },
       dbCodes:{
        srvtxt:[]
      },
      flg: [],
      atptxt: "",
      relstaEN: "",
			usgtxt: "",
			textContext:"",
			previewType:"",
      suppress:"",
      formatData:{}
    };
  },
  mounted() {
    this.getdbCode('srvtxt','','srvtxt');
  },
  created(){
  },
  watch: {
		parentsVisiable(newVal) {
			if (newVal) {
        this.trninr=this.parentsInfo.trninr;
        this.inifrm=this.parentsInfo.inifrm.toLowerCase();
        this.parentsVisiable = true;
        if(this.trninr){
          this.loadData();
        }
			}
		}
  },
  methods: {
    onNodeStatus(){  
       this.$parent.onNodeStatus(this.trninr)
    },
    handleClose(){
        	this.$emit('closeDialog')
    },
    async getdbCode(codeType, uil, codeNam) {
        let params = {
          codeType: codeType,
          uil: uil ? uil : 'EN'
        }
        let rtnmsg = await Api.post("/manager/dic/listDicInfo", params)
        if (rtnmsg.respCode === SUCCESS) {
          let srvtxt = rtnmsg.data.map(item => ({
            value: item.codeValue,
            label: item.codeName
          }));
          this.dbCodes[codeNam] = srvtxt
        }
      },
     async showMsg(row){
       this.$confirm('面函非最终版本,是否查看?', '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning',
			}).then(()=>{
        this.$parent.showMsg(row);
      })
    },
     async showPz(row){
        this.$parent.showPz(row);
    },
    async handleDisplay() {
      this.$parent.parentsVisiable=false;
      let inr = this.trninr;
      let inifrm = this.inifrm;
      let businessType = 'TRN';
			const loading = this.loading("快照数据加载中");
			this.routerPush({
				path: `/display/${inifrm}`,
				query: {
					businessInr: inr,
          businessType: businessType,
          noPrint:'Y'
				}
			});
    },
    async loadData() {
      let params = {
        trninr: this.trninr,
        trnType:"branch"
      };
      const loading = this.loading();
      const rtnmsg = await Api.post("/public/quesel/getDetailInfo", params);
      if (rtnmsg.respCode == SUCCESS) {
        this.trn = rtnmsg.data.trn;
        let relflg=rtnmsg.data.trn.relflg;
        switch(rtnmsg.data.trn.relflg){
          case "A":
            relflg="收单行已复核";
            break;
          case "B":
            relflg="总行已经办";
              break;
          case "D":
            relflg="收单行已完结";
            break;

        }
        this.trn.relflg=relflg;
        rtnmsg.data.gleList.forEach(item=>{
           item.status="Stored"
        })
        this.gleData.data = rtnmsg.data.gleList;
         this.bookData.data = rtnmsg.data.gleBookList;
        if(rtnmsg.data.smhList){
            rtnmsg.data.smhList.forEach((item)=>{
                  item.name=item.nam.substring(0,3)
                  item.extkey=item.nam.substring(4);
                  item.docsnf=item.cortyp==='LET'?'simple letter':"";
                  item.apf=item.cortyp==='LET'?'Letter':'Swift';
            })
        }
        this.smhList.data=rtnmsg.data.smhList;
        this.trsList.data = rtnmsg.data.trsList;
        this.wfeList.data = rtnmsg.data.wfeList;
      }
      loading.close();
    },
    getCodelabel(value,codenam) {
        const codeobj = this.dbCodes[codenam].find(obj => obj.value === value)
        return codeobj ? codeobj.label : value;
  },
    formatter(val) {
      let label;
      let wfetrssta = [
        { label: "Done", value: "D" },
        { label: "发布", value: "1" },
        { label: "Cancel", value: "C" },
        { label: "Error", value: "E" },
        { label: "Open", value: "O" },
        { label: "建立", value: "6" },
        { label: "Waiting", value: "W" },
        { label: "拒绝", value: "2" },
        { label: "有效", value: "A" },
        { label: "外部确认", value: "5" },
        { label: "Skip", value: "S" },
        { label: "需求修改", value: "3" },
        { label: "创建时签名", value: "4" },
        { label: "Retry", value: "R" }
      ];
      for (let i of wfetrssta) {
        if (i.value === val) {
          label = i.label;
          break;
        }
      }
      return label;
    },
    async handleDetail(index, row) {
      const params = {
        index: row.idx
      };
      let rtnmsg = await Api.post(
        `${this.requestPrefix}/executeDocpanDetail`,
        params
      );
      if (rtnmsg.respCode == SUCCESS) {
        this.title = row.pandsc;
        (this.centerDialogVisible = true), this.updateModel(rtnmsg.data);
        this.dialog = this.docpan.doceot[row.idx];
        this.index = row.idx;
      }
    },
    async show(idx, row) {
      var params = {
        selDst: "recpan.smhstm",
        selIds: [idx + 1],
        selBtnId: "A"
      };
      let rtnmsg = await Api.post(
        `/business/trnrel/executeRule/recpan.smhstm`,
        this.wrapper(params)
      );
      if (rtnmsg.respCode == SUCCESS) {
        this.title = "面函";
        let viewurl = "/#/docpan/show";
        let XMLdata;
        if (row.类型 == "LET") {
          window.sessionStorage.docTXT = "";
          window.sessionStorage.docXML = rtnmsg.data.docimm_xmldocblk;
        } else if (row.pandsc == "MT799") {
          window.sessionStorage.docTXT = "";
          XMLdata = rtnmsg.data.litbenl1blk;
        }
        window.open(
          viewurl,
          "newwindow",
          "height=1200,width=800,top=100,left=100,toolbar=no,resizable=no,menubar=no,location=no, status=no"
        );
      } else {
        const h = this.$createElement;
        const msg = rtnmsg.respMsg || "请求执行失败!";
        this.$notify.error({
          title: "错误",
          message: h("p", { style: "word-break:break-all;" }, msg)
        });
      }
    }
  }
};
</script>
<style scoped lang="less">
.messageLabel {
	/deep/ .el-form-item__label {
		text-align: left;
		font-weight: bold;
		font-size: 15px;
		color: #1561e0;
		width: auto !important;
	}
}
#business_container {
	.eContainer {
		.c-page-container-div {
			.eibs-tab {
				/deep/ .el-form {
					height: calc(100% - 64px)!important;
				}
			}
		}
	}
}
.eibs-tab {
	/deep/ .el-divider--horizontal {
		margin-top: 10px;
	}
	/deep/ .el-form-item__label {
		text-align: left;
		font-weight: bold;
	}
	/deep/ .el-col {
		.el-divider--horizontal {
			margin-top: 5px;
		}
	}
	/deep/ .el-form {
		overflow: auto!important;
		margin-bottom: 0!important;
		.el-form-item {
			margin-bottom: 10px;
		}
	}
	.btn-wrap {
		padding: 10px 0px;
		display: flex;
		justify-content: center;
		background: #fff;
		box-shadow: var(--box-shadow);
	}
}
.fot{
  position: fixed;
  bottom: 0;
  width: 100%;
  line-height: var(--footer-height);
  color: #fff;
}
</style>