import Taro, { Component } from '@tarojs/taro'
import { View, Image, Text, Navigator } from '@tarojs/components'
import LoginPopup from '@/c/login/Popup'
import PopupAd from './components/discountGroup/popup'
import './discountGroup.scss'
class Index extends Component {
onShareAppMessage() {
const { eId, eName } = this.$router.params
const { launchObj } = this.state
if (launchObj.hash) {
return {
title: `我想参加${eName}的洪楼团购,快来帮我助力下`,
path: `/pagesPlan/discountGroup?eId=${eId}&eName=${eName}&hash=${launchObj.hash}`,
}
} else {
return {
title: '南昌买房,来洪楼领取专属优惠',
path: `/pagesPlan/discountGroup?eId=${eId}`,
}
}
}
onShareTimeline () {
const { eId, eName } = this.$router.params
const { launchObj } = this.state
if (launchObj.hash) {
return {
title: `我想参加${eName}的洪楼团购,快来帮我助力下`,
path: `/pagesPlan/discountGroup?eId=${eId}&eName=${eName}&hash=${launchObj.hash}`,
}
} else {
return {
title: '南昌买房,来洪楼领取专属优惠',
path: `/pagesPlan/discountGroup?eId=${eId}`,
}
}
}
constructor (props) {
super(props)
this.state = {
searchKey: '',
page_size: 10,
page: 1,
isListEnd: false,
isListLoading: false,
isListEmpty: false,
dataList: [],
isRuleShow: false,
isSharePopup: false,
launchObj: {},
joinArr: [],
userInfo: '',
token: '',
isLoginPopupShow: false,
activityObj: {},
isJoin: false,
isGetShow: false,
}
}
config = {
navigationStyle: 'custom',
navigationBarTextStyle: 'white'
}
componentWillMount () {
Taro.$AHU(this)
const { eId, hash } = this.$router.params
if (hash) {
this.getDtl()
} else {
this.getMyDtl()
}
}
getMyDtl () {
const { eId } = this.$router.params
this.setState({
userInfo: Taro.getStorageSync('APP_userInfo') || {},
token: Taro.getStorageSync('APP_token') || ''
})
Taro.api.other.apiactivitybuyinginfo({estate_id: eId}).then(res => {
if (res.launch) {
this.setState({
joinArr: res.join || [],
launchObj: res.launch || {},
activityObj: res.activity || {},
isJoin: res.is_join || false
}, () => {
if (res.launch.status === 3 || res.launch.status === 4 || res.launch.status === 5 || res.launch.status === 6) {
this.openGetPopup()
}
// this.showQrCode()
})
} else {
this.setState({
activityObj: res.activity || {},
isRuleShow: true
})
}
})
}
getDtl () {
this.setState({
userInfo: Taro.getStorageSync('APP_userInfo') || {},
token: Taro.getStorageSync('APP_token') || ''
})
const { hash } = this.$router.params
Taro.api.other.apiactivitybuyinghash({hash}).then(res => {
if (res.launch) {
this.setState({
joinArr: res.join || [],
launchObj: res.launch || {},
activityObj: res.activity || {},
isJoin: res.is_join || false
}, () => {
if (this.subPopup) this.subPopup.getData({poster_img: res.activity.poster_img})
const { joinArr, activityObj } = this.state
if (joinArr.length === activityObj.option_req) {
Taro.$msgConfirm('你的好友已领取团购优惠,看看这个楼盘?', () => {
this.linkHouseDtl()
})
}
})
} else {
Taro.$msgConfirm('没有查到助力数据,看看这个楼盘?', () => {
this.linkHouseDtl()
})
}
})
}
componentDidShow () { }
componentDidHide () { }
renderRule () {
const { isRuleShow, launchObj, activityObj } = this.state
// console.log(activityObj.rule_img)
// const bg = require('./img/discountGroup/ex_rule.png')
const bgClose = require('@img/icon_g_close2.png')
return (
返回上一页
{
launchObj.id
?
我知道了
:
我已阅读,发起助力
}
{
launchObj.id
?
:
}
)
}
backPrevPage () {
let pages = getCurrentPages()
if (pages.length < 2) {
Taro.reLaunch({
url: '/pages/index/index'
})
} else {
Taro.navigateBack({
delta: 1
})
}
}
toHelpMe () {
const { eId } = this.$router.params
Taro.api.other.apiactivitybuyinglaunch({estate_id: eId}).then(res => {
this.setState({
launchObj: res || {},
isRuleShow: false,
isSharePopup: true,
})
})
}
dealPopup (str) {
const { bc } = this.props
const { formObj } = this.state
if (bc) {
if (str === 'confirm') {
bc('confirm', formObj)
} else {
bc()
}
}
}
openRulePopup () {
this.setState({
isRuleShow: true
})
}
closeRulePopup () {
this.setState({
isRuleShow: false
})
}
closeSharePopup () {
this.setState({
isRuleShow: false,
isSharePopup: false
}, () => {
this.getMyDtl()
})
}
helpHandle () {
const { hash } = this.$router.params
Taro.api.other.apiactivitybuyingjoin({hash}).then(res => {
Taro.$msgConfirm('助力成功', () => {
this.linkHouseDtl()
}, () => {
this.linkHouseDtl()
})
})
}
getUserProfile (e) {
wx.getUserProfile({
desc: '用于完善头像和昵称资料',
success: (res) => {
const dtlObj = res || {}
this.setState({
userInfo: dtlObj.userInfo
})
Taro.setStorageSync('APP_userInfo', dtlObj.userInfo)
}
})
}
openLoginPopup (obj) {
this.setState({
isLoginPopupShow: true
})
}
closeLoginPopup (str) {
this.setState({
isLoginPopupShow: false
})
if (str && str === 'success') {
this.getDtl()
}
}
linkHome () {
Taro.reLaunch({
url: '/pages/index/index'
})
}
renderGoHome () {
const icon = require('@img/images/icon_go_home.png')
return (
)
}
linkHouseDtl () {
const { eId } = this.$router.params
Taro.navigateTo({
url: `/pagesHouse/indexDtl?id=${eId}`
})
}
showQrCode () {
const { userInfo } = this.state
const { joinArr, activityObj, launchObj } = this.state
if (joinArr.length === activityObj.option_req) {
Taro.$msgConfirm(`恭喜您,获得团购优惠~优惠码:${userInfo.phone}-${launchObj.hash}`)
}
}
openGetPopup () {
this.setState({
isGetShow: true
})
}
closeGetPopup () {
this.setState({
isGetShow: false
})
}
renderGetSuccess () {
const { userInfo } = this.state
const { launchObj } = this.state
const bg = require('./img/discountGroup/bg_s.png')
const bg1 = require('./img/discountGroup/bg_s1.png')
const bg2 = require('./img/discountGroup/bg_s2.png')
const bged = require('./img/discountGroup/bg_sed.png')
const bged1 = require('./img/discountGroup/bg_sed1.png')
const bged2 = require('./img/discountGroup/bg_sed2.png')
const { eId } = this.$router.params
const { eName } = this.$router.params
return (
{
launchObj.status === 3
&&
}
{
launchObj.status === 4
&&
}
{
launchObj.status === 5
&&
}
{
launchObj.status === 6
&&
}
优惠码
{userInfo.phone}-{launchObj.hash}
关闭
去填写意向
{
launchObj.status === 3
&&
}
{
launchObj.status === 4
&&
}
{
launchObj.status === 6
&&
}
)
}
onPopupRef = (ref) => {
this.subPopup = ref
}
render () {
const bg = require('./img/discountGroup/bg_full.jpg')
const bgRule = require('./img/discountGroup/icon_rule.png')
const bg2 = require('./img/discountGroup/share_popup.png')
const bgLine = require('./img/discountGroup/bg_line.png')
const exUser = require('./img/discountGroup/ex_user.png')
const { isSharePopup, launchObj, activityObj, joinArr } = this.state
const cArr = new Array(activityObj.option_req).fill({name: '待助力'})
const joinItems = cArr.map((item, index) => {
let tag = '待助力'
if (joinArr[index] && joinArr[index].id) tag = '已助力'
return (
{tag}
)
})
const { hash } = this.$router.params
const { userInfo, token } = this.state
const uInfo = userInfo || Taro.getStorageSync('APP_userInfo')
const { isLoginPopupShow } = this.state
const { eName } = this.$router.params
const { isGetShow } = this.state
return (
{this.renderGoHome()}
{
uInfo && uInfo.avatarUrl
? token || isLoginPopupShow
? ''
:
:
}
{this.renderRule()}
{hash ? '好友': '我'}的助力
{hash ? `你的好友${launchObj.nickname}想买${eName}` : `领${eName}专属优惠`}
{activityObj.rule}
截止时间:{activityObj.end_at}
查看详细规则
{
hash
?
{
isJoin
?
已助力,去看看这个楼盘
:
帮他助力
}
:
{
joinArr.length === activityObj.option_req
?
:
}
}
好友助力进度{joinArr.length}/{activityObj.option_req}人
{joinItems}
{
isSharePopup
&&
{/* */}
}
{
isGetShow
&&
this.renderGetSuccess()
}
)
}
}
export default Index