index.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  1. // pages/yuezhan/pay_page/index.js
  2. const {
  3. request,
  4. serverName
  5. } = require('../../../utils/services');
  6. const {
  7. newRequestFns,
  8. newServerName
  9. } = require('../../../utils/newServices.js');
  10. // const WxParse = require('../../../common/component/wxParse/wxParse.js');
  11. const {
  12. Toast,
  13. removeArrItem
  14. } = require('../../../utils/util.js');
  15. const {
  16. defaultImg
  17. } = require('../../../utils/images');
  18. const WxParse = require('../../../common/component/wxParse/wxParse.js');
  19. const app = getApp();
  20. Page({
  21. /**
  22. * 页面的初始数据
  23. */
  24. data: {
  25. isAgree: true,
  26. logo_img: serverName +"/company_logo.jpg",
  27. half_star_img: "../../../imgs/icon/half.png",
  28. empty_star_img: "../../../imgs/icon/empty.png",
  29. full_star_img: "../../../imgs/icon/full.png",
  30. show_star: [{
  31. }],
  32. exhibitionDetail: {}
  33. },
  34. clickCell: function() {
  35. console.log(this.data.active);
  36. this.setData({
  37. active: !this.data.active
  38. })
  39. },
  40. fix_starImg: function(points) {
  41. let strPoints = String(Number(points).toFixed(2));
  42. let show_Arr = [];
  43. let ten = strPoints.split('.')[0] || 0;
  44. let unit = strPoints.split('.')[1] || 0;
  45. let surPlus = 0;
  46. if (strPoints < 0) {
  47. return
  48. }
  49. if (ten) {
  50. for (let i = 0; i < Number(ten); i++) {
  51. show_Arr.push({
  52. 'img': this.data.full_star_img
  53. })
  54. }
  55. surPlus = 5 - Number(ten);
  56. }
  57. if (unit && surPlus>0) {
  58. let numUnit = Number(unit.substr(0, 1)) || 0
  59. if (numUnit > 0) {
  60. // let fix_unit = Math.round(numUnit);
  61. // switch (true) {
  62. // case numUnit > 5:
  63. // show_Arr.push({
  64. // 'img': this.data.half_star_img
  65. // })
  66. // break;
  67. // case numUnit <= 5:
  68. // show_Arr.push({
  69. // 'img': this.data.half_star_img
  70. // })
  71. // break;
  72. // default:
  73. // break
  74. // }
  75. show_Arr.push({
  76. 'img': this.data.half_star_img
  77. })
  78. } else if (numUnit == 0) {
  79. show_Arr.push({
  80. 'img': this.data.empty_star_img
  81. })
  82. } else {
  83. return
  84. }
  85. }
  86. if (surPlus>0){
  87. for (let i = 0; i < surPlus - 1; i++) {
  88. show_Arr.push({
  89. 'img': this.data.empty_star_img
  90. })
  91. }
  92. }
  93. return show_Arr
  94. },
  95. readMore: function() {
  96. this.setData({
  97. readActive: !this.data.readActive
  98. })
  99. },
  100. addCommentLike: function(e) {
  101. let {
  102. type,
  103. id,
  104. idx
  105. } = e.currentTarget.dataset;
  106. console.log(idx, type, id)
  107. let {
  108. comments
  109. } = this.data;
  110. Toast.showToast2('loading');
  111. let loginSessionKey = wx.getStorageSync('token') || "";
  112. // if (loginSessionKey){
  113. newRequestFns['commentLike']({
  114. loginSessionKey,
  115. commentId: id,
  116. type: Number(type),
  117. }, "post", res => {
  118. if (res.data.code > -1) {
  119. console.log("asdw", comments.content[idx].hasLike)
  120. comments.content[idx].hasLike = res.data.data.hasLike
  121. if (res.data.data.hasLike) {
  122. comments.content[idx].likeCount += 1;
  123. } else {
  124. comments.content[idx].likeCount -= 1;
  125. }
  126. this.setData({
  127. comments: comments
  128. })
  129. }
  130. }, err => {
  131. }, complete => {
  132. Toast.hideLoading();
  133. })
  134. // }
  135. },
  136. addLike: function() {
  137. // if (this.data.isLike) {
  138. // this.setData({
  139. // isLike: !this.data.isLike,
  140. // likeNum: this.data.likeNum - 1
  141. // })
  142. // } else {
  143. // this.setData({
  144. // isLike: !this.data.isLike,
  145. // likeNum: this.data.likeNum + 1
  146. // })
  147. // }
  148. let loginSessionKey = wx.getStorageSync('token') || "";
  149. let {
  150. exhibitionId,
  151. exhibitionDetail,
  152. type:isChange
  153. } = this.data;
  154. let {
  155. collectedArr,
  156. collectedChange
  157. } = app.globalData, hasItem = true;
  158. let type = exhibitionDetail.hasCollect
  159. // if (loginSessionKey){
  160. newRequestFns['isCollect']({
  161. loginSessionKey,
  162. exhibitionId: exhibitionId,
  163. type: Number(type),
  164. }, "post", res => {
  165. if (res.data.code > -1) {
  166. for (let i = 0; i < collectedArr.length; i++) {
  167. if (collectedArr[i].collectedId && exhibitionId == collectedArr[i].collectedId) {
  168. console.log("true")
  169. collectedArr[i] = {
  170. collectedId: exhibitionId,
  171. status: res.data.data.hasCollect,
  172. }
  173. hasItem = false;
  174. }
  175. }
  176. if (hasItem) {
  177. collectedArr.push({
  178. collectedId: exhibitionId,
  179. status: res.data.data.hasCollect,
  180. })
  181. }
  182. app.globalData.collectedArr = collectedArr;
  183. console.log(isChange, res.data.data.hasCollect)
  184. if (isChange == res.data.data.hasCollect){
  185. app.globalData.collectedChange = false;
  186. }else{
  187. app.globalData.collectedChange = true;
  188. }
  189. exhibitionDetail.hasCollect = res.data.data.hasCollect
  190. if (exhibitionDetail.hasCollect) {
  191. exhibitionDetail.collectionsCount += 1;
  192. } else {
  193. exhibitionDetail.collectionsCount -= 1;
  194. }
  195. this.setData({
  196. exhibitionDetail: exhibitionDetail,
  197. })
  198. }
  199. }, err => {
  200. }, complete => {
  201. Toast.hideLoading();
  202. })
  203. // }
  204. },
  205. tapToCommentDetail: function() {
  206. let {
  207. exhibitionId
  208. } = this.data;
  209. console.log('detail')
  210. wx.navigateTo({
  211. // url: `../../zl_detail/create_evaluation/index?id=${exhibitionId}`,
  212. url: `../comment_detail/index?id=${exhibitionId}`,
  213. success: function(res) {},
  214. fail: function(res) {},
  215. complete: function(res) {},
  216. })
  217. },
  218. navigateToLocation: function() {
  219. let {
  220. latitude,
  221. longitude
  222. } = this.data;
  223. wx.openLocation({
  224. exhibitionId: 0,
  225. latitude: latitude,
  226. longitude: longitude,
  227. scale: 28,
  228. success: function(res) {},
  229. fail: function(res) {},
  230. complete: function(res) {}
  231. });
  232. },
  233. /**
  234. * 生命周期函数--监听页面加载
  235. */
  236. onLoad: function(options) {
  237. this.setData({
  238. defaultImg,
  239. exhibitionId: options.id,
  240. serverName
  241. })
  242. // this.getExhibitionDetail();
  243. let {
  244. cookieIDs = []
  245. } = app.globalData;
  246. let id = options.id;
  247. let hasItem = true;
  248. for (let i = 0; i < cookieIDs.length; i++) {
  249. if (cookieIDs[i] && id == cookieIDs[i]) {
  250. cookieIDs = removeArrItem(cookieIDs, cookieIDs[i])
  251. }
  252. }
  253. if (hasItem && id != undefined && (typeof(Number(id)) == 'number')) {
  254. cookieIDs.unshift(id)
  255. }
  256. console.log(id)
  257. app.globalData.cookieIDs = cookieIDs
  258. console.log(app.globalData.cookieIDs)
  259. },
  260. getExhibitionDetail: function() {
  261. let exhibitionId = this.data.exhibitionId;
  262. newRequestFns["getExhibitionDetail"]({
  263. exhibitionId: exhibitionId
  264. }, "", res => {
  265. let {
  266. data: exhibitionDetail
  267. } = res.data;
  268. let {
  269. description,
  270. openTime,
  271. comments,
  272. imageUrl
  273. } = exhibitionDetail;
  274. app.globalData.currentShareImg = imageUrl
  275. let _show_star = this.fix_starImg(exhibitionDetail.score || '0.0')
  276. if (comments){
  277. let commentsCon = comments.content;
  278. for (let i = 0; i < commentsCon.length; i++) {
  279. let comments_star = this.fix_starImg(commentsCon[i].score || '0.0')
  280. commentsCon[i]['imgObj'] = comments_star
  281. }
  282. }
  283. // console.log('asdasd', commentsCon)
  284. this.setData({
  285. exhibitionDetail,
  286. likeNum: exhibitionDetail.collectionsCount,
  287. type: exhibitionDetail.hasCollect,
  288. comments,
  289. show_star: _show_star
  290. });
  291. WxParse.wxParse('description', 'html', description, this, 5);
  292. WxParse.wxParse('openTime', 'html', openTime, this, 5);
  293. console.log(exhibitionDetail)
  294. })
  295. },
  296. bindAgreeChange: function(e) {
  297. this.setData({
  298. isAgree: !!e.detail.value.length
  299. });
  300. },
  301. tapToComement: function() {
  302. let {
  303. exhibitionId
  304. } = this.data;
  305. wx.navigateTo({
  306. url: `../../zl_detail/create_evaluation/index?id=${exhibitionId}`,
  307. success: function(res) {},
  308. fail: function(res) {},
  309. complete: function(res) {},
  310. })
  311. },
  312. tapToDetail: function() {
  313. wx.navigateTo({
  314. url: './rule_detail/index',
  315. success: function(res) {},
  316. fail: function(res) {},
  317. complete: function(res) {},
  318. })
  319. },
  320. doWeChatPay: function() {
  321. let loginSessionKey = wx.getStorageSync("token");
  322. let {
  323. exhibitionId,
  324. isAgree,
  325. exhibitionDetail
  326. } = this.data;
  327. let {
  328. hasPay
  329. } = exhibitionDetail;
  330. let {
  331. productPrice,
  332. showLink
  333. } = this.data.exhibitionDetail.product;
  334. console.log(productPrice)
  335. console.log(isAgree)
  336. if (hasPay) {
  337. app.globalData.currentUrl = showLink
  338. // console.log('dwdwdw', app.globalData.currentUrl)
  339. wx.navigateTo({
  340. url: `../../wv_page/index`,
  341. success: function(res) {},
  342. fail: function(res) {},
  343. complete: function(res) {},
  344. })
  345. } else {
  346. if (isAgree) {
  347. if (productPrice) {
  348. request['orderPay']({
  349. amount: productPrice,
  350. loginSessionKey,
  351. exhibitionId
  352. }, "post", res => {
  353. const {
  354. data: wechatPayModel
  355. } = res.data;
  356. const {
  357. timeStamp,
  358. nonceStr,
  359. signType,
  360. paySign,
  361. package: packageStr
  362. } = wechatPayModel;
  363. console.log(timeStamp,
  364. nonceStr,
  365. signType,
  366. paySign)
  367. // prettier-ignore
  368. wx.requestPayment({
  369. timeStamp,
  370. nonceStr,
  371. signType,
  372. paySign,
  373. 'package': packageStr,
  374. success: res => {
  375. console.log(res);
  376. app.globalData.currentUrl = showLink
  377. // console.log('dwdwdw', app.globalData.currentUrl)
  378. wx.navigateTo({
  379. url: `../../wv_page/index`,
  380. success: function (res) { },
  381. fail: function (res) { },
  382. complete: function (res) { },
  383. })
  384. },
  385. fail: err => {
  386. console.log(err);
  387. Toast.showToast2('warn', '支付取消');
  388. }
  389. });
  390. })
  391. } else {
  392. app.globalData.currentUrl = showLink
  393. wx.navigateTo({
  394. url: `../../wv_page/index`,
  395. success: function(res) {},
  396. fail: function(res) {},
  397. complete: function(res) {},
  398. })
  399. // Toast.showToast('tip', "暂时无法支付", () => {
  400. // return;
  401. // })
  402. }
  403. } else {
  404. Toast.showToast('tip', "购买/查看需要同意相关条款", () => {
  405. return;
  406. })
  407. }
  408. }
  409. },
  410. /**
  411. * 生命周期函数--监听页面初次渲染完成
  412. */
  413. onReady: function() {
  414. },
  415. /**
  416. * 生命周期函数--监听页面显示
  417. */
  418. onShow: function() {
  419. this.getExhibitionDetail();
  420. },
  421. /**
  422. * 生命周期函数--监听页面隐藏
  423. */
  424. onHide: function() {
  425. },
  426. /**
  427. * 生命周期函数--监听页面卸载
  428. */
  429. onUnload: function() {
  430. },
  431. /**
  432. * 页面相关事件处理函数--监听用户下拉动作
  433. */
  434. onPullDownRefresh: function() {
  435. },
  436. /**
  437. * 页面上拉触底事件的处理函数
  438. */
  439. onReachBottom: function() {
  440. },
  441. /**
  442. * 用户点击右上角分享
  443. */
  444. onShareAppMessage: function() {
  445. }
  446. })