| | |
| | | <el-input v-model="form.name" placeholder="请输入活动标题" class="max-w460"></el-input> |
| | | </el-form-item> |
| | | <el-form-item label="活动分类" prop="category_id"> |
| | | <el-select v-model="form.category_id" placeholder="请选择"> |
| | | <el-select v-model="form.category_id" placeholder="请选择" @change="handleCategoryChange"> |
| | | <el-option v-for="(item, index) in category" :key="index" :label="item.name" :value="item.category_id"></el-option> |
| | | </el-select> |
| | | </el-form-item> |
| | |
| | | <el-radio :label="0">否</el-radio> |
| | | </el-radio-group> |
| | | </el-form-item> |
| | | <el-form-item v-if="form.is_visit" label="被走访企业名称" prop="visit_supplier_name"> |
| | | <el-input v-model="form.visit_supplier_name" placeholder="商户没有入驻时,请输入被走访企业名称" class="max-w460"></el-input> |
| | | </el-form-item> |
| | | <el-form-item label="被走访企业" prop="visit_supplier_id" v-if="form.is_visit"> |
| | | <el-row> |
| | | <el-button @click="selectSupplier('visit')" icon="el-icon-plus">选择企业</el-button> |
| | |
| | | <div class="gray9" v-if="form.space_supplier_id==''">如没有可不选</div> |
| | | </el-row> |
| | | </el-form-item> |
| | | <el-form-item label="促销商品" v-if="form.visit_supplier_id > 0"> |
| | | <el-button icon="el-icon-plus" @click="selectProduct">选择商品</el-button> |
| | | <div class="gray9">当有走访企业时,可以选择该企业的商品进行促销</div> |
| | | </el-form-item> |
| | | <el-form-item label="商品列表" v-if="form.product_list.length > 0 && form.is_visit"> |
| | | <ProductPrice :products="form.product_list" @confirm="handlePriceConfirm"></ProductPrice> |
| | | </el-form-item> |
| | | <el-form-item label="活动费用" prop="activity_fee"> |
| | | <el-input v-model="form.fee" placeholder="请输入活动费用" class="max-w460"> |
| | | <template slot="append">元</template> |
| | |
| | | <el-input v-model="form.limit_num" placeholder="请输入活动名额" class="max-w460"> |
| | | <template slot="append">人</template> |
| | | </el-input> |
| | | <div class="gray9">0为不限制人数</div> |
| | | <div class="gray9">0为不限制人数{{selectedCategory.limit_num?(',该分类最多'+selectedCategory.limit_num+'人'):''}}</div> |
| | | </el-form-item> |
| | | <el-form-item label="联系电话" prop="phone"> |
| | | <el-input v-model="form.phone" placeholder="请输入联系电话" class="max-w460"></el-input> |
| | |
| | | <GetSupplier :open="open_supplier" @close="closeSupplierFunc"></GetSupplier> |
| | | <!--选择用户--> |
| | | <GetUser :is_open="open_user" @close="closeGetUserFunc"></GetUser> |
| | | <!--选择商品--> |
| | | <ProductSelect :isproduct="isproduct" :shop_supplier_id="form.visit_supplier_id" :excludeIds="excludeIds" :islist="islist" @closeDialog="closeProductDialogFunc($event)"> |
| | | 产品列表弹出层 |
| | | </ProductSelect> |
| | | </div> |
| | | </template> |
| | | |
| | |
| | | import GetBranch from '@/components/branch/Branch.vue'; |
| | | import GetSupplier from '@/components/supplier/Supplier.vue'; |
| | | import GetUser from '@/components/user/GetUser.vue'; |
| | | import ProductSelect from '@/components/product/Product'; |
| | | import ProductPrice from './dialog/Price.vue'; |
| | | export default { |
| | | components: { |
| | | /*编辑器*/ |
| | |
| | | Getpoint, |
| | | GetBranch, |
| | | GetSupplier, |
| | | GetUser |
| | | GetUser, |
| | | ProductSelect, |
| | | ProductPrice |
| | | }, |
| | | data() { |
| | | return { |
| | |
| | | reg_date: '', |
| | | act_date: '', |
| | | radius: 0, // 活动限定范围,在范围内才能进行相关操作,如签到、下单 |
| | | // verify_user_ids: '', |
| | | |
| | | product_list: [] //选择的产品列表 |
| | | }, |
| | | /*活动类别*/ |
| | | category: [], |
| | | /*选中的分类信息*/ |
| | | selectedCategory: null, |
| | | loading: false, |
| | | upload_type: 'image', // 封面image 分享海报pic |
| | | open_branch: false, |
| | |
| | | supplier_type: 'visit', |
| | | select_list:[], // 选择的核销员列表 |
| | | open_user: false, |
| | | excludeIds: [], |
| | | islist: true, //多选 |
| | | isproduct: false, |
| | | /*验证规则*/ |
| | | rules: { |
| | | name: [{ required: true, message: '请输入活动标题', trigger: 'blur' }], |
| | |
| | | .then(res => { |
| | | self.category = res.data.category; |
| | | if(self.category.length > 0){ |
| | | self.form.category_id = self.catgory[0].category_id; |
| | | self.form.category_id = self.category[0].category_id; |
| | | // 设置默认选中的分类信息 |
| | | self.selectedCategory = self.category[0]; |
| | | } |
| | | }) |
| | | .catch(error => { |
| | | |
| | | }); |
| | | }, |
| | | |
| | | /*处理分类选择变化*/ |
| | | handleCategoryChange(value) { |
| | | // 根据选中的category_id找到对应的分类对象 |
| | | const selected = this.category.find(item => item.category_id === value); |
| | | this.selectedCategory = selected || null; |
| | | |
| | | // 可以在这里添加其他业务逻辑,比如根据分类显示不同的表单字段等 |
| | | console.log('选中的分类信息:', this.selectedCategory); |
| | | }, |
| | | |
| | | /*添加活动*/ |
| | |
| | | self.$refs.form.validate(valid => { |
| | | if (valid) { |
| | | self.loading = true; |
| | | self.form.content = this.$refs.ue.getUEContent(); |
| | | form.content = this.$refs.ue.getUEContent(); |
| | | // 如果走访企业,则被走访企业就是场地提供者 |
| | | if (self.form.is_visit) { |
| | | self.form.space_supplier_id = ''; |
| | | if (form.is_visit) { |
| | | form.space_supplier_id = ''; |
| | | } else { |
| | | self.form.visit_supplier_id = ''; |
| | | form.visit_supplier_id = ''; |
| | | } |
| | | BranchApi.addActivity(form, true) |
| | | BranchApi.addActivity({formData: JSON.stringify(form)}, true) |
| | | .then(data => { |
| | | self.loading = false; |
| | | self.$message({ |
| | | message: data.msg, |
| | | type: 'success' |
| | | }); |
| | | self.$router.push('/branch/activity/index'); |
| | | self.$router.push('/activity/activity/index'); |
| | | }) |
| | | .catch(error => { |
| | | self.loading = false; |
| | |
| | | closeSupplierFunc(e) { |
| | | if (e.type != 'error') { |
| | | if (this.supplier_type == 'visit') { |
| | | // 如果换了走访企业,清除促销商品 |
| | | if (this.form.visit_supplier_id != e.params.shop_supplier_id) { |
| | | this.form.product_list = []; |
| | | } |
| | | this.form.visit_supplier_id = e.params.shop_supplier_id; |
| | | this.visit_supplier_name = e.params.name; |
| | | } else { |
| | |
| | | deleteVerifyUser(i) { |
| | | this.select_list.splice(i, 1); |
| | | }, |
| | | |
| | | selectProduct() { |
| | | this.isproduct = true; |
| | | }, |
| | | handlePriceConfirm(changedProducts) { |
| | | const excludeIds = changedProducts.map((row) => row.product_id); |
| | | this.excludeIds = excludeIds; |
| | | changedProducts; |
| | | this.form.product_list = changedProducts; |
| | | }, |
| | | /*商品选择关闭弹窗*/ |
| | | closeProductDialogFunc(e) { |
| | | const self = this; |
| | | self.isproduct = false; |
| | | const excludeIds = []; |
| | | if (e.type == 'success') { |
| | | let product = []; |
| | | e.params.forEach((item) => { |
| | | const arr1 = { |
| | | image: item.image, |
| | | product_name: item.product_name, |
| | | product_price: item.product_price, |
| | | product_id: item.product_id, |
| | | product_sku_id: item.sku[0].product_sku_id, |
| | | spec_sku_id: item.sku[0].spec_sku_id, |
| | | product_sku_name: '单规格' |
| | | }; |
| | | if (item.specList.length > 0 && item.spec_type == 20) { |
| | | item.specList.forEach((cell, colIndex) => { |
| | | const arr2 = { |
| | | image: item.image, |
| | | product_name: item.product_name, |
| | | product_price: cell.spec_form.product_price, |
| | | product_id: item.product_id, |
| | | product_sku_id: cell.product_sku_id, |
| | | spec_sku_id: cell.spec_sku_id, |
| | | product_sku_name: cell.spec_name |
| | | }; |
| | | product.push(arr2); |
| | | }); |
| | | } else { |
| | | product.push(arr1); |
| | | } |
| | | |
| | | excludeIds.push(item.product_id); |
| | | }); |
| | | |
| | | self.excludeIds = excludeIds; |
| | | const product_list = self.form.product_list; |
| | | const new_arr = self.mergeArraysByProductId(product_list, product, 'product_id'); |
| | | self.form.product_list = new_arr; |
| | | |
| | | } |
| | | }, |
| | | |
| | | /** |
| | | * 将 B 数组中不存在于 A 数组中的项(基于 product_id)合并到 A 数组中 |
| | | * @param {Array} arrayA - 目标数组 |
| | | * @param {Array} arrayB - 源数组 |
| | | * @param {string} idKey - 用于比较的键名(默认为 'product_id') |
| | | * @returns {Array} - 合并后的新数组 |
| | | */ |
| | | mergeArraysByProductId(arrayA, arrayB, idKey = 'product_id') { |
| | | // 创建 A 数组中所有 product_id 的集合 |
| | | const idsInA = new Set(arrayA.map((item) => item[idKey])); |
| | | // 筛选出 B 数组中不存在于 A 数组的项 |
| | | const itemsToAdd = arrayB.filter((item) => !idsInA.has(item[idKey])); |
| | | // 合并数组(不改变原数组) |
| | | return [...arrayA, ...itemsToAdd]; |
| | | }, |
| | | } |
| | | }; |
| | | </script> |