index.js 11 KB

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