skuApply.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <template>
  2. <div class="compnent-appply-sku">
  3. <el-dialog
  4. v-model="show"
  5. class="custom-apply-sku-dialog"
  6. title="申请商品"
  7. :close-on-click-modal="false"
  8. :close-on-press-escape="false"
  9. :before-close="close"
  10. width="700px"
  11. >
  12. <el-form
  13. ref="formRef"
  14. label-width="90px"
  15. :model="form"
  16. :rules="rules"
  17. >
  18. <el-form-item
  19. prop="product_name"
  20. label="英文品名"
  21. >
  22. <el-input v-model="form.product_name"></el-input>
  23. </el-form-item>
  24. <el-form-item
  25. prop="product_name_cn"
  26. label="中文品名"
  27. >
  28. <el-input v-model="form.product_name_cn"></el-input>
  29. </el-form-item>
  30. <el-form-item
  31. prop=""
  32. label="产品图片"
  33. >
  34. <image-upload
  35. v-model:list="imageList"
  36. width="100px"
  37. height="100px"
  38. :disable-preview="true"
  39. ></image-upload>
  40. </el-form-item>
  41. </el-form>
  42. <template #footer>
  43. <div class="flex justify-center items-center">
  44. <el-button
  45. type="primary"
  46. size="small"
  47. @click="checkForm(formRef)"
  48. >
  49. 确定
  50. </el-button>
  51. <el-button
  52. type=""
  53. size="small"
  54. @click="close"
  55. >
  56. {{ $t('btn_cancel') }}
  57. </el-button>
  58. </div>
  59. </template>
  60. </el-dialog>
  61. </div>
  62. </template>
  63. <script lang="ts" setup>
  64. import { defineComponent, ref, watch, inject } from 'vue'
  65. import {
  66. ElButton,
  67. ElInput,
  68. ElDialog,
  69. ElNotification,
  70. ElForm,
  71. ElFormItem,
  72. } from 'element-plus'
  73. import type { FormInstance } from 'element-plus'
  74. import { $t } from '@/i18n/index'
  75. import imageUpload from '@/components/ImageUpload.vue'
  76. import { applySKU } from '@/api/indent'
  77. defineComponent({
  78. name: 'ComponentApplySku',
  79. })
  80. const show = ref(false)
  81. const loading = ref(false)
  82. const imageList = ref([])
  83. const { visible = false } = defineProps<{ visible: boolean }>()
  84. const $emit = defineEmits(['update:visible', 'apply'])
  85. const rules = {
  86. product_name: [
  87. {
  88. required: true,
  89. message: $t('text_please_input'),
  90. trigger: 'change',
  91. },
  92. ],
  93. product_name_cn: [
  94. {
  95. required: true,
  96. message: $t('text_please_input'),
  97. trigger: 'change',
  98. },
  99. ],
  100. }
  101. watch(
  102. () => visible,
  103. () => {
  104. show.value = visible
  105. resetData()
  106. },
  107. )
  108. const form = ref({
  109. product_name: '',
  110. product_name_cn: '',
  111. images: '',
  112. })
  113. const formRef = ref()
  114. const $mediaRegExp = inject('mediaRegExp') as RegExp
  115. const checkForm = (formEl: FormInstance | undefined) => {
  116. if (!formEl) return
  117. formEl.validate((valid: boolean) => {
  118. if (!valid) return
  119. form.value.images = imageList.value
  120. .map((i: any) => {
  121. return i.url.replace($mediaRegExp, '/')
  122. })
  123. .join(',')
  124. loading.value = true
  125. applySKU(form.value)
  126. .then((response: any) => {
  127. if (response.code === 1) {
  128. ElNotification({
  129. title: '操作成功',
  130. message: 'SKU已提交申请',
  131. type: 'success',
  132. duration: 3000,
  133. })
  134. $emit('apply', { product_name: form.value.product_name })
  135. close()
  136. }
  137. })
  138. .finally(() => {
  139. loading.value = false
  140. })
  141. })
  142. }
  143. const resetData = () => {
  144. form.value = {
  145. product_name: '',
  146. product_name_cn: '',
  147. images: '',
  148. }
  149. imageList.value = []
  150. }
  151. const close = (done = {} as any) => {
  152. $emit('update:visible', false)
  153. if (typeof done === 'function') done()
  154. }
  155. </script>