/** * @m-choose-goods 选择商品 * @m-show-choose-goods 显示已选中的商品列表 */ Vue.component('m-choose-goods', { template: ` 搜索 已选 选择 已选 {{chooseIdList.length}}/20 确定 `, props: { 'showChooseGoods': { type: Boolean, default: false, }, 'needChoose': { type: Boolean, default: true, }, 'usedIdList': { type: Array, default: () => { return [] }, },//已选ID列表 'selectedClassId': { type: Array, default: () => { return [] }, },//已指定分类ID列表 'storeId': { type: String, default: '', },//门店ID }, data() { return { searchForm: { exists_class_id_arr: '', search_info: '', person1: '', person2: '', person3: '', store_id: '', page: 1, limit: 10, }, currentLen: 0, dataList: [], chooseList: [],//本次已选商品列表 chooseIdList: [],//本次已选商品ID列表 refresh: false, } }, methods: { closeDialog(type) { this.$emit('close', type === 1 ? this.chooseList : []); }, verifyUsed(item) { let key = item.id; if (item.attribute_state == 2) { key += '_' + item.sku_id; } return this.chooseIdList.indexOf(key) >= 0 ? true : false; }, chooseSearchClass(item) { this.searchForm.person1 = item.data[0] ? item.data[0] : ''; this.searchForm.person2 = item.data[1] ? item.data[1] : ''; this.searchForm.person3 = item.data[2] ? item.data[2] : ''; }, chooseIt(item) { this.chooseList.push(item); let key = item.id; if (item.attribute_state == 2) { key += '_' + item.sku_id; } this.chooseIdList.push(key); this.refresh = true; this.$nextTick(() => { this.refresh = false; }) }, // 切换记录每页数量 limitChange(val) { this.searchForm.limit = val; this.searchForm.page = 1; this.getGoodsList(); }, // 切换记录页数 pageChange(val) { this.searchForm.page = val; this.getGoodsList(); }, // 商品列表 getGoodsList() { $.ajax({ url: '/index.php/Retail/Mcoupon/appointGoods', type: "post", data: this.searchForm, success: (res) => { if (res.status == 1) { this.dataList = res.data.list; this.currentLen = res.data.count * 1; } else { this.dataList = []; this.currentLen = 0; } } }) }, }, watch: { showChooseGoods(n, o) { if (n) { this.searchForm.store_id = this.storeId; if (this.selectedClassId.length) { this.searchForm.person1 = this.selectedClassId[0] ? this.selectedClassId[0] : ''; this.searchForm.person2 = this.selectedClassId[1] ? this.selectedClassId[1] : ''; this.searchForm.person3 = this.selectedClassId[2] ? this.selectedClassId[2] : ''; } this.$nextTick(() => { this.searchForm.exists_id_arr = this.chooseIdList.join(','); this.pageChange(1); }) } else { this.searchForm = { exists_id_arr: '', search_info: '', person1: '', person2: '', person3: '', store_id: '', page: 1, limit: 10, }; this.currentLen = 0; this.dataList = []; this.chooseList = [];//本次已选分类列表 this.chooseIdList = [];//本次已选分类ID列表 this.refresh = false; } }, usedIdList(n) { this.chooseIdList = JSON.parse(JSON.stringify(n)); }, }, }); Vue.component('m-show-choose-goods', { template: ` 删除 `, props: { 'goodsList': { type: Array, default: () => { return []; }, }, 'operateState': { type: Boolean, default: false, },//操作的权限 }, methods: { //移除已选商品 removeGoods(index, goods_id) { this.goodsList.splice(index, 1); this.$nextTick(() => { this.$emit('del', goods_id); }); }, } });
已选 {{chooseIdList.length}}/20