var _request = require('../../utils/request.js') var _handle = require('../../utils/handle.js') var validator = require('../../utils/validator.js') Page({ data: { orderId: 0, count:1, cartList:[], cartCount:0, cartTotal:0, checkeditems:'', checkeditemsnum:'', checkedtotal:0, selectedall:false, submitlock:false, x:0, currentX: 0, perpage:10, nowpage:1, cartMore:true, showDialog: false, }, handleMovableChange: function(e) { // this.data.currentX = e.detail.x; this.data.currentX = e.detail.x; }, handleTouchend: function(e) { this.isMove = true; let index = e.currentTarget.id; let clist = this.data.cartList; // if (this.data.currentX < -46) { //// this.data.x = -92; // clist[index]['movex'] = -100; // this.setData({ // cartList: clist // }); // } else { clist[index]['movex'] = 0; this.setData({ cartList: clist }); // } }, onLoad: function (options) { // this.getCartList(); this.getCartList(); this.setData({submitlock: false}); this.setData({selectedall: false}); this.getIphoneX() }, onShow: function () { // this.getCartListAndSelected(); this.setData({submitlock: false}) }, getCartList:function(){ console.log('getCartList') var that = this var url = 'v1/products?ptype=shop_sale&&page='+that.data.nowpage+'&&per_page='+that.data.perpage var params = {} var success = function (res) { console.log(res) if(res.data.list){ for(let i in res.data.list){ res.data.list[i]['movex'] = 0; res.data.list[i]['IsBuy'] = false; res.data.list[i]['count'] = 1; } that.setData({ cartMore: res.data.list_count > that.data.cartList.length, cartList: that.data.cartList.concat(res.data.list || []), cartCount: res.data.count, cartTotal: res.data.total }) }else{ wx.showToast({ title: '请先授权登录~', icon: 'none', duration: 2000 }) } } _request.$get(url, params, success) }, onReachBottom: function () { console.log('onreachbottom') if (this.data.cartMore) { var page = this.data.nowpage + 1 this.setData({ nowpage: page }) this.getCartList() } }, getCartListAndSelected:function(){ console.log('getCartList') var that = this var url = 'v1/products?ptype=shop_sale&&page=1&&per_page=3' var params = {} var success = function (res) { console.log(res) for(let i in res.data.list){ res.data.list[i]['movex'] = 0; res.data.list[i]['IsBuy'] = false; res.data.list[i]['count'] = 1; } if(res.data.list){ that.setData({ cartList: res.data.list, cartCount: res.data.count, cartTotal: res.data.total }) // that.allSelect(); }else{ wx.showToast({ title: '请先授权登录~', icon: 'none', duration: 2000 }) } } _request.$get(url, params, success) }, add: function (e) { console.log('tapadd',e) var itemid = e.currentTarget.dataset.id; var itemcount = e.currentTarget.dataset.count; console.log('itemcount',itemcount) if (itemcount) { var index = e.currentTarget.dataset.index; var count = itemcount + 1; this.setData({ ['cartList[' + index + '].count']:count }) this.checkSelected(); // this.changeServercount(count,itemid); } }, mius: function (e) { console.log('tapmius',e) var that = this; var itemid = e.currentTarget.dataset.id; var itemcount = e.currentTarget.dataset.count; if (itemcount > 1) { var count = itemcount - 1; var index = e.currentTarget.dataset.index; this.setData({ ['cartList[' + index + '].count']:count }) this.checkSelected(); // this.changeServercount(count,itemid); }/*else{ wx.showModal({ title: '提示', content: '需要删除改商品吗?', success: function (sm) { if (sm.confirm) { var url = "/v1/cart/mult_delele"; var params = { ids:itemid } var success = function (res) { console.log(res) if(res.data.result){ } that.getCartList(); } _request.$post(url, params, success); } else if (sm.cancel) { console.log('用户点击取消') } } }) }*/ }, delitem:function(e){ var that = this; var itemid = e.currentTarget.dataset.id; console.log('itemid',itemid); // wx.showModal({ // title: '提示', // content: '需要删除改商品吗?', // success: function (sm) { // if (sm.confirm) { // var url = "/v1/cart/mult_delele"; // var params = { // ids:itemid // } // var success = function (res) { // console.log(res) // if(res.data.result){ // // } // that.getCartList(); // } // _request.$post(url, params, success); // } else if (sm.cancel) { // console.log('用户点击取消') // } // } // }) }, changeCount: function (val) { var count = val.detail.value var itemid = val.target.dataset.id; var index = val.target.dataset.index; if (count <= 0) { this.setData({ ['cartList[' + index + '].count']:1 }) this.checkSelected(); // this.changeServercount(1,itemid); } /*else if (count > this.data.project.left_count) { this.setData({ count: this.data.project.left_count }) this.changeCountService(this.data.project.left_count,itemid) }*/ else { this.setData({ ['cartList[' + index + '].count']:count }) this.checkSelected(); // this.changeServercount(count,itemid); } }, changeServercount:function(val,itemid){ console.log('changeCountService') var that = this var url = "/v1/cart/change_nums/" + itemid + "/" + val var params = {} var success = function (res) { console.log(res) if(res.result){ //修改成功 } } _request.$post(url, params, success); this.getCartList(); }, itemselected:function(e){ console.log(this) var nowitems = this.data.selectedItems; let index = e.currentTarget.dataset.index; var bool = this.data.cartList[index].IsBuy; console.log('bool',bool) this.setData({ ['cartList[' + index + '].IsBuy']: !bool }) this.checkSelected(); }, allSelect:function(){ if(this.data.selectedall){ for(var i in this.data.cartList){ this.setData({ ['cartList[' + i + '].IsBuy']: false }) } this.setData({ selectedall: false }) }else{ for(var i in this.data.cartList){ this.setData({ ['cartList[' + i + '].IsBuy']: true }) } this.setData({ selectedall: true }) } this.checkSelected(); }, checkSelected:function(){ var cartList = this.data.cartList; var checkitem = ''; var checkitemnum = ''; var checktotal = 0; var checkcount = 0; // console.log('cartList',cartList) for(var i in cartList){ if(cartList[i].IsBuy){ checkitem = checkitem + cartList[i].id+','; checkitemnum = checkitemnum + cartList[i].count+','; checktotal = checktotal + (parseFloat(cartList[i].price) * parseInt(cartList[i].count)); checkcount = checkcount + parseInt(cartList[i].count); } } checkitem = checkitem.substr(0,checkitem.length - 1); checkitemnum = checkitemnum.substr(0,checkitemnum.length - 1); this.setData({ checkeditems:checkitem, checkeditemsnum:checkitemnum, cartCount: checkcount, cartTotal: checktotal }) // this.mulChangeState(); }, mulChangeState:function(){ var that = this; var itemid = this.data.checkeditems; var itemnum = this.data.checkeditemsnum; var url = "v1/cart/mult_change_state"; var params = { ids:itemid, nums:itemnum } var success = function (res) { console.log('mulChangeState',res) if(res.data.result){ that.getCartList(); } } _request.$post(url, params, success); }, mulChangeStateToPay:function(){ var that = this; var lock = this.data.submitlock; if(!lock){ that.setData({submitlock: true}) var itemid = this.data.checkeditems; var itemnum = this.data.checkeditemsnum; var url = "v1/shop/order_mul"; var params = { ids:itemid, nums:itemnum } var success = function (res) { wx.showToast({ title: '正在跳转到结算页,请稍后~', icon: 'none', duration: 2000 }) console.log('mulChangeState',res) if (res.data.order_id) { wx.navigateTo({ url: '../pay/pay?orderId=' + res.data.order_id }) } } var err = function(err){ console.log(err) that.setData({submitlock: false}) } _request.$post(url, params, success, err); } }, toPay:function(){ var that = this; var url = "/v1/cart/order_mul"; var params = {} var success = function (res) { console.log(res) if (res.data.order_id) { wx.navigateTo({ url: '../pay/pay?orderId=' + res.data.order_id }) } } _request.$get(url, params, success); }, delSelected:function(){ var that = this; var itemid = this.data.checkeditems; if(itemid== ''){ wx.showToast({ title: '没有选中任何商品~', icon: 'none', duration: 2000 }) }else{ wx.showModal({ title: '提示', content: '确定要删除选中的商品吗?', success: function (sm) { if (sm.confirm) { var url = "/v1/cart/mult_delele"; var params = { ids:itemid } var success = function (res) { console.log(res) if(res.data.result){ } that.getCartList(); } _request.$post(url, params, success); } else if (sm.cancel) { console.log('用户点击取消') } } }) } }, toProject:function(val){ var id = val.currentTarget.dataset.val wx.navigateTo({ url: '/pages/projects/project-detail-noshare/project-detail-noshare?id=' + id + '&read=1' }) }, getIphoneX () { var that = this wx.getSystemInfo({ success: function (res) { if (res.model.toLowerCase().indexOf('iphone x') > -1) { that.setData({ value: 34 }) } } }) }, selectSize:function(val){ var that = this var id = val.currentTarget.dataset.val that.setData({ selectProjectid: id }); console.log('id',id); that.getProjectDetail(); that.getProductSize(); var animation = wx.createAnimation({ duration: 200, timingFunction: "ease-out" }) this.animation = animation animation.translateY(500).step() this.setData({ animationData: animation.export(), showDialog: true }) setTimeout(function () { animation.translateY(0).step() this.setData({ animationData: animation.export() }) }.bind(this), 200) }, getProjectDetail() { var that = this var url = "v1/product/" + that.data.selectProjectid; var params = {} var success = function (val) { var p = val.data.detail that.setData({ selectProject: val.data }); if(val.data.have_size){ that.getProductSize(); } } _request.$get(url, params, success) }, getProductSize(){ var that = this var url = "v1/product_size/" + that.data.selectProjectid; var params = {} var success = function (val) { let cbox = []; for(let i in val.data){ if(i != 'product' && val.data[i]) cbox.push(i); } console.log('cbox',cbox) that.setData({ selectProjectSize: val.data, checkbox:cbox }); } _request.$get(url, params, success) } })