var a = require("../../utils/public"), app = getApp(); var util = require('../../utils/util.js'); Component({ properties: { visible: { type: Boolean, value: false, observer: function (t) { t && this.setData({ value: 1, loading: false }) let tdata = this.data; this.get_goods_details(tdata.goodsid,2) } }, cur_sku_arr: { type: Object, value: {} }, skuList: { type: Object, value: {} }, sku_val: { type: Number, value: 1 }, sku: { type: Array, value: [] }, goodsid: { type: Number, value: 0 }, type: { type: Number, value: 0 }, buyType: { type: String, value: '' }, soliId: { type: Number, value: 0 }, vipInfo: { type: Object, value: { is_open_vipcard_buy: 0, is_vip_card_member: 0, is_member_level_buy: 0 } }, skin: { type: Object, value: { color: '#ff5344', subColor: '#ed7b3a', lighter: '#fff9f4' } } }, focusFlag: false, data: { value: 1, loading: false, showLimitTip: false, showLimitType: 0, eventIdx:0, reverseArr:[] }, methods: { close: function () { this.setData({ showLimitTip: false }) this.triggerEvent("cancel"); }, selectSku: function (event) { var that = this; let str = event.currentTarget.dataset.type; let obj = str.split("_"); this.setData({eventIdx:event.currentTarget.dataset.idx}) var sku_car_num = this.data.skuList.sku_mu_list             let arr = Object.values(sku_car_num)             var reverseArr = arr.reverse() // console.log(reverseArr)             var number = reverseArr[event.currentTarget.dataset.idx].car_quantity             this.setData({sku_val:number == 0 ? 1 : number,reverseArr}) let { sku, cur_sku_arr, skuList, sku_val } = this.data; let temp = { name: obj[3], id: obj[2], index: obj[0], idx: obj[1] }; sku.splice(obj[0], 1, temp); var id = ''; for (let i = 0; i < sku.length; i++) { if (i == sku.length - 1) { id = id + sku[i]['id']; } else { id = id + sku[i]['id'] + "_"; } } // console.log(id) // cur_sku_arr = Object.assign(cur_sku_arr, skuList.sku_mu_list[id]); // console.log(reverseArr) for(var i=0;i canBuyNum) { h.sku_val = canBuyNum == 0 ? 1 : canBuyNum; (canBuyNum > 0) && wx.showToast({ title: `最多只能购买${cur_sku_arr.canBuyNum}件`, icon: 'none' }) } let { car_quantity, goods_start_count } = this.data.cur_sku_arr; if (car_quantity && car_quantity >= goods_start_count) goods_start_count = 1; // 库存小于起购数量 按钮变灰 数量变起购 if (canBuyNum < goods_start_count) { // h.sku_val = goods_start_count; h.noEougnStock = true; } else { // h.sku_val = goods_start_count; } if (this.data.buyType == 'integral') { // h.sku_val = 1; } // console.log(cur_sku_arr) if(cur_sku_arr.car_quantity ==0 || cur_sku_arr.car_quantity == null){ cur_sku_arr.car_quantity = 1 } that.setData({ cur_sku_arr, sku, showLimitTip: false, showLimitType: 0, ...h }) }, /** * 数量加减 */ setNum: function (event) { let types = event.currentTarget.dataset.type; var that = this; var num = 1; let sku_val = this.data.sku_val * 1; let showLimitTip = false; let showLimitType = 0; var sku_car_num = this.data.cur_sku_arr              if (types == 'add') { num = sku_val + 1; let { one_limit_count, total_limit_count, oneday_limit_count } = this.data.cur_sku_arr; if (one_limit_count > 0 && num > one_limit_count) { wx.showToast({ title: `您本次只能购买${one_limit_count}份`, icon: 'none' }) num = one_limit_count; showLimitTip = true; showLimitType = 1; } else if (oneday_limit_count > 0 && num > oneday_limit_count) { wx.showToast({ title: `您今天只能购买${oneday_limit_count}份`, icon: 'none' }) num = oneday_limit_count; showLimitTip = true; showLimitType = 2; } else if (total_limit_count > 0 && num > total_limit_count) { wx.showToast({ title: `您最多只能购买${total_limit_count}份`, icon: 'none' }) num = total_limit_count; showLimitTip = true; showLimitType = 3; } } else if (types == 'decrease') { let { car_quantity, goods_start_count } = this.data.cur_sku_arr; if (car_quantity && car_quantity >= goods_start_count) goods_start_count = 1; if (sku_val > 1) { num = sku_val - 1; if (num < goods_start_count) { num = goods_start_count; wx.showToast({ title: `${goods_start_count}件起售`, icon: 'none' }) } } } let arr = that.data.sku; var options = this.data.skuList; if (arr.length > 0) { var id = ''; for (let i = 0; i < arr.length; i++) { if (i == arr.length - 1) { id = id + arr[i]['id']; } else { id = id + arr[i]['id'] + "_"; } } } if (options.length > 0) { let cur_sku_arr = options.sku_mu_list[id]; let max = cur_sku_arr['canBuyNum']; if (num > max) { num = num - 1; wx.showToast({ title: `最多只能购买${max}件`, icon: 'none' }) } } else { let cur_sku_arr = this.data.cur_sku_arr; if (num > cur_sku_arr['canBuyNum']) { num = num - 1; } } console.log(num) sku_car_num.car_quantity = num // reverseArr[this.data.eventIdx].car_quantity = num this.setData({ sku_val: num, showLimitTip, showLimitType, cur_sku_arr:sku_car_num }) }, get_goods_details: function (id, currentCommunity_id){ let that = this; let token = wx.getStorageSync('token'); app.util.request({ url: 'entry/wxapp/index', data: { controller: 'goods.get_goods_detail', token: token, id, community_id: currentCommunity_id }, dataType: 'json', success: function (res) { console.log(res,'详情') that.setData({ skuList:res.data.data.options, 'cur_sku_arr.levelprice':res.data.data.goods.levelprice, 'cur_sku_arr.actPrice':res.data.data.goods.actPrice, 'cur_sku_arr.marketPrice':res.data.data.goods.marketPrice }) console.log(that.data.cur_sku_arr) } }) }, join() { //加入购物车 this.gocarfrom(1) }, buy() { //购买 this.gocarfrom(0) }, gocarfrom: function (code) { var that = this; wx.showLoading(); // a.collectFormIds(e.detail.formId); that.goOrder(code); }, goOrder: function (code) { var that = this; if (that.data.can_car) { that.data.can_car = false; } let tdata = that.data; console.log(code) console.log(this.data.cur_sku_arr) if (code == 0) { let man_orderbuy_money = this.data.man_orderbuy_money * 1; let sku_val = this.data.cur_sku_arr.car_quantity; let cur_sku_arr = this.data.cur_sku_arr; let actPrice = cur_sku_arr.actPrice[0] + '.' + cur_sku_arr.actPrice[1]; console.log(actPrice * 1 * sku_val); if (actPrice * 1 * sku_val < man_orderbuy_money) { wx.showToast({ title: '满' + man_orderbuy_money + '元可下单!', icon: 'none' }) return false; } } let localtown_moneytype_fixed_freemoney = this.data.localtown_moneytype_fixed_freemoney * 1; let is_only_distribution = this.data.is_only_distribution; if (localtown_moneytype_fixed_freemoney >= 0 && is_only_distribution == 1 && code == 0) { let sku_val = this.data.cur_sku_arr.car_quantity; let cur_sku_arr = this.data.cur_sku_arr; let actPrice = cur_sku_arr.actPrice[0] + '.' + cur_sku_arr.actPrice[1]; if (actPrice * 1 * sku_val < localtown_moneytype_fixed_freemoney) { wx.showToast({ title: '同城配送商品满' + localtown_moneytype_fixed_freemoney + '元可下单!', icon: 'none' }) return false; } } var community = wx.getStorageSync('community'); var goods_id = tdata.goodsid; var community_id = community.communityId; var quantity = that.data.cur_sku_arr.car_quantity == 0 || !that.data.cur_sku_arr.car_quantity ? 1 : that.data.cur_sku_arr.car_quantity; var cur_sku_arr = that.data.cur_sku_arr; var sku_str = ''; var is_just_addcar = code; if (cur_sku_arr && cur_sku_arr.option_item_ids) { sku_str = cur_sku_arr.option_item_ids; } //20200622 // if (cur_sku_arr.car_quantity && cur_sku_arr.car_quantity > 0 && code == 1) { // quantity -= cur_sku_arr.car_quantity * 1; // } // quantity = quantity <= 0 ? 1 : quantity; console.log(quantity) let buy_type = this.data.buy_type ? this.data.buy_type : 'dan'; let data = { goods_id: goods_id, community_id, quantity, sku_str, buy_type, pin_id: 0, is_just_addcar } util.addCart(data).then(res => { console.log(res) if (res.showVipModal == 1) { let { pop_vipmember_buyimage } = res.data; wx.hideLoading(); that.setData({ pop_vipmember_buyimage, showVipModal: true, visible: false }) } else if (res.data.code == 3 || res.data.code == 7) { wx.showToast({ title: res.data.msg, icon: 'none', duration: 2000 }) } else { if (buy_type == 'integral') { // 积分 if (res.data.code == 6) { var msg = res.data.msg; wx.showToast({ title: msg, icon: 'none', duration: 2000 }) } else { //跳转结算页面 wx.navigateTo({ url: `/lionfish_comshop/pages/order/placeOrder?type=integral`, }) } } else { console.log(res.data.data) console.log(code) if (res.data.code == 4) { wx.hideLoading(); that.setData({ needAuth: true, showAuthModal: true, visible: false }) } else if (res.data.code == 6) { var msg = res.data.msg; let max_quantity = res.data.max_quantity || ''; (max_quantity > 0) && that.setData({ sku_val: max_quantity }) wx.showToast({ title: msg, icon: 'none', duration: 2000 }) } else { console.log(code) if (code == 1) { // that.close(); console.log(that.data.cur_sku_arr) console.log(that.data.reverseArr) console.log(that.data.skuList) var reverseArr = that.data.reverseArr; for(var i=0;i 3) { wx.redirectTo({ url: '/lionfish_comshop/pages/order/placeOrder?type=' + buy_type + '&is_limit=' + is_limit }) } else { wx.navigateTo({ url: '/lionfish_comshop/pages/order/placeOrder?type=' + buy_type + '&is_limit=' + is_limit }) } } } } } }).catch(res => { app.util.message(res || '请求失败', '', 'error'); }) }, // 输入框获得焦点 handleFocus: function () { this.focusFlag = true; }, handleBlur: function (t) { let a = t.detail; let val = parseInt(a.value); if (val == '' || isNaN(val)) { let { car_quantity, goods_start_count } = this.data.cur_sku_arr; if (car_quantity && car_quantity >= goods_start_count) { goods_start_count = 1; } else { wx.showToast({ title: `${goods_start_count}件起售`, icon: 'none' }) } this.setData({ sku_val: goods_start_count }) } }, // 监控输入框变化 changeNumber: function (t) { let { cur_sku_arr, sku_val } = this.data; let max = cur_sku_arr.stock * 1; let a = t.detail; this.focusFlag = false; let showLimitTip = false; let showLimitType = 0; let { car_quantity, goods_start_count } = this.data.cur_sku_arr; if (car_quantity && car_quantity >= goods_start_count) goods_start_count = 1; if (a) { let val = parseInt(a.value); val = val < 1 ? 1 : val; // 限购 let { one_limit_count, total_limit_count, oneday_limit_count } = cur_sku_arr; if (one_limit_count > 0 && val > one_limit_count) { wx.showToast({ title: `您本次只能购买${one_limit_count}份`, icon: 'none' }) sku_val = one_limit_count; showLimitTip = true; showLimitType = 1; } else if (oneday_limit_count > 0 && val > oneday_limit_count) { wx.showToast({ title: `您今天只能购买${oneday_limit_count}份`, icon: 'none' }) sku_val = oneday_limit_count; showLimitTip = true; showLimitType = 2; } else if (total_limit_count > 0 && val > total_limit_count) { wx.showToast({ title: `您最多只能购买${total_limit_count}份`, icon: 'none' }) sku_val = total_limit_count; showLimitTip = true; showLimitType = 3; } else if (val > max) { wx.showToast({ title: `最多只能购买${max}件`, icon: 'none' }) sku_val = max; } else { if (val < goods_start_count) { val = goods_start_count; wx.showToast({ title: `${goods_start_count}件起售`, icon: 'none' }) } sku_val = val; } } this.setData({ sku_val, showLimitTip, showLimitType }) } }, attached(){ console.log('执行了') } });