<template>
  <div class="page">
    <div class="fixed-top">
      <div class="header-search">
        <div class="search-input-content">
          <img src="https://cdn.cunwuyun.cn/img/search-blue.svg" alt="" class="search-icon">
          <input type="text" placeholder="请输入活动名称或地点" class="search-input" placeholder-style="color:#E2E8F1;"
                 v-model="inputValue" @confirm="getListInit" confirm-type="search"/>
        </div>
      </div>
      <div class="header-select">
        <div class="select-item" @click="activeStatusShow = true">
          <span>{{ activeStatusLabel }}</span>
          <img src="https://cdn.cunwuyun.cn/img/down.svg" alt="" class="down-icon">
        </div>
        <div class="select-item" @click="checkStatusShow = true">
          <span>{{ checkStatusLabel }}</span>
          <img src="https://cdn.cunwuyun.cn/img/down.svg" alt="" class="down-icon">
        </div>
      </div>
    </div>
    <div class="active-list">
      <div class="item" v-for="(item, index) in list" :key="index" @click="isToken(`./detail?id=${item.id}`)">
        <div class="item-top">
          <p class="title">{{ item.title }}</p>
          <div class="info">
            <span class="label">活动时间：</span>
            <span class="value">{{ item.beginTime }} 至<br/>{{ item.endTime }}</span>
          </div>
          <div class="info">
            <span class="label">活动地点：</span>
            <span class="value">{{ item.address }}</span>
          </div>
        </div>
        <div class="item-btn">
          <span class="phone-btn" @click.stop="callPhone(item.contactPhone)" v-if="item.contactPhone">呼叫联系人</span>
          <span v-if="item.signupStatus == 0 && item.logStatus == null"
                @click="isToken(`./toAdd?id=${item.id}`)">去报名</span>
          <span v-if="item.actionStatus == 1 && item.logStatus == 0"
                @click="isToken(`./addContent?id=${item.id}&reportId=${item.reportId}`)">填写日志</span>
          <span v-if="item.logStatus == 2" @click="isToken(`./logDetail?id=${item.id}&title=${item.title}`)">查看日志</span>
        </div>
        <span class="item-status"
              :class="'color'+item.actionStatus">{{
            $dict.getLabel('partyReportActionStatus', item.actionStatus)
          }}</span>
      </div>
      <AiEmpty v-if="!list.length" class="pad-t168"/>
    </div>
    <div class="fixed-bottom btn-footer">
      <div :class="listType == 0 ? 'confirm-bg' : ''" @click="listTypeChange('0')">
        <img src="https://cdn.cunwuyun.cn/dvcp/activityList/more-icon-fff.png" alt="" v-if="listType == 0">
        <img src="https://cdn.cunwuyun.cn/dvcp/activityList/more-icon-999.png" alt="" v-else>
        活动列表
      </div>
      <div :class="listType == 3 ? 'confirm-bg' : ''" @click="listTypeChange('3')">
        <img src="https://cdn.cunwuyun.cn/dvcp/activityList/pen-icon-fff.png" alt="" v-if="listType == 3">
        <img src="https://cdn.cunwuyun.cn/dvcp/activityList/pen-icon-999.png" alt="" v-else>
        我的活动
      </div>
    </div>
    <u-select v-model="activeStatusShow" :list="activeStatusList" @confirm="confirmActiveStatus"
              confirm-color="#07c160"></u-select>
    <u-select v-model="checkStatusShow" :list="checkStatusList" @confirm="confirmActiveStatus"
              confirm-color="#07c160"></u-select>
    <ai-login ref="login"></ai-login>
  </div>
</template>
<script>
import {mapState} from 'vuex'

