<template>
  <div>
    <avue-form :option="option" @submit="submit" v-model="form" ref="form"></avue-form>
  </div>
</template>

<script>
  import {issue, signin} from "@/api/bank/cardswallow";

  export default {
    name: "cardswallow-issue",
    data(){
      return {
        form: {},
        option: {
          submitText: "發送",
          emptyBtn: false,
          column: [
            {
              label: "銀行號",
              prop: "bankNo",
              span: 24,
              hide: true,
              disabled: true,
            },
            {
              label: "機構號",
              prop: "orgNo",
              hide: true,
              disabled: true,
            },
            {
              label: "機構名稱",
              prop: "orgName",
              disabled: true,
              rules: [{
                required: true,
                message: "請輸入機構號",
                trigger: "blur"
              }]
            },
            {
              label: "序號",
              prop: "serialNo",
              disabled: true,
            },
            {
              label: "發送時間",
              prop: "sendDate",
              type: "datetime",
              format: "yyyy-MM-dd",
              valueFormat: "yyyy-MM-dd",
              disabled: true,
            },
            {
              label: "發送支行",
              prop: "sendBank",
              disabled: true,
            },
            {
              label: "卡號",
              prop: "cardNo",
              disabled: true,
            },
            {
              label: "卡序號",
              prop: "cardSerialNo",
              disabled: true,
            },
            {
              label: "其他",
              prop: "machine",
              disabled: true,
            },
            {
              label: "機號",
              prop: "machineNo",
              disabled: true,
            },
            {
              label: "沒收卡日期",
              prop: "swallowDate",
              type: "datetime",
              format: "yyyy-MM-dd",
              valueFormat: "yyyy-MM-dd",
              disabled: true,
            },
            {
              label: "卡狀態",
              prop: "cardStatus",
              disabled: true,
            },
            {
              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;
              },
              disabled: true,
            },
            {
              label: "備註",
              prop: "remark",
            },

          ]
        }
      }
    },
    props: {
      form: {
        type: Array
      },

    },
    mounted() {
      if (this.form.process == 2){
        this.option.submitText = '發佈';
      }else{
        this.option.submitText = '簽收';
      }
    },
    methods: {
      submit(row, done){
        if (row.process == 2){
          issue(row).then(() => {
            this.$message.success("發佈成功！");
            this.$emit("close")
            // done();
          })
        }else{
          signin(row).then(() => {
            this.$message.success("簽收成功！");
            this.$emit("close")
            // done();
          });
        }
        done();
      },
    }
  }
</script>

<style scoped>

</style>
