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.

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