C端小程序
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

270 linhas
6.5 KiB

  1. // pages/spellDetail/index.js
  2. var config = require("../../config/config.js");
  3. const Http = require("../../utils/HttpBasics");
  4. const imgurl = require("../../utils/imgurl");
  5. const { spellStatus } = require("../../utils/spell");
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. tuanzhang: imgurl.tuanzhang.url,
  12. spellBg: imgurl.spellBg.url,
  13. position: imgurl.position.url,
  14. close03: imgurl.close03.url,
  15. home: imgurl.home.url,
  16. paramData: null,
  17. data: null,
  18. clock: "00",
  19. day: "0",
  20. hour: "00",
  21. min: "00",
  22. sec: "00",
  23. spellStatusList: spellStatus,
  24. isMyself: false,
  25. showAlert: false
  26. },
  27. gotoAgain() {
  28. let data = this.data.data;
  29. wx.navigateTo({
  30. url: `/pages/spellGroup/mySpellGroup/index?couponId=${data.couponId}&couponChannelId=${data.couponChannelId}`,
  31. })
  32. },
  33. getUserInfo: function () {
  34. let that = this;
  35. // 获取用户信息
  36. Http.get({
  37. url: config.api.getScore,
  38. data: {}
  39. })
  40. .then(res => {
  41. console.log(res)
  42. that.setData({
  43. nickName: res.data.nickName,
  44. avatarUrl: res.data.avatarUrl
  45. })
  46. })
  47. },
  48. gotoIndex(){
  49. wx.reLaunch({
  50. url: '/pages/index/index',
  51. })
  52. },
  53. gotoshare() {
  54. wx.navigateTo({
  55. url: `/pages/spellGroup/mySpellGroup/index?orderId=${this.data.paramData.orderId}&couponId=${this.data.paramData.couponId}&orderGroupId=${this.data.paramData.orderGroupId}&couponChannelId=${this.data.paramData.couponChannelId}`,
  56. })
  57. },
  58. gotoSearch() {
  59. wx.navigateTo({
  60. url: `/pages/spellGroup/spellGroup`,
  61. })
  62. },
  63. /**
  64. * 生命周期函数--监听页面加载
  65. */
  66. onLoad: function (options) {
  67. console.log(this.data.spellStatusList, options, 7777777)
  68. this.setData({
  69. paramData: options
  70. })
  71. this.getUserInfo()
  72. this.getDetail(options);
  73. this.checkUser(options)
  74. // 关闭来自于左上角的分享
  75. wx.hideShareMenu()
  76. },
  77. /**
  78. * 判断用户是否已经在团中
  79. */
  80. checkUser(options) {
  81. let that = this;
  82. Http.get({
  83. url: config.api.queryAttendStatus,
  84. data: {
  85. id: options.orderGroupId,
  86. }
  87. }).then(res => {
  88. wx.stopPullDownRefresh();
  89. console.log(res.data, 3333333333)
  90. that.setData({
  91. isMyself: res.data.attend
  92. })
  93. });
  94. },
  95. /**
  96. * 去使用
  97. */
  98. gotoUse() {
  99. wx.navigateTo({
  100. url: `/pages/couponorder/index/index`
  101. });
  102. },
  103. /**
  104. * 拼团状态字段转换
  105. */
  106. changeSatus(status) {
  107. console.log(spellStatus, 8888888)
  108. return spellStatus.filter(item => item.value == status)[0].name;
  109. },
  110. // 时间格式化输出,如11:03 25:19 每1s都会调用一次
  111. dateformat(micro_second) {
  112. // 总秒数
  113. var second = Math.floor(micro_second / 1000);
  114. // 天数
  115. var day = Math.floor(second / 3600 / 24) < 10 ? "0" + Math.floor(second / 3600 / 24) : Math.floor(second / 3600 / 24);
  116. // 小时
  117. var hr = Math.floor(second / 3600 % 24) < 10 ? "0" + Math.floor(second / 3600 % 24) : Math.floor(second / 3600 % 24);
  118. // 分钟
  119. var min = Math.floor(second / 60 % 60) < 10 ? "0" + Math.floor(second / 60 % 60) : Math.floor(second / 60 % 60);
  120. // 秒
  121. var sec = Math.floor(second % 60) < 10 ? "0" + Math.floor(second % 60) : Math.floor(second % 60);
  122. // return day + "天" + hr + "小时" + min + "分钟" + sec + "秒";
  123. return {
  124. a1: day,
  125. b1: hr,
  126. c1: min,
  127. d1: sec
  128. }
  129. },
  130. countdown(end_time) {
  131. let that = this;
  132. var EndTime = end_time;
  133. var NowTime = new Date().getTime();
  134. var total_micro_second = EndTime - NowTime || [];
  135. // 渲染倒计时时钟
  136. let obj = that.dateformat(total_micro_second);
  137. if (total_micro_second > 0) {
  138. that.setData({
  139. clock: obj,
  140. day: obj.a1,
  141. hour: obj.b1,
  142. min: obj.c1,
  143. sec: obj.d1,
  144. })
  145. } else {
  146. that.setData({
  147. clock: "00",
  148. day: "0",
  149. hour: "00",
  150. min: "00",
  151. sec: "00",
  152. })
  153. }
  154. setTimeout(function () {
  155. total_micro_second -= 1000;
  156. that.countdown(end_time);
  157. }, 1000)
  158. },
  159. //关闭弹框
  160. gotoClose() {
  161. this.setData({
  162. showAlert: false
  163. })
  164. },
  165. //跳转拼团列表
  166. gotoSpellList() {
  167. wx.navigateTo({
  168. url: '/pages/spellGroup/spellGroup',
  169. })
  170. },
  171. getDetail() {
  172. let that = this;
  173. Http.get({
  174. url: config.api.queryOrderGroupStatus,
  175. data: {
  176. orderId: this.data.paramData.orderId,
  177. couponId: this.data.paramData.couponId,
  178. id: this.data.paramData.orderGroupId
  179. }
  180. }).then(res => {
  181. wx.stopPullDownRefresh();
  182. let data = res.data;
  183. data.statustext = that.changeSatus(data.status);
  184. if (data.status != 11) {
  185. that.countdown(data.expiredDate);
  186. }
  187. data.salePrice = (data.salePrice / 100).toFixed(2)
  188. for (let i = 0; i < data.remainPeople; i++) {
  189. let a = {};
  190. data.userList.push(a)
  191. }
  192. if (res.data.couponStatus != 0) {
  193. that.setData({
  194. showAlert: true
  195. })
  196. }
  197. that.setData({
  198. data: res.data
  199. })
  200. });
  201. },
  202. /**
  203. * 生命周期函数--监听页面初次渲染完成
  204. */
  205. onReady: function () {
  206. },
  207. /**
  208. * 生命周期函数--监听页面显示
  209. */
  210. onShow: function () {
  211. },
  212. /**
  213. * 生命周期函数--监听页面隐藏
  214. */
  215. onHide: function () {
  216. },
  217. /**
  218. * 生命周期函数--监听页面卸载
  219. */
  220. onUnload: function () {
  221. },
  222. /**
  223. * 页面相关事件处理函数--监听用户下拉动作
  224. */
  225. onPullDownRefresh: function () {
  226. this.getDetail(this.data.paramData);
  227. this.checkUser(this.data.paramData)
  228. },
  229. /**
  230. * 页面上拉触底事件的处理函数
  231. */
  232. onReachBottom: function () {
  233. },
  234. /**
  235. * 用户点击右上角分享
  236. */
  237. // paramData
  238. onShareAppMessage: function (res) {
  239. if (res.from === 'button') {
  240. console.log(res, this.data.nickName, this.data.avatarUrl, 3333333333333333333333)
  241. // 来自页面内转发按钮
  242. let _this = this;
  243. return {
  244. title: '拼团',
  245. path: `/pages/index/index?couponId=${_this.data.data.couponId}&orderGroupId=${_this.data.data.orderGroupId}&couponChannelId=${_this.data.paramData.couponChannelId}&orderId=${_this.data.data.orderId}&avatarUrl=${_this.data.avatarUrl}&nickName=${_this.data.nickName}`,
  246. imageUrl: _this.data.data.coverImg,
  247. success: function (res) {
  248. // 转发成功
  249. },
  250. fail: function (res) {
  251. // 转发失败
  252. }
  253. }
  254. } else {
  255. console.log(res, 444444444444444444)
  256. }
  257. }
  258. })