public.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. var app = getApp(), flag = true;
  2. /**
  3. * 加入购物车
  4. */
  5. function addToCart(data, fn) {
  6. if (flag){
  7. flag = false;
  8. // 请求数据
  9. // 成功
  10. wx.hideLoading();
  11. wx.showToast({
  12. title: "已加入购物车",
  13. image: "../../images/addShopCart.png"
  14. })
  15. flag = true;
  16. app.globalData.cartNum += data.goodsNum;
  17. fn && fn();
  18. // 失败
  19. flag = true;
  20. fn && fn();
  21. }
  22. }
  23. /**
  24. * 购物车提交
  25. */
  26. function skuConfirm(data, fn) {
  27. //请求
  28. //成功
  29. fn && fn();
  30. // app.globalData.settleInfo = res.data;
  31. wx.navigateTo({
  32. url: "/lionfish_comshop/pages/order/placeOrder"
  33. });
  34. // 失败
  35. // 100008 === t.head.error && wx.showToast({
  36. // title: "购买单数已达到上限,无法购买此商品",
  37. // icon: "none"
  38. // });
  39. }
  40. /**
  41. * 手机formID
  42. */
  43. function collectFormIds(e) {
  44. console.log(e)
  45. var formIds = app.globalData.formIds;
  46. if (!formIds)
  47. {
  48. formIds = [];
  49. }
  50. formIds.push(e), app.globalData.formIds = formIds;
  51. var token = wx.getStorageSync('token');
  52. app.util.request({
  53. 'url': 'entry/wxapp/index',
  54. 'data': {
  55. controller: 'user.get_member_form_id',
  56. token: token,
  57. from_id: e
  58. },
  59. dataType: 'json',
  60. success: function (res) {
  61. }
  62. })
  63. }
  64. /**
  65. * 手机验证
  66. */
  67. function checkMobile(t) {
  68. return /^1[1-9][0-9]\d{8}$/.test(t);
  69. }
  70. /**
  71. * 身份证验证
  72. */
  73. function isIdCard(t) {
  74. return /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(t);
  75. }
  76. module.exports = {
  77. addToCart,
  78. skuConfirm,
  79. collectFormIds,
  80. checkMobile,
  81. isIdCard
  82. }