findword.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  1. // pages/findword/findword.js
  2. var app=getApp();
  3. var utils=require("../../../utils/http");
  4. let page=1;
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. datashow: false,
  11. keytext:'',
  12. wordType: "1",
  13. tagType: "",
  14. toolflag: false,
  15. dataList: [], // 列表数据
  16. titleList:[],
  17. page:1,
  18. imgUrl:app.globalData.imgUrl,
  19. date:0,
  20. titflag:true,
  21. wordflag:false,
  22. quesionflag:false,
  23. type:1,//1是一般搜索,2是热词搜索
  24. nowid:'',
  25. nowwordobj:{},
  26. answerflag:false,
  27. hotwordflag:false,
  28. allcommentNum:0,
  29. commentArr:[],
  30. comments:''
  31. },
  32. /**
  33. * 生命周期函数--监听页面加载
  34. */
  35. onLoad: function (options) {
  36. var that=this;
  37. this.setData({
  38. type:options.type,
  39. word:options.word
  40. })
  41. wx.showLoading();
  42. this.wordlistfun();
  43. },
  44. unsuretap: function () {
  45. this.setData({
  46. quesionflag:true,
  47. okeytext:this.data.word
  48. })
  49. },
  50. submitap:function(){
  51. const that=this;
  52. if(!this.data.okeytext){
  53. wx.showToast({
  54. title: '提交的问题不能为空!',
  55. icon: 'none',
  56. duration: 2000
  57. })
  58. return false;
  59. }
  60. that.setData({
  61. quesionflag:false
  62. })
  63. utils.$post({
  64. url: app.globalData.webUrl + 'api/talkskill/submit_questions',
  65. header: {
  66. 'Authorization':'bearer '+app.globalData.token
  67. },
  68. data:{
  69. questions:that.data.okeytext
  70. },
  71. success: function (res) {
  72. if (res.data.code == "0"){
  73. wx.showToast({
  74. title:res.data.msg,
  75. icon: 'none',
  76. duration: 2000
  77. })
  78. }
  79. setTimeout(() => {
  80. wx.hideLoading()
  81. }, 1200);
  82. }
  83. })
  84. },
  85. closeask: function () {
  86. this.setData({
  87. quesionflag:false
  88. })
  89. },
  90. closeword: function () {
  91. this.setData({
  92. wordflag:false
  93. })
  94. },
  95. asktap:function(e){
  96. this.setData({
  97. answerflag:true,
  98. comments:this.data.nowwordobj.content
  99. })
  100. },
  101. closeasktap:function(e){
  102. this.setData({
  103. answerflag:false
  104. })
  105. },
  106. askcommerntap:function(e){
  107. this.setData({
  108. comments: e.detail.value,
  109. })
  110. },
  111. commentap:function(e){
  112. const that=this;
  113. if(!this.data.comments){
  114. wx.showToast({
  115. title: '答案不能为空!',
  116. icon: 'none',
  117. duration: 2000
  118. })
  119. return false;
  120. }
  121. if(this.data.comments==this.data.nowwordobj.content){
  122. wx.showToast({
  123. title: '您未进行优化操作,无法提交!',
  124. icon: 'none',
  125. duration: 2000
  126. })
  127. return false;
  128. }
  129. that.setData({
  130. answerflag:false
  131. })
  132. wx.showLoading({
  133. title: '评论中...',
  134. })
  135. utils.$post({
  136. url: app.globalData.webUrl + 'api/talkskill/addComment',
  137. header: {
  138. 'Authorization':'bearer '+app.globalData.token
  139. },
  140. data:{
  141. taid:that.data.nowid,//话术id
  142. content:that.data.comments,//内容
  143. },
  144. success: function (res) {
  145. if (res.data.code == "0") {
  146. wx.showToast({
  147. title: '评论成功!',
  148. icon: 'none',
  149. duration: 2000
  150. })
  151. that.setData({
  152. sayflag:false,
  153. comments:''
  154. })
  155. page=0;
  156. that.comment();
  157. }
  158. setTimeout(() => {
  159. wx.hideLoading()
  160. }, 1200);
  161. }
  162. })
  163. },
  164. zantap:function(e){
  165. const that=this;
  166. let idx=e.currentTarget.dataset.idx,commentArr=that.data.commentArr;
  167. let str="";
  168. if(commentArr[idx].ispraise==0){
  169. str='api/talkskill/praise';
  170. }else{
  171. str='api/talkskill/praiseCancel';
  172. }
  173. utils.$post({
  174. url: app.globalData.webUrl + str,
  175. header: {
  176. 'Authorization':'bearer '+app.globalData.token
  177. },
  178. data:{
  179. id:e.currentTarget.dataset.wid,
  180. },
  181. success: function (res) {
  182. if (res.data.code == "0"){
  183. if(commentArr[idx].ispraise==0){
  184. commentArr[idx].praise=commentArr[idx].praise*1+1;
  185. commentArr[idx].ispraise=1;
  186. }else{
  187. commentArr[idx].praise=commentArr[idx].praise-1;
  188. commentArr[idx].ispraise=0;
  189. }
  190. that.setData({
  191. commentArr:commentArr
  192. })
  193. }
  194. }
  195. })
  196. },
  197. wordmsg:function(){
  198. const that=this;
  199. that.comment();
  200. utils.$post({
  201. url: app.globalData.webUrl + 'api/talkskill/talkskill_xq',
  202. header: {
  203. 'Authorization':'bearer '+app.globalData.token
  204. },
  205. data:{
  206. id:that.data.nowid,
  207. },
  208. success: function (res) {
  209. wx.hideLoading();
  210. if (res.data.code == "0"){
  211. that.setData({
  212. nowwordobj:res.data.data
  213. })
  214. }
  215. }
  216. })
  217. },
  218. comment:function(){
  219. let that=this;
  220. page=page*1+1;
  221. utils.$post({
  222. url: app.globalData.webUrl + 'api/talkskill/commentList',
  223. header: {
  224. 'Authorization':'bearer '+app.globalData.token
  225. },
  226. data:{
  227. taid:that.data.nowid,//话术id
  228. page:page,
  229. },
  230. success: function (res) {
  231. let commentArr=that.data.commentArr;
  232. if (res.data.code == "0") {
  233. commentArr=(page==1?res.data.data:(commentArr.concat(res.data.data)));
  234. that.setData({
  235. allcommentNum:res.data.count,
  236. commentArr:commentArr,
  237. })
  238. }
  239. setTimeout(() => {
  240. wx.hideLoading()
  241. }, 1200);
  242. }
  243. })
  244. },
  245. /**
  246. * 生命周期函数--监听页面初次渲染完成
  247. */
  248. onReady: function () {
  249. },
  250. dothis:function(){},
  251. wordlistfun:function(){
  252. var that=this;
  253. that.setData({
  254. page:1
  255. })
  256. if(that.data.keytext==''){
  257. that.setData({
  258. titflag:true
  259. })
  260. }else{
  261. that.setData({
  262. titflag:false,
  263. })
  264. }
  265. utils.$post({
  266. url: app.globalData.webUrl + 'api/talkskill/lists',
  267. header: {
  268. 'Authorization':'bearer '+app.globalData.token
  269. },
  270. data:{
  271. hot_keyword: that.data.type==2?that.data.word:'',
  272. page: that.data.page,
  273. label: '',
  274. keyword:that.data.type==1?that.data.word:''
  275. },
  276. success: function (res) {
  277. wx.hideLoading();
  278. if (res.data.code == "0"){
  279. var list=res.data.data;
  280. that.setData({
  281. dataList: list,
  282. datashow:true
  283. })
  284. }
  285. }
  286. })
  287. },
  288. wordtap:function(e){
  289. if(e.detail.scrollTop>=230){
  290. this.setData({
  291. toolflag:true
  292. })
  293. }else{
  294. this.setData({
  295. toolflag:false
  296. })
  297. }
  298. },
  299. tagTap:function(e){
  300. var that=this;
  301. this.setData({
  302. tagType:e.target.dataset.text,
  303. datashow:false
  304. })
  305. wx.showLoading();
  306. this.wordlistfun();
  307. },
  308. wordTap:function(e){
  309. var that=this;
  310. this.setData({
  311. wordType:e.target.dataset.type,
  312. datashow:false
  313. })
  314. wx.showLoading();
  315. this.wordlistfun();
  316. },
  317. searchwordtap:function(e){
  318. this.setData({
  319. word: e.detail.value,
  320. datashow:false
  321. })
  322. },
  323. setmineask:function(e){
  324. this.setData({
  325. okeytext: e.detail.value,
  326. })
  327. },
  328. swordtap:function(){
  329. this.setData({
  330. datashow:false
  331. })
  332. wx.showLoading();
  333. this.wordlistfun();
  334. },
  335. wordMsgTap:function(e){
  336. const that=this;
  337. page=0;
  338. this.setData({
  339. wordflag:true,
  340. nowid:e.currentTarget.dataset.vid,
  341. commentArr:[],
  342. allcommentNum:0,
  343. answerflag:false
  344. })
  345. this.wordmsg();
  346. wx.createIntersectionObserver().relativeToViewport({bottom: 50}).observe('.wordmsgview', (res) => {
  347. that.comment();
  348. })
  349. },
  350. wordmsg:function(){
  351. const that=this;
  352. utils.$post({
  353. url: app.globalData.webUrl + 'api/talkskill/talkskill_xq',
  354. header: {
  355. 'Authorization':'bearer '+app.globalData.token
  356. },
  357. data:{
  358. id:that.data.nowid,
  359. },
  360. success: function (res) {
  361. wx.hideLoading();
  362. if (res.data.code == "0"){
  363. that.setData({
  364. nowwordobj:res.data.data
  365. })
  366. }
  367. }
  368. })
  369. },
  370. copyfun:function(type,wid){
  371. const that=this;
  372. utils.$post({
  373. url: app.globalData.webUrl + 'api/talkskill/use_talkskill',
  374. header: {
  375. 'Authorization':'bearer '+app.globalData.token
  376. },
  377. data:{
  378. type:type==1?'use_admin':'use_comment',//use_comment:复制用户的,use_admin:复制后台的
  379. id:wid,//每条评论的id
  380. },
  381. success: function (res) {
  382. }
  383. })
  384. },
  385. copyText:function(e){
  386. this.copyfun(e.currentTarget.dataset.type,e.currentTarget.dataset.wid);
  387. wx.setClipboardData({
  388. data: e.currentTarget.dataset.text,
  389. success (res) {
  390. },fail(res){
  391. console.log(res)
  392. }
  393. })
  394. },
  395. collectTap:function(){
  396. let that=this;
  397. var surl="";
  398. if(!that.data.nowwordobj.collect){
  399. surl="api/talkskill/collect";
  400. }else{
  401. surl="/api/talkskill/collectCancel";
  402. }
  403. utils.$post({
  404. url: app.globalData.webUrl + surl,
  405. header: {
  406. 'Authorization':'bearer '+app.globalData.token
  407. },
  408. data:{
  409. id:that.data.nowid,//话术id
  410. },
  411. success: function (res) {
  412. if (res.data.code == "0") {
  413. let nowwordobj=that.data.nowwordobj;
  414. if(!that.data.nowwordobj.collect){
  415. nowwordobj.collect=1;
  416. that.setData({
  417. nowwordobj:nowwordobj
  418. })
  419. wx.showToast({
  420. title: res.data.msg,
  421. icon: 'none',
  422. duration: 2000
  423. })
  424. }else{
  425. nowwordobj.collect=0;
  426. that.setData({
  427. nowwordobj:nowwordobj
  428. })
  429. wx.showToast({
  430. title: res.data.msg,
  431. icon: 'none',
  432. duration: 2000
  433. })
  434. }
  435. } else {
  436. if(res.data.msg=='您已收藏'){
  437. nowwordobj.collect=1;
  438. that.setData({
  439. nowwordobj:nowwordobj
  440. })
  441. }
  442. }
  443. setTimeout(() => {
  444. wx.hideLoading()
  445. }, 1200);
  446. }
  447. })
  448. },
  449. /**
  450. * 生命周期函数--监听页面显示
  451. */
  452. onShow: function () {
  453. },
  454. /**
  455. * 生命周期函数--监听页面隐藏
  456. */
  457. onHide: function () {
  458. },
  459. /**
  460. * 生命周期函数--监听页面卸载
  461. */
  462. onUnload: function () {
  463. },
  464. /**
  465. * 页面相关事件处理函数--监听用户下拉动作
  466. */
  467. onPullDownRefresh: function () {
  468. var that=this;
  469. that.setData({
  470. page:1
  471. })
  472. var type = that.data.wordType == "1" ? "time" : that.data.wordType == "2" ? "hot" : "score";
  473. var label = this.data.tagType == "0" ? "" : this.data.tagType;
  474. utils.$post({
  475. url: app.globalData.webUrl + 'api/talkskill/lists',
  476. header: {
  477. 'Authorization':'bearer '+app.globalData.token
  478. },
  479. data:{
  480. hot_keyword: that.data.type==2?that.data.word:'',
  481. page: that.data.page,
  482. label: '',
  483. keyword:that.data.type==1?that.data.word:''
  484. },
  485. success: function (res) {
  486. wx.stopPullDownRefresh()
  487. wx.hideLoading();
  488. if (res.data.code == "0"){
  489. var list=res.data.data;
  490. that.setData({
  491. dataList:list
  492. })
  493. }
  494. }
  495. })
  496. },
  497. /**
  498. * 页面上拉触底事件的处理函数
  499. */
  500. onReachBottom: function () {
  501. var that=this;
  502. wx.showLoading()
  503. var page=that.data.page;
  504. page=page*1+1;
  505. that.setData({
  506. page:page
  507. })
  508. var type = that.data.wordType == "1" ? "time" : that.data.wordType == "2" ? "hot" : "score";
  509. var label = this.data.tagType == "0" ? "" : this.data.tagType;
  510. utils.$post({
  511. url: app.globalData.webUrl + 'api/talkskill/lists',
  512. header: {
  513. 'Authorization':'bearer '+app.globalData.token
  514. },
  515. data:{
  516. hot_keyword: that.data.type==2?that.data.word:'',
  517. page: that.data.page,
  518. label: '',
  519. keyword:that.data.type==1?that.data.word:''
  520. },
  521. success: function (res) {
  522. wx.hideLoading();
  523. var dataList=that.data.dataList;
  524. if (res.data.code == "0"){
  525. dataList = dataList.concat(res.data.data);
  526. var list=dataList;
  527. that.setData({
  528. dataList:list
  529. })
  530. }
  531. }
  532. })
  533. },
  534. /**
  535. * 用户点击右上角分享
  536. */
  537. })