<template>
  <view class="content">
    <view class="c-top">
      <view class="" @click="getback()">
        <uni-icons type="left" size="18"></uni-icons>
      </view>
      <view class="c-title">{{ flag ? obj.newsTitle : obj.title }}</view>
      <view class=""></view>
    </view>
    <!-- html -->
    <view class="c-content" v-if="flag">
      <view class="cont-gongs">{{ obj.publishUnit }}</view>
      <u-parse :content="obj.newsContent" :tagStyle="style"></u-parse>
      <view class="videobox" v-if="videoList != null && videoList !== ''">
        <video :src="baseUrl+ videoList" controls></video>
      </view>
      <view class="cont-time">{{ getDate(createTime) || new Date() }}</view>
    </view>

    <view class="c-content" v-else>
      <u-parse style="font-size: 18px;text-indent: 2rem" :content="obj.content" :tagStyle="style"></u-parse>
      <view class="cont-time">{{ getDate(obj.createTime) || new Date() }}</view>
    </view>


    <uni-popup ref="alertDialog" type="dialog">
      <uni-popup-dialog :type="msgType" cancelText="关闭" confirmText="同意" title="通知" content="您确认删除吗"
                        @confirm="dialogConfirm()"
                        @close="dialogClose"></uni-popup-dialog>
    </uni-popup>
  </view>
</template>

<script>
import config from '@/config'
import request from '../../utils/request';
import {formatDate} from "../../utils/utils";

export default {
  data() {
    return {
      id: '',
      obj: {},
      style: {
        image: 'width: 100%;'
      },
      inputvalue: '',
      createTime: '',
      pinglun: false,
      dianzan: false,
      shoucang: false,
      baseUrl: config.baseImageUrl,
      pinglunlist: [],
      arrlist: [],
      user: {},
      videoList: null,
      type: 'center',
      msgType: 'success',
      messageText: '这是一条成功提示',
      flag: true
    }
  },

  onLoad(option) {
    this.id = option.id
    if (option.index) {
      this.flag = false
      this.getWarnDetail()
    } else {
      this.getlistindex()
    }
  },

  onShow() {
    this.user = uni.getStorageSync('userinfo')
  },
  methods: {
    getWarnDetail(){
      request({
        url: '/warnMsg/warnMsg/' + this.id,
        method: 'get'
      }).then(res => {
        this.obj = res.data
      })
    },
    getDate(value) {
      return formatDate(value)
    },
    //dianzan
    async getdianzan() {

      let data = {
        newsId: this.id,
        type: 'like',
      }
      let res = await request({
        url: '/appInspection/news/likeOrCollect',
        method: 'post',
        params: data

      })
      this.getlistindex()

    },

    async getdelete(id) {
      let data = {
        commentId: id,
      }
      let res = await request({
        url: '/appInspection/news/delNewsComment',
        method: 'post',
        params: data
      })
      this.getlistindex()
    },
    //评论
    getpinglun() {
      this.pinglun = !this.pinglun
    },
    getback() {
      uni.navigateBack({
        delta: 1,
      })
    },
    async getnew() {
      let data = {
        newsId: this.id,
      }
      let res = await request({
        url: '/appInspection/news/getDetail',
        method: 'get',
        params: data
      })
    },
    async getlistindex() {

      let res = await request({
        url: '/appInspection/news/getDetail?newsId=' + this.id,
        method: 'get',
      })
      this.obj = res.data
      this.videoList = res.data.videoUrl
      if (res.data.isLike == '1') {
        this.dianzan = true
      } else {
        this.dianzan = false
      }
      if (res.data.isCollect == '1') {
        this.shoucang = true
      } else {
        this.shoucang = false
      }
      this.createTime = this.obj.createTime
      let resx = await request({
        url: '/appInspection/news/getCommentList?newsId=' + this.id,
      })
      this.pinglunlist = resx.rows
      let ress = await request({
        url: '/appInspection/news/addReadNum?newsId=' + this.id + '&objectId=' + uni.getStorageSync('partnerId'),
        method: 'post',
      })
    },
    async getfasong() {
      let data = {
        newsId: this.id,
        context: this.inputvalue,
      }
      let res = await request({
        url: '/appInspection/news/addInspectionNewsComment',
        method: 'post',
        data: data
      })
      this.inputvalue = ''
      this.getlistindex()
    },
    dialogToggle(id) {
      this.deleteid = id
      this.$refs.alertDialog.open()
    },
    dialogClose() {
    },
    dialogConfirm() {
      this.getdelete(this.deleteid)
    },


  }

}
</script>

