<template>
  <div class="TagList">
    <u-navbar back-icon-color="#000" title="居民标签管理" title-color="#000" title-width="300" title-size="32" 
        :title-bold="true" :background="backgroundNavbar" :is-fixed="true" height="44" z-index="999"></u-navbar>
    <div class="header-content-bg">
      <img src="https://cdn.sinoecare.com/i/2024/07/12/6690a1303d423.png" alt="">
    </div>
    <div class="list-content">
      <div class="item" v-for="(item, index) in list" :key="index">
        <div class="title">{{item.labelName}}</div>
        <div class="btn">
          <img src="https://cdn.sinoecare.com/i/2024/07/16/6696151a1a160.png" alt="" @click="toAdd(item.id)">
          <img src="https://cdn.sinoecare.com/i/2024/07/16/6696151964a8b.png" alt="" @click="del(item.id)">
        </div>
        <!-- <div class="tag-list">
          <div class="item-tag">122</div>
          <div class="item-tag">122</div>
          <div class="item-tag">122</div>
        </div> -->
        <div class="info">创建人：{{item.createUserName}}</div>
        <div class="info">创建时间：{{item.createTime}}</div>
      </div>
      <AiEmpty v-if="!list.length"></AiEmpty>
    </div>
    <div class="footer" @click="toAdd('')">
      <div class="btn">新增标签</div>
    </div>
  </div>
</template>

<script>
import {mapState} from 'vuex'

export default {
  name: 'TagList',
  appName: '居民标签管理',
  customNavigation: true,
  data() {
    return {
      backgroundNavbar: {
        background: 'url(https://cdn.sinoecare.com/i/2024/07/12/6690a1309c7d3.png) no-repeat',
        backgroundSize: 'cover',
      },
      current: 1,
      pages: 2,
      list: []
    }
  },
  computed: {
    ...mapState(['user']),
  },
  onLoad() {
    this.getList()
    uni.$on('updateTag', ()=>{
      this.current = 1
      this.pages = 2
      this.getList()
    })
  },
  onShow() {
    uni.setNavigationBarColor({
      frontColor: 'black',
      backgroundColor: '#ffffff'
    })
  },
  methods: {
    getList() {
      if(this.current > this.pages) return
      this.$instance.post('app/appresidentlabelinfo/list', null, {
        params: {
          size: 20,
          current: this.current,
        },
      })
      .then((res) => {
        if (res.code == 0) {
          // res.data.records.map((item) => {
          //   item.isCheck = false
          // })
          this.list = this.current > 1 ? [...this.list, ...res.data.records] : res.data.records

          this.pages = res.data.pages
        }
      })
    },
    toAdd(id) {
      uni.navigateTo({url: `./AddTag?id=${id}`})
    },
    del(id) {
      this.$dialog.confirm({content: "确定删除该数据?"}).then(() => {
        this.$instance.post(`app/appresidentlabelinfo/delete?ids=${id}`).then(res => {
          if (res?.code == 0) {
            this.$u.toast("删除成功!")
            this.current = 1
            this.getList()
          }
        })
      }).catch(() => 0)
    }
  },
  onReachBottom() {
    // this.current = this.current + 1
    // this.getList()
  },
}
</script>

<style scoped lang="scss">
.TagList {
  height: 100%;
  .header-content-bg {
    width: 100%;
    position: fixed;
    img {
      width: 100%;
      height: 592px;
    }
  }
  .list-content {
    padding: 16px 0 220px 0;
    .item {
      width: calc(100% - 64px);
      background: #FFF;
      border-radius: 16px;
      padding: 32px 32px 30px 32px;
      margin: 0 0 32px 32px;
      box-sizing: border-box;
      position: relative;
      .title {
        width: calc(100% - 88px);
        line-height: 44px;
        font-family: PingFangSC-Medium;
        font-weight: 500;
        font-size: 32px;
        color: #333;
        margin-bottom: 4px;
      }
      .info {
        line-height: 44px;
        color: #999;
        font-size: 26px;
        margin-top: 8px;
      }
      .tag-list {
        .item-tag {
          display: inline-block;
          padding: 4px 10px;
          line-height: 34px;
          font-family: PingFangSC-Regular;
          font-weight: 400;
          font-size: 24px;
          color: #8891A1;
          margin: 0 16px 16px 0;
          background-color: #F0F2F5;
        }
      }
      .btn {
        position: absolute;
        top: 32px;
        right: 32px;
        img {
          width: 56px;
          height: 56px;
          margin-left: 32px;
        }
      }
    }
  }
  .footer {
    width: 100%;
    position: fixed;
    bottom: 0;
    left: 0;
    background-color: #F4F5FA;
    padding: 64px 64px 68px 64px;
    z-index: 9;
    .btn {
      width: calc(100% - 128px);
      line-height: 88px;
      background: #026AF2;
      border-radius: 44px;
      font-family: PingFangSC-Medium;
      font-weight: 500;
      font-size: 34px;
      color: #FFF;
      text-align: center;
    }
  }
}
</style>
