Authored by 肖亚东

报名逻辑开发以及其他问题修改

... ... @@ -14,7 +14,7 @@ Component({
},
onApplyAction(e) {
if (this.properties.data.applyed) {
if (this.properties.data.registered === 'Y') {//已报名
return;
}
... ...
... ... @@ -4,5 +4,5 @@
<view class="activity-name">{{data.title}}</view>
<view class="activity-location">展位号:{{data.place}}</view>
</view>
<view wx:if="{{data.need_register === 'Y'}}" class="activity-apply {{data.registered === 'Y' ? 'inactive': ''}}" bindtap="onApplyAction" data-activity-id="123">{{data.registered? '已报名' : '报名'}}</view>
<view wx:if="{{data.need_register === 'Y'}}" class="activity-apply {{data.registered === 'Y' ? 'inactive': ''}}" catchtap="onApplyAction" data-activity-id="{{data.id}}">{{data.registered === 'Y'? '已报名' : '报名'}}</view>
</view>
\ No newline at end of file
... ...
import {API_HOST, YOHOOD_HOST, SERVICE_HOST} from '../../libs/config';
import {GET, POST} from '../../libs/request';
import { loginAndRegisterTapped } from '../../utils/login';
import { getUnionID } from '../../utils/login';
import { applyActivity } from '../../utils/activity';
var app = getApp()
... ... @@ -8,7 +9,8 @@ Page({
data: {
days: [],//日期列表
list: {},//活动列表,days的数据为key
curactivityList: [], //当前选中的日期
select: 0,//当前选中的tab
curactivityList: [], //当前选中的日期数据列表
},
onLoad: function(options) {
//Do some initialize when page load.
... ... @@ -36,16 +38,17 @@ Page({
console.log('====================================');
let days = data.days;
let list = data.list;
let select = 0;
let curactivityList = []
if (days.length > 0) {
let selectDay = days[0];
curactivityList = list[selectDay]
}
that.setData({
days,
list,
select,
curactivityList
})
}
... ... @@ -72,14 +75,72 @@ Page({
});
},
applyAction(e) {
// let activityId = e.detail.activityId;
// let array = this.data.array;
let activityId = e.detail.activityId;
// if (app.globalData.userInfo.uid) {//已登录
let that = this;
if (app.globalData.userInfo.uid) {//已登录
applyActivity(id, function (result) {
if (result.succeed) {
// that.setData({
// } else {
// loginAndRegisterTapped();
// }
// })
}
wx.showToast({
title: result.message,
icon: 'none',
duration: 3000
})
}
);
} else {
this.loginAndRegisterTapped();
}
},
//跳转到登录页面
loginAndRegisterTapped:function(needBind) {
let app = getApp()
if(wx.getSetting){
wx.getSetting({
success: (res) => {
if (res && res.authSetting && res.authSetting["scope.userInfo"] !== null && res.authSetting["scope.userInfo"] !== undefined && res.authSetting["scope.userInfo"] === false) {
wx.showModal({
title: '',
content: '检测到您未打开微信用户信息授权,开启后即可进行登录',
confirmText: "去开启",
confirmColor: "#000000",
success: function (res) {
if (res.confirm) {
wx.openSetting({
success: (res) => {
// console.log(res.authSetting["scope.userInfo"])
if (res.authSetting["scope.userInfo"] !== null && res.authSetting["scope.userInfo"] !== undefined && res.authSetting["scope.userInfo"] === true) {
getUnionID(app.getWechatThirdSession(), function (response) {
// console.log(response)
})
}
}
})
} else {
wx.navigateTo({
url: '/pages/bindPhoneNumber/bindPhoneNumber',
})
}
}
})
} else {
wx.navigateTo({
url: '/pages/bindPhoneNumber/bindPhoneNumber',
})
}
}
})
} else {
wx.showModal({
title: '提示',
content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
})
}
},
onHide: function() {
... ...
... ... @@ -2,13 +2,11 @@
import { ACTIVITY_HOST, YOHOOD_HOST, API_HOST, SERVICE_HOST } from '../../libs/config';
import { GET, POST } from '../../libs/request';
import guangUtil from './util';
import Promise from '../../vendors/es6-promise';
import util from '../../utils/util';
import WxParse from '../../vendors/wxParse/wxParse';
import { getQRCodeSource } from '../../libs/miniQRCodeRoute.js'
import { jumpByUrl } from '../../libs/urlRoute';
import { getUnionID } from '../../utils/login';
import { applyActivity } from '../../utils/activity';
//获取应用实例
let app = getApp();
... ... @@ -26,6 +24,7 @@ Page({
isShowIndicator: false,
isActivtyDetail: false,
needApply: false, //是否能报名
replyTemArray: [],
articleInfo: {},
articleContent: {},
... ... @@ -88,8 +87,6 @@ Page({
WxParse.wxParse('replyTemArray', 'html', article, that, 0);
let replyTemArray = this.data.replyTemArray;
console.log(replyTemArray);
// debugger;
that.setData({
articleInfo: data,
replyTemArray,
... ... @@ -109,18 +106,14 @@ Page({
if (json && json.code == 200) {
let data = json.data;
console.log('====================================');
console.log(data);
console.log('====================================');
wx.setNavigationBarTitle({title: data.title || '文章详情'});
wx.setNavigationBarTitle({title: data.title || '活动详情'});
var article = data.content;
WxParse.wxParse('replyTemArray', 'html', article, that, 0);
let replyTemArray = this.data.replyTemArray;
console.log(replyTemArray);
// debugger;
// debugger
that.setData({
articleInfo: data,
replyTemArray,
... ... @@ -132,45 +125,32 @@ Page({
})
},
setGoodsMore: function(event) {
let data = event.currentTarget.dataset;
let findex = data.findex || 0;
let flen = data.flen || 0;
let articleContent = this.data.articleContent;
articleContent.finalDetail[findex].relatedReco.moreNum = flen;
this.setData({articleContent: articleContent});
},
onPageScroll: function(event) {
var { scrollTop } = event;
var isShow = scrollTop > windowHeight * 2 ? true : false;
if (isShow != this.data.isShowIndicator) {
this.setData({
isShowIndicator: isShow
});
}
},
backToTop: function () {
wx.pageScrollTo({
scrollTop: 0,
});
},
productCellTapped: function(event) {
let data = event.currentTarget.dataset;
let skn = data.skn;
if (!skn) {
return;
}
wx.navigateTo({
url: `/pages/goodsDetail/goodsDetail?productSkn=${skn}&${this.data.yasParam}`
});
},
//活动报名
applyAction: function(event) {
if (this.data.articleInfo.registered === 'Y') {//已报名
return;
}
let that = this;
let id = event.currentTarget.dataset.id;
if (app.globalData.userInfo.uid) {//已登录
applyActivity(id, function (result) {
if (result.succeed) {
let articleInfo = that.data.articleInfo;
articleInfo.registered = 'Y';
that.setData({
articleInfo
})
}
wx.showToast({
title: result.message,
icon: 'none',
duration: 3000
})
}
);
} else {
this.loginAndRegisterTapped();
}
},
//跳转到登录页面
... ... @@ -219,6 +199,21 @@ Page({
}
},
onPageScroll: function(event) {
var { scrollTop } = event;
var isShow = scrollTop > windowHeight * 2 ? true : false;
if (isShow != this.data.isShowIndicator) {
this.setData({
isShowIndicator: isShow
});
}
},
backToTop: function () {
wx.pageScrollTo({
scrollTop: 0,
});
},
onShareAppMessage: function (res) {
let param = {
FROM: res.from,
... ...
<import src="../../vendors/wxParse/wxParse.wxml"/>
<view class="newsDetail-detail-page">
<!-- <view class="newsDetail-container" style="padding-bottom:{{isActivtyDetail ? '136rpx;' : '0'}}"> -->
<view class="newsDetail-container">
<view class="newsDetail-container" style="padding-bottom:{{(isActivtyDetail && articleInfo.need_register==='Y') ? '136rpx;' : '0'}}">
<!-- 标题头部 -->
<view class="title-header">
<view class="newsDetail-title">{{articleInfo.title}}</view>
... ... @@ -17,21 +16,6 @@
<template is="wxParse" data="{{wxParseData:detail.nodes}}"/>
</view>
<view class="item-block big-img-block" wx:if="{{detail.bigImage}}">
<image src="{{detail.bigImage}}" mode="widthFix"></image>
<view class="tag-list-box" wx:if="{{detail.tagList.length}}">
<view class="tag-list-box-item"
bindtap="productCellTapped"
data-skn="{{tagItem.product_skn}}"
wx:for="{{detail.tagList}}"
wx:key="bigTagKey"
wx:for-item="tagItem">
<image src="/page/subPackage/pages/newsDetail/images/cart@2x.png"></image>
<text class="ellipsis name">{{tagItem.tagName}}</text>
</view>
</view>
</view>
<view class="item-block small-img-block" wx:if="{{detail.smallImage.length}}">
<image src="{{sitem.src}}" wx:for="{{detail.smallImage}}" wx:key="skey" wx:for-item="sitem"></image>
</view>
... ... @@ -45,69 +29,12 @@
preload="none">不好意思,您的浏览器不支持此视频!</video>
</view>
<view class="item-block related-reco" wx:if="{{detail.relatedReco.goods.length}}">
<block wx:for="{{detail.relatedReco.goods}}" wx:key="goodsKey" wx:for-index="gindex" wx:for-item="goods">
<view class="goods-more" wx:if="{{detail.relatedReco.changeDisplayType}}"
bindtap="productCellTapped"
data-skn="{{goods.product_skn}}">
<image src="{{goods.default_images}}"></image>
<view class="ellipsis title">{{goods.product_name}}</view>
<view class="goods-deps">
<text class="price">{{goods.salePriceStr}}</text>
<view class="show-info" wx:if="{{goods.isLimit}}">
<text>查看详情</text>
<image src="/page/subPackage/pages/newsDetail/images/more@2x.png"></image>
</view>
<image src="/page/subPackage/pages/newsDetail/images/cart2@3x.png"
wx:else></image>
</view>
</view>
<view class="one-goods {{gindex >= detail.relatedReco.moreNum ? 'hidden' : ''}}"
bindtap="productCellTapped"
data-skn="{{goods.product_skn}}"
wx:else>
<image src="{{goods.default_images}}"></image>
<view class="goods-deps">
<view class="ellipsis title">{{goods.product_name}}</view>
<text class="price">{{goods.salePriceStr}}</text>
<view class="cart-icon">
<view class="show-info" wx:if="{{goods.isLimit}}">
<text>查看详情</text>
<image src="/page/subPackage/pages/newsDetail/images/more@2x.png"></image>
</view>
<image src="/page/subPackage/pages/newsDetail/images/cart2@3x.png"
wx:else></image>
</view>
</view>
</view>
</block>
<view class="more-deps" wx:if="{{detail.relatedReco.changeDisplayType === false && (detail.relatedReco.goods.length - detail.relatedReco.moreNum) > 0}}"
bindtap="setGoodsMore"
data-findex="{{findex}}"
data-flen="{{detail.relatedReco.goods.length}}">
<view class="more-text">
<text>展开剩余{{detail.relatedReco.goods.length - detail.relatedReco.moreNum}}个商品</text>
<image class="more-down-icon" src="/page/subPackage/pages/newsDetail/images/more_unfold@2x.png"></image>
</view>
</view>
</view>
</block>
</view>
<view class="tags-block" wx:if="{{articleInfo && articleInfo.tags.length}}">
<navigator url="/page/subPackage/pages/newsDetail/tags?query={{item.name}}{{yasParam}}"
class="tags-item"
hover-class="none"
open-type="navigate"
wx:for="{{articleInfo.tags}}" wx:key="index" wx:for-item="item">
<text>{{item.name}}</text>
</navigator>
</view>
</view>
<!-- 活动详情报名按钮 -->
<!-- <view wx:if="{{isActivtyDetail}}" class="apply-button" bindtap="applyAction" data-id="{{articleInfo.id}}">
报名
</view> -->
<view wx:if="{{isActivtyDetail && articleInfo.need_register==='Y'}}" class="apply-button {{articleInfo.registered === 'Y' ? 'inactive': ''}}" bindtap="applyAction" data-id="{{articleInfo.id}}">
{{articleInfo.registered === 'Y'? '已报名' : '报名'}}
</view>
</view>
... ...
... ... @@ -369,4 +369,8 @@
bottom: 0;
left: 0;
z-index: 99;
}
.newsDetail-detail-page .inactive {
background-color: #D8D8D8;
}
\ No newline at end of file
... ...
... ... @@ -217,11 +217,8 @@ function _processArticleDetail(articleContent) {
let finalDetail = [];
let allGoods = [];
let replyTexts = [];
debugger;
articleContent.map((value, index) => {
debugger
// 文字
let text = _get(value, 'text.data.text', false);
if (text) {
... ...
import {API_HOST, YOHOOD_HOST} from '../libs/config';
import {GET, POST} from '../libs/request';
import {isStringEmpty} from './util'
//活动报名
function applyActivity(id, callbackFunc) {
if (isStringEmpty(id)) {
callbackFunc({
succeed: false,
message: "活动id为空",
code: -1,
});
return
}
let app = getApp()
let param = {
method: '',
uid: app.getUid(),
id
}
GET(YOHOOD_HOST, param)
.then(data => {
if (data && data.code == 200) {
callbackFunc({
succeed: true,
message: "报名成功",
});
} else {
callbackFunc({
succeed: false,
message: data.message || "报名失败",
});
}
})
.catch(res => {
callbackFunc({
succeed: false,
message: res.errMsg
});
});
}
module.exports = {
applyActivity
}
... ...
'use strict'
function parseActivityListData(data, bannerWidth, bannerHeight, listImageWidth, listImageHeight) {
let newData = [];
data && data.map((item, index) => {
if (index > 10) {
return;
}
item.src = item.src.replace(/{width}/g, bannerWidth).replace(/{height}/g, bannerHeight).replace('{mode}', 2);
for (var i = 0; i < item.productList.length; i++) {
item.productList[i].default_images = item.productList[i].default_images.replace(/{width}/g, listImageWidth).replace(/{height}/g, listImageHeight).replace('{mode}', 2);
}
newData.push(item);
});
return newData;
}
module.exports = {
parseActivityListData
}
'use strict'
var util = require('/util.js')
//商品详情页晒单评价需预处理的数据
function parseEvaluateListDataDetailWith(data, picWidth, picHeight, icoWidth, icoHeight, imageWidth) {
let newData = [];
if (data.length > 2) {
return newData;
}
if (data.length == 1) {
newData = data;
} else {
for (var i = 0; i < data.length; i++) {
let item = data[i];
if (i == 0 && item.url) {
newData.push(item);
break;
}
item.url = '';
newData.push(item);
}
}
return parseEvaluateListData(newData, picWidth, picHeight, icoWidth, icoHeight, imageWidth);
}
//晒单列表需处理的数据
function parseEvaluateListData(data, picWidth, picHeight, icoWidth, icoHeight, imageWidth) {
let newData = [];
data && data.map((item, index) => {
let headIco = ''; // 头像
let nickName = ''; // 昵称
let vipLevelImg = ''; // 等级
let factory_goods_name = ''; // 颜色
let size_name = ''; // 尺码
if (item.userInfo) {
nickName = getNickName(item.userInfo.nickName, item.anonymous);
headIco = item.userInfo.headIco ? item.userInfo.headIco.replace(new RegExp('{width}'), icoWidth).replace(new RegExp('{height}'), icoHeight).replace(new RegExp('{mode}'), 2) : '/pages/userCenter/images/mine_default_head.png';
let vipLevel = item.userInfo.vipLevel;
if (vipLevel == 1) {
vipLevelImg = '/pages/userCenter/images/yin-vip@2x.png';
} else if (vipLevel == 2) {
vipLevelImg = '/pages/userCenter/images/jin-vip@2x.png';
} else if (vipLevel == 3) {
vipLevelImg = '/pages/userCenter/images/baijin-vip@2x.png';
}
}
if (item.goods) {
let title = item.goods.sku_title ? item.goods.sku_title : '尺码'
size_name = item.goods.size_name ? title+': ' + item.goods.size_name : '';
factory_goods_name = item.goods.factory_goods_name ? '颜色: ' + item.goods.factory_goods_name : '';
}
let url = item.url ? item.url.replace(new RegExp('{width}'), picWidth).replace(new RegExp('{height}'), picHeight).replace(new RegExp('{mode}'), 2) : ''; //缩略图
let src = item.url ? item.url.replace(new RegExp('{width}'), imageWidth).replace(new RegExp('{height}'), imageWidth).replace(new RegExp('{mode}'), 2) : ''; //放大图
let createTime = util.formatTimeByDefined(item.createTime, 'Y.M.D');
let satisfiedArr = [];
if (item.satisfied > 0) {
for (let i = 0; i < item.satisfied; i++) {
satisfiedArr.push(i);
}
}
let sizeName = '';
if (item.size == 'SMALL') {
sizeName = '偏小';
} else if (item.size == 'MIDDLE') {
sizeName = '适中';
} else if (item.size == 'BIG') {
sizeName = '偏大';
}
let newItem = {
headIco,
nickName,
vipLevelImg,
reply: item.reply,
replyTitle: item.replyTitle,
weight: item.weight ? '体重:' + item.weight + 'kg' : '',
height: item.height ? '身高:' + item.height + 'cm' : '',
satisfied: satisfiedArr,
size: sizeName,
content: item.content,
url,
src,
createTime,
factory_goods_name,
size_name
};
newData.push(newItem);
});
return newData;
}
function getNickName(nickName, anoymous){
if (nickName == null || nickName == '') {
return '***';
}
if (!anoymous) {
if (getStrLength(nickName) <= 11) {
return nickName;
}
return subString(nickName) + '...';
} else {
if (nickName.length <= 3) {
return '***';
}
return nickName.charAt(0).toString() + '***' + nickName.charAt(nickName.length-1).toString();
}
}
//获取中英文字符串的长度
function getStrLength(value) {
let valueLength = 0;
let chinese = "[\u0391-\uFFE5]";
/* 获取字段值的长度,如果含中文字符,则每个中文字符长度为2,否则为1 */
for (let i = 0; i < value.length; i++) {
/* 获取一个字符 */
let temp = value.substring(i, i + 1);
/* 判断是否为中文字符 */
if (temp.match(chinese)) {
/* 中文字符长度为2 */
valueLength += 2;
} else {
/* 其他字符长度为1 */
valueLength += 1;
}
}
return valueLength;
}
function subString(str) {
var newLength = 0;
var newStr = "";
var chineseRegex = /[^\x00-\xff]/g;
var singleChar = "";
var strLength = str.replace(chineseRegex, "**").length;
for (var i = 0; i < strLength; i++) {
singleChar = str.charAt(i).toString();
newStr += singleChar;
if (singleChar.match(chineseRegex) != null) {
newLength += 2;
} else {
newLength++;
}
if (newLength >= 10) {
break;
}
}
return newStr;
}
module.exports = {
parseEvaluateListData,
parseEvaluateListDataDetailWith
}
\ No newline at end of file
'use strict'
function getChannelCode(channel) {
let config = {
boy: 1,
girl: 2,
child: 3,
lifestyle: 4,
};
return config[channel] ? config[channel] : config['boy'];
}
function getGenderCode(channel) {
let config = {
boy: '1,3',
girl: '2,3',
child: '',
lifestyle: '',
};
return config[channel] ? config[channel] : config['boy'];
}
function getRecPosCode(channel) {
let config = {
boy: '100001',
girl: '100002',
child: '',
lifestyle: '',
};
return config[channel] ? config[channel] : config['boy'];
}
function getRecommandContentCode(channel) {
let config = {
boy: '201504091403001',
girl: '201504091403002',
child: '201504091403002',
lifestyle: '201504091403002',
};
return config[channel] ? config[channel] : config['boy'];
}
function getResourceCode(channel){
let config = {
boy: '9cb6138be8e60c96f48107da481816c2',
girl: 'b1fa86320d3f9d9e89153129aeea1b3e',
child: 'e9875682c1599a886bfbdb965b740022',
lifestyle: '9aa25f5133f011ec96c2045eb15ae425',
};
return config[channel] ? config[channel] : config['boy'];
}
//获取首页的contentcode
function getHomeContentCode(channel){
let config = {
boy:'305e0a7a4aba32b08c6dd6dc5da47fa9',
// boy: '9cb6138be8e60c96f48107da481816c2',
girl:'5d9665e6a0a8ec5b2f0c126b36364d24'
}
return config[channel]?config[channel]:config['boy'];
}
module.exports = {
getChannelCode,
getGenderCode,
getRecPosCode,
getRecommandContentCode,
getResourceCode,
getHomeContentCode
}
import { getGoodDetailParam,getImageUrl } from './util';
function parseHomeList(json, windowWidth, windowHeight, listImageWidth, listImageHeight){
let newList=[];
let index = 1;
json && json.map((item,index)=>{
if (item.template_name == 'focus' || item.template_name == 'newFocus'){
//焦点图 -- 只需要对列表中的图片url进行格式化 默认宽高: 750 : 500
for(var i =0;i<item.data.length;i++){
let src = item.data[i].src;
item.data[i].src = getImageUrl(item.data[i].src,750,500);
let param = getGoodDetailParam(item.data[i].url);
if(param){
let json = JSON.parse(param);
item.data[i].title = json.title;
item.data[i]._src = json.cover_url
}
}
} else if (item.template_name == 'newSingleImage'){
//新一张图片 ratio 为 高/宽 抽取出 src title ratio
item.ratio = item.data.imageWidth <= 0 || item.data.imageHeight<=0?0: item.data.imageHeight / item.data.imageWidth
item.ratio = Math.ceil(750 * item.ratio);
item.title = item.data.title;
// if(item.title != '精彩活动' && item.title!='热门品类' && item.title !='潮流品牌'){
// item.title = '';
// }
if(item.data.list && item.data.list[0]){
item.src = getImageUrl(item.data.list[0].src, item.data.imageWidth, item.data.imageHeight)
item.url = item.data.list[0].url
}
} else if (item.template_name =='new_recommend_content_five'){
//热门品类楼层
item.title = item.data.title.title;
item.moreUrl = item.data.more.url;
item.list = item.data.list;
for(var i=0;i<item.list.length;i++){
item.list[i].src = getImageUrl(item.list[i].src, 188, 198);
}
} else if (item.template_name == '3:4ImageListFloor'){
//潮流品牌图片列表
item.title = item.data.title;
item.list = item.data.list;
for(var i=0;i<item.list.length;i++){
item.list[i].src = getImageUrl(item.list[i].src,220,220);
}
let more = item.data.more;
if(more && more.url){
item.moreUrl = more.url;
}
} else if (item.template_name == 'popularListFloor' || item.template_name == 'newProductListFloor'){
//商品列表
for(var i = 0;i<item.data.list.length;i++){
try{
item.data.list[i].default_images = item.data.list[i].default_images.replace(/{width}/g, listImageWidth).replace(/{height}/g, listImageHeight).replace('{mode}', 2);
}catch(e){
console.log('--ReplaceError--')
}
item.data.list[i].index = index;
item.data.list[i].display_type = item.data.display_type; //1显示价格2显示店铺
}
} else if (item.template_name == 'image_list') {
//商品列表
for (var i = 0; i < item.data.list.length; i++) {
try{
item.data.list[i].src = item.data.list[i].src.replace(/{width}/g, 150).replace(/{height}/g, 150).replace('{mode}', 2);
}catch(e){
console.log('--ReplaceError--')
}
}
} else if (item.template_name == 'twoPicture'){
let width = item.data.imageWidth > 0 ? item.data.imageWidth:345;
let height = item.data.imageHeight > 0 ? item.data.imageHeight:200;
item.ratio = height/width;
item.data && item.data.list && item.data.list.map((item,index)=>{
try{
item.src = item.src.replace(/{width}/g, width).replace(/{height}/g, height).replace('{mode}', 2);
}catch(e){
}
})
item.title = item.data.title;
}else if (item.template_name == 'sv_new_user_floor') {
// 新人楼层
if (item.data && item.data.banner_image && item.data.banner_image.length > 0) {
for(var i = 0;i<item.data.banner_image.length;i++){
if (item.data.banner_image[i].src) {
try{
item.data.banner_image[i].src = item.data.banner_image[i].src.replace(/{width}/g, 1500).replace(/{height}/g, 720).replace('{mode}', 2);
}catch(e){
console.log('--ReplaceError--')
}
}
}
}
} else if (item.template_name == 'collageBuyPrdList'){
if (item.data.layout_float == 'V' || item.data.layout_float == 'v'){
item.layout_float='V';
item.sknList = item.data.sknList;
}else{
item.prdList = []
try {
item.data.data.prdList.map((list_item, index) => {
list_item.defaultImages = list_item.defaultImages.replace(/{width}/g, 188).replace(/{height}/g, 250).replace('{mode}', 2)
item.prdList.push(list_item)
})
} catch (e) { }
}
}
// else{
// item.template_name = "undefine";
// }
index++;
newList.push(item);
})
return newList;
}
export{
parseHomeList
}
\ No newline at end of file
'use strict'
function getGoodInfo(data) {
let newData = [];
let idElement = '编号: ' + data.erpProductId
newData.push(idElement)
if (!!data.productionTime) {
newData.push('规格: ' + data.colorName)
let gender = ''
if (data.gender == 1) {
gender = '男款'
} else if (data.gender == 2) {
gender = '女款'
} else if (data.gender == 3) {
gender = '通用'
}
if (gender) {
newData.push('性别: ' + gender)
}
newData.push('保质期: ' + data.guaranteeDay)
newData.push('生产日期: ' + data.productionTime)
} else {
newData.push('颜色: ' + data.colorName)
let gender = ''
if (data.gender == 1) {
gender = '男款'
} else if (data.gender == 2) {
gender = '女款'
} else if (data.gender == 3) {
gender = '通用'
}
if (gender) {
newData.push('性别: ' + gender)
}
}
data && data.standardBos.map((item, index) => {
let newItem = item.standardName + ': ' + item.standardVal
newData.push(newItem);
});
return newData;
}
function getGoodSize(data) {
let titleList = ['吊牌尺码']
data && data.sizeAttributeBos.map((item, index) => {
let newItem = item.attributeName;
titleList.push(newItem);
});
let sizeList = []
data && data.sizeBoList.map((item, index) => {
let itemList = [];
itemList.push(item.sizeName)
item.sortAttributes.map((subItem, subIndex) => {
itemList.push(subItem.sizeValue)
})
sizeList.push(itemList)
});
return {titleList, sizeList};
}
function getGoodImages(data, listImageWidth, listImageHeight) {
let imageList = []
data && data.map((item, index) => {
item = item.image_url.replace(/{width}/g, listImageWidth).replace(/{height}/g, listImageHeight).replace('{mode}', 2);
imageList.push(item);
});
return imageList;
}
function getModelList(data) {
let modelList = []
let model = {}
data && data.map((item, index) => {
model.name = item.modelName
model.height = item.height
model.weight = item.weight
model.vital = item.vitalStatistics
model.size = item.fitModelBo.fit_size
model.feel = item.fitModelBo.feel
modelList.push(item)
});
return modelList
}
module.exports = {
getGoodInfo,
getGoodSize,
getGoodImages,
getModelList,
}
\ No newline at end of file
'use strict'
import { getYHStorageSync } from './util';
const Search_History_Key = 'Search_History_Key';
function addSearchHistory(keyword) {
if (!keyword.trim()) {
return false;
}
let list = fetchSearchHistory();
let newList = list.filter((value, i) => {
return value != keyword;
});
newList = [keyword, ...newList];
newList = newList.slice(0, 10);
try {
wx.setStorageSync(Search_History_Key, newList);
} catch (e) {
}
return true;
}
function removeSearchHistory(keyword) {
let list = fetchSearchHistory();
let newList = list.filter((value, i) => {
return value != keyword;
});
wx.setStorage({
key: Search_History_Key,
data: newList,
});
return true;
}
function clearSearchHistory() {
try {
wx.removeStorageSync(Search_History_Key);
} catch (e) {
return false;
}
return true;
}
function fetchSearchHistory() {
let value = getYHStorageSync(Search_History_Key,'search')
if (value) {
return value;
}
return [];
}
module.exports = {
addSearchHistory,
removeSearchHistory,
clearSearchHistory,
fetchSearchHistory,
};
\ No newline at end of file
'use strict'
import {getImageUrlWithWH} from './util';
function toDecimal2(x) {
var f = parseFloat(x);
if (isNaN(f)) {
return false;
}
var f = Math.round(x * 100) / 100;
var s = f.toString();
var rs = s.indexOf('.');
if (rs < 0) {
rs = s.length;
s += '.';
}
while (s.length <= rs + 2) {
s += '0';
}
return s;
}
function processGiftOrPriceGift(giftList, isGift) {
let selledOutGiftTypeCount = 0;
giftList.map((item, index) => {
let statusString = "";
if (item.status == 0) {
statusString = "去凑单";
} else if (item.status == 10) {
if (item.promotion_type == "Gift") {//Cashreduce,Degressdiscount,Cheapestfree,Discount,Gift,Needpaygift,SpecifiedAmount
statusString = "领赠品";
} else if (item.promotion_type == "Needpaygift") {
statusString = "去换购";
}
} else if (item.status == 20) {
selledOutGiftTypeCount++;
statusString = "已抢光";
} else if (item.status == 30) {
statusString = "更换";
}
item.statusString = statusString;
item.isGift = isGift;
});
if (selledOutGiftTypeCount == giftList.height) {
giftList.map((item, index) => {
item.statusString = "已抢光";
});
}
;
return giftList;
}
function processGoodsItem(goodsItem) {
let imagesUrl = getImageUrlWithWH(goodsItem.goods_images, 75, 100);
goodsItem.goods_images = imagesUrl;
if (!!goodsItem.sku_title) {
goodsItem.goodColorSizeString = "颜色:" + goodsItem.factory_goods_name + " " + goodsItem.sku_title +":" + goodsItem.size_name;
} else {
goodsItem.goodColorSizeString = "颜色:" + goodsItem.factory_goods_name + " " + "尺码:" + goodsItem.size_name;
}
let isShowOldPrice = true;
let priceString = '';
let shoppingProductType = goodsItem.goods_type;
if (shoppingProductType == 'price_gift') {
priceString = goodsItem.last_price;
} else if (shoppingProductType == 'gift') {
priceString = '0.00';
} else {
if (goodsItem.last_vip_price < goodsItem.sales_price) {
priceString = goodsItem.last_vip_price;
} else {
priceString = goodsItem.sales_price;
}
isShowOldPrice = false;
}
priceString = '¥' + toDecimal2(priceString);
let oldPricString = goodsItem.sales_price;
oldPricString = '¥' + toDecimal2(oldPricString);
if (goodsItem.price_down > 0) {
goodsItem.price_down = toDecimal2(goodsItem.price_down);
}
if (parseInt(goodsItem.buy_number) > parseInt(goodsItem.storage_number)) {
goodsItem.bLackStorage = true;
}
if (goodsItem.selected == "Y") {
goodsItem.bSelected = true;
}
goodsItem.priceString = priceString;
goodsItem.oldPricString = oldPricString;
goodsItem.isShowOldPrice = isShowOldPrice;
var unique_identifier = goodsItem.product_sku + goodsItem.batch_no.toString() + goodsItem.bundle_activity_id.toString();
goodsItem.unique_identifier = unique_identifier;
return goodsItem;
}
function isGoodsSelectAll(goodsList) {
if (!goodsList || !goodsList.length) {
return false;
}
let allGoodsSelect = true;
goodsList.map((goodsItem, index) => {
if (!goodsItem.bLackStorage && goodsItem.goods_type !== 'gift') {
if (goodsItem.selected !== 'Y') {
allGoodsSelect = false;
}
}
});
return allGoodsSelect;
}
function processPromotionItem(promotionItem, isSubPromotion) {
let promotionStatusString = "";
if (promotionItem.status == 0) {
promotionStatusString = "去凑单";
} else if (promotionItem.status == 10) {
if (promotionItem.promotion_type == "Gift") {//Cashreduce,Degressdiscount,Cheapestfree,Discount,Gift,Needpaygift,SpecifiedAmount
promotionStatusString = "领赠品";
} else if (promotionItem.promotion_type == "Needpaygift") {
promotionStatusString = "去换购";
}
} else if (promotionItem.status == 20) {
promotionStatusString = "已抢光";
} else if (promotionItem.status == 30) {
promotionStatusString = "更换";
}
if (promotionStatusString == "已抢光") {
promotionItem.seldoutStyle = true;
}
promotionItem.statuString = promotionStatusString;
if (isSubPromotion) {
let typeString = '';
if (promotionItem.promotion_type == "Gift") {
typeString = '赠品';
} else if (promotionItem.promotion_type == 'Needpaygift') {
typeString = '加价购';
} else if (promotionItem.promotion_type == 'Cashreduce') {
typeString = '满减';
} else {
typeString = '折扣';
}
promotionItem.typeString = typeString;
}
return promotionItem;
}
function curShoppingCartDataAddExpandedFlag(curShoppingCartData) {
let goodsList = curShoppingCartData.goods_list;
let validGoodsList = [];
if (goodsList) {
goodsList.map((goodsItem, index) => {
goodsItem = processGoodsItem(goodsItem);
validGoodsList.push(goodsItem);
})
}
curShoppingCartData.goods_list = goodsList;
let goodsPoolList = curShoppingCartData.goods_pool_list;
if (goodsPoolList) {
goodsPoolList.map((item, index) => {
if (item.pool_batch_no && item.pool_id) {
//套餐商品参数转换
item.int_pool_buy_number = parseInt(item.pool_buy_number);
item.int_pool_storage_number = parseInt(item.pool_storage_number);
}
let goodsPoolGoodsList = item.goods_list;
if (goodsPoolGoodsList) {
goodsPoolGoodsList.map((goodsItem, index) => {
goodsItem = processGoodsItem(goodsItem);
validGoodsList.push(goodsItem);
})
}
item.isPromotionExpanded = false;
let promotionList = item.promotion_list;
if (promotionList) {
promotionList.map((promotionItem, promotionIndex) => {
promotionItem = processPromotionItem(promotionItem, false);
})
item.promotion_list = promotionList;
}
let subPool = item.sub_pool;
if (subPool) {
subPool.map((subPoolItem, index) => {
let promotionList = subPoolItem.promotion_list;
if (promotionList) {
promotionList.map((promotionItem, promotionIndex) => {
promotionItem = processPromotionItem(promotionItem, true);
})
subPoolItem.promotion_list = promotionList;
}
let subPoolGoodsList = subPoolItem.goods_list;
if (subPoolGoodsList) {
subPoolGoodsList.map((subPoolGoodsItem, index) => {
subPoolGoodsItem = processGoodsItem(subPoolGoodsItem);
validGoodsList.push(subPoolGoodsItem);
})
}
})
}
item.sub_pool = subPool;
});
}
curShoppingCartData.validGoodsList = validGoodsList;
curShoppingCartData.isValidGoodsSelectAll = isGoodsSelectAll(validGoodsList);
// let newgPriceGiftList = [];
let gPriceGiftList = curShoppingCartData.g_price_gift_list;
// if (gPriceGiftList && gPriceGiftList.length && canShowGiftEntrance(gPriceGiftList)) {
// newgPriceGiftList = processGiftOrPriceGift(gPriceGiftList, false);
// }
// curShoppingCartData.g_price_gift_list = newgPriceGiftList;
// let newgGiftList = [];
let gGiftList = curShoppingCartData.g_gift_list;
// if (gGiftList && gGiftList.length && canShowGiftEntrance(gGiftList)) {
// newgGiftList = processGiftOrPriceGift(gGiftList, true);
// }
// curShoppingCartData.g_gift_list = newgGiftList;
let gGiftAndPriceGiftList = [];
if (gGiftList && gGiftList.length) {
let giftItem = transformToGiftModelWithGiftList(gGiftList, true);
if (giftItem.canShow) {
gGiftAndPriceGiftList.push(giftItem);
}
}
if (gPriceGiftList && gPriceGiftList.length) {
let priceGiftItem = transformToGiftModelWithGiftList(gPriceGiftList, false);
if (priceGiftItem.canShow) {
gGiftAndPriceGiftList.push(priceGiftItem);
}
}
// if (newgPriceGiftList.length && newgGiftList.length) {
// gGiftAndPriceGiftList = [newgGiftList[0], newgPriceGiftList[0]];
// } else if (newgPriceGiftList.length) {
// gGiftAndPriceGiftList = [newgPriceGiftList[0]];
// } else if (newgGiftList.length) {
// gGiftAndPriceGiftList = [newgGiftList[0]];
// }
curShoppingCartData.gGiftAndPriceGiftList = gGiftAndPriceGiftList;
//失效商品
let offShelvesGoodsList = curShoppingCartData.off_shelves_goods_list;
let soldOutGoodsList = curShoppingCartData.sold_out_goods_list;
let invalidGoodsList = [...offShelvesGoodsList, ...soldOutGoodsList];
if (invalidGoodsList && invalidGoodsList.length) {
invalidGoodsList.map((invalidGoodsItem, index) => {
let imagesUrl = getImageUrlWithWH(invalidGoodsItem.goods_images, 75, 100);
;
invalidGoodsItem.goods_images = imagesUrl;
})
}
let last_order_amount = curShoppingCartData.shopping_cart_data.last_order_amount;
last_order_amount = '¥' + toDecimal2(last_order_amount);
curShoppingCartData.shopping_cart_data.last_order_amount = last_order_amount;
curShoppingCartData.invalidGoodsList = invalidGoodsList;
let has_product_in_shop_cart = (curShoppingCartData.goods_list.length + curShoppingCartData.goods_pool_list.length + curShoppingCartData.off_shelves_goods_list.length + curShoppingCartData.sold_out_goods_list.length > 0);
curShoppingCartData.has_product_in_shop_cart = has_product_in_shop_cart;
return curShoppingCartData;
}
function canShowGiftEntrance(items) {
let result = false;
let statusCount_10 = 0;//已满足
let statusCount_20 = 0;//已售罄
items.map((item, index) => {
if (item.status == 10) {
statusCount_10++;
} else if (item.status == 20) {
statusCount_20++;
}
});
if (statusCount_10 > 0 || (items.length > 0 && statusCount_20 == items.length)) {
result = true;
}
return result;
}
function transformToGiftModelWithGiftList(list, isGift) {
let resultItem = {};
resultItem.isGift = isGift;
resultItem.title = isGift ? '赠品' : '全场加价购';
let promotion_ids = '';
list.map((item, index) => {
if (item.status == 10) {
promotion_ids = promotion_ids + (promotion_ids.length == 0 ? '' : ',') + item.promotion_id;
}
});
resultItem.promotion_ids = promotion_ids;
if (promotion_ids.length > 0) {
if (isGift) {
resultItem.statusString = '领赠品';
} else {
resultItem.statusString = '去换购';
}
resultItem.showArrow = true;
} else {
resultItem.statusString = '已抢光';
resultItem.showArrow = false;
}
resultItem.canShow = canShowGiftEntrance(list);
return resultItem;
}
function curPageDataAllSelectWhenEditing(curShoppingCartData, allSelect) {
let goodsList = curShoppingCartData.goods_list;
let validGoodsList = [];
if (goodsList) {
goodsList.map((goodsItem, index) => {
goodsItem = processGoodsItem(goodsItem);
if (allSelect) {
goodsItem.selected = 'Y';
goodsItem.bSelected = true;
} else {
goodsItem.selected = 'N';
goodsItem.bSelected = false;
}
})
}
let goodsPoolList = curShoppingCartData.goods_pool_list;
if (goodsPoolList) {
goodsPoolList.map((item, index) => {
if (item.pool_type == '3' && item.pool_batch_no) {
item.selected = allSelect ? 'Y' : 'N';
}
let goodsPoolGoodsList = item.goods_list;
if (goodsPoolGoodsList) {
goodsPoolGoodsList.map((goodsItem, index) => {
goodsItem = processGoodsItem(goodsItem);
if (allSelect) {
goodsItem.selected = 'Y';
goodsItem.bSelected = true;
} else {
goodsItem.selected = 'N';
goodsItem.bSelected = false;
}
})
}
let subPool = item.sub_pool;
if (subPool) {
subPool.map((subPoolItem, index) => {
let subPoolGoodsList = subPoolItem.goods_list;
if (subPoolGoodsList) {
subPoolGoodsList.map((subPoolGoodsItem, index) => {
subPoolGoodsItem = processGoodsItem(subPoolGoodsItem);
if (allSelect) {
subPoolGoodsItem.selected = 'Y';
subPoolGoodsItem.bSelected = true;
} else {
subPoolGoodsItem.selected = 'N';
subPoolGoodsItem.bSelected = false;
}
})
}
})
}
item.sub_pool = subPool;
});
}
return curShoppingCartData;
}
function curPageDataSingleSelectWhenEditing(curShoppingCartData, selectItem) {
let isValidGoodsSelectAll = true;
let goodsList = curShoppingCartData.goods_list;
let validGoodsList = [];
if (goodsList) {
goodsList.map((goodsItem, index) => {
goodsItem = processGoodsItem(goodsItem);
if (goodsItem.unique_identifier == selectItem.unique_identifier) {
if (goodsItem.selected == 'Y') {
goodsItem.selected = 'N';
goodsItem.bSelected = false;
} else {
goodsItem.selected = 'Y';
goodsItem.bSelected = true;
}
}
if (isValidGoodsSelectAll && (!goodsItem.bSelected)) {
isValidGoodsSelectAll = false;
}
})
}
curShoppingCartData.goods_list = goodsList;
let goodsPoolList = curShoppingCartData.goods_pool_list;
if (goodsPoolList) {
goodsPoolList.map((item, index) => {
let goodsPoolGoodsList = item.goods_list;
if (goodsPoolGoodsList) {
goodsPoolGoodsList.map((goodsItem, index) => {
goodsItem = processGoodsItem(goodsItem);
if (goodsItem.unique_identifier == selectItem.unique_identifier) {
if (goodsItem.selected == 'Y') {
goodsItem.selected = 'N';
goodsItem.bSelected = false;
} else {
goodsItem.selected = 'Y';
goodsItem.bSelected = true;
}
}
if (isValidGoodsSelectAll && (!goodsItem.bSelected)) {
isValidGoodsSelectAll = false;
}
})
}
let subPool = item.sub_pool;
if (subPool) {
subPool.map((subPoolItem, index) => {
let subPoolGoodsList = subPoolItem.goods_list;
if (subPoolGoodsList) {
subPoolGoodsList.map((subPoolGoodsItem, index) => {
subPoolGoodsItem = processGoodsItem(subPoolGoodsItem);
if (subPoolGoodsItem.unique_identifier == selectItem.unique_identifier) {
if (subPoolGoodsItem.selected == 'Y') {
subPoolGoodsItem.selected = 'N';
subPoolGoodsItem.bSelected = false;
} else {
subPoolGoodsItem.selected = 'Y';
subPoolGoodsItem.bSelected = true;
}
}
if (isValidGoodsSelectAll && (!subPoolGoodsItem.bSelected)) {
isValidGoodsSelectAll = false;
}
})
}
})
}
item.sub_pool = subPool;
});
curShoppingCartData.goods_pool_list = goodsPoolList;
}
curShoppingCartData.isValidGoodsSelectAll = isValidGoodsSelectAll;
return curShoppingCartData;
}
function curPageDataSingleSelectBundleProductWhenEditing(curShoppingCartData, selectBundleItem) {
if (curShoppingCartData.goods_pool_list) {
curShoppingCartData.goods_pool_list.map((item, index) => {
if (item.pool_type == 3 && item.pool_batch_no) {
item.selected = selectBundleItem.selected;
let goodsPoolGoodsList = item.goods_list;
if (goodsPoolGoodsList) {
goodsPoolGoodsList.map((goodsItem, index) => {
goodsItem = processGoodsItem(goodsItem);
if (item.selected == 'Y') {
goodsItem.selected = 'Y';
goodsItem.bSelected = true;
} else {
goodsItem.selected = 'N';
goodsItem.bSelected = false;
}
})
}
}
});
}
return curShoppingCartData;
}
function editInfoDicFromGoodsList(goodsList, isSelectAll) {
if (!goodsList || !goodsList.length) {
return [];
}
let editInfoDicArray = [];
goodsList.map((goodsItem, index) => {
if (!goodsItem.bLackStorage && goodsItem.goods_type !== 'gift') {
editInfoDicArray.push({
buy_number: goodsItem.buy_number ? goodsItem.buy_number : 0,
goods_type: goodsItem.goods_type ? goodsItem.goods_type : "",
product_sku: goodsItem.product_sku ? goodsItem.product_sku : "",
promotion_id: goodsItem.promotion_id ? goodsItem.promotion_id : 0,
selected: isSelectAll ? "Y" : "N",
activity_id: goodsItem.bundle_activity_id ? goodsItem.bundle_activity_id : 0,
batch_no: goodsItem.batch_no ? goodsItem.batch_no : 0,
})
}
});
return editInfoDicArray;
}
function editInfoDicFromBundleItem(bundleItem) {
if (!bundleItem || !bundleItem.goods_list.length) {
return [];
}
let editInfoDicArray = [];
bundleItem.goods_list.map((goodsItem, index) => {
editInfoDicArray.push({
buy_number: goodsItem.buy_number ? goodsItem.buy_number : 0,
goods_type: goodsItem.goods_type ? goodsItem.goods_type : "",
product_sku: goodsItem.product_sku ? goodsItem.product_sku : "",
promotion_id: goodsItem.promotion_id ? goodsItem.promotion_id : 0,
selected: bundleItem.selected,
activity_id: goodsItem.bundle_activity_id ? goodsItem.bundle_activity_id : 0,
batch_no: goodsItem.batch_no ? goodsItem.batch_no : 0,
})
});
return editInfoDicArray;
}
function editInfoSelectedGoodsList(goodsList, isEdit) {
if (!goodsList || !goodsList.length) {
return [];
}
let editInfoDicArray = [];
goodsList.map((goodsItem, index) => {
if ((!goodsItem.bLackStorage || isEdit) && goodsItem.goods_type !== 'gift') {
if (goodsItem.selected == 'Y') {
editInfoDicArray.push({
buy_number: goodsItem.buy_number ? goodsItem.buy_number : 0,
goods_type: goodsItem.goods_type ? goodsItem.goods_type : "",
product_sku: goodsItem.product_sku ? goodsItem.product_sku : "",
promotion_id: goodsItem.promotion_id ? goodsItem.promotion_id : 0,
selected: "Y",
activity_id: goodsItem.bundle_activity_id ? goodsItem.bundle_activity_id : 0,
batch_no: goodsItem.batch_no ? goodsItem.batch_no : 0,
})
}
}
});
return editInfoDicArray;
}
function editInfoOfAllGoods(goodsList) {
if (!goodsList || !goodsList.length) {
return [];
}
let editInfoDicArray = [];
goodsList.map((goodsItem, index) => {
editInfoDicArray.push({
buy_number: goodsItem.buy_number ? goodsItem.buy_number : 0,
goods_type: goodsItem.goods_type ? goodsItem.goods_type : "",
product_sku: goodsItem.product_sku ? goodsItem.product_sku : "",
promotion_id: goodsItem.promotion_id ? goodsItem.promotion_id : 0,
selected: goodsItem.selected,
activity_id: goodsItem.bundle_activity_id ? goodsItem.bundle_activity_id : 0,
batch_no: goodsItem.batch_no ? goodsItem.batch_no : 0,
})
});
return editInfoDicArray;
}
function hasLackStorageGoodsInList(goodsList) {
if (!goodsList || !goodsList.length) {
return false;
}
let hasLackStorageGoods = false;
goodsList.map((goodsItem, index) => {
if (goodsItem.bLackStorage) {
hasLackStorageGoods = true;
}
});
return hasLackStorageGoods;
}
module.exports = {
curShoppingCartDataAddExpandedFlag,
editInfoDicFromGoodsList,
hasLackStorageGoodsInList,
curPageDataAllSelectWhenEditing,
curPageDataSingleSelectWhenEditing,
editInfoOfAllGoods,
editInfoSelectedGoodsList,
curPageDataSingleSelectBundleProductWhenEditing,
editInfoDicFromBundleItem,
}
\ No newline at end of file
'use strict'
import { API_HOST, SERVICE_HOST, PAYMENT_CODE} from '../libs/config';
import {GET, POST} from '../libs/request';
import { getYHStorageSync } from './util';
import {
logEvent,
YB_SC_PAY_RES,
} from '../libs/analytics.js'
let app = getApp();
let orderCode;
//微信支付action
function wexinPay(data,payParam){
console.log(data.payment_amount);
console.log(data.order_amount);
let wetoast = new app.WeToast();
let order_amount = data.payment_amount ? data.payment_amount : data.order_amount;
let order_code = data.order_code;
let isVirtual = payParam && payParam.isVirtual ? 'true':'false';
if(!data){
let params = {
ORDER_AMOUNT: order_amount,
PAY_TYPE: 1,
PAY_RES: 0,
ORD_NUM: order_code,
};
logEvent(YB_SC_PAY_RES, params);
wx.showModal({
content: '支付失败,请求参数不完整.',
showCancel: false,
confirmText: "确定",
})
return
}
if(!data.order_code){
let params = {
ORDER_AMOUNT: order_amount,
PAY_TYPE: 1,
PAY_RES: 0,
ORD_NUM: order_code,
};
logEvent(YB_SC_PAY_RES, params);
wx.showModal({
content: '支付失败,订单号未获取到.',
showCancel: false,
confirmText: "确定",
})
return
}
if(!app.globalData.WXThird_session){
let params = {
ORDER_AMOUNT: order_amount,
PAY_TYPE: 1,
PAY_RES: 0,
ORD_NUM: order_code,
};
logEvent(YB_SC_PAY_RES, params);
wx.showModal({
content: '支付失败,用户session未获取到.',
showCancel: false,
confirmText: "确定",
})
return
}
wx.showToast({
title: '加载中',
icon: 'loading',
duration: 10000
})
orderCode = data.order_code
let param = {
method:'/payment/weixin_data',
order_code:data.order_code,
payment_code: PAYMENT_CODE,
'3rd_session':app.globalData.WXThird_session,
}
GET(SERVICE_HOST+'/payment/weixin_data', param)
.then(function(data) {
wx.hideToast()
if(data && data.data && data.code == 200){
wx.requestPayment({
'timeStamp': data.data.timeStamp,
'nonceStr': data.data.nonceStr,
'package': data.data.package,
'signType': data.data.signType,
'paySign':data.data.paySign,
'success':function(res){
let app = getApp()
// console.log("openID:", app.globalData.openID ? app.globalData.openID : getYHStorageSync('openID','wxpay'))
//上报formID
let prepareID = data.data.package
if (prepareID && prepareID.length > 10) {
prepareID = prepareID.slice(10)
let formIdParams = {
uid: app.getUid(),
order_code: orderCode,
openId: app.globalData.openID ? app.globalData.openID : getYHStorageSync('openID','wxpay'),
miniapp_type: app.globalData.miniapp_type,
formId: prepareID,
method: 'wechat.formId.add',
formType: 'pay',
}
// console.log("prepareID:",formIdParams)
GET(API_HOST, formIdParams)
.then((data) => {
// console.log('responsedata', data)
})
.catch(error => {
})
}
let params = {
ORDER_AMOUNT: order_amount,
PAY_TYPE: 1,
PAY_RES: 1,
ORD_NUM: order_code,
};
logEvent(YB_SC_PAY_RES, params);
payConfirm(orderCode)
// wx.showModal({
// content: '支付成功',
// showCancel: false,
// confirmText: "确定",
// complete: function(res) {
// wx.navigateBack({
// delta: getCurrentPages().length-1
// })
if (payParam && payParam.fromPage == 'groupPurchaseDetail'){
wx.navigateTo({
url: "/pages/groupPurchase/groupPurchaseResult?activity_id=" + payParam.activity_id + '&group_no=' + payParam.group_no + '&page_name=' + 'statements' + '&page_param=' + ''
});
}else {
wx.navigateTo({
url: "/pages/paymentSuccessed/paymentSuccessed?orderCode=" + order_code + '&hasSuc=true' + '&price=' + parseInt(order_amount).toFixed(2) + '&isVirtual=' + isVirtual
});
}
// }})
},
'fail':function(res){
let params = {
ORDER_AMOUNT: order_amount,
PAY_TYPE: 1,
PAY_RES: 0,
ORD_NUM: order_code,
};
logEvent(YB_SC_PAY_RES, params);
if(res.errMsg=='requestPayment:fail cancel'){
wx.redirectTo({
url: '/pages/orders/orders'
})
}else{
wx.showModal({
content: res.errMsg,
showCancel: false,
confirmText: "确定",
complete: function(res) {
wx.redirectTo({
url: '/pages/orders/orders'
})
}
})
}
}
})
}else{
wx.hideToast()
wx.showModal({
content: data.code+':'+data.message,
showCancel: false,
confirmText:'确定',
confirmColor:"#000",
complete: function(res) {
wx.redirectTo({
url: '/pages/orders/orders'
})
}
})
}
})
.catch(function(error) {
// console.log(error+'')
});
}
//支付确认接口
function payConfirm(orderCode){
if(!orderCode||orderCode==0){
return
}
let param = {
method:'app.SpaceOrders.payConfirm',
order_code:orderCode,
payment_id:45,
uid:app.globalData.userInfo.uid,
}
GET(API_HOST, param)
}
module.exports = {
wexinPay: wexinPay,
}
\ No newline at end of file