groupDetails.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774
  1. // 团长接龙详情
  2. var app = getApp();
  3. var status = require('../../utils/index.js');
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. showGoodsModal: false,
  10. showCommentModal: false,
  11. pid: 0,
  12. showShareModal: false,
  13. list: [],
  14. loadText: "加载中...",
  15. noData: 0,
  16. loadMore: true,
  17. orderList: [],
  18. noOrderMore: false,
  19. noOrderData: 0,
  20. solitaire_is_message: 0
  21. },
  22. imagePath: '',
  23. options: '',
  24. page: 1,
  25. orderPage: 1,
  26. /**
  27. * 生命周期函数--监听页面加载
  28. */
  29. onLoad: function (options) {
  30. status.setNavBgColor();
  31. this.options = options;
  32. let id = options.id || 0;
  33. if(!id) {
  34. app.util.message('参数错误', 'redirect:/lionfish_comshop/moduleA/solitaire/groupIndex', 'error');
  35. }
  36. },
  37. initFn() {
  38. let that = this;
  39. let id = this.options && this.options.id || 0;
  40. this.page = 1;
  41. this.setData({
  42. list: [],
  43. loadText: "加载中...",
  44. noData: 0,
  45. loadMore: true
  46. }, () => {
  47. id && that.getData(id);
  48. })
  49. },
  50. /**
  51. * 生命周期函数--监听页面显示
  52. */
  53. onShow: function () {
  54. let id = this.options && this.options.id || 0;
  55. id && this.getData(id), this.getOrderList();
  56. },
  57. onHide: function () {
  58. this.setData({ clearTime: true })
  59. },
  60. /**
  61. * 获取详情
  62. */
  63. getData: function (id) {
  64. const token = wx.getStorageSync('token');
  65. let that = this;
  66. app.util.request({
  67. url: 'entry/wxapp/index',
  68. data: {
  69. controller: 'solitaire.get_solitaire_detail',
  70. id,
  71. token,
  72. is_head: 1
  73. },
  74. dataType: 'json',
  75. success: function (res) {
  76. if (res.data.code == 0) {
  77. let { head_data, soli_info, solitaire_target, solitaire_target_takemember, solitaire_target_takemoney, solitaire_target_type,solitaire_is_message } = res.data;
  78. // 完成接龙差值
  79. let {
  80. soli_total_money, //一共下单金额
  81. order_count //一共下多少单
  82. } = soli_info;
  83. let diffMoney = solitaire_target_takemoney * 1 - soli_total_money * 1;
  84. let diffMember = solitaire_target_takemember * 1 - order_count * 1;
  85. that.setData({
  86. community: head_data || '',
  87. soli_info,
  88. solitaire_target,
  89. solitaire_target_takemember,
  90. solitaire_target_takemoney,
  91. solitaire_target_type,
  92. diffMoney,
  93. diffMember,
  94. clearTime: false,
  95. solitaire_is_message
  96. }, ()=>{
  97. that.drawImg(head_data, soli_info);
  98. })
  99. if(solitaire_is_message==1){
  100. that.getCommentList()
  101. }
  102. } else if (res.data.code == 2) {
  103. app.util.message('您还未登录', 'switchTo:/lionfish_comshop/pages/index/index', 'error');
  104. return;
  105. } else {
  106. app.util.message(res.data.msg, 'redirect:/lionfish_comshop/moduleA/solitaire/groupIndex', 'error');
  107. return;
  108. }
  109. }
  110. })
  111. },
  112. showImgPrev: function (event){
  113. var idx = event ? event.currentTarget.dataset.idx : '';
  114. let urls = this.data.soli_info.images_list || [];
  115. wx.previewImage({
  116. current: urls[idx],
  117. urls
  118. });
  119. },
  120. /**
  121. * 商品弹窗
  122. */
  123. handleGoodsModal: function(){
  124. this.setData({
  125. showGoodsModal: !this.data.showGoodsModal
  126. })
  127. },
  128. /**
  129. * 评论弹窗
  130. */
  131. handleCommentModal: function () {
  132. this.setData({
  133. showCommentModal: !this.data.showCommentModal,
  134. pid: 0
  135. })
  136. },
  137. /**
  138. * 留言
  139. */
  140. subComment: function (e) {
  141. let { soli_info, pid } = this.data;
  142. let soli_id = soli_info.id || '';
  143. let content = e.detail.value.content || '';
  144. if (content == '') {
  145. wx.showToast({
  146. title: '请输入内容',
  147. icon: 'none'
  148. })
  149. return;
  150. }
  151. let that = this;
  152. const token = wx.getStorageSync('token');
  153. app.util.request({
  154. url: 'entry/wxapp/index',
  155. data: {
  156. controller: 'solitaire.sub_solipost',
  157. soli_id,
  158. content,
  159. pid,
  160. token
  161. },
  162. dataType: 'json',
  163. success: function (res) {
  164. if (res.data.code == 0) {
  165. let { post_id, cur_time } = res.data;
  166. let userInfo = wx.getStorageSync('userInfo');
  167. let list = that.data.list;
  168. if (pid!=0) {
  169. let comment = {
  170. id: post_id,
  171. pid,
  172. username: userInfo.nickName,
  173. content
  174. }
  175. let idx = list.findIndex(item => item.id == pid);
  176. if (idx !== -1) {
  177. list[idx].reply.push(comment);
  178. }
  179. } else {
  180. let comment = {
  181. id: post_id,
  182. soli_id,
  183. pid,
  184. username: userInfo.nickName,
  185. avatar: userInfo.avatarUrl,
  186. content,
  187. fav_count: 0,
  188. addtime: cur_time,
  189. reply: [],
  190. is_agree: false
  191. }
  192. list.unshift(comment);
  193. }
  194. soli_info.comment_total = soli_info.comment_total * 1 + 1;
  195. that.setData({ soli_info, list, content: '', showCommentModal: false, noData: 0 })
  196. app.util.message(res.data.msg || '留言成功', '', 'success');
  197. } else {
  198. app.util.message(res.data.msg || '留言失败', '', 'error');
  199. }
  200. }
  201. })
  202. },
  203. /**
  204. * 回复留言
  205. */
  206. replyComment: function(e){
  207. let pid = e.currentTarget.dataset.id || '';
  208. this.setData({
  209. showCommentModal: !this.data.showCommentModal,
  210. pid
  211. })
  212. },
  213. /**
  214. * 删除留言
  215. */
  216. deleteComment: function(e){
  217. let that = this;
  218. let id = e.currentTarget.dataset.id || '';
  219. let idx = e.currentTarget.dataset.idx || '';
  220. id && wx.showModal({
  221. title: '操作提示',
  222. content: '确认删除此留言?',
  223. confirmColor: '#ff5041',
  224. success(res) {
  225. if (res.confirm) {
  226. wx.showLoading({ title: '删除中...' })
  227. const token = wx.getStorageSync('token');
  228. app.util.request({
  229. url: 'entry/wxapp/index',
  230. data: {
  231. controller: 'solitaire.delete_comment',
  232. id,
  233. token
  234. },
  235. dataType: 'json',
  236. success: function (res) {
  237. wx.hideLoading();
  238. if (res.data.code == 0) {
  239. let { list, soli_info } = that.data;
  240. list.splice(idx, 1);
  241. let noData = false;
  242. if (list.length==0) noData = true;
  243. soli_info.comment_total = soli_info.comment_total * 1 - 1;
  244. that.setData({ list, soli_info, noData });
  245. wx.showToast({
  246. title: res.data.msg || '删除成功',
  247. icon: 'none'
  248. })
  249. } else if (res.data.code == 2) {
  250. app.util.message('您还未登录', 'switchTo:/lionfish_comshop/pages/index/index', 'error');
  251. return;
  252. } else {
  253. app.util.message(res.data.msg || '删除失败', '', 'error');
  254. }
  255. }
  256. })
  257. }
  258. }
  259. });
  260. },
  261. /**
  262. * 点赞
  263. */
  264. favComment: function (e) {
  265. let that = this;
  266. let soli_info = this.data.soli_info;
  267. let soli_id = soli_info.id || '';
  268. let post_id = e ? e.currentTarget.dataset.post_id : '';
  269. let idx = e ? e.currentTarget.dataset.idx : 0;
  270. const token = wx.getStorageSync('token');
  271. post_id && app.util.request({
  272. url: 'entry/wxapp/index',
  273. data: {
  274. controller: 'solitaire.fav_soli_post',
  275. soli_id,
  276. post_id,
  277. token
  278. },
  279. dataType: 'json',
  280. success: function (res) {
  281. if (res.data.code == 0) {
  282. if (res.data.do == 1) {
  283. // 点赞成功
  284. let list = that.data.list;
  285. list[idx].is_agree = true;
  286. list[idx].fav_count = list[idx].fav_count * 1 + 1;
  287. that.setData({ list })
  288. } else {
  289. // 取消成功
  290. let list = that.data.list;
  291. list[idx].is_agree = false;
  292. list[idx].fav_count = list[idx].fav_count * 1 - 1;
  293. that.setData({ list })
  294. }
  295. } else if (res.data.code == 1) {
  296. that.setData({ needAuth: true, showAuthModal: true })
  297. } else {
  298. wx.showToast({
  299. title: res.data.msg || '点赞失败',
  300. icon: 'none'
  301. })
  302. }
  303. }
  304. })
  305. },
  306. /**
  307. * 结束接龙
  308. */
  309. endSolitaire: function (e) {
  310. let that = this;
  311. let soli_info = that.data.soli_info;
  312. let id = soli_info.id;
  313. id && wx.showModal({
  314. title: '操作提示',
  315. content: '确认终止此接龙吗?',
  316. confirmColor: '#ff5041',
  317. success(res) {
  318. if (res.confirm) {
  319. wx.showLoading({ title: '提交中...' })
  320. const token = wx.getStorageSync('token');
  321. app.util.request({
  322. url: 'entry/wxapp/index',
  323. data: {
  324. controller: 'solitaire.end_solitaire',
  325. id,
  326. token
  327. },
  328. dataType: 'json',
  329. success: function (res) {
  330. wx.hideLoading();
  331. if (res.data.code == 0) {
  332. soli_info.end = 1;
  333. that.setData({ soli_info });
  334. wx.showToast({
  335. title: res.data.msg || '接龙已终止',
  336. icon: 'none'
  337. })
  338. } else if (res.data.code == 2) {
  339. app.util.message('您还未登录', 'switchTo:/lionfish_comshop/pages/index/index', 'error');
  340. return;
  341. } else {
  342. app.util.message(res.data.msg || '操作失败', '', 'error');
  343. }
  344. }
  345. })
  346. }
  347. }
  348. });
  349. },
  350. drawImg: function (head, soli_info) {
  351. let images_list = soli_info.images_list;
  352. let qrcode_image = soli_info.qrcode_image;
  353. let content = soli_info.content.replace(/<[^&gt]+>|&[^&gt]+;/g, "").trim();
  354. content = content.replace(/<\/?.+?>/g, "");
  355. content = content.replace(/&nbsp;/g, "");
  356. let option = [];
  357. let h = 300
  358. if (images_list.length) {
  359. option.push({
  360. "type": "image",
  361. "url": images_list[0],
  362. "css":
  363. {
  364. "width": "442px",
  365. "height": "300px",
  366. "top": "230px",
  367. "left": "36px",
  368. "rotate": "0",
  369. "borderRadius": "",
  370. "borderWidth": "",
  371. "borderColor": "",
  372. "shadow": "",
  373. "mode": "scaleToFill"
  374. }
  375. })
  376. h = 0;
  377. }
  378. this.setData({
  379. template: {
  380. "width": "514px",
  381. "height": (710 - h) + "px",
  382. "background": "#fff",
  383. "views": [
  384. {
  385. "type": "image",
  386. "url": head.avatar,
  387. "css":
  388. {
  389. "width": "46px",
  390. "height": "46px",
  391. "top": "25px",
  392. "left": "36px",
  393. "rotate": "0",
  394. "borderRadius": "3px",
  395. "borderWidth": "",
  396. "borderColor": "#000000",
  397. "shadow": "",
  398. "mode": "scaleToFill"
  399. }
  400. },
  401. {
  402. "type": "text",
  403. "text": head.head_name,
  404. "css":
  405. {
  406. "color": "#000000",
  407. "background": "",
  408. "width": "385px",
  409. "height": "20.02px",
  410. "top": "30px",
  411. "left": "96px",
  412. "rotate": "0",
  413. "borderRadius": "",
  414. "borderWidth": "",
  415. "borderColor": "#000000",
  416. "shadow": "",
  417. "padding": "0px",
  418. "fontSize": "14px",
  419. "fontWeight": "bold",
  420. "maxLines": "1",
  421. "lineHeight": "20.202000000000005px",
  422. "textStyle": "fill",
  423. "textDecoration": "none",
  424. "fontFamily": "",
  425. "textAlign": "left"
  426. }
  427. },
  428. {
  429. "type": "text",
  430. "text": head.community_name,
  431. "css":
  432. {
  433. "color": "#999999",
  434. "background": "",
  435. "width": "385px",
  436. "height": "17.16px",
  437. "top": "52px",
  438. "left": "96px",
  439. "rotate": "0",
  440. "borderRadius": "",
  441. "borderWidth": "",
  442. "borderColor": "#000000",
  443. "shadow": "",
  444. "padding": "0px",
  445. "fontSize": "12px",
  446. "fontWeight": "normal",
  447. "maxLines": "1",
  448. "lineHeight": "17.316000000000003px",
  449. "textStyle": "fill",
  450. "textDecoration": "none",
  451. "fontFamily": "",
  452. "textAlign": "left"
  453. }
  454. },
  455. {
  456. "type": "text",
  457. "text": content,
  458. "css":
  459. {
  460. "color": "#666666",
  461. "background": "",
  462. "width": "442px",
  463. "height": "52.181999999999995px",
  464. "top": "158px",
  465. "left": "36px",
  466. "rotate": "0",
  467. "borderRadius": "",
  468. "borderWidth": "",
  469. "borderColor": "#000000",
  470. "shadow": "",
  471. "padding": "0px",
  472. "fontSize": "18px",
  473. "fontWeight": "normal",
  474. "maxLines": "2",
  475. "lineHeight": "25.974000000000004px",
  476. "textStyle": "fill",
  477. "textDecoration": "none",
  478. "fontFamily": "",
  479. "textAlign": "left"
  480. }
  481. },
  482. {
  483. "type": "text",
  484. "text": soli_info.solitaire_name,
  485. "css":
  486. {
  487. "color": "#000000",
  488. "background": "",
  489. "width": "442px",
  490. "height": "42.89999999999999px",
  491. "top": "95px",
  492. "left": "36px",
  493. "rotate": "0",
  494. "borderRadius": "",
  495. "borderWidth": "",
  496. "borderColor": "#000000",
  497. "shadow": "",
  498. "padding": "0px",
  499. "fontSize": "30px",
  500. "fontWeight": "normal",
  501. "maxLines": "1",
  502. "lineHeight": "43.290000000000006px",
  503. "textStyle": "fill",
  504. "textDecoration": "none",
  505. "fontFamily": "",
  506. "textAlign": "left"
  507. }
  508. },
  509. {
  510. "type": "text",
  511. "text": "一群人正在赶来接龙",
  512. "css":
  513. {
  514. "color": "#999999",
  515. "background": "",
  516. "width": "442px",
  517. "height": "22.88px",
  518. "top": (595 - h) + "px",
  519. "left": "204px",
  520. "rotate": "0",
  521. "borderRadius": "",
  522. "borderWidth": "",
  523. "borderColor": "#000000",
  524. "shadow": "",
  525. "padding": "0px",
  526. "fontSize": "16px",
  527. "fontWeight": "normal",
  528. "maxLines": "2",
  529. "lineHeight": "23.088000000000005px",
  530. "textStyle": "fill",
  531. "textDecoration": "none",
  532. "fontFamily": "",
  533. "textAlign": "left"
  534. }
  535. },
  536. {
  537. "type": "text",
  538. "text": "长按识别或扫码参与",
  539. "css":
  540. {
  541. "color": "#999999",
  542. "background": "",
  543. "width": "442px",
  544. "height": "22.88px",
  545. "top": (630 - h) + "px",
  546. "left": "204px",
  547. "rotate": "0",
  548. "borderRadius": "",
  549. "borderWidth": "",
  550. "borderColor": "#000000",
  551. "shadow": "",
  552. "padding": "0px",
  553. "fontSize": "16px",
  554. "fontWeight": "normal",
  555. "maxLines": "2",
  556. "lineHeight": "23.088000000000005px",
  557. "textStyle": "fill",
  558. "textDecoration": "none",
  559. "fontFamily": "",
  560. "textAlign": "left"
  561. }
  562. },
  563. {
  564. "type": "image",
  565. "url": qrcode_image,
  566. "css":
  567. {
  568. "width": "120px",
  569. "height": "120px",
  570. "top": (560 - h) + "px",
  571. "left": "356px",
  572. "rotate": "0",
  573. "borderRadius": "",
  574. "borderWidth": "",
  575. "borderColor": "#000000",
  576. "shadow": "",
  577. "mode": "scaleToFill"
  578. }
  579. },
  580. ...option
  581. ]
  582. }
  583. });
  584. },
  585. onImgOK(e) {
  586. this.imagePath = e.detail.path;
  587. this.setData({
  588. image: this.imagePath
  589. })
  590. },
  591. saveImage() {
  592. let that = this;
  593. wx.saveImageToPhotosAlbum({
  594. filePath: this.imagePath,
  595. success(res) {
  596. that.setData({ showShareModal: false })
  597. wx.showToast({
  598. title: '保存成功!'
  599. })
  600. },
  601. fail(res) {
  602. wx.showToast({
  603. title: '保存失败,请重试!',
  604. icon: 'none'
  605. })
  606. }
  607. });
  608. },
  609. handleShareModal: function () {
  610. this.setData({
  611. showShareModal: !this.data.showShareModal
  612. })
  613. },
  614. handleGoodsModal: function(e){
  615. if (this.data.showGoodsModal){
  616. this.setData({
  617. showGoodsModal: false,
  618. goodsModalList: []
  619. })
  620. } else {
  621. let idx = e ? e.currentTarget.dataset.idx : '';
  622. let orderList = this.data.orderList;
  623. let goodsModalList = orderList[idx].goodslist || [];
  624. this.setData({
  625. showGoodsModal: true,
  626. goodsModalList
  627. })
  628. }
  629. },
  630. /**
  631. * 获取评论列表
  632. */
  633. getCommentList: function () {
  634. let that = this;
  635. let id = this.options && this.options.id || 0;
  636. const token = wx.getStorageSync('token');
  637. wx.showLoading();
  638. app.util.request({
  639. url: 'entry/wxapp/index',
  640. data: {
  641. controller: 'solitaire.get_comment_list',
  642. page: this.page,
  643. token,
  644. id
  645. },
  646. dataType: 'json',
  647. success: function (res) {
  648. wx.hideLoading();
  649. if (res.data.code == 0) {
  650. let h = {};
  651. let list = res.data.data;
  652. if (list.length < 20) h.noMore = true;
  653. let oldList = that.data.list;
  654. list = oldList.concat(list);
  655. that.page++;
  656. that.setData({
  657. list,
  658. ...h
  659. })
  660. } else if (res.data.code == 1) {
  661. // 无数据
  662. if (that.page == 1) that.setData({
  663. noData: 1
  664. })
  665. that.setData({
  666. loadMore: false,
  667. noMore: false,
  668. loadText: "没有更多记录了~"
  669. })
  670. }
  671. }
  672. })
  673. },
  674. /**
  675. * 页面上拉触底事件的处理函数
  676. */
  677. onReachBottom: function () {
  678. if (!this.data.loadMore||this.data.solitaire_is_message==0) return false;
  679. this.getCommentList();
  680. },
  681. /**
  682. * 获取评论列表
  683. */
  684. getOrderList: function () {
  685. let that = this;
  686. let id = this.options && this.options.id || 0;
  687. wx.showLoading();
  688. app.util.request({
  689. url: 'entry/wxapp/index',
  690. data: {
  691. controller: 'solitaire.get_soli_order_list',
  692. page: this.orderPage,
  693. id,
  694. size: 5
  695. },
  696. dataType: 'json',
  697. success: function (res) {
  698. wx.hideLoading();
  699. if (res.data.code == 0) {
  700. let h = {};
  701. let list = res.data.data;
  702. if (list.length < 5) h.noOrderMore = true;
  703. let oldList = that.data.orderList;
  704. let orderList = oldList.concat(list);
  705. that.orderPage++;
  706. that.setData({
  707. orderList,
  708. ...h
  709. })
  710. } else if (res.data.code == 1) {
  711. // 无数据
  712. let h = {};
  713. if (that.orderPage == 1) h.noOrderData = 1;
  714. that.setData({
  715. noOrderMore: true,
  716. ...h
  717. })
  718. }
  719. }
  720. })
  721. },
  722. getMoreOrder: function(){
  723. this.data.noOrderMore || this.getOrderList();
  724. },
  725. /**
  726. * 用户点击右上角分享
  727. */
  728. onShareAppMessage: function () {
  729. let share_id = wx.getStorageSync('member_id') || '';
  730. let soli_info = this.data.soli_info || '';
  731. let title = soli_info.solitaire_name || '';
  732. let share_path = `lionfish_comshop/moduleA/solitaire/details?id=${soli_info.id}&share_id=${share_id}`;
  733. return {
  734. title,
  735. path: share_path,
  736. success: function (res) {
  737. // 转发成功
  738. },
  739. fail: function (res) {
  740. // 转发失败
  741. }
  742. }
  743. }
  744. })