<template>
  <div class="propertyNotice_manage">
    <div class="whiteBoard">
      <div class="addRepair" @tap="newRelease">新增发布 <van-icon name="add" style="margin-left: 8rpx"/></div>
      <div class="noticeItem" v-for="item in repairList">
        <div class="noticeName">{{item.title}}</div>
        <div class="noticeBottom">
          <div class="noticeTime">{{item.releaseTime}}</div>
          <div class="noticeBtnBox">
            <button class="mbtn editBtn" @tap="editClick(item)">编辑</button>
            <button class="mbtn closeBtn" @tap="changeType(item)">{{ item.status === 'published'?'下架':'上架' }}</button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import dayjs from "dayjs";
import { noticeParkList,propertyNoticeList,getUserLocalStorageInfo, noticeParkEdit } from "@/js_sdk/http";


export default {
  name: "index",
  data(){
    return{
      getUserLocalStorageInfo: getUserLocalStorageInfo(),
      type:'',
      repairList:[
        // {name:'关于组织2020年无锡市服务业提质增效资金项目申报的通知',time:'2024-1-21  13:00'},
        // {name:'关于组织2020年无锡市服务业提质增效资金项目申报的通知',time:'2024-1-21  13:00'},
        // {name:'关于组织2020年无锡市',time:'2024-1-21  13:00'},
      ]
    }
  },
  onLoad(type){
    // console.log('type',type)
    this.type = type.type
    const data = {
      userId:this.getUserLocalStorageInfo.userId,
      type:type.type,
      status:''
    }
    if (type.type=='1'){
      uni.setNavigationBarTitle({
        title: '园区通知',
      });
      const dayjs = require('dayjs')
      noticeParkList(data).then(res=>{
        if (res.length) {
          res.forEach(e => {
            e.releaseTime = dayjs(e.releaseTime).format('YYYY-MM-DD HH:mm:ss')
            e.type = type.type
          })
          this.repairList = res
        }
      })
    }else{
      uni.setNavigationBarTitle({
        title: '物业通知',
      });
      const dayjs = require('dayjs')
      propertyNoticeList(data).then(res=>{
        if (res.length){
          res.forEach(e=>{
            e.releaseTime = dayjs(e.releaseTime).format('YYYY-MM-DD HH:mm:ss')
            e.type = type.type
          })
          this.repairList = res
        }
      })
    }
  },
  methods:{
    newRelease(){
      uni.navigateTo({
        url:'/pages/subPackages/propertyNotice_manage/newRelease?addType=' + '发布' + '&noticeType=' + this.type
      })
    },
    editClick(item) {
      uni.navigateTo({
        url:'/pages/subPackages/propertyNotice_manage/newRelease?addType=' + '编辑' + '&id=' + item.id+ '&noticeType=' + this.type
      })
    },
    changeType(item) {
      let status = ''
      if(item.status === 'published'){
        status = 'off_shelf'
      }else {
        status = 'published'
      }
      noticeParkEdit({id:item.id,status}).then(res=>{

      })
    }
  }
}
</script>

<style lang="scss">

.propertyNotice_manage{
    .whiteBoard{
      background: white;
      margin-top: 24rpx;
      box-sizing: border-box;
      padding: 32rpx;
      height: 1424rpx;
        .addRepair{
          display: flex;
          justify-content: flex-end;
          align-items: center;
          color: rgba(3, 101, 249, 1);
        }
      .noticeItem{
        padding: 24rpx 32rpx;
        width: 686rpx;
        background: rgba(245, 247, 250, 1);
        box-sizing: border-box;
        border-radius: 16rpx;
        margin-top: 24rpx;
        .noticeName{
          color:rgba(34, 34, 34, 1);
          font-size: 32rpx;
          font-weight: 600;
          line-height: 48rpx;
        }
        .noticeBottom{
          display: flex;
          justify-content: space-between;
          align-items: center;
          margin-top: 16rpx;
          .noticeTime{
            font-size: 28rpx;
            color: rgba(102, 102, 102, 1);
          }
          .noticeBtnBox{
            display: flex;
            .mbtn{
              width: 160rpx;
              height: 60rpx;
              border-radius: 32rpx;
              display: flex;
              align-items: center;
              justify-content: center;
              font-size: 28rpx;
              &::after{
                border: none;
              }
            }
            .editBtn{
              border: 1px solid rgba(3, 101, 249, 1);
              color: rgba(3, 101, 249, 1);
              background: white;
              margin-right: 24rpx;
            }
            .closeBtn{
              color: white;
              background: linear-gradient( 316deg, #84AAFF 0%, #0365F9 100%);
            }
          }
        }
      }
    }
}
</style>
