AddSelection.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <template>
  2. <el-dialog
  3. :visible.sync="visible"
  4. v-bind="modalOptions"
  5. append-to-body
  6. >
  7. <el-form
  8. ref="formData"
  9. :model="formData"
  10. :rules="formRules"
  11. size="mini"
  12. label-suffix=":"
  13. label-width="150px"
  14. >
  15. <el-form-item label="商品ID" prop="productId">
  16. <el-input
  17. v-model="formData.productId" maxlength="20" placeholder="商品ID" disabled
  18. />
  19. </el-form-item>
  20. <el-form-item label="商家Id" prop="productIdproductId">
  21. <el-input
  22. v-model="formData.productIdproductId" maxlength="20" placeholder="请输入商家id"
  23. />
  24. </el-form-item>
  25. <!-- <el-form-item label="平台分类" prop="classifyId">
  26. <el-select v-model="formData.classifyId" placeholder="请选择平台分类">
  27. <el-option
  28. v-for="item in classOptions" :key="item.classifyId" :label="item.classifyName"
  29. :value="item.classifyId"
  30. >
  31. </el-option>
  32. </el-select>
  33. </el-form-item> -->
  34. <el-form-item label="商家分组" prop="shopGroupId">
  35. <el-cascader
  36. v-model="formData.shopGroupArr" placeholder="请选择商家分组" :options="shopGroupList"
  37. :props="{ checkStrictly: true, expandTrigger: 'hover', label: 'groupName', value: 'shopGroupId', children: 'childs' }"
  38. clearable
  39. />
  40. <!-- <el-select v-model="formData.shopGroupId" placeholder="请选择">
  41. <el-option v-for="item in shopGroup" :key="item.shopGroupId" :label="item.groupName"
  42. :value="item.shopGroupId">
  43. </el-option>
  44. </el-select> -->
  45. </el-form-item>
  46. <el-form-item label="是否加入选品" prop="shelveState">
  47. <el-radio-group v-model="formData.shelveState">
  48. <el-radio :label="1">是</el-radio>
  49. <el-radio :label="0">不是</el-radio>
  50. </el-radio-group>
  51. </el-form-item>
  52. </el-form>
  53. <template #footer>
  54. <span class="dialog-footer">
  55. <el-button size="mini" @click="handleClose">取 消</el-button>
  56. <el-button type="primary" size="mini" @click="handleSubmit">确 定</el-button>
  57. </span>
  58. </template>
  59. </el-dialog>
  60. </template>
  61. <script>
  62. import { commdityClassGetAll, commdityClassGetGroup, getProductById, addProductFixed } from '@/api/commodity'
  63. export default {
  64. name: 'AddSelection',
  65. components: {
  66. },
  67. data() {
  68. return {
  69. modalOptions: {
  70. closeOnClickModal: false,
  71. width: '620px',
  72. title: ''
  73. },
  74. visible: false,
  75. formData: {
  76. productId: '',
  77. productIdproductId: 186,
  78. shopParentId: '',
  79. shopGroupId: '',
  80. shopGroupArr: [], // 非后端参数
  81. shelveState: ''
  82. },
  83. formRules: {
  84. productId: [
  85. { required: true, message: '缺少商品ID' }
  86. ],
  87. productIdproductId: [
  88. { required: true, message: '商家id不能为空' }
  89. ],
  90. shopGroupId: [
  91. { required: true, message: '请选择商家分组' }
  92. ],
  93. shelveState: [
  94. { required: true, message: '请选择是否加入选品' }
  95. ]
  96. },
  97. classOptions: [],
  98. shopGroupList: []
  99. }
  100. },
  101. created() {
  102. this.getAllClass()
  103. this.getGroupSelect()
  104. },
  105. methods: {
  106. handleClose() {
  107. this.visible = false
  108. },
  109. // 获取商品类别
  110. async getAllClass() {
  111. const res = await commdityClassGetAll({ page: 1, pageSize: 9999 })
  112. this.classOptions = res.data.list
  113. },
  114. // 商家分组查询
  115. async getGroupSelect() {
  116. const res = await commdityClassGetGroup({ search: '', page: 1, pageSize: 9999 })
  117. this.shopGroupList = res.data.list
  118. },
  119. initList() {
  120. },
  121. handleOpen(params = {}) {
  122. this.modalOptions.title = '加入选品'
  123. this.formData.productId = params.productId
  124. this.formData.shopGroupArr = []
  125. // this.formData = Object.assign(this.$options.data().formData, params)
  126. this.visible = true
  127. this.initList()
  128. if (params.productId) {
  129. this.getInfo(params.productId)
  130. }
  131. this.$refs.formData && this.$refs.formData.resetFields()
  132. },
  133. async getInfo(id) {
  134. const loading = this.$loading({ text: '加载中' })
  135. try {
  136. const res = await getProductById({ productId: id })
  137. // this.formData = Object.assign(this.$options.data().formData, res.data, {
  138. this.formData = Object.assign(this.$options.data().formData, this.formData, {
  139. shopParentId: res.data.shopId || ''
  140. // shopGroupId: res.data.shopGroupId || '',
  141. })
  142. this.$nextTick(() => {
  143. this.$refs.formData && this.$refs.formData.validate()
  144. })
  145. } finally {
  146. loading.close()
  147. }
  148. },
  149. handleSubmit() {
  150. this.$refs.formData.validate(async (valid) => {
  151. if (valid) {
  152. const loading = this.$loading({ text: '加载中' })
  153. try {
  154. const { shopGroupArr, ...otps } = this.formData
  155. const params = {
  156. ...otps,
  157. shopGroupId: Array.isArray(shopGroupArr) && shopGroupArr.length ? shopGroupArr[shopGroupArr.length - 1] : ''
  158. }
  159. await addProductFixed(params)
  160. loading.close()
  161. this.$message({ message: `选品添加成功!`, type: 'success' })
  162. this.$emit('success')
  163. this.visible = false
  164. } catch (e) {
  165. loading.close()
  166. } finally {
  167. loading.close()
  168. }
  169. } else {
  170. this.$message({ message: '请输入相关信息', type: 'warning' })
  171. return false
  172. }
  173. })
  174. }
  175. }
  176. }
  177. </script>