123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292 |
- // pages/details/details.js
- const getReq = require('./../../config.js').getReq;
- const app = getApp();
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- imgUrls: [],
- datas: {},
- getOneSummary: [],
- webViewUrl: '',
- indicatorDots: true,
- vertical: false,
- autoplay: true,
- interval: 2000,
- duration: 500,
- animation_flag: false,
- sec_index: 0,
- goodsNumber: 1,
- cartOrBuy: '',
- getgift: '',
- options_goods_id:''
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- let webViewUrl = `https://passport.lrlz.com/mobile/index.php?act=goods_common&op=detail&goods_id=${options.goods_id}&client_type=ios`
- this.setData({
- webViewUrl,
- options_goods_id: options.goods_id
- })
- this.getDatas(options.goods_id)
- },
- getDatas(goods_id) {
- wx.showLoading({
- title: '加载中',
- })
- var self = this
- getReq({
- act: 'goods_common',
- op: 'index',
- goods_id
- }, function (res) {
- wx.hideLoading()
- if (res.code == 200) {
- let oneSummary = self.getOneSummary(res.datas.summary, goods_id)
- let getgift = self.getgift(res.datas.summary, goods_id)
- self.setData({
- datas: res.datas,
- getOneSummary: oneSummary,
- imgUrls: res.datas.common_info.images,
- getgift
- })
- }
- else {
- wx.showToast({
- icon: 'none',
- title: res.message,
- duration: 1500
- })
- }
- })
- },
- getOneSummary(sumarys, goods_id) {
- let getOneSummary = sumarys.filter((item, index) => {
- return item.goods_id == goods_id
- })
- return getOneSummary[0]
- },
- secSku(e) {
- let goodsId = e.currentTarget.dataset.goodsid
- let sec_index = e.currentTarget.dataset.secindex
- if (this.data.sec_index == sec_index) {
- return
- }
- let getOneSummary = this.getOneSummary(this.data.datas.summary, goodsId)
- let getgift = this.getgift(this.data.datas.summary, goodsId)
- if (getOneSummary.goods_storage < 1) {
- wx.showToast({
- title: '客官!暂时没有库存!',
- icon: 'none',
- duration: 1500
- })
- return
- }
- this.setData({
- sec_index,
- getOneSummary,
- goodsNumber: 1,
- getgift
- })
- },
- goodsNumHandle(e) {
- let type = e.currentTarget.dataset.type
- if (type == 'minus') {
- if (this.data.goodsNumber <= 1) {
- wx.showToast({
- title: '客官!不能再少了!',
- icon: 'none',
- duration: 1500
- })
- return
- }
- else {
- this.setData({
- goodsNumber: --this.data.goodsNumber
- })
- }
- }
- else {
- if (this.data.goodsNumber >= this.data.getOneSummary['goods_storage']) {
- wx.showToast({
- title: '客官!只有这么多了!',
- icon: 'none',
- duration: 1500
- })
- return
- }
- else {
- this.setData({
- goodsNumber: ++this.data.goodsNumber
- })
- }
- }
- },
- checkSubmit() {
- if (!app.globalData.userInfo) {
- wx.navigateTo({
- url: '/pages/login/login'
- });
- return;
- }
- let cartOrBuy = this.data.cartOrBuy
- this.setData({
- animation_flag: false
- })
- if (cartOrBuy == 'isCart') {
- wx.showLoading({
- title: '加载中',
- })
- getReq({
- act: 'cart',
- op: 'addex',
- quantity: this.data.goodsNumber,
- goods_id: this.data.getOneSummary.goods_id
- }, function (res) {
- wx.hideLoading()
- if (res.code == 200) {
- wx.showToast({
- icon: 'none',
- title: '添加成功!',
- duration: 1500
- })
- }
- else {
- wx.showToast({
- icon: 'none',
- title: res.message,
- duration: 1500
- })
- }
- })
- }
- else if (cartOrBuy == 'isBuy') {
- if (this.data.getOneSummary.goods_storage < 1) {
- wx.showToast({
- title: '客官!暂时没有库存!',
- icon: 'none',
- duration: 1500
- })
- return
- }
- wx.navigateTo({
- url: `/pages/confirmOrder/confirmOrder?goods_id=${this.data.getOneSummary.goods_id}&iscart=0&num=${this.data.goodsNumber}`
- })
- }
- else {
- return
- }
- },
- toWebView() {
- let webViewUrl = encodeURIComponent(this.data.webViewUrl)
- wx.navigateTo({
- url: `/pages/webView/webView?url=${webViewUrl}`
- })
- },
- animation_flag(e) {
- let cartOrBuy = e.currentTarget.dataset.cartorbuy || 'none'
- let flag = e.currentTarget.dataset.flag
- let animation_flag = flag == 'true' ? true : false
- this.setData({
- animation_flag,
- cartOrBuy
- })
- },
- getgift(sumarys, goods_id) {
- let goods = this.getOneSummary(sumarys, goods_id)
- let giftSummary = ''
- if (goods.have_gift) {
- giftSummary = this.getGiftSummary(sumarys, goods.gifts)
- }
- return giftSummary
- },
- getGiftSummary(sumarys, gifts) {
- let arr = []
- gifts.map(item => {
- sumarys.filter(sum => {
- if(item.gift_goods_id == sum.goods_id) {
- arr.push({
- sum,
- gifts: item
- })
- }
- })
- })
- return arr
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- if (app.globalData.fcodeErr) {
- wx.showToast({
- icon: 'none',
- title: app.globalData.fcodeErr,
- duration: 1500
- })
- app.globalData.fcodeErr = ''
- this.setData({
- animation_flag: false
- })
- // console.log(this.data.options_goods_id)
- setTimeout(() => {
- this.getDatas(this.data.options_goods_id)
- }, 1500)
- }
- if (app.globalData.backLogin) {
- this.getDatas(this.data.getOneSummary.goods_id);
- }
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|