<template>
	<div class="eibs-tab">
		<c-col :span="24">
			<c-col :span="12" style="padding-right: 20px;">
				<c-col :span="24">
					<c-ptap :model="model" :isAdrblk="false" :haveAdrLabel="true" :disabled="true" :requiredExtkey="true" :argadr="{ title: $t('ptap.申请人'), grp: 'fcdgrp', rol: 'apl'}" ptytyp="C" @handleChange="getCshVoList" chooseLanguage="CN"></c-ptap>
					<!--					<c-ptap :argadr="{title: '申请人', grp: 'fcdgrp', rol: 'apl'}" :disabled="true" :haveAdrLabel="true" :iAdrblk="false" :model="model" :noRef='true' @handleChange="getCshVoList" adrKey="nam" bchinr='00000047' ptytyp="C"></c-ptap>-->
				</c-col>
				<c-col :span="24">
          <el-form-item>
            <div style="width: 100%;display: flex;justify-content: flex-start;">
              <div style="flex: 1;display: flex;justify-content: flex-start;">
                <c-checkbox @change="getCshVoList" false-label="N" true-label="Y" v-model="model.errflg">已使用保证金
                </c-checkbox>
                <c-checkbox false-label="N" true-label="Y" v-model="model.gleflg">是否过账</c-checkbox>
              </div>
              <c-button @click="exportExcel" v-if="model.errflg === 'Y'" class="medium_bcs" size="medium" type="success">
                导出Excel
              </c-button>
            </div>
          </el-form-item>
				</c-col>
			</c-col>

			<c-col :span="12" style="padding-left: 20px;">
				<c-col :span="24">
					<el-form-item label="业务编号" prop="fcdgrp.rec.ownref">
						<c-input disabled maxlength="16" placeholder="请输入业务编号" v-model="model.fcdgrp.rec.ownref"></c-input>
					</el-form-item>
				</c-col>
				<c-col :span="24">
					<el-form-item label="说明" prop="fcdgrp.rec.reason">
						<c-input disabled maxlength="40" placeholder="请输入说明" v-model="model.fcdgrp.rec.reason"></c-input>
					</el-form-item>
				</c-col>
				<c-col :span="24">
					<c-col :span="12">
						<el-form-item label="保证金金额" prop="fcdgrp.rec.cur">
							<c-select disabled placeholder="请选择币种" style="width: 100%" v-model="model.fcdgrp.rec.cur">
							</c-select>
						</el-form-item>
					</c-col>
					<c-col :span="12">
						<el-form-item label-width="5px" prop="fcdgrp.rec.amt">
							<c-input-currency :currency="model.fcdgrp.rec.cur" disabled placeholder="请输入金额" v-model="model.fcdgrp.rec.amt"></c-input-currency>
						</el-form-item>
					</c-col>
				</c-col>

				<c-col :span="24">
					<c-col :span="12">
						<el-form-item label="保证金账号" prop="fcdgrp.rec.extact">
							<c-input disabled maxlength="8" v-model="model.fcdgrp.rec.extact"></c-input>
						</el-form-item>
					</c-col>
					<c-col :span="12">
						<el-form-item label="" label-width="5px" prop="fcdgrp.rec.engact">
							<c-input disabled maxlength="16" v-model="model.fcdgrp.rec.engact"></c-input>
						</el-form-item>
					</c-col>
				</c-col>
			</c-col>

		</c-col>

		<c-col :span="24">
			<el-table :data="model.cshVoList" @row-click="handleRowClick" highlight-current-row size="medium" style="width:100%" v-loading="load">
				<!-- <el-table-column align="left" label="" prop="extact" width="150" /> -->
				<!-- <el-table-column align="left" label="INR" prop="inr" width="150" /> -->
				<el-table-column align="left" label="业务编号" prop="ownref" min-width="150px" />
				<el-table-column align="left" label="收取日期" prop="credat" min-width="150px" />
				<el-table-column align="left" label="币种" prop="cur" min-width="100px" />
				<el-table-column align="left" label="金额" prop="amt" min-width="100px">
					<template slot-scope="scope">
						<span> {{moneyFormat(scope.row.amt, scope.row.cur) }}
						</span>
					</template>
				</el-table-column>
				<el-table-column align="left" label="保证金账号" prop="engact" min-width="200px" />
				<el-table-column align="left" :formatter="formatGleflg" label="是否过账" prop="gleflg" min-width="150px" />
				<el-table-column align="left" :formatter="formatRelflg" label="是否到账" prop="relflg" min-width="150px" />
				<el-table-column align="left" :formatter="formatUseflg" label="是否被用" prop="useflg" min-width="150px" />
				<el-table-column align="left" label="说明" prop="reason" min-width="150px" />
				<!-- 要不要 -->
				<el-table-column align="left" label="被用在交易" prop="regref" v-if="this.model.errflg==='Y'" min-width="200px" />
				<el-table-column fixed="right" label="操作" v-if="this.model.errflg==='Y'">
					<template slot-scope="scope">
						<el-button @click="handleChange(scope.$index, scope.row)" size="mini">更改状态
						</el-button>
					</template>
				</el-table-column>
			</el-table>
      <el-pagination layout="total, sizes, prev, pager, next, jumper" :total="pagination.total" :page-size="pagination.pageSize" :current-page="pagination.pageNum" @size-change="handleSizeChange" @current-change="currentChange">
      </el-pagination>
		</c-col>
	</div>
</template>
<script>
import event from "../event";

export default {
  inject: ["root"],
  props: ["model", "codes"],
  mixins: [event],
  data() {
    return {
      load: false,
      pagination: {
        pageNum: 1,
        pageSize: 10,
        total: 0
      },
    };
  },
  methods: {
    handleRowClick(val) {
      this.model.fcdgrp.rec.inr = val.inr;
      this.model.fcdgrp.rec.ownref = val.ownref;
      this.model.fcdgrp.rec.reason = val.reason;
      this.model.fcdgrp.rec.cur = val.cur;
      this.model.fcdgrp.rec.amt = val.amt;
      this.model.fcdgrp.rec.extact = val.extact;
      this.model.fcdgrp.rec.engact = val.engact;
      // 处理点击事件
      console.log(this.model.errflg);
      if (this.model.errflg === "Y") {
        this.$emit("update-disabled", true); // 向父组件发送事件,更新isDisabled状态
      } else {
        this.$emit("update-disabled", false); // 向父组件发送事件,更新isDisabled状态
      }
    },
    handleChange(index, row) {
      this.open();
    },
    open() {
      this.$confirm("确定要更新保证金使用状态?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.change().then(rtnmsg => {
            if (rtnmsg.respCode === SUCCESS) {
              this.$message({
                type: "success",
                message: "更新成功!"
              });
            } else {
              this.$message({
                type: "error",
                message: "更新失败!"
              });
            }
          });
          this.getCshVoList();
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消"
          });
        });
    },
    formatGleflg(row, column) {
      if (row.gleflg === "Y") return "是";
      if (row.gleflg === "N") return "否";
    },
    formatRelflg(row, column) {
      if (row.relflg === "Y") return "是";
      if (row.relflg === "N") return "否";
    },
    formatUseflg(row, column) {
      if (row.useflg === "U") return "是";
      if (row.useflg === "N") return "否";
    }
  },
  created: function() {}
};
</script>
<style>
</style>