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