123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560 |
- // pages/findword/findword.js
- var app=getApp();
- var utils=require("../../../utils/http");
- let page=1;
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- datashow: false,
- keytext:'',
- wordType: "1",
- tagType: "",
- toolflag: false,
- dataList: [], // 列表数据
- titleList:[],
- page:1,
- imgUrl:app.globalData.imgUrl,
- date:0,
- titflag:true,
- wordflag:false,
- quesionflag:false,
- type:1,//1是一般搜索,2是热词搜索
- nowid:'',
- nowwordobj:{},
- answerflag:false,
- hotwordflag:false,
- allcommentNum:0,
- commentArr:[],
- comments:''
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- var that=this;
- this.setData({
- type:options.type,
- word:options.word
- })
- wx.showLoading();
- this.wordlistfun();
- },
- unsuretap: function () {
- this.setData({
- quesionflag:true,
- okeytext:this.data.word
- })
- },
- submitap:function(){
- const that=this;
- if(!this.data.okeytext){
- wx.showToast({
- title: '提交的问题不能为空!',
- icon: 'none',
- duration: 2000
- })
- return false;
- }
- that.setData({
- quesionflag:false
- })
- utils.$post({
- url: app.globalData.webUrl + 'api/talkskill/submit_questions',
- header: {
- 'Authorization':'bearer '+app.globalData.token
- },
- data:{
- questions:that.data.okeytext
- },
- success: function (res) {
- if (res.data.code == "0"){
- wx.showToast({
- title:res.data.msg,
- icon: 'none',
- duration: 2000
- })
- }
- setTimeout(() => {
- wx.hideLoading()
- }, 1200);
- }
- })
- },
- closeask: function () {
- this.setData({
- quesionflag:false
- })
- },
- closeword: function () {
- this.setData({
- wordflag:false
- })
- },
- asktap:function(e){
- this.setData({
- answerflag:true,
- comments:this.data.nowwordobj.content
- })
- },
- closeasktap:function(e){
- this.setData({
- answerflag:false
- })
- },
- askcommerntap:function(e){
- this.setData({
- comments: e.detail.value,
- })
- },
- commentap:function(e){
- const that=this;
- if(!this.data.comments){
- wx.showToast({
- title: '答案不能为空!',
- icon: 'none',
- duration: 2000
- })
- return false;
- }
- if(this.data.comments==this.data.nowwordobj.content){
- wx.showToast({
- title: '您未进行优化操作,无法提交!',
- icon: 'none',
- duration: 2000
- })
- return false;
- }
- that.setData({
- answerflag:false
- })
- wx.showLoading({
- title: '评论中...',
- })
- utils.$post({
- url: app.globalData.webUrl + 'api/talkskill/addComment',
- header: {
- 'Authorization':'bearer '+app.globalData.token
- },
- data:{
- taid:that.data.nowid,//话术id
- content:that.data.comments,//内容
- },
- success: function (res) {
- if (res.data.code == "0") {
- wx.showToast({
- title: '评论成功!',
- icon: 'none',
- duration: 2000
- })
- that.setData({
- sayflag:false,
- comments:''
- })
- page=0;
- that.comment();
- }
- setTimeout(() => {
- wx.hideLoading()
- }, 1200);
- }
- })
- },
- zantap:function(e){
- const that=this;
- let idx=e.currentTarget.dataset.idx,commentArr=that.data.commentArr;
- let str="";
-
- if(commentArr[idx].ispraise==0){
- str='api/talkskill/praise';
- }else{
- str='api/talkskill/praiseCancel';
- }
-
-
- utils.$post({
- url: app.globalData.webUrl + str,
- header: {
- 'Authorization':'bearer '+app.globalData.token
- },
- data:{
- id:e.currentTarget.dataset.wid,
- },
- success: function (res) {
- if (res.data.code == "0"){
-
- if(commentArr[idx].ispraise==0){
- commentArr[idx].praise=commentArr[idx].praise*1+1;
- commentArr[idx].ispraise=1;
- }else{
- commentArr[idx].praise=commentArr[idx].praise-1;
- commentArr[idx].ispraise=0;
- }
- that.setData({
- commentArr:commentArr
- })
- }
- }
- })
- },
- wordmsg:function(){
- const that=this;
- that.comment();
- utils.$post({
- url: app.globalData.webUrl + 'api/talkskill/talkskill_xq',
- header: {
- 'Authorization':'bearer '+app.globalData.token
- },
- data:{
- id:that.data.nowid,
- },
- success: function (res) {
- wx.hideLoading();
- if (res.data.code == "0"){
- that.setData({
- nowwordobj:res.data.data
- })
- }
-
- }
- })
- },
- comment:function(){
- let that=this;
- page=page*1+1;
- utils.$post({
- url: app.globalData.webUrl + 'api/talkskill/commentList',
- header: {
- 'Authorization':'bearer '+app.globalData.token
- },
- data:{
- taid:that.data.nowid,//话术id
- page:page,
- },
- success: function (res) {
- let commentArr=that.data.commentArr;
- if (res.data.code == "0") {
- commentArr=(page==1?res.data.data:(commentArr.concat(res.data.data)));
- that.setData({
- allcommentNum:res.data.count,
- commentArr:commentArr,
- })
- }
- setTimeout(() => {
- wx.hideLoading()
- }, 1200);
- }
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- dothis:function(){},
- wordlistfun:function(){
- var that=this;
- that.setData({
- page:1
- })
- if(that.data.keytext==''){
- that.setData({
- titflag:true
- })
- }else{
- that.setData({
- titflag:false,
- })
- }
- utils.$post({
- url: app.globalData.webUrl + 'api/talkskill/lists',
- header: {
- 'Authorization':'bearer '+app.globalData.token
- },
- data:{
- hot_keyword: that.data.type==2?that.data.word:'',
- page: that.data.page,
- label: '',
- keyword:that.data.type==1?that.data.word:''
- },
- success: function (res) {
- wx.hideLoading();
- if (res.data.code == "0"){
- var list=res.data.data;
- that.setData({
- dataList: list,
- datashow:true
- })
- }
-
- }
- })
- },
- wordtap:function(e){
- if(e.detail.scrollTop>=230){
- this.setData({
- toolflag:true
- })
- }else{
- this.setData({
- toolflag:false
- })
- }
- },
- tagTap:function(e){
- var that=this;
- this.setData({
- tagType:e.target.dataset.text,
- datashow:false
- })
- wx.showLoading();
- this.wordlistfun();
- },
- wordTap:function(e){
- var that=this;
- this.setData({
- wordType:e.target.dataset.type,
- datashow:false
- })
- wx.showLoading();
- this.wordlistfun();
- },
- searchwordtap:function(e){
- this.setData({
- word: e.detail.value,
- datashow:false
- })
- },
- setmineask:function(e){
- this.setData({
- okeytext: e.detail.value,
- })
- },
- swordtap:function(){
- this.setData({
- datashow:false
- })
- wx.showLoading();
- this.wordlistfun();
- },
- wordMsgTap:function(e){
- const that=this;
- page=0;
- this.setData({
- wordflag:true,
- nowid:e.currentTarget.dataset.vid,
- commentArr:[],
- allcommentNum:0,
- answerflag:false
- })
- this.wordmsg();
- wx.createIntersectionObserver().relativeToViewport({bottom: 50}).observe('.wordmsgview', (res) => {
- that.comment();
- })
- },
- wordmsg:function(){
- const that=this;
- utils.$post({
- url: app.globalData.webUrl + 'api/talkskill/talkskill_xq',
- header: {
- 'Authorization':'bearer '+app.globalData.token
- },
- data:{
- id:that.data.nowid,
- },
- success: function (res) {
- wx.hideLoading();
- if (res.data.code == "0"){
- that.setData({
- nowwordobj:res.data.data
- })
- }
-
- }
- })
- },
- copyfun:function(type,wid){
- const that=this;
- utils.$post({
- url: app.globalData.webUrl + 'api/talkskill/use_talkskill',
- header: {
- 'Authorization':'bearer '+app.globalData.token
- },
- data:{
- type:type==1?'use_admin':'use_comment',//use_comment:复制用户的,use_admin:复制后台的
- id:wid,//每条评论的id
- },
- success: function (res) {
- }
- })
- },
- copyText:function(e){
- this.copyfun(e.currentTarget.dataset.type,e.currentTarget.dataset.wid);
- wx.setClipboardData({
- data: e.currentTarget.dataset.text,
- success (res) {
- },fail(res){
- console.log(res)
- }
- })
- },
- collectTap:function(){
- let that=this;
- var surl="";
- if(!that.data.nowwordobj.collect){
- surl="api/talkskill/collect";
- }else{
- surl="/api/talkskill/collectCancel";
- }
- utils.$post({
- url: app.globalData.webUrl + surl,
- header: {
- 'Authorization':'bearer '+app.globalData.token
- },
- data:{
- id:that.data.nowid,//话术id
- },
- success: function (res) {
- if (res.data.code == "0") {
- let nowwordobj=that.data.nowwordobj;
- if(!that.data.nowwordobj.collect){
- nowwordobj.collect=1;
- that.setData({
- nowwordobj:nowwordobj
- })
- wx.showToast({
- title: res.data.msg,
- icon: 'none',
- duration: 2000
- })
- }else{
- nowwordobj.collect=0;
- that.setData({
- nowwordobj:nowwordobj
- })
- wx.showToast({
- title: res.data.msg,
- icon: 'none',
- duration: 2000
- })
- }
- } else {
- if(res.data.msg=='您已收藏'){
- nowwordobj.collect=1;
- that.setData({
- nowwordobj:nowwordobj
- })
- }
- }
- setTimeout(() => {
- wx.hideLoading()
- }, 1200);
- }
- })
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- var that=this;
- that.setData({
- page:1
- })
- var type = that.data.wordType == "1" ? "time" : that.data.wordType == "2" ? "hot" : "score";
- var label = this.data.tagType == "0" ? "" : this.data.tagType;
- utils.$post({
- url: app.globalData.webUrl + 'api/talkskill/lists',
- header: {
- 'Authorization':'bearer '+app.globalData.token
- },
- data:{
- hot_keyword: that.data.type==2?that.data.word:'',
- page: that.data.page,
- label: '',
- keyword:that.data.type==1?that.data.word:''
- },
- success: function (res) {
- wx.stopPullDownRefresh()
- wx.hideLoading();
- if (res.data.code == "0"){
- var list=res.data.data;
- that.setData({
- dataList:list
- })
- }
-
- }
- })
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- var that=this;
- wx.showLoading()
- var page=that.data.page;
- page=page*1+1;
- that.setData({
- page:page
- })
- var type = that.data.wordType == "1" ? "time" : that.data.wordType == "2" ? "hot" : "score";
- var label = this.data.tagType == "0" ? "" : this.data.tagType;
- utils.$post({
- url: app.globalData.webUrl + 'api/talkskill/lists',
- header: {
- 'Authorization':'bearer '+app.globalData.token
- },
- data:{
- hot_keyword: that.data.type==2?that.data.word:'',
- page: that.data.page,
- label: '',
- keyword:that.data.type==1?that.data.word:''
- },
- success: function (res) {
- wx.hideLoading();
- var dataList=that.data.dataList;
- if (res.data.code == "0"){
- dataList = dataList.concat(res.data.data);
- var list=dataList;
- that.setData({
- dataList:list
- })
- }
-
- }
- })
- },
- /**
- * 用户点击右上角分享
- */
-
- })
|