examine.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <template>
  2. <div class="">
  3. <el-dialog
  4. v-model="show"
  5. :title="$t(prefix + 'dialog_title_audit')"
  6. :close-on-click-modal="false"
  7. :close-on-press-escape="false"
  8. :before-close="close"
  9. width="550px"
  10. >
  11. <el-form
  12. ref="formRef"
  13. v-loading="loading"
  14. style="width: 500px"
  15. :rules="rules"
  16. :model="form"
  17. label-width="110px"
  18. >
  19. <el-form-item
  20. :label="$t(prefix + 'label_name')"
  21. prop=""
  22. >
  23. <div>{{ form.product_name }}</div>
  24. </el-form-item>
  25. <el-form-item
  26. label="中文品名"
  27. prop=""
  28. >
  29. <div>{{ form.product_name_cn }}</div>
  30. </el-form-item>
  31. <el-form-item
  32. :label="$t(prefix + 'label_audit')"
  33. prop=""
  34. >
  35. <el-radio-group
  36. v-model="form.status"
  37. @change="formRef!.clearValidate('product_sku')"
  38. >
  39. <el-radio :label="1">审核通过</el-radio>
  40. <el-radio :label="2">审核不通过</el-radio>
  41. </el-radio-group>
  42. </el-form-item>
  43. <el-form-item
  44. :label="$t(prefix + 'label_category')"
  45. prop="category_id"
  46. >
  47. <el-cascader
  48. v-model="form.category_id"
  49. style="width: 410px"
  50. :options="categoryData"
  51. :props="{ label: 'name', value: 'id' }"
  52. ></el-cascader>
  53. </el-form-item>
  54. <el-form-item
  55. label="SKU"
  56. prop="product_sku"
  57. >
  58. <el-input v-model="form.product_sku" />
  59. </el-form-item>
  60. <el-form-item
  61. :label="$t(prefix + 'label_feedback')"
  62. prop="feedback"
  63. >
  64. <el-input
  65. v-model="form.feedback"
  66. type="textarea"
  67. :rows="5"
  68. ></el-input>
  69. </el-form-item>
  70. </el-form>
  71. <template #footer>
  72. <div class="flex justify-center items-center">
  73. <el-button
  74. type="danger"
  75. size="small"
  76. @click="checkForm(2)"
  77. >
  78. 驳回
  79. </el-button>
  80. <el-button
  81. size="small"
  82. type="primary"
  83. @click="checkForm(1)"
  84. >
  85. 审核通过
  86. </el-button>
  87. </div>
  88. </template>
  89. </el-dialog>
  90. </div>
  91. </template>
  92. <script lang="ts" setup>
  93. import { defineComponent, ref, watch } from 'vue'
  94. import {
  95. ElRadio,
  96. ElRadioGroup,
  97. ElDialog,
  98. ElButton,
  99. ElForm,
  100. ElFormItem,
  101. ElInput,
  102. ElNotification,
  103. ElCascader,
  104. } from 'element-plus'
  105. import type { FormInstance } from 'element-plus'
  106. import cloneDeep from 'lodash.clonedeep'
  107. import { $t } from '@/i18n/index'
  108. import { saveExamine } from '@/api/product'
  109. defineComponent({
  110. name: 'DialogExamineRecord',
  111. })
  112. const $emit = defineEmits(['update:visible'])
  113. const {
  114. visible = false,
  115. dataForExamine = {} as any,
  116. categoryData = [],
  117. } = defineProps<{
  118. visible: boolean
  119. dataForExamine: object
  120. categoryData: any[]
  121. }>()
  122. const prefix = 'order.product.'
  123. let show = ref(false)
  124. let loading = ref(false)
  125. const formRef = ref<FormInstance>()
  126. const form = ref({
  127. product_name: '',
  128. product_name_cn: '',
  129. product_sku: '',
  130. category_id: [],
  131. images: '',
  132. status: 1,
  133. } as any)
  134. const checkSKU = (rule: any, value: any, cb: any) => {
  135. if (form.value.status !== 1) {
  136. cb()
  137. } else {
  138. if (!value) {
  139. cb(new Error($t('text_please_input')))
  140. } else {
  141. cb()
  142. }
  143. }
  144. }
  145. const rules = {
  146. product_sku: [{ required: true, validator: checkSKU, trigger: 'change' }],
  147. category_id: [
  148. {
  149. required: true,
  150. message: $t('text_please_input'),
  151. trigger: 'change',
  152. },
  153. ],
  154. }
  155. watch(
  156. () => visible,
  157. () => {
  158. show.value = visible
  159. if (show.value) {
  160. const temp: any = {
  161. feedback: '',
  162. }
  163. if (typeof dataForExamine.category_id === 'number') {
  164. temp.category_id = getCategory(dataForExamine.category_id)
  165. }
  166. form.value = Object.assign({}, cloneDeep(dataForExamine), temp)
  167. // eslint-disable-next-line
  168. if (form.value.status == 0) {
  169. // 未审核状态直接选 审核通过, 其他两种情况不管
  170. form.value.status = 1
  171. }
  172. delete form.value.admin_name
  173. delete form.value.admin_id
  174. delete form.value.create_time
  175. delete form.value.update_time
  176. }
  177. },
  178. )
  179. const getCategory = (id: number | string) => {
  180. const result: any[] = []
  181. categoryData.forEach((first: any) => {
  182. if (first.id === id) {
  183. result.push(first.id)
  184. return
  185. }
  186. if (first.children?.length) {
  187. first.children.forEach((second: any) => {
  188. if (second.id === id) {
  189. result.push(first.id)
  190. result.push(second.id)
  191. return
  192. }
  193. if (second.children?.length) {
  194. second.children.forEach((third: any) => {
  195. if (third.id === id) {
  196. result.push(first.id)
  197. result.push(second.id)
  198. result.push(third.id)
  199. return
  200. }
  201. })
  202. }
  203. })
  204. }
  205. })
  206. return result
  207. }
  208. /**
  209. * flag 2 驳回. 其他通过.
  210. */
  211. const checkForm = (flag: number) => {
  212. if (!formRef.value) return
  213. formRef.value.validate((valid) => {
  214. if (valid) {
  215. const p = cloneDeep(form.value)
  216. p.category_id = p.category_id[p.category_id.length - 1].toString()
  217. p.status = flag
  218. p.product_id = p.id
  219. delete p.product_name
  220. delete p.product_name_cn
  221. delete p.images
  222. saveExamine(p).then((res: any) => {
  223. if (res.code === 1) {
  224. ElNotification({
  225. title: '操作成功',
  226. message: '正在刷新数据',
  227. duration: 3000,
  228. })
  229. close()
  230. }
  231. })
  232. }
  233. })
  234. }
  235. let close = (done = {} as any) => {
  236. $emit('update:visible', 0)
  237. if (typeof done === 'function') done()
  238. }
  239. </script>
  240. <style lang="scss" scoped></style>