C端小程序
Não pode escolher mais do que 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.

292 linhas
7.1 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.wmhome.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.switchTab({
  50. url: '/pages/main/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. if (options.orderGroupId){
  73. if (options.orderId && options.couponId){
  74. this.getDetail(options);
  75. }
  76. this.checkUser(options);
  77. }
  78. // 关闭来自于左上角的分享
  79. wx.hideShareMenu()
  80. },
  81. /**
  82. * 判断用户是否已经在团中
  83. */
  84. checkUser(options) {
  85. let that = this;
  86. Http.get({
  87. url: config.api.queryAttendStatus,
  88. data: {
  89. id: options.orderGroupId,
  90. }
  91. }).then(res => {
  92. wx.stopPullDownRefresh();
  93. console.log(res.data, 3333333333)
  94. that.setData({
  95. isMyself: res.data.attend
  96. })
  97. });
  98. },
  99. /**
  100. * 去使用
  101. */
  102. gotoUse() {
  103. wx.navigateTo({
  104. url: `/pages/couponorder/index/index`
  105. });
  106. },
  107. /**
  108. * 拼团状态字段转换
  109. */
  110. changeSatus(status) {
  111. console.log(spellStatus, 8888888)
  112. return spellStatus.filter(item => item.value == status)[0].name;
  113. },
  114. // 时间格式化输出,如11:03 25:19 每1s都会调用一次
  115. dateformat(micro_second) {
  116. // 总秒数
  117. var second = Math.floor(micro_second / 1000);
  118. // 天数
  119. var day = Math.floor(second / 3600 / 24) < 10 ? "0" + Math.floor(second / 3600 / 24) : Math.floor(second / 3600 / 24);
  120. // 小时
  121. var hr = Math.floor(second / 3600 % 24) < 10 ? "0" + Math.floor(second / 3600 % 24) : Math.floor(second / 3600 % 24);
  122. // 分钟
  123. var min = Math.floor(second / 60 % 60) < 10 ? "0" + Math.floor(second / 60 % 60) : Math.floor(second / 60 % 60);
  124. // 秒
  125. var sec = Math.floor(second % 60) < 10 ? "0" + Math.floor(second % 60) : Math.floor(second % 60);
  126. // return day + "天" + hr + "小时" + min + "分钟" + sec + "秒";
  127. return {
  128. a1: day,
  129. b1: hr,
  130. c1: min,
  131. d1: sec
  132. }
  133. },
  134. countdown(time) {
  135. let that = this;
  136. var EndTime = time;
  137. if (that.data.data != null && that.data.data.status==10) {
  138. EndTime = that.data.data.expiredDate;
  139. }
  140. var NowTime = new Date().getTime();
  141. var total_micro_second = EndTime - NowTime || [];
  142. // 渲染倒计时时钟
  143. let obj = that.dateformat(total_micro_second);
  144. console.log(obj)
  145. if (total_micro_second > 0) {
  146. that.setData({
  147. clock: obj,
  148. day: obj.a1,
  149. hour: obj.b1,
  150. min: obj.c1,
  151. sec: obj.d1,
  152. })
  153. } else {
  154. that.setData({
  155. // data:null,
  156. clock: "00",
  157. day: "00",
  158. hour: "00",
  159. min: "00",
  160. sec: "00",
  161. })
  162. // that.getOneSpell(that.data.couponId)
  163. }
  164. if (that.data.showTime) {
  165. setTimeout(function () {
  166. total_micro_second -= 1000;
  167. that.countdown();
  168. }, 1000)
  169. }
  170. },
  171. //关闭弹框
  172. gotoClose() {
  173. this.setData({
  174. showAlert: false
  175. })
  176. },
  177. //跳转拼团列表
  178. gotoSpellList() {
  179. wx.navigateTo({
  180. url: '/pages/spellGroup/spellGroup',
  181. })
  182. },
  183. getDetail() {
  184. let that = this;
  185. Http.get({
  186. url: config.api.queryOrderGroupStatus,
  187. data: {
  188. orderId: this.data.paramData.orderId,
  189. couponId: this.data.paramData.couponId,
  190. id: this.data.paramData.orderGroupId
  191. }
  192. }).then(res => {
  193. wx.stopPullDownRefresh();
  194. let data = res.data;
  195. data.statustext = that.changeSatus(data.status);
  196. if (data.status ==10) {
  197. that.countdown(data.expiredDate);
  198. }
  199. data.salePrice = (data.salePrice / 100).toFixed(2)
  200. for (let i = 0; i < data.remainPeople; i++) {
  201. let a = {};
  202. data.userList.push(a)
  203. }
  204. if (res.data.couponStatus != 0) {
  205. that.setData({
  206. showAlert: true
  207. })
  208. }
  209. that.setData({
  210. data: res.data
  211. })
  212. });
  213. },
  214. /**
  215. * 生命周期函数--监听页面初次渲染完成
  216. */
  217. onReady: function () {
  218. },
  219. /**
  220. * 生命周期函数--监听页面显示
  221. */
  222. onShow: function () {
  223. this.setData({
  224. showTime: true
  225. })
  226. if (this.data.data != null&&this.data.data.status ==10) {
  227. this.countdown()
  228. }
  229. },
  230. /**
  231. * 生命周期函数--监听页面隐藏
  232. */
  233. onHide: function () {
  234. this.setData({
  235. showTime: false
  236. })
  237. },
  238. /**
  239. * 生命周期函数--监听页面卸载
  240. */
  241. onUnload: function () {
  242. this.setData({
  243. showTime: false
  244. })
  245. },
  246. /**
  247. * 页面相关事件处理函数--监听用户下拉动作
  248. */
  249. onPullDownRefresh: function () {
  250. this.getDetail(this.data.paramData);
  251. this.checkUser(this.data.paramData)
  252. },
  253. /**
  254. * 页面上拉触底事件的处理函数
  255. */
  256. onReachBottom: function () {
  257. },
  258. /**
  259. * 用户点击右上角分享
  260. */
  261. // paramData
  262. onShareAppMessage: function (res) {
  263. if (res.from === 'button') {
  264. console.log(res, this.data.nickName, this.data.avatarUrl, 3333333333333333333333)
  265. // 来自页面内转发按钮
  266. let _this = this;
  267. return {
  268. title: _this.data.nickName + '超值推荐的' + _this.data.data.title,
  269. 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}`,
  270. imageUrl: _this.data.data.coverImg,
  271. success: function (res) {
  272. // 转发成功
  273. },
  274. fail: function (res) {
  275. // 转发失败
  276. }
  277. }
  278. } else {
  279. console.log(res, 444444444444444444)
  280. }
  281. }
  282. })