C端小程序
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

495 lignes
13 KiB

  1. const navigationBarHeight = (getApp().statusBarHeight + 44) + 'px'
  2. let config = require("../../../config/config.js");
  3. let util = require("../../../utils/util");
  4. let Http = require("../../../utils/HttpBasics");
  5. let app = getApp();
  6. const imgurl = require("../../../utils/imgurl");
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. showFlag: false,
  13. navigationBarHeight,
  14. succUrl: imgurl.succ.url,
  15. spcodeUrl: imgurl.spcode.url,
  16. chevronUrl: imgurl.chevron.url,
  17. teljpgUrl: imgurl.teljpg.url,
  18. newUrl: imgurl.new1.url,
  19. weixinTitle: imgurl.weixinTitle.url,
  20. showModalStatus: false,
  21. flag: 0,
  22. order: null,
  23. orderId: null,
  24. //存储计时器
  25. setInter: "",
  26. mystatus: '',
  27. staticGamedata: {},
  28. showIf: false,
  29. showPage: false,
  30. showButton: false,
  31. cardDetail: null,
  32. supportTransfer: '',
  33. cardIf: false,
  34. contentType: 0,
  35. orderFlag: false, //判断是不是线上配送
  36. },
  37. copeCode(e) {
  38. let code = e.currentTarget.dataset.text
  39. wx.setClipboardData({
  40. data: code,
  41. success: function() {
  42. wx.showToast({
  43. title: '复制成功',
  44. icon: "none"
  45. })
  46. }
  47. })
  48. },
  49. gokuaidi(e) {
  50. let nu = e.currentTarget.dataset.nu
  51. wx.navigateToMiniProgram({
  52. appId: 'wx6885acbedba59c14',
  53. path: `pages/result/result?nu=${nu}&com=&querysource=third_xcx`
  54. })
  55. },
  56. setShow() {
  57. this.setData({
  58. showFlag: true
  59. })
  60. },
  61. hieShow() {
  62. this.setData({
  63. showFlag: false
  64. })
  65. },
  66. //刷新订单
  67. updetail() {
  68. let that = this
  69. let url = config.api.orderDetail
  70. // let data = {}
  71. // if (that.data.orderFlag) {
  72. // url = config.api.goodsDetail
  73. // data = {
  74. // mainOrderId: this.data.orderId
  75. // }
  76. // } else {
  77. // data = {
  78. // orderId: this.data.orderId
  79. // }
  80. // }
  81. Http.get({
  82. url: url,
  83. data: {
  84. orderId: this.data.orderId
  85. }
  86. }).then(res => {
  87. wx.hideLoading();
  88. // if (res.data.level == 0) { //单券
  89. // if (res.code == 200) {
  90. // that.getUserInfo()
  91. // that.setData({
  92. // showPage: true,
  93. // composeOrderType: res.data.composeOrderType
  94. // })
  95. // }
  96. // let tempData = res.data
  97. // if (tempData.deliveryInfo) tempData.deliveryInfo = JSON.parse(tempData.deliveryInfo)
  98. // that.setData({
  99. // order: res.data,
  100. // supportTransfer: res.data.supportTransfer
  101. // });
  102. // that.getStaticGame()
  103. // //createDate 创建时间
  104. // var createDate = util.formatTime(res.data.createDate, "yyyy-MM-dd hh:mm:ss");
  105. // that.setData({
  106. // createDate: createDate
  107. // });
  108. // } else {
  109. // if (that.data.orderFlag) {
  110. that.getStaticGame()
  111. var createDate = util.formatTime(res.data.orders[0].createDate, "yyyy-MM-dd hh:mm:ss");
  112. let tempData = res.data.orders[0]
  113. tempData.deliveryInfo = tempData.deliveryInfo ? JSON.parse(tempData.deliveryInfo) : ""
  114. that.setData({
  115. order: tempData,
  116. showPage: true,
  117. createDate: createDate,
  118. composeOrderType: tempData.composeOrderType
  119. })
  120. console.log(that.data.order)
  121. // }
  122. // }
  123. })
  124. .catch(error => {
  125. wx.hideLoading();
  126. wx.showModal({
  127. title: '提示',
  128. content: error.errMsg,
  129. showCancel: false
  130. })
  131. })
  132. },
  133. //确认收货
  134. verify() {
  135. Http.post({
  136. url: config.api.verify,
  137. data: {
  138. couponOrderId: this.data.order.couponOrderId
  139. }
  140. }).then(res => {
  141. wx.showToast({
  142. title: '签收成功',
  143. icon: "none"
  144. })
  145. this.updetail()
  146. }).catch(err => {
  147. wx.showModal({
  148. title: '提示',
  149. content: err.message ? err.message : err.data,
  150. showCancel: false
  151. })
  152. })
  153. },
  154. phone: function(e) {
  155. let that = this;
  156. console.log(e);
  157. wx.makePhoneCall({
  158. phoneNumber: e.currentTarget.dataset.merchantlinkphone
  159. });
  160. },
  161. /**
  162. * 跳转到门店列表的详情页面
  163. */
  164. gotoDetail(e) {
  165. wx.navigateTo({
  166. url: `/pages/index/searchbar/detail/index?id=${e.currentTarget.dataset.id}`
  167. })
  168. },
  169. getUserInfo: function() {
  170. let that = this;
  171. // 获取用户信息
  172. Http.get({
  173. url: config.api.getScore,
  174. data: {}
  175. })
  176. .then(res => {
  177. console.log(res)
  178. that.setData({
  179. userName: res.data.nickName,
  180. avatarUrl: res.data.avatarUrl
  181. })
  182. })
  183. },
  184. onShareAppMessage: function(res) {
  185. app.globalData.previewFlag = true
  186. if (res.from === 'button') {
  187. console.log(res, 3333333333333333333333)
  188. // 来自页面内转发按钮
  189. let _this = this;
  190. return {
  191. title: _this.data.userName + '赠送您一张' + _this.data.order.title,
  192. path: '/pages/index/index?couponChannelId=' + this.data.order.couponChannelId + '&cuserId=' + this.data.order.cuserId + '&couponId=' + this.data.order.productId + '&coverImg=' + this.data.order.coverImg + '&userName=' + this.data.userName + '&avatarUrl=' + this.data.avatarUrl + '&couponOrderId=' + this.data.order.couponOrderId + '&updateDate=' + this.data.order.updateDate,
  193. imageUrl: this.data.order.coverImg,
  194. success: function(res) {
  195. // 转发成功
  196. },
  197. fail: function(res) {
  198. // 转发失败
  199. }
  200. }
  201. } else {
  202. console.log(res, 444444444444444444)
  203. }
  204. },
  205. powerDrawer: function(e) {
  206. let that = this;
  207. console.log(e)
  208. // couponOrderStatus
  209. // 0 未使用
  210. // 1 已使用
  211. // 2 已过期
  212. // 3 已经退款
  213. if (that.data.mystatus == "" || that.data.mystatus == undefined) {
  214. wx.navigateTo({
  215. url: `/pages/orderquanma/index?quancode=${
  216. e.currentTarget.dataset.quancode
  217. }&title=${e.currentTarget.dataset.title}&subtitle=${
  218. e.currentTarget.dataset.subtitle
  219. }&remark=${e.currentTarget.dataset.remark}&couponorderstatus=${
  220. e.currentTarget.dataset.couponorderstatus}&validstatus=${e.currentTarget.dataset.validstatus}
  221. &contentType=${that.data.contentType}`
  222. });
  223. } else {
  224. wx.navigateTo({
  225. url: `/pages/orderquanma/index?quancode=${
  226. e.currentTarget.dataset.quancode
  227. }&title=${e.currentTarget.dataset.title}&subtitle=${
  228. e.currentTarget.dataset.subtitle
  229. }&remark=${e.currentTarget.dataset.remark}&couponorderstatus=${
  230. that.data.mystatus}&validstatus=${e.currentTarget.dataset.validstatus}
  231. &contentType=${that.data.contentType}`
  232. });
  233. }
  234. },
  235. gotogame: function() {
  236. let that = this;
  237. wx.redirectTo({
  238. url: '/pages/game/index?url=' + that.data.staticGamedata.url + "&id=" + that.data.staticGamedata.id + "&gameId=" + that.data.staticGamedata.gameId,
  239. })
  240. },
  241. // 买完卡跳转到立即使用页面
  242. gotoUse: function() {
  243. wx.navigateTo({
  244. url: '/pages/cardorder/index/index'
  245. })
  246. },
  247. // 获取游戏
  248. getStaticGame(token) {
  249. let _this = this;
  250. Http.get({
  251. url: config.api.getGame,
  252. data: {
  253. triggleAction: 3 // 购买触发
  254. }
  255. }).then(res => {
  256. if (res.data.id) {
  257. _this.setData({
  258. showIf: true
  259. })
  260. }
  261. _this.setData({
  262. staticGamedata: res.data
  263. })
  264. })
  265. .catch(err => {
  266. console.log(err);
  267. })
  268. },
  269. /**
  270. * 生命周期函数--监听页面加载
  271. */
  272. onLoad: function(options) {
  273. let that = this;
  274. if (options.dingdan && options.dingdan == "order") {
  275. that.setData({
  276. orderFlag: true //判断是不是线上配送
  277. })
  278. }
  279. that.setData({
  280. orderId: options.orderId,
  281. contentType: options.contentType,
  282. composeOrderType: options.composeOrderType
  283. });
  284. wx.hideShareMenu()
  285. if (options.cardIf) {
  286. that.setData({
  287. cardIf: true
  288. })
  289. }
  290. wx.showLoading({
  291. title: "加载中"
  292. });
  293. that.updetail()
  294. },
  295. onShow: function() {
  296. let that = this;
  297. that.setData({
  298. showButton: false
  299. })
  300. },
  301. /**
  302. * 去拼团
  303. */
  304. goToOrderGroup(orderId, orderGroupId, _this) {
  305. let that = this;
  306. // 支付成功
  307. Http.post({
  308. url: config.api.toOrderGroup,
  309. data: {
  310. id: orderGroupId,
  311. orderId,
  312. couponId: _this.data.order.productId
  313. }
  314. })
  315. .then(res => {
  316. wx.redirectTo({
  317. url: `/pages/spellDetail/index?orderId=${orderId}&couponId=${_this.data.order.productId}&orderGroupId=${res.data.orderGroupId}`
  318. });
  319. })
  320. .catch(err => {
  321. console.log(err);
  322. })
  323. // return;
  324. },
  325. /**
  326. * 发起支付
  327. */
  328. orderFunc(e) {
  329. var that = this;
  330. that.setData({
  331. showButton: true
  332. })
  333. wx.showLoading({
  334. title: "加载中..."
  335. });
  336. const orderId = "" + that.data.orderId;
  337. if (that.data.order.payment > 0) {
  338. // 支付金额不为0
  339. Http.post({
  340. url: config.api.payOrderCreate,
  341. data: {
  342. orderId: orderId,
  343. composeOrderType: that.data.composeOrderType
  344. }
  345. }).then(res => {
  346. var payOrderId = "" + res.data.payOrderId;
  347. wx.hideLoading();
  348. wx.requestPayment({
  349. timeStamp: res.data.timeStamp,
  350. nonceStr: res.data.nonceStr,
  351. package: res.data.package,
  352. signType: (res.data.signType) ? res.data.signType : "MD5",
  353. paySign: res.data.paySign,
  354. success: res => {
  355. wx.showLoading({
  356. title: '订单正在处理中...',
  357. })
  358. setTimeout(function() {
  359. wx.hideLoading()
  360. }, 5000)
  361. that.payOrderUpdate(that.data.orderId, payOrderId, 1, '', '', that); // 支付成功
  362. if (res.errMsg == "requestPayment:ok") {
  363. if (that.data.order.type == 100) {
  364. wx.setStorage({
  365. key: 'couponNum2',
  366. data: "couponNum2"
  367. })
  368. } else if (that.data.order.type != 5) {
  369. wx.setStorage({
  370. key: 'couponNum',
  371. data: "couponNum"
  372. })
  373. }
  374. }
  375. },
  376. fail: res => {
  377. that.setData({
  378. showButton: false
  379. })
  380. that.payOrderUpdate(that.data.orderId, payOrderId, 2, '', 'fail', that);
  381. return;
  382. },
  383. });
  384. }).catch(err => {
  385. wx.hideLoading();
  386. that.setData({
  387. showButton: false
  388. })
  389. wx.showModal({
  390. title: "抱歉",
  391. content: err.message,
  392. showCancel: false
  393. })
  394. });
  395. } else {
  396. // 免费券
  397. that.payOrderUpdate(orderId, "0", 1, '', 'free') // 支付成功
  398. if (that.data.order.type == 100) {
  399. wx.setStorage({
  400. key: 'couponNum2',
  401. data: "couponNum2"
  402. })
  403. } else if (that.data.order.type != "5") {
  404. wx.setStorage({
  405. key: 'couponNum',
  406. data: "couponNum"
  407. })
  408. }
  409. wx.showToast({
  410. title: "支付成功",
  411. duration: 2000,
  412. image: imgurl.success.url,
  413. });
  414. }
  415. },
  416. /**
  417. * 支付订单更新
  418. */
  419. payOrderUpdate: (orderId, payOrderId, status, reason, type, _this) => {
  420. // 支付成功
  421. Http.post({
  422. url: config.api.payOrderUpdate,
  423. data: {
  424. payOrderId: payOrderId,
  425. composeOrderId: orderId,
  426. status: status,
  427. reason: reason
  428. }
  429. })
  430. .then(res => {
  431. wx.hideLoading();
  432. _this.setData({
  433. showButton: false
  434. })
  435. if (!type && type != 'free') {
  436. wx.showToast({
  437. title: "购买成功",
  438. duration: 2000,
  439. image: imgurl.success.url,
  440. mask: false,
  441. success: function() {
  442. wx.showLoading({
  443. title: "加载中..."
  444. });
  445. setTimeout(function() {
  446. wx.hideLoading();
  447. }, 1600);
  448. setTimeout(() => {
  449. let url = ""
  450. if (_this.data.orderFlag) {
  451. wx.redirectTo({
  452. url: `/pages/order/detail/index?orderId=${orderId}&dingdan=order`
  453. });
  454. } else {
  455. wx.redirectTo({
  456. url: `/pages/order/detail/index?orderId=${orderId}`
  457. });
  458. }
  459. }, 1600);
  460. }
  461. });
  462. } else if (type == 'free') {
  463. wx.redirectTo({
  464. url: `/pages/order/detail/index?orderId=${orderId}`
  465. });
  466. }
  467. })
  468. .catch(err => {
  469. console.log(err)
  470. if (!type) {
  471. setTimeout(function() {
  472. _this.payOrderUpdate(orderId, payOrderId, status, reason, type, _this);
  473. }, 1500)
  474. }
  475. });
  476. },
  477. });