Skip to content

Commit

Permalink
搜索框增加一键扫条形码搜商品
Browse files Browse the repository at this point in the history
  • Loading branch information
gooking committed Dec 25, 2021
1 parent 61b7568 commit 80ae8ca
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 7 deletions.
1 change: 1 addition & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ App({
if (this.configLoadOK) {
this.configLoadOK()
}
// wx.setStorageSync('shopMod', '1') // 测试用,不要取消注释
}
})
// ---------------检测navbar高度
Expand Down
4 changes: 2 additions & 2 deletions config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
version: '12.9.2',
note: '细节优化', // 这个为版本描述,无需修改
version: '12.10.0',
note: '搜索框增加一键扫条形码搜商品', // 这个为版本描述,无需修改
subDomain: 'tz', // liu123 此处改成你自己的专属域名。什么是专属域名?请看教程 https://www.it120.cc/help/qr6l4m.html
merchantId: 951, // 商户ID,可在后台工厂设置-->商户信息查看
sdkAppID: 1400450467, // 腾讯实时音视频应用编号,请看教程 https://www.it120.cc/help/nxoqsl.html
Expand Down
10 changes: 10 additions & 0 deletions miniprogram_npm/apifm-wxapi/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,16 @@ module.exports = {
}
return request('/shop/goods/list', true, 'post', data);
},
goodsv2: (data) => {
if (!data) {
data = {}
}
const shopIds = wx.getStorageSync('shopIds')
if (shopIds) {
data.shopId = shopIds
}
return request('/shop/goods/list/v2', true, 'post', data)
},
goodsDetail: function goodsDetail(id) {
var token = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';

Expand Down
13 changes: 13 additions & 0 deletions pages/category/category.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,4 +411,17 @@ Page({
})
}
},
searchscan() {
wx.scanCode({
scanType: ['barCode', 'qrCode', 'datamatrix', 'pdf417'],
success: res => {
this.setData({
inputVal: res.result
})
wx.navigateTo({
url: '/pages/goods/list?name=' + res.result,
})
}
})
}
})
4 changes: 3 additions & 1 deletion pages/category/category.wxml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<van-search value="{{ name }}" placeholder="请输入搜索关键词" shape="round" bind:search="bindconfirm" />
<van-search value="{{ name }}" placeholder="请输入搜索关键词" shape="round" bind:search="bindconfirm" use-right-icon-slot>
<van-icon slot="right-icon" name="scan" bind:click="searchscan" />
</van-search>
<view class="main">
<scroll-view class="category-container" scroll-y="true" scroll-with-animation="true" scroll-into-view="{{ aaa }}">
<van-sidebar custom-class="sidebar-l" active-key="{{ activeCategory }}">
Expand Down
6 changes: 3 additions & 3 deletions pages/goods/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,16 @@ Page({
if (this.data.categoryId) {
_data.categoryId = this.data.categoryId
}
const res = await WXAPI.goods(_data)
const res = await WXAPI.goodsv2(_data)
wx.hideLoading()
if (res.code == 0) {
if (this.data.page == 1) {
this.setData({
goods: res.data,
goods: res.data.result,
})
} else {
this.setData({
goods: this.data.goods.concat(res.data),
goods: this.data.goods.concat(res.data.result),
})
}
} else {
Expand Down
5 changes: 5 additions & 0 deletions pages/index/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,11 @@ Page({
TOOLS.showTabBarBadge()
this.goodsDynamic()
this.miaoshaGoods()
const refreshIndex = wx.getStorageSync('refreshIndex')
if (refreshIndex) {
this.onPullDownRefresh()
wx.removeStorageSync('refreshIndex')
}
},
async goodsDynamic(){
const res = await WXAPI.goodsDynamic(0)
Expand Down
10 changes: 10 additions & 0 deletions pages/search/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,15 @@ Page({
wx.redirectTo({
url: '/pages/goods/list?name=' + keywords,
})
},
searchscan() {
wx.scanCode({
scanType: ['barCode', 'qrCode', 'datamatrix', 'pdf417'],
success: res => {
wx.redirectTo({
url: '/pages/goods/list?name=' + res.result,
})
}
})
}
})
4 changes: 3 additions & 1 deletion pages/search/index.wxml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<van-search placeholder="请输入搜索关键词" focus bind:search="search" />
<van-search placeholder="请输入搜索关键词" focus bind:search="search" use-right-icon-slot>
<van-icon slot="right-icon" name="scan" bind:click="searchscan" />
</van-search>
<van-empty wx:if="{{ !list || list.length == 0 }}" description="暂无历史搜索" />
<van-cell-group wx:if="{{ list && list.length > 0 }}" title="历史搜索">
<van-cell wx:for="{{list}}" wx:key="*this">
Expand Down
1 change: 1 addition & 0 deletions pages/shop/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ Page({
const idx = e.currentTarget.dataset.idx
wx.setStorageSync('shopInfo', this.data.shops[idx])
wx.setStorageSync('shopIds', this.data.shops[idx].id)
wx.setStorageSync('refreshIndex', 1)
wx.switchTab({
url: '/pages/index/index'
})
Expand Down

0 comments on commit 80ae8ca

Please sign in to comment.