C端小程序
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

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