<template>
  <div>
    <avue-crud :option="option"
               :table-loading="loading"
               :data="data"
               @row-update="infoSubmit"
               @row-del="removeItem"
               @selection-change="selectionChange"
               v-model="form"
               ref="crud2">
      <template slot="menuLeft">
        <el-button type="success"
                   size="small"
                   icon="el-icon-circle-check"
                   plain
                   @click="handleSubmit">批量提交
        </el-button>
      </template>
    </avue-crud>
  </div>
</template>

<script>
  import {cardswallowSubmit} from "@/api/bank/cardswallow";

  export default {
    name: "cardswallow-comfirm",
    data(){
      return {
        loading: false,
        data: [],
        selectionList: [],
        form: {},
        option: {
          height:'auto',
          calcHeight: 30,
          tip: false,
          searchShow: false,
          searchShowBtn: false,
          columnBtn: false,
          refreshBtn: false,
          searchMenuSpan: 6,
          border: true,
          index: true,
          viewBtn: false,
          editBtn: true,
          addBtn: false,
          selection: true,
          dialogClickModal: false,
          column: [
            {
              label: "銀行號",
              prop: "bankNo",
              span: 24,
              hide: true,
              rules: [{
                required: true,
                message: "請輸入銀行號",
                trigger: "blur"
              }]
            },
            {
              label: "機構號",
              prop: "orgNo",
              rules: [{
                required: true,
                message: "請輸入機構號",
                trigger: "blur"
              }]
            },
            {
              label: "機構名稱",
              prop: "orgName",
              rules: [{
                required: true,
                message: "請輸入機構號",
                trigger: "blur"
              }]
            },
            {
              label: "序號",
              prop: "serialNo",
              rules: [{
                required: true,
                message: "請輸入序號",
                trigger: "blur"
              }]
            },
            {
              label: "發送時間",
              prop: "sendDate",
              type: "date",
              format: "yyyy-MM-dd",
              valueFormat: "yyyy-MM-dd",
              rules: [{
                required: true,
                message: "請輸入發送時間",
                trigger: "blur"
              }]
            },
            {
              label: "發送支行",
              prop: "sendBank",
              rules: [{
                required: true,
                message: "請輸入發送支行",
                trigger: "blur"
              }]
            },
            {
              label: "發送支行機構號",
              prop: "sendOrgNo",
              hide: true,
              display: false,
              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",
              type: "date",
              format: "yyyy-MM-dd",
              valueFormat: "yyyy-MM-dd",
              rules: [{
                required: true,
                message: "請輸入沒收卡日期",
                trigger: "blur"
              }]
            },
            {
              label: "卡狀態",
              prop: "cardStatus",
              rules: [{
                required: true,
                message: "請輸入卡狀態",
                trigger: "blur"
              }]
            },
            /* {
               label: "發送狀態",
               prop: "sendStatus",
               type: "select",
               dataType: "string",
               display: false,
               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"
              }]
            },

          ]
        }
      }
    },
    computed: {
      ids() {
        let ids = [];
        this.selectionList.forEach(ele => {
          ids.push(ele.id);
        });
        return ids.join(",");
      }
    },
    props: {
      data: {
        type: Array
      },

    },
    mounted() {
    },
    methods: {
      infoSubmit(row, index, done, loading){
        cardswallowSubmit(row).then(() => {
          this.data.splice(index, 1);
          this.$message({
            type: "success",
            message: "操作成功!"
          });
          loading = false;
          done();
        });
      },
      handleSubmit(){
        if (this.selectionList.length === 0) {
          this.$message.warning("請選擇至少一條數據");
          return;
        }
        for (let i = 0; i < this.selectionList.length; i++) {
          let item = this.selectionList[i];
          cardswallowSubmit(item).then(() => {
            this.data.splice(item.$index, 1);
          });
        }
        this.$message({
          type: "success",
          message: "操作成功!"
        });
      },
      removeItem(row, index){
        this.data.splice(index, 1)
      },
      selectionChange(list) {
        this.selectionList = list;
      },
    }
  }
</script>

<style scoped>

</style>
