|
@@ -0,0 +1,387 @@
|
|
|
|
|
+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
|
|
|
|
|
+ },
|
|
|
|
|
+ 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();
|
|
|
|
|
+ },
|
|
|
|
|
+ onShow: function () {
|
|
|
|
|
+ this.getCartList();
|
|
|
|
|
+ this.setData({submitlock: false});
|
|
|
|
|
+ this.setData({selectedall: false});
|
|
|
|
|
+ this.getCartListAndSelected();
|
|
|
|
|
+ },
|
|
|
|
|
+ getCartList: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)
|
|
|
|
|
+ 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({
|
|
|
|
|
+ cartList: res.data.list,
|
|
|
|
|
+ cartCount: res.data.count,
|
|
|
|
|
+ cartTotal: res.data.total
|
|
|
|
|
+ })
|
|
|
|
|
+ }else{
|
|
|
|
|
+ wx.showToast({
|
|
|
|
|
+ title: '请先授权登录~',
|
|
|
|
|
+ icon: 'none',
|
|
|
|
|
+ duration: 2000
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ _request.$get(url, params, success)
|
|
|
|
|
+ },
|
|
|
|
|
+ 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('用户点击取消')
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+})
|