<template>
  <el-dialog title="查看详情" :visible.sync="show" width="670px" :before-close="close">
    <div style="pading-left: 15px;">
      <div class="rpList">
        <div v-for="(item, idx) in replyList" :key="idx">
          <i class="iconfont sign" :class="`${item.sign ? 'icon-huiyuan-copy blue' : 'icon-kefu1 warning-color'}`"></i>
          <div class="head">
            <p class="name">{{ item.name }}</p>
            <p>{{ item.time }}</p>
            <el-button class="del" type="text">删除</el-button>
          </div>
          <div class="content">
            <div class="text">{{ item.text }}</div>
            <div class="imgl" v-if="item.imgList && item.imgList.length">
              <img v-for="(img, idx) in item.imgList" :key="idx" style="width: 52px; height: 52px;cursor: pointer;" title="点击查看大图" class="mr10" :src="img" preview-title-enable="true" preview-nav-enable="true" @click="showImage(img)" />
            </div>
          </div>
        </div>
      </div>
      <el-form :model="form" :rules="rules" ref="form" label-width="0" class="demo-ruleForm">
        <p class="mb5 regular-font-color">添加回复：</p>
        <el-form-item prop="content">
          <dm-input type="textarea" v-model="form.content" :rows="4" placeholder="请输入回复内容" :maxlength="200"></dm-input>
        </el-form-item>
      </el-form>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button @click="close">关 闭</el-button>
      <el-button type="primary" @click="submit('form')">提 交</el-button>
    </span>
    <vue-gic-img-preview :imgUrl="imgUrl" :imgShowFlag="imgShowFlag" @hideImage="hideImage"></vue-gic-img-preview>
  </el-dialog>
</template>
<script>
import { evaluationReply } from '@/service/api/evaluationApi.js';
export default {
  props: {
    show: {
      type: Boolean,
      default: false
    },
    id: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      form: {
        content: ''
      },
      rules: {
        content: [{ required: true, message: '请输入回复内容', trigger: 'blur' }, { max: 200, message: '字数不能大于200', trigger: 'blur' }] // eslint-disable-line
      },
      srcList: [],
      replyList: [
        { id: 1, name: '管理员', text: '11', time: '11', sign: 0 },
        { id: 2, name: 'ss', text: '22', time: '11', sign: 1, imgList: ['http://image.biaobaiju.com/uploads/20180801/23/1533136201-VtUkzgfLxA.jpg', 'http://www.17qq.com/img_qqtouxiang/77853183.jpeg', 'http://image.biaobaiju.com/uploads/20181004/16/1538640094-ZSrlkKGWcX.jpg'] },
        { id: 3, name: '管理员', text: '33', time: '11', sign: 0 },
        { id: 4, name: 'ss', text: '44', time: '11', sign: 1 },
        { id: 5, name: 'ss', text: '55', time: '11', sign: 0 },
        { id: 6, name: '管理员', text: '66', time: '11', sign: 1 },
        { id: 7, name: 'ss', text: '77', time: '11', sign: 0 },
        { id: 8, name: '管理员', text: '88', time: '11', sign: 1, imgList: ['http://img.qqzhi.com/uploads/2019-02-27/045131967.jpg'] }
      ],
      imgShowFlag: false,
      imgUrl: ''
    };
  },
  watch: {
    show(val) {
      if (val) {
        let arr = [];
        this.replyList.forEach(v => {
          if (v.sign && v.imgList && v.imgList.length) {
            arr = arr.concat(v.imgList);
          }
        });
        this.srcList = arr;
      }
    }
  },
  methods: {
    close() {
      this.$refs.form.resetFields();
      this.$emit('update:show', false);
    },
    showImage(src) {
      if (!src || src == '') {
        return false;
      }
      this.imgShowFlag = true;
      this.imgUrl = src;
    },
    hideImage(val) {
      this.imgShowFlag = val;
    },
    submit(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          evaluationReply({ evaluateId: this.id, replyContent: this.form.content }).then(res => {
            if (res.errorCode === 0) {
              this.close();
              this.$emit('refresh');
              this.$tips({ type: 'success', message: '回复成功' });
            } else {
              this.$tips({ type: 'warning', message: res.message || '回复失败' });
            }
          });
        } else {
          return false;
        }
      });
    }
  }
};
</script>

<style scoped lang="scss">
.rpList {
  height: 400px;
  overflow-y: auto;
  > div {
    position: relative;
    padding-left: 40px;
    padding-bottom: 20px;
    i.sign {
      position: absolute;
      left: 0;
      top: 3px;
      width: 32px;
      height: 32px;
      line-height: 32px;
      text-align: center;
      font-size: 18px;
      background: rgba(235, 236, 240, 1);
      border-radius: 50%;
    }
    &:after {
      top: 40px;
      position: absolute;
      width: 1px;
      background: #e4e7ed;
      left: 15px;
      content: '';
      height: calc(100% - 42px);
    }
  }
  .head {
    overflow: hidden;
    position: relative;
    .del {
      position: absolute;
      right: 0px;
      top: 0px;
    }
    p.name {
      color: rgba(48, 49, 51, 1);
      line-height: 20px;
      & + p {
        color: rgba(96, 98, 102, 1);
        line-height: 18px;
      }
    }
  }
  .content {
    margin-top: 10px;
    padding: 12px 18px;
    background: #f5f7fa;
    .text {
      width: 532px;
      color: rgba(48, 49, 51, 1);
      line-height: 20px;
    }
    .imgl {
      margin-top: 7px;
    }
  }
}
.demo-ruleForm {
  margin-top: 25px;
  padding-left: 40px;
}
</style>
