123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287 |
- // pages/goods-details/index.js
- var app = getApp()
- var WxParse = require('../../wxParse/wxParse.js')
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- hideShopPopup: true, //规格弹出框
- indicatorDors: true,
- autoplay: true,
- interval: 4000,
- duration: 500,
- goodsDetail:{}, //商品详情对象
- buyNumMax:0, //最大购买数量
- buyNumMin: 0, //最小购买数量
- buyNumber: 0, //单个购买数量
- shopNum: 0, //全部购买数量
- propertyChildIds: '',//规格属性id
- propertyChildNames: '',//规格属性名
- selectSizePrice: 0,//单个选择商品价格
- selectSize: '选择: ',//选择规格
- hasMoreSelect: false,//是否有多种规格可选
- shopCarInfo: {},//设置在缓存的订单信息
- canSubmit: false,//是否能添加到订单
- imgurl: app.data.resturl,
- comments: [],
- id:'',
- zanstatus: 'N',
- znum: 0
- },
- onLoad:function(options){
- this.setData({
- id:options.id
- })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onShow: function (options) {
- var that = this
- //加载缓存,取得订单信息
- wx.getStorage({
- key: 'shopCarInfo',
- success:function(res){
- // console.log(`initshopCarInfo:${res.data}`)
- that.setData({
- shopCarInfo: res.data,
- shopNum: res.data.shopNum
- })
- }
- })
- let id = this.data.id;
- let openid = app.globalData.openid;
- //请求该商品详细数据
- wx.request({
- url: app.data.resturl + '/ginfo.action',
- data: {
- id: id,
- openid:openid
- },
- success:function(res){
- // console.log(res.data.data)
- let selectSizeTemp = ''
- that.setData({
- goodsDetail: res.data.dinfo,
- znum: res.data.dinfo.zan,
- zanstatus: res.data.dinfo.praiseStatus,
- comments: res.data.dlist,
- buyNumber:1
- })
- WxParse.wxParse('article', 'html', res.data.dinfo.goodsMiaoshu, that, 5)
-
-
- }
- })
- },
- addShopCar: function() {
- if (this.data.goodsDetail.properties && !this.data.canSubmit){
- this.bindGuiGeTap()
- return
- }
- let shopCarMap = {}
- shopCarMap.goodsId = this.data.goodsDetail.goodsId;
- shopCarMap.pic = this.data.imgurl + this.data.goodsDetail.goodsPic;
- shopCarMap.name = this.data.goodsDetail.goodsName;
- shopCarMap.label = this.data.goodsDetail.goodsName;
-
- shopCarMap.price = this.data.goodsDetail.goodsShichangjia
- shopCarMap.left = ''
- shopCarMap.active = true
- shopCarMap.number = this.data.buyNumber
-
- var shopCarInfo = this.data.shopCarInfo
- if (!shopCarInfo.shopNum){
- shopCarInfo.shopNum = 0
- }
- if(!shopCarInfo.shoplist){
- shopCarInfo.shoplist= []
- }
- var hasSameGoodsIndex = -1
- for (var i = 0; i < shopCarInfo.shoplist.length;i++){
- var tamShopCarMap = shopCarInfo.shoplist[i]
- if (tamShopCarMap.goodsId === shopCarMap.goodsId){
- shopCarMap.number = shopCarMap.number + tamShopCarMap.number
- hasSameGoodsIndex = i
- break
- }
- }
- shopCarInfo.shopNum = shopCarInfo.shopNum + this.data.buyNumber
- if (hasSameGoodsIndex > -1) {
- shopCarInfo.shoplist.splice(hasSameGoodsIndex, 1, shopCarMap)
- } else{
- shopCarInfo.shoplist.push(shopCarMap)
- }
- this.setData({
- shopCarInfo: shopCarInfo,
- shopNum: shopCarInfo.shopNum
- })
- this.closePopupTap()
- // wx.showToast({
- // title: '加入购物车成功',
- // icon: 'sucess',
- // duration: 2000
- // })
- wx.setStorage({
- key: 'shopCarInfo',
- data: shopCarInfo
- })
- },
- bindGuiGeTap(){
- this.setData({
- hideShopPopup: false
- })
- },
- closePopupTap(){
- this.setData({
- hideShopPopup: true
- })
- },
- numJiaTap(){
- let buyNumber = this.data.buyNumber
- if (buyNumber < this.data.buyNumMax){
- buyNumber++
- }
- console.log(buyNumber)
- this.setData({
- buyNumber: buyNumber
- })
- },
- numJianTap() {
- let buyNumber = this.data.buyNumber
- if (buyNumber > this.data.buyNumMin) {
- buyNumber--
- }
- this.setData({
- buyNumber: buyNumber
- })
- },
-
- goShopCar() {
- wx.reLaunch({
- //url: '../shop-cart/index'
- url: '../to-pay-order/index'
- })
- },
- tobuy(){
- if (this.data.goodsDetail.properties && !this.data.canSumbit){
- this.bindGuiGeTap()
- return
- }
- if (this.data.buyNumber<1){
- wx.showModal({
- title: '提示',
- concent:'暂时缺货哦~',
- showCancel:fasle
- })
- return
- }
- this.addShopCar()
- this.goShopCar()
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- zan: function () {
- let openid = app.globalData.openid;
- if (openid == '') {
- wx.redirectTo({
- url: '../../pages/login/login',
- })
- return;
- }
- let id = this.data.goodsDetail.goodsId;
- let zstatus = this.data.zanstatus;
- let zcount = this.data.znum;
- let types = 1;
- if (zstatus == 'Y') {
- types = 2;
- }
- let param = "tcid=" + id + "&uid=" + openid + "&types=" + types;
- //console.log(param);
- let that = this;
- wx.request({
- url: app.data.resturl + '/praise.action',
- header: {
- 'content-type': 'application/x-www-form-urlencoded'
- },
- method: 'post',
- data: param,
- success: function (resp) {
- let rescode = resp.data.code;
- if (rescode == 200) {
- if (zstatus == 'N') {
- zstatus = 'Y';
- zcount = zcount + 1;
- } else {
- zstatus = 'N';
- zcount = zcount - 1;
- if (zcount < 0) { zcount = 0; }
- }
- that.setData({
- zanstatus: zstatus,
- znum: zcount
- });
- }
- }
- })
-
- },
-
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
-
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
-
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
-
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
-
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
-
- }
- })
|