抖音小程序C端
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

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