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.

349 regels
9.1 KiB

  1. // pages/spellGroup/mySpellGroup/index.js
  2. var config = require("../../../config/config.js");
  3. const Http = require("../../../utils/HttpBasics");
  4. const imgurl = require("../../../utils/imgurl");
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. teljpgUrl: imgurl.teljpg.url,
  11. couponChannelId:'',
  12. couponId:'',
  13. data:[],
  14. spellData:null,
  15. canSpell:true,
  16. canBuyIf:true
  17. },
  18. /**
  19. * 生命周期函数--监听页面加载
  20. */
  21. onLoad: function (options) {
  22. this.setData({
  23. couponChannelId: options.couponChannelId,
  24. couponId: options.couponId
  25. })
  26. this.getDetail(options.couponChannelId);
  27. this.getOneSpell(options.couponId)
  28. },
  29. /**
  30. * 拨打电话
  31. */
  32. phone: function (e) {
  33. let that = this;
  34. wx.makePhoneCall({
  35. phoneNumber: e.target.dataset.merchantlinkphone
  36. });
  37. },
  38. /**
  39. * 直接购买
  40. */
  41. gotoBuy(){
  42. console.log(22222)
  43. this.setData({
  44. canBuyIf: false
  45. })
  46. },
  47. /**
  48. * 发起拼团
  49. */
  50. gotoSpell(){
  51. console.log(111111111)
  52. this.setData({
  53. canSpell:false
  54. })
  55. this.orderFunc()
  56. },
  57. /**
  58. * 获取一个拼团信息
  59. */
  60. getOneSpell(couponId){
  61. let that = this;
  62. Http.get({
  63. url: config.api.queryRemainOne,
  64. data: {
  65. couponId: couponId
  66. }
  67. }).then(res => {
  68. if(res.data){
  69. that.setData({
  70. spellData: res.data
  71. });
  72. }
  73. });
  74. },
  75. /**
  76. * 获取券详情信息
  77. */
  78. getDetail(couponChannelId){
  79. let that = this;
  80. Http.get({
  81. url: config.api.couponDetail,
  82. data: {
  83. couponChannelId: couponChannelId
  84. }
  85. }).then(res => {
  86. let data = res.data;
  87. data.price = (data.price / 100).toFixed(2)
  88. data.salePrice = (data.salePrice / 100).toFixed(2)
  89. that.setData({
  90. data
  91. });
  92. });
  93. },
  94. /**
  95. * 发起支付
  96. */
  97. orderFunc(discount) {
  98. var that = this;
  99. Http.post({
  100. url: config.api.checkPhoneStatus,
  101. data: {}
  102. })
  103. .then(res => {
  104. /**
  105. * orderSave 下单
  106. */
  107. debugger
  108. // return Http.post({
  109. // url: config.api.orderSave,
  110. // data: data
  111. // });
  112. })
  113. .catch(err => {
  114. console.log(err);
  115. that.setData({
  116. showbutton: false,
  117. showbutton1: false
  118. })
  119. if (err.code == 2011) {
  120. wx.showToast({
  121. title: "商户信息没找到",
  122. image: './../../../assets/images/fail.png',
  123. duration: 2000,
  124. mask: false
  125. });
  126. } else if (err.code == 2013) {
  127. wx.showToast({
  128. title: "商户信息禁用",
  129. image: './../../../assets/images/fail.png',
  130. duration: 2000,
  131. mask: false
  132. });
  133. } else if (err.code == 3000) {
  134. wx.showToast({
  135. title: "库存不足",
  136. image: './../../../assets/images/fail.png',
  137. duration: 2000,
  138. mask: false
  139. });
  140. } else if (err.code == 3001) {
  141. wx.showToast({
  142. title: "超过限购条件",
  143. image: './../../../assets/images/fail.png',
  144. duration: 2000,
  145. mask: false
  146. });
  147. } else if (err.code == 3002) {
  148. wx.showToast({
  149. title: "订单失败",
  150. image: './../../../assets/images/fail.png',
  151. duration: 2000,
  152. mask: false
  153. });
  154. } else if (err.code == 3003) {
  155. wx.showToast({
  156. title: "订单不存在",
  157. image: './../../../assets/images/fail.png',
  158. duration: 2000,
  159. mask: false
  160. });
  161. } else if (err.code == 3004) {
  162. wx.showToast({
  163. title: "订单不存在",
  164. image: './../../../assets/images/fail.png',
  165. duration: 2000,
  166. mask: false
  167. });
  168. } else if (err.code == 4003) {
  169. wx.showToast({
  170. title: "卡券已作废",
  171. image: './../../../assets/images/fail.png',
  172. duration: 2000,
  173. mask: false
  174. });
  175. } else if (err.code == 11005) {
  176. /**
  177. * 将值传到用户手机号授权的页面
  178. *
  179. */
  180. wx.redirectTo({
  181. url: "/pages/getphoneInfo/index?path=spell&couponChannelId=" +
  182. that.data.couponChannelId + '&couponId=' + that.data.couponId
  183. });
  184. } else if (err.code == 11006) {
  185. // 用户手机已加密
  186. wx.redirectTo({
  187. url: "/pages/phoneinput/phoneinput?path=spell&couponChannelId=" +
  188. that.data.couponChannelId + '&couponId=' + that.data.couponId
  189. });
  190. } else {
  191. wx.showToast({
  192. title: err.message,
  193. icon: 'none',
  194. duration: 2000,
  195. mask: false
  196. });
  197. }
  198. })
  199. .then(res => {
  200. console.log(res)
  201. if (discount != 'discount') {
  202. if (typeof (res) != "undefined") {
  203. let orderId = "" + res.data.id;
  204. that.setData({
  205. orderId: orderId
  206. });
  207. if (res.data.payment > 0) {
  208. // 支付金额不为0
  209. /**
  210. * 支付订单创建
  211. */
  212. Http.post({
  213. url: config.api.payOrderCreate,
  214. data: {
  215. orderId: orderId
  216. }
  217. })
  218. .then(res => {
  219. var payOrderId = "" + res.data.payOrderId;
  220. wx.hideLoading();
  221. wx.requestPayment({
  222. timeStamp: res.data.timeStamp,
  223. nonceStr: res.data.nonceStr,
  224. package: res.data.package,
  225. signType: (res.data.signType) ? res.data.signType : "MD5",
  226. paySign: res.data.paySign,
  227. success: res => {
  228. wx.showLoading({
  229. title: '订单正在处理中...',
  230. })
  231. setTimeout(function () {
  232. wx.hideLoading()
  233. }, 5000)
  234. that.payOrderUpdate(that.data.orderId, payOrderId, 1, '', '', that);
  235. if (res.errMsg == "requestPayment:ok") {
  236. setTimeout(function () {
  237. wx.hideLoading();
  238. }, 2000);
  239. /**
  240. * 用户支付成功以后跳转到券包列表
  241. */
  242. if (that.data.cardType == 100) {
  243. wx.setStorage({
  244. key: 'couponNum2',
  245. data: "couponNum2"
  246. })
  247. } else if (that.data.data.type != 5) {
  248. wx.setStorage({
  249. key: 'couponNum',
  250. data: "couponNum"
  251. })
  252. }
  253. }
  254. },
  255. fail: res => {
  256. /**
  257. * 支付失败,需要更新订单的状态
  258. */
  259. that.payOrderUpdate(that.data.orderId, payOrderId, 2, '', 'fail', that);
  260. that.setData({
  261. showbutton: false
  262. })
  263. return;
  264. },
  265. complete: res => { }
  266. });
  267. /// End payment --------
  268. })
  269. .catch(err => {
  270. wx.showToast({
  271. title: err.message,
  272. icon: 'none',
  273. duration: 2000,
  274. mask: false
  275. });
  276. })
  277. } else {
  278. console.log(that.data.type)
  279. // 免费券
  280. that.payOrderUpdate(orderId, "0", 1, '', 'free');
  281. if (that.data.cardType == 100) {
  282. wx.setStorage({
  283. key: 'couponNum2',
  284. data: "couponNum2"
  285. })
  286. } else if (that.data.data.type != "5") {
  287. wx.setStorage({
  288. key: 'couponNum',
  289. data: "couponNum"
  290. })
  291. }
  292. }
  293. }
  294. } else {
  295. if (res) {
  296. wx.navigateTo({
  297. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${res.data.id}`,
  298. })
  299. }
  300. }
  301. })
  302. },
  303. /**
  304. * 生命周期函数--监听页面初次渲染完成
  305. */
  306. onReady: function () {
  307. },
  308. /**
  309. * 生命周期函数--监听页面显示
  310. */
  311. onShow: function () {
  312. this.setData({
  313. canSpell:true,
  314. canBuyIf:true
  315. })
  316. },
  317. /**
  318. * 生命周期函数--监听页面隐藏
  319. */
  320. onHide: function () {
  321. },
  322. /**
  323. * 生命周期函数--监听页面卸载
  324. */
  325. onUnload: function () {
  326. },
  327. /**
  328. * 页面相关事件处理函数--监听用户下拉动作
  329. */
  330. onPullDownRefresh: function () {
  331. },
  332. /**
  333. * 页面上拉触底事件的处理函数
  334. */
  335. onReachBottom: function () {
  336. }
  337. })