<template>
  <div class="goods-bottom">
    <template v-if="status == 1">
      <template v-if="groupId">
        <template v-if="info.groupBuyStatus == 2 || info.groupBuyStatus == 3">
          <cr-button
            shape="circle"
            :disabled="disabled"
            type="primary"
            block
            @click="createOrJoin(2)"
          >
            立即开团
          </cr-button>
        </template>
        <template v-else>
          <cr-button
            class="mutiplie"
            plain
            type="primary"
            shape="circle"
            :disabled="disabled"
            @click="createOrJoin(2)"
            >自己做团长</cr-button
          >
          <cr-button
            v-if="!info.joinGroup"
            class="mutiplie"
            shape="circle"
            :disabled="disabled"
            type="primary"
            block
            @click="createOrJoin(3)"
          >
            立即参团
          </cr-button>
        </template>
      </template>
      <template v-else>
        <cr-button
          shape="circle"
          :disabled="disabled"
          type="primary"
          block
          @click="createOrJoin(1)"
        >
          立即开团
        </cr-button>
      </template>
    </template>
    <template v-else>
      <cr-button
        v-if="info.groupBuyStatus == 1"
        shape="circle"
        :disabled="disabled"
        type="primary"
        block
        @click="shareTo"
      >
        邀请好友
      </cr-button>
      <cr-button
        v-if="info.groupBuyStatus != 1 && !timeIsOver"
        shape="circle"
        plain
        :disabled="disabled"
        type="primary"
        block
        @click="toList"
      >
        查看其他商品
      </cr-button>
    </template>
  </div>
</template>
<script>
export default {
  name: 'BottomNav',
  props: {
    groupId: {
      type: Number,
      default: 0
    },
    info: {
      type: Object,
      default() {
        return {};
      }
    },
    disabled: {
      type: Boolean,
      default: false
    },
    goodsId: {
      type: String,
      default: ''
    },
    status: {
      type: Number,
      default: 1 // 1是大图详情页， 2是小图详情页
    },
    endTime: {
      type: String,
      default: ''
    },
    currentTime: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      nativeBridge: null,
      timeIsOver: false
    };
  },
  created() {
    if (this.status == 2) {
      // 订单详情页
      const currentTime = new Date(this.currentTime.replace(/\-/g, '/')).getTime();
      const endTime = new Date(this.endTime.replace(/\-/g, '/')).getTime();
      this.timeIsOver = currentTime >= endTime ? true : false;
    }
  },
  methods: {
    toList() {
      const { activityId } = this.$route.query || '';
      if (activityId) {
        this.$router.push({ name: 'groupBuyList', query: { activityId } });
      }
    },
    shareTo() {
      // 邀请好友
      this.$emit('share');
    },
    createOrJoin(mark) {
      // 参团
      // mark 1-> 开团  0-> 参团 2->自己做团长
      this.$emit('buy', mark);
    }
  }
};
</script>
<style lang="less" scoped>
.goods-bottom {
  position: fixed;
  left: 0;
  bottom: 0;
  display: flex;
  justify-content: space-evenly;
  align-items: center;
  width: 100%;
  background: @white;
  border-top: 2px solid #f7f7f7;
  padding-bottom: calc(10px + constant(safe-area-inset-bottom));
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  padding-top: 10px;
  padding-left: 12px;
  padding-right: 12px;
  box-sizing: border-box;
  z-index: 89;
  button {
    flex: 1;
    font-size: 16px;
    &.mutiplie {
      margin: 0 @padding-xs;
    }
  }
}
</style>
