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.

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