discountGroup.jsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. import Taro, { Component } from '@tarojs/taro'
  2. import { View, Image, Text, Navigator } from '@tarojs/components'
  3. import LoginPopup from '@/c/login/Popup'
  4. import PopupAd from './components/discountGroup/popup'
  5. import './discountGroup.scss'
  6. class Index extends Component {
  7. onShareAppMessage() {
  8. const { eId, eName } = this.$router.params
  9. const { launchObj } = this.state
  10. if (launchObj.hash) {
  11. return {
  12. title: `我想参加${eName}的洪楼团购,快来帮我助力下`,
  13. path: `/pagesPlan/discountGroup?eId=${eId}&eName=${eName}&hash=${launchObj.hash}`,
  14. }
  15. } else {
  16. return {
  17. title: '南昌买房,来洪楼领取专属优惠',
  18. path: `/pagesPlan/discountGroup?eId=${eId}`,
  19. }
  20. }
  21. }
  22. onShareTimeline () {
  23. const { eId, eName } = this.$router.params
  24. const { launchObj } = this.state
  25. if (launchObj.hash) {
  26. return {
  27. title: `我想参加${eName}的洪楼团购,快来帮我助力下`,
  28. path: `/pagesPlan/discountGroup?eId=${eId}&eName=${eName}&hash=${launchObj.hash}`,
  29. }
  30. } else {
  31. return {
  32. title: '南昌买房,来洪楼领取专属优惠',
  33. path: `/pagesPlan/discountGroup?eId=${eId}`,
  34. }
  35. }
  36. }
  37. constructor (props) {
  38. super(props)
  39. this.state = {
  40. searchKey: '',
  41. page_size: 10,
  42. page: 1,
  43. isListEnd: false,
  44. isListLoading: false,
  45. isListEmpty: false,
  46. dataList: [],
  47. isRuleShow: false,
  48. isSharePopup: false,
  49. launchObj: {},
  50. joinArr: [],
  51. userInfo: '',
  52. token: '',
  53. isLoginPopupShow: false,
  54. activityObj: {},
  55. isJoin: false,
  56. isGetShow: false,
  57. }
  58. }
  59. config = {
  60. navigationStyle: 'custom',
  61. navigationBarTextStyle: 'white'
  62. }
  63. componentWillMount () {
  64. Taro.$AHU(this)
  65. const { eId, hash } = this.$router.params
  66. if (hash) {
  67. this.getDtl()
  68. } else {
  69. this.getMyDtl()
  70. }
  71. }
  72. getMyDtl () {
  73. const { eId } = this.$router.params
  74. this.setState({
  75. userInfo: Taro.getStorageSync('APP_userInfo') || {},
  76. token: Taro.getStorageSync('APP_token') || ''
  77. })
  78. Taro.api.other.apiactivitybuyinginfo({estate_id: eId}).then(res => {
  79. if (res.launch) {
  80. this.setState({
  81. joinArr: res.join || [],
  82. launchObj: res.launch || {},
  83. activityObj: res.activity || {},
  84. isJoin: res.is_join || false
  85. }, () => {
  86. if (res.launch.status === 3 || res.launch.status === 4 || res.launch.status === 5 || res.launch.status === 6) {
  87. this.openGetPopup()
  88. }
  89. // this.showQrCode()
  90. })
  91. } else {
  92. this.setState({
  93. activityObj: res.activity || {},
  94. isRuleShow: true
  95. })
  96. }
  97. })
  98. }
  99. getDtl () {
  100. this.setState({
  101. userInfo: Taro.getStorageSync('APP_userInfo') || {},
  102. token: Taro.getStorageSync('APP_token') || ''
  103. })
  104. const { hash } = this.$router.params
  105. Taro.api.other.apiactivitybuyinghash({hash}).then(res => {
  106. if (res.launch) {
  107. this.setState({
  108. joinArr: res.join || [],
  109. launchObj: res.launch || {},
  110. activityObj: res.activity || {},
  111. isJoin: res.is_join || false
  112. }, () => {
  113. if (this.subPopup) this.subPopup.getData({poster_img: res.activity.poster_img})
  114. const { joinArr, activityObj } = this.state
  115. if (joinArr.length === activityObj.option_req) {
  116. Taro.$msgConfirm('你的好友已领取团购优惠,看看这个楼盘?', () => {
  117. this.linkHouseDtl()
  118. })
  119. }
  120. })
  121. } else {
  122. Taro.$msgConfirm('没有查到助力数据,看看这个楼盘?', () => {
  123. this.linkHouseDtl()
  124. })
  125. }
  126. })
  127. }
  128. componentDidShow () { }
  129. componentDidHide () { }
  130. renderRule () {
  131. const { isRuleShow, launchObj, activityObj } = this.state
  132. // console.log(activityObj.rule_img)
  133. // const bg = require('./img/discountGroup/ex_rule.png')
  134. const bgClose = require('@img/icon_g_close2.png')
  135. return (
  136. <View className={isRuleShow ? 'l-modal-box' : 'l-modal-box hide'}>
  137. <View className='lmb-bg'></View>
  138. <View className='lmb-body'>
  139. <View className="scoped-rule">
  140. <Image src={activityObj.rule_img} className="bg" />
  141. <View className="ops">
  142. <View className="op t2" onClick={this.backPrevPage.bind(this)}>返回上一页</View>
  143. {
  144. launchObj.id
  145. ?
  146. <View className="op" onClick={this.closeRulePopup.bind(this)}>我知道了</View>
  147. :
  148. <View className="op" onClick={this.toHelpMe.bind(this)}>我已阅读,发起助力</View>
  149. }
  150. </View>
  151. {
  152. launchObj.id
  153. ?
  154. <Image src={bgClose} className="close" onClick={this.closeRulePopup.bind(this)} />
  155. :
  156. <Image src={bgClose} className="close" onClick={this.backPrevPage.bind(this)} />
  157. }
  158. </View>
  159. </View>
  160. </View>
  161. )
  162. }
  163. backPrevPage () {
  164. let pages = getCurrentPages()
  165. if (pages.length < 2) {
  166. Taro.reLaunch({
  167. url: '/pages/index/index'
  168. })
  169. } else {
  170. Taro.navigateBack({
  171. delta: 1
  172. })
  173. }
  174. }
  175. toHelpMe () {
  176. const { eId } = this.$router.params
  177. Taro.api.other.apiactivitybuyinglaunch({estate_id: eId}).then(res => {
  178. this.setState({
  179. launchObj: res || {},
  180. isRuleShow: false,
  181. isSharePopup: true,
  182. })
  183. })
  184. }
  185. dealPopup (str) {
  186. const { bc } = this.props
  187. const { formObj } = this.state
  188. if (bc) {
  189. if (str === 'confirm') {
  190. bc('confirm', formObj)
  191. } else {
  192. bc()
  193. }
  194. }
  195. }
  196. openRulePopup () {
  197. this.setState({
  198. isRuleShow: true
  199. })
  200. }
  201. closeRulePopup () {
  202. this.setState({
  203. isRuleShow: false
  204. })
  205. }
  206. closeSharePopup () {
  207. this.setState({
  208. isRuleShow: false,
  209. isSharePopup: false
  210. }, () => {
  211. this.getMyDtl()
  212. })
  213. }
  214. helpHandle () {
  215. const { hash } = this.$router.params
  216. Taro.api.other.apiactivitybuyingjoin({hash}).then(res => {
  217. Taro.$msgConfirm('助力成功', () => {
  218. this.linkHouseDtl()
  219. }, () => {
  220. this.linkHouseDtl()
  221. })
  222. })
  223. }
  224. getUserProfile (e) {
  225. wx.getUserProfile({
  226. desc: '用于完善头像和昵称资料',
  227. success: (res) => {
  228. const dtlObj = res || {}
  229. this.setState({
  230. userInfo: dtlObj.userInfo
  231. })
  232. Taro.setStorageSync('APP_userInfo', dtlObj.userInfo)
  233. }
  234. })
  235. }
  236. openLoginPopup (obj) {
  237. this.setState({
  238. isLoginPopupShow: true
  239. })
  240. }
  241. closeLoginPopup (str) {
  242. this.setState({
  243. isLoginPopupShow: false
  244. })
  245. if (str && str === 'success') {
  246. this.getDtl()
  247. }
  248. }
  249. linkHome () {
  250. Taro.reLaunch({
  251. url: '/pages/index/index'
  252. })
  253. }
  254. renderGoHome () {
  255. const icon = require('@img/images/icon_go_home.png')
  256. return (
  257. <Image className="g-go-home" src={icon} onClick={this.linkHome.bind(this)}/>
  258. )
  259. }
  260. linkHouseDtl () {
  261. const { eId } = this.$router.params
  262. Taro.navigateTo({
  263. url: `/pagesHouse/indexDtl?id=${eId}`
  264. })
  265. }
  266. showQrCode () {
  267. const { userInfo } = this.state
  268. const { joinArr, activityObj, launchObj } = this.state
  269. if (joinArr.length === activityObj.option_req) {
  270. Taro.$msgConfirm(`恭喜您,获得团购优惠~优惠码:${userInfo.phone}-${launchObj.hash}`)
  271. }
  272. }
  273. openGetPopup () {
  274. this.setState({
  275. isGetShow: true
  276. })
  277. }
  278. closeGetPopup () {
  279. this.setState({
  280. isGetShow: false
  281. })
  282. }
  283. renderGetSuccess () {
  284. const { userInfo } = this.state
  285. const { launchObj } = this.state
  286. const bg = require('./img/discountGroup/bg_s.png')
  287. const bg1 = require('./img/discountGroup/bg_s1.png')
  288. const bg2 = require('./img/discountGroup/bg_s2.png')
  289. const bged = require('./img/discountGroup/bg_sed.png')
  290. const bged1 = require('./img/discountGroup/bg_sed1.png')
  291. const bged2 = require('./img/discountGroup/bg_sed2.png')
  292. const { eId } = this.$router.params
  293. const { eName } = this.$router.params
  294. return (
  295. <View className="get-success">
  296. <View className="bg"></View>
  297. {
  298. launchObj.status === 3
  299. &&
  300. <Image src={bg1} className="bgImg" />
  301. }
  302. {
  303. launchObj.status === 4
  304. &&
  305. <Image src={bg2} className="bgImg" />
  306. }
  307. {
  308. launchObj.status === 5
  309. &&
  310. <Image src={bg} className="bgImg" />
  311. }
  312. {
  313. launchObj.status === 6
  314. &&
  315. <Image src={bg} className="bgImg" />
  316. }
  317. <View className="gs-wrap">
  318. <View className={launchObj.status === 5 ? 'gs-code' : 'gs-code t2'}>
  319. <View className="p1">优惠码</View>
  320. <View className="p2">{userInfo.phone}-{launchObj.hash}</View>
  321. </View>
  322. <View className="gs-footer">
  323. <View className="b t2" onClick={this.closeGetPopup.bind(this)}>关闭</View>
  324. <Navigator url={`/pagesPlan/apply2?eId=${eId}&eName=${eName}`} className="b">去填写意向</Navigator>
  325. </View>
  326. {
  327. launchObj.status === 3
  328. &&
  329. <Image src={bged1} className="gs-ed" />
  330. }
  331. {
  332. launchObj.status === 4
  333. &&
  334. <Image src={bged2} className="gs-ed" />
  335. }
  336. {
  337. launchObj.status === 6
  338. &&
  339. <Image src={bged} className="gs-ed" />
  340. }
  341. </View>
  342. </View>
  343. )
  344. }
  345. onPopupRef = (ref) => {
  346. this.subPopup = ref
  347. }
  348. render () {
  349. const bg = require('./img/discountGroup/bg_full.jpg')
  350. const bgRule = require('./img/discountGroup/icon_rule.png')
  351. const bg2 = require('./img/discountGroup/share_popup.png')
  352. const bgLine = require('./img/discountGroup/bg_line.png')
  353. const exUser = require('./img/discountGroup/ex_user.png')
  354. const { isSharePopup, launchObj, activityObj, joinArr } = this.state
  355. const cArr = new Array(activityObj.option_req).fill({name: '待助力'})
  356. const joinItems = cArr.map((item, index) => {
  357. let tag = '待助力'
  358. if (joinArr[index] && joinArr[index].id) tag = '已助力'
  359. return (
  360. <View className={tag === '已助力' ? 'dgs-item t2' : 'dgs-item'} key={index}>
  361. <View className="dgs-img">
  362. <Image src={tag === '已助力' ? joinArr[index].avatar : exUser} className="img" />
  363. </View>
  364. <View className="dgs-text">{tag}</View>
  365. </View>
  366. )
  367. })
  368. const { hash } = this.$router.params
  369. const { userInfo, token } = this.state
  370. const uInfo = userInfo || Taro.getStorageSync('APP_userInfo')
  371. const { isLoginPopupShow } = this.state
  372. const { eName } = this.$router.params
  373. const { isGetShow } = this.state
  374. return (
  375. <View className="l-box">
  376. <PopupAd onRef={this.onPopupRef} />
  377. {this.renderGoHome()}
  378. {
  379. uInfo && uInfo.avatarUrl
  380. ? token || isLoginPopupShow
  381. ? ''
  382. : <Button className="g-u-btn" onClick={this.openLoginPopup.bind(this)}></Button>
  383. : <Button className="g-u-btn" onClick={this.getUserProfile.bind(this)}></Button>
  384. }
  385. <LoginPopup show={isLoginPopupShow} close={this.closeLoginPopup.bind(this)} />
  386. {this.renderRule()}
  387. <View className="discount-group">
  388. <Image src={bg} className="dg-bg" />
  389. <Image src={bgRule} className="dg-rule-btn" onClick={this.openRulePopup.bind(this)} />
  390. <View className="dg-wrap">
  391. <View className="dg-top">
  392. <View className="dgt-img">
  393. <Image src={launchObj.avatar || exUser} className="img" />
  394. </View>
  395. <View className="dgt-text">{hash ? '好友': '我'}的助力</View>
  396. </View>
  397. <View className="dg-info">
  398. <View className="p1">{hash ? `你的好友${launchObj.nickname}想买${eName}` : `领${eName}专属优惠`}</View>
  399. <View className="p2">{activityObj.rule}</View>
  400. <View className="p3">截止时间:{activityObj.end_at}</View>
  401. <View className="p4" onClick={this.openRulePopup.bind(this)}>查看详细规则</View>
  402. </View>
  403. {
  404. hash
  405. ?
  406. <View className="dg-btn">
  407. {
  408. isJoin
  409. ?
  410. <View className="text" onClick={this.linkHouseDtl.bind(this)}>已助力,去看看这个楼盘</View>
  411. :
  412. <View className="text" onClick={this.helpHandle.bind(this)}>帮他助力</View>
  413. }
  414. </View>
  415. :
  416. <View className="dg-btn">
  417. {
  418. joinArr.length === activityObj.option_req
  419. ?
  420. <Button className="text" onClick={this.openGetPopup.bind(this)}>恭喜您,助力成功,查看凭证</Button>
  421. :
  422. <Button className="text btn-to-div" openType="share">喊好友助力</Button>
  423. }
  424. </View>
  425. }
  426. <View className="dg-share">
  427. <View className="dgs-header">
  428. <Image className="bg" src={bgLine} />
  429. <View className="t">好友助力进度{joinArr.length}/{activityObj.option_req}人</View>
  430. </View>
  431. <View className="dgs-content">
  432. {joinItems}
  433. </View>
  434. </View>
  435. </View>
  436. {
  437. isSharePopup
  438. &&
  439. <View className="dg-popup">
  440. <View className="bg"></View>
  441. <Image src={bg2} className="img" />
  442. {/* <Button className="yes btn-to-div" openType="share"></Button> */}
  443. <View className="no" onClick={this.closeSharePopup.bind(this)}></View>
  444. </View>
  445. }
  446. {
  447. isGetShow
  448. &&
  449. this.renderGetSuccess()
  450. }
  451. </View>
  452. </View>
  453. )
  454. }
  455. }
  456. export default Index