赵明涛
11 months ago
16 changed files with 491 additions and 132 deletions
-
13uniapp_project_code/src/components/index/keyboard/keyboard_listener.vue
-
4uniapp_project_code/src/components/index/list_item.vue
-
24uniapp_project_code/src/components/index/page_standby.vue
-
8uniapp_project_code/src/components/index/view_footer.nvue
-
10uniapp_project_code/src/components/index/view_header.nvue
-
6uniapp_project_code/src/components/pay/paying.vue
-
48uniapp_project_code/src/components/pay/success.vue
-
0uniapp_project_code/src/pages/index/-standby.nvue
-
132uniapp_project_code/src/pages/index/index.vue
-
244uniapp_project_code/src/pages/index/standby.vue
-
7uniapp_project_code/src/pages/login/index.vue
-
39uniapp_project_code/src/pages/login/success.vue
-
22uniapp_project_code/src/pages/pay/index.vue
-
BINuniapp_project_code/src/static/index/camera_icon2.png
-
8uniapp_project_code/src/utils/util.js
@ -0,0 +1,244 @@ |
|||||
|
<template> |
||||
|
<view> |
||||
|
<page-standby></page-standby> |
||||
|
<keyboard-listener style="height: 1px;" @keyup="onKeyup" @keydown="onKeydown"></keyboard-listener> |
||||
|
</view> |
||||
|
</template> |
||||
|
|
||||
|
<script> |
||||
|
|
||||
|
import pageStandby from '@/components/index/page_standby.vue';//待机页 |
||||
|
import keyboardListener from '@/components/index/keyboard/keyboard_listener.vue'; //键盘监听 |
||||
|
|
||||
|
import util from "@/utils/util.js" |
||||
|
import dictKeyboard from '@/utils/dictOfKeyboard' |
||||
|
import { |
||||
|
API |
||||
|
} from "@/utils/api"; |
||||
|
import { |
||||
|
ox |
||||
|
} from "@/utils/server"; |
||||
|
|
||||
|
let app = getApp(); |
||||
|
export default { |
||||
|
components: { |
||||
|
'page-standby': pageStandby, |
||||
|
'keyboard-listener': keyboardListener, |
||||
|
}, |
||||
|
watch: { |
||||
|
//已拆分standby到单独页面, 不再需要计算在本nvue页面高度 |
||||
|
// showPageStandby(ov,nv){ |
||||
|
// if(nv){ |
||||
|
// // #ifdef APP-NVUE |
||||
|
// setTimeout(async()=>{ |
||||
|
// dom = weex.requireModule("dom"); |
||||
|
// let size = await util.getNvueRefSize(this,dom,"mfooter"); |
||||
|
// this.footerHeight = size.height.toFixed(2) |
||||
|
// },200) |
||||
|
// // #endif |
||||
|
// } |
||||
|
// } |
||||
|
}, |
||||
|
computed: { |
||||
|
shopListTotalPrice() { |
||||
|
let _total = 0 |
||||
|
if (!this.shopList || this.shopList.length < 1) return 0 |
||||
|
this.shopList.forEach(item => { |
||||
|
_total += item.shopCountPrice |
||||
|
}) |
||||
|
return _total |
||||
|
}, |
||||
|
shopListTotalCount() { |
||||
|
let _total = 0 |
||||
|
if (!this.shopList || this.shopList.length < 1) return 0 |
||||
|
this.shopList.forEach(item => { |
||||
|
_total += item.shopCount |
||||
|
}) |
||||
|
return _total |
||||
|
}, |
||||
|
//已拆分standby到单独页面, 不再需要计算在本nvue页面高度 |
||||
|
// footerHeight(){ |
||||
|
// return this.screenHeight - 100 |
||||
|
// } |
||||
|
}, |
||||
|
data() { |
||||
|
return { |
||||
|
// showPageStandby: false, |
||||
|
showQRInputBox: false, |
||||
|
showEndPhoneBox: false, |
||||
|
screenHeight: '', |
||||
|
footerHeight: '', |
||||
|
// globalData: app.globalData, |
||||
|
globalData: "", |
||||
|
shopList: [], |
||||
|
decryptList: [], |
||||
|
strResult: "", |
||||
|
} |
||||
|
}, |
||||
|
async onLoad(res) { |
||||
|
console.log("onload:", res) |
||||
|
// this.test() |
||||
|
// this.showPageStandby = true |
||||
|
}, |
||||
|
async onReady() { |
||||
|
// this.screenHeight = await util.getPageHeight() |
||||
|
console.log(`the index page onReady----` + this.screenHeight) |
||||
|
app = getApp(); |
||||
|
setTimeout(async () => { |
||||
|
await this.updateGoodsList().then(async () => { |
||||
|
// console.log("skulist:", this.shopList) |
||||
|
}) |
||||
|
}, 100) |
||||
|
}, |
||||
|
methods: { |
||||
|
async setTestSku() { |
||||
|
console.log("Test set SKU 10000012") |
||||
|
let skulist = await this.searchGoodBySku("10000012") |
||||
|
this.shopList = this.shopList.concat(skulist) |
||||
|
}, |
||||
|
|
||||
|
combinedList(list1, list2) { |
||||
|
|
||||
|
console.log("combinedList", list1, list2) |
||||
|
if (!list2) return util.showNone("未找到商品") |
||||
|
|
||||
|
let _list = list1 |
||||
|
list2.forEach(item => { |
||||
|
let _index = _list.findIndex(_item => _item.id == item.id) |
||||
|
if (_index != -1) { |
||||
|
_list[_index].shopCount += 1 |
||||
|
_list[_index].shopCountPrice = _list[_index].erp_goods.erp_goods_price * _list[_index].shopCount |
||||
|
} else { |
||||
|
_list.push(item) |
||||
|
} |
||||
|
}) |
||||
|
return _list |
||||
|
}, |
||||
|
|
||||
|
// 按键松开事件 |
||||
|
async onKeyup(event) { |
||||
|
console.log("按键松开: ", event) |
||||
|
// decryptList, strResult |
||||
|
let res = dictKeyboard.dict[event.keyCode]; |
||||
|
console.log("keyCode from keyboard:", res); |
||||
|
this.decryptList.push(res); |
||||
|
if (event.keyCode != 13) { |
||||
|
return console.log("继续接收:", this.decryptList) |
||||
|
}; |
||||
|
this.decryptList.pop(); |
||||
|
this.strResult = await dictKeyboard.resultScan(this.decryptList); |
||||
|
console.log("扫码结果-step-1:", this.strResult) |
||||
|
this.orderQrcode = this.strResult |
||||
|
console.log("decryptList-before-splice: ", this.decryptList) |
||||
|
this.decryptList.splice(0); |
||||
|
console.log("decryptList-after-splice: " + this.decryptList) |
||||
|
|
||||
|
//过滤结果中的down_arrow |
||||
|
if (this.strResult.indexOf("down_arrow") != -1) { |
||||
|
this.strResult = this.strResult.replace("down_arrow", "") |
||||
|
} |
||||
|
console.log("扫码结果-step-2:", this.strResult) |
||||
|
|
||||
|
let skulist = await this.searchGoodBySku(this.strResult).then(res => { |
||||
|
console.log("searchGoodBySku suc: ", res) |
||||
|
return res |
||||
|
}).then(skulist => { |
||||
|
this.addSkuListToShopList(skulist); |
||||
|
// return skulist |
||||
|
}).catch(err => { |
||||
|
console.log("searchGoodBySku err: ", err) |
||||
|
util.showNone("未找到商品") |
||||
|
}) |
||||
|
//将skulist合并到shopList |
||||
|
// this.shopList = this.combinedList(this.shopList, skulist) |
||||
|
// this.shopList = this.shopList.concat(skulist) |
||||
|
|
||||
|
}, |
||||
|
//跳转index页面,并将商品列表传递过去 |
||||
|
addSkuListToShopList(skulist) { |
||||
|
console.log("addSkuListToShopList", skulist) |
||||
|
skulist = encodeURIComponent(JSON.stringify(skulist)) |
||||
|
uni.reLaunch({ |
||||
|
url: `/pages/index/index?skulist=${skulist}`, |
||||
|
animationType: 'zoom-fade-out', |
||||
|
animationDuration: 300 |
||||
|
}); |
||||
|
|
||||
|
}, |
||||
|
|
||||
|
// 监听按键按下事件 |
||||
|
onKeydown(event) { |
||||
|
// console.log("按键按下: ", event) |
||||
|
}, |
||||
|
// 业务逻辑 |
||||
|
getGoodFromPad(sku, brand_id) { |
||||
|
return ox.get({ |
||||
|
url: API.getGoodFromPad, |
||||
|
data: { |
||||
|
sku, |
||||
|
brand_id |
||||
|
}, |
||||
|
isDefaultGet: true |
||||
|
}) |
||||
|
.then(res => { |
||||
|
util.hideLoad(); |
||||
|
if (res.data.code == 0) { } |
||||
|
return res |
||||
|
}) |
||||
|
}, |
||||
|
// 更新商品列表 |
||||
|
async updateGoodsList() { |
||||
|
let _list = await this.getGoodsList() |
||||
|
//打印信息 |
||||
|
console.log("app.globaldata: ", app.globalData) |
||||
|
app.globalData.goodsList = _list |
||||
|
}, |
||||
|
// 更新购物车列表 |
||||
|
updateShopList() { |
||||
|
app.globalData.shopList = this.shopList |
||||
|
}, |
||||
|
getGoodsList() { |
||||
|
let url = |
||||
|
"https://testmanager.ouxuanzhineng.cn/admin/erpRetailGoods/list?brand_id=63&stadium_id=167&type_key=&key=&page=1&page_size=9999&is_sale=1&is_show_on_assistant=1&token=e6cabeae-0c1a-11ee-aa40-5254005df464"; |
||||
|
let urlParams = util.getUrlParams(url); |
||||
|
console.log("getGoodsList需要适配urlParams:", urlParams) |
||||
|
|
||||
|
return ox.get({ |
||||
|
url: API.getGoodsList, |
||||
|
data: urlParams, |
||||
|
isDefaultGet: true, |
||||
|
failMsg: "获取商品列表失败" |
||||
|
}) |
||||
|
.then(res => { |
||||
|
|
||||
|
util.hideLoad(); |
||||
|
console.log("getGoodsList suc: ", res) |
||||
|
|
||||
|
//为res.list中每一项设置shopCountPrice,shopCount |
||||
|
res.list.forEach(item => { |
||||
|
item.shopCount = 1 |
||||
|
item.shopCountPrice = item.erp_goods.erp_goods_price |
||||
|
}) |
||||
|
return res |
||||
|
}) |
||||
|
}, |
||||
|
searchGoodBySku(sku) { |
||||
|
return new Promise((resolve, reject) => { |
||||
|
let _list = app.globalData.goodsList.list |
||||
|
// let _good = _list.find(item=>item.erp_goods.erp_goods_sku == sku) |
||||
|
//sku可能不唯一, 返回数组 |
||||
|
let _goods = _list.filter(item => item.erp_goods.erp_goods_sku == sku) |
||||
|
|
||||
|
if (_goods.length) { |
||||
|
resolve(_goods) |
||||
|
} else { |
||||
|
reject(false) |
||||
|
} |
||||
|
}) |
||||
|
}, |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
</script> |
||||
|
|
||||
|
<style lang="scss" scoped></style> |
After Width: 112 | Height: 111 | Size: 3.7 KiB |
Write
Preview
Loading…
Cancel
Save
Reference in new issue