diff --git a/src/subpackage/retail/components/hover_cart_list/hover_cart_list.vue b/src/subpackage/retail/components/hover_cart_list/hover_cart_list.vue index 3bfd21a..cfd03b8 100644 --- a/src/subpackage/retail/components/hover_cart_list/hover_cart_list.vue +++ b/src/subpackage/retail/components/hover_cart_list/hover_cart_list.vue @@ -10,17 +10,17 @@ - + - {{ item.erp_goods_name }} - {{ `${item.erp_goods_specs}/${item.erp_goods_specs}/${item.erp_goods_specs}` }} + {{ item.goods_name }} + {{ item.erp_goods.erp_goods_specs }} - {{ item.erp_goods_price }} + {{ item.erp_goods.erp_goods_price }} @@ -169,11 +169,13 @@ .item-right-name { font-size: 28rpx; + word-break: break-all; } .item-right-spec { margin: 8rpx 0 14rpx 0; font-size: 24rpx; color: #9A9A9D; + word-break: break-all; } } .item-right-price-count { @@ -181,6 +183,7 @@ .item-right-price-row { color: $orange; + word-break: break-all; >view { &:first-child { diff --git a/src/subpackage/retail/components/store_card_select/store_card_select.vue b/src/subpackage/retail/components/store_card_select/store_card_select.vue index 0e2e1f8..19cf516 100644 --- a/src/subpackage/retail/components/store_card_select/store_card_select.vue +++ b/src/subpackage/retail/components/store_card_select/store_card_select.vue @@ -37,7 +37,7 @@ export default { props: [ - "show", "price", "storeId" + "show", "price", "storeId", "brandId" ], data() { return { @@ -72,6 +72,7 @@ retailServer.get({ url: retailApi.assistantGetValueCardList, data: { + brand_id: this.brandId, stadium_id: this.storeId, key: this.searchCardValue, total_amount: this.price diff --git a/src/subpackage/retail/js/retail_api.js b/src/subpackage/retail/js/retail_api.js index 9d5375b..aec703e 100644 --- a/src/subpackage/retail/js/retail_api.js +++ b/src/subpackage/retail/js/retail_api.js @@ -7,6 +7,8 @@ export const RETAIL_API = { assistantGetAssistantStadiums:`${ORIGIN}/admin/assistant/getAssistantStadiums`, // 店铺列表 assistantListErpGoodsCateAndGoods:`${ORIGIN}/admin/assistant/listErpGoodsCateAndGoods`, // 分类物品列表 assistantGetValueCardList:`${ORIGIN}/admin/assistant/getValueCardList`, // 搜索储蓄卡 + getCategoryList:`${ORIGIN}/classifyer/all`, // 分类列表 + getGoodsList:`${ORIGIN}/admin/erpRetailGoods/list`, // 商品列表 } export default RETAIL_API; \ No newline at end of file diff --git a/src/subpackage/retail/pages/confirm_goods/confirm_goods.vue b/src/subpackage/retail/pages/confirm_goods/confirm_goods.vue index b202c31..db70163 100644 --- a/src/subpackage/retail/pages/confirm_goods/confirm_goods.vue +++ b/src/subpackage/retail/pages/confirm_goods/confirm_goods.vue @@ -10,20 +10,20 @@ - + - {{ item.erp_goods_name }} + {{ item.goods_name }} - {{ `${item.erp_goods_specs}/${item.erp_goods_specs}/${item.erp_goods_specs}` }} + {{ item.erp_goods.erp_goods_specs }} x{{ item.count }} - {{ item.erp_goods_price }} + {{ item.erp_goods.erp_goods_price }} @@ -66,31 +66,21 @@ onLoad(option) { let data = JSON.parse(decodeURIComponent(option.data)); this.curStore = data.curStore; - this.cartListFinal = []; - for (let i = 0; i < data.cartListFinal.length; ++i) - this.cartListFinal.push(tools.getNewObj(data.cartListFinal[i])); + this.cartListFinal = data.cartListFinal; + this.totalPrice = data.totalPrice; this.fixMainHeight(); // 适配主内容高度 - this.calcTotalPrice(); // 计算总价 util.showLoad(); setTimeout(util.hideLoad, 500); }, methods: { // 提交订单 cartConfirm() { - let data = { cartListFinal: this.cartListFinal, curStore: this.curStore }; + let data = { cartListFinal: this.cartListFinal, curStore: this.curStore, totalPrice: this.totalPrice }; uni.navigateTo({ url: `/subpackage/retail/pages/confirm_order/confirm_order?data=${encodeURIComponent(JSON.stringify(data))}` }); }, - // 计算总价 - calcTotalPrice() { - let price = 0.0; - for (let i = 0; i < this.cartListFinal.length; ++i) - price += (this.cartListFinal[i].count * this.cartListFinal[i].erp_goods_price); - - this.totalPrice = price.toFixed(2); - }, // 适配主内容高度 fixMainHeight() { let _this = this; @@ -205,11 +195,13 @@ .item-right-name { font-size: 28rpx; + word-break: break-all; } .item-right-spec { margin: 8rpx 0 14rpx 0; font-size: 24rpx; color: #9A9A9D; + word-break: break-all; @include centerFlex(space-between); } } @@ -218,6 +210,7 @@ .item-right-price-row { color: $orange; + word-break: break-all; >view { &:first-child { diff --git a/src/subpackage/retail/pages/confirm_order/confirm_order.vue b/src/subpackage/retail/pages/confirm_order/confirm_order.vue index 40134ee..322ad9f 100644 --- a/src/subpackage/retail/pages/confirm_order/confirm_order.vue +++ b/src/subpackage/retail/pages/confirm_order/confirm_order.vue @@ -42,7 +42,7 @@ @@ -54,6 +54,7 @@ import tools from '../../js/tools'; import retailServer from '../../js/retail_server'; import retailApi from '../../js/retail_api'; + import { mapState } from 'vuex' import storeCardSelect from '../../components/store_card_select/store_card_select'; @@ -82,12 +83,10 @@ onLoad(option) { let data = JSON.parse(decodeURIComponent(option.data)); this.curStore = data.curStore; - this.cartListFinal = []; - for (let i = 0; i < data.cartListFinal.length; ++i) - this.cartListFinal.push(tools.getNewObj(data.cartListFinal[i])); + this.cartListFinal = data.cartListFinal; + this.totalPrice = data.totalPrice; this.fixMainHeight(); // 适配主内容高度 - this.calcTotalPrice(); // 计算总价 this.createPayWayList(); // 创建支付方式列表 util.showLoad(); setTimeout(util.hideLoad, 500); @@ -95,6 +94,9 @@ onShow() { this.getPaySuccess(); // 获取支付成功状态 }, + computed:{ + ...mapState([ 'brandInfo',]) + }, methods: { getPaySuccess() { uni.getStorage({ @@ -111,31 +113,27 @@ // 商品出库 goodsRetail(info) { let _this = this; - let data = []; + let goods_data = []; for (let i = 0; i < this.cartListFinal.length; ++i) { - if (this.cartListFinal[i].count) { - data.push({ - id: this.cartListFinal[i].id, - name: this.cartListFinal[i].erp_goods_name, - price: this.cartListFinal[i].erp_goods_price, - nums: this.cartListFinal[i].count, - unit: this.cartListFinal[i].erp_goods_unit, - }); - } + goods_data.push({ + id: this.cartListFinal[i].erp_goods.erp_goods_cid, + name: this.cartListFinal[i].erp_goods.erp_goods_name, + price: this.cartListFinal[i].erp_goods.erp_goods_price, + nums: this.cartListFinal[i].count, + unit: this.cartListFinal[i].erp_goods.erp_goods_unit, + }); } - let newData = { - store_id: _this.curStore.id, - goods_data: data, - pay_type: info.type, - }; - if (info.inputValue) newData["other_pay_type"] = info.inputValue; - if (info.cardNo) newData["card_no"] = info.cardNo; - util.showLoad(); retailServer.post({ url: retailApi.assistantRetail, - data: newData, + data: { + goods_data, + brand_id: _this.brandInfo.brand.id, store_id: _this.curStore.id, + amount: _this.totalPrice, pay_type: info.type, + other_pay_type: info.inputValue, + card_no: info.cardNo + }, isDefaultGet: false, failMsg: '出库失败!' }).then(res => { @@ -249,14 +247,6 @@ showOrHideStoreCardSelect(status) { this.storeCardSelectShow= status; }, - // 计算总价 - calcTotalPrice() { - let price = 0.0; - for (let i = 0; i < this.cartListFinal.length; ++i) - price += (this.cartListFinal[i].count * this.cartListFinal[i].erp_goods_price); - - this.totalPrice = price.toFixed(2); - }, // 适配主内容高度 fixMainHeight() { let _this = this; diff --git a/src/subpackage/retail/pages/index/index.vue b/src/subpackage/retail/pages/index/index.vue index df3e95f..29ee88f 100644 --- a/src/subpackage/retail/pages/index/index.vue +++ b/src/subpackage/retail/pages/index/index.vue @@ -26,34 +26,34 @@ - + - + - - + + 盘罄 - {{ item.erp_goods_name }} - {{ `${item.erp_goods_specs}/${item.erp_goods_specs}/${item.erp_goods_specs}` }} - 特价 + {{ item.goods_name }} + {{ item.erp_goods.erp_goods_specs }} + - - {{ item.erp_goods_price }} + + {{ item.erp_goods.erp_goods_price }} - + {{ item.count }} - - + + @@ -75,12 +75,10 @@ - {{ totalCount }} - {{ cartTotalCount }} + {{ totalCount }} 合计: - {{ totalPrice }} - {{ cartTotalPrice }} + {{ totalPrice }} @@ -96,6 +94,7 @@ import tools from '../../js/tools'; import retailServer from '../../js/retail_server'; import retailApi from '../../js/retail_api'; import hoverCartList from '../../components/hover_cart_list/hover_cart_list'; +import { mapState } from 'vuex' export default { components: { @@ -110,10 +109,20 @@ export default { categoryScrollTop: 0, // 分类滚动值 categoryOldScrollTop: 0, // 分类滚动旧值 // 分类索引值,默认第一项是搜索,第二项可能是热销,会在获取接口数据时判断,然后过滤掉 - categoryIndex: 1, + categoryIndex: 1, + params: { + brand_id: '', + stadium_id: '', + type_key: '', + key: '', + page: 1, + page_size: 10, + }, + total: 0, + searchData: null, + searchText: '', // curStoreList: [{ id: '', name: '请选择门店'}], // 当前门店列表 - indexData: {}, // 首页 统计数据 curStoreList: [], // 当前门店列表 storeListDisabled: false, // 当前门店列表禁用状态 curStore: {}, // 当前门店 @@ -121,8 +130,6 @@ export default { mainHeight: "0rpx", // 主内容高度 totalPrice: 0, // 总价 totalCount: 0, // 总量 - cartTotalPrice: 0, // 购物车总价 - cartTotalCount: 0, // 购物车总量 cartList: [], // 购物车列表 cartListFinal: [], // 购物车最终列表数据 @@ -131,6 +138,7 @@ export default { } }, onLoad() { + this.params.brand_id = this.brandInfo.brand.id; this.deleteSearchLocal(); // 删除本地的搜索记录 this.getStoreList(); // 获取店铺列表 this.fixMainHeight(); // 适配主内容高度 @@ -139,6 +147,9 @@ export default { this.getSearchLocal(); // 获取本地的搜索记录 this.getRetailStatus(); // 获取收款出库状态 }, + computed:{ + ...mapState([ 'brandInfo',]) + }, watch: { cartList() { this.setCartConfirmStyle(); @@ -152,7 +163,11 @@ export default { uni.getStorage({ key: 'retailStatus', success: (res) => { - _this.getGoodsInfo(); // 重新获取 刷新商品数据,把出库的数据清了 + _this.searchText = ''; + _this.params.page = 1; + _this.params.type_key = ''; + _this.params.key = ''; + _this.getCategoryInfo(); // 重新获取 刷新商品数据,把出库的数据清了 _this.deleteRetailLocal(); // 删除收款出库状态 }, fail: (err) => { _this.deleteRetailLocal();}, @@ -177,37 +192,13 @@ export default { setSearchData(data) { util.showLoad(); setTimeout(util.hideLoad, 500); - this.goodsInfo[0].goods_list = []; - - // 剔除相同的商品 - let tempData = {}; - for (let i = 0; i < data.length; ++i) { - if (data[i].goods_list) { - for (let j = 0; j < data[i].goods_list.length; ++j) { - data[i].goods_list[j].count = 0; // 用来计数 - tempData["" + data[i].goods_list[j].id] = data[i].goods_list[j]; - } - } - } - - for (let key in tempData) this.goodsInfo[0].goods_list.push(tempData[key]); - - // 同步一下数据,因为有可能搜索的数据 在其他分类出现过 - let otherData = []; - for (let i = this.categoryIndex; i < this.goodsInfo.length; ++i) { - for (let j = 0; j < this.goodsInfo[i].goods_list.length; ++j) - otherData.push(this.goodsInfo[i].goods_list[j]); - } - for (let i = 0; i < this.goodsInfo[0].goods_list.length; ++i) { - for (let j = 0; j < otherData.length; ++j) { - if (this.goodsInfo[0].goods_list[i].id == otherData[j].id) - this.goodsInfo[0].goods_list[i].count = otherData[j].count; - } - } - // end + this.searchData = data; + this.goodsInfo[0].goods_list = data.list; + this.searchText = data.searchText; + this.setCount(0); this.categoryGoTop(); // 每次搜索后,分类列表都要滚动到顶部 this.goodsInfo[0].isCateShow = true; - this.mainCategoryClick(this.goodsInfo[0].cate.id); + this.mainCategoryClick(this.goodsInfo[0].cate.id, this.goodsInfo[0].isShow); }, // 获取本地的历史搜索 getSearchLocal() { @@ -229,7 +220,7 @@ export default { }, // 触发搜索 searchTrigger() { - let data = { curStore: this.curStore }; + let data = { curStore: this.curStore, brandInfo: this.brandInfo }; uni.navigateTo({ url: `/subpackage/retail/pages/search/search?data=${encodeURIComponent(JSON.stringify(data))}` }); @@ -237,19 +228,7 @@ export default { // 购物车输入确认 cartInputConfirm(value, i) { this.cartList[i].erp_goods_price = value; - this.calcCartTotalPriceAndCount(); // 计算购物车总价跟总量 - }, - // 计算购物车总价跟总量 - calcCartTotalPriceAndCount() { - let price = 0.0; - let count = 0; - - for (let i = 0; i < this.cartList.length; ++i) { - price += (this.cartList[i].count * this.cartList[i].erp_goods_price); - count += this.cartList[i].count; - } - this.cartTotalPrice = price.toFixed(2); - this.cartTotalCount = count; + this.calcTotalPriceAndCount(); // 计算购物车总价跟总量 }, // 清空购物车 clearCart() { @@ -259,85 +238,64 @@ export default { this.goodsInfo[i].goods_list[j].count = 0; } this.isShowCartList = false; - this.calcCartTotalPriceAndCount(); // 计算购物车总价跟总量 this.calcTotalPriceAndCount(); // 计算总价跟总量 }, // 购物车列表数量选项触发 cartCountClick(type, i) { - // 增减购物车对应的主页数量 - let curId = this.cartList[i].id; - let mainItems = []; // 可能不止一个 - for (let i = 0; i < this.goodsInfo.length; ++i) { - for (let j = 0; j < this.goodsInfo[i].goods_list.length; ++j) { - if (curId == this.goodsInfo[i].goods_list[j].id) - mainItems.push(this.goodsInfo[i].goods_list[j]); - } - } - switch (type) { case "add": { - if (this.cartList[i].count + 1 > this.cartList[i].stock_num) { + if (this.cartList[i].count + 1 > this.cartList[i].erp_goods.stock_num) { util.showNone("库存就这么多了!"); return; } - this.cartList[i].count += 1; - for (let i = 0; i < mainItems.length; ++i) mainItems[i].count += 1; + this.cartList[i].count += 1; } break; case "sub": { if (this.cartList[i].count > 0) this.cartList[i].count -= 1; - - for (let i = 0; i < mainItems.length; ++i) { - if (mainItems[i].count > 0) mainItems[i].count -= 1; - } } break; } + // 找主页当前列表有无该数据 + for (let k = 0; k < this.goodsInfo.length; ++k) { + if (this.goodsInfo[k].isShow) { + for (let j = 0; j < this.goodsInfo[k].goods_list.length; ++j) { + if (this.goodsInfo[k].goods_list[j].id === this.cartList[i].id) { + this.goodsInfo[k].goods_list[j].count = this.cartList[i].count; + } + } + break; + } + } if (this.cartList[i].count <= 0) this.cartList.splice(i, 1); // 没数量了就删掉 if (!this.cartList.length) this.isShowCartList = false; // 列表没了,隐藏 - this.calcCartTotalPriceAndCount(); // 计算购物车总价跟总量 this.calcTotalPriceAndCount(); // 计算总价跟总量 }, - // 获取购物车列表的最终数据 - getCartListFinalData() { - let arr = []; - for (let i = 0; i < this.cartList.length; ++i) { - if (this.cartList[i].count) arr.push(tools.getNewObj(this.cartList[i])); - } - return arr; - }, // 购物车确认 cartConfirm() { if (this.cartList.length <= 0) return; - this.cartListFinal = this.getCartListFinalData(); - - // 有数据,那么需要跳到确定页面 - if (this.cartListFinal.length) { - this.isShowCartList = false; - let data = { cartListFinal: this.cartListFinal, curStore: this.curStore }; - uni.navigateTo({ - url: `/subpackage/retail/pages/confirm_goods/confirm_goods?data=${encodeURIComponent(JSON.stringify(data))}` - }); - } - else { - util.showNone("购物车无数据!"); - } + this.cartListFinal = JSON.parse(JSON.stringify(this.cartList)); + this.isShowCartList = false; + let data = { cartListFinal: this.cartListFinal, curStore: this.curStore, totalPrice: this.totalPrice }; + uni.navigateTo({ + url: `/subpackage/retail/pages/confirm_goods/confirm_goods?data=${encodeURIComponent(JSON.stringify(data))}` + }); }, // 加入购物车列表 - addToCartList() { - this.cartList = []; - - // 计算购物车列表 - for (let i = this.categoryIndex; i < this.goodsInfo.length; ++i) { - for (let j = 0; j < this.goodsInfo[i].goods_list.length; ++j) { - if (this.goodsInfo[i].goods_list[j].count) - this.cartList.push(tools.getNewObj(this.goodsInfo[i].goods_list[j])); + addToCartList(goodsItem) { + let mark = -1; + for (let i = 0; i < this.cartList.length; ++i) { + if (this.cartList[i].id === goodsItem.id) { + mark = i; + this.cartList[i].count = goodsItem.count; + break; } } - - // 再把搜索跟热销的 不在其他分类里的数据找出来也加上 - let tempData = this.findDifferentData(); // 找不同 - for (let i = 0; i < tempData.length; ++i) this.cartList.push(tools.getNewObj(tempData[i])); + if (mark === -1) { + this.cartList.push(JSON.parse(JSON.stringify(goodsItem))); + } else if (goodsItem.count <= 0) { + this.cartList.splice(mark, 1); + } }, setCartConfirmStyle() { this.cartConfirmOpacity = this.cartList.length > 0 ? 1 : 0.3; @@ -345,17 +303,7 @@ export default { // 购物车点击 cartClick() { if (!this.cartList.length) return; - - if (this.isShowCartList) { - this.isShowCartList = false; - } - else { - this.addToCartList(); // 将主页数据加入到购物车列表 - this.cartTotalPrice = this.totalPrice; - this.cartTotalCount = this.totalCount; - this.isShowCartList = true; - this.calcCartTotalPriceAndCount(); // 计算购物车总价跟总量 - } + this.isShowCartList = !this.isShowCartList; }, // 适配主内容高度 fixMainHeight() { @@ -410,21 +358,9 @@ export default { let price = 0.0; let count = 0; - // 先计算搜索、热销后面的价格跟数量 - for (let i = this.categoryIndex; i < this.goodsInfo.length; ++i) { - for (let j = 0; j < this.goodsInfo[i].goods_list.length; ++j) { - price += (this.goodsInfo[i].goods_list[j].count * this.goodsInfo[i].goods_list[j].erp_goods_price); - count += this.goodsInfo[i].goods_list[j].count; - } - } - - // 再回过头来计算搜索跟热销的,计算热销物品不在 其他分类里的价格跟数量 - let tempData = this.findDifferentData(); // 找不同 - if (tempData.length) { - for (let i = 0; i < tempData.length; ++i) { - price += (tempData[i].count * tempData[i].erp_goods_price); - count += tempData[i].count; - } + for (let i = 0; i < this.cartList.length; ++i) { + price = parseFloat(price) + parseFloat(this.cartList[i].count * this.cartList[i].erp_goods.erp_goods_price); + count += this.cartList[i].count; } this.totalPrice = price.toFixed(2); this.totalCount = count; @@ -456,11 +392,11 @@ export default { if (goodsItem) { switch (type) { case "add": { - if (goodsItem.count + 1 > goodsItem.stock_num) { + if (goodsItem.count + 1 > goodsItem.erp_goods.stock_num) { util.showNone("库存就这么多了!"); return; } - goodsItem.count += 1; + goodsItem.count += 1; } break; case "sub": { if (goodsItem.count <= 0) return; @@ -469,18 +405,12 @@ export default { } } - // 遍历物品列表,把相同物品的数量 设置成当前点击物品的数量 - for (let i = 0; i < this.goodsInfo.length; ++i) { - for (let j = 0; j < this.goodsInfo[i].goods_list.length; ++j) { - if (this.goodsInfo[i].goods_list[j].id == goodsItem.id) - this.goodsInfo[i].goods_list[j].count = goodsItem.count; - } - } + this.addToCartList(goodsItem); // 将主页数据加入到购物车列表 this.calcTotalPriceAndCount(); // 计算总价跟总量 - this.addToCartList(); // 将主页数据加入到购物车列表 }, // 主页分类选项触发 - mainCategoryClick(id) { + mainCategoryClick(id, isShow) { + if (isShow) return; // 将所有按钮恢复默认状态,点击的按钮则是另外的状态 let item = null; for (let i = 0; i < this.goodsInfo.length; ++i) { @@ -489,72 +419,109 @@ export default { if (this.goodsInfo[i].cate.id == id) item = this.goodsInfo[i]; } - if (item) { item.style = this.categoryBtnStyle.click; item.isShow = true; + this.params.type_key = item.cate.classifyer_id; + this.params.key = item.cate.name === '搜索' ? this.searchText : ''; + this.params.page = 1; + + util.showLoad(); + if (!this.searchData) { + item.goods_list = []; + this.getGoodsInfo(); // 获取商品信息 + } else { + util.hideLoad(); + } } }, - // 获取商品信息 - getGoodsInfo() { + // 获取商品分类 + async getCategoryInfo() { let _this = this; _this.goodsInfo = []; + _this.params.page = 1; - retailServer.get({ - url: retailApi.assistantListErpGoodsCateAndGoods, + // 获取分类 + let res = await retailServer.get({ + url: retailApi.getCategoryList, data: { - // brand_id: _this.indexData.brand.id, - stadium_id: _this.curStore.id, + parent_classifyer_id: `${_this.brandInfo.brand.id}-${_this.curStore.id}-零售商品分类` }, isDefaultGet: false, - failMsg: '加载物品数据失败!' - }).then(res => { - if (res.data.code == 0) { + failMsg: '加载商品分类数据失败!' + }).catch(() => {}); + // 默认第一个搜索,第二个全部 + _this.categoryIndex = 2; // 分类索引值从2开始,前面两项过滤掉(搜索、全部) + _this.goodsInfo = [{ + isCateShow: false, isShow: false, style: _this.categoryBtnStyle.default, goods_list: [], + cate: { id: -2, classifyer_id: '', name: "搜索" } + }, { + isCateShow: true, isShow: true, style: _this.categoryBtnStyle.click, goods_list: [], + cate: { id: -1, classifyer_id: '', name: "全部" } + } + ]; + if (res && res.data && res.data.data) { + for (let i = 0; i < res.data.data.length; ++i) { _this.goodsInfo.push({ - isCateShow: false, - isShow: false, - style: _this.categoryBtnStyle.default, - cate: { - created_at: "", - erp_goods_cate_brandid: -1, - erp_goods_cate_name: "搜索", - id: -1, - update_at: "", - }, - goods_list: [], + isCateShow: true, isShow: false, style: _this.categoryBtnStyle.default, goods_list: [], + cate: { + id: res.data.data[i].id, + classifyer_id: res.data.data[i].classifyer_id, + name: res.data.data[i].name + } }); - - for (let i = 0; i < res.data.data.list.length; ++i) { - // 过滤没有商品数据的分类 - if (!res.data.data.list[i].goods_list || !res.data.data.list[i].goods_list.length) continue; - - // 如果有热销,那么分类索引值从2开始,前面两项过滤掉(搜索、热销) - if (res.data.data.list[i].cate.erp_goods_cate_name == "热销") _this.categoryIndex = 2; - - for (let j = 0; j < res.data.data.list[i].goods_list.length; ++j) - res.data.data.list[i].goods_list[j].count = 0; // 用来计数 - - res.data.data.list[i].isCateShow = true; - res.data.data.list[i].isShow = false; - res.data.data.list[i].style = _this.categoryBtnStyle.default; - _this.goodsInfo.push(res.data.data.list[i]); - } - - _this.cartList = []; // 购物车的数据清空,每次切换门店都执行 - _this.totalCount = 0; - _this.totalPrice = 0; - if (_this.goodsInfo.length > 1) { - _this.goodsInfo[1].style = _this.categoryBtnStyle.click; - _this.goodsInfo[1].isShow = true; + } + _this.cartList = []; // 购物车的数据清空,每次切换门店都执行 + _this.totalCount = 0; + _this.totalPrice = 0; + _this.categoryGoTop(); // 分类列表需要滚动至顶部 + } + + this.getGoodsInfo(); + }, + // 获取商品信息 + async getGoodsInfo() { + let _this = this; + let goodsRes = await retailServer.get({ + url: retailApi.getGoodsList, + data: _this.params, + isDefaultGet: false, + failMsg: '加载商品数据失败!' + }).catch(() => {}); + if (goodsRes && goodsRes.data && goodsRes.data.data && goodsRes.data.data.list) { + for (let j = 0; j < goodsRes.data.data.list.length; ++j) { + goodsRes.data.data.list[j].count = 0; // 用来计数 + goodsRes.data.data.list[j].erp_goods = goodsRes.data.data.list[j].erp_goods || {}; + } + for (let i = 0; i < _this.goodsInfo.length; ++i) { + if (_this.goodsInfo[i].isShow) { + // _this.goodsInfo[i].goods_list = goodsRes.data.data.list; + _this.goodsInfo[i].goods_list = _this.goodsInfo[i].goods_list.concat(goodsRes.data.data.list); + this.setCount(i); // 购物车列表的数量覆盖上当前列表的数量 + break; } - _this.categoryGoTop(); // 分类列表需要滚动至顶部 - util.hideLoad(); } - else { - util.hideLoad(); - util.showNone(res.data.message || '操作失败!'); + _this.total = goodsRes.data.data.total; + } + util.hideLoad(); + }, + setCount(index) { + for (let i = 0; i < this.cartList.length; ++i) { + for (let j = 0; j < this.goodsInfo[index].goods_list.length; ++j) { + if (this.cartList[i].id === this.goodsInfo[index].goods_list[j].id) { + this.goodsInfo[index].goods_list[j].count = this.cartList[i].count; + break; + } } - }); + } + }, + refreshList() { + // 还没到最后一页 + if (this.params.page * this.params.page_size <= this.total) { + util.showLoad(); + this.params.page += 1; + this.getGoodsInfo(); + } }, // 店铺列表 getStoreList() { @@ -574,7 +541,8 @@ export default { _this.curStoreList = [..._this.curStoreList, ..._list]; _this.curStore = _this.curStoreList[0] || {}; _this.storeListDisabled = _this.curStoreList.length > 1 ? false : true; - _this.getGoodsInfo(); // 获取商品信息 + _this.params.stadium_id = _this.curStore.id; + _this.getCategoryInfo(); // 获取商品分类 } else { util.hideLoad(); @@ -589,7 +557,7 @@ export default { _this.curStore = curStoreList[e.detail.value] || {}; _this.$nextTick(function() { util.showLoad(); - _this.getGoodsInfo(); // 获取商品信息 + _this.getCategoryInfo(); // 获取商品分类 }); }, } @@ -720,6 +688,7 @@ export default { display: flex; flex-direction: row; padding: 20rpx 0; + overflow: hidden; .item-left { position: relative; @@ -768,11 +737,13 @@ export default { .item-right-name { font-size: 28rpx; + word-break: break-all; } .item-right-spec { margin: 8rpx 0 14rpx 0; font-size: 24rpx; color: #9A9A9D; + word-break: break-all; } .item-right-special { width: 58rpx; @@ -791,6 +762,7 @@ export default { .item-right-price-row { color: $orange; + word-break: break-all; >view { font-size: 36rpx; diff --git a/src/subpackage/retail/pages/search/search.vue b/src/subpackage/retail/pages/search/search.vue index 736c304..b517d18 100644 --- a/src/subpackage/retail/pages/search/search.vue +++ b/src/subpackage/retail/pages/search/search.vue @@ -32,12 +32,14 @@ searchText: "", // 搜索文本 historyList: [], // 历史列表 curStore: {}, // 当前店铺信息 + brandInfo: {}, // 当前品牌信息 } }, onLoad(option) { this.getSearchHistory(); // 获取搜索历史 let data = JSON.parse(decodeURIComponent(option.data)); this.curStore = data.curStore; + this.brandInfo = data.brandInfo; }, methods: { // 删除历史搜索 @@ -67,9 +69,9 @@ this.searchText = ""; }, // 触发搜索 - searchTrigger(text, type) { + async searchTrigger(text, type) { if (!text) { - util.showNone("请输入商品名称、sku"); + util.showNone("请输入商品名称"); return; } @@ -86,39 +88,40 @@ } util.showLoad(); - retailServer.get({ - url: retailApi.assistantListErpGoodsCateAndGoods, - data: { assistant_key: text, stadium_id: _this.curStore.id }, + let res = await retailServer.get({ + url: retailApi.getGoodsList, + data: { + brand_id: _this.brandInfo.brand.id, + stadium_id: _this.curStore.id, + type_key: '', + key: text, + page: 1, + page_size: 10 + }, isDefaultGet: false, failMsg: '搜索失败!' - }).then(res => { - if (res.data.code == 0) { - let mark = false; - for (let i = 0; i < res.data.data.list.length; ++i) { - if (res.data.data.list[i].goods_list && res.data.data.list[i].goods_list.length) - mark = true; - } - - // 没数据 - if (!mark) { - util.showNone("暂无数据"); - return; - } - - uni.setStorage({ - key: "searchData", - data: res.data.data.list, - success: () => { - util.hideLoad(); - uni.navigateBack({ delta: 1 }); // 有数据的话就返回到上一页面,加载对应数据 - }, - fail: (err) => { util.showNone("搜索失败"); }, - }); + }).catch(() => {}); + if (res && res.data && res.data.data && res.data.data.list) { + if (!res.data.data.list.length) { + util.showNone("暂无数据"); + return; } - else { - util.showNone(res.data.message || '操作失败!'); + for (let j = 0; j < res.data.data.list.length; ++j) { + res.data.data.list[j].count = 0; // 用来计数 + res.data.data.list[j].erp_goods = res.data.data.list[j].erp_goods || {}; } - }); + uni.setStorage({ + key: "searchData", + data: { searchText: text, list: res.data.data.list }, + success: () => { + util.hideLoad(); + uni.navigateBack({ delta: 1 }); // 有数据的话就返回到上一页面,加载对应数据 + }, + fail: (err) => { util.showNone("搜索失败"); }, + }); + } else { + util.showNone(res.data.message || '操作失败!'); + } }, // 获取搜索历史 getSearchHistory() {