C端小程序
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

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