mockChannelForm.vue 3.1 KB

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