addForm.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <template>
  2. <ContentWrap v-loading="formLoading">
  3. <el-tabs v-model="activeName">
  4. <el-tab-pane label="商品信息" name="basicInfo">
  5. <BasicInfoForm
  6. ref="BasicInfoRef"
  7. v-model:activeName="activeName"
  8. :propFormData="formData"
  9. />
  10. </el-tab-pane>
  11. <el-tab-pane label="商品详情" name="description">
  12. <DescriptionForm
  13. ref="DescriptionRef"
  14. v-model:activeName="activeName"
  15. :propFormData="formData"
  16. />
  17. </el-tab-pane>
  18. <el-tab-pane label="其他设置" name="otherSettings">
  19. <OtherSettingsForm
  20. ref="OtherSettingsRef"
  21. v-model:activeName="activeName"
  22. :propFormData="formData"
  23. />
  24. </el-tab-pane>
  25. </el-tabs>
  26. <el-form>
  27. <el-form-item style="float: right">
  28. <el-button :loading="formLoading" type="primary" @click="submitForm">保存</el-button>
  29. <el-button @click="close">返回</el-button>
  30. </el-form-item>
  31. </el-form>
  32. </ContentWrap>
  33. </template>
  34. <script lang="ts" name="ProductManagementForm" setup>
  35. import { useTagsViewStore } from '@/store/modules/tagsView'
  36. import { BasicInfoForm, DescriptionForm, OtherSettingsForm } from './components'
  37. import { SpuType } from '@/api/mall/product/management/type' // const { t } = useI18n() // 国际化
  38. // const { t } = useI18n() // 国际化
  39. // const message = useMessage() // 消息弹窗
  40. const { push, currentRoute } = useRouter() // 路由
  41. // const { query } = useRoute() // 查询参数
  42. const { delView } = useTagsViewStore() // 视图操作
  43. const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
  44. const activeName = ref('basicInfo') // Tag 激活的窗口
  45. const BasicInfoRef = ref<ComponentRef<typeof BasicInfoForm>>() // 商品信息Ref
  46. const DescriptionRef = ref<ComponentRef<typeof DescriptionForm>>() // 商品详情Ref
  47. const OtherSettingsRef = ref<ComponentRef<typeof OtherSettingsForm>>() // 其他设置Ref
  48. const formData = ref<SpuType>({
  49. name: '', // 商品名称
  50. categoryId: undefined, // 商品分类
  51. keyword: '', // 关键字
  52. unit: '', // 单位
  53. picUrl: '', // 商品封面图
  54. sliderPicUrls: [], // 商品轮播图
  55. introduction: '', // 商品简介
  56. deliveryTemplateId: 0, // 运费模版
  57. selectRule: '',
  58. specType: false, // 商品规格
  59. subCommissionType: false, // 分销类型
  60. description: '', // 商品详情
  61. sort: 1, // 商品排序
  62. giveIntegral: 1, // 赠送积分
  63. virtualSalesCount: 1, // 虚拟销量
  64. recommendHot: false, // 是否热卖
  65. recommendBenefit: false, // 是否优惠
  66. recommendBest: false, // 是否精品
  67. recommendNew: false, // 是否新品
  68. recommendGood: false // 是否优品
  69. })
  70. /** 获得详情 */
  71. const getDetail = async () => {}
  72. /** 提交按钮 */
  73. const submitForm = async () => {
  74. // TODO 三个表单逐一校验,如果有一个表单校验不通过则切换到对应表单,如果有两个及以上的情况则切换到最前面的一个并弹出提示消息
  75. // 校验各表单
  76. try {
  77. await unref(BasicInfoRef)?.validate()
  78. await unref(DescriptionRef)?.validate()
  79. await unref(OtherSettingsRef)?.validate()
  80. // 校验都通过后提交表单
  81. console.log(formData.value)
  82. } catch {}
  83. }
  84. /**
  85. * 重置表单
  86. */
  87. const resetForm = async () => {
  88. formData.value = {
  89. name: '', // 商品名称
  90. categoryId: 0, // 商品分类
  91. keyword: '', // 关键字
  92. unit: '', // 单位
  93. picUrl: '', // 商品封面图
  94. sliderPicUrls: [], // 商品轮播图
  95. introduction: '', // 商品简介
  96. deliveryTemplateId: 0, // 运费模版
  97. selectRule: '',
  98. specType: false, // 商品规格
  99. subCommissionType: false, // 分销类型
  100. description: '', // 商品详情
  101. sort: 1, // 商品排序
  102. giveIntegral: 1, // 赠送积分
  103. virtualSalesCount: 1, // 虚拟销量
  104. recommendHot: false, // 是否热卖
  105. recommendBenefit: false, // 是否优惠
  106. recommendBest: false, // 是否精品
  107. recommendNew: false, // 是否新品
  108. recommendGood: false // 是否优品
  109. }
  110. }
  111. /** 关闭按钮 */
  112. const close = () => {
  113. resetForm()
  114. delView(unref(currentRoute))
  115. push('/product/product-management')
  116. }
  117. /** 初始化 */
  118. onMounted(() => {
  119. getDetail()
  120. })
  121. </script>