<template>
  <div class="AppTvMsg">
    <AiTopFixed>
      <div class="currentLeft-top">
        <AiSelect @data="selectType" :list="typeList" v-model="type"></AiSelect>
      </div>
    </AiTopFixed>
    <div class="record">
      <div class="item" v-for="(item, index) in list" :key="index">
        <p class="content">{{item.content}}</p>
        <p :class="`type${item.type}`">{{item.type == '10' ? '主动报备提醒' : '核酸监测'}}</p>
        <u-icon name="trash" color="#ff4466" size="40" class="del" @click="del(item)"></u-icon>
      </div>
    </div>
    <AiEmpty v-if="!list.length"></AiEmpty>
    <img src="./img/add-icon.png" alt="" class="add-img" @click="add">
  </div>
</template>
<script>

export default {
  name: "AppTvMsg",
  appName: '极光推送',
  data() {
    return {
      list: [],
      current: 1,
      type: '',
      typeList: [{label: '全部', value: ''}, {label: '核酸监测', value: '15' }, {label: '主动报备提醒', value: '10' }]
    }
  },
  onLoad() {
    this.getList()
    uni.$on('getList', () => {
      this.list = []
      this.current = 1

      this.$nextTick(() => {
        this.getList()
      })
    })
  },

  onShow() {
    document.title = '极光推送'
  },

  methods: {
    selectType(selecteds) {
      this.type = selecteds?.[0]?.value
      this.getListInit()
    },
    add() {
      uni.navigateTo({
        url: `./add`
      })
    },

    getListInit() {
      this.list = []
      this.current = 1
      this.getList()
    },
    getList() {
      this.$http.post(`/app/appiptvjpush/list`, null, {
        params: {
          type: this.type,
          current: this.current,
          size: 10
        }
      }).then(res => {
        if (res.code == 0) {
          if (this.current > 1) {
            this.list = [...this.list, ...res.data.records]
          } else {
            this.list = res.data.records
          }
        } else {
          uni.hideLoading()
        }
      }).catch(() => {
        uni.hideLoading()
      })
    },
    del(item) {
      this.$confirm(`是否要删除推送消息`).then(() => {
        this.$http.post(`/app/appiptvjpush/delete?ids=${item.id}`).then((res) => {
          if (res.code == 0) {
            this.getListInit()
            this.$u.toast('删除成功')
          }
        })
      })
    },
  },

  onReachBottom() {
    this.current ++
    this.getList()
  }
}
</script>
<style lang="scss" scoped>
.AppTvMsg {
  padding-bottom: 128px;
  ::v-deep .AiTopFixed{
    .content{
      padding: 0;
    }
  }
  .record {
    padding: 32px;

    .item {
      width: 100%;
      padding: 32px 30px;
      box-sizing: border-box;
      background-color: #fff;
      border-radius: 8px;
      margin-bottom: 16px;
      position: relative;
      .del{
        position: absolute;
        top: 32px;
        right: 32px;
      }
      .content{
        width: 500px;
        word-break: break-all;
        margin-bottom: 8px;
      }
      .type10{
        color:#4E8EEE;
      }
      .type15{
        color:#42D784;
      }
    }
  }

  .add-img {
    width: 120px;
    position: fixed;
    bottom: 120px;
    right: 32px;
  }

  .currentLeft-top {
    display: flex;
    align-items: center;
    padding: 32px 32px 0;

    .left {
      width: 200px;
      display: flex;
      align-items: center;

      img {
        width: 48px;
        height: 48px;
      }
    }
  }
  ::v-deep .u-search {
    margin-bottom: 0 !important;
  }
}
</style>
