| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405 |
- 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
- },
- 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.setData({cartList:[]})
- this.getCartList();
- this.setData({
- submitlock: false,
- selectedall: false
- });
- // this.getCartListAndSelected();
- },
- getCartList:function(){
- console.log('getCartList')
- var that = this
- var url = 'v1/products?ptype=cent_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=cent_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/cent/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/cent/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('用户点击取消')
- }
- }
- })
- }
- }
- })
|