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.

285 lines
7.2 KiB

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