payment-operation.tsx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. import { getMenus } from '@/api/system/menu'
  2. import { clientTypeArray, openTypeArray } from '@/utils/searchArray'
  3. import { SearchOutline } from '@vicons/ionicons5'
  4. import {
  5. NForm,
  6. NFormItem,
  7. NInput,
  8. NSpace,
  9. NButton,
  10. useMessage,
  11. NRadioGroup,
  12. NRadio,
  13. NSelect
  14. } from 'naive-ui'
  15. import { defineComponent, onMounted, PropType, reactive, ref } from 'vue'
  16. import { sysPaymentConfigSave, sysPaymentConfigUpdate } from '../../api'
  17. export default defineComponent({
  18. name: 'role-operation',
  19. props: {
  20. type: {
  21. type: String,
  22. default: 'add'
  23. },
  24. data: {
  25. type: Object as PropType<any>,
  26. default: () => {}
  27. }
  28. },
  29. emits: ['close', 'getList'],
  30. setup(props, { slots, attrs, emit }) {
  31. const forms = reactive({
  32. paramName: null,
  33. paramValue: null,
  34. clientType: null,
  35. openType: null,
  36. description: null
  37. })
  38. const btnLoading = ref(false)
  39. const formsRef = ref()
  40. const message = useMessage()
  41. const onSubmit = async () => {
  42. formsRef.value.validate(async (error: any) => {
  43. if (error) return false
  44. try {
  45. btnLoading.value = true
  46. if (props.type === 'add') {
  47. await sysPaymentConfigSave({ ...forms })
  48. message.success('添加成功')
  49. } else if (props.type === 'edit') {
  50. await sysPaymentConfigUpdate({ ...forms, id: props.data.id })
  51. message.success('修改成功')
  52. }
  53. emit('close')
  54. emit('getList')
  55. } catch (e: any) {
  56. console.log(e, 'e')
  57. }
  58. btnLoading.value = false
  59. })
  60. }
  61. onMounted(async () => {
  62. if (props.type === 'edit') {
  63. const data = props.data
  64. forms.paramName = data.paramName
  65. forms.paramValue = data.paramValue
  66. forms.clientType = data.clientType
  67. forms.openType = data.openType
  68. forms.description = data.description
  69. }
  70. })
  71. return () => (
  72. <div style="background: #fff; padding-top: 12px">
  73. <NForm model={forms} ref={formsRef} label-placement="left" label-width="100">
  74. <NFormItem
  75. label="提供方"
  76. path="openType"
  77. rule={[
  78. {
  79. required: true,
  80. message: '请输入提供方'
  81. }
  82. ]}
  83. >
  84. <NSelect
  85. placeholder="请输入提供方"
  86. v-model:value={forms.openType}
  87. options={openTypeArray}
  88. />
  89. </NFormItem>
  90. <NFormItem
  91. label="客户端类型"
  92. path="clientType"
  93. rule={[
  94. {
  95. required: true,
  96. message: '请输入客户端类型'
  97. }
  98. ]}
  99. >
  100. <NSelect
  101. placeholder="请输入客户端类型"
  102. v-model:value={forms.clientType}
  103. options={clientTypeArray}
  104. />
  105. </NFormItem>
  106. <NFormItem
  107. label="参数名称"
  108. path="paramName"
  109. rule={[
  110. {
  111. required: true,
  112. message: '请输入参数名称'
  113. }
  114. ]}
  115. >
  116. <NInput
  117. v-model:value={forms.paramName}
  118. placeholder="请输入参数名称"
  119. clearable
  120. maxlength={100}
  121. ></NInput>
  122. </NFormItem>
  123. <NFormItem
  124. label="参数值"
  125. path="paramValue"
  126. rule={[
  127. {
  128. required: true,
  129. message: '请输入参数值'
  130. }
  131. ]}
  132. >
  133. <NInput
  134. v-model:value={forms.paramValue}
  135. placeholder="请输入参数值"
  136. clearable
  137. maxlength={100}
  138. ></NInput>
  139. </NFormItem>
  140. <NFormItem label="备注" path="description">
  141. <NInput
  142. v-model:value={forms.description}
  143. maxlength={180}
  144. type="textarea"
  145. rows={2}
  146. placeholder="请输入备注"
  147. clearable
  148. />
  149. </NFormItem>
  150. </NForm>
  151. <NSpace justify="end">
  152. <NButton type="default" onClick={() => emit('close')}>
  153. 取消
  154. </NButton>
  155. <NButton type="primary" onClick={onSubmit} loading={btnLoading.value}>
  156. 保存
  157. </NButton>
  158. </NSpace>
  159. </div>
  160. )
  161. }
  162. })