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.

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