C端小程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

286 行
6.4 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. gotoSearch() {
  54. wx.navigateTo({
  55. url: `/pages/spellGroup/spellGroup`,
  56. })
  57. },
  58. /**
  59. * 生命周期函数--监听页面加载
  60. */
  61. onLoad: function (options) {
  62. console.log(this.data.spellStatusList, options, 7777777)
  63. this.setData({
  64. paramData: options
  65. })
  66. this.getUserInfo();
  67. if (options.orderGroupId){
  68. if (options.orderId && options.couponId){
  69. this.getDetail(options);
  70. }
  71. }
  72. // 关闭来自于左上角的分享
  73. wx.hideShareMenu()
  74. },
  75. /**
  76. * 去拼团
  77. */
  78. goToOrderGroup(orderId, orderGroupId, _this){
  79. console.log(22222222)
  80. let that = this;
  81. // 支付成功
  82. Http.post({
  83. url: config.api.toOrderGroup,
  84. data: {
  85. id: orderGroupId,
  86. orderId,
  87. couponId: _this.data.data.couponId
  88. }
  89. })
  90. .then(res => {
  91. wx.redirectTo({
  92. url: `/pages/spellDetail/index?orderId=${orderId}&couponId=${_this.data.paramData.couponId}&orderGroupId=${res.data.orderGroupId}&couponChannelId=${_this.data.paramData.couponChannelId}`
  93. });
  94. })
  95. .catch(err => {
  96. console.log(err);
  97. })
  98. // return;
  99. },
  100. /**
  101. * 支付订单更新
  102. */
  103. payOrderUpdate: (orderId, payOrderId, status, reason, _this, orderGroupId) => {
  104. console.log(orderGroupId,7777)
  105. let that = this;
  106. // 支付成功
  107. Http.post({
  108. url: config.api.payOrderUpdate,
  109. data: {
  110. payOrderId: payOrderId,
  111. orderId: orderId,
  112. status: status,
  113. reason: reason
  114. }
  115. })
  116. .then(res => {
  117. wx.hideLoading()
  118. if (orderGroupId==undefined){
  119. wx.navigateTo({
  120. url: '/pages/order/detail/index?orderId='+res.data.id,
  121. })
  122. }else{
  123. _this.goToOrderGroup(orderId, res.data.orderGroupId, _this)
  124. }
  125. })
  126. .catch(err => {
  127. console.log(err);
  128. if (err.code!=12002){
  129. setTimeout(function () {
  130. _this.payOrderUpdate(orderId, payOrderId, status, reason, _this, orderGroupId);
  131. }, 2000)
  132. }
  133. })
  134. },
  135. gotoPay(){
  136. let that=this;
  137. wx.showLoading({
  138. title: '支付创建中...',
  139. })
  140. Http.post({
  141. url: config.api.payOrderCreate,
  142. data: {
  143. orderId: that.data.paramData.orderId
  144. }
  145. })
  146. .then(res => {
  147. var payOrderId = "" + res.data.payOrderId;
  148. wx.hideLoading();
  149. wx.requestPayment({
  150. timeStamp: res.data.timeStamp,
  151. nonceStr: res.data.nonceStr,
  152. package: res.data.package,
  153. signType: (res.data.signType) ? res.data.signType : "MD5",
  154. paySign: res.data.paySign,
  155. success: res => {
  156. wx.showLoading({
  157. title: '订单正在处理中...',
  158. })
  159. setTimeout(function () {
  160. wx.hideLoading()
  161. }, 5000)
  162. that.payOrderUpdate(that.data.paramData.orderId, payOrderId, 1, '', that, 0);
  163. if (res.errMsg == "requestPayment:ok") {
  164. setTimeout(function () {
  165. wx.hideLoading();
  166. }, 2000);
  167. }
  168. },
  169. fail: res => {
  170. /**
  171. * 支付失败,需要更新订单的状态
  172. */
  173. that.payOrderUpdate(that.data.orderId, payOrderId, 2, '', that, 0);
  174. that.setData({
  175. showbutton: false,
  176. canSpell: true,
  177. canBuyIf: true
  178. })
  179. return;
  180. },
  181. complete: res => { }
  182. });
  183. /// End payment --------
  184. })
  185. .catch(err => {
  186. that.setData({
  187. canSpell: true,
  188. canBuyIf: true
  189. })
  190. wx.showToast({
  191. title: err.message,
  192. icon: 'none',
  193. duration: 2000,
  194. mask: false
  195. });
  196. })
  197. },
  198. /**
  199. * 去使用
  200. */
  201. gotoUse() {
  202. wx.navigateTo({
  203. url: `/pages/couponorder/index/index`
  204. });
  205. },
  206. /**
  207. * 拼团状态字段转换
  208. */
  209. changeSatus(status) {
  210. console.log(spellStatus, 8888888)
  211. return spellStatus.filter(item => item.value == status)[0].name;
  212. },
  213. //跳转拼团列表
  214. gotoSpellList() {
  215. wx.navigateTo({
  216. url: '/pages/spellGroup/spellGroup',
  217. })
  218. },
  219. /**
  220. * 获取券详情信息
  221. */
  222. getDetail(){
  223. let that = this;
  224. Http.get({
  225. url: config.api.couponDetail,
  226. data: {
  227. couponChannelId: this.data.paramData.couponChannelId
  228. }
  229. }).then(res => {
  230. wx.stopPullDownRefresh();
  231. let data = res.data;
  232. that.setData({
  233. data
  234. });
  235. });
  236. },
  237. /**
  238. * 生命周期函数--监听页面初次渲染完成
  239. */
  240. onReady: function () {
  241. },
  242. /**
  243. * 生命周期函数--监听页面显示
  244. */
  245. onShow: function () {
  246. this.setData({
  247. showTime: true
  248. })
  249. },
  250. /**
  251. * 生命周期函数--监听页面隐藏
  252. */
  253. onHide: function () {
  254. this.setData({
  255. showTime: false
  256. })
  257. },
  258. /**
  259. * 生命周期函数--监听页面卸载
  260. */
  261. onUnload: function () {
  262. this.setData({
  263. showTime: false
  264. })
  265. },
  266. /**
  267. * 页面相关事件处理函数--监听用户下拉动作
  268. */
  269. onPullDownRefresh: function () {
  270. this.getDetail(this.data.paramData);
  271. },
  272. /**
  273. * 页面上拉触底事件的处理函数
  274. */
  275. onReachBottom: function () {
  276. }
  277. })