export default {
  name: "AppActivityList",
  appName: "活动列表",
  computed: {
    ...mapState(['user', 'token'])
  },
  data() {
    return {
      inputValue: '',
      current: 1,
      list: [],
      activeStatus: '',
      activeStatusLabel: '活动状态',
      activeStatusShow: false,
      activeStatusList: [],
      checkStatusShow: false,
      checkStatusList: [],
      checkStatus: '',
      checkStatusLabel: '报名状态',
      listType: '0',
      partyId: '',
      areaId: ''
    }
  },
  onLoad() {
    this.areaId = uni.getStorageSync('areaId')
    if (this.user.partyId) {
      this.partyId = this.user.partyId
    } else {
      this.partyId = this.user.residentId
    }
  },
  onShow() {
    this.$dict.load('partyReportActionStatus', 'partyReportSignupStatus').then(() => {
      this.activeStatusList = this.getSelectList('partyReportActionStatus')
      this.checkStatusList = this.getSelectList('partyReportSignupStatus')
      this.getListInit()
    })
  },
  methods: {
    confirmActiveStatus(e) {
      if (this.activeStatusShow) {
        this.activeStatusLabel = e[0].label
        this.activeStatus = e[0].value
      }

      if (this.checkStatusShow) {
        this.checkStatusLabel = e[0].label
        this.checkStatus = e[0].value
      }
      this.getListInit()
    },
    getListInit() {
      this.current = 1
      this.list = []
      this.getList()
    },
    getList() {
      this.$instance.post(`/app/apppartyreport/list-xcx?title=${this.inputValue}&size=10&current=${this.current}&listType=${this.listType}&actionStatus=${this.activeStatus}&signupStatus=${this.checkStatus}&partyId=${this.partyId}&areaId=${this.areaId}`).then(res => {
        if (res.code == 0) {
          if (this.current > res.data.pages) {
            return
          }
          this.list = this.current > 1 ? [...this.list, ...res.data.records] : res.data.records;
        }
      })
    },
    isToken(url) {
      if (this.token) {//判断是否登录
        if (this.user.status == 0) {
          if (!this.user.phone) {//判断已经绑定手机
            this.$linkTo('/pages/phone/bingPhoneNumber?from=auth')
          } else {
            this.$linkTo('/pages/auth/authenticationInfo')
          }
        } else {
          this.$linkTo(url)
        }
      } else {
        // this.$getUserProfile().then((v) => {
        //   this.$autoLogin(v.userInfo).then(() => {
        //     this.isToken(url)
        //   })
        // }).catch(() => {
        //   this.$toast('请先登录')
        // })
        this.login()
      }
    },
    login() {
      this.$refs.login.show()
    },
    // toDetail(id) {
    //   this.$linkTo(`./detail?id=${id}`)
    // },
    // toAddContent(id, reportId) {
    //   this.$linkTo(`./addContent?id=${id}&reportId=${reportId}`)
    // },
    // toAdd(id) {
    //   this.$linkTo(`./add?id=${id}`)
    // },
    // toLogDetail(id) {
    //   this.$linkTo(`./logDetail?id=${id}`)
    // },
    listTypeChange(type) {
      this.listType = type
      this.activeStatus = ''
      this.activeStatusLabel = '活动状态'
      this.checkStatus = ''
      this.checkStatusLabel = '报名状态'
      this.getListInit()
    },
    getSelectList(dictName) {
      var list = []
      this.$dict.getDict(dictName).map(i => {
        var item = {
          label: i.dictName,
          value: i.dictValue
        }
        list.push(item)
      })
      list.unshift({label: '全部', value: ''})
      return list
    },
    callPhone(phone) {
      wx.makePhoneCall({
        phoneNumber: phone,
      })
    }
  },
  onReachBottom() {
    this.current = this.current + 1;
    this.getList()
  },
}
</script>
<style scoped lang="scss">
@import "../../common/common.scss";

.page {
  width: 100%;
  background-color: #F3F6F9;

  .fixed-top {
    z-index: 99;
  }

  .active-list {
    padding: 234px 32px 112px;
    margin-top: 8px;
    background-color: #F3F6F9;
    box-sizing: border-box;

    .item {
      width: 100%;
      background: #FFF;
      padding: 32px 0 0;
      box-sizing: border-box;
      margin-bottom: 34px;
      position: relative;
      overflow: hidden;

      .item-top {
        padding: 0 32px;
      }

      .title {
        width: 576px;
        font-size: 32px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #333;
        line-height: 44px;
        word-break: break-all;
        margin-bottom: 32px;
      }

      .info {
        font-size: 30px;
        line-height: 42px;
        margin-bottom: 8px;

        .label {
          display: inline-block;
          width: 150px;
          color: #999;
          vertical-align: top;
        }

        .value {
          display: inline-block;
          width: calc(100% - 150px);
          color: #343D65;
        }
      }

      .item-btn {
        margin-top: 32px;
        padding: 20px 32px;
        border-top: 2px solid #eee;
        text-align: right;

        span {
          display: inline-block;
          padding: 0 24px;
          line-height: 56px;
          border-radius: 28px;
          border: 2px solid #1365DD;
          color: #1365DD;
          font-size: 28px;
          margin-left: 32px;
        }

        .phone-btn {
          border: 2px solid #E1E1E1;
          color: #606060;
        }
      }

      .item-status {
        width: 160px;
        height: 40px;
        line-height: 36px;
        font-size: 26px;
        font-weight: 500;
        position: absolute;
        right: -38px;
        top: 24px;
        -webkit-transform: rotate(90deg);
        transform: rotate(45deg);
        text-align: center;
      }

      .color0 {
        background: #FFF3E9;
        color: #FF8822;
      }

      .color1 {
        background: #EEF5FF;
        color: #5A98F2;
      }

      .color2 {
        background: #F2F2F2;
        color: #999;
      }
    }
  }

  .btn-footer {
    display: flex;
    height: 112px;
    line-height: 112px;
    background-color: #fff;
    border-top: 2px solid #ddd;
    box-sizing: border-box;

    div {
      flex: 1;
      text-align: center;
      font-size: 32px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #666;

      img {
        width: 36px;
        height: 36px;
        margin-right: 8px;
        vertical-align: sub;
      }
    }

    .confirm-bg {
      background-color: #197DF0;
      color: #fff;
    }
  }

}
</style>
