<template>
  <div class="app-container zap-main">
    <div class="zap-content zap-margin-top">
      <el-button
        type="primary"
        icon="el-icon-plus"
        @click="handleAdd"
        >添加虚拟账户</el-button>
    </div>
    <el-table class="zap-table" v-loading="loading" :data="accList" @selection-change="handleSelectionChange" stripe>
      <el-table-column label="序号" type="index" width="55" align="center" />
      <el-table-column label="开户行" align="center" prop="paiBankName" />
      <el-table-column label="账户类型" :formatter="formulaFormat" align="center" prop="paiAcctype"/>
      <el-table-column label="账户卡号" align="center" prop="paiAccno" />
      <el-table-column label="账户状态" :formatter="formulaFormatSend" align="center" prop="paiStatus"/>
      <!-- <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['admin:accInf:delete']"
            >删除</el-button
          >
        </template>
      </el-table-column> -->
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加虚拟账户 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px" :inline="true">
        <el-form-item prop="paiBankName" label="开户银行" size="large">
          <el-select
            @change="changePayer"
            v-model="form.paiBankName"
            :disabled="disableds"
            filterable
            clearable
            remote
            reserve-keyword
            placeholder="请选择开户银行"
            :remote-method="getBankList"
          >
            <el-option
              v-for="(item, index) in bankList"
              :key="index"
              :label="item.zcbiBankName"
              :value="item.zcbiBankName"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="法人姓名" prop="scyLegal" size="large">
          <el-input v-model="form.scyLegal"  style="width: 215px" placeholder="请输入法人姓名" maxlength="15" readonly/>
        </el-form-item>
        <el-form-item label="法人手机号" prop="scyPhone" size="large">
          <el-input v-model="form.scyPhone"  style="width: 215px" placeholder="请输入法人手机号" maxlength="15" readonly/>
        </el-form-item>
        <el-form-item label="身份证号" prop="scyLegalId" size="large">
          <el-input v-model="form.scyLegalId"  style="width: 215px" placeholder="请输入身份证号" maxlength="15" readonly/>
        </el-form-item>
        <el-form-item label="邮箱" prop="email" size="large">
          <el-input v-model="form.email"  style="width: 215px" placeholder="请输入邮箱" maxlength="15" readonly/>
        </el-form-item>
        <el-form-item label="企业名称" prop="scyName" size="large">
          <el-input v-model="form.scyName"  style="width: 215px" placeholder="请输入企业名称" maxlength="15" readonly/>
        </el-form-item>
        <el-form-item label="企业注册地址" prop="scyAddress" size="large">
          <el-input v-model="form.scyAddress"  style="width: 215px" placeholder="请输入企业注册地址" maxlength="15" readonly/>
        </el-form-item>
      </el-form>
      <el-row style="height: 109px" type="flex" align="middle" justify="center">
        <el-button type="primary" plain @click="cancel">取 消</el-button>
        <el-button type="primary" @click="submitForm">确 定</el-button>
      </el-row>
    </el-dialog>
  </div>
</template>

<script>
import { listAdminAcc,listCorporation} from "@/api/system/adminAccInf";
import { listBank } from "@/api/system/accInf";
import { register } from "@/api/bank/bankInterface";
import { release } from 'os';
import Cookies from 'js-cookie';
export default {
  name: "accInf",
  data() {
    return {
      //可用余额
      KYAMT: null,
      //电子账户
      accno: null,
      // id隐藏
      isShow: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      //联系人隐藏
      disabled: false,
      disableds: false,
      // 总条数
      total: 0,
      // 账户表格数据
      accList: [],
      //账户卡号数据
      cardList: [],
      //姓名
      nameList: [],
      bankList: [],
      //字典
      formulaOptions: [],
      formulaOptionsSend: [],
      UserList: [],
      enclosureList: [],
      sfzList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否显示弹出层
      edit: false,
      // 是否显示弹出层
      recharge: false,
      // 是否显示弹出层
      withdrawal: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        scyName: null,
        smiType: null,
        smiManager: null,
        smiContract: null,
        smiContractPhone: null,
        sfsContent: null,
        sfsIsDel: null,
        sfsRemark: null,
        ssId: null,
        ssName: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        paiBankName: [
          {
            required: true,
            message: "开户银行不能为空",
            trigger: ["change", "blur"],
          },
        ],
      },
    };
  },
  created() {
    this.getList();
    this.getBankList();
    this.getDicts("pay_pai_acctype").then((response) => {
      this.formulaOptions = response.data;
    });
    this.getDicts("pay_pai_status").then((response) => {
      this.formulaOptionsSend = response.data;
    });
  },
  methods: {
    //切换账款类型
    changePayer(value) {
      if (value) {
        this.$set(this.form, "paiQlbankname", value);
      }
    },
    /** 查询账户列表 */
    getList() {
      this.loading = true;
      listAdminAcc(this.queryParams).then((response) => {
        this.accList = response.data.records;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 修改取消按钮
    cancelEdit() {
      this.edit = false;
      this.reset();
    },
    // 充值取消按钮
    cancelRecharge() {
      this.recharge = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        paiBankName: null,
        scyLegal: null,
        scyPhone: null,
        scyLegalId: null,
        email: null,
        scyName: null,
        scyAddress: null,
      };
      this.noneBtnImg = false;
      this.enclosureList = [];
      this.sfzList = [];
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.scyId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    //资方类型
    formulaFormat(row, column) {
      return this.selectDictLabel(this.formulaOptions, row.paiAcctype);
    },
    //奖项
    formulaFormatSend(row, column) {
      return this.selectDictLabel(this.formulaOptionsSend, row.paiStatus);
    },
    //查询银行名称
    getBankList(paiBankName) {
      this.queryParams.paiBankName = paiBankName;
      listBank(this.queryParams).then((response) => {
        this.bankList = response.data.records;
      });
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      listCorporation().then((response) =>{
        this.form = response.data[0]
      })
      this.open = true;
      // this.$set(this.form, "name", "丛美红");
      // this.$set(this.form, "phone", "18810133746");
      // this.$set(this.form, "IDCard", "210282198912038724");
      // this.$set(this.form, "email", "congmeihong@zcylian.com");
      // this.$set(this.form, "companyName", "招采云链（山东）信息服务有限公司");
      // this.$set(this.form, "companyAddress", "中国（山东）自由贸易试验区济南片区汉峪金谷A3-1-1401");
      this.title = "添加虚拟账户";
    },
    /** 新增提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        console.log(this.form);
        if (valid) {
          const loading = this.$loading({
            lock: true,
            text: "Loading",
            spinner: "el-icon-loading",
            background: "rgba(0, 0, 0, 0.7)",
          });
          register()
            .then((response) => {
              debugger
              loading.close();
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            })
            .catch((response) => {
              loading.close();
            });
        }
      });
    },
    /** 提交按钮 */
    submitEdit() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          const loading = this.$loading({
            lock: true,
            text: "Loading",
            spinner: "el-icon-loading",
            background: "rgba(0, 0, 0, 0.7)",
          });
          updateAcc(this.form)
            .then((response) => {
              loading.close();
              this.msgSuccess("修改成功");
              this.edit = false;
              this.getList();
            })
            .catch((response) => {
              loading.close();
            });
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const paiId = row.paiId || this.ids;
      const paiAccno = row.paiAccno;
      this.$confirm(
        '是否确认删除账户卡号为"' + paiAccno + '"的数据项?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(function () {
          return delAdminAcc(paiId);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        });
    },
  },
};
</script>
