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.

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