<template>
  <div id="apploval-opinion" class="contain-wrap">
    <div class="title">
      <div class="left">
        <img class="icon-img" src="/static/images/icon/icon-msg.png" />
        <span>发表意见</span>
      </div>
      <div @click="handleMore">更多>></div>
    </div>
    <div class="log-wrap" v-for="(item, index) in commentList" :key="index">
      <div class="log-item">
        <div class="img-wrap">
          <img src="@/assets/img/public/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>
    </div>
    <div class="count">共&nbsp;{{ count }}&nbsp;条发表记录</div>
    <div class="text-content">
      <el-input v-model="param.content" type="textarea" :autosize="{ minRows: 5, maxRows: 8 }" maxlength="300" show-word-limit placeholder="请输入意见留言"></el-input>
      <div class="btn-wrap">
        <el-button type="primary" @click="saveComment">
          <img class="icon-img" src="/static/images/icon/icon-position.png" />
          <p>发表</p>
        </el-button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'ls-comment',
  props: {
    detailInfo: {
      //表单数据渲染（外部接收）
      type: Object,
      default: {},
      required: false
    }
  },
  created: function() {},

  mounted: function() {
    this.$nextTick( ()=> {
       this.param.busId = this.$common.getUrlParams('busId');
    });
  },
  methods: {
    //当前分页
    currentChange(val) {
      this.pagers.currPage = val;
      this.getComment();
    },

    //获取评论列表
    getComment(val) {
      console.log('val', val);
      let param = {
        currPage: this.pagers.currPage,
        pageSize: this.pagers.size,
        queryParam: {
          busId: val.busId,
          commentType: '1',
          reviewStatus: '',
          status: 1
        }
      };
      this.param.busId = val.busId;
      this.param.moduleId = val.moduleId;
      if(this.param.moduleId==null){
         this.param.moduleId = 3104
      }
      this.$ajax.post({
        domain: 'crmUrl',
        url: 'comment.commentByBusIdList',
        data: JSON.stringify(param),
        success: function(res) {
          console.log(res);
          if (res.errorCode === 200) {
            this.commentList = res.data.records;
            this.pagetotal = res.data.total;
            this.pagers.totals = res.data.total;
            this.count = res.data.total;
            console.log('commentList============>', this.commentList);
          } else {
            this.$message({
              type: 'error',
              message: res.msg
            });
          }
        }.bind(this),
        error: function(res) {
          this.$message({
            type: 'error',
            message: res.msg
          });
        }
      });
    },

    //新增评论 点新增还是没值
    saveComment() {
      console.log('saveComment=========>', this.param);
      if (!this.param.content) {
        this.$message.error('请先输入评论');
      } else {
        console.log('this.param', this.param);
        this.$ajax.post({
          domain: 'crmUrl',
          url: 'comment.saveComment',
          data: JSON.stringify(this.param),
          success: function(res) {
            console.log(res);
            if (res.errorCode === 200) {
              this.$message({
                message: '评论成功',
                type: 'success'
              });
              this.$parent.getTaskDetails();
            } else {
              this.$message({
                message: res.msg,
                type: 'error'
              });
            }
          }.bind(this),
          error: function(res) {
            this.$message({
              message: res.msg,
              type: 'error'
            });
          }
        });
      }
    },

    //更多:从第二页开始
    handleMore(){
      console.log("this.param更多传参======================>",this.param)
      this.$router.push({name:'commentPage',param:this.param});
    },

  },
  props: [],
  data: function() {
    return {
      param: {
        moduleId: 0,
        busId: '',
        busStatus: '',
        content: '',
        result: '',
        reviewerType: '',
        commentType: '1',
        status: 1,
      },
      processId: '',
      opinionContent: '',
      commentList: [{ userName: '', createdate: '' }],
      count: 0,
      //分页参数
      pagers: {
        currPage: 1,
        size: 1,
        pageOptions: [5, 10, 20, 30],
        totals: 0
      }
    };
  }
};
</script>

<style type="text/css" lang="scss">
#apploval-opinion {
  background-color: #fff;
  margin-top: 0.2rem;
  .text-content {
    display: flex;
    padding: 0 0.2rem;

    .btn-wrap {
      padding-left: 0.24rem;
      .el-button--primary {
        height: 100%;
        font-size: 0.56rem;
        color: #008cee;
        background-color: #ecf5ff;
        border-color: #ecf5ff;
      }
    }
  }


}
</style>
