<template>
  <div class="app-container">
    <div style="background-color: #fff;padding: 20px;border-radius: 10px;">
      <p style="margin: 0; font-weight: 800;font-size: 16px;color: #343434;display: flex;align-items: center;margin-bottom: 20px;">
        <img src="../../../assets/images/icon_htgl_btzs.png" alt="" style="width: 16px;height: 20px;">
       <span style="margin-left: 10px;">社区资讯</span>
      </p>
      <div style="background: #F3F3F3;padding: 20px 15px; padding-bottom: 0;margin-bottom: 20px;">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="120px">
      <el-row>

        <el-col :span="24">
          <el-col :span="8">
            <el-form-item label="社区资讯标题" prop="communityTitle">
                    <el-input
                      v-model="queryParams.communityTitle"
                      placeholder="请输入社区资讯标题"
                      clearable
                      @keyup.enter.native="handleQuery"
                    />
                  </el-form-item>
          </el-col>
          <el-col :span="8">
           <el-form-item label="社区资讯类型" prop="communityType">
                   <el-select v-model="queryParams.communityType" placeholder="请选择社区资讯类型" clearable>
                     <el-option
                       v-for="dict in dict.type.community_typ"
                       :key="dict.value"
                       :label="dict.label"
                       :value="dict.value"
                     />
                   </el-select>
          </el-form-item>
          </el-col>

          <el-col :span="8">
           <el-form-item label="发布时间" prop="publishTime">
                   <el-date-picker clearable
                     v-model="queryParams.publishTime"
                     type="date"
                     value-format="yyyy-MM-dd"
                     placeholder="请选择发布时间">
                   </el-date-picker>
                 </el-form-item>

          </el-col>
          <el-col :span="8">
           <el-form-item label="社区资讯状态" prop="status">
                   <el-select v-model="queryParams.status" placeholder="请选择社区资讯状态" clearable>
                     <el-option
                       v-for="dict in dict.type.zinxdunt"
                       :key="dict.value"
                       :label="dict.label"
                       :value="dict.value"
                     />
                   </el-select>
          </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item class="butt">
              <el-button size="mini" type="primary"   @click="handleQuery">搜索</el-button>
              <el-button size="mini"  @click="resetQuery">重置</el-button>
            </el-form-item>
          </el-col>
        </el-col>
      </el-row>

    </el-form>
    </div>
    <div class="casr">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          size="mini"
          @click="handleAdd"
          v-hasPermi="['wuYe:news:add']"
        >新增</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="success"
          plain
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['wuYe:news:edit']"
        >修改</el-button>
      </el-col> -->
      <!-- <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['wuYe:news:remove']"
        >删除</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          size="mini"
          @click="handleExport"
          v-hasPermi="['wuYe:news:export']"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-badge :value="tose" class="item">
        <el-button
          plain
          size="mini"
          @click="handleExportwud"
          v-hasPermi="['wuYe:news:wudu']"
        >未读互动</el-button>
        </el-badge>
      </el-col>

      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table :max-height="tableMaxHeight" v-loading="loading" :data="newsList" @selection-change="handleSelectionChange">
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <el-table-column label="标题" align="center" prop="communityTitle"  show-overflow-tooltip />
      <!-- <el-table-column label="内容" align="center" prop="communityContent"  width="180" show-overflow-tooltip>
      <template slot-scope="scope">
          <div v-html="scope.row.communityContent">
          </div>
        </template>
      </el-table-column> -->
      <el-table-column label="类型" align="center" prop="communityType" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.community_typ" :value="scope.row.communityType"/>
        </template>
      </el-table-column>
      <el-table-column label="是否启用" align="center" key="status"  v-hasPermi="['wuYe:news:remove']">
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.status"
            active-value="1"
            inactive-value="2"
            @change="handleStatusChange(scope.row)"
          ></el-switch>
        </template>
      </el-table-column>
      <el-table-column label="发布时间" align="center" prop="publishTime" width="180">
        <template slot-scope="scope">
          <span>{{scope.row.publishTime}}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="作者" align="center" prop="author" />
      <el-table-column label="来源" align="center" prop="source" width="100" show-overflow-tooltip/> -->
      <el-table-column label="封面图片" align="center" prop="coverImage" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.coverImage" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <!-- <el-table-column label="浏览次数" align="center" prop="viewCount" /> -->
      <el-table-column label="是否置顶" align="center" prop="isTop">
              <template slot-scope="scope">
                <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.isTop"/>
              </template>
      </el-table-column>
      <!-- <el-table-column label="备注" align="center" prop="remark" /> -->
      <el-table-column width="120" label="操作" align="center" class-name="small-padding fixed-width" >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            style="color: #46CB99;"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['wuYe:news:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            @click="handleUpdatef(scope.row)"
          >查看</el-button>
          <!-- <el-button
            size="mini"
            type="text"
            @click="handleDelete(scope.row)"
            v-hasPermi="['wuYe:news:remove']"
          >关闭 </el-button> -->
        </template>
      </el-table-column>
    </el-table>
    </div>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    </div>

    <!-- 添加或修改社区资讯对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="社区资讯标题" prop="communityTitle">
              <el-input v-model="form.communityTitle" placeholder="请输入社区资讯标题" />
            </el-form-item>
          </el-col>
          <!-- <el-col :span="8">
            <el-form-item label="作者" prop="author">
              <el-input v-model="form.author" placeholder="请输入作者" />
            </el-form-item>
          </el-col> -->
          <el-col :span="8">
           <el-form-item label="是否置顶" prop="isTop">
             <el-select v-model="form.isTop" placeholder="请选择是否置顶">
                         <el-option
                           v-for="dict in dict.type.sys_yes_no"
                           :key="dict.value"
                           :label="dict.label"
                           :value="dict.value"
                         ></el-option>
                       </el-select>
           </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="社区资讯类型" prop="communityType">
              <el-select v-model="form.communityType" placeholder="请选择社区资讯类型">
                <el-option
                  v-for="dict in dict.type.community_typ"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
         <!-- <el-col :span="8">
            <el-form-item label="来源" prop="source">
              <el-input v-model="form.source" placeholder="请输入来源，记录资讯的来源" />
            </el-form-item>
          </el-col> -->
          <el-col :span="8">
            <el-form-item label="发布时间" prop="publishTime">
              <el-date-picker clearable
              style="width:100%"
                v-model="form.publishTime"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择发布时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="社区资讯内容">
              <editor v-model="form.communityContent" :min-height="192"/>
            </el-form-item>
          </el-col>
          <el-col :span="24" v-if="isshonue">
            <el-form-item label="封面图片" prop="coverImage">
              <image-upload v-model="form.coverImage"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer" v-if="isshonue">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
     <el-dialog title="查看信息" :visible.sync="openc" width="800px" append-to-body class="blse">
           <div style="background-color: #fff;border-radius: 20px;padding: 20px;margin-bottom: 20px;" v-if="weudulist.length !=0" v-for="(item,index) in weudulist" :key="index" @click="handleUpdatef(item)">
               <div style="display: flex;justify-content: space-between;align-items: center;">
                 <div style="display: flex;align-items: center;">
                    <!-- <image-preview :src="item.avatar" :width="46" :height="46" style="border-radius: 50%;"/> -->
                    <img src="../../../assets/images/toux.png" alt="" style="width: 46px;height: 46px;border-radius: 50%;">
                    <div style="font-weight: 800;color: #272727;font-size: 16px; margin-left: 10px;">{{item.nickName == null?'暂无数据':item.nickName}}</div>
                 </div>
                 <div style="font-size: 14px;color: #666666;">
                   <span v-if="item.targetType == 1">评论了你的文章</span>
                   <span v-if="item.targetType == 2">点赞了你的文章</span>
                   <span v-if="item.targetType == 3">收藏了你的文章</span>
                   <span v-if="item.targetType == 4">回复了你的评论</span>
                   <span v-if="item.targetType == 5">点赞了你的评论</span>
                   <span style="margin-left: 10px;">{{item.createTime}}</span>
                 </div>
               </div>
               <div style="display: flex; align-items: center;">
                 <p style="width:6px;height:16px;margin: 0;margin-left: 56px;background-color: #FACA7D;border-radius: 3px;" v-if="item.targetType == 2 || item.targetType==5"></p>
                 <p style="width:6px;height:16px;margin: 0;margin-left: 56px;background-color: #86AFFF;border-radius: 3px;" v-if="item.targetType == 3"></p>
                 <p style="width:6px;height:16px;margin: 0;margin-left: 56px;background-color: #93E9C2;border-radius: 3px;" v-if="item.targetType == 1 ||item.targetType==4"></p>
                 <p style="margin:0;margin-left:10px;font-size:16px;color: #272727;flex:1;display:flex;justify-content: space-between;">
                   {{item.targetTitle == null?'暂无数据':item.targetTitle}}
                 <img src="../../../assets/images/icon_mine_dzsc_ent.png" alt="" style="width: 12px;height: 24px;">
                 </p>
               </div>
           </div>
           <div style="margin-top: 20px;display: flex;justify-content: center;align-items: center;" v-if="weudulist.length ==0">
              <img   src="../../../assets/images/zwshjbig.png" alt="" style="">
           </div>
     </el-dialog>
  </div>
</template>

<script>
import { listNews, getNews, delNews, addNews, updateNews,getCommentInteraction,getCommentInteractionCount } from "@/api/wuguan/news";
// import comment from 'bright-comment'
export default {
  name: "News",
  dicts: ['community_typ','sys_yes_no','zinxdunt'],

  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 社区资讯表格数据
      newsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      openc:false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        communityTitle: null,
        communityType: null,
        communityContent: null,
        publishTime: null,
        author: null,
        source: null,
        coverImage: null,
        viewCount: null,
        isTop: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        communityTitle: [
          { required: true, message: "社区资讯标题不能为空", trigger: "blur" }
        ],
        communityType: [
          { required: true, message: "社区资讯类型不能为空", trigger: "change" }
        ],
      },
      isshonue:false,
      weudulist:[],
      tose:0,
      tableMaxHeight:200
    };
  },
  created() {
    this.getList();
    this.gettenum()
  window.onresize = () => {
  	      this.changeTableMaxHeight()
  	    }
  	    this.changeTableMaxHeight()
  },
  mounted() {
  	window.onresize = () => {
  	          this.changeTableMaxHeight()
  	        }
  	        this.changeTableMaxHeight()
  },
  methods: {
    /** 查询社区资讯列表 */
    getList() {
      this.loading = true;
      listNews(this.queryParams).then(response => {
        this.newsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 获取当前时间
    gettime(){
      let nowDate = new Date()
      				  let date = {
      				    year: nowDate.getFullYear(),
      				    month: nowDate.getMonth() + 1,
      				    date: nowDate.getDate()
      				  }

      				   if (parseInt(date.date) < 10) {
      				      date.date = '0' + date.date
      				    }
                  let nghe = date.year + '-' + date.month + '-' + date.date
      				  return nghe

    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        communityId: null,
        communityTitle: null,
        communityType: null,
        communityContent: null,
        status: '1',
        publishTime: this.gettime(),
        author: null,
        source: null,
        coverImage: null,
        viewCount: null,
        isTop: 'N',
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    // 用户状态修改
    handleStatusChange(row) {
      let text = row.status === "1" ? "启用" : "停用";
      var that = this
      this.$modal.confirm('确认要"' + text + '"吗？').then(function() {
         that.getti(row);
      }).then(() => {
        this.$modal.msgSuccess(text + "成功");
      }).catch(function() {
        row.status = row.status === "1" ? "2" : "1";
      });
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.communityId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加社区资讯";
      this.isshonue = true
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const communityId = row.communityId || this.ids
      getNews(communityId).then(response => {
        this.form = response.data;
        this.open = true;
        this.isshonue = true
        this.title = "修改社区资讯";
      });
    },
    handleUpdatef(row) {
      this.openc = false
      this.$router.push({
        path: '/wuguan/newxq',
        query: {
        	'id':row.communityId,
        }
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.communityId != null) {
            updateNews(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addNews(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    getti(row){
      updateNews(row).then(response => {

      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const communityIds = row.communityId || this.ids;
      this.$modal.confirm('是否确认删除社区资讯编号为"' + communityIds + '"的数据项？').then(function() {
        return delNews(communityIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('wuYe/news/export', {
        ...this.queryParams
      }, `news_${new Date().getTime()}.xlsx`)
    },
    // 未读
    handleExportwud(){
      this.gettenum()
      this.gette()
      // this.$modal.msgSuccess("没有未读互动");
      // this.tose = 0
    },
    gette(row){
      let sngs={}
      getCommentInteraction(sngs).then(response => {
        this.weudulist = response.data.list
        this.openc = true
        // this.tose = response.data.total

      });
    },
    gettenum(row){
      let sngs={}
      getCommentInteractionCount(sngs).then(response => {
        this.tose = response.data
        // if(this.tose != 0){

        // }

      });
    },
    // 获取屏幕高度
    showFilterForm () {
          this.filterActive = !this.filterActive
          this.changeTableMaxHeight()
        },

        changeTableMaxHeight () {
          let height = document.body.offsetHeight // 网页可视区域高度
          // if (this.filterActive) {
          //   this.tableMaxHeight = height - 320
          // } else {
            this.tableMaxHeight = height - 150
          // }
          console.log(height)
        }

  }
};
</script>
<style  lang="scss">
  .blse{
    .el-dialog__body{
      background-color: #F2F3FD;
      padding: 20px;
    }
  }
  .butt{
    .el-button--small{
      padding: 9px 23px !important;
      font-size: 14px;
    }
  }
  .casr{
    .el-tabs__item.is-active{
      color: #196CFF;
    }
    .el-tabs--card > .el-tabs__header .el-tabs__item{
      padding: 0  30px !important;
    }
  }
  .el-table .el-table__header-wrapper th{
    background-color:#F5F6F8;
    color:#343434;
  }
  .el-table{
    color:#343434;
  }
</style>
<style scoped lang="scss">
  .goe{
    p{
      margin: 0;
      font-weight: 800;
      font-size: 16px;
      color: #161616;
      margin-top: 10px;
      margin-bottom: 3px;
      padding: 0 10px;
      overflow: hidden;
      text-overflow: ellipsis;
      display:-webkit-box; //作为弹性伸缩盒子模型显示。
      -webkit-box-orient:vertical; //设置伸缩盒子的子元素排列方式--从上到下垂直排列
      -webkit-line-clamp:1; //显示的行
    }
    p:nth-child(2){
      // margin-bottom: 10px;
      margin-top: 0;
     font-weight: 400;
     font-size: 14px;
     color: #AAAAAA;
     display: flex;
     justify-content: space-between;
     align-items: center;
     padding-bottom: 10px;
     span:nth-child(2){
       padding: 3px 5px;
       background: #EDEDED;
       border-radius: 10px;
     }
    }
  }
  .ingwe{
    border: 2px solid #196CFF;
  }
  </style>
