
return {
  data:function() {
    return {
      loading: false,
      list: [], //答疑列表
      channelid:'10002',
      page: 1,
      pageCount: 1,
      mytype:true,
      select:false,
      textarea:'',
      imageList:[],
      fileList:[],
      imageDialogVisible:false,
      imgList:[],
      activeImageIndex:0,
      showEmoji:false,
      showImg:false,
      emojiList: [{
          name: '[微笑]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_0.png'
        },
        {
          name: '[撇嘴]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_1.png'
        },
        {
          name: '[色]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_2.png'
        },
        {
          name: '[发呆]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_3.png'
        },
        {
          name: '[得意]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_4.png'
        },
        {
          name: '[流泪]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_5.png'
        },
        {
          name: '[害羞]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_6.png'
        },
        {
          name: '[闭嘴]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_7.png'
        },
        {
          name: '[睡觉]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_8.png'
        },
        {
          name: '[大哭]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_9.png'
        },
        {
          name: '[尴尬]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_10.png'
        },
        {
          name: '[怒]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_11.png'
        },
        {
          name: '[调皮]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_12.png'
        },
        {
          name: '[大笑]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_13.png'
        },
        {
          name: '[惊讶]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_14.png'
        },
        {
          name: '[难过]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_15.png'
        },
        {
          name: '[酷]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_16.png'
        },
        {
          name: '[冷汗]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_17.png'
        },
        {
          name: '[抓狂]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_18.png'
        },
        {
          name: '[吐]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_19.png'
        },
        {
          name: '[偷笑]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_20.png'
        },
        {
          name: '[可爱]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_21.png'
        },
        {
          name: '[白眼]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_22.png'
        },
        {
          name: '[傲慢]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_23.png'
        },
        {
          name: '[饥饿]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_24.png'
        },
        {
          name: '[困]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_25.png'
        },
        {
          name: '[惊恐]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_26.png'
        },
        {
          name: '[流汗]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_27.png'
        },
        {
          name: '[憨笑]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_28.png'
        },
        {
          name: '[大兵]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_29.png'
        },
        {
          name: '[奋斗]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_30.png'
        },
        {
          name: '[咒骂]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_31.png'
        },
        {
          name: '[疑问]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_32.png'
        },
        {
          name: '[嘘]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_33.png'
        },
        {
          name: '[晕]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_34.png'
        },
        {
          name: '[折磨]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_35.png'
        },
        {
          name: '[衰]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_36.png'
        },
        {
          name: '[骷髅]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_37.png'
        },
        {
          name: '[敲打]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_38.png'
        },
        {
          name: '[再见]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_39.png'
        },
        {
          name: '[擦汗]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_40.png'
        },
        {
          name: '[抠鼻]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_41.png'
        },
        {
          name: '[鼓掌]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_42.png'
        },
        {
          name: '[糗大了]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_43.png'
        },
        {
          name: '[坏笑]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_44.png'
        },
        {
          name: '[左哼哼]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_45.png'
        },
        {
          name: '[右哼哼]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_46.png'
        },
        {
          name: '[哈欠]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_47.png'
        },
        {
          name: '[鄙视]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_48.png'
        },
        {
          name: '[委屈]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_49.png'
        },
        {
          name: '[快哭了]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_50.png'
        },
        {
          name: '[阴险]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_51.png'
        },
        {
          name: '[亲亲]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_52.png'
        },
        {
          name: '[吓]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_53.png'
        },
        {
          name: '[可怜]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_54.png'
        },
        {
          name: '[菜刀]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_55.png'
        },
        {
          name: '[西瓜]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_56.png'
        },
        {
          name: '[啤酒]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_57.png'
        },
        {
          name: '[篮球]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_58.png'
        },
        {
          name: '[乒乓球]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_59.png'
        },
        {
          name: '[咖啡]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_60.png'
        },
        {
          name: '[饭]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_61.png'
        },
        {
          name: '[猪头]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_62.png'
        },
        {
          name: '[玫瑰]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_63.png'
        },
        {
          name: '[凋谢]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_64.png'
        },
        {
          name: '[示爱]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_65.png'
        },
        {
          name: '[爱心]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_66.png'
        },
        {
          name: '[心碎]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_67.png'
        },
        {
          name: '[蛋糕]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_68.png'
        },
        {
          name: '[闪电]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_69.png'
        },
        {
          name: '[炸弹]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_70.png'
        },
        {
          name: '[刀]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_71.png'
        },
        {
          name: '[足球]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_72.png'
        },
        {
          name: '[瓢虫]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_73.png'
        },
        {
          name: '[便便]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_74.png'
        },
        {
          name: '[月亮]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_75.png'
        },
        {
          name: '[太阳]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_76.png'
        },
        {
          name: '[礼物]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_77.png'
        },
        {
          name: '[拥抱]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_78.png'
        },
        {
          name: '[强]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_79.png'
        },
        {
          name: '[弱]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_80.png'
        },
        {
          name: '[握手]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_81.png'
        },
        {
          name: '[胜利]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_82.png'
        },
        {
          name: '[抱拳]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_83.png'
        },
        {
          name: '[勾引]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_84.png'
        },
        {
          name: '[拳头]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_85.png'
        },
        {
          name: '[差劲]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_86.png'
        },
        {
          name: '[爱你]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_87.png'
        },
        {
          name: '[NO]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_88.png'
        },
        {
          name: '[OK]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_89.png'
        },
        {
          name: '[爱情]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_90.png'
        },
        {
          name: '[飞吻]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_91.png'
        },
        {
          name: '[跳跳]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_92.png'
        },
        {
          name: '[发抖]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_93.png'
        },
        {
          name: '[怄火]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_94.png'
        },
        {
          name: '[转圈]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_95.png'
        },
        {
          name: '[磕头]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_96.png'
        },
        {
          name: '[回头]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_97.png'
        },
        {
          name: '[跳绳]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_98.png'
        },
        {
          name: '[挥手]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_99.png'
        },
        {
          name: '[激动]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_100.png'
        },
        {
          name: '[街舞]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_101.png'
        },
        {
          name: '[献吻]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_102.png'
        },
        {
          name: '[左太极]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_103.png'
        },
        {
          name: '[右太极]',
          url: '/KS_Inc/static/edu/images/emoji/smiley_104.png'
        }
      ]
    };
  },
 
  methods: {
    returnPage: function (name) {
      this.$router.push({
          name:name,
          query:{
              costype:this.$route.query.costype
          }
      })
    },
    /**
     * 添加表情
     */
    setEmoji:function(str) {
      this.textarea = this.textarea + str
    },
    closeEmoji:function () {
      this.showEmoji=false
    },
    toggleEmoji: function(){
      this.showEmoji = !this.showEmoji
    },
    toggleImg: function(){
      this.showImg = !this.showImg
    },
    open: function (url) {
      location.href = url
    },
    //图片预览
    lookImg(imgList, i) {
      this.imgList = imgList
      this.activeImageIndex = i
      this.imageDialogVisible = true
    },
    imageError:function(e){
      console.log(e)
    },
    changeTab:function(){
      this.mytype = !this.mytype
      this.getUserAskTopList()
    },
    getReply:function(item){
      item.isShowReply = !item.isShowReply
      if(item.replyList.length<=0){
        GetUserAskPostList({
          topicid: item.topicid
        }).then(function (res) {
          res.data.map(function(reply){
            var content = reply.content;
            var div = document.createElement('div');
            div.innerHTML = content;
            var imgs = div.querySelectorAll('img');
            var showpics = [];
            imgs.forEach(function(el){
              showpics.push({
                pic_src:el.src
              });
            });
            reply.content = div.innerText;
            reply.showpics = showpics;
  
          });
          item.replyRequested = true;
          item.replyList = res.data;
        })
      }
     
    },
    getUserAskTopList: function (p) {
      p = p || 1;
      if(this.loading){
        return
      }
      this.loading = true;
      //获取评论列表
      if (p == 1) {
        this.list = [];
      }
      this.page = p;
      var that = this;
      GetUserAskTopList({
        page: p,
        mytype: that.mytype?1:0,
        verify: 0,
        classid: that.$route.query.classid,
        channelid: that.channelid,
        pagesize: 10,
        key: that.key,
        apptoken: that.$store.state.appToken
      }).then(function (res) {
        that.pageCount = res.pagecount * 10;
        if (res.result) {
          res.data.map(function (item) {
            if(item.content.match(/\[[\u4e00-\u9fa5]+\]/g)&&item.content.match(/\[[\u4e00-\u9fa5]+\]/g).length){
                item.content.match(/\[[\u4e00-\u9fa5]+\]/g).map(function(eitem){
                    that.emojiList.map(function(emoitem){
                      if(emoitem.name==eitem){
                        console.log(emoitem)
                        item.content = item.content.replace(eitem,'<img src="'+emoitem.url+'" class="emo-icon"/>');
                      }
                    })
                })
            }
            item.isShowReply = true;
            item.replyList = [];
          });
          // res.data.map(function (item) {
          //   item.isShowReply = true;
          //   item.replyList = [];
          // });

          that.list = res.data;
        }
        setTimeout(function(){
          that.loading = false;
          window,scrollTo(0,0)
        },100)
      });
    },
    handleSuccess:function(res,files, fileList){
      if(fileList.length>3){
        this.$message.warning(`最多只能上传3张图片`);
        fileList = fileList.splice[3]
      }
      this.fileList = fileList
      this.changeImageList(fileList)
    },
    changeImageList:function(list){
      this.imageList = list.map(function(item){
        return item.response.fileUrl
      })
    },
    delImage:function(i){
       this.imageList.splice(i, 1); 
      this.fileList.splice(i, 1) 
    },
    save:function(){
      var that = this
      if(this.textarea == ''){
        this.$message.warning(`问题不能为空`);
        return false
      }
      var imageList = this.imageList.join(',');
        SaveAskTopic({
          content: that.textarea,
          mytype: 1,
          channelid: that.channelid,
          pagesize: 10,
          proid: that.$route.params.id,
	        classid: this.$route.query.classid,
          photolist: imageList,
          userid:this.$store.state.userId,
          apptoken:this.$store.state.appToken
        }).then(function (res) {
          if (res.result) {
            that.$message.success(`提问成功`);
            that.textarea = "";
            that.message = "";
            that.imageList =[];
            that.fileList= [];  
            // that.getUserAskTopList()
            location.reload()
          } else {
            that.$message.warning(res.msg);
          }
        })
    },
  
    //删除
    del: function (topicid) {
      var that = this;
      this.$confirm('确定要删除这条问题吗？', '', {
        confirmButtonText: '删除',
        cancelButtonText: '取消',
        type: 'danger',
        showClose:false,
        customClass:'confirm-style',
        confirmButtonClass:'confirm-true__btn'
      }).then(function() {
        DeleteUserConsultation({
              topicids: topicid,
              apptoken:that.$store.state.appToken
            }).then(function (res) {
              if (res.result) {
                that.$message({
                  type: 'success',
                  message: '删除成功!'
                });
                that.getUserAskTopList(that.page)
              } else {
                that.$message({
                  type: 'warning',
                  message: res.msg
                });
              }
            });
        
      })
    
    }
  },
  created: function () {
    var that = this
    if(that.$route.query.costype=='8'){
      that.channelid = '10001'
    }else{
      that.channelid = '10002'
    }
    that.getUserAskTopList()
  }

}
