cart.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. (global.webpackJsonp = global.webpackJsonp || []).push([ [ "pages/cart/cart" ], {
  2. 158: function(t, e, n) {
  3. (function(t) {
  4. function e(t) {
  5. return t && t.__esModule ? t : {
  6. default: t
  7. };
  8. }
  9. n(4), e(n(2)), t(e(n(159)).default);
  10. }).call(this, n(1).createPage);
  11. },
  12. 159: function(t, e, n) {
  13. n.r(e);
  14. var r = n(160), c = n(162);
  15. for (var i in c) "default" !== i && function(t) {
  16. n.d(e, t, function() {
  17. return c[t];
  18. });
  19. }(i);
  20. n(165);
  21. var a = n(13), o = Object(a.default)(c.default, r.render, r.staticRenderFns, !1, null, null, null, !1, r.components, void 0);
  22. o.options.__file = "pages/cart/cart.vue", e.default = o.exports;
  23. },
  24. 160: function(t, e, n) {
  25. n.r(e);
  26. var r = n(161);
  27. n.d(e, "render", function() {
  28. return r.render;
  29. }), n.d(e, "staticRenderFns", function() {
  30. return r.staticRenderFns;
  31. }), n.d(e, "recyclableRender", function() {
  32. return r.recyclableRender;
  33. }), n.d(e, "components", function() {
  34. return r.components;
  35. });
  36. },
  37. 161: function(t, e, n) {
  38. n.r(e), n.d(e, "render", function() {
  39. return r;
  40. }), n.d(e, "staticRenderFns", function() {
  41. return i;
  42. }), n.d(e, "recyclableRender", function() {
  43. return c;
  44. }), n.d(e, "components", function() {});
  45. var r = function() {
  46. var t = this;
  47. t.$createElement;
  48. t._self._c, t._isMounted || (t.e0 = function(e) {
  49. t.allChecked && t.clearCart();
  50. });
  51. }, c = !1, i = [];
  52. r._withStripped = !0;
  53. },
  54. 162: function(t, e, n) {
  55. n.r(e);
  56. var r = n(163), c = n.n(r);
  57. for (var i in r) "default" !== i && function(t) {
  58. n.d(e, t, function() {
  59. return r[t];
  60. });
  61. }(i);
  62. e.default = c.a;
  63. },
  64. 163: function(t, e, n) {
  65. (function(t) {
  66. function r(t, e, n, r, c, i, a) {
  67. try {
  68. var o = t[i](a), u = o.value;
  69. } catch (t) {
  70. return void n(t);
  71. }
  72. o.done ? e(u) : Promise.resolve(u).then(r, c);
  73. }
  74. function c(t) {
  75. return function() {
  76. var e = this, n = arguments;
  77. return new Promise(function(c, i) {
  78. function a(t) {
  79. r(u, c, i, a, o, "next", t);
  80. }
  81. function o(t) {
  82. r(u, c, i, a, o, "throw", t);
  83. }
  84. var u = t.apply(e, n);
  85. a(void 0);
  86. });
  87. };
  88. }
  89. function i(t, e) {
  90. var n = Object.keys(t);
  91. if (Object.getOwnPropertySymbols) {
  92. var r = Object.getOwnPropertySymbols(t);
  93. e && (r = r.filter(function(e) {
  94. return Object.getOwnPropertyDescriptor(t, e).enumerable;
  95. })), n.push.apply(n, r);
  96. }
  97. return n;
  98. }
  99. function a(t, e, n) {
  100. return e in t ? Object.defineProperty(t, e, {
  101. value: n,
  102. enumerable: !0,
  103. configurable: !0,
  104. writable: !0
  105. }) : t[e] = n, t;
  106. }
  107. Object.defineProperty(e, "__esModule", {
  108. value: !0
  109. }), e.default = void 0;
  110. var o = function(t) {
  111. return t && t.__esModule ? t : {
  112. default: t
  113. };
  114. }(n(23)), u = n(164), s = {
  115. components: {
  116. uniNumberBox: function() {
  117. n.e("components/uni-number-box").then(function() {
  118. return resolve(n(504));
  119. }.bind(null, n)).catch(n.oe);
  120. }
  121. },
  122. data: function() {
  123. return {
  124. total: 0,
  125. allChecked: !1,
  126. empty: !1,
  127. cartList: []
  128. };
  129. },
  130. onShow: function() {
  131. this.hasLogin && this.loadData();
  132. },
  133. watch: {
  134. cartList: function(t) {
  135. var e = 0 === t.length;
  136. this.empty !== e && (this.empty = e);
  137. }
  138. },
  139. computed: function(t) {
  140. for (var e = 1; e < arguments.length; e++) {
  141. var n = null != arguments[e] ? arguments[e] : {};
  142. e % 2 ? i(Object(n), !0).forEach(function(e) {
  143. a(t, e, n[e]);
  144. }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(t, Object.getOwnPropertyDescriptors(n)) : i(Object(n)).forEach(function(e) {
  145. Object.defineProperty(t, e, Object.getOwnPropertyDescriptor(n, e));
  146. });
  147. }
  148. return t;
  149. }({}, (0, n(6).mapState)("user", [ "hasLogin" ])),
  150. methods: {
  151. loadData: function() {
  152. var t = this;
  153. return c(o.default.mark(function e() {
  154. var n;
  155. return o.default.wrap(function(e) {
  156. for (;;) switch (e.prev = e.next) {
  157. case 0:
  158. n = t, (0, u.getCartList)({}).then(function(t) {
  159. n.cartList.length;
  160. var e = n.cartList.reverse(), r = t.data.valid.reverse();
  161. n.cartList = r.map(function(t, n) {
  162. t.checked = !0;
  163. var r = e[n];
  164. return r && "loaded" == r.loaded && (t.loaded = "loaded"), t;
  165. }).reverse(), n.calcTotal();
  166. }).catch(function(t) {
  167. console.log(t);
  168. });
  169. case 2:
  170. case "end":
  171. return e.stop();
  172. }
  173. }, e);
  174. }))();
  175. },
  176. onImageLoad: function(t, e) {
  177. this.$set(this[t][e], "loaded", "loaded");
  178. },
  179. onImageError: function(t, e) {
  180. this[t][e].image = "/static/error/errorImage.jpg";
  181. },
  182. navToLogin: function() {
  183. var e = "/pages/public/login";
  184. e = "/pages/public/wxLogin", t.navigateTo({
  185. url: e
  186. });
  187. },
  188. check: function(t, e) {
  189. if ("item" === t) this.cartList[e].checked = !this.cartList[e].checked; else {
  190. var n = !this.allChecked;
  191. this.cartList.forEach(function(t) {
  192. t.checked = n;
  193. }), this.allChecked = n;
  194. }
  195. this.calcTotal(t);
  196. },
  197. numberChange: function(t) {
  198. var e = this.cartList[t.index];
  199. e.cart_num = t.number, (0, u.getCartNum)({
  200. id: e.id,
  201. number: t.number
  202. }), this.calcTotal();
  203. },
  204. deleteCartItem: function(e) {
  205. var n = this.cartList[e].id;
  206. (0, u.cartDel)({
  207. ids: n
  208. }), this.cartList.splice(e, 1), t.hideLoading(), this.calcTotal();
  209. },
  210. clearCart: function() {
  211. var e = this;
  212. t.showModal({
  213. content: "清空购物车?",
  214. success: function(t) {
  215. if (t.confirm) {
  216. var n = e.cartList.map(function(t) {
  217. return t.id;
  218. });
  219. (0, u.cartDel)({
  220. ids: n.join(",")
  221. }).then(function(t) {}), e.cartList = [];
  222. }
  223. }
  224. });
  225. },
  226. calcTotal: function() {
  227. var t = this.cartList;
  228. if (0 !== t.length) {
  229. var e = 0, n = !0;
  230. t.forEach(function(t) {
  231. !0 === t.checked ? e += t.truePrice * t.cart_num : !0 === n && (n = !1);
  232. }), this.allChecked = n, this.total = Number(e.toFixed(2));
  233. } else this.empty = !0;
  234. },
  235. createOrder: function() {
  236. var e = [];
  237. this.cartList.forEach(function(t) {
  238. t.checked && e.push(t.id);
  239. }), t.navigateTo({
  240. url: "/pages/order/createOrder?id=" + e.join(",")
  241. });
  242. }
  243. }
  244. };
  245. e.default = s;
  246. }).call(this, n(1).default);
  247. },
  248. 165: function(t, e, n) {
  249. n.r(e);
  250. var r = n(166), c = n.n(r);
  251. for (var i in r) "default" !== i && function(t) {
  252. n.d(e, t, function() {
  253. return r[t];
  254. });
  255. }(i);
  256. e.default = c.a;
  257. },
  258. 166: function(t, e, n) {}
  259. }, [ [ 158, "common/runtime", "common/vendor" ] ] ]);