<template>
  <div class="home_wrapper">
    <div
      class="header_main"
      :style="`background-image:url(${require(showBtn?'@/assets/images/sunVillage_info/list_head_green.png':'@/assets/images/sunVillage_info/list_head_red.png')})`"
    >
      投诉建议
      <div class="return_btn" @click="onClickLeft"></div>
      <div class="add_btn" @click="goAdd" v-show="showBtn"></div>
    </div>
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="getList"
    >
      <van-swipe-cell v-for="(item,index) in applicationList" :key="index" >
        <van-cell
          :border="false"
          center
          :to="{name: 'sunVillageInfoListComplaintDetail',query:{id:item.id,type:showBtn?'':'code'}}"
        >
          <template #right-icon>
            <p :class="{
              'state1':item.advideState=='已解决',
              'state2':item.advideState!='已解决',
              }">{{item.advideState}}</p>
          </template>
          <template #title>
            <p class="tit">{{item.title}}</p>
            <p class="time">{{item.adviceTime}}</p>
            <p class="dept"><van-icon name="location" color="#3977e7" />{{item.deptName}}</p>
          </template>
          <template #icon>
            <img src="../../assets/images/sunVillage_info/complaint_add_icon_05.png" style="width: 1.5rem;margin-right: 2%;">
          </template>
        </van-cell>
<!--        <template #right v-if="showBtn">-->
<!--          <div style="background-color: #ee0a24;height: 100%" @click="goRemove(item.id)">删除</div>-->
<!--          <div style="background-color: #07c160" @click="goEdit(item.id)">修改</div>-->
<!--          <div style="background-color: rgb(255, 166, 62);" v-if="item.status != '3'" @click="goRanking(item.id)">发布</div>-->
<!--        </template>-->
      </van-swipe-cell>
    </van-list>
  </div>
</template>

<script>
  import { adviceList , delPoll , publicPoll } from "@/api/sunVillage_info/fixedAssets";
  import Cookies from "js-cookie";
  import request from '@/utils/request'
  import {Dialog} from "vant";
  export default {
    name: "certificateList",
    data() {
      return {
        applicationList:[],
        loading: false,
        finished: false,
        show: true,
        fileList:[],
        showBtn:true,
        queryParams:{}
      };
    },
    created() {
      if (this.$route.query.typeX!=1){
        if (!Cookies.get('user')){
          Dialog.confirm({
            title: '系统提示',
            message: '登录状态已过期，请重新登录',
            confirmButtonText: '重新登录',
            cancelButtonText: '取消'
          }).then(() => {
            this.$router.push({path:'/sunVillage_info/login_code'})
          })
        }
        this.queryParams = {
          advicePhone:JSON.parse(Cookies.get('user')).phone,
          translate_dict:1,
        }
      }else{
        this.showBtn = false;
        this.queryParams = {
          deptId:Cookies.get('deptId'),
          translate_dict:1,
        }
      }

    },
    methods: {
      getList(){
        var _this = this;
        adviceList(this.queryParams).then(response => {
          _this.listLength = response.total;
          response.rows.map(res=>{
            _this.applicationList.push(res);
          })

          if(_this.applicationList.length >= response.total){
            _this.finished = true;
            return;
          }else{
            _this.loading = false;
            _this.queryParams.pageNum += 1 ;
          }
        });
      },
      goAdd(){
        this.$router.push({path:'/sunVillage_info/list_complaint_add', query: {type: 'code'}})
      },
      goDetail(id){
        this.$router.push({path:'/sunVillage_info/list_vote_detail',query: {id:id}})
      },
      goEdit(id){
        this.$router.push({path:'/sunVillage_info/list_vote_edit',query: {id:id}})
      },
      goRanking(id){
        this.$dialog.alert({
          title: '提示',
          message: '确认发布？',
          showCancelButton:true,
        })
          .then(() => {
            publicPoll(id).then(response => {
              this.$notify({ type: 'success', message: '发布成功' });
              this.applicationList = [];
              this.getList()
            });
          })
          .catch(() => {
            // on cancel
          });
      },
      goRemove(id){
        this.$dialog.alert({
          title: '提示',
          message: '确认删除？',
          showCancelButton:true,
        })
          .then(() => {
            delPoll(id).then(response => {
              this.$notify({ type: 'success', message: '删除成功' });
              this.applicationList = [];
              this.getList()
            });
          })
          .catch(() => {
            // on cancel
          });

      }
    },



  }
</script>

<style scoped lang="scss">
  .home_wrapper{
    background: #e9e9e9;
    min-height: 100vh;
    width: 100vw;
    .header_main{
      height: 116px;
      background: url('../../assets/images/sunVillage_info/list_head.png') no-repeat;
      background-size: 100% 100%;
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      font-size: 36px;
      line-height: 116px;
      text-align: center;
      color: #fff;
      position: relative;
      .return_btn{
        width: 24px;
        height: 43.2px;
        background: url('../../assets/images/sunVillage_info/list_icon_5.png') center center no-repeat;
        background-size: 20px 36px;
        position: absolute;
        left: 38px;
        top: 36px;
      }
      .add_btn{
        width: 56.4px;
        height: 40.8px;
        background: url('../../assets/images/sunVillage_info/list_icon_9.png') center center no-repeat;
        background-size: 47px 34px;
        position: absolute;
        right: 38px;
        top: 36px;
      }
    }
    .van-swipe-cell {
      position: relative;
      overflow: hidden;
      cursor: grab;
      width: 96%;
      margin: 0 auto;
      margin-top: 15PX;
      box-shadow: 5PX 5PX 2PX #ccc;
      border-radius: 10PX;
    }
    /deep/ .van-swipe-cell__right{
      display: flex;
      align-items: center;
      width: 150PX;
      margin-left: 5PX;
      a,div{
        margin: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        color: #ffffff;
        font-size: 14PX;
        height: 100%;
        flex: 1;
      }
    }

    .tit{
      color: #333333;
      font-size: .45rem;
    }
    .time{
      color: #aaaaaa;
      font-size: .35rem;
    }
    .dept{
      color: #3977e7;
      font-size: .35rem;
      display: flex;
      align-items: center;
    }

    .state1{
      background: #e4f8f4;
      border: 1px solid #c5efe7;
      color: #2ec6a9;
      padding: 0 3vw;
      border-radius: 5vw;
    }

    .state2{
      background: #fedfe3;
      border: 1px solid #fcb9c2;
      color: #f60325;
      padding: 0 3vw;
      border-radius: 5vw;
    }
  }
</style>
