noneConfigChannelForm.vue 3.1 KB

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