| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681 |
- 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,
- checkbox:'',
- },
- 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;
- res.data.list[i]['overtype'] = res.data.list[i]['have_size'] ? false:true;
- }
- 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;
- var overtype = this.data.cartList[index].overtype;
- console.log('bool',bool)
- if(overtype){
- if(this.data.cartList[index].is_deliver && (this.data.cartList[index].deliver_state == 1 || this.data.cartList[index].deliver_state == 3)){
- var txt = this.data.cartList[index].deliver_state == 1 ? '商品正在预售中暂未开放购买~' : '商品已售罄~';
- wx.showToast({
- title: txt,
- icon: 'none',
- duration: 3000
- })
- }else{
- this.setData({
- ['cartList[' + index + '].IsBuy']: !bool
- })
-
- this.checkSelected();
- }
- }else{
- wx.showToast({
- title: '商品 '+this.data.cartList[index].name+' 请先选择规格~',
- icon: 'none',
- duration: 3000
- })
- }
-
- },
- 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){
- if(this.data.cartList[i].overtype){
- if(this.data.cartList[i].is_deliver && (this.data.cartList[i].deliver_state == 1 || this.data.cartList[i].deliver_state == 3)){
- var txt = this.data.cartList[i].deliver_state == 1 ? '商品正在预售中暂未开放购买~' : '商品已售罄~';
- wx.showToast({
- title: txt,
- icon: 'none',
- duration: 3000
- })
- }else{
- this.setData({
- ['cartList[' + i + '].IsBuy']: true
- })
- }
- }else{
- wx.showToast({
- title: '商品 '+this.data.cartList[i].name+' 请先选择规格~',
- icon: 'none',
- duration: 3000
- })
- }
- }
- 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;
- var item = val.currentTarget.dataset.item;
- that.setData({
- selectProjectid: id,
- selectProjectItem: item
- });
-
- 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)
- },
- hideDialog:function(e){
- var that = this
- that.data.showDialog = !that.data.showDialog
- if (that.data.showDialog) {
- that.showModal(1)
- } else {
- that.hideModal(1)
- }
- },
- // 显示弹框
- showModal: function (type) {
- var animation = wx.createAnimation({
- duration: 200,
- timingFunction: "ease-out"
- })
- this.animation = animation
- animation.translateY(500).step()
- if(type == 1){
- this.setData({
- animationData: animation.export(),
- showDialog: true
- })
- }else{
- this.setData({
- animationData: animation.export(),
- showCartDialog: true
- })
- }
-
- setTimeout(function () {
- animation.translateY(0).step()
- this.setData({
- animationData: animation.export()
- })
- }.bind(this), 200)
- },
- // 隐藏弹框
- hideModal: function (type = 1) {
- var animation = wx.createAnimation({
- duration: 200,
- timingFunction: "ease-out"
- })
- this.animation = animation
- animation.translateY(500).step()
- this.setData({
- animationData: animation.export(),
- })
- setTimeout(function () {
- animation.translateY(0).step()
- if(type == 1){
- this.setData({
- animationData: animation.export(),
- showDialog: false
- })
- }else{
- this.setData({
- animationData: animation.export(),
- showCartDialog: false
- })
- }
-
- }.bind(this), 200)
- },
- checkSize(event){
- var type = event.currentTarget.dataset.type;
- var id = event.currentTarget.dataset.id;
- var list = event.currentTarget.dataset.list;
- var tname = event.currentTarget.dataset.tname;
- var that = this;
- var tkey = type=='color_list'?'cname':'sname';
- var reproduct = this.data.selectProjectSize;
- // console.log('reproduct',reproduct)
- for(var i in reproduct[type]['attr_values']){
- // console.log('reproduct[type][i].is_select',reproduct[type]['attr_values'][i].is_select)
- reproduct[type]['attr_values'][i].is_select = false;
- if(reproduct[type]['attr_values'][i].id == id) reproduct[type]['attr_values'][i].is_select = true;
- }
- // console.log('reproduct',reproduct)
-
- that.setData({
- selectProjectSize :reproduct,
- [type]:id,
- [tkey]:tname
- })
- console.log('that.data[type]',that.data[type])
- let cflag = true;
- for(let i in that.data.checkbox){
- if(that.data[that.data.checkbox[i]] == 0) cflag = false;
- }
- if(cflag){
- that.getProductDetail();
- }
-
- },
- getProductDetail () {
- var that = this;
- console.log(that.data.size_list);
- console.log(that.data.color_list);
- var sizelist = that.data.size_list ? that.data.size_list : 0;
- var colorlist = that.data.color_list ? that.data.color_list : 0;
-
- var url = "v1/product_detail/" + that.data.selectProjectid + "/" + sizelist + "/" + colorlist;
- var params = {}
- var success = function (val) {
- console.log('val',val)
- if(val.data.product){
- that.setData({
- canpay:true,
- selectProject:val.data.product,
- selectProjectid:val.data.product.id,
- noproduct:false
- })
- that.setData({
- canpay:true,
- selectProject:val.data.product,
- selectProjectid:val.data.product.id,
- noproduct:false
- })
- }else{
- that.setData({
- canpay:false,
- noproduct:true
- })
- }
- }
- var fail = function(err){
-
- }
- _request.$get(url, params, success, fail)
- },
- selectType:function(){
- var that = this;
- var itemindex = this.data.selectProjectItem;
- var itemdata = this.data.selectProject;
- console.log('xuanzzzzz')
- console.log(this.data.cartList)
- console.log(this.data.selectProject)
- console.log(this.data.selectProjectItem)
- itemdata['count']=1;
- itemdata['IsBuy']=this.data.cartList[itemindex].IsBuy;
- itemdata['movex']=0;
- itemdata['overtype']=true;
- that.setData({
- ['cartList[' + itemindex + ']']:itemdata
- })
- that.hideModal(1);
- },
- selectTypeno:function(){
- wx.showToast({
- title: '选中的规格暂无库存,请选择其他规格~',
- icon: 'none',
- duration: 2000
- })
- }
- })
|