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.

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