C端小程序
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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