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.

287 rivejä
7.0 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(time) {
  131. let that = this;
  132. var EndTime = time;
  133. if (that.data.data != null && that.data.data.status==10) {
  134. EndTime = that.data.data.expiredDate;
  135. }
  136. var NowTime = new Date().getTime();
  137. var total_micro_second = EndTime - NowTime || [];
  138. // 渲染倒计时时钟
  139. let obj = that.dateformat(total_micro_second);
  140. console.log(obj)
  141. if (total_micro_second > 0) {
  142. that.setData({
  143. clock: obj,
  144. day: obj.a1,
  145. hour: obj.b1,
  146. min: obj.c1,
  147. sec: obj.d1,
  148. })
  149. } else {
  150. that.setData({
  151. // data:null,
  152. clock: "00",
  153. day: "00",
  154. hour: "00",
  155. min: "00",
  156. sec: "00",
  157. })
  158. // that.getOneSpell(that.data.couponId)
  159. }
  160. if (that.data.showTime) {
  161. setTimeout(function () {
  162. total_micro_second -= 1000;
  163. that.countdown();
  164. }, 1000)
  165. }
  166. },
  167. //关闭弹框
  168. gotoClose() {
  169. this.setData({
  170. showAlert: false
  171. })
  172. },
  173. //跳转拼团列表
  174. gotoSpellList() {
  175. wx.navigateTo({
  176. url: '/pages/spellGroup/spellGroup',
  177. })
  178. },
  179. getDetail() {
  180. let that = this;
  181. Http.get({
  182. url: config.api.queryOrderGroupStatus,
  183. data: {
  184. orderId: this.data.paramData.orderId,
  185. couponId: this.data.paramData.couponId,
  186. id: this.data.paramData.orderGroupId
  187. }
  188. }).then(res => {
  189. wx.stopPullDownRefresh();
  190. let data = res.data;
  191. data.statustext = that.changeSatus(data.status);
  192. if (data.status ==10) {
  193. that.countdown(data.expiredDate);
  194. }
  195. data.salePrice = (data.salePrice / 100).toFixed(2)
  196. for (let i = 0; i < data.remainPeople; i++) {
  197. let a = {};
  198. data.userList.push(a)
  199. }
  200. if (res.data.couponStatus != 0) {
  201. that.setData({
  202. showAlert: true
  203. })
  204. }
  205. that.setData({
  206. data: res.data
  207. })
  208. });
  209. },
  210. /**
  211. * 生命周期函数--监听页面初次渲染完成
  212. */
  213. onReady: function () {
  214. },
  215. /**
  216. * 生命周期函数--监听页面显示
  217. */
  218. onShow: function () {
  219. this.setData({
  220. showTime: true
  221. })
  222. if (this.data.data != null&&this.data.data.status ==10) {
  223. this.countdown()
  224. }
  225. },
  226. /**
  227. * 生命周期函数--监听页面隐藏
  228. */
  229. onHide: function () {
  230. this.setData({
  231. showTime: false
  232. })
  233. },
  234. /**
  235. * 生命周期函数--监听页面卸载
  236. */
  237. onUnload: function () {
  238. this.setData({
  239. showTime: false
  240. })
  241. },
  242. /**
  243. * 页面相关事件处理函数--监听用户下拉动作
  244. */
  245. onPullDownRefresh: function () {
  246. this.getDetail(this.data.paramData);
  247. this.checkUser(this.data.paramData)
  248. },
  249. /**
  250. * 页面上拉触底事件的处理函数
  251. */
  252. onReachBottom: function () {
  253. },
  254. /**
  255. * 用户点击右上角分享
  256. */
  257. // paramData
  258. onShareAppMessage: function (res) {
  259. if (res.from === 'button') {
  260. console.log(res, this.data.nickName, this.data.avatarUrl, 3333333333333333333333)
  261. // 来自页面内转发按钮
  262. let _this = this;
  263. return {
  264. title: '拼团',
  265. 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}`,
  266. imageUrl: _this.data.data.coverImg,
  267. success: function (res) {
  268. // 转发成功
  269. },
  270. fail: function (res) {
  271. // 转发失败
  272. }
  273. }
  274. } else {
  275. console.log(res, 444444444444444444)
  276. }
  277. }
  278. })