C端小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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