C端小程序
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

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