Blame view

src/pages/questiondetail/index.vue 8.6 KB
ce4c83ff   wxy   初始提交
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
  <template>
    <div class='questiondetail' v-if='lists[0]'>
      <div class='head-title'>
        {{lists[0] ? lists[0].consultant_Title : ''}}
        <div class="img-box" v-if='imgfiles.length>0' style='padding-top: 20rpx;'>
          <img v-for="(item,i) in imgfiles" :key="i" @tap='previewImg(i)' :src="imgLoaded[i]?item:'/static/imgs/img.png'" @error='hideImg(i)' mode='aspectFill'>
        </div>
        <div class='foot'>
          <span>咨询者:{{wx_name}}</span>
          <div v-for='(tag, j) in tags' :key='j' class='tags'>{{tag? tag: ''}}</div>
        </div>
      </div>
      <div class='list-item' v-for='(item,i) in lists' :key='i'>
        <div class='para-title'><div/>{{'第'+sequence[i]+'次提问'}}</div>
        <div class='text' style='margin-top: 25rpx;'>{{item.consultant_Content}}</div>
        <!-- <div class='img-box'><img v-for='(img,j) in item.imgfiles' :key='j' :src='img'></div> -->
        <div class='time'>{{item.consultant_Date}}</div>
        <div v-if='item.is_Replay==1'>
          <div class='head'><img class='photo' :src='rootAvatar+item.pic' mode='aspectFill'>{{item.name}}律师的回答
            <!-- <img class='new' src='/static/imgs/new.png'> -->
          </div>
          <div class='text' style='margin-bottom: 25rpx;'>{{item.consultant_Reply}}</div>
          <div class='time'>{{item.replay_Date}}</div>
        </div>
        <form v-if='i+1==lists.length && item.is_Replay!=1' @submit='commit'>
          <div class='textarea'>
            <textarea placeholder='请输入您要回答的内容' name='text' :value='text' @input='text=service.Input($event)' maxlength=10000 />
            <div>{{text.length}}/10000</div>
          </div>
          <div class='commit'>
            <button form-type='submit' hover-class='fade' :disabled='commiting'>提交</button>
          </div>
        </form>
      </div>
    </div>
    <div v-else class='LoadingMask'>
      <img src="/static/imgs/loading.png">
    </div>
  </template>
  
  <script>
    export default {
      data() {
        return {
          cwxid: '',
          sysNewsId: '',
          text: '',
          sequence: ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十'],
          lists: [],
          imgfiles: [],
          imgLoaded: [],
          tags:[],
          wx_name:'',
          commiting: false
        }
      },
      methods: {
        hideImg(i) {
          this.$set(this.imgLoaded, i, false)
        },
        previewImg(i) {
          wx.previewImage({
            urls: this.imgfiles,
            current: this.imgfiles[i]
          })
        },
        getLawyerPic(liid){
          return new Promise( resolve => {
            wx.request({
              url: this.rootUrl + '/law/lawyer/' + liid,
              success: res => {
                resolve(res.data[0].pic_Name)
              }
            })
          })
        },
        Timer(orginIndex,key){
          return new Promise(resolve =>{
            console.log('timer')
            setTimeout(()=>{
              if(this.lists[orginIndex][key]) resolve(this.lists[orginIndex][key])
              else this.Timer(orginIndex, key).then(e=>resolve(e))
            },50)
          })
        },
        loadConversations() {
          wx.request({
            url: this.rootUrl + '/conwx/singleqalaw/' + this.cwxid,
            data: { sysNewsId: this.sysNewsId },
            success: res => {
              this.lists = res.data.lists
              console.log(res.data.lists)
              this.imgfiles = res.data.pics.map(v=> this.rootAvatar + v.pic_Name)
              this.imgLoaded = new Array(this.imgfiles.length).fill(true)
  
              const map = {}
  
              this.lists.forEach((v,i) => {
                if(map[v.liid]) {
                  this.Timer(map[v.liid],'pic').then(pic => this.$set(this.lists[i],'pic',pic))
                }
                else if(v.liid) {
                  map[v.liid] = i.toString()
                  this.getLawyerPic(v.liid).then(pic => this.$set(this.lists[i],'pic',pic))
                }
                v.consultant_Date = this.service.correctTime(v.consultant_Date,'full')
                if(v.replay_Date) v.replay_Date = this.service.correctTime(v.replay_Date,'full')
              })
              console.log(this.lists[0].cate_Name)
              try {
                this.tags = this.lists[0].cate_Name.split(',')
              }catch (e) {
                this.tags = this.lists[0].cate_Name
              }
              this.text = ''
              this.wx_name = this.lists[0].wx_name
              this.commiting = false
            },
            fail: res => {
              console.log(res)
            }
          })
        },
        commit(e, type='first') {
          if(this.commiting){
            return
          }
          let inputs = this.service.filter(e.mp.detail.value)
          if(!inputs.allowed){
            return
          }else{
            inputs = inputs.obj
          }
          if(!this.service.checkEmptyInput([inputs.text],['回答内容'])){
            return
          }
          if(!this.service.checkBadWords([inputs.text],['回答内容'])){
            return
          }
          if(type=='first'){
            wx.showModal({
              title:'',
              content: '确定要发布吗?',
              success: res => {
                if (res.confirm){
                  this.execCommit(e, inputs)
                }
              }
            })
          }else{
            this.execCommit(e, inputs)
          }
        },
        execCommit(e,inputs){
          wx.showLoading({ title: '正在上传' })
          this.commiting = true
          wx.request({
            url: this.rootUrl + '/qa/replyqa',
            method: 'POST',
            header: { 'content-type': 'application/x-www-form-urlencoded' },
            data: {
              QAID: this.lists[this.lists.length - 1].qaid,
              Consultant_Reply: inputs.text,
              sessionID: wx.getStorageSync('sessionID')
            },
            success: res => {
              if(res.statusCode=='500'){
                this.service.getUnionId(this.rootAvatar,this.rootUrl).then(res=>{
                  console.log(res)
                  this.commiting = false
                  this.commit(e, 'again')
                })
              }else{
                if (res.data == 1) {
                  wx.showToast({ title: '发送成功' })
                  this.loadConversations()
                }else{
                  wx.hideLoading()
                  wx.showToast({title:'上传失败 请检查上传内容',icon: 'none'})
                  this.commiting = false
                }
              }
            },
            fail: res => {
              console.log(res)
              wx.hideLoading()
              wx.showToast({title:'上传失败',icon: 'none'})
              this.commiting = false
            }
          })
        }
      },
      onLoad() {
        this.cwxid = this.$root.$mp.query.cwxid
        if(this.$root.$mp.query.sysNewsId !== null && this.$root.$mp.query.sysNewsId !== '' && this.$root.$mp.query.sysNewsId !== undefined){
          this.sysNewsId = this.$root.$mp.query.sysNewsId
        }
        this.loadConversations()
      },
      onUnload(){
        this.cwxid = ''
        this.sysNewsId = ''
        this.text = ''
        this.lists = []
        this.imgfiles = []
        this.imgLoaded = []
        this.tags = []
        this.wx_name = ''
      }
    }
  </script>
  <style lang="stylus" scoped>
    .questiondetail
      position absolute
      Height_Width(100%)
      Background()
      BorderBox()
      > .list-item
        background white
        .text
          margin 10rpx 30rpx 0 30rpx
          text-align justify
          word-wrap break-word
          Font(28rpx, 45rpx)
        .time
          margin-top 20rpx
          padding 0 0 20rpx 30rpx
          Font(28rpx)
          color grey
    .head-title
      padding 25rpx
      Flex(flex, space-between, , column)
      Font(32rpx, 40rpx, bold)
      background white
      .foot
        Flex(flex,flex-end,center)
        color #777
        span
          Font(28rpx)
          margin 0 auto 0 0
        .tags
          Font(26rpx, 40rpx)
          border-radius 6rpx
          border 1rpx solid themeColor
          color themeColor
          padding 0 10rpx
          margin-left 15rpx
    .head
      Flex(flex, , center)
      padding 10rpx 30rpx
      font-size 30rpx
      color themeColor
      background white
      .photo
        Height_Width(86rpx)
        margin-right 20rpx
        border-radius 50%
        background-color #eee
      .new
        Height_Width(35rpx)
        margin-left 20rpx
    .textarea
      margin 0 40rpx
      padding-top 30rpx
      font-size 30rpx
      textarea
        height 400rpx
        width calc(100% - 20rpx)
        line-height 50rpx
        border-radius 10rpx
        border 1rpx solid #EEE
        background white
      div
        text-align right
        line-height 60rpx
    .ask
      Background()
      .commit
        padding-top 0
        height 110rpx
    .wait-reply
      Font(28rpx, 70rpx)
      text-align center
      color grey
      Background()
    .para-title
      line-height 80rpx
      color themeColor
      Border(1rpx, 0, 0, 0)
  </style>