Commit f6cf82d5 authored by tangkun's avatar tangkun
Browse files

小程序初始化

parents

Too many changes to show.

To preserve performance only 1000 of 1000+ files are displayed.
/*
* Eslint config file
* Documentation: https://eslint.org/docs/user-guide/configuring/
* Install the Eslint extension before using this feature.
*/
module.exports = {
}
# 云开发 quickstart
这是云开发的快速启动指引,其中演示了如何上手使用云开发的三大基础能力:
- 数据库:一个既可在小程序前端操作,也能在云函数中读写的 JSON 文档型数据库
- 文件存储:在小程序前端直接上传/下载云端文件,在云开发控制台可视化管理
- 云函数:在云端运行的代码,微信私有协议天然鉴权,开发者只需编写业务逻辑代码
## 参考文档
- [云开发文档](https://developers.weixin.qq.com/miniprogram/dev/wxcloud/basis/getting-started.html)
{
"permissions": {
"openapi": [
]
}
}
\ No newline at end of file
// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init({
// API 调用都保持和云函数当前所在环境一致
env: cloud.DYNAMIC_CURRENT_ENV
})
// 云函数入口函数
exports.main = async (event, context) => {
// 根据用户提交的cloudid 获取对应的运动数据
let weRunData = event.weRunData
console.log(weRunData)
return weRunData.data.stepInfoList
}
\ No newline at end of file
{
"name": "getMovementSteps",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"wx-server-sdk": "~2.5.3"
}
}
\ No newline at end of file
{
"permissions": {
"openapi": [
"wxacode.get"
]
}
}
\ No newline at end of file
const cloud = require('wx-server-sdk');
cloud.init({
env: cloud.DYNAMIC_CURRENT_ENV
});
const db = cloud.database();
// 创建集合云函数入口函数
exports.main = async (event, context) => {
try {
// 创建集合
await db.createCollection('sales');
await db.collection('sales').add({
// data 字段表示需新增的 JSON 数据
data: {
region: '华东',
city: '上海',
sales: 11
}
});
await db.collection('sales').add({
// data 字段表示需新增的 JSON 数据
data: {
region: '华东',
city: '南京',
sales: 11
}
});
await db.collection('sales').add({
// data 字段表示需新增的 JSON 数据
data: {
region: '华南',
city: '广州',
sales: 22
}
});
await db.collection('sales').add({
// data 字段表示需新增的 JSON 数据
data: {
region: '华南',
city: '深圳',
sales: 22
}
});
return {
success: true
};
} catch (e) {
// 这里catch到的是该collection已经存在,从业务逻辑上来说是运行成功的,所以catch返回success给前端,避免工具在前端抛出异常
return {
success: true,
data: 'create collection success'
};
}
};
const cloud = require('wx-server-sdk');
cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV });
exports.main = async (event, context) => {
return {
dataList: [
{ _id: '1', title: '微信气泡徽章', price: 1800 },
{ _id: '2', title: '微信地球鼠标垫', price: 5800 },
{ _id: '3', title: '微信黄脸大贴纸', price: 500 }
],
}
};
\ No newline at end of file
const cloud = require('wx-server-sdk');
cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV });
exports.main = async (event, context) => {
const pagePath = event.pagePath;
// 获取小程序二维码的buffer
const resp = await cloud.openapi.wxacode.get({
path: pagePath,
});
const { buffer } = resp;
// 将图片上传云存储空间
const upload = await cloud.uploadFile({
cloudPath: String(pagePath).replaceAll('/', '_') + '.png',
fileContent: buffer
});
return upload.fileID;
};
\ No newline at end of file
const cloud = require('wx-server-sdk');
cloud.init({
env: cloud.DYNAMIC_CURRENT_ENV
});
// 获取小程序二维码云函数入口函数
exports.main = async (event, context) => {
// 获取小程序二维码的buffer
const resp = await cloud.openapi.wxacode.get({
path: 'pages/index/index'
});
const { buffer } = resp;
// 将图片上传云存储空间
const upload = await cloud.uploadFile({
cloudPath: 'code.png',
fileContent: buffer
});
return upload.fileID;
};
const cloud = require('wx-server-sdk');
cloud.init({
env: cloud.DYNAMIC_CURRENT_ENV
});
// 获取openId云函数入口函数
exports.main = async (event, context) => {
// 获取基础信息
const wxContext = cloud.getWXContext();
return {
openid: wxContext.OPENID,
appid: wxContext.APPID,
unionid: wxContext.UNIONID,
};
};
const getOpenId = require('./getOpenId/index');
const getMiniProgramCode = require('./getMiniProgramCode/index');
const createCollection = require('./createCollection/index');
const selectRecord = require('./selectRecord/index');
const updateRecord = require('./updateRecord/index');
const sumRecord = require('./sumRecord/index');
const fetchGoodsList = require('./fetchGoodsList/index');
const genMpQrcode = require('./genMpQrcode/index');
// 云函数入口函数
exports.main = async (event, context) => {
switch (event.type) {
case 'getOpenId':
return await getOpenId.main(event, context);
case 'getMiniProgramCode':
return await getMiniProgramCode.main(event, context);
case 'createCollection':
return await createCollection.main(event, context);
case 'selectRecord':
return await selectRecord.main(event, context);
case 'updateRecord':
return await updateRecord.main(event, context);
case 'sumRecord':
return await sumRecord.main(event, context);
case 'fetchGoodsList':
return await fetchGoodsList.main(event, context);
case 'genMpQrcode':
return await genMpQrcode.main(event, context);
}
};
{
"name": "quickstartFunctions",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"wx-server-sdk": "~2.4.0"
}
}
const cloud = require('wx-server-sdk');
cloud.init({
env: cloud.DYNAMIC_CURRENT_ENV
});
const db = cloud.database();
// 查询数据库集合云函数入口函数
exports.main = async (event, context) => {
// 返回数据库查询结果
return await db.collection('sales').get();
};
const cloud = require('wx-server-sdk');
cloud.init({
env: cloud.DYNAMIC_CURRENT_ENV
});
const db = cloud.database();
const $ = db.command.aggregate;
// 聚合记录云函数入口函数
exports.main = async (event, context) => {
// 返回数据库聚合结果
return db.collection('sales').aggregate()
.group({
_id: '$region',
sum: $.sum('$sales')
})
.end();
};
const cloud = require('wx-server-sdk');
cloud.init({
env: cloud.DYNAMIC_CURRENT_ENV
});
const db = cloud.database();
// 修改数据库信息云函数入口函数
exports.main = async (event, context) => {
try {
// 遍历修改数据库信息
for (let i = 0; i < event.data.length; i++) {
await db.collection('sales').where({
_id: event.data[i]._id
})
.update({
data: {
sales: event.data[i].sales
},
});
}
return {
success: true,
data: event.data
};
} catch (e) {
return {
success: false,
errMsg: e
};
}
};
//app.js
App({
globalData: {
supplierId: null,
socketUrl: null, // socketUrl
timeout: 10000, // 延迟
socketHeartTimer: null,
callback: (e) => {}, // socket连接回调函数
socketClientTimer: null, // socket连接定时器
isSocketConnect: false, // 当前socket是否连接
},
onShow() {
// 开启socket
//this.connectSocketFunciton();
},
overShare () {
//监听路由切换
wx.onAppRoute((res) => {
let pages = getCurrentPages(),
view = pages[pages.length - 1]
if (view) {
wx.showShareMenu({
withShareTicket: true,
menus: ['shareAppMessage', 'shareTimeline']
})
}
})
},
// 小程序进入后台
onHide() {
// 关闭全局socket状态连接定时器
clearInterval(this.globalData.socketClientTimer)
// 关闭socket
this.closeSocketFunction()
},
// 检查用户登录状态,并决定是否开启socket
checkLoginUserSocket() {
this.globalData.supplierId = wx.getStorageSync('supplierId') || null;
if (this.globalData.supplierId) {
//登录状态下调用连接socket 且判断是否已经连接socket
if (!this.globalData.isSocketConnect) {
// console.log("-----用户一登录---连接socket")
this.connectSocketFunciton()
}
} else {
// console.log("-----用户未登录--关闭socket")
//未登录状态下清除定时器关闭socket
this.closeSocketFunction()
}
},
//小程序连接socket
connectSocketFunciton() {
var that = this
var socketUrl = `wss://talent.199.nuomayun.com:2348`
wx.connectSocket({
url: socketUrl,
success: (res => {
// 标识socket已连接
that.globalData.isSocketConnect = true
// 初始化连接监听
that.initEventHandler()
}),
fail: (fail => {})
})
},
// 绑定监听
initEventHandler() {
var that = this
// socket连接开启
wx.onSocketOpen((result) => {
// 开启心跳
that.startHeart()
})
// socket连接关闭
wx.onSocketClose((res) => {
if (that.globalData.isSocketConnect) {
that.connectSocketFunciton()
}
})
// 接收socket消息
wx.onSocketMessage((res) => {
console.log("onSocketMessage", res)
//第一次消息如果为init就绑定uid
// var data = JSON.parse(res.data)
//这里data可以根据后端返回的数据做一些处理 根据自己的需求做出对应的处理
// 全局socket接收消息的方法回调
that.globalData.callback(res)
})
},
//发送心跳
startHeart() {
if (this.globalData.isSocketConnect) {
this.globalData.socketHeartTimer = setInterval(() => {
wx.sendSocketMessage({
data: 'heartBath',
success: function (res) {},
fail: function (res) {}
})
}, 45 * 1000)
} else {
clearTimeout(this.globalData.socketHeartTimer)
}
},
//此页面关闭socket和定时器的函数
closeSocketFunction: function () {
if (this.globalData.isSocketConnect) {
// 标识socket已断开
this.globalData.isSocketConnect = false
// 关闭socket连接
wx.closeSocket()
// 关闭socket心跳定时器
clearInterval(this.globalData.socketHeartTimer)
}
},
onLaunch: function () {
//贝塞尔曲线 - 预定那里使用
this.screenSize();
this.overShare()
// 展示本地存储能力
var logs = wx.getStorageSync('logs') || []
logs.unshift(Date.now())
wx.cloud.init({
// env 参数说明:
// env 参数决定接下来小程序发起的云开发调用(wx.cloud.xxx)会默认请求到哪个云环境的资源
// 此处请填入环境 ID, 环境 ID 可打开云控制台查看
// 如不填则使用默认环境(第一个创建的环境)
env: 'cloud1-3g779bd274c79d6b',
traceUser: true,
})
//wx.setStorageSync('logs', logs)
// 登录
// wx.login({
// success: res => {
// // 发送 res.code 到后台换取 openId, sessionKey, unionId
// }
// })
// 获取用户信息
wx.getSetting({
success: res => {
if (res.authSetting['scope.userInfo']) {
// 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
wx.getUserInfo({
success: res => {
// 可以将 res 发送给后台解码出 unionId
this.globalData.userInfo = res.userInfo
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// 所以此处加入 callback 以防止这种情况
if (this.userInfoReadyCallback) {
this.userInfoReadyCallback(res)
}
}
})
}
}
})
// const updateManager = wx.getUpdateManager();
// updateManager.onCheckForUpdate(function (res) {
// // 请求完新版本信息的回调
// console.log(res.hasUpdate)
// })
// updateManager.onUpdateReady(function () {
// wx.showModal({
// title: '更新提示',
// content: '新版本已经准备好,是否重启应用?',
// success: function (res) {
// if (res.confirm) {
// // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
// updateManager.applyUpdate()
// }
// }
// })
// })
// updateManager.onUpdateFailed(function () {
// // 新版本下载失败
// })
},
// 贝塞尔曲线开始
screenSize: function () {
var that = this;
wx.getSystemInfo({
success: function (res) {
var ww = res.windowWidth;
var hh = res.windowHeight;
that.globalData.ww = ww;
that.globalData.hh = hh;
}
})
},
bezier: function (points, part) {
let sx = points[0]['x'];
let sy = points[0]['y'];
let cx = points[1]['x'];
let cy = points[1]['y'];
let ex = points[2]['x'];
let ey = points[2]['y'];
var bezier_points = [];
// 起始点到控制点的x和y每次的增量
var changeX1 = (cx - sx) / part;
var changeY1 = (cy - sy) / part;
// 控制点到结束点的x和y每次的增量
var changeX2 = (ex - cx) / part;
var changeY2 = (ey - cy) / part;
//循环计算
for (var i = 0; i <= part; i++) {
// 计算两个动点的坐标
var qx1 = sx + changeX1 * i;
var qy1 = sy + changeY1 * i;
var qx2 = cx + changeX2 * i;
var qy2 = cy + changeY2 * i;
// 计算得到此时的一个贝塞尔曲线上的点
var lastX = qx1 + (qx2 - qx1) * i / part;
var lastY = qy1 + (qy2 - qy1) * i / part;
// 保存点坐标
var point = {};
point['x'] = lastX;
point['y'] = lastY;
bezier_points.push(point);
}
return {
'bezier_points': bezier_points
};
},
// 贝塞尔曲线结束
globalData: {
userInfo: null
}
})
\ No newline at end of file
{
"pages": [
"pages/home/index",
"pages/classification/index",
"pages/classification/commodity/index",
"pages/my/index/index",
"pages/shoppingCart/index/index",
"pages/park/index/index",
"pages/shoppingMALL/createOrder/index",
"pages/shoppingMALL/details/index",
"pages/shoppingMALL/index/index",
"pages/order/index/index",
"pages/order/details/index",
"pages/my/personalData/index/index",
"pages/my/personalData/bindingMobile/index",
"pages/news/index/index",
"pages/news/list/index",
"pages/news/search/index",
"pages/news/service/index",
"pages/news/web/index",
"pages/my/address/add/index",
"pages/my/address/edit/index",
"pages/my/address/index/index",
"pages/my/address/search/index",
"pages/my/contactUs/index/index",
"pages/my/card/index/index",
"pages/my/about/index",
"pages/reserve/index/index",
"pages/reserve/createOrder/index",
"pages/zone/commodity/index",
"pages/zone/index/index",
"pages/couponCenter/index/index",
"pages/Cashier/index/index",
"pages/Cashier/result/index",
"pages/search/index/index",
"pages/article/index/index",
"pages/authorize/index/index",
"pages/authorize/detail/index"
],
"preloadRule": {},
"window": {
"backgroundTextStyle": "light",
"backgroundColor": "#F7F7FA",
"navigationBarBackgroundColor": "#F7F7FA",
"navigationBarTitleText": "挪码商城平台",
"navigationBarTextStyle": "black"
},
"usingComponents": {
"positioning-park": "/components/positioningPark",
"customer-service": "/components/customerService",
"shopping-cart": "/components/shoppingCart",
"load-ing": "/components/loading",
"load-default": "/components/defaultLoading",
"notice": "/components/notice",
"progre-ss": "/components/progress",
"is-sign-in": "/components/isSignIn",
"add-shopping-cart": "/components/addShoppingCart"
},
"requiredPrivateInfos": [
"getLocation"
],
"sitemapLocation": "sitemap.json",
"permission": {
"scope.userLocation": {
"desc": "你的位置信息将用于获取园区距离"
},
"scope.writePhotosAlbum": {
"desc": "上传文件的权限说明"
}
}
}
\ No newline at end of file
/**app.wxss**/
page {
height: 100%;
width: 100%;
font-size: 32rpx;
}
/* 超出两行小数点省略 */
.oneLines{display: -webkit-box;overflow: hidden;text-overflow: ellipsis;word-wrap: break-word;white-space: normal !important;-webkit-line-clamp: 1;-webkit-box-orient: vertical;word-break: break-all;}
.twoLines{display: -webkit-box;overflow: hidden;text-overflow: ellipsis;word-wrap: break-word;white-space: normal !important;-webkit-line-clamp: 2;-webkit-box-orient: vertical;word-break: break-all;}
.threeLines{display: -webkit-box;overflow: hidden;text-overflow: ellipsis;word-wrap: break-word;white-space: normal !important;-webkit-line-clamp: 3;-webkit-box-orient: vertical;word-break: break-all;}
/*checkbox 选项框大小 */
checkbox .wx-checkbox-input {
width: 40rpx;
height: 40rpx;
border-radius: 50%;
}
/*checkbox选中后样式 */
checkbox .wx-checkbox-input.wx-checkbox-input-checked {
background: #FA7268;
border: 1px solid #FA7268;
}
/*checkbox选中后图标样式 */
checkbox .wx-checkbox-input.wx-checkbox-input-checked::before {
width: 28rpx;
height: 28rpx;
line-height: 28rpx;
text-align: center;
font-size: 22rpx;
color: #ffffff;
background: transparent;
transform: translate(-50%, -50%) scale(1);
-webkit-transform: translate(-50%, -50%) scale(1);
}
/*radio未选中时样式 */
radio .wx-radio-input{
/* 自定义样式.... */
height: 32rpx;
width: 32rpx;
border-radius: 50%;
border: 2rpx solid #999;
background: transparent;
}
/* 选中后的 背景样式 (红色背景 无边框 可根据UI需求自己修改) */
radio .wx-radio-input.wx-radio-input-checked {
border-color: #FA7268!important;
}
/* 选中后的 对勾样式 (白色对勾 可根据UI需求自己修改) */
radio .wx-radio-input.wx-radio-input-checked::before {
/* 去除对号 */
content: '';
width: 32rpx;
height: 32rpx;
border-radius: 50%;
background-color: #FA7268;
}
.paymentType radio .wx-radio-input.wx-radio-input-checked{border-color: #FFA53C!important;}
.paymentType radio .wx-radio-input.wx-radio-input-checked::before {
background-color: #FFA53C;
}
/* 没有数据 */
.noData{position: fixed;top: 0;left: 0;z-index: 1;width: 100%;height: 100%;display: flex;flex-direction: column;align-items: center;justify-content: center;}
.noData image{width: 410rpx;height: 416rpx;}
.noData .text{font-size: 28rpx;color: #999999;}
/* 空页面 */
.emptyPage{width: 100%;height: 100%;display: flex;flex-direction: column;align-items: center;background: #ffffff;overflow: hidden;}
.emptyPage .img{width: 80rpx;height: 80rpx;margin: 300rpx 0 30rpx;}
.emptyPage .tips{color: #A0A0A0;}
.bottomLogo{position: fixed;width: 100%;text-align: center;left: 0;bottom: 0;z-index: 1;padding: 28rpx 0;}
.bottomLogo image{width: 20rpx;height: 14rpx;}
/* 页脚 */
.navigation{position: fixed;left: 0;bottom: 0;z-index: 10;width: 100%;height: 100rpx;background: #fff;font-size: 20rpx;display: flex;justify-content: space-around;align-items: center;padding-bottom: calc(constant(safe-area-inset-bottom) - 30rpx);padding-bottom: calc(env(safe-area-inset-bottom) - 30rpx);}
.navigation .li{display: flex;flex-direction: column;align-items: center;justify-content: center;color: #A0A1A3;width: 20%;}
.navigation .li .liNews{width: 52rpx;height: 52rpx;position: relative;}
.navigation .li .liNews .liNum{position: absolute;top: 0;right: -10rpx;z-index: 1;width: 28rpx;height: 28rpx;background: #FA431D;border-radius: 50%;color: #ffffff;font-size: 20rpx;display: flex;align-items: center;justify-content: center;}
.navigation .li .active{color: #666666;}
.navigation .li image{width: 52rpx;height: 52rpx;}
.navigation .code{width: 178rpx;height: 74rpx;display: flex;align-items: center;justify-content: center;border-radius: 38rpx; background: -webkit-linear-gradient(top,#FA7268,#3361D6);color: #ffffff;}
.navigation .code image{width: 34rpx;height: 34rpx;margin-right: 10rpx;}
.navigation .li .num{background: #fac88f;width: 28rpx;height: 28rpx;font-size: 20rpx;color: #ffffff; position: absolute;top: -14rpx;right: -14rpx;z-index: 1;border: 2rpx solid #FFFFFF;border-radius: 50%;display: flex;align-items: center;justify-content: center;}
.no{text-align: center;color: #999999;margin-bottom: 40rpx;font-size: 28rpx;}
.listTips{font-size: 20rpx;color: #BFBFBF;padding: 20rpx 0;text-align: center;}
.publicsearch{width: 28rpx;height: 28rpx;}
/* 底部弹窗遮罩层(动画) */
.cover_screen{ width: 100%;height: 100%;position: fixed;top: 0;left: 0;background: #000;opacity: 0.3;overflow: hidden;z-index: 10000;color: #fff;}
/* 底部弹窗(动画) */
.customPop{width: 100%;box-sizing: border-box;position: fixed;bottom: 0;left: 0;z-index: 10001;
background: #fff;overflow: hidden;font-size: 28rpx;border-radius: 20rpx 20rpx 0 0;}
.customPop .top{display: flex;align-items: center;justify-content: space-between;padding: 30rpx 20rpx;}
.customPop .top .two{color: #87c5fc;}
::-webkit-scrollbar {
display: none;
width: 0;
height: 0;
color: transparent;
}
/* 进度条 */
.reekoProgress{position: relative;margin-top: 16rpx;}
.publicProgress{border-radius: 28rpx !important;border: 1px solid rgb(255, 211, 208);background: rgb(255, 239, 239) !important;background: #ffffff !important;
overflow: hidden;}
.publicProgress .van-progress__pivot{display: none;}
.reekoProgress .stockPercentage{position: absolute;top: 0;z-index: 1;left: 0;font-size: 20rpx;color: #E30114;height: 32rpx;padding-left: 20rpx;display: flex;align-items: center;}
/* 标签布局 */
.labelLayout{float: left;display: flex;align-items: center;padding-top: 6rpx;}
.df{display: flex;}
.flex-a{display: flex;justify-content: space-around;align-items: center;}
.flex-b{display: flex;justify-content: space-between;align-items: center;}
.flex-c{display: flex;justify-content: center;align-items: center;}
.flex-e{display: flex;justify-content: flex-end;align-items: center;}
.flex-s{display: flex;justify-content: flex-start;align-items: center;}
\ No newline at end of file
// components/addShoppingCart/index.js
var call = require("../../utils/request.js");
Component({
/**
* 组件的属性列表
*/
properties: {
},
/**
* 组件的初始数据
*/
data: {
operationShow: false,
reekoData: {}, // 数据
quantity: 1, // 购买数量
specificationsIndex: 0, // 规格索引
skuId: '', // 商品规格id
buyMethod: [], // 当前商品的支付方式
buySeparately: false, // 当前规格 商品是否是特殊商品
},
/**
* 组件的方法列表
*/
methods: {
// 触发加入购物车
async inits(item){
let parkId = wx.getStorageSync('currentPark').id
let { goodsUUID,storeId } = item
wx.showLoading({
mask: true,
title: '添加中',
})
let transmit = {
storeId,
buyNums: 1,
goodsUUID
}
await wx.cloud.callContainer({
config: {
env: "prod-5g1ij4bldaaeb7dd"
},
path: `/v1/store/cart/${parkId}`,
header: {
"X-WX-SERVICE": "springboot-pc42"
},
method: "POST",
data: transmit
}).then(res =>{
console.log(res,'添加购物车')
if( res.data.code == 1 ){
wx.showToast({ title: '添加成功',icon: 'success',duration: 1000 })
this.triggerEvent('shoppingCart') // 促发父组件 看看购物车里的数据
}else{
wx.showToast({ icon: 'none',title: res.data.errorMsg,duration: 3000 });
}
})
},
// 获取详情
getGoodsinfo (id) {
console.log(id,'当前商品id')
call.httpData('GET','/api/index/goodsinfo', { id,type: 1 },
res => {
console.log(res,'获取详情')
if(res.code == 1){
let { skuList,extServiceList,buySeparately } = res.data
let specificationsName = '' // 规格显示的文本
let skuId = '' // 规格id
let additionalList = [] // 附加服务
let extIds = [] // 附加服务id
let buyMethod = [] // 当前商品的支付方式
if(0 in skuList){
specificationsName = skuList[0].name // 默认选中的规格
skuId = skuList[0].id // 默认选中的规格id
buyMethod = skuList[0].buyMethod
}
if(0 in extServiceList){
for(let item of extServiceList){
if(item.checksta){
additionalList.push(item)
extIds.push(item.id)
}
}
}
let reekoData = res.data
this.setData({ reekoData,specificationsName,skuId,additionalList,extIds,buyMethod,buySeparately })
this.calculation() // 计算价格
}else{
wx.showToast({ icon: 'none',title: res.msg });
}
this.setData({ pageStatus: true })
},function (err) {
console.log(err)
})
},
// 关闭操作
onOperationClose() {
this.setData({ operationShow: false });
},
// 购买数量改变
onNumChange(event) {
console.log(event.detail);
this.setData({ quantity: event.detail })
this.calculation() // 计算价格
},
// 切换规格
onGuigeChange(e){
console.log(e.currentTarget.dataset.index)
let quantity = this.data.quantity // 当前的数量
let specificationsIndex = e.currentTarget.dataset.index
let { id,name,buyMethod,buySeparately,limitQuantity } = this.data.reekoData.skuList[specificationsIndex]
if(limitQuantity != 0 && limitQuantity != -1){ // 通过限购改变数量
quantity = limitQuantity // 数量
}
this.setData({ specificationsIndex,specificationsName: name,skuId: id,buyMethod,buySeparately,quantity })
this.calculation() // 计算价格
},
// 切换附加服务
onFujiaChange(e){
let { index,obj } = e.currentTarget.dataset
console.log(index,obj)
if(obj.required == 0){ // 不是必选
let reekoData = this.data.reekoData
reekoData.extServiceList[index].checksta = !reekoData.extServiceList[index].checksta
let additionalList = []
let extIds = []
for(let list of reekoData.extServiceList){
if(list.checksta){
additionalList.push(list)
extIds.push(list.id)
}
}
this.setData({ reekoData,additionalList,extIds })
this.calculation() // 计算价格
}
},
// 加入购物车
addCar () {
let { storeId,id } = this.data.reekoData // storeId 门店id id 商品id
let skuId = this.data.skuId // 商品规格id
let quantity = this.data.quantity // 商品数量
let extIds = this.data.extIds // 附加服务id
call.httpData('POST','/api/shopping_cart/addcart', { storeId,goodsId: id,skuId,quantity,extIds},
res => {
console.log(res,'加入购物车成功')
if(res.code == 1){
wx.showToast({ icon: 'success',title: res.msg })
this.setData({ operationShow: false })
this.triggerEvent('seeShoppingCart') // 促发父组件 看看购物车里的数量
}else{
wx.showToast({ icon: 'none',title: res.msg });
}
},function (err) {
console.log(err)
})
},
// 立即购买
immediately(freight) {
let { id,storeId,storeTitle,pic,title,totalPrice,subtotal,additionalServices,freeShipping,storePrice,deliveryMethod } = this.data.reekoData
let additionalList = this.data.additionalList
let services_name = ''
if(0 in additionalList){services_name = `,${additionalList[0].services_name}`}
let tips = `${this.data.specificationsName}${services_name}`
// let subtotal = totalPrice + additionalServices
subtotal = subtotal + freight
console.log(`总价:${subtotal}、满${freeShipping}免运费、运费${freight}`)
console.log(this.data.buyMethod)
storePrice = Number(storePrice) * Number(this.data.quantity)
let shoppingData = [{
freight, // 运费
benchmarkingFreight: freight, // 保留运费
fpayType: '1', // 运费默认支付方式
storeTitle,
totalPrice,
storeId,
goodsId: id,
goodsSkuId: this.data.skuId, // 商品规格id
extIds: this.data.extIds, // 附加服务id
quantity: this.data.quantity,
subtotal,
additionalServices, // 附加服务费
buySeparately: this.data.buySeparately, // 是否是特殊商品
goodsList:[{
pic,
title,
totalPrice,
tips,
storeTitle,
storePrice, // 蜀道币价格
quantity: this.data.quantity,
buyMethod: this.data.buyMethod, // 支付方式
buyMethodText: this.data.buyMethod[0].name,
buyMethodId: this.data.buyMethod[0].id,
}],
deliveryMethod, // 配送方式
}]
console.log(shoppingData,'看一下')
wx.navigateTo({
url: '/subPackages/pages/standard/home/recommend/shoppingDetails/confirm/index/index?shoppingData=' + JSON.stringify(shoppingData)
})
},
// 计算价格
calculation(){
let reekoData = this.data.reekoData // 购买数据
let skuIndex = this.data.specificationsIndex // 规格索引
let quantity = Number(this.data.quantity) // 数量
let skuPrice = reekoData.skuList[skuIndex].salesprice // 规格价格
let scribingPrice = reekoData.skuList[skuIndex].scribing_price // 规格下划价格
let storePrice = reekoData.skuList[skuIndex].storePrice // 蜀道币价格
let stock = reekoData.skuList[skuIndex].stock // 库存
let skuSalesVolume = reekoData.skuList[skuIndex].skuSalesVolume // 销量
let detailPicList = reekoData.skuList[skuIndex].detailPicList // 商品图片
let limitQuantity = reekoData.skuList[skuIndex].limitQuantity // // 限购
console.log('规格价格'+skuPrice)
let extServicePrice = 0 // 附加服务价格
for(let list of reekoData.extServiceList){
if(list.checksta){
extServicePrice += Number(list.services_price * quantity)
}
}
console.log(extServicePrice,'附加服务价格')
if(0 in reekoData.skuList){
let totalPrice = Number(skuPrice) *Number(quantity)
reekoData.totalPrice = Math.round(totalPrice * 100) / 100;
}else{
reekoData.totalPrice = 0
}
reekoData.additionalServices = extServicePrice
reekoData.subtotal = reekoData.totalPrice + extServicePrice
reekoData.price = skuPrice
reekoData.scribingPrice = scribingPrice
reekoData.stock = stock
reekoData.storePrice = storePrice
reekoData.salesVolume = skuSalesVolume // 销量
reekoData.detailPicList = detailPicList // 商品图片
reekoData.limitQuantity = limitQuantity // 限购
this.setData({ reekoData,operationShow: true })
},
}
})
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