Files

2289 lines
64 KiB
JavaScript
Raw Permalink Normal View History

var WxParse = null;
//获取应用实例
var app = getApp()
var sopenFrame = null
var sopenFrame0 = null
var sopenFrame1 = null
var areas = null;
var that = null
var that0 = null
var viewId = 0
var ttype = 0
var addtype = 0
var pics = []
var yunfeis = []
var showpic = ""
var showpics = []
var selectedguige = ""
var selectedguigeid = ""
var selectedcolor = ""
var updateing = 0
var updateing2 = 0
var wait = 120
var ifshowhongbao = 0;
var ifqd = 0;
var interval = null;
var ifPaypush = 0,
ifplay = 0;
var mp3data = null;
var mp3index = 0;
Page({
data: {
indicatorDots: true,
indicatorDots0: true,
ifxn: 0,
vertical: false,
vertical0: false,
autoplay: true,
interval: 6000,
interval0: 8000,
duration: 1000,
duration0: 1000,
loadingHidden: false, // loading
currentTab: 0, // 预设当前项的值
scrollLeft: 0, // tab标题的滚动条位置
images: [],
news: [],
webname: "零碳小店",
aBody: "",
introbody: "",
qkeyword: "请输入商品关键字",
keyword: "",
keywordwidth: "100%",
closesearch: true,
getfocus: false,
authorizeHidden: true,
onauthorizetitle: "确认授权",
authorizeHidden0: true,
onauthorizetitle0: "获取微信手机号",
getcode0: "获取验证码",
savebutton0: "确认绑定",
Currentselection: "全国",
unbindPhoneHidden: true,
kaihongbaoHidden: true,
canIUseGetUserProfile: false,
flashhidden: true,
products: [],
products0: [],
item_index: 0,
categoryid: 0,
FHZJE: 0,
uLevel: "普通会员",
marquee: 0, //每次移动X坐标
windowWidth: 0, //小程序宽度
maxScroll: 0, //文本移动至最左侧宽度及文本宽度
Start: 0,
navData: [],
nav_item0: "",
TabwindowWidth: 95,
currentTab: 0,
navScrollLeft: 0,
menu_ico0: false,
menu_ico1: true,
viewId: 0,
title: "",
oldpricetitle: "",
oldprice: "0.00",
currentprice: "0.00",
currenttitle: "",
body: "",
qybtnHidden: true,
serverHidden: true,
servermsg: "",
favorite: "收藏",
addcartHidden: true,
guigesHidden: false,
colorHidden: true,
selguige_font: "请选择:",
selguige_title: "规格或颜色",
selguiges: [],
currentindex: 0,
minprice: 0.00,
showindex: 0,
showimage: "",
showimages: "",
sharepic: "",
cartmsgHidden: true,
qyaddcart: "确认",
cartcount: 0,
ttype: 0,
tguid: 0,
IFPD: 0,
IFDJPD: 0,
IFCS: 0,
sharetitle: "",
closenoticeHidden: true,
showtitle: "",
showbody: "",
myAudios: [],
icon1: 0, //企业介绍icon,0=显示,1=隐藏
icon2: 0, //操作教程icon,0=显示,1=隐藏
icon3: 0, //发图素材icon,0=显示,1=隐藏
icon4: 0, //健康知识icon,0=显示,1=隐藏
icon5: 0, //客服专区icon,0=显示,1=隐藏
},
onShow: function () {
if (typeof this.getTabBar === 'function' && this.getTabBar()) {
that0 = this;
var userId = wx.getStorageSync("userId")
var userInfodata = wx.getStorageSync("userInfo")
var sel = 0;
var ifsel = 0;
if (userId && userInfodata) {
var userInfo = JSON.parse(userInfodata)
ifsel = userInfo.bdshEnable;
}
if (ifsel == 1) {
that0.getTabBar().setData({
"list": [{
"pagePath": "/pages/index/index",
"text": "首页",
"iconPath": "/images/footer-icon-01.png",
"selectedIconPath": "/images/footer-icon-01-active.png"
},
{
"pagePath": "/pages/news/index",
"iconPath": "/images/footer-icon-05.png",
"selectedIconPath": "/images/footer-icon-05-active.png",
"text": "资讯"
},
{
"pagePath": "/pages/my/index",
"text": "我的",
"iconPath": "/images/footer-icon-04.png",
"selectedIconPath": "/images/footer-icon-04-active.png"
}
]
})
} else {
that0.getTabBar().setData({
"list": [{
"pagePath": "/pages/index/index",
"text": "首页",
"iconPath": "/images/footer-icon-01.png",
"selectedIconPath": "/images/footer-icon-01-active.png"
},
{
"pagePath": "/pages/news/index",
"iconPath": "/images/footer-icon-05.png",
"selectedIconPath": "/images/footer-icon-05-active.png",
"text": "资讯"
},
{
"pagePath": "/pages/business/index",
"iconPath": "/images/footer-icon-02.png",
"selectedIconPath": "/images/footer-icon-02-active.png",
"text": "门店"
},
{
"pagePath": "/pages/my/index",
"text": "我的",
"iconPath": "/images/footer-icon-04.png",
"selectedIconPath": "/images/footer-icon-04-active.png"
}
]
})
}
that0.getTabBar().setData({
selected: sel
})
}
},
//事件处理函数
swiperchange: function (e) {
//console.log(e.detail.current)
},
//事件处理函数
swiperchange0: function (e) {
//console.log(e.detail.current)
},
onLoad: function (options) {
that = this
if (wx.getUserProfile) {
this.setData({
canIUseGetUserProfile: true
})
}
wx.setBackgroundColor({
backgroundColor: "#00B050",
})
if (options.tguid) {
var tguid = options.tguid;
if (tguid != "") {
wx.setStorageSync("tguid", tguid)
if (options.viewid) {
wx.setStorageSync("viewid", options.viewid)
if (options.poid) {
wx.setStorageSync("viewpoid", options.poid)
}
wx.setStorageSync("tguid0", tguid)
}
if (options.videoid) {
wx.setStorageSync("videoid0", options.videoid)
}
that.setData({
flashhidden: false
})
wx.navigateTo({
url: "../register/index?ifzt=1"
})
//app.getUserInfo()
}
}
if (options.scene) {
const tguid = decodeURIComponent(options.scene);
if (tguid != "") {
wx.setStorageSync("tguid", tguid)
that.setData({
flashhidden: false
})
wx.navigateTo({
url: "../register/index?ifzt=1"
})
}
}
WxParse = require('../../wxParse/wxParse.js');
areas = require('../../area.js');
var indexdata = wx.getStorageSync('indexdata3')
if (indexdata) {
var resindexdata = JSON.parse(indexdata);
that.setData({
images: resindexdata.pic,
navData: resindexdata.pic1,
news: resindexdata.news,
products: resindexdata.products,
products0: resindexdata.products1,
loadingHidden: true
})
}
that.getIconList();
that.rdata(0);
sopenFrame = setInterval(function () {
if (app.globalData.IFRefreshindex == 1) {
app.globalData.IFRefreshindex = 0;
that.clearCache();
that.rdata(0);
}
}, 1000);
sopenFrame0 = setInterval(function () {
//if(that.data.authorizeHidden==true&&that.data.authorizeHidden0==true){
that.setData({
Start: 0
});
var userId = wx.getStorageSync("userId")
var LoginId = wx.getStorageSync("LoginId")
if (userId && LoginId) {
that.rdata0();
app.globalData.IFRefreshmy = 1;
app.globalData.IFRefreshshop = 1;
app.globalData.IFRefreshordershop0 = 1;
}
}, 10000);
sopenFrame1 = setInterval(function () {
that.rdata1();
}, 3000);
},
onPullDownRefresh: function () {
//在当前页面显示导航条加载动画
wx.showNavigationBarLoading();
//显示 loading 提示框。需主动调用 wx.hideLoading 才能关闭提示框
wx.showLoading({
title: '刷新中...',
})
that.clearCache();
that.setData({
loadingHidden: true
});
ifshowhongbao = 0;
if (that.data.currentTab == 0) {
wx.removeStorageSync('selcityid')
wx.removeStorageSync('selcountyid')
wx.removeStorageSync('dlMemberId')
that.rdata(1);
} else {
that.setData({
products: []
})
that.getlist(1);
}
},
// 页面上拉触底事件(上拉加载更多)
onReachBottom: function () {
/*if (that.data.currentTab >0) {
that.setData({
loadingHidden:false
});
that.getlist(2);//后台获取新数据并追加渲染
}*/
},
// 清缓存
clearCache: function () {
that.setData({
Start: 0,
loadingHidden: false
});
}, // 左右滚动tab标题切换标签
switchTab: function (e) {
let current = e.currentTarget.dataset.current;
this.setData({
currentTab: current
});
//每个tab选项宽度占1/5
var singleNavWidth = 100;
//tab选项居中
that.setData({
scrollLeft: (current) * singleNavWidth
})
this.rdata(0);
},
switchNav(event) {
var cur = event.currentTarget.dataset.current;
//每个tab选项宽度占1/5
var singleNavWidth = that.data.TabwindowWidth;
//tab选项居中
that.setData({
navScrollLeft: (cur - 2) * singleNavWidth
})
if (that.data.currentTab == cur) {
return false;
} else {
that.setData({
currentTab: cur
})
}
if (that.data.currentTab <= 1) {
that.setData({
menu_ico0: false
})
if (that.data.currentTab < 0) {
that.setData({
currentTab: 0
})
}
} else {
that.setData({
menu_ico0: true
})
}
if (that.data.currentTab >= that.data.navData.length - 2) {
that.setData({
menu_ico1: false
})
if (that.data.currentTab > that.data.navData.length - 1) {
that.setData({
currentTab: that.data.navData.length - 1
})
}
} else {
that.setData({
menu_ico1: true
})
}
if (that.data.currentTab == 0) {
} else {
that.clearCache();
that.setData({
products: []
})
that.setData({
categoryid: that.data.navData[that.data.currentTab].id
})
that.getlist(0);
}
},
rdata: function (t) {
updateing = 0
try {
var userId = wx.getStorageSync("userId")
var LoginId = wx.getStorageSync("LoginId")
wx.request({
url: app.globalData.apiurl + "/xapiajax.ashx",
data: {
action: "getindexdata",
userId: (!userId ? "" : userId),
LoginId: (!LoginId ? "" : LoginId),
categoryid: (that.data.navData.length > 0 ? that.data.navData[that.data.currentTab].id : "")
},
method: "GET",
dataType: "json",
header: {
"content-type": "application/json" // 默认值
},
success(res) {
if (res.data.status == 1) {
var showbody = ""
var indexdata = wx.getStorageSync('indexdata3')
if (indexdata) {
showbody = JSON.parse(indexdata).showbody;
}
if (showbody != res.data.showbody && res.data.showbody != "") {
var body = res.data.showbody;
WxParse.wxParse('body', 'html', body, that);
that.setData({
showtitle: res.data.showtitle,
closenoticeHidden: false,
})
}
wx.setStorageSync('indexdata3', JSON.stringify(res.data))
that.setData({
images: res.data.pic,
//images0: res.data.pic0,
navData: res.data.pic1,
news: res.data.news,
products: res.data.products,
products0: res.data.products1,
IFCS: res.data.IFCS,
loadingHidden: true
})
if (res.data.dlMemberId != "" && res.data.dlMemberId != "0") {
wx.setStorageSync('dlMemberId', res.data.dlMemberId);
}
wx.setStorageSync('servermsg', res.data.servermsg)
if (userId && LoginId) {
wx.setStorageSync('userInfo', JSON.stringify(res.data.userInfo))
/*if(res.data.userInfo.HBID>0){
if(ifshowhongbao==0){
ifshowhongbao=1;
that.setData({
kaihongbaoHidden:false
})
}
}else{
that.setData({
kaihongbaoHidden:true
})
} */
}
app.globalData.IFRefreshmy = 1
app.globalData.IFRefreshshangquan = 1
} else {
wx.showToast({
title: res.data.msg,
icon: "none",
duration: 20000
})
if (res.data.msg == "您未登录" || res.data.msg == "参数错误") {
wx.removeStorageSync('userId')
wx.removeStorageSync('LoginId')
that.rdata(0)
}
}
if (t == 1) {
//隐藏loading 提示框
wx.hideLoading();
//隐藏导航条加载动画
wx.hideNavigationBarLoading();
//停止下拉刷新
wx.stopPullDownRefresh();
}
}
})
} catch (err) {
wx.showToast({
title: err,
icon: "none",
duration: 2000
})
}
},
getlist: function (gp) {
var userId = wx.getStorageSync("userId")
var LoginId = wx.getStorageSync("LoginId")
var selcityid = wx.getStorageSync("selcityid")
var selcountyid = wx.getStorageSync("selcountyid")
var dlMemberId = wx.getStorageSync("dlMemberId")
wx.request({
url: app.globalData.apiurl + "/xapiajax.ashx",
data: {
action: "getwxshoplist",
userId: (!userId ? "" : userId),
LoginId: (!LoginId ? "" : LoginId),
selcityid: (!selcityid ? "" : selcityid),
selcountyid: (!selcountyid ? "" : selcountyid),
dlMemberId: (!dlMemberId ? "" : dlMemberId),
categoryid: that.data.categoryid,
keyword: that.data.keyword,
Start: that.data.Start
},
method: "GET",
dataType: "json",
header: {
"content-type": "application/json" // 默认值
},
success(res) {
if (res.data.status == 1) {
var tmpArr = null;
if (gp == 2) {
tmpArr = that.data.products;
tmpArr.push.apply(tmpArr, res.data.productlist);
} else {
tmpArr = res.data.productlist;
}
that.setData({
products: tmpArr,
Start: that.data.Start + res.data.productlist.length,
loadingHidden: true
})
if (gp == 0 || gp == 1) {
if (res.data.productlist.length == 0) {
that.setData({
nodataHidden: false
})
}
}
} else {
if (res.data.msg == "您未登录") {
wx.removeStorageSync('userId')
wx.removeStorageSync('LoginId')
}
}
if (gp == 1) {
//隐藏loading 提示框
wx.hideLoading();
//隐藏导航条加载动画
wx.hideNavigationBarLoading();
//停止下拉刷新
wx.stopPullDownRefresh();
}
}
})
},
gblen: function () {
var len = 0;
for (var i = 0; i < this.length; i++) {
if (this.charCodeAt(i) > 127 || this.charCodeAt(i) == 94) {
len += 2;
} else {
len++;
}
}
return len;
},
rdata0: function () {
var userId = wx.getStorageSync("userId")
var LoginId = wx.getStorageSync("LoginId")
wx.request({
url: app.globalData.apiurl + "/xapiajax.ashx",
data: {
action: "getmydata",
userId: (!userId ? "" : userId),
LoginId: (!LoginId ? "" : LoginId)
},
method: "GET",
dataType: "json",
header: {
"content-type": "application/json" // 默认值
},
success(res) {
if (res.data.status == 1) {
wx.setStorageSync('userInfo', JSON.stringify(res.data.userInfo))
app.globalData.IFRefreshmy = 1;
/*if(res.data.userInfo.HBID>0){
if(ifshowhongbao==0){
ifshowhongbao=1;
that.setData({
kaihongbaoHidden:false
})
}
}else{
that.setData({
kaihongbaoHidden:true
})
if(res.data.userInfo.IFqd==0&&ifqd==0){
ifqd=1
wx.showModal({
title: '签到提示',
content: '您今日未签到,是否要去签到?',
success (res0) {
if (res0.confirm) {
wx.navigateTo({
url: "../qiandao/index"
})
}
}
})
}
}*/
} else {
if (res.data.msg == "您未登录") {
wx.removeStorageSync('userId')
wx.removeStorageSync('LoginId')
}
}
if (res.data.CloseEnable == "1") {
wx.removeStorageSync('userId')
wx.removeStorageSync('LoginId')
}
}
});
},
rdata1: function () {
var userId = wx.getStorageSync("userId")
var LoginId = wx.getStorageSync("LoginId")
var userInfodata = wx.getStorageSync("userInfo")
if (userId && LoginId && userInfodata) {
var userdata = JSON.parse(userInfodata)
if (userdata.Paypush == 1 && ifPaypush == 0 && ifplay == 0) {
ifPaypush = 1;
wx.request({
url: app.globalData.apiurl + "/xapiajax.ashx",
data: {
action: "getPaypushdata0",
userId: (!userId ? "" : userId),
LoginId: (!LoginId ? "" : LoginId),
},
method: "GET",
dataType: "json",
header: {
"content-type": "application/json" // 默认值
},
success(res) {
if (res.data.status == 1) {
for (var i = 0; i < res.data.data.length; i++)
{
}
if (res.data.data.length > 0) {
ifplay = 1;
mp3data = res.data.data;
mp3index = 0;
that.playmp3();
}
ifPaypush = 0;
}
else {
if (res.data.msg == "您未登录") {
wx.removeStorageSync('userId')
wx.removeStorageSync('LoginId')
}
}
}
});
}
}
},
playmp3: function () {
try {
var path = mp3data[mp3index].mp3;
let innerAudioContext = wx.createInnerAudioContext()
// 设置音频资源
innerAudioContext.src = path
innerAudioContext.obeyMuteSwitch = true;
innerAudioContext.onEnded(res => { //监听停止事件
if (mp3index < mp3data.length) {
innerAudioContext.destroy();
if (mp3index < mp3data.length - 1) {
mp3index += 1;
that.playmp3();
} else {
ifplay = 0;
}
}
})
innerAudioContext.onError(res => {
})
innerAudioContext.play();
} catch (err) {
wx.showToast({
title: err,
icon: "none",
duration: 8000
})
}
},
scrolltxt: function () {
var d = that.data;
clearInterval(interval);
interval = setInterval(function () {
var next = d.marquee - 1; //每次移动距离
if (next < 0 && Math.abs(next) > d.maxScroll) {
next = d.windowWidth;
clearInterval(interval);
that.scrolltxt();
}
that.setData({
marquee: next
});
}, 40);
},
kaihongbao: function () {
var userId = wx.getStorageSync("userId")
var LoginId = wx.getStorageSync("LoginId")
var userInfodata = wx.getStorageSync("userInfo")
if (userId && LoginId && userInfodata) {
var userInfo = JSON.parse(userInfodata)
if (that.data.loadingHidden) {
that.setData({
loadingHidden: false
})
wx.request({
url: app.globalData.apiurl + "/xapiajax.ashx",
data: {
action: "IFZJLQHongBao",
userId: (userId == null ? "" : userId),
LoginId: (LoginId == null ? "" : LoginId),
id: userInfo.HBID
},
method: "POST",
dataType: "json",
header: {
"content-type": "application/x-www-form-urlencoded" // 默认值
},
success(res0) {
if (res0.data.status == 1) {
if (res0.data.LQType == 1) {
wx.navigateTo({
url: "../myhongbaodetails/index?id=" + userInfo.HBID
})
} else {
wx.setStorageSync('hongbaoid', userInfo.HBID);
wx.navigateTo({
url: "../myvideo/index"
})
}
} else {
wx.showToast({
title: res.data.msg,
icon: "none",
duration: 3000
})
}
that.setData({
loadingHidden: true,
kaihongbaoHidden: true
})
}
});
}
} else {
wx.navigateTo({
url: "../login/index"
})
}
},
setRemainTimeto: function () {
var Products0 = that.data.Products0;
var Products1 = that.data.Products1;
for (var i = 0; i < Products0.length; i++) {
var times = Products0[i].times;
if (times != "" && times != "未开始" && times != "进行中" && times != "已结束") {
var SysSecond = parseInt(times);
if (SysSecond > 0) {
SysSecond = SysSecond - 1;
var second = Math.floor(SysSecond % 60).toString();
var minite = Math.floor((SysSecond / 60) % 60).toString();
var hour = Math.floor((SysSecond / 3600) % 24).toString();
var day = Math.floor((SysSecond / (3600 * 24))).toString();
var timesto = "";
if (day > 0) {
timesto = day + "天 ";
}
if (hour > 0) {
timesto += hour + "时 ";
}
if (minite > 0) {
timesto += minite + "分 ";
}
if (second > 0) {
timesto += second + "秒 ";
}
Products0[i].times = SysSecond;
Products0[i].timesto = timesto;
Products0[i].ifqg = false;
} else {
Products0[i].ifqg = true;
}
} else {
Products0[i].timesto = Products0[i].times;
if (Products0[i].times == "进行中") {
Products0[i].ifqg = true;
} else {
Products0[i].ifqg = false;
}
}
}
for (var i = 0; i < Products1.length; i++) {
var times = Products1[i].times;
if (times != "" && times != "未开始" && times != "进行中" && times != "已结束") {
var SysSecond = parseInt(times);
if (SysSecond > 0) {
SysSecond = SysSecond - 1;
var second = Math.floor(SysSecond % 60).toString();
var minite = Math.floor((SysSecond / 60) % 60).toString();
var hour = Math.floor((SysSecond / 3600) % 24).toString();
var day = Math.floor((SysSecond / (3600 * 24))).toString();
var timesto = "";
if (day > 0) {
timesto = day + "天 ";
}
if (hour > 0) {
timesto += hour + "时 ";
}
if (minite > 0) {
timesto += minite + "分 ";
}
if (second > 0) {
timesto += second + "秒 ";
}
Products1[i].times = SysSecond;
Products1[i].timesto = timesto;
Products1[i].ifqg = false;
} else {
Products1[i].ifqg = true;
}
} else {
Products1[i].timesto = Products1[i].times;
if (Products1[i].times == "进行中") {
Products1[i].ifqg = true;
} else {
Products1[i].ifqg = false;
}
}
}
that.setData({
Products0: Products0,
Products1: Products1,
})
},
gotodetail: function (e) {
var id = e.currentTarget.dataset.id
wx.navigateTo({
url: "../details/index?id=" + id
})
},
gotoPointDetail: function (e) {
var id = e.currentTarget.dataset.id
wx.navigateTo({
url: "../detailsPoint/index?id=" + id
})
},
onauthorize: function () {
wx.getSetting({
success(ress) {
if (!ress.authSetting['scope.userInfo']) {
wx.authorize({
scope: 'scope.userInfo',
success() {
that.getUserInfoto(1)
},
fail() {},
complete() {
that.getUserInfoto(1)
}
})
} else {
that.getUserInfoto(1)
}
}
})
},
getPhoneNumber: function (e) {
if (e.detail.errMsg == "getPhoneNumber:ok") {
that.setData({
onauthorizetitle0: "获取中..."
})
var userId = wx.getStorageSync("userId")
var LoginId = wx.getStorageSync("LoginId")
if (updateing == 0) {
updateing = 1
wx.request({
url: app.globalData.apiurl + "/xapiajax.ashx",
data: {
action: "getwxphone",
encryptedData: e.detail.encryptedData,
iv: e.detail.iv,
userId: (!userId ? "" : userId),
LoginId: (!LoginId ? "" : LoginId)
},
method: "POST",
dataType: "json",
header: {
"content-type": "application/x-www-form-urlencoded" // 默认值
},
success: function (res2) {
updateing = 0
wx.showToast({
title: "获取成功",
icon: "success",
duration: 2000
})
that.setData({
phone: res2.data.Phone,
onauthorizetitle0: "获取微信手机号"
})
}
})
}
}
},
getUserInfoto: function (t) {
that.setData({
onauthorizetitle: "授权中..."
})
wx.getUserInfo({
success: function (res1) {
var userInfo = res1.userInfo
var nickName = userInfo.nickName
var avatarUrl = userInfo.avatarUrl
var gender = userInfo.gender //性别 0未知、1男、2
var province = userInfo.province
var city = userInfo.city
var country = userInfo.country
var userId = wx.getStorageSync("userId")
var LoginId = wx.getStorageSync("LoginId")
if (updateing2 == 0) {
updateing2 = 1
wx.request({
url: app.globalData.apiurl + "/xapiajax.ashx",
data: {
action: "updateWxUserInfo",
userId: (!userId ? "" : userId),
LoginId: (!LoginId ? "" : LoginId),
ncname: nickName,
avatar: avatarUrl,
gender: gender,
province: province,
city: city,
country: country
},
method: "POST",
dataType: "json",
header: {
"content-type": "application/x-www-form-urlencoded" // 默认值
},
success(res2) {
updateing2 = 0
if (res2.data.status == 1) {
wx.setStorageSync('userInfo', JSON.stringify(res2.data.userInfo))
app.globalData.IFRefreshmy = 1
if (t == 1) {
wx.showToast({
title: "授权成功",
icon: "success",
duration: 3000
})
}
that.setData({
authorizeHidden: true,
onauthorizetitle: "确认授权"
})
} else {
if (t == 1) {
wx.showToast({
title: res2.data.msg,
icon: "success",
duration: 3000
})
}
}
}
})
}
}
})
},
getUserProfile: function (e) {
that.setData({
onauthorizetitle: "授权中..."
})
wx.getUserProfile({
desc: '用于完善会员资料',
success: (res1) => {
var userInfo = res1.userInfo
var nickName = userInfo.nickName
var avatarUrl = userInfo.avatarUrl
var gender = userInfo.gender //性别 0未知、1男、2
var province = userInfo.province
var city = userInfo.city
var country = userInfo.country
var userId = wx.getStorageSync("userId")
var LoginId = wx.getStorageSync("LoginId")
if (updateing2 == 0) {
updateing2 = 1
wx.request({
url: app.globalData.apiurl + "/xapiajax.ashx",
data: {
action: "updateWxUserInfo",
userId: (!userId ? "" : userId),
LoginId: (!LoginId ? "" : LoginId),
ncname: nickName,
avatar: avatarUrl,
gender: gender,
province: province,
city: city,
country: country
},
method: "POST",
dataType: "json",
header: {
"content-type": "application/x-www-form-urlencoded" // 默认值
},
success(res2) {
updateing2 = 0
if (res2.data.status == 1) {
wx.setStorageSync('userInfo', JSON.stringify(res2.data.userInfo))
app.globalData.IFRefreshmy = 1
wx.showToast({
title: "授权成功",
icon: "success",
duration: 3000
})
that.setData({
authorizeHidden: true,
onauthorizetitle: "确认授权"
})
} else {
wx.showToast({
title: res2.data.msg,
icon: "success",
duration: 3000
})
}
}
})
}
}
})
},
closeauth: function (e) {
that.setData({
authorizeHidden: true
})
updateing = 0
},
closeauth0: function (e) {
that.setData({
authorizeHidden0: true
})
updateing = 0
},
inauth: function (e) {
},
closeflash: function (e) {
that.setData({
flashhidden: false
})
updateing = 0
},
onslide: function (e) {
var url = e.currentTarget.dataset.id
var sopenFrame = setInterval(function () {
that.setData({
flashhidden: true
})
}, 1000);
wx.navigateTo({
url: url
})
},
onflash: function (e) {
var url = e.currentTarget.dataset.id
var sflash = setInterval(function () {
that.setData({
flashhidden: true
})
clearInterval(sflash)
}, 1000);
wx.navigateTo({
url: url
})
},
onshop: function (e) {
var id = e.currentTarget.dataset.id
wx.navigateTo({
url: "../othershop/index?t=" + id
})
},
onmenu: function (e) {
var index = e.currentTarget.dataset.index;
for (var i = 0; i < that.data.groups.length; i++) {
if (i == index) {
that.data.groups[i].selected = 1;
} else {
that.data.groups[i].selected = 0;
}
}
that.setData({
groups: that.data.groups
})
},
onCategory: function (e) {
var id = e.currentTarget.dataset.id
if (id.indexOf("分类") != -1) {
wx.navigateTo({
url: "../classify/index"
})
} else if (id.indexOf("复购") != -1) {
var userId = wx.getStorageSync("userId")
var LoginId = wx.getStorageSync("LoginId")
var userInfodata = wx.getStorageSync("userInfo")
if (userId && LoginId && userInfodata) {
wx.navigateTo({
url: "../fugou/index"
})
} else {
wx.navigateTo({
url: "../login/index"
})
}
} else if (id.indexOf("资讯") != -1) {
wx.navigateTo({
url: "../news/index"
})
} else if (id.indexOf("邀请好友") != -1) {
var userId = wx.getStorageSync("userId")
var LoginId = wx.getStorageSync("LoginId")
var userInfodata = wx.getStorageSync("userInfo")
if (userId && LoginId && userInfodata) {
wx.navigateTo({
url: "../mytgm/index"
})
} else {
wx.navigateTo({
url: "../login/index"
})
}
} else if (id.indexOf("企业介绍") != -1) {
let that = this
var userId = wx.getStorageSync("userId")
var LoginId = wx.getStorageSync("LoginId")
var userInfodata = wx.getStorageSync("userInfo")
if (userId && LoginId && userInfodata) {
wx.request({
url: app.globalData.apiurl + "/api/api.ashx?action=index_about_id",
data: {},
method: "POST",
dataType: "json",
header: {
"content-type": "application/x-www-form-urlencoded"
},
success(res) {
if (res.data.status == 1) {
wx.navigateTo({
url: "../articledetail/index?id="+res.data.about_id
})
}
else
{
wx.showToast({
title: res.data.msg,
icon: "none",
duration: 3000
})
}
}
})
}
else {
wx.navigateTo({
url: "../login/index"
})
}
} else if (id.indexOf("体验区") != -1) {
var userId = wx.getStorageSync("userId")
var LoginId = wx.getStorageSync("LoginId")
var userInfodata = wx.getStorageSync("userInfo")
if (userId && LoginId && userInfodata) {
wx.navigateTo({
url: "../othershop0/index?t=13"
})
} else {
wx.navigateTo({
url: "../login/index"
})
}
} else if (id.indexOf("会客厅") != -1) {
var userId = wx.getStorageSync("userId")
var LoginId = wx.getStorageSync("LoginId")
var userInfodata = wx.getStorageSync("userInfo")
if (userId && LoginId && userInfodata) {
var userdata = JSON.parse(userInfodata)
if (userdata.dluLevel > 1) {
wx.navigateTo({
url: "../othershop0/index?t=4"
})
} else {
wx.showToast({
title: "未达到代理级别",
icon: "none",
duration: 3000
})
}
} else {
wx.navigateTo({
url: "../login/index"
})
}
} else if (id.indexOf("操作教程") != -1) {
var userId = wx.getStorageSync("userId")
var LoginId = wx.getStorageSync("LoginId")
var userInfodata = wx.getStorageSync("userInfo")
if (userId && LoginId && userInfodata) {
wx.navigateTo({
url: "../xsxt/index?t=11"
})
} else {
wx.navigateTo({
url: "../login/index"
})
}
} else if (id.indexOf("发图素材") != -1) {
var userId = wx.getStorageSync("userId")
var LoginId = wx.getStorageSync("LoginId")
var userInfodata = wx.getStorageSync("userInfo")
if (userId && LoginId && userInfodata) {
wx.navigateTo({
url: "../articles/index?t=0"
})
} else {
wx.navigateTo({
url: "../login/index"
})
}
} else if (id.indexOf("健康知识") != -1) {
var userId = wx.getStorageSync("userId")
var LoginId = wx.getStorageSync("LoginId")
var userInfodata = wx.getStorageSync("userInfo")
if (userId && LoginId && userInfodata) {
wx.navigateTo({
url: "../articles/index?t=1"
})
} else {
wx.navigateTo({
url: "../login/index"
})
}
} else if (id.indexOf("客服专区") != -1) {
var userId = wx.getStorageSync("userId")
var LoginId = wx.getStorageSync("LoginId")
var userInfodata = wx.getStorageSync("userInfo")
if (userId && LoginId && userInfodata) {
wx.navigateTo({
url: "../mykf/index"
})
} else {
wx.navigateTo({
url: "../login/index"
})
}
} else if (id.indexOf("品牌展示") != -1) {
var userId = wx.getStorageSync("userId")
var LoginId = wx.getStorageSync("LoginId")
var userInfodata = wx.getStorageSync("userInfo")
if (userId && LoginId && userInfodata) {
wx.navigateTo({
url: "../othershop0/index?t=7"
})
} else {
wx.navigateTo({
url: "../login/index"
})
}
} else if (id.indexOf("客服中心") != -1) {
var userId = wx.getStorageSync("userId")
var LoginId = wx.getStorageSync("LoginId")
var userInfodata = wx.getStorageSync("userInfo")
if (userId && LoginId && userInfodata) {
wx.navigateTo({
url: "../mykf/index"
})
}
} else if (id.indexOf("资讯") != -1) {
wx.navigateTo({
url: "../news/index"
})
} else if (id.indexOf("订单") != -1) {
var userId = wx.getStorageSync("userId")
var LoginId = wx.getStorageSync("LoginId")
var userInfodata = wx.getStorageSync("userInfo")
if (userId && LoginId && userInfodata) {
wx.navigateTo({
url: "../myorder/index"
})
} else {
wx.navigateTo({
url: "../login/index"
})
}
} else if (id.indexOf("健康知识") != -1) {
wx.navigateTo({
url: "../othershop0/index?t=2"
})
} else if (id.indexOf("创客区") != -1) {
wx.navigateTo({
url: "../othershop0/index?t=4"
})
} else if (id.indexOf("流量专区") != -1) {
wx.navigateTo({
url: "../othershop0/index?t=5"
})
} else if (id.indexOf("凯旋岁月") != -1) {
wx.navigateTo({
url: "../othershop00/index?t=9"
})
} else if (id.indexOf("签到") != -1) {
var userId = wx.getStorageSync("userId")
var LoginId = wx.getStorageSync("LoginId")
var userInfodata = wx.getStorageSync("userInfo")
if (userId && LoginId && userInfodata) {
wx.showToast({
title: "正在开发中...",
icon: "none",
duration: 3000
})
/*wx.navigateTo({
url: "../qiandao/index"
})*/
} else {
wx.navigateTo({
url: "../login/index"
})
}
} else if (id.indexOf("购物车") != -1) {
wx.navigateTo({
url: "../cart/index"
})
} else {
wx.navigateTo({
url: "../list/index?id=" + id
})
}
},
onCategory0: function (e) {
var index = e.currentTarget.dataset.index;
that.setData({
item_index: index
})
},
onnews: function (e) {
wx.navigateTo({
url: "../article/index"
})
},
onnotice: function (e) {
var id = e.currentTarget.dataset.id
if (id != 0) {
wx.navigateTo({
url: "../articledetail/index?id=" + id
})
}
},
onmianfeilingqu: function (e) {
var userId = wx.getStorageSync("userId")
var LoginId = wx.getStorageSync("LoginId")
var userInfodata = wx.getStorageSync("userInfo")
if (userId && LoginId && userInfodata) {
var userInfo = JSON.parse(userInfodata)
if (that.data.uLevel.indexOf("普通会员") == -1) {
if (userInfo.byordercount == 0) {
wx.navigateTo({
url: "../mianfeilingqu/index"
})
} else {
wx.showToast({
title: "每月只能领取一次",
icon: "none",
duration: 3000
})
}
} else {
wx.showToast({
title: "您需要升级才能参加免费领取",
icon: "none",
duration: 3000
})
}
} else {
wx.navigateTo({
url: "../login/index"
})
}
},
getcode0: function (e) {
var userId = wx.getStorageSync("userId")
var LoginId = wx.getStorageSync("LoginId")
var b = true
if (b) {
if (updateing == 0) {
updateing = 1
wx.request({
url: app.globalData.apiurl + "/xapiajax.ashx",
data: {
action: "sendphonecode2",
userId: (!userId ? "" : userId),
LoginId: (!LoginId ? "" : LoginId),
phone: that.data.phone
},
method: "POST",
dataType: "json",
header: {
"content-type": "application/x-www-form-urlencoded" // 默认值
},
success(res) {
updateing = 0
if (res.data.status == 1) {
wx.showToast({
title: res.data.msg,
icon: "success",
duration: 3000
})
that.gettime0()
} else {
wx.showToast({
title: res.data.msg,
icon: "none",
duration: 3000
})
}
}
})
}
}
},
gettime0: function () {
if (wait == 0) {
that.setData({
getcode0: "获取验证码"
})
wait = 120;
updateing = 0
} else {
that.setData({
getcode0: "重新发送(" + wait + ")"
})
wait--;
setTimeout(function () {
that.gettime0()
}, 1000)
}
},
inputphone: function (e) {
that.setData({
phone: e.detail.value
})
},
bindPhone: function (e) {
var phone = that.data.phone
var code = e.detail.value.code
var userId = wx.getStorageSync("userId")
var LoginId = wx.getStorageSync("LoginId")
var b = true
if (b) {
if (code == null || code == "") {
b = false
wx.showToast({
title: "手机验证码不能为空!",
icon: "none",
duration: 3000
})
}
}
if (b) {
if (updateing == 0) {
updateing = 1
that.setData({
savebutton0: "请稍候..."
})
wx.request({
url: app.globalData.apiurl + "/xapiajax.ashx",
data: {
action: "bindphone",
userId: (!userId ? "" : userId),
LoginId: (!LoginId ? "" : LoginId),
phone: phone,
code: code
},
method: "POST",
dataType: "json",
header: {
"content-type": "application/x-www-form-urlencoded" // 默认值
},
success(res) {
updateing = 0
wx.showToast({
title: res.data.msg,
icon: "none",
duration: 3000
})
if (res.data.status == 1) {
wx.showToast({
title: res.data.msg,
icon: "none",
duration: 3000
})
if (res.data.IFDL == 1) {
wx.removeStorageSync('userId')
wx.removeStorageSync('LoginId')
wx.removeStorageSync('userInfo')
app.globalData.IFLogin = 0
app.globalData.IFRefreshmy = 1
app.getUserInfo();
} else {
wx.setStorageSync('userInfo', JSON.stringify(res.data.userInfo))
}
that.setData({
authorizeHidden0: true
})
that.rdata(0)
} else {
wx.showToast({
title: res.data.msg,
icon: "none",
duration: 3000
})
}
that.setData({
savebutton0: "确认解绑"
})
}
})
}
}
},
getkeyword: function (e) {
that.setData({
keyword: e.detail.value
})
},
onshwowsearch: function (e) {
that.setData({
closesearch: false,
getfocus: true,
})
},
onclosesearch: function (e) {
that.setData({
closesearch: true
})
},
onsearch: function () {
var keyword = that.data.keyword.replace(/\s+/g, "");
if (keyword != "") {
wx.navigateTo({
url: "../list/index?keyword=" + keyword
})
} else {
wx.showToast({
title: "关键字不能为空",
icon: "none",
duration: 3000
})
}
},
onselection: function () {
wx.navigateTo({
url: "../selcity/index"
})
},
ontempm: function (e) {
var t = e.currentTarget.dataset.id;
that.setData({
tempmtype: t,
musers: (t == 0 ? that.data.pmusers : that.data.pmusers0)
})
},
onpd: function (e) {
var ids = e.currentTarget.dataset.id
wx.navigateTo({
url: "../details/index?" + ids
})
},
addcart: function (e) {
var t = e.currentTarget.dataset.id
addtype = parseInt(t);
that.showaddcart();
},
showaddcart: function () {
var userId = wx.getStorageSync("userId")
var LoginId = wx.getStorageSync("LoginId")
var userInfodata = wx.getStorageSync("userInfo")
var ifdl = true;
if (!userId || !LoginId) {
ifdl = false;
wx.navigateTo({
url: "../login/index"
})
} else {
var userInfo = JSON.parse(userInfodata);
if (userInfo.Phone == "" && userInfo.FHEnable4 == "0") {
ifdl = false;
wx.showToast({
title: "您还没有绑定手机号",
icon: "none",
duration: 2000
})
that.setData({
authorizeHidden0: false
})
} else {
if (that.data.ttype == 6 && addtype == 1) {
if (that.data.yydptgz == 0) {
ifdl = false;
that.setData({
ptgzHidden: false
})
}
}
}
}
if (ifdl) {
that.setData({
addcartHidden: false
})
that.getselguige();
}
},
closeaddcart: function (e) {
that.setData({
addcartHidden: true
})
},
closenotice: function (e) {
that.setData({
closenoticeHidden: true
})
},
inaddcart: function (e) {
},
viewimages: function (e) {
var showimages = that.data.showimages;
var imgList = new Array();
for (var i = 0; i < showimages.length; i++) {
imgList[i] = showimages[i].img;
}
wx.previewImage({
urls: imgList,
current: imgList[that.data.showindex]
})
},
viewimages0: function (e) {
var index = e.currentTarget.dataset.index;
var showimages = that.data.showimages;
var imgList = new Array();
for (var i = 0; i < showimages.length; i++) {
imgList[i] = showimages[i].img;
}
wx.previewImage({
urls: imgList,
current: imgList[index]
})
},
selcolor: function (e) {
var datavalue = e.currentTarget.dataset.id;
var selectedcolor = that.data.selguiges[that.data.currentindex].colors[datavalue].color
that.data.selguiges[that.data.currentindex].selectedcolor = selectedcolor;
var strimages = that.data.selguiges[that.data.currentindex].images;
var showimage = "";
var showindex = 0;
if (strimages != "") {
var aimages = strimages.split('|');
var strshowimages = "[";
for (var i = 0; i < aimages.length; i++) {
if (aimages[i] != "") {
var images = aimages[i].split(',');
var image0 = app.globalData.apiurl + "/GetFiles.ashx?image=" + images[0] + "&itsize=720x460&itmode=cut";
var image1 = app.globalData.apiurl + "/GetFiles.ashx?image=" + images[0] + "&itsize=150x150&itmode=cut";
if (strshowimages == "[") {
strshowimages += "{\"img\":\"" + image0 + "\",\"minimg\":\"" + image1 + "\",\"label\":\"\",\"yanse\":\"" + (images.length > 1 ? images[1] : "") + "\"}";
} else {
strshowimages += ",{\"img\":\"" + image0 + "\",\"minimg\":\"" + image1 + "\",\"label\":\"\",\"yanse\":\"" + (images.length > 1 ? images[1] : "") + "\"}";
}
}
}
strshowimages += "]";
var showimages = JSON.parse(strshowimages);
for (var j = 0; j < showimages.length; j++) {
if (showimages[j].yanse == selectedcolor) {
showimage = showimages[j].minimg;
showindex = j;
}
}
if (showimage == "") {
showimage = showimages[0].minimg;
showindex = 0;
}
that.setData({
showimage: showimage,
showimages: showimages,
showindex: showindex,
})
}
that.setData({
selguiges: that.data.selguiges,
colorHidden: true
})
that.getselguige();
},
increment: function (e) {
var index = e.currentTarget.dataset.id;
var kc = that.data.selguiges[index].kc
var num = that.data.selguiges[index].selectednum
var c = /^[0-9]*$/;
if (!c.test(num)) {
wx.showToast({
title: "输入的数量有误",
icon: "none",
duration: 2000
})
} else {
kc = parseInt(kc);
num = parseInt(num);
var b = num + 1;
if (b > kc) {
wx.showToast({
title: "库存不足",
icon: "none",
duration: 2000
})
b = num
}
if (that.data.ttype == 6 && addtype == 1) {
var aguige = that.data.selguiges;
var IFNum = 0;
for (var i = 0; i < aguige.length; i++) {
if (i != index) {
var num = parseInt(aguige[i].selectednum);
if (num > 0) {
IFNum += 1;
}
}
}
if (IFNum > 0) {
wx.showToast({
title: "拼单只能选择一种规格",
icon: "none",
duration: 2000
})
b = 0
}
if (b > 1) {
wx.showToast({
title: "拼单不能大于1",
icon: "none",
duration: 2000
})
b = 1
}
}
that.data.selguiges[index].selectednum = b;
that.setData({
selguiges: that.data.selguiges
})
if (that.data.selguiges[index].images != "") {
var aimages = that.data.selguiges[index].images.split('|');
var strshowimages = "[";
for (var i = 0; i < aimages.length; i++) {
if (aimages[i] != "") {
var images = aimages[i].split(',');
var image0 = app.globalData.apiurl + "/GetFiles.ashx?image=" + images[0] + "&itsize=720x460&itmode=cut";
var image1 = app.globalData.apiurl + "/GetFiles.ashx?image=" + images[0] + "&itsize=150x150&itmode=cut";
if (strshowimages == "[") {
strshowimages += "{\"img\":\"" + image0 + "\",\"minimg\":\"" + image1 + "\",\"label\":\"\",\"yanse\":\"" + (images.length > 1 ? images[1] : "") + "\"}";
} else {
strshowimages += ",{\"img\":\"" + image0 + "\",\"minimg\":\"" + image1 + "\",\"label\":\"\",\"yanse\":\"" + (images.length > 1 ? images[1] : "") + "\"}";
}
}
}
strshowimages += "]";
var showimages = JSON.parse(strshowimages);
var strimages = showimages[0].minimg;
that.setData({
showimage: strimages,
showindex: 0,
showimages: showimages
})
}
}
that.getselguige();
},
inputOnlyNum: function (e) {
var num = e.detail.value;
var index = e.currentTarget.dataset.id;
var kc = that.data.selguiges[index].kc
var c = /^[0-9]*$/;
if (!c.test(num)) {
wx.showToast({
title: "输入的数量有误",
icon: "none",
duration: 2000
})
} else {
kc = parseInt(kc);
num = parseInt(num);
var b = num;
if (that.data.ttype == 6 && addtype == 1) {
var aguige = that.data.selguiges;
var IFNum = 0;
for (var i = 0; i < aguige.length; i++) {
if (i != index) {
var num = parseInt(aguige[i].selectednum);
if (num > 0) {
IFNum += 1;
}
}
}
if (IFNum > 0) {
wx.showToast({
title: "拼单只能选择一种规格",
icon: "none",
duration: 2000
})
b = 0
}
if (b > 1) {
wx.showToast({
title: "拼单不能大于0",
icon: "none",
duration: 2000
})
b = 1
}
}
if (b > kc) {
wx.showToast({
title: "库存不足",
icon: "none",
duration: 2000
})
b = num
}
if (b < 0) {
wx.showToast({
title: "不能小于0",
icon: "none",
duration: 2000
})
b = num
}
that.data.selguiges[index].selectednum = b;
that.setData({
selguiges: that.data.selguiges
})
if (b > 0) {
if (that.data.selguiges[index].images != "") {
var aimages = that.data.selguiges[index].images.split('|');
var strshowimages = "[";
for (var i = 0; i < aimages.length; i++) {
if (aimages[i] != "") {
var images = aimages[i].split(',');
var image0 = app.globalData.apiurl + "/GetFiles.ashx?image=" + images[0] + "&itsize=720x460&itmode=cut";
var image1 = app.globalData.apiurl + "/GetFiles.ashx?image=" + images[0] + "&itsize=150x150&itmode=cut";
if (strshowimages == "[") {
strshowimages += "{\"img\":\"" + image0 + "\",\"minimg\":\"" + image1 + "\",\"label\":\"\",\"yanse\":\"" + (images.length > 1 ? images[1] : "") + "\"}";
} else {
strshowimages += ",{\"img\":\"" + image0 + "\",\"minimg\":\"" + image1 + "\",\"label\":\"\",\"yanse\":\"" + (images.length > 1 ? images[1] : "") + "\"}";
}
}
}
strshowimages += "]";
var showimages = JSON.parse(strshowimages);
var strimages = showimages[0].minimg;
that.setData({
showimage: strimages,
showindex: 0,
showimages: showimages
})
}
} else {
var strimages = "";
var showimages = [];
var aguige = that.data.selguiges;
for (var i = 0; i < aguige.length; i++) {
var num = parseInt(aguige[i].selectednum);
if (num > 0) {
var aimages = that.data.selguiges[index].images.split('|');
var strshowimages = "[";
for (var i = 0; i < aimages.length; i++) {
if (aimages[i] != "") {
var images = aimages[i].split(',');
var image0 = app.globalData.apiurl + "/GetFiles.ashx?image=" + images[0] + "&itsize=720x460&itmode=cut";
var image1 = app.globalData.apiurl + "/GetFiles.ashx?image=" + images[0] + "&itsize=150x150&itmode=cut";
if (strshowimages == "[") {
strshowimages += "{\"img\":\"" + image0 + "\",\"minimg\":\"" + image1 + "\",\"label\":\"\",\"yanse\":\"" + (images.length > 1 ? images[1] : "") + "\"}";
} else {
strshowimages += ",{\"img\":\"" + image0 + "\",\"minimg\":\"" + image1 + "\",\"label\":\"\",\"yanse\":\"" + (images.length > 1 ? images[1] : "") + "\"}";
}
}
}
strshowimages += "]";
showimages = JSON.parse(strshowimages);
strimages = showimages[0].minimg;
}
}
if (strimages == "") {
showimages = that.data.goodsPicsInfo;
strimages = showimages[0].minimg;
}
that.setData({
showimage: strimages,
showindex: 0,
showimages: showimages
})
}
}
that.getselguige();
},
decrement: function (e) {
var index = e.currentTarget.dataset.id;
var kc = that.data.selguiges[index].kc
var num = that.data.selguiges[index].selectednum
var c = /^[0-9]*$/;
if (!c.test(num)) {
wx.showToast({
title: "输入的数量有误",
icon: "none",
duration: 2000
})
} else {
kc = parseInt(kc);
num = parseInt(num);
var b = num - 1;
if (b < 0) {
wx.showToast({
title: "不能小于0",
icon: "none",
duration: 2000
})
b = num
}
that.data.selguiges[index].selectednum = b;
that.setData({
selguiges: that.data.selguiges
})
if (b > 0) {
if (that.data.selguiges[index].images != "") {
var aimages = that.data.selguiges[index].images.split('|');
var strshowimages = "[";
for (var i = 0; i < aimages.length; i++) {
if (aimages[i] != "") {
var images = aimages[i].split(',');
var image0 = app.globalData.apiurl + "/GetFiles.ashx?image=" + images[0] + "&itsize=720x460&itmode=cut";
var image1 = app.globalData.apiurl + "/GetFiles.ashx?image=" + images[0] + "&itsize=150x150&itmode=cut";
if (strshowimages == "[") {
strshowimages += "{\"img\":\"" + image0 + "\",\"minimg\":\"" + image1 + "\",\"label\":\"\",\"yanse\":\"" + (images.length > 1 ? images[1] : "") + "\"}";
} else {
strshowimages += ",{\"img\":\"" + image0 + "\",\"minimg\":\"" + image1 + "\",\"label\":\"\",\"yanse\":\"" + (images.length > 1 ? images[1] : "") + "\"}";
}
}
}
strshowimages += "]";
var showimages = JSON.parse(strshowimages);
var strimages = showimages[0].minimg;
that.setData({
showimage: strimages,
showindex: 0,
showimages: showimages
})
}
} else {
var strimages = "";
var showimages = [];
var aguige = that.data.selguiges;
for (var i = 0; i < aguige.length; i++) {
var num = parseInt(aguige[i].selectednum);
if (num > 0) {
var aimages = that.data.selguiges[index].images.split('|');
var strshowimages = "[";
for (var i = 0; i < aimages.length; i++) {
if (aimages[i] != "") {
var images = aimages[i].split(',');
var image0 = app.globalData.apiurl + "/GetFiles.ashx?image=" + images[0] + "&itsize=720x460&itmode=cut";
var image1 = app.globalData.apiurl + "/GetFiles.ashx?image=" + images[0] + "&itsize=150x150&itmode=cut";
if (strshowimages == "[") {
strshowimages += "{\"img\":\"" + image0 + "\",\"minimg\":\"" + image1 + "\",\"label\":\"\",\"yanse\":\"" + (images.length > 1 ? images[1] : "") + "\"}";
} else {
strshowimages += ",{\"img\":\"" + image0 + "\",\"minimg\":\"" + image1 + "\",\"label\":\"\",\"yanse\":\"" + (images.length > 1 ? images[1] : "") + "\"}";
}
}
}
strshowimages += "]";
showimages = JSON.parse(strshowimages);
strimages = showimages[0].minimg;
}
}
if (strimages == "") {
showimages = that.data.goodsPicsInfo;
strimages = showimages[0].minimg;
}
that.setData({
showimage: strimages,
showindex: 0,
showimages: showimages
})
}
}
that.getselguige();
},
getselguige: function (e) {
var guiges = ""
var aguige = that.data.selguiges;
for (var i = 0; i < aguige.length; i++) {
var color = aguige[i].selectedcolor;
var num = parseInt(aguige[i].selectednum);
if (num > 0) {
if (guiges == "") {
guiges = (aguige[i].gg + color + ":" + num);
} else {
guiges += ("\n" + aguige[i].gg + color + ":" + num);
}
}
}
if (guiges == "") {
that.data.selguige_font = "请选择:";
that.data.selguige_title = "规格或颜色";
} else {
that.data.selguige_font = "已选择:";
that.data.selguige_title = guiges;
}
that.setData({
selguige_font: that.data.selguige_font,
selguige_title: that.data.selguige_title
})
},
qyaddcart: function (e) {
var userId = wx.getStorageSync("userId")
var LoginId = wx.getStorageSync("LoginId")
var userInfodata = wx.getStorageSync("userInfo")
var bb = true;
if (!userId || !LoginId) {
ifdl = false;
wx.navigateTo({
url: "../login/index"
})
} else {
var userInfo = JSON.parse(userInfodata);
if (userInfo.Phone == "" && userInfo.FHEnable4 == "0") {
bb = false;
wx.showToast({
title: "您还没有绑定手机号",
icon: "none",
duration: 2000
})
that.setData({
authorizeHidden0: false
})
}
}
if (bb) {
var guiges = "";
var aguige = that.data.selguiges;
for (var i = 0; i < aguige.length; i++) {
var color = aguige[i].selectedcolor;
var num = parseInt(aguige[i].selectednum);
if (num > 0) {
if (aguige[i].colors.length > 0) {
if (color == "") {
wx.showToast({
title: aguige[i].gg + "的颜色必须选择",
icon: "none",
duration: 3000
})
bb = false;
}
}
if (bb) {
if (guiges == "") {
guiges = (aguige[i].id + "|" + color + "|" + num);
} else {
guiges += ("," + aguige[i].id + "|" + color + "|" + num);
}
}
}
}
}
if (bb) {
if (guiges == "") {
wx.showToast({
title: "请填写购买数量",
icon: "none",
duration: 3000
})
bb = false;
}
}
if (bb) {
if (that.data.qyaddcart == "请稍候...") {
wx.showToast({
title: "请不要重复点击",
icon: "none",
duration: 3000
})
bb = false;
}
}
if (bb) {
var userId = wx.getStorageSync("userId")
var LoginId = wx.getStorageSync("LoginId")
var CartId = wx.getStorageSync("CartId")
that.setData({
qyaddcart: "请稍候..."
})
wx.request({
url: app.globalData.apiurl + "/xapiajax.ashx",
data: {
action: "addcart",
userId: (!userId ? "" : userId),
LoginId: (!LoginId ? "" : LoginId),
CartId: (!CartId ? "" : CartId),
guiges: guiges,
at: addtype,
viewId: viewId
},
method: "POST",
dataType: "json",
header: {
"content-type": "application/x-www-form-urlencoded" // 默认值
},
success(res) {
that.setData({
qyaddcart: "确认"
})
if (res.data.status == 1) {
that.setData({
addcartHidden: true
})
wx.setStorageSync('CartId', res.data.CartId)
wx.navigateTo({
url: "../sell/index"
})
} else {
wx.showToast({
title: res.data.msg,
icon: "none",
duration: 2000
})
}
}
})
}
},
gotolb: function (e) {
var id = e.currentTarget.dataset.id
wx.navigateTo({
url: "../list/index?id=" + id
})
},
ondetail: function (e) {
var id = e.currentTarget.dataset.id
wx.navigateTo({
url: "../details/index?id=" + id
})
},
//获取首页icon状态列表
getIconList: function () {
wx.request({
url: app.globalData.apiurl + "/api/api.ashx?action=index_icon_list",
data: {},
method: "POST",
dataType: "json",
header: {
"content-type": "application/x-www-form-urlencoded"
},
success(res) {
if (res.data.status == 1) {
that.setData({
icon1: res.data.is_icon1,
icon2: res.data.is_icon2,
icon3: res.data.is_icon3,
icon4: res.data.is_icon4,
icon5: res.data.is_icon5
})
}
}
})
},
catchdetail: function (e) {
}
})