<!-- 系统配置 - 权限配置 -->
<template>
  <div class="page">
    <topBar
      v-if="topList.length > 0"
      :top-list="topList"
      :moren="moren"
    />
    <div v-if="tableData" class="box">
      <div v-for="(item,index) in tableData" :key="index" class="lists" >
        <div class="time">
          <div class="border-bottom">{{ item.monthTime }}</div>
          <div class="div-box" @click="clickHref(items.pkId)" v-for="items in item.noticeList">
            <div class="title">
              <div style="font-weight: 600">{{items.title}}</div>
              <div v-html="items.content" class="overflow1"  style="font-size: 14px;color: #333;margin-top: 10px;font-weight: inherit"></div>
            </div>
            <div class="time-s">{{items.creationTime}}</div>

          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getcountryAllList } from '@/api/exchangerate'
import topBar from '@/components/topBar'
import { getbdmenuList, getPubenumsList } from '@/api/system'
import { getgradeRanglist, getAwardsListChiose } from '@/api/level'
import * as apis from '@/api/financialCase.js'
import { Message } from 'element-ui'
import * as api from '@/api/translate'
import {getNoticeList} from "@/api/translate";

export default {
  name: 'notice',
  components: {
    topBar
  },
  data() {
    return {
      tableData:[],
      moren: '/informCentre/noticeList',
      topList: [
        {
          name: '公告列表',
          path: '/informCentre/noticeList',
        },
      ],
    }
  },
  created() {
    this.research()
  },
  methods: {
    clickHref(id) {
      this.$router.push({
        name: 'noticeDetails',
        query: {
          pkId: id
        }
      })
    },
    // 导出
    handleExport() {
      this.download(
        '/system/manage/user/export',
        { ...this.params },
        `${'系统管理员'}${new Date().getTime()}.xlsx`
      )
    },
    addRules() {
      this.types = 1
      this.ruleShow = true
    },
    submitBtn() {
      // 添加角色
      this.ruleSubmit()
    },
    updateShow(item) {
      this.types = 2
      // 更新角色信息
      this.userId = item.userId
      api.userDetails(item.userId).then((res) => {
        if (res.code === 200) {
          this.ruleShow = true
          this.table = { 'userName': res.data.userName, 'nickName': res.data.nickName,
            'password': '', 'phonenumber': res.data.phonenumber,
            'sms': res.data.sms == 0 ? '启用' : '停用', 'status': res.data.status == 0 ? '启用' : '停用',
            'roleIdList': res.data.roleIdList, 'vertexIdList': res.data.vertexIdList,
            'countryIdList': res.data.countryIdList, 'authority': res.data.authority == 0 ? '启用' : '停用',
            'pkDept': res.data.pkDept
          }
        } else {
          Message({
            message: res.msg,
            type: 'error'
          })
        }
      })
    },
    delRole(item) {
      // 删除角色信息
      this.$confirm('确认要删除该管理员吗', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        api.delUser(item.userId).then((res) => {
          if (res.code === 200) {
            Message({
              message: '删除成功',
              type: 'success'
            })
            this.research()
          } else {
            Message({
              message: res.msg,
              type: 'error'
            })
          }
        })
      })
    },
    deppClone(obj) {
      const _obj = JSON.stringify(obj)
      const _obj1 = JSON.parse(_obj)
      return _obj1
    },
    ruleSubmit() {
      const datas = this.table
      const that = this
      this.$refs['forms'].validate(valid => {
        if (!valid) {
          return false
        } else {
          if (this.types === 1) {
            api.addUser(datas).then((res) => {
              if (res.code === 200) {
                Message({
                  message: '添加成功',
                  type: 'success'
                })
                that.ruleShow = false
                that.table = { 'userName': '', 'nickName': '', 'password': '', 'phonenumber': '',
                  'sms': '', 'authority': '', 'status': '', 'roleIdList': [], 'vertexIdList': [],
                  'countryIdList': '',
                  'pkDept': ''
                }
                that.research()
              } else {
                Message({
                  message: res.msg,
                  type: 'error'
                })
              }
            })
          }
          if (this.types === 2) {
            const datas1 = this.deppClone(datas)
            if (datas.sms === '启用') {
              datas1.sms = ''
              datas1.sms = 0
            } else if (datas.sms === '停用') {
              datas1.sms = ''
              datas1.sms = 1
            }
            if (datas1.authority === '启用') {
              datas1.authority = ''
              datas1.authority = 0
            } else if (datas.authority === '停用') {
              datas1.authority = ''
              datas1.authority = 1
            }
            if (datas1.status === '启用') {
              datas1.status = ''
              datas1.status = 0
            } else if (datas.status === '停用') {
              datas1.status = ''
              datas1.status = 1
            }
            datas1.userId = this.userId
            api.putUser(datas1).then((res) => {
              if (res.code === 200) {
                Message({
                  message: '修改成功',
                  type: 'success'
                })
                that.ruleShow = false
                that.table = { 'userName': '', 'nickName': '', 'password': '', 'phonenumber': '',
                  'sms': '', 'authority': '', 'status': '', 'roleIdList': [], 'vertexIdList': [],
                  'countryIdList': '',
                  'pkDept': ''
                }
                that.research()
              } else {
                Message({
                  message: res.msg,
                  type: 'error'
                })
              }
            })
          }
        }
      })
    },
    statusChange(value) {
      if (this.table.status.length > 1) {
        this.table.status.splice(0, 1)
      }
    },
    handleClose() {
      this.ruleShow = false
      this.table = {
        'userName': '', 'nickName': '', 'password': '', 'phonenumber': '',
        'sms': '', 'authority': '', 'status': '', 'roleIdList': [], 'vertexIdList': [],
        'countryIdList': '',
        'pkDept': ''
      }
    },
    changeBox(row) {
      console.error(row)
    },
    addFrom() {
    },
    addRule() {
    },
    changeTime(value) {
      // this.queryParams.creationTime = value[0]
      // this.queryParams.endCreationTime = value[1]
    },
    handleChangeMunu(value) {
      console.log('🌈', value[value.length - 1])
      this.queryParams.menuId = value[value.length - 1]
    },
    // 菜单下拉选
    getPubenumsList() {
      getPubenumsList().then((res) => {
        this.menuOptions = res.data
      })
    },
    // 等级范围选择
    getgradeRanglist() {
      getgradeRanglist().then((res) => {
        this.gradeRangList = res.data
      })
    },
    // 奖衔下拉列表
    getAwardsListChiose() {
      getAwardsListChiose().then((res) => {
        this.awardsList = res.rows
      })
    },
    async getUserId(data) {
      return this.$store.state.user.user.userId
    },
    async research(data) {
      api.getNoticeList().then((res) => {
        console.error(res)
        this.tableData = res.rows
        this.total = res.total
      })
    },
    reChongzhi() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 50,
        userName: '', // 角色姓名
        roleString: '', // 权限字符
        status: '', // 状态
        startDate: '', // 开始时间
        endDate: [] // 结束时间
      }
      this.research()
    },

    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    objectSpanMethod({ row, column, rowIndex, columnIndex }) {
      // if (columnIndex === 0) {
      //   if (rowIndex % 2 === 0) {
      //     return {
      //       rowspan: 2,
      //       colspan: 1,
      //     };
      //   } else {
      //     return {
      //       rowspan: 0,
      //       colspan: 0,
      //     };
      //   }
      // }
    },
    tableRowClassName({ row, rowIndex }) {
      if (rowIndex % 2 == 1) {
        return 'warning-row'
      } else if (rowIndex % 2 == 0) {
        return 'success-row'
      }
      return ''
    }
  }
}
</script>
<style lang="scss" scoped>
.overflow1{
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  width: 1200px;
}
.time-s{
  color: #666;
  font-size: 12px;
  margin-top: 35px;
}
.div-box{
  padding: 15px 20px 10px  20px;
  display: flex;
  justify-content: space-between;
  //margin: 0 20px;
  border-bottom: 1px solid rgba(0,0,0,0.1);
  //line-height: 24px;
}
.lists{
  width: 100%;
}
.border-bottom{
  border-bottom: 2px solid rgba(0,0,0,0.1);
  padding-bottom: 10px;
  padding-left: 20px;
  font-weight: 600;
}
.title{
  color: #333;
  font-size: 18px;
}
.time{
  color: #000;
  font-size: 18px;
  //font-weight: 600;
  width: 100%;
}
.name{
  color: #333;
  font-size: 18px;
  font-weight: bold;
  flex: 1;
  margin-left: 10px;
}
.style3{
  background: rgba(0,155,88,0.3)!important;
  color: #009B58!important;
}
.style2{
  background: rgba(58,58,58,0.3)!important;
  color: #3F3F3F!important;
}
.style1{
  width: 44px;
  height: 22px;
  background: rgba(255,134,134,0.3);
  border-radius: 4px 4px 4px 4px;
  line-height: 22px;
  text-align: center;
  color: #C42525;
  font-size: 14px;
}
.box{
  box-shadow: 0px 2px 20px 0px rgba(238,238,238,0.5);
  border-radius: 10px 10px 10px 10px;
  background-color: #fff;
  height: 1000px;
  padding-bottom: 20px;
}
.lists{
  padding: 20px 0 0 0;
  //border-bottom:1px solid rgba(0,0,0,0.1);
  display: flex;
  justify-content: space-between;
  cursor: pointer;
}
::v-deep .el-dialog__title{
  font-weight: bold;
}
.button-style{
  width: 209px;
  height: 48px;
  background: #CCCCCC;
  border-radius: 5px 5px 5px 5px;
  opacity: 1;
  line-height: 48px;
  padding: 0!important;
  color: #fff;
  font-size: 18px;
}
::v-deep .el-dialog__header{
  border-bottom: 1px solid rgba(0,0,0,0.1);
}
.button-s{
  padding: 0 2px!important;
}
::v-deep .el-button{
  padding: 10px 20px;
}
::v-deep .el-date-editor .el-range__close-icon{
  margin-top: -10px;
}
::v-deep .el-date-editor .el-range-separator{
  margin-top: -10px;
}
::v-deep .el-date-editor .el-range__icon{
  margin-top: -10px;
}
::v-deep .el-input__inner{
  //height:28px;
  //line-height: 28px;
}
::v-deep .el-form-item{
  margin-bottom: 15px;
}
::v-deep .el-form-item__label{
  color: #333;
  font-weight: inherit;
}
::v-deep .el-row {
  margin-top: 20px;
}
::v-deep .el-table .warning-row {
  background: #f9f9f9;
}

::v-deep .el-table .success-row {
  background: #ffffff;
}
::v-deep .el-table thead {
  color: #000000;
}
.openClose {
  margin-top: 10px;
  margin-right: 10px;
  color: #666666;
  text-align: center;
}
.page {
  padding: 20px;
  background: #f9f9f9;
  font-size: 14px;
  overflow-y: auto;
  //margin-bottom: 100px;
  .thetopbox {
    background: #ffffff;
    border-radius: 8px;
    padding-bottom: 10px;
    .searchbox {
      display: flex;
      align-items: center;
      .searchtitle {
        margin-right: 10px;
      }
      .searchbtn {
        background: #08143f;
        color: #ffffff;
      }
    }
  }
  .main {
    margin-top: 20px;
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0px 2px 20px 0px rgba(238, 238, 238, 0.5);

    .maintop {
      display: flex;
      padding: 10px 20px;
      justify-content: space-between;
      align-items: center;
      .mainbtn {
        .thebtn1 {
          color: #ffffff;
          background: rgba(67, 145, 253, 1);
        }
      }
    }
  }
}
</style>
