goodsdetail.js 10.5 KB
var t = require("../../../utils/network.js"), a = [];

Page({
    data: {
        is_favour: 0,
        info: [],
        comments: [],
        index: 1,
        ouid: "",
        ids: "",
        id: "",
        num: 1,
        minusStatus: "disabled",
        attrValueList: [],
        selectName: "",
        selectAttrid: [],
        address: [],
        redshow: !1,
        iindex: 0
    },
    onSlideChangeEnd: function(t) {
        this.setData({
            index: t.detail.current + 1
        });
    },
    onLoad: function(t) {
        console.log(t), this.setData({
            id: t.id,
            selectName: ""
        });
        var a = this;
        a.getdetail(), wx.getStorage({
            key: "ouid",
            success: function(t) {
                console.log(t), a.setData({
                    ouid: t.data
                }), a.init_attr(), a.carts();
            }
        });
    },
    previewImage1: function(t) {
        var a = t.currentTarget.dataset.index, e = t.currentTarget.dataset.imgindex, s = this.data.comments[e].img;
        console.log(s.length), console.log(e), wx.previewImage({
            current: s[a],
            urls: s
        });
    },
    previewImage: function(t) {
        var a = t.currentTarget.dataset.index, e = this.data.info.photo;
        wx.previewImage({
            current: e[a],
            urls: e
        });
    },
    onReady: function() {},
    onShow: function() {
        var t = this;
        wx.getStorage({
            key: "ouid",
            success: function(a) {
                console.log(a), t.setData({
                    ouid: a.data
                }), t.setData({
                    selectName: "",
                    attrValueList: []
                }), t.init_attr(), t.getdetail(), t.carts();
            }
        });
    },
    onHide: function() {},
    getdetail: function() {
        var a = this;
        t.POST({
            url: "Index/detail_good",
            header: "application/x-www-form-urlencoded",
            params: {
                id: a.data.id
            },
            success: function(t) {
                if (console.log(t), "success" == t.data.state) {
                    a.setData({
                        comments: t.data.comments,
                        info: t.data.info,
                        attrValueList: t.data.info.standard,
                        is_favour: t.data.is_favour
                    });
                    for (var e = a.data.attrValueList, s = 0; s < e.length; s++) for (var i = 0; i < e[s].stval.length; i++) e[s].attrValueStatus ? e[s].attrValueStatus[i] = !1 : (e[s].attrValueStatus = [], 
                    e[s].attrValueStatus[i] = !1);
                    a.setData({
                        attrValueList: e
                    }), console.log(a.data.attrValueList);
                } else wx.showToast({
                    title: "暂无数据",
                    icon: "none",
                    image: "",
                    duration: 2e3
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    onUnload: function() {},
    onPullDownRefresh: function() {
        this.getdetail();
    },
    onReachBottom: function() {},
    onShareAppMessage: function() {
        this.data.info;
        var t = this.data.id;
        return {
            title: "礼寓Leemoral",
            desc: this.data.info.name,
            path: "/pages/index/goodsdetail/goodsdetail?id=" + t
        };
    },
    gotoindex: function() {
        wx.switchTab({
            url: "../index"
        });
    },
    collection: function() {
        var a = this;
        t.POST({
            url: "User/do_favor",
            header: "application/x-www-form-urlencoded",
            params: {
                ouid: a.data.ouid,
                id: a.data.id,
                is_favour: a.data.is_favour
            },
            success: function(t) {
                "success" == t.data.state && a.setData({
                    is_favour: t.data.is_favour
                }), wx.showToast({
                    title: t.data.msg,
                    duration: 2e3,
                    iocn: "success"
                });
            }
        });
    },
    shopping: function() {
        wx.switchTab({
            url: "../../cart/cart"
        });
    },
    tagChoose: function(t) {
        for (var e = t.currentTarget.dataset.selectIndex, s = t.currentTarget.dataset.attrIndex, i = this.data.attrValueList, o = i[e].stval.length, n = 0; n < o; n++) i[e].attrValueStatus[n] = !1;
        i[e].attrValueStatus[s] = !0;
        var d = i[e].stval[s], r = "";
        console.log(d), a[e] = d;
        for (var u = a.length, n = 0; n < u; n++) console.log(i[e].attrValueStatus[s]), 
        void 0 != a[n] && 1 == i[e].attrValueStatus[s] && (console.log(a[n]), r += a[n] + ", ");
        console.log("选择的" + r), r = r.substring(0, r.lastIndexOf(",")), this.setData({
            attrValueList: i,
            selectName: r
        });
    },
    bindMinus: function() {
        var t = this.data.num;
        t > 1 && t--;
        var a = t <= 1 ? "disabled" : "normal";
        this.setData({
            num: t,
            minusStatus: a
        });
    },
    bindPlus: function() {
        var t = this.data.num, a = ++t < 1 ? "disabled" : "normal";
        this.setData({
            num: t,
            minusStatus: a
        });
    },
    bindManual: function(t) {
        var a = t.detail.value;
        this.setData({
            num: a
        });
    },
    cars: function() {
        var t = this;
        console.log(t.data.attrValueList);
        var a = t.data.selectName.split(",");
        "" == t.data.selectName || a.length < t.data.attrValueList.length ? wx.showToast({
            title: "请选择商品规格",
            icon: "none",
            duration: 2e3
        }) : (t.add_car(), t.setData({
            redshow: !0
        }), wx.showToast({
            title: " 已加入购物车",
            duration: 2e3,
            icon: "none"
        }));
    },
    add_car: function() {
        var a = this, e = this.data.selectName.split(",");
        console.log(e), "" == this.data.selectName || e.length < this.data.attrValueList.length ? wx.showToast({
            title: "请选择商品规格",
            icon: "none",
            duration: 2e3
        }) : t.POST({
            url: "Pay/add_car",
            header: "application/x-www-form-urlencoded",
            params: {
                ouid: this.data.ouid,
                gid: this.data.id,
                standard: this.data.selectName,
                count: this.data.num
            },
            success: function(t) {
                if (t.data.state = "success") {
                    var e = t.data.id;
                    e && a.setData({
                        ids: e
                    });
                } else wx.showToast({
                    title: "请等待",
                    icon: "loding"
                });
            }
        });
    },
    add_carnow: function() {
        var a = this, e = this.data.selectName.split(",");
        "" == this.data.selectName || e.length < this.data.attrValueList.length ? wx.showToast({
            title: "请选择商品规格",
            icon: "none",
            duration: 2e3
        }) : t.POST({
            url: "Pay/add_carnow",
            header: "application/x-www-form-urlencoded",
            params: {
                ouid: this.data.ouid,
                gid: this.data.id,
                standard: this.data.selectName,
                count: this.data.num,
                
            },
            success: function(t) {
                if (t.data.state = "success") {
                    var e = t.data.id;
                    e && a.setData({
                        ids: e
                    });
                } else wx.showToast({
                    title: "请等待",
                    icon: "loding"
                });
            }
        });
    },
    morecomment: function() {
        var t = this.data.info.id;
        wx.navigateTo({
            url: "../discuss/discuss?id=" + t
        });
    },
    buy: function() {
        var t = this, a = this.data.selectName.split(",");
        "" == this.data.selectName || a.length < this.data.attrValueList.length ? wx.showToast({
            title: "请选择商品规格",
            icon: "none",
            duration: 2e3
        }) : (wx.showLoading({
            title: "处理中...."
        }), this.add_carnow(), setTimeout(function() {
            wx.hideLoading(), wx.navigateTo({
                url: "../../my/pay/pay?ids=" + t.data.ids + "&type=0"
            });
        }, 1e3));
    },
    carts: function() {
        var a = this;
        t.GET({
            url: "Pay/my_cars",
            header: "application/x-www-form-urlencoded",
            params: {
                ouid: a.data.ouid
            },
            success: function(t) {
                t.data.cars ? a.setData({
                    redshow: !0
                }) : a.setData({
                    redshow: !1
                });
            }
        });
    },
    init_attr: function() {
        var t = "", e = this.data.attrValueList;
        a = [];
        for (var s = e.length, i = 0; i < s; i++) a.push({
            key: i,
            value: e[i].stval[0]
        }), t += ' "' + a[i].value + '" ';
        var o = this.data.selectName;
        o = t, this.setData({
            selectName: o
        });
    },
    onShareAppMessage: function (options) {
  let that = this;
  let ouid;
  // 设置菜单中的转发按钮触发转发事件时的转发内容
  var shareObj = {
   title: '嗒咕商场', // 默认是小程序的名称(可以写slogan等)
   path: '/pages/start/start?share_id=' + wx.getStorageSync('ouid'), // 默认是当前页面,必须是以‘/’开头的完整路径
   imgUrl: '',//自定义图片路径,可以是本地文件路径、代码包文件路径或者网络图片路径,支持PNG及JPG,不传入 imageUrl 则使用默认截图。显示图片长宽比是 5:4
   success: function (res) {
    // 转发成功之后的回调
    if (res.errMsg == 'shareAppMessage:ok') { }
   },
   fail: function () {
    // 转发失败之后的回调
    if (res.errMsg == 'shareAppMessage:fail cancel') {
     // 用户取消转发
    } else if (res.errMsg == 'shareAppMessage:fail') {
     // 转发失败,其中 detail message 为详细失败信息
    }
   },
   complete: function () {
    // 转发结束之后的回调(转发成不成功都会执行)
   }
  }
  return shareObj;
 },
});