C端小程序
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

384 rindas
10 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. navigationBarHeight,
  13. succUrl: imgurl.succ.url,
  14. spcodeUrl: imgurl.spcode.url,
  15. chevronUrl: imgurl.chevron.url,
  16. teljpgUrl: imgurl.teljpg.url,
  17. newUrl: imgurl.new1.url,
  18. weixinTitle: imgurl.weixinTitle.url,
  19. showModalStatus: false,
  20. flag: 0,
  21. order: null,
  22. orderId: null,
  23. //存储计时器
  24. setInter: "",
  25. mystatus: '',
  26. staticGamedata: {},
  27. showIf: false,
  28. showPage:false,
  29. showButton:false,
  30. cardDetail:null,
  31. supportTransfer:'',
  32. cardIf:false,
  33. contentType: 0,
  34. },
  35. phone: function (e) {
  36. let that = this;
  37. console.log(e);
  38. wx.makePhoneCall({
  39. phoneNumber: e.currentTarget.dataset.merchantlinkphone
  40. });
  41. },
  42. /**
  43. * 跳转到门店列表的详情页面
  44. */
  45. gotoDetail(e) {
  46. wx.navigateTo({
  47. url: `/pages/index/searchbar/detail/index?id=${e.currentTarget.dataset.id}`
  48. })
  49. },
  50. getUserInfo: function () {
  51. let that = this;
  52. // 获取用户信息
  53. Http.get({
  54. url: config.api.getScore,
  55. data: {}
  56. })
  57. .then(res => {
  58. console.log(res)
  59. that.setData({
  60. userName: res.data.nickName,
  61. avatarUrl: res.data.avatarUrl
  62. })
  63. })
  64. },
  65. onShareAppMessage: function (res) {
  66. app.globalData.previewFlag = true
  67. if (res.from === 'button') {
  68. console.log(res, 3333333333333333333333)
  69. // 来自页面内转发按钮
  70. let _this = this;
  71. return {
  72. title: _this.data.userName+'赠送您一张' + _this.data.order.title,
  73. 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,
  74. imageUrl: this.data.order.coverImg,
  75. success: function (res) {
  76. // 转发成功
  77. },
  78. fail: function (res) {
  79. // 转发失败
  80. }
  81. }
  82. } else {
  83. console.log(res, 444444444444444444)
  84. }
  85. },
  86. powerDrawer: function (e) {
  87. let that = this;
  88. console.log(e)
  89. // couponOrderStatus
  90. // 0 未使用
  91. // 1 已使用
  92. // 2 已过期
  93. // 3 已经退款
  94. if (that.data.mystatus == "" || that.data.mystatus == undefined) {
  95. wx.navigateTo({
  96. url: `/pages/orderquanma/index?quancode=${
  97. e.currentTarget.dataset.quancode
  98. }&title=${e.currentTarget.dataset.title}&subtitle=${
  99. e.currentTarget.dataset.subtitle
  100. }&remark=${e.currentTarget.dataset.remark}&couponorderstatus=${
  101. e.currentTarget.dataset.couponorderstatus}&validstatus=${e.currentTarget.dataset.validstatus}
  102. &contentType=${that.data.contentType}`
  103. });
  104. } else {
  105. wx.navigateTo({
  106. url: `/pages/orderquanma/index?quancode=${
  107. e.currentTarget.dataset.quancode
  108. }&title=${e.currentTarget.dataset.title}&subtitle=${
  109. e.currentTarget.dataset.subtitle
  110. }&remark=${e.currentTarget.dataset.remark}&couponorderstatus=${
  111. that.data.mystatus}&validstatus=${e.currentTarget.dataset.validstatus}
  112. &contentType=${that.data.contentType}`
  113. });
  114. }
  115. },
  116. gotogame: function () {
  117. let that = this;
  118. wx.redirectTo({
  119. url: '/pages/game/index?url=' + that.data.staticGamedata.url + "&id=" + that.data.staticGamedata.id + "&gameId=" + that.data.staticGamedata.gameId,
  120. })
  121. },
  122. // 买完卡跳转到立即使用页面
  123. gotoUse:function(){
  124. wx.navigateTo({
  125. url: '/pages/cardorder/index/index'
  126. })
  127. },
  128. // 获取游戏
  129. getStaticGame(token) {
  130. let _this = this;
  131. Http.get({
  132. url: config.api.getGame,
  133. data: {
  134. triggleAction: 3 // 购买触发
  135. }
  136. }).then(res => {
  137. if (res.data.id) {
  138. _this.setData({
  139. showIf: true
  140. })
  141. }
  142. _this.setData({
  143. staticGamedata: res.data
  144. })
  145. })
  146. .catch(err => {
  147. console.log(err);
  148. })
  149. },
  150. /**
  151. * 生命周期函数--监听页面加载
  152. */
  153. onLoad: function (options) {
  154. console.log(options.html)
  155. let that = this;
  156. that.setData({
  157. orderId: options.orderId,
  158. contentType: options.contentType,
  159. composeOrderType: options.composeOrderType
  160. });
  161. wx.hideShareMenu()
  162. if(options.cardIf){
  163. that.setData({
  164. cardIf:true
  165. })
  166. }
  167. wx.showLoading({
  168. title: "加载中"
  169. });
  170. Http.get({
  171. url: config.api.orderDetail,
  172. data: {
  173. orderId: options.orderId
  174. }
  175. })
  176. .then(res => {
  177. wx.hideLoading();
  178. if(res.code == 200){
  179. that.getUserInfo()
  180. that.setData({
  181. showPage:true,
  182. composeOrderType: res.data.composeOrderType
  183. })
  184. }
  185. that.setData({
  186. order: res.data,
  187. supportTransfer: res.data.supportTransfer
  188. });
  189. that.getStaticGame()
  190. //createDate 创建时间
  191. var createDate = util.formatTime(res.data.createDate, "yyyy-MM-dd hh:mm:ss");
  192. that.setData({
  193. createDate: createDate
  194. });
  195. })
  196. .catch(error=>{
  197. wx.hideLoading();
  198. wx.showModal({
  199. title: '提示',
  200. content: error.errMsg,
  201. showCancel:false
  202. })
  203. })
  204. },
  205. onShow:function(){
  206. let that = this;
  207. that.setData({
  208. showButton: false
  209. })
  210. },
  211. /**
  212. * 去拼团
  213. */
  214. goToOrderGroup(orderId, orderGroupId, _this) {
  215. let that = this;
  216. // 支付成功
  217. Http.post({
  218. url: config.api.toOrderGroup,
  219. data: {
  220. id: orderGroupId,
  221. orderId,
  222. couponId: _this.data.order.productId
  223. }
  224. })
  225. .then(res => {
  226. wx.redirectTo({
  227. url: `/pages/spellDetail/index?orderId=${orderId}&couponId=${_this.data.order.productId}&orderGroupId=${res.data.orderGroupId}`
  228. });
  229. })
  230. .catch(err => {
  231. console.log(err);
  232. })
  233. // return;
  234. },
  235. /**
  236. * 发起支付
  237. */
  238. orderFunc(e) {
  239. var that = this;
  240. that.setData({
  241. showButton: true
  242. })
  243. wx.showLoading({
  244. title: "加载中..."
  245. });
  246. const orderId = "" + that.data.orderId;
  247. if (that.data.order.payment > 0) {
  248. // 支付金额不为0
  249. Http.post({
  250. url: config.api.payOrderCreate,
  251. data: {
  252. orderId: orderId,
  253. composeOrderType: that.data.composeOrderType
  254. }
  255. }).then(res => {
  256. var payOrderId = "" + res.data.payOrderId;
  257. wx.hideLoading();
  258. wx.requestPayment({
  259. timeStamp: res.data.timeStamp,
  260. nonceStr: res.data.nonceStr,
  261. package: res.data.package,
  262. signType: (res.data.signType) ? res.data.signType : "MD5",
  263. paySign: res.data.paySign,
  264. success: res => {
  265. wx.showLoading({
  266. title: '订单正在处理中...',
  267. })
  268. setTimeout(function () {
  269. wx.hideLoading()
  270. }, 5000)
  271. that.payOrderUpdate(that.data.orderId, payOrderId, 1,'','',that); // 支付成功
  272. if (res.errMsg == "requestPayment:ok") {
  273. if (that.data.order.type == 100) {
  274. wx.setStorage({
  275. key: 'couponNum2',
  276. data: "couponNum2"
  277. })
  278. } else if (that.data.order.type != 5) {
  279. wx.setStorage({
  280. key: 'couponNum',
  281. data: "couponNum"
  282. })
  283. }
  284. }
  285. },
  286. fail: res => {
  287. that.setData({
  288. showButton:false
  289. })
  290. that.payOrderUpdate(that.data.orderId, payOrderId, 2,'','fail',that);
  291. return;
  292. },
  293. });
  294. }).catch(err=>{
  295. wx.hideLoading();
  296. that.setData({
  297. showButton: false
  298. })
  299. wx.showModal({
  300. title: "抱歉",
  301. content: err.message,
  302. showCancel: false
  303. })
  304. });
  305. } else {
  306. // 免费券
  307. that.payOrderUpdate(orderId, "0", 1,'','free') // 支付成功
  308. if (that.data.order.type == 100) {
  309. wx.setStorage({
  310. key: 'couponNum2',
  311. data: "couponNum2"
  312. })
  313. } else if (that.data.order.type != "5") {
  314. wx.setStorage({
  315. key: 'couponNum',
  316. data: "couponNum"
  317. })
  318. }
  319. wx.showToast({
  320. title: "支付成功",
  321. duration: 2000,
  322. image: imgurl.success.url,
  323. });
  324. }
  325. },
  326. /**
  327. * 支付订单更新
  328. */
  329. payOrderUpdate: (orderId, payOrderId, status, reason,type,_this) => {
  330. // 支付成功
  331. Http.post({
  332. url: config.api.payOrderUpdate,
  333. data: {
  334. payOrderId: payOrderId,
  335. composeOrderId: orderId,
  336. status: status,
  337. reason: reason
  338. }
  339. })
  340. .then(res => {
  341. wx.hideLoading();
  342. _this.setData({
  343. showButton: false
  344. })
  345. if (!type&&type!='free') {
  346. wx.showToast({
  347. title: "购买成功",
  348. duration: 2000,
  349. image: imgurl.success.url,
  350. mask: false,
  351. success: function () {
  352. wx.showLoading({
  353. title: "加载中..."
  354. });
  355. setTimeout(function () {
  356. wx.hideLoading();
  357. }, 1600);
  358. setTimeout(() => {
  359. wx.redirectTo({
  360. url: `/pages/order/detail/index?orderId=${orderId}`
  361. });
  362. }, 1600);
  363. }
  364. });
  365. } else if (type == 'free'){
  366. wx.redirectTo({
  367. url: `/pages/order/detail/index?orderId=${orderId}`
  368. });
  369. }
  370. })
  371. .catch(err => {
  372. console.log(err)
  373. if (!type) {
  374. setTimeout(function () {
  375. _this.payOrderUpdate(orderId, payOrderId, status, reason, type, _this);
  376. }, 1500)
  377. }
  378. });
  379. },
  380. });