Blame view

yudao-ui-admin/src/views/pay/app/components/mockChannelForm.vue 3.15 KB
6a387387   jason   新增模拟支付渠道,通知查询为空bu...
1
2
3
4
5
6
7
8
9
10
11
12
  <template>
    <div>
      <el-dialog :visible.sync="dialogVisible" :title="title" @closed="close" append-to-body width="800px">
        <el-form ref="form" :model="formData" :rules="rules" size="medium" label-width="100px" v-loading="formLoading">
          <el-form-item label-width="180px" label="渠道状态" prop="status">
            <el-radio-group v-model="formData.status" size="medium">
              <el-radio v-for="dict in this.getDictDatas(DICT_TYPE.COMMON_STATUS)" :key="parseInt(dict.value)"
                        :label="parseInt(dict.value)">
                {{ dict.label }}
              </el-radio>
            </el-radio-group>
          </el-form-item>
6a387387   jason   新增模拟支付渠道,通知查询为空bu...
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
          <el-form-item label-width="180px" label="备注" prop="remark">
            <el-input v-model="formData.remark" :style="{width: '100%'}"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="close">取消</el-button>
          <el-button type="primary" @click="submitForm">确定</el-button>
        </div>
      </el-dialog>
    </div>
  </template>
  <script>
  import { createChannel, getChannel, updateChannel } from "@/api/pay/channel";
  import { CommonStatusEnum } from "@/utils/constants";
  
  export default {
    name: "mockChannelForm",
    data() {
      return {
        dialogVisible: false,
        formLoading: false,
        title:'',
        formData: {
          appId: '',
          code: '',
          status: undefined,
          feeRate: 0,
          remark: '',
          config: {
            name: 'mock-conf'
          }
        },
        rules: {
          status: [{ required: true,  message: '渠道状态不能为空',  trigger: 'blur' }]
        }
      }
    },
    methods: {
      open(appId, code) {
        this.dialogVisible = true;
        this.formLoading = true;
        this.reset(appId, code);
        getChannel(appId, code).then(response => {
          if (response.data && response.data.id) {
            this.formData = response.data;
            this.formData.config = JSON.parse(response.data.config);
          }
          this.title = !this.formData.id ? '创建支付渠道' : '编辑支付渠道'
        }).finally(() => {
          this.formLoading = false;
        });
      },
      close() {
        this.dialogVisible = false;
        this.reset(undefined, undefined);
      },
      submitForm() {
        this.$refs['form'].validate(valid => {
          if (!valid) {
            return
          }
          const data = { ...this.formData };
          data.config = JSON.stringify(this.formData.config);
          if (!data.id) {
            createChannel(data).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.$emit('success')
              this.close();
            });
          } else {
            updateChannel(data).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.$emit('success')
              this.close();
            })
          }
        });
      },
      /** 重置表单 */
      reset(appId, code) {
        this.formData = {
          appId: appId,
          code: code,
          status: CommonStatusEnum.ENABLE,
          remark: '',
          feeRate: 0,
          config: {
            name: 'mock-conf'
          }
        }
        this.resetForm('form')
      },
    }
  }
  </script>