<template>
  <div class="activeApplication">
    <div class="appFirstBox">
      <img :src="url" class="firstImg"/>
      <div class="appTitle">
        <span class="titleName">{{ form.activityName }}</span>
        <span class="titleType">{{ form.statusName }}</span>
      </div>
      <div @tap.stop="clickColl()" class="joinBox">
        <span class="joinName">{{ form.registrationNumbers }}人参加</span>
        <span class="shoucang"><img :src="form.collectorsStatus==='2' ? heartSel : heart" class="scImg"/> 收藏</span>
      </div>
      <div class="contactBox">
          <span class="contackLeft">
            <span style="color: #666666;font-size: 28rpx">联系电话：</span>
            <span style="color: #18172A;font-size: 36rpx;font-weight: 600">{{ form.activityPhone }}</span>
          </span>
        <img src="https://www.idea-co-sf.com/gardenProduct/image/phoneIcon.png" class="phoneIcon">
      </div>
    </div>
    <div class="appSecondBox">
      <div class="secondBoxItem">
        <span class="secondBoxTitle">活动举办</span>
        <span class="secondBoxInfo">{{ form.activitiesNotice }}</span>
      </div>
      <div class="secondBoxItem">
        <span class="secondBoxTitle">活动内容</span>
        <span class="secondBoxInfo">{{ form.activityContent }}</span>
      </div>
      <div class="secondBoxItem">
        <span class="secondBoxTitle">活动时间</span>
        <span class="secondBoxInfo">{{ form.activityStartTime }}  ~  {{ form.activityEndTime }}</span>
      </div>
      <div class="secondBoxItem">
        <span class="secondBoxTitle">活动地址</span>
        <span class="secondBoxInfo dhInfo">
             <span>{{ form.activityAddress }} - {{ form.activityAddressDetail }}</span>
             <img src="./image/dhIcon.png" class="dhIcon">
           </span>
      </div>
      <div class="secondBoxItem">
        <span class="secondBoxTitle">报名条件</span>
        <span class="secondBoxInfo">
             {{ form.registrationConditions }}
           </span>
      </div>
      <div class="secondBoxItem">
        <span class="secondBoxTitle">报名时间</span>
        <span class="secondBoxInfo">
             {{ form.registrationStartTime }}  ~  {{ form.registrationEndTime }}
           </span>
      </div>
      <div class="secondBoxItem">
        <span class="secondBoxTitle">活动参与</span>
        <span class="secondBoxInfo">
             {{ form.activityQuota }}
           </span>
      </div>
    </div>
    <button v-if="!registrationFlag" class="bmBtn" @tap="toApplication">我要报名</button>
    <button v-if="registrationFlag" class="bmBtn2" @tap="toApplication">已报名</button>
  </div>
</template>

<script>
import {getHomeCommunityActivityById, getByCodes, isRegistration, getUserLocalStorageInfo, homeActivityClickCollect} from "../../../js_sdk/http";

export default {
  name: "activeApplication",
  data() {
    return {
      getUserLocalStorageInfo: getUserLocalStorageInfo(),
      dc_key: ['activity_stat'],
      heartSel: "https://www.idea-co-sf.com/gardenProduct/image/heartSel.png",
      heart: "https://www.idea-co-sf.com/gardenProduct/image/heart.png",
      isColl: true,
      form: {},
      dic_SelectList: [],
      statusList: [],
      activityId: '',
      registrationFlag: false,
      url: ''
    }
  },
  created() {
    this.getByCodes()
  },
  onLoad(options) {
    this.activityId = options.activityId
    this.url = url
    this.getById()
  },
  methods: {
    getById(){
      const data = {
        id : this.activityId,
        createdBy: getUserLocalStorageInfo().userId,
      }
      getHomeCommunityActivityById(data).then(res => {
        if (res.errno === 0) {
          this.form = res.data
          this.statusList.forEach(item => {
            if (this.form.status == item.value) {
              this.form.statusName = item.label
            }
          })

          const data = {
            activityId: this.activityId,
            companyId: getUserLocalStorageInfo().userId
          }
          isRegistration(data).then(res => {
            if (res.errno === 0) {
              this.registrationFlag = res.data
            }
          })
        }
      })
    },
    async getByCodes() {
      let data = await getByCodes(JSON.stringify(this.dc_key));
      this.dic_SelectList = this.$common.handleDicList(data);
      this.statusList = this.dic_SelectList.activity_stat
      console.log('this.statusList', this.statusList)
    },
    clickColl() {
      if (this.form.collectorsStatus==='2'){
        this.form.collectorsStatus='1'
      }else{
        this.form.collectorsStatus='2'
      }

      homeActivityClickCollect({
        id: this.activityId,
        createdBy: getUserLocalStorageInfo().userId,
        collectorsStatus: this.form.collectorsStatus
      }).then(res => {
      });
    },
    toApplication() {
      uni.navigateTo({
        url: '/pages/subPackages/parkActivity/applicationInfo?activityId=' + this.form.id + "&registrationFlag=" + this.registrationFlag
      })
    }
  }
}
</script>

<style lang="scss">
.activeApplication {
  padding-bottom: 120rpx;

  .appFirstBox {
    margin: 24rpx 0;
    padding: 24rpx 32rpx;
    background: white;
    display: flex;
    flex-direction: column;

    .firstImg {
      width: 686rpx;
      height: 300rpx;
    }

    .appTitle {
      display: flex;
      align-items: center;
      margin: 24rpx 0;

      .titleName {
        font-size: 32rpx;
        color: rgba(24, 23, 42, 1);
      }

      .titleType {
        background: rgba(3, 101, 249, 0.20);
        font-size: 28rpx;
        color: rgba(3, 101, 249, 1);
        width: 112rpx;
        height: 48rpx;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 2px 2px 2px 2px;
      }
    }

    .joinBox {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding-bottom: 24rpx;

      .joinName {
        font-size: 28rpx;
        color: rgba(136, 136, 136, 1);
      }

      .shoucang {
        display: flex;
        align-items: center;
        font-size: 28rpx;
        color: rgba(24, 23, 42, 1);

        .scImg {
          width: 32rpx;
          height: 28rpx;
          margin-right: 8rpx;
        }
      }
    }

    .contactBox {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 24rpx 0;
      border-top: 1px solid #E6E6E6;

      .contackLeft {
        display: flex;
        align-items: center;
      }

      .phoneIcon {
        width: 64rpx;
        height: 64rpx;
      }
    }
  }

  .appSecondBox {
    padding: 32rpx;
    background: white;

    .secondBoxItem {
      display: flex;
      flex-direction: column;
      margin-bottom: 48rpx;

      .secondBoxTitle {
        color: #222222;
        font-size: 32rpx;
        font-weight: 600;
        margin-bottom: 16rpx;
      }

      .secondBoxInfo {
        font-size: 28rpx;
        color: #666666;
        line-height: 40rpx;
      }

      .dhInfo {
        display: flex;
        justify-content: space-between;

        .dhIcon {
          width: 36rpx;
          height: 36rpx;
          padding-left: 20rpx;
          border-left: 1px solid #E6E6E6;
        }
      }
    }
  }

  .bmBtn {
    width: 654rpx;
    height: 96rpx;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    background: #0365F9;
    border-radius: 8rpx;
    margin: 48rpx 48rpx 0rpx 48rpx;
  }

  .bmBtn2 {
    width: 654rpx;
    height: 96rpx;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    background: #9f9e9e;
    border-radius: 8rpx;
    margin: 48rpx 48rpx 0rpx 48rpx;
  }
}
</style>
