<template>
  <div class="ls-apploval-log page-contain">
    <top-nav title="意见留言"
             :showQuery="false"></top-nav>
    <!-- <van-nav-bar title="意见留言"
                 left-text="返回"
                 right-text=""
                 left-arrow
                 @click-left="onClickLeft" /> -->
    <div class="process-contain">
      <van-list v-model="loading"
                :finished="finished"
                finished-text="没有更多了"
                @load="onLoad"
                class="data-list">
        <div class="log-wrap"
             v-for="(item, index) in commentList"
             :key="index">
          <van-swipe-cell>
            <div class="log-item">
              <div class="img-wrap">
                <img v-if="item.userImg" :src="item.userImg" />
                <img v-else src="@/assets/images/photo.png" />
                <span>{{ item.creater }}</span>
              </div>

              <div class="text-wrap">
                <div class="text">{{ item.content }}</div>
                <div class="time">{{ item.createTime }}</div>
              </div>
            </div>
            <template #right
                      v-if="item.deleteButton">
              <van-button style="margin-left: 2px; height: 100%;font-size: 14px;"
                          square
                          type="warning"
                          text="删除"
                          @click="deleteData(item.id)" />
            </template>
          </van-swipe-cell>
        </div>
      </van-list>
    </div>
  </div>
</template>

<script>
import { Toast } from 'vant'
export default {
  name: 'comment-more',
  components: {},
  mounted () { },
  data () {
    return {
      loading: false,
      finished: false,
      refreshing: true,
      // 分页参数
      queryParam: {
        busId: '',
        commentType: '1',
        reviewStatus: '',
        status: 1,
        moduleId: 0
      },
      pager: {
        currPage: 1,
        pageSize: 10,
        pageOptions: [5, 10, 20, 30],
        totals: 0
      },
      commentList: []
    }
  },
  methods: {
    onClickLeft () {
      this.$router.go(-1)
    },
    onClickRight () {
      Toast('按钮')
    },
    // 获取评论列表
    onLoad () {
      this.queryParam.busId = this.$route.query.rowId
      var that = this
      let param = {
        pageSize: that.pager.pageSize,
        currPage: that.pager.currPage,
        queryParam: that.queryParam
      }
      that.$axios.post({
        domain: 'crmUrl',
        url: 'comment.commentByBusIdList',
        data: param,
        requestType: 'body',
        success: function (res) {
          if (res.errorCode === 200) {
            that.loading = false;
            that.commentList = [...that.commentList, ...res.data.records]
            that.commentList.forEach((v, i) => {debugger
              that.getUserImg(v.createrId, i)
            })
            that.pager.currPage++
            if (that.commentList.length === res.data.total) {
              that.finished = true
            }
          } else {
            that.finished = true
            Toast.fail(res.msg)
          }
        },
        error: function (res) {
          that.finished = true
          Toast.fail(res.msg)
        }
      })
    },
    // 获取 用户头像
    getUserImg (uid, i) {

      this.$axios.get({
        domain: 'ddingtUrl',
        url: 'dding.getUserImg',
        data: { uid },
        success: function (res) {
          if (res.errorCode === 200) {
            let userImg = res.data
            this.$set(this.commentList[i], 'userImg', userImg)
          }
        }.bind(this)
      })
    },
    // 刷新
    onRefresh () {
      console.log('刷新了吗？')
      // 重新初始化这些属性
      this.finished = false
      this.commentList = []
      this.pager.currPage = 1
      this.pager.pageSize = 10
      this.loading = true
      this.onLoad()
    },
    deleteData (deleid) {
      let param = { id: deleid }
      this.$dialog.confirm({
        title: '提示',
        message: '是否删除该数据?'
      }).then(() => {
        this.$axios.post({
          domain: 'crmUrl',
          url: 'comment.deleteByIdComment',
          data: param,
          requestType: 'body',
          success: function (res) {
            if (res.errorCode === 200) {
              Toast.success('删除成功')
              this.getComment({ busId: this.queryParam.busId, moduleId: this.queryParam.moduleId })
            } else {
              Toast.fail(res.msg)
            }
          }.bind(this),
          error: function (res) {
            Toast.fail(res.msg)
          }
        })
      }).catch(() => {
      })
    }
  }
}
</script>

<style type="text/css" scoped lang="scss">
.page-contain {
  background-color: #fff;
  overflow-y: auto;
  padding-bottom: 0;
  padding-top: 80px;
}

.ls-apploval-log {
  background-color: #fff;

  .process-contain {
    padding: 20px;
    border-top: 1px solid #e7e7e7;

    .log-wrap {
      padding: 20px 20px 0;

      .log-item {
        background: #f9f9f9;
        border-radius: 10px;
        flex: 1;
        display: flex;
        padding: 20px;
        padding-top: 25px;

        .img-wrap {
          display: flex;
          flex-direction: column;
          justify-content: center;
          align-items: center;

          img {
            width: 68px;
            height: 68px;
            border-radius: 50%;
          }
        }
        .text-wrap {
          flex: 1;
          padding-left: 20px;
          word-break: break-word;
          .text {
            color: #666;
            font-size: 24px;
            line-height: 40px;
          }
          .time {
            color: #999999;
            font-size: 22px;
          }
        }
      }
    }
  }
}
</style>
