areacart.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. var _request = require('../../utils/request.js')
  2. var _handle = require('../../utils/handle.js')
  3. var validator = require('../../utils/validator.js')
  4. Page({
  5. data: {
  6. orderId: 0,
  7. count:1,
  8. cartList:[],
  9. cartCount:0,
  10. cartTotal:0,
  11. checkeditems:'',
  12. checkeditemsnum:'',
  13. checkedtotal:0,
  14. selectedall:false,
  15. submitlock:false,
  16. x:0,
  17. currentX: 0,
  18. perpage:10,
  19. nowpage:1,
  20. cartMore:true,
  21. showDialog: false,
  22. },
  23. handleMovableChange: function(e) {
  24. // this.data.currentX = e.detail.x;
  25. this.data.currentX = e.detail.x;
  26. },
  27. handleTouchend: function(e) {
  28. this.isMove = true;
  29. let index = e.currentTarget.id;
  30. let clist = this.data.cartList;
  31. // if (this.data.currentX < -46) {
  32. //// this.data.x = -92;
  33. // clist[index]['movex'] = -100;
  34. // this.setData({
  35. // cartList: clist
  36. // });
  37. // } else {
  38. clist[index]['movex'] = 0;
  39. this.setData({
  40. cartList: clist
  41. });
  42. // }
  43. },
  44. onLoad: function (options) {
  45. // this.getCartList();
  46. this.getCartList();
  47. this.setData({submitlock: false});
  48. this.setData({selectedall: false});
  49. this.getIphoneX()
  50. },
  51. onShow: function () {
  52. // this.getCartListAndSelected();
  53. this.setData({submitlock: false})
  54. },
  55. getCartList:function(){
  56. console.log('getCartList')
  57. var that = this
  58. var url = 'v1/products?ptype=shop_sale&&page='+that.data.nowpage+'&&per_page='+that.data.perpage
  59. var params = {}
  60. var success = function (res) {
  61. console.log(res)
  62. if(res.data.list){
  63. for(let i in res.data.list){
  64. res.data.list[i]['movex'] = 0;
  65. res.data.list[i]['IsBuy'] = false;
  66. res.data.list[i]['count'] = 1;
  67. }
  68. that.setData({
  69. cartMore: res.data.list_count > that.data.cartList.length,
  70. cartList: that.data.cartList.concat(res.data.list || []),
  71. cartCount: res.data.count,
  72. cartTotal: res.data.total
  73. })
  74. }else{
  75. wx.showToast({
  76. title: '请先授权登录~',
  77. icon: 'none',
  78. duration: 2000
  79. })
  80. }
  81. }
  82. _request.$get(url, params, success)
  83. },
  84. onReachBottom: function () {
  85. console.log('onreachbottom')
  86. if (this.data.cartMore) {
  87. var page = this.data.nowpage + 1
  88. this.setData({
  89. nowpage: page
  90. })
  91. this.getCartList()
  92. }
  93. },
  94. getCartListAndSelected:function(){
  95. console.log('getCartList')
  96. var that = this
  97. var url = 'v1/products?ptype=shop_sale&&page=1&&per_page=3'
  98. var params = {}
  99. var success = function (res) {
  100. console.log(res)
  101. for(let i in res.data.list){
  102. res.data.list[i]['movex'] = 0;
  103. res.data.list[i]['IsBuy'] = false;
  104. res.data.list[i]['count'] = 1;
  105. }
  106. if(res.data.list){
  107. that.setData({
  108. cartList: res.data.list,
  109. cartCount: res.data.count,
  110. cartTotal: res.data.total
  111. })
  112. // that.allSelect();
  113. }else{
  114. wx.showToast({
  115. title: '请先授权登录~',
  116. icon: 'none',
  117. duration: 2000
  118. })
  119. }
  120. }
  121. _request.$get(url, params, success)
  122. },
  123. add: function (e) {
  124. console.log('tapadd',e)
  125. var itemid = e.currentTarget.dataset.id;
  126. var itemcount = e.currentTarget.dataset.count;
  127. console.log('itemcount',itemcount)
  128. if (itemcount) {
  129. var index = e.currentTarget.dataset.index;
  130. var count = itemcount + 1;
  131. this.setData({
  132. ['cartList[' + index + '].count']:count
  133. })
  134. this.checkSelected();
  135. // this.changeServercount(count,itemid);
  136. }
  137. },
  138. mius: function (e) {
  139. console.log('tapmius',e)
  140. var that = this;
  141. var itemid = e.currentTarget.dataset.id;
  142. var itemcount = e.currentTarget.dataset.count;
  143. if (itemcount > 1) {
  144. var count = itemcount - 1;
  145. var index = e.currentTarget.dataset.index;
  146. this.setData({
  147. ['cartList[' + index + '].count']:count
  148. })
  149. this.checkSelected();
  150. // this.changeServercount(count,itemid);
  151. }/*else{
  152. wx.showModal({
  153. title: '提示',
  154. content: '需要删除改商品吗?',
  155. success: function (sm) {
  156. if (sm.confirm) {
  157. var url = "/v1/cart/mult_delele";
  158. var params = {
  159. ids:itemid
  160. }
  161. var success = function (res) {
  162. console.log(res)
  163. if(res.data.result){
  164. }
  165. that.getCartList();
  166. }
  167. _request.$post(url, params, success);
  168. } else if (sm.cancel) {
  169. console.log('用户点击取消')
  170. }
  171. }
  172. })
  173. }*/
  174. },
  175. delitem:function(e){
  176. var that = this;
  177. var itemid = e.currentTarget.dataset.id;
  178. console.log('itemid',itemid);
  179. // wx.showModal({
  180. // title: '提示',
  181. // content: '需要删除改商品吗?',
  182. // success: function (sm) {
  183. // if (sm.confirm) {
  184. // var url = "/v1/cart/mult_delele";
  185. // var params = {
  186. // ids:itemid
  187. // }
  188. // var success = function (res) {
  189. // console.log(res)
  190. // if(res.data.result){
  191. //
  192. // }
  193. // that.getCartList();
  194. // }
  195. // _request.$post(url, params, success);
  196. // } else if (sm.cancel) {
  197. // console.log('用户点击取消')
  198. // }
  199. // }
  200. // })
  201. },
  202. changeCount: function (val) {
  203. var count = val.detail.value
  204. var itemid = val.target.dataset.id;
  205. var index = val.target.dataset.index;
  206. if (count <= 0) {
  207. this.setData({
  208. ['cartList[' + index + '].count']:1
  209. })
  210. this.checkSelected();
  211. // this.changeServercount(1,itemid);
  212. } /*else if (count > this.data.project.left_count) {
  213. this.setData({
  214. count: this.data.project.left_count
  215. })
  216. this.changeCountService(this.data.project.left_count,itemid)
  217. }*/ else {
  218. this.setData({
  219. ['cartList[' + index + '].count']:count
  220. })
  221. this.checkSelected();
  222. // this.changeServercount(count,itemid);
  223. }
  224. },
  225. changeServercount:function(val,itemid){
  226. console.log('changeCountService')
  227. var that = this
  228. var url = "/v1/cart/change_nums/" + itemid + "/" + val
  229. var params = {}
  230. var success = function (res) {
  231. console.log(res)
  232. if(res.result){
  233. //修改成功
  234. }
  235. }
  236. _request.$post(url, params, success);
  237. this.getCartList();
  238. },
  239. itemselected:function(e){
  240. console.log(this)
  241. var nowitems = this.data.selectedItems;
  242. let index = e.currentTarget.dataset.index;
  243. var bool = this.data.cartList[index].IsBuy;
  244. console.log('bool',bool)
  245. this.setData({
  246. ['cartList[' + index + '].IsBuy']: !bool
  247. })
  248. this.checkSelected();
  249. },
  250. allSelect:function(){
  251. if(this.data.selectedall){
  252. for(var i in this.data.cartList){
  253. this.setData({
  254. ['cartList[' + i + '].IsBuy']: false
  255. })
  256. }
  257. this.setData({
  258. selectedall: false
  259. })
  260. }else{
  261. for(var i in this.data.cartList){
  262. this.setData({
  263. ['cartList[' + i + '].IsBuy']: true
  264. })
  265. }
  266. this.setData({
  267. selectedall: true
  268. })
  269. }
  270. this.checkSelected();
  271. },
  272. checkSelected:function(){
  273. var cartList = this.data.cartList;
  274. var checkitem = '';
  275. var checkitemnum = '';
  276. var checktotal = 0;
  277. var checkcount = 0;
  278. // console.log('cartList',cartList)
  279. for(var i in cartList){
  280. if(cartList[i].IsBuy){
  281. checkitem = checkitem + cartList[i].id+',';
  282. checkitemnum = checkitemnum + cartList[i].count+',';
  283. checktotal = checktotal + (parseFloat(cartList[i].price) * parseInt(cartList[i].count));
  284. checkcount = checkcount + parseInt(cartList[i].count);
  285. }
  286. }
  287. checkitem = checkitem.substr(0,checkitem.length - 1);
  288. checkitemnum = checkitemnum.substr(0,checkitemnum.length - 1);
  289. this.setData({
  290. checkeditems:checkitem,
  291. checkeditemsnum:checkitemnum,
  292. cartCount: checkcount,
  293. cartTotal: checktotal
  294. })
  295. // this.mulChangeState();
  296. },
  297. mulChangeState:function(){
  298. var that = this;
  299. var itemid = this.data.checkeditems;
  300. var itemnum = this.data.checkeditemsnum;
  301. var url = "v1/cart/mult_change_state";
  302. var params = {
  303. ids:itemid,
  304. nums:itemnum
  305. }
  306. var success = function (res) {
  307. console.log('mulChangeState',res)
  308. if(res.data.result){
  309. that.getCartList();
  310. }
  311. }
  312. _request.$post(url, params, success);
  313. },
  314. mulChangeStateToPay:function(){
  315. var that = this;
  316. var lock = this.data.submitlock;
  317. if(!lock){
  318. that.setData({submitlock: true})
  319. var itemid = this.data.checkeditems;
  320. var itemnum = this.data.checkeditemsnum;
  321. var url = "v1/shop/order_mul";
  322. var params = {
  323. ids:itemid,
  324. nums:itemnum
  325. }
  326. var success = function (res) {
  327. wx.showToast({
  328. title: '正在跳转到结算页,请稍后~',
  329. icon: 'none',
  330. duration: 2000
  331. })
  332. console.log('mulChangeState',res)
  333. if (res.data.order_id) {
  334. wx.navigateTo({
  335. url: '../pay/pay?orderId=' + res.data.order_id
  336. })
  337. }
  338. }
  339. var err = function(err){
  340. console.log(err)
  341. that.setData({submitlock: false})
  342. }
  343. _request.$post(url, params, success, err);
  344. }
  345. },
  346. toPay:function(){
  347. var that = this;
  348. var url = "/v1/cart/order_mul";
  349. var params = {}
  350. var success = function (res) {
  351. console.log(res)
  352. if (res.data.order_id) {
  353. wx.navigateTo({
  354. url: '../pay/pay?orderId=' + res.data.order_id
  355. })
  356. }
  357. }
  358. _request.$get(url, params, success);
  359. },
  360. delSelected:function(){
  361. var that = this;
  362. var itemid = this.data.checkeditems;
  363. if(itemid== ''){
  364. wx.showToast({
  365. title: '没有选中任何商品~',
  366. icon: 'none',
  367. duration: 2000
  368. })
  369. }else{
  370. wx.showModal({
  371. title: '提示',
  372. content: '确定要删除选中的商品吗?',
  373. success: function (sm) {
  374. if (sm.confirm) {
  375. var url = "/v1/cart/mult_delele";
  376. var params = {
  377. ids:itemid
  378. }
  379. var success = function (res) {
  380. console.log(res)
  381. if(res.data.result){
  382. }
  383. that.getCartList();
  384. }
  385. _request.$post(url, params, success);
  386. } else if (sm.cancel) {
  387. console.log('用户点击取消')
  388. }
  389. }
  390. })
  391. }
  392. },
  393. toProject:function(val){
  394. var id = val.currentTarget.dataset.val
  395. wx.navigateTo({
  396. url: '/pages/projects/project-detail-noshare/project-detail-noshare?id=' + id + '&read=1'
  397. })
  398. },
  399. getIphoneX () {
  400. var that = this
  401. wx.getSystemInfo({
  402. success: function (res) {
  403. if (res.model.toLowerCase().indexOf('iphone x') > -1) {
  404. that.setData({
  405. value: 34
  406. })
  407. }
  408. }
  409. })
  410. },
  411. selectSize:function(val){
  412. var that = this
  413. var id = val.currentTarget.dataset.val
  414. that.setData({
  415. selectProjectid: id
  416. });
  417. console.log('id',id);
  418. that.getProjectDetail();
  419. that.getProductSize();
  420. var animation = wx.createAnimation({
  421. duration: 200,
  422. timingFunction: "ease-out"
  423. })
  424. this.animation = animation
  425. animation.translateY(500).step()
  426. this.setData({
  427. animationData: animation.export(),
  428. showDialog: true
  429. })
  430. setTimeout(function () {
  431. animation.translateY(0).step()
  432. this.setData({
  433. animationData: animation.export()
  434. })
  435. }.bind(this), 200)
  436. },
  437. getProjectDetail() {
  438. var that = this
  439. var url = "v1/product/" + that.data.selectProjectid;
  440. var params = {}
  441. var success = function (val) {
  442. var p = val.data.detail
  443. that.setData({
  444. selectProject: val.data
  445. });
  446. if(val.data.have_size){
  447. that.getProductSize();
  448. }
  449. }
  450. _request.$get(url, params, success)
  451. },
  452. getProductSize(){
  453. var that = this
  454. var url = "v1/product_size/" + that.data.selectProjectid;
  455. var params = {}
  456. var success = function (val) {
  457. let cbox = [];
  458. for(let i in val.data){
  459. if(i != 'product' && val.data[i]) cbox.push(i);
  460. }
  461. console.log('cbox',cbox)
  462. that.setData({
  463. selectProjectSize: val.data,
  464. checkbox:cbox
  465. });
  466. }
  467. _request.$get(url, params, success)
  468. }
  469. })