detail.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <template>
  2. <CusDialog
  3. :show="show"
  4. :title="titleCpt"
  5. @onClose="$emit('update:show', false)"
  6. width="400px"
  7. height="auto"
  8. @onSubmit="onSubmit"
  9. :loading="state.loading"
  10. >
  11. <div class="__cus-dialog-form">
  12. <CusForm ref="ref_form" label-width="90px">
  13. <CusFormColumn
  14. :span="24"
  15. required
  16. label="字典名称"
  17. v-model:param="state.form.dictLabel"
  18. />
  19. <CusFormColumn
  20. :span="24"
  21. required
  22. label="字典值"
  23. v-model:param="state.form.dictValue"
  24. />
  25. <CusFormColumn
  26. v-if="transfer.mode !== 'parent'"
  27. :span="24"
  28. required
  29. label="字典状态"
  30. v-model:param="state.form.dictState"
  31. link="switch"
  32. :options="DictionaryStore.dictStateList"
  33. active-value="0"
  34. inactive-value="1"
  35. />
  36. <CusFormColumn
  37. :span="24"
  38. required
  39. label="排序"
  40. v-model:param="state.form.sortCode"
  41. link="input-number"
  42. :min="0"
  43. :max="999"
  44. />
  45. </CusForm>
  46. </div>
  47. </CusDialog>
  48. </template>
  49. <script setup lang="ts">
  50. import {computed, getCurrentInstance, nextTick, reactive, ref, watch} from "vue";
  51. import {useDictionaryStore} from "@/stores";
  52. import {ElMessage, ElMessageBox} from "element-plus";
  53. import {dictAdd, dictEdit, dictInfo} from "@/api/modules/manage/dict";
  54. const emit = defineEmits(['update:show', 'refresh'])
  55. const {proxy} = getCurrentInstance()
  56. const DictionaryStore = useDictionaryStore()
  57. const props = defineProps({
  58. show: {default: false},
  59. transfer: {}
  60. })
  61. const state: any = reactive({
  62. form: {},
  63. loading: false
  64. })
  65. const ref_form = ref()
  66. const titleCpt = computed(() => {
  67. let t = ''
  68. switch (props.transfer.mode) {
  69. case 'parent': t = '新增字典'
  70. break
  71. case 'add': t = '新增字典项'
  72. break
  73. case 'edit': t = '编辑字典项'
  74. break
  75. }
  76. return t
  77. })
  78. const onSubmit = () => {
  79. ref_form.value.submit().then(() => {
  80. ElMessageBox.confirm("是否提交?", "提示", {
  81. confirmButtonText: "确定",
  82. cancelButtonText: "取消",
  83. type: "warning",
  84. } as any).then(() => {
  85. state.loading = true
  86. switch (props.transfer.mode) {
  87. case 'parent': {
  88. dictAdd(state.form).then(res => {
  89. if (res.code === 200) {
  90. ElMessage.success('新增成功!')
  91. emit('update:show', false)
  92. emit('refresh', true)
  93. } else {
  94. ElMessage.error(res.msg)
  95. }
  96. state.loading = false
  97. })
  98. } break
  99. case 'add': {
  100. dictAdd(state.form).then(res => {
  101. if (res.code === 200) {
  102. ElMessage.success('新增成功!')
  103. emit('update:show', false)
  104. emit('refresh')
  105. } else {
  106. ElMessage.error(res.msg)
  107. }
  108. state.loading = false
  109. })
  110. } break
  111. case 'edit': {
  112. dictEdit(state.form).then(res => {
  113. if (res.code === 200) {
  114. ElMessage.success('编辑成功!')
  115. emit('update:show', false)
  116. emit('refresh')
  117. } else {
  118. ElMessage.error(res.msg)
  119. }
  120. state.loading = false
  121. })
  122. } break
  123. }
  124. }).catch(() => {})
  125. }).catch((e) => {
  126. ElMessage({
  127. message: e[0].message,
  128. grouping: true,
  129. type: 'warning',
  130. })
  131. })
  132. }
  133. const initDetail = () => {
  134. state.form = props.transfer.row
  135. }
  136. watch(() => props.show, (n) => {
  137. if (n) {
  138. initDictionary()
  139. if (props.transfer.mode === 'parent') {
  140. state.form = {
  141. parentId: 0,
  142. dictState: '0',
  143. sortCode: 999
  144. }
  145. } else if (props.transfer.mode === 'add') {
  146. state.form = {
  147. parentId: props.transfer.parentId,
  148. dictState: '0',
  149. sortCode: 999
  150. }
  151. } else {
  152. initDetail()
  153. }
  154. nextTick(() => {
  155. ref_form.value.reset()
  156. })
  157. }
  158. })
  159. const initDictionary = () => {
  160. }
  161. </script>
  162. <style lang="scss" scoped>
  163. </style>