<style scoped lang="scss">
.content {
  width: 100%;
  height: calc(100vh);
  // background-color: #F6F6F6;
  box-sizing: border-box;
  // padding-top: 45px;
}

.cont-title {
  width: 100%;
  text-align: center;
  font-size: 24px;
  font-weight: bold;
  color: #333333;
  margin-bottom: 5px;
}

.cont-gongs {
  text-align: right;
  font-size: 14px;
  font-weight: 400;
  color: #666666;
  margin-bottom: 25px;
}

.videobox {
  width: 100%;
  margin: 0 auto;
}

.cont-time {
  font-size: 16px;
  font-weight: 400;
  color: #666666;
  margin-bottom: 25px;
  float: right;
}

.top-icon {
  margin-bottom: 45px;
}

.c-top {
  width: 100%;
  height: 88px;
  box-sizing: border-box;
  padding: 15px;
  padding-top: 44px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: white;
}

.c-title {
  font-size: 18px;
  font-weight: bold
}

.c-content {
  width: 100%;
  background-color: white;
  box-sizing: border-box;
  padding: 15px;
}

.pinglist {
  width: 100%;
  background-color: white;
  margin-top: 15px;
  box-sizing: border-box;
  padding: 15px;
  border-radius: 16px 16px 0px 0px;
}

.pinginput {
  width: 100%;
  height: 50px;
  background-color: white;
  display: flex;
  position: fixed;
  bottom: 0px;
  z-index: 99;
  box-sizing: border-box;
  padding: 15px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.left-input {
  width: 50%;
  height: 35px;
  border-radius: 50px;
  background: #E7E7E7;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  font-size: 16px;
}

.t-right {
  width: 60px;
  border-left: 1px solid #a6a6a6;
  font-size: 16px;
  color: #a6a6a6;
  box-sizing: border-box;
  padding-left: 5px;
}

.list-top {

}

.gang {
  width: 8%;
  height: 4px;
  background: #0D2E8D;
}

.view-box {
  border-bottom: 1px solid #D8D8D8;
  display: flex;
  justify-content: space-between;
  margin-top: 10px;
  box-sizing: border-box;
  padding-bottom: 9px;
}

.touxiang {
  width: 40px;
  height: 40px;
  background: #D8D8D8;
  border-radius: 50%;
  overflow: hidden;

  image {
    width: 100%;
    height: 100%;
  }
}

.vb-right {
  width: 85%;
}

.vb-nr {

}

.vb-bottom {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 5px;
}

.vb-title {
  font-size: 16px;
  font-weight: 400;
  color: #666666;
}

.right-xuan {
  display: flex;
}

.sc-botm {
  display: flex;
  align-items: center;
  margin-right: 5px;
}

.icon-sc {
  width: 20px;
  height: 20px;
  margin-right: 5px;

  image {
    width: 100%;
    height: 100%;
  }
}

.s-botm {
  display: flex;
  align-items: center;
  margin-right: 5px;
  color: crimson;
}

.icon-s {
  width: 18px;
  height: 18px;
  margin-right: 5px;

  image {
    width: 100%;
    height: 100%;
  }
}

.font-s {
  font-size: 15px;
  line-height: 16px;
}

.zuo-hui {
  font-size: 15px;
  font-weight: 400;
  color: #B7B7B7;
}
</style>