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

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