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.

преди 6 години
преди 6 години
преди 5 години
преди 6 години
преди 3 години
преди 2 години
преди 5 години
преди 6 години
преди 5 години
преди 2 години
преди 2 години
преди 1 година
преди 1 година
преди 6 години
преди 2 години
преди 3 години
преди 2 години
преди 2 години
преди 3 години
преди 5 години
преди 6 години
преди 2 години
преди 2 години
преди 5 години
преди 2 години
преди 5 години
преди 6 години
преди 6 години
преди 5 години
преди 6 години
преди 5 години
преди 5 години
преди 6 години
преди 5 години
преди 6 години
преди 2 години
преди 2 години
преди 2 години
преди 2 години
преди 2 години
преди 6 години
преди 5 години
преди 6 години
преди 6 години
преди 6 години
преди 2 години
преди 6 години
преди 2 години
преди 6 години
преди 6 години
преди 5 години
преди 6 години
преди 1 година
преди 6 години
преди 6 години
преди 5 години
преди 6 години
преди 1 година
преди 5 години
преди 6 години
преди 6 години
преди 6 години
преди 1 година
преди 2 години
преди 1 година
преди 2 години
преди 2 години
преди 6 години
преди 6 години
преди 6 години
преди 6 години
преди 6 години
преди 6 години
преди 6 години
преди 5 години
преди 2 години
преди 6 години
преди 5 години
преди 5 години
преди 5 години
преди 6 години
преди 6 години
преди 5 години
преди 6 години
преди 2 години
преди 5 години
преди 2 години
преди 2 години
преди 6 години
преди 3 години
преди 3 години
преди 3 години
преди 5 години
преди 6 години
преди 5 години
преди 6 години
преди 5 години
преди 6 години
преди 5 години
преди 5 години
преди 5 години
преди 6 години
преди 5 години
преди 5 години
преди 3 години
преди 6 години
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891
  1. // pages/spellGroup/mySpellGroup/index.js
  2. const navigationBarHeight = (getApp().statusBarHeight + 50) + 'px'
  3. var config = require("../../../config/config.js");
  4. const Http = require("../../../utils/HttpBasics");
  5. const imgurl = require("../../../utils/imgurl");
  6. const utils = require("../../../utils/util.js");
  7. let app = getApp();
  8. Page({
  9. /**
  10. * 页面的初始数据
  11. */
  12. data: {
  13. mouldType: 0,
  14. mouldConfig: {},
  15. navigationBarHeight,
  16. fenxiang: imgurl.fenxiang1.url,
  17. homeSelectedO: imgurl.homeSelectedO.url,
  18. isshowposter: false, //是否显示分享弹框
  19. teljpgUrl: imgurl.teljpg.url,
  20. wmhome: imgurl.wmhome.url,
  21. share01: imgurl.share01.url,
  22. close02: imgurl.close02.url,
  23. closedUrl: imgurl.closed.url,
  24. quesGouUrl: imgurl.ques_gou.url,
  25. headbgUrl: imgurl.headbg.url,
  26. quesBgUrl: imgurl.ques_bg.url,
  27. couponChannelId: '',
  28. couponId: '',
  29. data: null,
  30. spellData: null,
  31. canSpell: true,
  32. canBuyIf: true,
  33. clock: "00",
  34. day: "00",
  35. hour: "00",
  36. min: "00",
  37. sec: "00",
  38. detailPicture: [],
  39. coverPicture: [],
  40. swiperCurrent: 0,
  41. showTime: true,
  42. limitCondition: "",
  43. minLimit: 0,
  44. maxLimit: 0,
  45. spellGroupOrder: false,
  46. opacity: 0,
  47. queueData: null,
  48. zIndex: 11,
  49. display: "none",
  50. orderGroupId: '',
  51. merchantVoList: [],
  52. goHomeUrl: "",
  53. mallList: '',
  54. contentType: '',
  55. activityStatus: ''
  56. },
  57. /**
  58. * 生命周期函数--监听页面加载
  59. */
  60. onLoad: function (options) {
  61. this.setData({
  62. mouldType: app.globalData.mouldType,
  63. mouldConfig: app.globalData.mouldConfig,
  64. goHomeUrl: app.globalData.goHomeUrl,
  65. })
  66. Http.get({
  67. url: config.api.checkUserStatus,
  68. data: {
  69. token: app.globalData.token
  70. }
  71. }).then(res => {
  72. Http.get({
  73. url: config.api.checkPhoneStatus,
  74. data: {}
  75. }).then(res => {
  76. this.setData({
  77. couponChannelId: options.couponChannelId,
  78. couponId: options.couponId ? options.couponId : ''
  79. })
  80. if (options && options.couponChannelId) {
  81. this.getDetail(options.couponChannelId);
  82. }
  83. if (options && options.couponId) {
  84. this.getOneSpell(options.couponId)
  85. }
  86. }).catch(res => {
  87. wx.redirectTo({
  88. url: `/pages/getphoneInfo/index`
  89. });
  90. })
  91. }).catch(res => {
  92. wx.redirectTo({
  93. url: `/pages/getuserinfo/index`
  94. })
  95. })
  96. },
  97. /**
  98. * 显示分享海报
  99. */
  100. /* showPoster: function() {
  101. //跳转到海报生成页
  102. wx.navigateTo({
  103. url: `/pages/canvas/index?couponChannelId=${this.data.data.id}`
  104. })
  105. }, */
  106. showPoster: function () {
  107. console.log(this.data.data)
  108. let that = this;
  109. Http.get({
  110. url: config.api.checkUserStatus,
  111. data: {
  112. token: app.globalData.token
  113. }
  114. }).then(res => {
  115. wx.navigateTo({
  116. url: `/pages/canvas/index?couponChannelId=${that.data.data.id}`
  117. })
  118. }).catch(err => {
  119. console.log(err)
  120. if (err.code == 11004) {
  121. // 用户昵称未授权
  122. wx.redirectTo({
  123. url: `/pages/getuserinfo/index?couponChannelId=${that.data.data.id}&fromflag=poster`
  124. })
  125. }
  126. })
  127. //跳转到海报生成页
  128. },
  129. /**
  130. * 显示分享弹框
  131. */
  132. showshare: function () {
  133. this.setData({
  134. isshowposter: true,
  135. })
  136. },
  137. /**
  138. * 隐藏分享弹框
  139. */
  140. hidemodal: function () {
  141. this.setData({
  142. isshowposter: false,
  143. })
  144. },
  145. gotoIndex: function () {
  146. let this_ = this
  147. wx.switchTab({
  148. url: this_.data.goHomeUrl,
  149. })
  150. },
  151. /**
  152. * 拨打电话
  153. */
  154. phone: function (e) {
  155. let that = this;
  156. wx.makePhoneCall({
  157. phoneNumber: e.target.dataset.merchantlinkphone
  158. });
  159. },
  160. /**
  161. * 直接购买
  162. */
  163. gotoBuy(e) {
  164. let that = this;
  165. this.setData({
  166. canBuyIf: false,
  167. formId: e.detail.formId,
  168. queueData: null,
  169. orderGroupId: ''
  170. })
  171. that.getQuestions();
  172. },
  173. getQuestions(type) {
  174. let that = this;
  175. Http.get({
  176. url: config.api.getQuestion,
  177. data: {
  178. couponType: JSON.stringify(that.data.data.type)
  179. }
  180. })
  181. .then(res => {
  182. wx.hideLoading();
  183. if (res.data == undefined) {
  184. // 立即购买
  185. that.orderFunc(type);
  186. } else if (res.data) {
  187. var animation = wx.createAnimation({});
  188. animation.translate((that.data.widthScreen - that.data.widthScreen), 0).scale(1).opacity(1).step({
  189. duration: 500
  190. })
  191. that.setData({
  192. queueData: animation.export(),
  193. zIndex: 9,
  194. opacity: 1,
  195. display: "block",
  196. questionnaire: JSON.parse(res.data.content),
  197. questionId: res.data.id
  198. });
  199. }
  200. })
  201. .catch(err => {
  202. wx.hideLoading();
  203. wx.showToast({
  204. title: err.message,
  205. icon: 'none',
  206. duration: 2000,
  207. mask: false
  208. });
  209. })
  210. },
  211. /**
  212. * 点击提交问题单选
  213. */
  214. formSubmit: function (e) {
  215. console.log(e);
  216. let that = this;
  217. /**
  218. * 多选
  219. */
  220. if (e.currentTarget.dataset.flags == 'multi') {
  221. if (that.data.anwserId.length == 0) {
  222. var answserIs = null
  223. } else {
  224. var answserIs = that.data.anwserId.join(",");
  225. }
  226. } else if (e.currentTarget.dataset.flags == 'single') {
  227. var answserIs = e.detail.value;
  228. }
  229. console.log(answserIs)
  230. console.log(e.currentTarget.dataset.questionid)
  231. Http.post({
  232. url: config.api.answerQuestion,
  233. data: {
  234. answer: answserIs,
  235. questionId: e.currentTarget.dataset.questionid
  236. }
  237. })
  238. .then(res => {
  239. that.closeQuestion();
  240. })
  241. .catch(err => {
  242. wx.showToast({
  243. title: err.message,
  244. icon: 'none',
  245. duration: 2000,
  246. mask: false
  247. });
  248. })
  249. },
  250. /**
  251. * 多选
  252. */
  253. checkboxChange: function (e) {
  254. console.log(e)
  255. this.setData({
  256. anwserId: e.detail.value
  257. })
  258. },
  259. closeQuestion: function () {
  260. let that = this;
  261. that.setData({
  262. display: "none",
  263. zIndex: 11,
  264. opacity: 0
  265. })
  266. setTimeout(function () {
  267. that.orderFunc();
  268. }, 500)
  269. },
  270. // 时间格式化输出,如11:03 25:19 每1s都会调用一次
  271. dateformat(micro_second) {
  272. // 总秒数
  273. var second = Math.floor(micro_second / 1000);
  274. // 天数
  275. var day = Math.floor(second / 3600 / 24) < 10 ? "0" + Math.floor(second / 3600 / 24) : Math.floor(second / 3600 / 24);
  276. // 小时
  277. var hr = Math.floor(second / 3600 % 24) < 10 ? "0" + Math.floor(second / 3600 % 24) : Math.floor(second / 3600 % 24);
  278. // 分钟
  279. var min = Math.floor(second / 60 % 60) < 10 ? "0" + Math.floor(second / 60 % 60) : Math.floor(second / 60 % 60);
  280. // 秒
  281. var sec = Math.floor(second % 60) < 10 ? "0" + Math.floor(second % 60) : Math.floor(second % 60);
  282. // return day + "天" + hr + "小时" + min + "分钟" + sec + "秒";
  283. return {
  284. a1: day,
  285. b1: hr,
  286. c1: min,
  287. d1: sec
  288. }
  289. },
  290. countdown(time) {
  291. let that = this;
  292. var EndTime = time;
  293. if (that.data.spellData != null) {
  294. EndTime = that.data.spellData.expiredDate;
  295. }
  296. var NowTime = new Date().getTime();
  297. var total_micro_second = EndTime - NowTime || [];
  298. // 渲染倒计时时钟
  299. let obj = that.dateformat(total_micro_second);
  300. if (total_micro_second > 0) {
  301. that.setData({
  302. clock: obj,
  303. day: obj.a1,
  304. hour: obj.b1,
  305. min: obj.c1,
  306. sec: obj.d1,
  307. })
  308. } else {
  309. that.setData({
  310. clock: "00",
  311. day: "00",
  312. hour: "00",
  313. min: "00",
  314. sec: "00",
  315. })
  316. }
  317. if (that.data.showTime) {
  318. setTimeout(function () {
  319. total_micro_second -= 1000;
  320. that.countdown();
  321. }, 1000)
  322. }
  323. },
  324. // 获得未支付的订单
  325. getUnPaidOrder(couponId) {
  326. let that = this;
  327. Http.get({
  328. url: config.api.getUnPaidOrder,
  329. data: {
  330. couponId: couponId
  331. }
  332. }).then(res => {
  333. that.setData({
  334. disOrderNumber: res.data.orderNumber,
  335. couponChannelId: res.data.couponChannelId,
  336. orderGroupId: res.data.orderGroupId,
  337. composeOrderType: res.data.composeOrderType
  338. })
  339. // 拼团订单
  340. if (res.data.payment / 100 != Number(that.data.data.price)) {
  341. that.setData({
  342. spellGroupOrder: true
  343. })
  344. } else {
  345. // 原价购买订单
  346. that.setData({
  347. spellGroupOrder: false
  348. })
  349. }
  350. if (that.data.spellGroupOrder) {
  351. wx.showModal({
  352. title: '提示',
  353. content: "您有未支付拼团订单,请先进行支付",
  354. confirmText: "去支付",
  355. success: function (res1) {
  356. if (res1.confirm) {
  357. wx.navigateTo({
  358. url: `/pages/spellGroup/paySpellGroup/index?orderId=${res.data.composeOrderId}&couponChannelId=${that.data.couponChannelId}&couponId=${couponId}&orderGroupId={that.data.orderGroupId}&composeOrderType=${that.data.composeOrderType}`,
  359. })
  360. }
  361. }
  362. })
  363. } else {
  364. wx.showModal({
  365. title: '提示',
  366. content: '您有未支付订单,请先进行支付',
  367. confirmText: "去支付",
  368. success: function (res1) {
  369. if (res1.confirm) {
  370. wx.navigateTo({
  371. url: `/pages/order/detail/index?orderId=${res.data.composeOrderId}&composeOrderType=${that.data.composeOrderType}`,
  372. })
  373. }
  374. }
  375. })
  376. }
  377. }).catch(error => {
  378. console.log(error)
  379. wx.showToast({
  380. title: error.message,
  381. icon: "none",
  382. duration: 3000
  383. })
  384. })
  385. },
  386. /**
  387. * 发起拼团
  388. */
  389. gotoSpell(e) {
  390. app.globalData.previewFlag = false
  391. let that = this;
  392. that.setData({
  393. canSpell: false,
  394. formId: e.detail.formId,
  395. orderGroupId: 0
  396. })
  397. that.getQuestions(0);
  398. },
  399. //参与别人的拼团
  400. gotoPartner() {
  401. console.log(this.data.spellData.nickName, 'nickname');
  402. wx.navigateTo({
  403. url: `/pages/joinFrDpell/index?orderId=${this.data.spellData.orderId}&couponId=${this.data.spellData.couponId}&orderGroupId=${this.data.spellData.orderGroupId}&nickName=${this.data.spellData.nickName}&couponChannelId=${this.data.couponChannelId}&avatarUrl=${this.data.spellData.avatarUrl}`
  404. });
  405. },
  406. /**
  407. * 获取一个拼团信息
  408. */
  409. getOneSpell(couponId) {
  410. let that = this;
  411. Http.get({
  412. url: config.api.queryRemainOne,
  413. data: {
  414. couponId: couponId
  415. }
  416. }).then(res => {
  417. wx.stopPullDownRefresh();
  418. if (res.data) {
  419. that.countdown(res.data.expiredDate);
  420. that.setData({
  421. spellData: res.data
  422. });
  423. }
  424. });
  425. },
  426. getHtml(couponChannelId) {
  427. Http.get({
  428. url: config.api.couponHtmlDetail,
  429. data: {
  430. couponChannelId: couponChannelId
  431. }
  432. }).then(res => {
  433. console.log(res)
  434. if (res.code == 200 && res.data.html) {
  435. this.setData({
  436. curHtml: decodeURI(res.data.html),
  437. type: res.data.type
  438. })
  439. app.globalData.curHtml = this.data.curHtml;
  440. console.log(app.globalData.curHtml)
  441. }
  442. })
  443. },
  444. /**
  445. * 获取券详情信息
  446. */
  447. getDetail(couponChannelId) {
  448. let that = this;
  449. Http.get({
  450. url: config.api.couponDetail,
  451. data: {
  452. couponChannelId: couponChannelId
  453. }
  454. }).then(res => {
  455. wx.stopPullDownRefresh();
  456. let data = res.data;
  457. if (res.data.contentType != undefined && res.data.contentType == 1) {
  458. //获取图文展示详情html
  459. this.setData({
  460. contentType: res.data.contentType
  461. })
  462. this.getHtml(couponChannelId);
  463. }
  464. if (res && res.data && res.data.detailPicture) {
  465. that.setData({
  466. detailPicture: JSON.parse(res.data.detailPicture)
  467. })
  468. }
  469. if (res && res.data && res.data.coverPicture) {
  470. that.setData({
  471. coverPicture: JSON.parse(res.data.coverPicture)
  472. })
  473. }
  474. if (res && res.data && res.data.conditions) {
  475. that.setData({
  476. limitCondition: JSON.parse(res.data.conditions).type
  477. })
  478. if (JSON.parse(res.data.conditions).type == 2 && (JSON.parse(res.data.conditions).min || JSON.parse(res.data.conditions).min == 0)) {
  479. that.setData({
  480. minLimit: JSON.parse(res.data.conditions).min
  481. })
  482. }
  483. if (JSON.parse(res.data.conditions).type == 2 && (JSON.parse(res.data.conditions).max) || JSON.parse(res.data.conditions).max == 0) {
  484. that.setData({
  485. maxLimit: JSON.parse(res.data.conditions).max
  486. })
  487. }
  488. }
  489. data.price = (data.price / 100).toFixed(2)
  490. data.salePrice = (data.salePrice / 100).toFixed(2);
  491. data.validStartDate = utils.formatTime(data.validStartDate, 'yyyy-MM-dd')
  492. data.validEndDate = utils.formatTime(data.validEndDate, 'yyyy-MM-dd')
  493. data.soldStartTime = utils.formatTime(data.soldStartTime, 'yyyy-MM-dd')
  494. data.soldEndTime = utils.formatTime(data.soldEndTime, 'yyyy-MM-dd')
  495. that.setData({
  496. data,
  497. activityStatus: data.activityStatus
  498. // merchantVoList: data.merchantVoList
  499. });
  500. Http.get({
  501. url: config.api.couponMerchant,
  502. data: {
  503. couponChannelId: couponChannelId
  504. }
  505. }).then(res => {
  506. const keys = Object.keys(res.data)
  507. const mallList = []
  508. keys.forEach(item => {
  509. const arr = item.split('|')
  510. const obj = {
  511. tenantId: arr[0],
  512. mallName: arr[1],
  513. merchantVoList: res.data[item],
  514. expand: true
  515. }
  516. mallList.push(obj)
  517. })
  518. this.setData({
  519. mallList: mallList
  520. })
  521. console.log(this.data.mallList, 'mallList');
  522. })
  523. });
  524. },
  525. /**
  526. * 去拼团
  527. */
  528. goToOrderGroup(orderId, orderGroupId, _this) {
  529. let that = this;
  530. // 支付成功
  531. Http.post({
  532. url: config.api.toOrderGroup,
  533. data: {
  534. id: orderGroupId,
  535. orderId,
  536. couponId: _this.data.data.couponId
  537. }
  538. })
  539. .then(res => {
  540. wx.navigateTo({
  541. url: `/pages/spellDetail/index?orderId=${orderId}&couponId=${_this.data.data.couponId}&orderGroupId=${res.data.orderGroupId}&couponChannelId=${_this.data.couponChannelId}`
  542. });
  543. })
  544. .catch(err => {
  545. console.log(err);
  546. })
  547. },
  548. /**
  549. * 支付订单更新
  550. */
  551. payOrderUpdate: (orderId, payOrderId, status, reason, _this, orderGroupId) => {
  552. console.log(orderGroupId, 7777)
  553. let that = this;
  554. // 支付成功
  555. Http.post({
  556. url: config.api.payOrderUpdate,
  557. data: {
  558. payOrderId: payOrderId,
  559. composeOrderId: orderId,
  560. status: status,
  561. reason: reason
  562. }
  563. })
  564. .then(res => {
  565. wx.hideLoading()
  566. if (orderGroupId !== 0) {
  567. wx.navigateTo({
  568. url: '/pages/order/detail/index?orderId=' + res.data.mainOrderId,
  569. })
  570. } else {
  571. _this.goToOrderGroup(res.data.singleOrder.id, res.data.mainOrderId, _this)
  572. }
  573. })
  574. .catch(err => {
  575. if (err.code != 12002) {
  576. setTimeout(function () {
  577. _this.payOrderUpdate(orderId, payOrderId, status, reason, _this, orderGroupId);
  578. }, 2000)
  579. }
  580. })
  581. },
  582. /**
  583. * 发起支付
  584. */
  585. orderFunc() {
  586. let that = this;
  587. let orderGroupId = this.data.orderGroupId;
  588. let data = {
  589. couponChannelId: this.data.data.id,
  590. couponId: this.data.data.couponId,
  591. formId: this.data.formId
  592. }
  593. /**
  594. * 拼团订单
  595. */
  596. if (this.data.orderGroupId == 0) {
  597. data.orderGroupId = this.data.orderGroupId,
  598. that.setData({
  599. isFromSpell: true
  600. })
  601. } else {
  602. that.setData({
  603. isFromSpell: false
  604. })
  605. }
  606. Http.get({
  607. url: config.api.checkUserStatus,
  608. data: {
  609. token: app.globalData.token
  610. }
  611. }).then(res => {
  612. Http.get({
  613. url: config.api.checkPhoneStatus,
  614. data: {}
  615. }).then(res => {
  616. /**
  617. * orderSave 下单
  618. */
  619. return Http.post({
  620. url: config.api.orderSave,
  621. data: data
  622. });
  623. }).catch(err => {
  624. console.log(err);
  625. that.setData({
  626. showbutton: false,
  627. showbutton1: false,
  628. canSpell: true,
  629. canBuyIf: true
  630. })
  631. if (err.code == 2011) {
  632. wx.showToast({
  633. title: "商户信息没找到",
  634. image: './../../../assets/images/fail.png',
  635. duration: 2000,
  636. mask: false
  637. });
  638. } else if (err.code == 2013) {
  639. wx.showToast({
  640. title: "商户信息禁用",
  641. image: './../../../assets/images/fail.png',
  642. duration: 2000,
  643. mask: false
  644. });
  645. } else if (err.code == 3000) {
  646. wx.showToast({
  647. title: "库存不足",
  648. image: './../../../assets/images/fail.png',
  649. duration: 2000,
  650. mask: false
  651. });
  652. } else if (err.code == 3001) {
  653. wx.showToast({
  654. title: "您已超过限购",
  655. image: './../../../assets/images/fail.png',
  656. duration: 2000,
  657. mask: false
  658. });
  659. } else if (err.code == 3002) {
  660. wx.showToast({
  661. title: "订单失败",
  662. image: './../../../assets/images/fail.png',
  663. duration: 2000,
  664. mask: false
  665. });
  666. } else if (err.code == 3003) {
  667. wx.showToast({
  668. title: "订单不存在",
  669. image: './../../../assets/images/fail.png',
  670. duration: 2000,
  671. mask: false
  672. });
  673. } else if (err.code == 3004) {
  674. wx.showToast({
  675. title: "订单不存在",
  676. image: './../../../assets/images/fail.png',
  677. duration: 2000,
  678. mask: false
  679. });
  680. } else if (err.code == 4003) {
  681. wx.showToast({
  682. title: "卡券已作废",
  683. image: './../../../assets/images/fail.png',
  684. duration: 2000,
  685. mask: false
  686. });
  687. } else if (err.code == 3012) {
  688. // wx.showToast({
  689. // title: err.message,
  690. // icon: "none"
  691. // })
  692. that.getUnPaidOrder(that.data.data.couponId);
  693. } else if (err.code == 11005) {
  694. /**
  695. * 将值传到用户手机号授权的页面
  696. *
  697. */
  698. wx.redirectTo({
  699. url: `/pages/getphoneInfo/index?path=spell&couponChannelId=${that.data.couponChannelId}&couponId=${that.data.data.couponId}`
  700. });
  701. } else if (err.code == 11006) {
  702. // 用户手机已加密
  703. wx.redirectTo({
  704. url: `/pages/phoneinput/phoneinput?path=spell&couponChannelId=${that.data.couponChannelId}&couponId=${that.data.data.couponId}`
  705. });
  706. } else {
  707. wx.showToast({
  708. title: err.message,
  709. icon: 'none',
  710. duration: 2000,
  711. mask: false
  712. });
  713. }
  714. }).then(res => {
  715. console.log(res, "123")
  716. if (typeof (res) != "undefined") {
  717. let orderId = "" + res.data.mainOrderId;
  718. that.setData({
  719. orderId: orderId,
  720. composeOrderType: res.data.composeOrderType,
  721. canSpell: false,
  722. canBuyIf: true
  723. });
  724. // 支付金额不为0
  725. /**
  726. * 支付订单创建
  727. */
  728. Http.post({
  729. url: config.api.payOrderCreate,
  730. data: {
  731. orderId: orderId,
  732. composeOrderType: that.data.composeOrderType
  733. }
  734. }).then(res => {
  735. var payOrderId = "" + res.data.payOrderId;
  736. wx.hideLoading();
  737. wx.requestPayment({
  738. timeStamp: res.data.timeStamp,
  739. nonceStr: res.data.nonceStr,
  740. package: res.data.package,
  741. signType: (res.data.signType) ? res.data.signType : "MD5",
  742. paySign: res.data.paySign,
  743. success: res => {
  744. that.setData({
  745. canSpell: false
  746. })
  747. wx.showLoading({
  748. title: '订单正在处理中...',
  749. })
  750. // setTimeout(function() {
  751. // wx.hideLoading()
  752. // }, 5000)
  753. that.payOrderUpdate(that.data.orderId, payOrderId, 1, '', that, orderGroupId);
  754. if (res.errMsg == "requestPayment:ok") {
  755. setTimeout(function () {
  756. wx.hideLoading();
  757. }, 2000);
  758. }
  759. },
  760. fail: res => {
  761. /**
  762. * 支付失败,需要更新订单的状态
  763. */
  764. that.payOrderUpdate(that.data.orderId, payOrderId, 2, '', that, orderGroupId);
  765. that.setData({
  766. showbutton: false,
  767. canSpell: true,
  768. canBuyIf: true
  769. })
  770. return;
  771. },
  772. complete: res => { }
  773. });
  774. /// End payment --------
  775. })
  776. .catch(err => {
  777. that.setData({
  778. canSpell: true,
  779. canBuyIf: true
  780. })
  781. wx.showToast({
  782. title: err.message,
  783. icon: 'none',
  784. duration: 2000,
  785. mask: false
  786. });
  787. })
  788. }
  789. })
  790. })
  791. .catch(err => {
  792. console.log(err)
  793. if (err.code == 11004) {
  794. wx.redirectTo({
  795. url: `/pages/getuserinfo/index?fromflag=spellcoupondetail&couponChannelIdflag=${that.data.couponChannelId}`,
  796. })
  797. } else {
  798. wx.showToast({
  799. title: err.message,
  800. icon: "none",
  801. duration: 2500
  802. })
  803. }
  804. })
  805. },
  806. /**
  807. * 生命周期函数--监听页面显示
  808. */
  809. onShow() {
  810. this.setData({
  811. mouldType: app.globalData.mouldType,
  812. canSpell: true,
  813. canBuyIf: true,
  814. showTime: true,
  815. })
  816. if (this.data.spellData != null) {
  817. this.countdown()
  818. }
  819. },
  820. /**
  821. * 生命周期函数--监听页面隐藏
  822. */
  823. onHide: function () {
  824. this.setData({
  825. showTime: false
  826. })
  827. },
  828. /**
  829. * 生命周期函数--监听页面卸载
  830. */
  831. onUnload: function () {
  832. this.setData({
  833. showTime: false
  834. })
  835. },
  836. /**
  837. * 页面相关事件处理函数--监听用户下拉动作
  838. */
  839. onPullDownRefresh: function (e) {
  840. let that = this;
  841. console.log(this.data.couponId, 222)
  842. that.getDetail(that.data.couponChannelId);
  843. if (that.data.couponId) {
  844. that.getOneSpell(that.data.couponId)
  845. }
  846. },
  847. onShareAppMessage: function (options) {
  848. app.globalData.previewFlag = true
  849. console.log(options)
  850. var that = this;
  851. var shareObj = {
  852. title: that.data.data.title,
  853. path: `/pages/index/index?couponChannelId=${that.data.couponChannelId}&couponId=${that.data.data.couponId}&spellGroup=spellGroup`,
  854. success: function (res) {
  855. if (res.errMsg == 'shareAppMessage:ok') { }
  856. },
  857. fail: function (error) {
  858. if (res.errMsg == 'shareAppMessage:fail cancel') { } else if (res.errMsg == 'shareAppMessage:fail') { }
  859. }
  860. };
  861. // 来自页面内的按钮的转发
  862. if (options.from == 'button') {
  863. var eData = options.target.dataset.id;
  864. shareObj.path = `/pages/index/index?couponChannelId=${eData}&couponId=${that.data.data.couponId}&spellGroup=spellGroup&frommd=JC`;
  865. }
  866. console.log(shareObj)
  867. // 返回shareObj
  868. return shareObj;
  869. },
  870. })