<template>
  <div class='question'>
    <div class='questionbox' v-if='loaded'>
      <navigator v-for='(item,i) in lists' :key='i' :url="'../questiondetail/main?cwxid='+item.cwxid" hover-class='hover'>
        <div class='title'>{{item.consultant_Title}}</div>
        <div class='text'>{{item.consultant_Content}}</div>
        <div class='foot'>
          <div v-for='(tag, j) in item.cate_Name' :key='j' class='tags'>{{tag}}</div>
          <div class='time'>{{item.consultant_Date}}</div>
        </div>
      </navigator>
      <NoData v-if='lists.length==0' paddingTop=0 />
    </div>
    <!--<button class="book" name="book" @click='subscribe'>订阅消息</button>-->
  </div>
</template>

<script>
  import NoData from '@/components/NoData'
  export default {
    components:{NoData},
    data() {
      return {
        lists: [],
        tmplIds: [],
        loaded: false
      }
    },
    methods: {
      loadQuestions() {
        wx.request({
          url: this.rootUrl + '/conwx/allqaforlawyer/',
          data:{sessionID: wx.getStorageSync('sessionID')},
          success: res=> {
            if(res.statusCode=='500'){
              this.service.getUnionId(this.rootAvatar,this.rootUrl).then(res => this.loadQuestions() )
            } else {
              console.log(res)
              // this.tmplIds.push(res.data.tmplIds)
              const questionArr = res.data
              questionArr.forEach(v=>{
                v.consultant_Date = this.service.correctTime(v.consultant_Date,'all').semantic
                v.cate_Name = v.cate_Name.split(',')
              })
              this.lists = []
              this.lists = questionArr
              this.loaded = true
              wx.hideLoading()
            }
          },
          fail: res=> {
            console.log(err)
          }
        })
      },
      subscribe (){
        // wx.requestSubscribeMessage({
        //   tmplIds: this.tmplIds,
        //   success (res) {
        //     console.log(res)
        //     if (res['N7I9WVwRXIRzAUOG6aVK7_Zo2EVJFCKBYhqsWip-T8g'] === 'accept'){
        //       wx.showToast({
        //         title: '订阅成功！',
        //         duration: 1000,
        //         success(data) {
        //           console.log(res)
        //         }
        //       })
        //     }else if (res['N7I9WVwRXIRzAUOG6aVK7_Zo2EVJFCKBYhqsWip-T8g'] === 'reject'){
        //       wx.showToast({
        //         title: '已拒绝接受消息',
        //         duration: 1000,
        //         success(data) {
        //           console.log(res)
        //         }
        //       })
        //     }
        //   },
        //   fail (res) {
        //     // console.log(res)
        //   }
        // })
      }
    },
    onLoad(){
      wx.showLoading({ title: '正在加载' })
    },
    onShow() {
      this.loadQuestions()
    }
  }
</script>
<style lang="stylus" scoped>
  .question
    position absolute
    width 100%
    min-height 100%
    Background()
  .questionbox
    Background()
    > navigator
      padding 25rpx
      margin-bottom 20rpx
      background white
      .title
        font-size 32rpx
        font-weight bold
        padding-bottom 15rpx
      .text
        overflow hidden
        text-overflow ellipsis
        display -webkit-box
        -webkit-line-clamp 3
        -webkit-box-orient vertical
        Font(28rpx, 40rpx)
        color #666
      .foot
        Flex(flex, , center)
        .tags
          Font(26rpx, 40rpx)
          border-radius 8rpx
          border 1rpx solid themeColor
          color themeColor
          padding 0 10rpx
          margin-right 15rpx
        .time
          Font(28rpx)
          margin 0 0 0 auto
          color #777
  .book
    margin 25rpx auto
    width 50%
    height 80rpx
    color #fff
    background-color #aa001a
</style>
