Commit eb04515b authored by jiangjiantao's avatar jiangjiantao

扫商品页面交互

parent 116e8c72
......@@ -2,3 +2,7 @@
.DS_Store
/.tea
.tea/layout.json
.tea/layout.json
.tea/entryFiles-development/index$.worker.js
.tea/entryFiles-development/index$.web.js
.tea/entryFiles-development/config$.js
{"tinyType":"alipayiot","tinyCnName":"支付宝 IoT","tinyProjectType":"xpaas-mini","alipayiot:xpaas-mini:tinyIcon":"https://gw.alipayobjects.com/mdn/rms_c763d8/afts/img/A*vNMFT7X_u3sAAAAAAAAAAABkARQnAQ","alipayiot:xpaas-mini:auditLink":null,"alipayiot:xpaas-mini:whiteListLink":null,"alipayiot:xpaas-mini:createLink":null,"alipayiot:xpaas-mini:component2":false,"alipayiot:xpaas-mini:_enableAutoPush":false,"alipayiot:xpaas-mini:_appIdList":[],"alipayiot:xpaas-mini:uploadTime":"","alipayiot:xpaas-mini:packageSize":0,"alipayiot:xpaas-mini:lastDeviceName":"蜻蜓F4","isSimulatorOpen":true,"isNotFirstToggleSimulator":true,"alipayiot:xpaas-mini:MockStore":{"localLoginInfo":{"name":"ywxadmin","password":"1234567a","sn":""},"localAccountInfo":{"accountId":126,"actType":1,"agreement":1,"isShopCart":0,"merchantId":"2088222276054714","merchantName":"一网鲜(杭州)信息科技有限公司","realName":"力拔山兮气盖世时不利兮骓不逝","storeList":[{"address":"杭州市江干区科技园路2号","hasStoreManager":1,"storeId":"001","storeName":"一网鲜"}],"token":"431398226761175040","userName":"ywxadmin","userPhone":"13858057743"}},"storageVersion":"1.5.7"}
const g = typeof global !== 'undefined' ? global : self;
g.appXAppJson = {
"app": {
"$homepage": "pages/paysuccess/paysuccess"
}
};
require('@alipay/appx-compiler/lib/sjsEnvInit');
require('./config$');
require('../../custom_widgets/spin/spin?hash=05d2a9730dd6009bf9446182f9c985f40f8c0f43');
require('../../node_modules/mini-antui/es/input-item/index?hash=05d2a9730dd6009bf9446182f9c985f40f8c0f43');
require('../../pages/paysuccess/paysuccess?hash=8a39df616008c86a406618844f053cdc5567752b');
require('../../pages/login/login?hash=4ebd76d5932655db30c27bd67ebeb700d746609f');
require('../../pages/index/index?hash=32d7d2807ed4e666ef03b4b3fe8c38ecf2e34e68');
if(!self.__appxInited) {
self.__appxInited = 1;
require('./config$');
var AFAppX = self.AFAppX.getAppContext
? self.AFAppX.getAppContext().AFAppX
: self.AFAppX;
self.getCurrentPages = AFAppX.getCurrentPages;
self.getApp = AFAppX.getApp;
self.Page = AFAppX.Page;
self.App = AFAppX.App;
self.my = AFAppX.bridge || AFAppX.abridge;
self.abridge = self.my;
self.Component = AFAppX.WorkerComponent || function(){};
self.$global = AFAppX.$global;
self.requirePlugin = AFAppX.requirePlugin;
if(AFAppX.registerApp) {
AFAppX.registerApp({
appJSON: appXAppJson,
});
}
function success() {
require('../../app');
require('../../custom_widgets/spin/spin?hash=05d2a9730dd6009bf9446182f9c985f40f8c0f43');
require('../../node_modules/mini-antui/es/input-item/index?hash=05d2a9730dd6009bf9446182f9c985f40f8c0f43');
require('../../pages/paysuccess/paysuccess?hash=8a39df616008c86a406618844f053cdc5567752b');
require('../../pages/login/login?hash=4ebd76d5932655db30c27bd67ebeb700d746609f');
require('../../pages/index/index?hash=32d7d2807ed4e666ef03b4b3fe8c38ecf2e34e68');
}
self.bootstrapApp ? self.bootstrapApp({ success }) : success();
}
\ No newline at end of file
{"layout":{"left":{"currentId":"scm_container","size":310},"right":{"currentId":""},"bottom":{"currentId":"devtools","size":164}},"storageVersion":"1.5.5"}
\ No newline at end of file
{"layout":{"left":{"currentId":"scm_container","size":371},"right":{"currentId":""},"bottom":{"currentId":"devtools","size":215}},"storageVersion":"1.5.5"}
\ No newline at end of file
......@@ -10,7 +10,9 @@ App({
BASE_URL: null,
appId:"1542075029346",
//小程序容器版本
containerVersionCode: null
containerVersionCode: null,
localAccountInfo:null,
sn:""
},
onLaunch(options) {
......
{
"pages": [
"pages/login/login",
"pages/scan/scan",
"pages/paysuccess/paysuccess",
"pages/login/login",
"pages/index/index"
],
"window": {
......
......@@ -23,6 +23,8 @@ Page({
this.setData({
sn: serialno.value
});
//设置到全局变量
getApp().globalData.sn = serialno.value;
}
//获取下本地登录数据
......@@ -111,15 +113,14 @@ Page({
sn: this.data.sn
}
});
//请求网络
var api = require("../../utils/api.js");
var loginCallbackTemp = this.loginCallback.bind(this);
api.login({
baseUrl: getApp().globalData.BASE_URL,
appId:getApp().globalData.appId,
name: this.data.name,
password: this.data.password,
sn: this.data.sn+"xx",
callback: loginCallbackTemp
});
},
......@@ -132,9 +133,11 @@ Page({
key: 'localAccountInfo', // 缓存数据的key
data: res.data, // 要缓存的数据
});
//跳转广告页
//登陆信息设置到全局变量
getApp().globalData.localAccountInfo = res.data;
//todo 临时跳转到扫商品页面 跳转广告页
my.reLaunch({
url: "/pages/paysuccess/paysuccess"
url: "/pages/scan/scan"
});
my.showToast({
type: 'success',
......
......@@ -43,7 +43,7 @@
display: flex;
flex-direction: row;
width: 100%;
height: 87.5rpx;
height: 175rpx;
align-items:center;
}
/* 商品价格 */
......
......@@ -28,19 +28,19 @@
总额
</view>
<view class="scan-price-total">
¥688.00
¥{{totalPrice}}
</view>
<view class="scan-price-quantity-propmt">
(共3件)
(共{{totalQuantity}}件)
</view>
</view>
<view class="scan-bottom-item">
<!-- <view class="scan-bottom-item">
<view class="scan-price-total-propmt">
已优惠
</view>
<view class="scan-disc-total">
¥68.00
¥{{totalDisc}}
</view>
</view>
</view> -->
</view>
</view>
\ No newline at end of file
var api = require("../../utils/api.js");
import { Page } from '../../utils/scan';
Page({
data: {
goods: [
{
/**
* 活动id
*/
activityId: "",
/**
* 活动类型
*/
activityType: "",
/**
* 活动名字
*/
activityName: "",
/**
* 折扣金额
*/
discnt: 0,
/**
* 活动开始时间
*/
startTime: 0,
/**
* 活动结束时间
*/
endTime: 0,
/**
* 商品图片
*/
pic: "",
/**
* 商品名字
*/
name: "杜蕾斯",
/**
* 商品价格,单位:分,后端定义的int,fck
*/
price: 20.88,
/**
* 售卖价格(单位分)
*/
salePrice: 0,
/**
* 商品数量:用于本地计算,默认为1
*/
quantity: 1,
goods: [],
totalPrice: 0.00,
totalQuantity: 0
},
/**
* 商品条码
*/
barcode: "",
/**
* 是否咱家优惠
*/
hasDiscount: false,
},
{
/**
* 活动id
*/
activityId: "",
/**
* 活动类型
*/
activityType: "",
/**
* 活动名字
*/
activityName: "",
/**
* 折扣金额
*/
discnt: 0,
/**
* 活动开始时间
*/
startTime: 0,
/**
* 活动结束时间
*/
endTime: 0,
/**
* 商品图片
*/
pic: "",
/**
* 商品名字
*/
name: "杜蕾斯",
/**
* 商品价格,单位:分,后端定义的int,fck
*/
price: 20.88,
/**
* 售卖价格(单位分)
*/
salePrice: 0,
/**
* 商品数量:用于本地计算,默认为1
*/
quantity: 1,
//外接扫码枪事件
onKeyPress(r) {
console.log("scan onKeyPress==>" + r);
this.getGoodInfoByBarcode(r);
},
/**
* 商品条码
*/
barcode: "",
/**
* 是否咱家优惠
*/
hasDiscount: false,
//获取商品信息
getGoodInfoByBarcode(barcode) {
////根据条形码查询商品接口
var API_SCAN = "market/barcodeQuery";
my.showLoading({});
var scanGoodRequest = api.createCommonRequest();
scanGoodRequest.goodsId = barcode;
console.log("扫商品的请求 ==>" + JSON.stringify(scanGoodRequest));
my.request({
url: getApp().globalData.BASE_URL + API_SCAN,
method: 'POST',
dataType: 'json',
timeout: 30000,
data: scanGoodRequest,
success: (res) => {
my.hideLoading();
console.log("扫描商品成功 ==>" + JSON.stringify(res));
if (res.data.success != true) {
my.showToast({
type: 'fail',
content: res.data.message,
duration: 2000
});
} else {
var arr = Object.keys(res.data.data);
if (arr.length == 0) {
my.showToast({
type: 'fail',
content: "该商品没有对应的活动",
duration: 2000
});
} else {
//识别商品成功
this.parseGoodInfo(res.data.data);
console.log("识别商品信息成功");
}
}
},
{
/**
* 活动id
*/
activityId: "",
/**
* 活动类型
*/
activityType: "",
/**
* 活动名字
*/
activityName: "",
/**
* 折扣金额
*/
discnt: 0,
/**
* 活动开始时间
*/
startTime: 0,
/**
* 活动结束时间
*/
endTime: 0,
/**
* 商品图片
*/
pic: "",
/**
* 商品名字
*/
name: "杜蕾斯",
/**
* 商品价格,单位:分,后端定义的int,fck
*/
price: 20.88,
/**
* 售卖价格(单位分)
*/
salePrice: 0,
/**
* 商品数量:用于本地计算,默认为1
*/
quantity: 1,
fail: (res) => {
my.hideLoading();
console.log("扫商品的请求 ==>" + JSON.stringify(res));
my.showToast({
type: 'exception',
content: api.decodeErrorMessage(res.error),
duration: 2000
});
}
});
},
/**
* 商品条码
*/
barcode: "",
/**
* 是否咱家优惠
*/
hasDiscount: false,
},
{
/**
* 活动id
*/
activityId: "",
/**
* 活动类型
*/
activityType: "",
/**
* 活动名字
*/
activityName: "",
/**
* 折扣金额
*/
discnt: 0,
/**
* 活动开始时间
*/
startTime: 0,
/**
* 活动结束时间
*/
endTime: 0,
/**
* 商品图片
*/
pic: "",
/**
* 商品名字
*/
name: "杜蕾斯",
/**
* 商品价格,单位:分,后端定义的int,fck
*/
price: 20.88,
/**
* 售卖价格(单位分)
*/
salePrice: 0,
/**
* 商品数量:用于本地计算,默认为1
*/
quantity: 1,
/**
* 商品条码
*/
barcode: "",
/**
* 是否咱家优惠
*/
hasDiscount: false,
},
{
/**
* 活动id
*/
activityId: "",
/**
* 活动类型
*/
activityType: "",
/**
* 活动名字
*/
activityName: "",
/**
* 折扣金额
*/
discnt: 0,
/**
* 活动开始时间
*/
startTime: 0,
/**
* 活动结束时间
*/
endTime: 0,
/**
* 商品图片
*/
pic: "",
/**
* 商品名字
*/
name: "杜蕾斯",
/**
* 商品价格,单位:分,后端定义的int,fck
*/
price: 20.88,
/**
* 售卖价格(单位分)
*/
salePrice: 0,
/**
* 商品数量:用于本地计算,默认为1
*/
quantity: 1,
//转化商品信息
parseGoodInfo(goodinfo) {
//价格 分转元
goodinfo.quantity = 1;
goodinfo.price = goodinfo.price/100
goodinfo.salePrice = goodinfo.salePrice/100
goodinfo.discnt = goodinfo.discnt/100
/**
* 商品条码
*/
barcode: "",
/**
* 是否咱家优惠
*/
hasDiscount: false,
}, {
/**
* 活动id
*/
activityId: "",
/**
* 活动类型
*/
activityType: "",
/**
* 活动名字
*/
activityName: "",
/**
* 折扣金额
*/
discnt: 0,
/**
* 活动开始时间
*/
startTime: 0,
/**
* 活动结束时间
*/
endTime: 0,
/**
* 商品图片
*/
pic: "",
/**
* 商品名字
*/
name: "杜蕾斯",
/**
* 商品价格,单位:分,后端定义的int,fck
*/
price: 20.88,
/**
* 售卖价格(单位分)
*/
salePrice: 0,
/**
* 商品数量:用于本地计算,默认为1
*/
quantity: 1,
//总数量
let totalQuantityTemp = 0
//总价格
let totalPriceTemp = 0.00
/**
* 商品条码
*/
barcode: "",
/**
* 是否咱家优惠
*/
hasDiscount: false,
//数量+1
let isHasSame = false;
let lastgoods = this.data.goods;
let goodstemp = []
let goodtemp
lastgoods.forEach(function (item, index, array) {
if(item.barcode == goodinfo.barcode){
let quantitytemp = item.quantity
item.quantity = quantitytemp+1
isHasSame = true
goodtemp = item
}else{
totalQuantityTemp = totalQuantityTemp + item.quantity
totalPriceTemp = totalPriceTemp + item.price*item.quantity
goodstemp.push(item)
}
],
})
if(isHasSame){
totalQuantityTemp = totalQuantityTemp + goodtemp.quantity
totalPriceTemp = totalPriceTemp + goodtemp.price*goodtemp.quantity
let nowgoods = []
nowgoods.push(goodtemp);
var newgoods = nowgoods.concat(goodstemp)
this.setData({ goods: newgoods })
}else{
totalQuantityTemp = totalQuantityTemp + 1
totalPriceTemp = totalPriceTemp + goodinfo.price
let nowgoods = []
nowgoods.push(goodinfo);
var newgoods = nowgoods.concat(lastgoods)
this.setData({ goods: newgoods })
}
},
//汇总
this.setData({ totalQuantity: totalQuantityTemp,
totalPrice: totalPriceTemp,
})
//管理员需要额外传一个storeid
}
});
\ No newline at end of file
//login
var API_LOGIN = "store/cashier/login";
const app = getApp()
//返回的数据都为code、data的形式
function login({ baseUrl, appId, name, password, sn, callback }) {
var loginRequest = createCommonRequest(appId,null,sn);
function login({ baseUrl, name, password, callback }) {
var loginRequest = createCommonRequest();
loginRequest.username = name;
loginRequest.password = password;
loginRequest.loginType = "1";
console.log("login request==>" + JSON.stringify(loginRequest));
var loginResponse = { code: {}, data: {} };
my.request({
......@@ -47,13 +45,15 @@ function login({ baseUrl, appId, name, password, sn, callback }) {
}
function createCommonRequest(appId, token, deviceNo) {
function createCommonRequest() {
var commonRequest = {
};
commonRequest.appId = appId;
commonRequest.token = token;
commonRequest.deviceNo = deviceNo;
commonRequest.appId = app.globalData.appId;
//token 设置到公共请求体
if(app.globalData.localAccountInfo != null){
commonRequest.token = app.globalData.localAccountInfo.token;
}
commonRequest.deviceNo = app.globalData.sn;
commonRequest.batchNo = "";
commonRequest.timestamp = timestampToTime();
commonRequest.format = "JSON";
......@@ -92,4 +92,6 @@ function decodeErrorMessage(error) {
return "请求失败";
}
module.exports.login = login;
\ No newline at end of file
module.exports.login = login;
module.exports.createCommonRequest = createCommonRequest;
module.exports.decodeErrorMessage = decodeErrorMessage;
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment