1
0

joinGroup.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. var app = getApp();
  2. var util = require('../../utils/util.js');
  3. var goodsUtil = require('../../utils/goods.js');
  4. var api = require('../../config/api.js');
  5. Page({
  6. data: {
  7. groupId: 0,
  8. openId: 0,
  9. type: 0,
  10. goods: {},
  11. group: {},
  12. specificationList: [],
  13. productList: [],
  14. attendList: [],
  15. groupList: [],
  16. number: 1,
  17. min_open_group: 0,
  18. attend_num: 0,
  19. checkedSpecText: '请选择规格数量',
  20. openAttr: false,
  21. showPage: false,
  22. page: 1,
  23. size: 6,
  24. count: 0,
  25. selfStatus: 0,// 本人参与的是否被取消 0正常 1取消
  26. groupEnd: {}
  27. },
  28. //获取商品信息
  29. getGoodsInfo: function () {
  30. let that = this;
  31. util.request(api.GroupDetail, { id: that.data.groupId }).then(function (res) {
  32. if (res.errno === 0) {
  33. that.setData({
  34. group: res.data.groupVo,
  35. goods: res.data.info,
  36. specificationList: res.data.specificationList,
  37. productList: res.data.productList
  38. });
  39. //
  40. let _specificationList = res.data.specificationList;
  41. for (let i = 0; i < _specificationList.length; i++) {
  42. if (_specificationList[i].valueList.length == 1) {
  43. //如果已经选中,则反选
  44. _specificationList[i].valueList[0].checked = true;
  45. }
  46. }
  47. that.setData({
  48. 'specificationList': _specificationList
  49. });
  50. }
  51. });
  52. },
  53. //获取已经参与的人
  54. getAttendList() {
  55. let that = this;
  56. util.request(api.AttendList, { openId: that.data.openId }).then(function (res) {
  57. if (res.errno === 0) {
  58. that.setData({
  59. attendList: res.data
  60. });
  61. }
  62. if (res.data.length > 0) {
  63. for (let i = 0; i < res.data.length; i++) {
  64. if (res.data[i].user_id == wx.getStorageSync('userId')) {
  65. that.setData({
  66. type: 1
  67. })
  68. if (res.data[i].attend_status == 3) {
  69. that.setData({
  70. selfStatus: 1
  71. })
  72. }
  73. }
  74. }
  75. }
  76. });
  77. },
  78. clickSkuValue: function (event) {
  79. let that = this;
  80. let specNameId = event.currentTarget.dataset.nameId;
  81. let specValueId = event.currentTarget.dataset.valueId;
  82. //判断是否可以点击
  83. //TODO 性能优化,可在wx:for中添加index,可以直接获取点击的属性名和属性值,不用循环
  84. let _specificationList = this.data.specificationList;
  85. for (let i = 0; i < _specificationList.length; i++) {
  86. if (_specificationList[i].specification_id == specNameId) {
  87. for (let j = 0; j < _specificationList[i].valueList.length; j++) {
  88. if (_specificationList[i].valueList[j].id == specValueId) {
  89. //如果已经选中,则反选
  90. if (_specificationList[i].valueList[j].checked) {
  91. _specificationList[i].valueList[j].checked = false;
  92. } else {
  93. _specificationList[i].valueList[j].checked = true;
  94. }
  95. } else {
  96. _specificationList[i].valueList[j].checked = false;
  97. }
  98. }
  99. }
  100. }
  101. this.setData({
  102. 'specificationList': _specificationList
  103. });
  104. //重新计算spec改变后的信息
  105. goodsUtil.changeSpecInfo(that);
  106. },
  107. //根据已选的值,计算其它值的状态
  108. setSpecValueStatus: function () {
  109. },
  110. onLoad: function (options) {
  111. // 页面初始化 options为页面跳转所带来的参数
  112. let para = {
  113. end_time: parseInt(options.end_time)
  114. };
  115. this.setData({
  116. groupId: parseInt(options.groupId),
  117. openId: parseInt(options.openId),
  118. min_open_group: parseInt(options.min_open_group),
  119. attend_num: parseInt(options.attend_num),
  120. groupEnd: para
  121. });
  122. util.countdown(this, para, 'groupEnd', null)
  123. this.getGoodsInfo()
  124. this.getAttendList()
  125. this.getTopic()
  126. },
  127. onReady: function () {
  128. },
  129. onShow: function () {
  130. // 页面显示
  131. },
  132. onHide: function () {
  133. // 页面隐藏
  134. this.setData({
  135. openAttr: false
  136. })
  137. },
  138. onUnload: function () {
  139. // 页面关闭
  140. },
  141. getTopic: function () {
  142. let that = this;
  143. that.setData({
  144. groupList: []
  145. });
  146. util.request(api.GroupList, { page: that.data.page, size: that.data.size }).then(function (res) {
  147. if (res.errno === 0) {
  148. that.setData({
  149. groupList: res.data.data
  150. })
  151. }
  152. })
  153. },
  154. switchAttrPop: function () {
  155. this.setData({
  156. openAttr: !this.data.openAttr
  157. })
  158. },
  159. cutNumber: function () {
  160. this.setData({
  161. number: (this.data.number - 1 > 1) ? this.data.number - 1 : 1
  162. });
  163. },
  164. addNumber: function () {
  165. this.setData({
  166. number: this.data.number + 1
  167. });
  168. },
  169. checkProduct: function () {
  170. var that = this;
  171. if (this.data.openAttr == false) {
  172. //打开规格选择窗口
  173. this.setData({
  174. openAttr: !this.data.openAttr,
  175. collectBackImage: "/static/images/detail_back.png"
  176. });
  177. } else {
  178. //提示选择完整规格
  179. if (!goodsUtil.isCheckedAllSpec(that)) {
  180. return false;
  181. }
  182. //根据选中的规格,判断是否有对应的sku信息
  183. let checkedProduct = goodsUtil.getCheckedProductItem(goodsUtil.getCheckedSpecKey(that), that);
  184. if (!checkedProduct || checkedProduct.length <= 0) {
  185. //找不到对应的product信息,提示没有库存
  186. return false;
  187. }
  188. //验证库存
  189. if (checkedProduct.goods_number < this.data.number) {
  190. //找不到对应的product信息,提示没有库存
  191. return false;
  192. }
  193. wx.navigateTo({
  194. url: '/pages/shopping/groupcheck/groupcheck?number=' + this.data.number + '&productId=' + checkedProduct[0].id
  195. + '&openId=' + this.data.openId + '&groupId=' + this.data.groupId,
  196. })
  197. }
  198. },
  199. switchNav(event) {
  200. wx.switchTab({
  201. url: '/pages/index/index'
  202. });
  203. },
  204. onShareAppMessage: function () {
  205. var that = this;
  206. return {
  207. title: that.data.goods.name,
  208. desc: null != that.data.group.ad_desc ? that.data.group.ad_desc : "商业版",
  209. imageUrl: '',
  210. path: '/pages/joinGroup/joinGroup?openId=' + that.data.openId + '&groupId=' + that.data.groupId
  211. + '&goodsId=' + that.data.goodsId
  212. + '&min_open_group=' + that.data.min_open_group
  213. + '&attend_num=' + that.data.attend_num
  214. + '&end_time=' + that.data.groupEnd.end_time,
  215. success: function (res) {
  216. console.log("转发成功");
  217. // 转发成功
  218. },
  219. fail: function (res) {
  220. // 转发失败
  221. console.log("转发失败");
  222. }
  223. }
  224. }
  225. })