grade-details.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. // pages/grade-details/grade-details.js
  2. import httpRequestApi from '../../../utils/APIClient';
  3. import util from '../../../utils/util';
  4. const app = getApp();
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. productId: '',
  11. payList: [],
  12. titleIcon: '',
  13. title: '',
  14. bookInfo: '',
  15. lessonList: [],
  16. content: [{
  17. text: "转发给自己的朋友们",
  18. color: "#000"
  19. },
  20. {
  21. text: " 分享好课,追随您一起学习进步",
  22. color: "#000"
  23. },
  24. {
  25. text: " 您的魅力不是吹的!",
  26. color: "#000"
  27. },
  28. {
  29. text: `在限定时间内成功拼团,您将得到奖学金。`,
  30. color: "#FF4600"
  31. }
  32. ],
  33. // share: false,
  34. isIPX: app.globalData.isIPX,
  35. isIOS: app.globalData.isIOS,
  36. flag: true,
  37. knowFlag: true,
  38. menuFlag: false,
  39. modalType: "text",
  40. isCloseShow: false,
  41. modalText: [{
  42. text: '您发起的团购尚未完成',
  43. type: 'bigOrange'
  44. },
  45. {
  46. text: '拼团成功,才能发起新的团购',
  47. type: 'bigOrange'
  48. },
  49. {
  50. text: '快喊朋友们一起助力',
  51. type: 'bigOrange'
  52. }
  53. ],
  54. isModalShow: false,
  55. formIsANAsshole: true,
  56. isPaying: false
  57. },
  58. //tab切换
  59. tabSwitch: function (e) {
  60. if(e.currentTarget.dataset.flag === "know" && this.data.knowFlag === false){
  61. this.setData({
  62. knowFlag: true,
  63. menuFlag: false
  64. })
  65. }
  66. if(e.currentTarget.dataset.flag === "menu" && this.data.menuFlag === false){
  67. this.setData({
  68. knowFlag: false,
  69. menuFlag: true
  70. })
  71. }
  72. },
  73. //获取团购信息并掉起支付
  74. pay: function (e) {
  75. console.log(e)
  76. if(this.data.haveTapMoney){
  77. return false
  78. }
  79. this.setData({
  80. haveTapMoney : true
  81. })
  82. const productId = this.data.productId;
  83. const groupId = e.currentTarget.dataset.id;
  84. const osType = this.data.isIOS ? 'IOS' : 'ANDROID';
  85. const formId = e.detail.formId
  86. //开始发起团购
  87. this.setData({
  88. isPaying: true
  89. })
  90. httpRequestApi.SendGroupPurchas({
  91. productId,
  92. groupId,
  93. osType,
  94. formId
  95. }).success((res) => {
  96. console.log('发起团购', res);
  97. if (res.data.message) {
  98. if(res.data.code == '803'){
  99. // this.setData({
  100. // modalType: 'text',
  101. // isModalShow: true
  102. // })
  103. wx.navigateTo({
  104. url:`/pages/groupPage/my-group/my-group`
  105. })
  106. }else{
  107. wx.showModal({
  108. title: '提示',
  109. content: res.data.message,
  110. success(res) {
  111. if (res.confirm) {
  112. console.log('用户点击确定')
  113. } else if (res.cancel) {
  114. console.log('用户点击取消')
  115. }
  116. }
  117. })
  118. }
  119. return false;
  120. }
  121. this.setData({
  122. orderId: res.data.data.groupPurchaseOrder.id
  123. })
  124. // 如果已经拥有当前课程,则无需支付,直接进入拼团成功页面
  125. if (res.data.data.groupPurchaseOrder.groupType === 'PROMOTION') {
  126. wx.redirectTo({
  127. url: `/pages/groupPage/make-money/make-money?productId=${productId}&id=${res.data.data.groupPurchaseOrder.id}&groupId=${groupId}`
  128. })
  129. wx.setNavigationBarTitle({
  130. title: '拼团详情'
  131. })
  132. // let that = this;
  133. // wx.showModal({
  134. // title: '重新发起团购',
  135. // content: '您会获得奖励哦',
  136. // success() {
  137. // console.log(res)
  138. // that.popup.close();
  139. // if (res.data.data.groupPurchaseOrder.headCount !== 1) {
  140. // setTimeout(() => {
  141. // wx.redirectTo({
  142. // url: `/pages/groupPage/make-money/make-money?productId=${productId}&id=${res.data.data.groupPurchaseOrder.id}&groupId=${groupId}`
  143. // })
  144. // wx.setNavigationBarTitle({
  145. // title: '拼团详情'
  146. // })
  147. // }, 1800)
  148. // }
  149. // }
  150. // })
  151. } else if (this.data.isIOS) {
  152. let that = this;
  153. wx.navigateTo({
  154. url: `/pages/groupPage/collage-details/collage-details?orderId=${that.data.orderId}`
  155. })
  156. wx.setNavigationBarTitle({
  157. title: '拼团详情'
  158. })
  159. // wx.showModal({
  160. // title: '提示',
  161. // content: '开团成功',
  162. // success(res) {
  163. // console.log(res)
  164. // that.popup.close();
  165. // setTimeout(() => {
  166. // wx.navigateTo({
  167. // url: `/pages/groupPage/collage-details/collage-details?orderId=${that.data.orderId}`
  168. // })
  169. // wx.setNavigationBarTitle({
  170. // title: '拼团详情'
  171. // })
  172. // }, 1800)
  173. // }
  174. // })
  175. } else {
  176. //掉起支付
  177. console.log(res.data.data.groupPurchaseOrder)
  178. this.setData({
  179. groupCount:res.data.data.groupPurchaseOrder.headcount
  180. })
  181. // this.prePayMap(res.data.data.prePayMap, res.data.data.groupPurchaseOrder.id, res.data.data.groupPurchaseOrder.headcount);
  182. this.prePayMap(res.data.data.prePayMap, res.data.data.groupPurchaseOrder.id);
  183. }
  184. }).fail((error) => {
  185. })
  186. },
  187. //支付
  188. prePayMap: function (prePayMap, orderId, num) {
  189. // this.setData({
  190. // modalType: 'image',
  191. // isModalShow: true
  192. // })
  193. // return
  194. console.log(prePayMap)
  195. console.log(orderId)
  196. console.log(num)
  197. const that = this;
  198. //console.log(new Date().getTime())
  199. wx.requestPayment({
  200. 'appId': prePayMap.appId,
  201. 'timeStamp': prePayMap.timeStamp,
  202. 'nonceStr': prePayMap.nonceStr,
  203. 'package': prePayMap.package,
  204. 'signType': 'MD5',
  205. 'paySign': prePayMap.sign,
  206. 'success': function (res) {
  207. that.setData({
  208. modalType: 'image',
  209. isModalShow: true,
  210. haveTapMoney: false
  211. })
  212. console.log('支付成功', res)
  213. // wx.showModal({
  214. // title: '提示',
  215. // content: '支付成功',
  216. // success(res) {
  217. // if (num !== 1) {
  218. // that.popup.close();
  219. // setTimeout(() => {
  220. // wx.navigateTo({
  221. // url: `/pages/groupPage/collage-details/collage-details?orderId=${orderId}`
  222. // })
  223. // wx.setNavigationBarTitle({
  224. // title: '拼团详情'
  225. // })
  226. // }, 1800)
  227. // } else {
  228. // wx.redirectTo({
  229. // url: `/pages/groupPage/grade-details/grade-details?productId=${that.data.productId}`
  230. // })
  231. // }
  232. // }
  233. // })
  234. },
  235. 'fail': function (res) {
  236. console.log('支付失败', res)
  237. that.setData({
  238. haveTapMoney: false
  239. })
  240. }
  241. })
  242. },
  243. showAlert: function () {
  244. this.setData({
  245. alertFlag: !this.data.alertFlag
  246. })
  247. },
  248. /**
  249. * 生命周期函数--监听页面加载
  250. */
  251. onLoad: function (options) {
  252. console.log(options)
  253. if (options.goBackHome) {
  254. this.setData({
  255. goBackHome: true,
  256. alertFlag:true
  257. })
  258. }
  259. // const productId = options.productId;
  260. this.getBookInfo(options.productId);
  261. this.areYouBookSuper(options.productId)
  262. this.getGroupInfo(options.productId)
  263. // if (productId) {
  264. this.setData({
  265. productId: options.productId
  266. })
  267. // }
  268. },
  269. // 课本鉴权
  270. areYouBookSuper: function (productId) {
  271. // const productArr = [];
  272. // productArr.push(productId);
  273. httpRequestApi.areYouSuperSecond(productId).success(res => {
  274. console.log(res)
  275. this.setData({
  276. imSuper: res.data.data.auth ? true : false,
  277. lastThreeYears: res.data.data.auth ? util.addThreeYears(res.data.data.auth.endTime) : false,
  278. knowFlag: res.data.data.auth ? false : true,
  279. menuFlag: res.data.data.auth ? true : false,
  280. haveCreatedHelp: res.data.data.createdShare, // 创建过助力团
  281. haveJoinHelp: res.data.data.joinShare, // 参加过助力团
  282. haveJoinNormal: res.data.data.joinOrder, // 参加过支付团
  283. tasteDay: res.data.data.auth ? util.formatDate(res.data.data.auth.endTime - res.data.data.currentTime,5) : ''
  284. })
  285. console.log(this.data.imSuper)
  286. console.log(this.data.lastThreeYears)
  287. })
  288. },
  289. getBookInfo: function (productId) {
  290. //课本详情
  291. httpRequestApi.getBookDetail(wx.getStorageSync('uid'), productId).success((res) => {
  292. console.log('课本详情', res.data.data);
  293. const bookInfo = res.data.data.product;
  294. const lessonList = res.data.data.lessonList;
  295. wx.setNavigationBarTitle({
  296. title: '语文 ' + bookInfo.subTitle
  297. })
  298. const data = app.towxml.toJson(
  299. bookInfo.description,
  300. 'markdown',
  301. this
  302. )
  303. this.setData({
  304. titleIcon: bookInfo.bgImg,
  305. title: bookInfo.title,
  306. bookInfo: bookInfo.description,
  307. article: data
  308. })
  309. const lessonTemp = [];
  310. lessonList.forEach(item => {
  311. const temp = {};
  312. temp.id = item.id;
  313. temp.title = item.title;
  314. temp.readNum = item.readCount;
  315. lessonTemp.push(temp);
  316. });
  317. this.setData({
  318. lessonList: lessonTemp
  319. });
  320. })
  321. },
  322. getGroupInfo: function (productId) {
  323. //团购内容
  324. httpRequestApi.getGroupPurchaseInfo(productId).success((res) => {
  325. console.log(res)
  326. this.setData({
  327. payList: res.data.data
  328. })
  329. })
  330. },
  331. goToClass: function (e) {
  332. let id = e.currentTarget.dataset.id;
  333. let title = e.currentTarget.dataset.title;
  334. wx.navigateTo({
  335. url: `../../main/class/class?id=${id}&title=${title}`
  336. })
  337. },
  338. /**
  339. * 生命周期函数--监听页面初次渲染完成
  340. */
  341. onReady: function () {
  342. //获取弹窗组件
  343. this.popup = this.selectComponent("#popup");
  344. },
  345. modalConfirmHandler: function(){
  346. this.setData({
  347. isModalShow: false
  348. })
  349. if(this.data.modalType === 'image'){
  350. if (this.data.groupCount !== 1) {
  351. this.popup.close();
  352. setTimeout(() => {
  353. wx.navigateTo({
  354. url: `/pages/groupPage/collage-details/collage-details?orderId=${this.data.orderId}`
  355. })
  356. wx.setNavigationBarTitle({
  357. title: '拼团详情'
  358. })
  359. }, 1800)
  360. } else {
  361. wx.redirectTo({
  362. url: `/pages/groupPage/grade-details/grade-details?productId=${this.data.productId}`
  363. })
  364. }
  365. }
  366. },
  367. modalCloseHandler: function(){
  368. this.setData({
  369. isModalShow: false
  370. })
  371. }
  372. })