<!--
	作者：yangzhijie1488@163.com
	时间：2017-12-12
	描述：追踪日志
-->

<template>
  <div>
    <div v-for="items in traceComments" :key="items" class="media">
      <h4 class="media-heading">
        {{ items.createdName
        }}<a class="fa-pull-right" @click="edit(items)">编辑</a>
      </h4>
      <div class="media-body">
        <div>
          <div v-dompurify-html="items.content" />
          <br />
          {{ items.created }}
        </div>
        <div v-if="items.attachments != '' && items.attachments != undefined">
          <div
            v-for="item in split(items.attachments)"
            :key="item"
            @click="download(item)"
          >
            <a>{{ item }}</a>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
var Common = require('../common/Common.js');
var DownloadService = require('pc-component-v3').default.DownloadService;
export default {
  components: {
    Common,
    DownloadService,
  },
  // props: ['traceId', 'trace'],
  props: {
    traceId: {
      type: String,
      default: null,
    }, 
    trace: {
      type: String,
      default: null,
    },
  },

  data: function () {
    return {
      traceComments: [],
      className: 'com.leanwo.prodog.trace.model.TraceComment',
      uuid: '',
    };
  },

  watch: {
    traceId: function (curVal, oldVal) {
      if (curVal != undefined) {
        this.getTraceComment();
      }
    },
  },

  mounted: function () {
    this.uuid = this.$route.params.uuid;
    if (this.traceId != undefined) {
      this.getTraceComment();
    }
  },
  methods: {
    /**
     * 根据追踪表Id获取评论
     * @author GuoZhiBo 20171201
     */
    getTraceComment: function () {
      var _self = this;
      $.ajax({
        url: Common.getApiURL('TraceCommentResource/queryTraceComment'),
        type: 'get',
        dataType: 'json',
        async: false,
        data: {
          traceId: _self.traceId,
        },
        beforeSend: function (request) {
          Common.addTokenToRequest(request);
        },
        success: function (data) {
          _self.traceComments = data;
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
          Common.processException(XMLHttpRequest, textStatus, errorThrown);
        },
      });
    },

    /**
     * 将字符串以”，“进行分割成字符串
     * @author GuoZhiBo 20171201
     */
    split: function (items) {
      if (items != null && items != '') {
        return items.split(',');
      } else {
        return null;
      }
    },
    /**
     * 下载文件
     * @param  {String} fileName 文件名
     * @return {void}
     */
    download: function (fileName) {
      var _self = this;
      DownloadService.fileDownload(_self.className, fileName);
    },
    /**
     * 获取图片地址
     * @param  {String} item 图片名称
     * @return {String}      图片URL地址
     */
    getImageSrc: function (item) {
      var _self = this;
      if (item != undefined && item != null) {
        return Common.getImageSrc(
          'com.leanwo.prodog.trace.model.TraceComment',
          item,
        );
      } else {
        return '';
      }
    },
    /**
     * 获取图片地址
     */
    getImageSrcName: function (imageName) {
      return Common.getImageSrc('com.leanwo.prodog.model.base.User', imageName);
    },

    /**
     * 打开评论界面进行评论
     * @author GuoZhiBo 20171201
     */
    edit: function (item) {
      this.$router.push('/trace/traceCommentEdit/' + item.id);
    },
  },
};
</script>

<style>
</style>