<!-- 常驻工区--> 
<template>
    <div>
        <div
            class="set-residen-work"
            @click="showSaveSpace"
            v-if="IsResiden==3"
        >
            <span class="set-text">设置常驻</span>
            <image
                class="spimg"
                :src="h5StaticPath+'arrow.svg'"
            />
        </div>
        <div class="residen-work" v-if="IsResiden===4">
            <span class="just-text">常驻工区</span>
        </div>
    </div>

</template>

<script>
import wepy from '@wepy/core'
import config from '@/config'
import {changeDefaultSpace} from '@/packagesEnv/api/officehome.js'
wepy.component({
  props: {
    IsResiden: Number,
    spaceId: String,
    userInfo: Object
  },
  data: {
    h5StaticPath: config.h5StaticPath + '/page-officehome/'
  },
  computed: {},
  methods: {
    showSaveSpace() {
      const _this = this
      console.log(this, '----this')
      _this.$root.getCurrentSpace()
      wx.showModal({
        title: '设置常驻工区',
        content: '将该空间设定为您的常驻工区?',
        confirmText: '确定',
        cancelText: '取消',
        cancelColor: '#c4c4c4',
        confirmColor: '#1DB1B2',
        success: res => {
          if (res.confirm) {
            changeDefaultSpace(_this.spaceId).then(res => {
                // getCurrentPages 小程序自己的方法
              var pages = getCurrentPages()
              _this.$root.getCurrentSpace()
              wx.showToast({
                title: '设置成功',
                icon: 'success',
                duration: 3000,
                complete: res => {
                  if (pages.length <= 1) {
                    wx.redirectTo({ url: '/packagesEnv/pages/home/index' })
                  } else {
                    wx.navigateBack()
                  }
                }
              })
            })
          }
        }
      })
    }
  },
    // 生命周期 - 创建完成（可以访问当前this实例）
  created() {

  },
    // 生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {

  }
})
</script>
<style lang='less' scoped>
.residen-work {
    margin-right: 40rpx;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 120rpx;
    height: 46rpx;
    padding: 8rpx 16rpx 8rpx 16rpx;
    border-radius: 8rpx;
    gap: 20rpx;
    background: rgba(61, 203, 204, 0.3);
    .just-text {
        font-family: PingFang SC;
        font-size: 22rpx;
        font-weight: 400;
        line-height: 30rpx;
        color: rgba(27, 33, 41, 1);
    }
}
.set-residen-work {
    margin-right: 40rpx;
    width: 128rpx;
    display: flex;
    align-items: center;
    .set-text {
        font-family: PingFang SC;
        font-size: 24rpx;
        font-weight: 400;
        line-height: 40rpx;
        color: #8b949e;
    }
    .spimg {
        margin-left: 8rpx;
        width: 24rpx;
        height: 24rpx;
    }
}
</style>
