C端小程序
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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