<template>
  <basic-container>
    <avue-crud :option="option"
               :table-loading="loading"
               :data="data"
               :page.sync="page"
               :permission="permissionList"
               :before-open="beforeOpen"
               v-model="form"
               ref="crud"
               @row-update="rowUpdate"
               @row-save="rowSave"
               @row-del="rowDel"
               @search-change="searchChange"
               @search-reset="searchReset"
               @selection-change="selectionChange"
               @current-change="currentChange"
               @size-change="sizeChange"
               @refresh-change="refreshChange"
               @on-load="onLoad">

      <template slot="process" slot-scope="{row, index}">
        <el-tag size="small " type="primary" plain v-if="row.process == 2">待發佈</el-tag>
        <el-tag size="small " type="warning" plain v-if="row.process == 3">待確認</el-tag>
        <el-tag size="small " type="success" plain v-if="row.process == 4">已確認</el-tag>
      </template>
      <template slot="menu" slot-scope="{row, index}">
        <el-button size="mini " type="primary" plain v-if="permission.cardswallow_issue && row.process == 2" @click="form = row,issueVisible = true">去發佈</el-button>
      </template>
    </avue-crud>

    <el-dialog :append-to-body="true" :modal-append-to-body="false" :visible.sync="issueVisible">
      <cardswallow-issue :form="form" @close="issueVisible = false, onLoad(page)"></cardswallow-issue>
    </el-dialog>

  </basic-container>
</template>

<script>
  import {getList, getDetail, add, update, remove, settingSave, getSetting} from "@/api/bank/cardswallow";
  import {mapGetters} from "vuex";
  import CardswallowIssue from "../../components/common/cardswallow-issue";

  export default {
    name: "release-cardswallow",
    components: {CardswallowIssue},
    data() {
      return {
        issueVisible: false,

        form: {},
        query: {},
        loading: true,
        page: {
          pageSize: 10,
          currentPage: 1,
          total: 0
        },
        selectionList: [],
        option: {
          height:'auto',
          calcHeight: 30,
          tip: false,
          searchShow: true,
          searchMenuSpan: 6,
          border: true,
          index: true,
          viewBtn: true,
          addBtn: false,
          editBtn: false,
          delBtn: false,
          selection: true,
          dialogClickModal: false,
          column: [
            {
              label: "銀行號",
              prop: "bankNo",
              span: 24,
              hide: true,
              rules: [{
                required: true,
                message: "請輸入銀行號",
                trigger: "blur"
              }]
            },
            {
              label: "機構號",
              prop: "orgNo",
              hide: true,
              rules: [{
                required: true,
                message: "請輸入機構號",
                trigger: "blur"
              }]
            },
            {
              label: "機構名稱",
              prop: "orgName",
              disabled: true,
              rules: [{
                required: true,
                message: "請輸入機構號",
                trigger: "blur"
              }]
            },
            {
              label: "序號",
              prop: "serialNo",
              rules: [{
                required: true,
                message: "請輸入序號",
                trigger: "blur"
              }]
            },
            {
              label: "發送時間",
              prop: "sendDate",
              rules: [{
                required: true,
                message: "請輸入發送時間",
                trigger: "blur"
              }]
            },
            {
              label: "發送支行",
              prop: "sendBank",
              rules: [{
                required: true,
                message: "請輸入發送支行",
                trigger: "blur"
              }]
            },
            {
              label: "卡號",
              prop: "cardNo",
              rules: [{
                required: true,
                message: "請輸入卡號",
                trigger: "blur"
              }]
            },
            {
              label: "卡序號",
              prop: "cardSerialNo",
              rules: [{
                required: true,
                message: "請輸入卡序號",
                trigger: "blur"
              }]
            },
            {
              label: "其他",
              prop: "machine",
              rules: [{
                required: true,
                message: "請輸入其他",
                trigger: "blur"
              }]
            },
            {
              label: "機號",
              prop: "machineNo",
              rules: [{
                required: true,
                message: "請輸入機號",
                trigger: "blur"
              }]
            },
            {
              label: "沒收卡日期",
              prop: "swallowDate",
              rules: [{
                required: true,
                message: "請輸入沒收卡日期",
                trigger: "blur"
              }]
            },
            {
              label: "卡狀態",
              prop: "cardStatus",
              rules: [{
                required: true,
                message: "請輸入卡狀態",
                trigger: "blur"
              }]
            },
            {
              label: "發送狀態",
              prop: "sendStatus",
              type: "select",
              dataType: "string",
              dicUrl: `/api/blade-system/dict/dictionary?code=send_status`,
              props: {
                label: "dictValue",
                value: "dictKey"
              },
              dicFormatter: (res) => {
                res.data.forEach(item => {item.disabled = item.isSealed == 1;})
                return res.data;
              },
              rules: [{
                required: true,
                message: "請輸入發送狀態",
                trigger: "blur"
              }]
            },
            {
              label: "備註",
              prop: "remark",
              rules: [{
                required: false,
                message: "請輸入備註",
                trigger: "blur"
              }]
            },
            {
              label: "進度",
              prop: "process",
              display: false,
              rules: [{
                required: false,
                message: "請輸入備註",
                trigger: "blur"
              }]
            },

            {
              label: "支行確認人員工號",
              prop: "bankConfirmNo",
              editDisplay: false,
              hide: true,
              rules: [{
                required: true,
                message: "請輸入支行確認人員工號",
                trigger: "blur"
              }]
            },
            {
              label: "支行確認人姓名",
              prop: "bankConfirmName",
              editDisplay: false,
              hide: true,
              rules: [{
                required: true,
                message: "請輸入支行確認人姓名",
                trigger: "blur"
              }]
            },
            {
              label: "確認日期",
              prop: "bankConfirmTime",
              editDisplay: false,
              hide: true,
              rules: [{
                required: true,
                message: "請輸入確認日期",
                trigger: "blur"
              }]
            },
          ]
        },
        data: [],
        data2: [],
      };
    },
    computed: {
      ...mapGetters(["permission"]),
      permissionList() {
        return {
          addBtn: this.vaildData(this.permission.cardswallow_add, false),
          viewBtn: this.vaildData(this.permission.cardswallow_view, false),
          delBtn: this.vaildData(this.permission.cardswallow_delete, false),
          editBtn: this.vaildData(this.permission.cardswallow_edit, false)
        };
      },
      ids() {
        let ids = [];
        this.selectionList.forEach(ele => {
          ids.push(ele.id);
        });
        return ids.join(",");
      }
    },
    methods: {
      beforeOpen(done, type) {
        if (["edit", "view"].includes(type)) {
          getDetail(this.form.id).then(res => {
            this.form = res.data.data;
          });
        }
        done();
      },
      searchReset() {
        this.query = {};
        this.onLoad(this.page);
      },
      searchChange(params, done) {
        this.query = params;
        this.page.currentPage = 1;
        this.onLoad(this.page, params);
        done();
      },
      selectionChange(list) {
        this.selectionList = list;
      },
      selectionClear() {
        this.selectionList = [];
        this.$refs.crud.toggleSelection();
      },
      currentChange(currentPage){
        this.page.currentPage = currentPage;
      },
      sizeChange(pageSize){
        this.page.pageSize = pageSize;
      },
      refreshChange() {
        this.onLoad(this.page, this.query);
      },
      onLoad(page, params = {}) {
        this.loading = true;
        params.process = 2; // 待發佈
        getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
          const data = res.data.data;
          this.page.total = data.total;
          this.data = data.records;
          this.loading = false;
          this.selectionClear();
        });
      }
    }
  };
</script>

<style>
</style>
