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