index.js 5.51 KB
Newer Older
zhanghaozhe committed
1 2 3
import React, { Component } from 'react'
import { VList } from '../../common'
import { Tabs, WhiteSpace, Toast } from 'antd-mobile'
xuzhenghua committed
4
import './index.scss'
xuzhenghua committed
5
import HeaderSearch from '../../common/HeaderSearch/index'
zhanghaozhe committed
6
import { http } from "@/utils"
xuzhenghua committed
7
import Loading from '@/common/Loading'
zhanghaozhe committed
8
import { connect } from 'react-redux';
xuzhenghua committed
9

10
@connect(({user}) => ({
zhanghaozhe committed
11
  user,
12
}))
xuzhenghua committed
13
class Preferential extends Component {
zhanghaozhe committed
14 15 16 17 18 19
  constructor(props) {
    super(props)
    this.state = {
      dataList: [],
      courseStatus: 0,
      isLoading: true,
xuzhenghua committed
20
    }
zhanghaozhe committed
21
  }
xuzhenghua committed
22

zhanghaozhe committed
23 24 25
  componentDidMount() {
    this.specialSale()
  }
xuzhenghua committed
26

zhanghaozhe committed
27 28 29 30 31 32 33
  // 限时特惠
  specialSale = () => {
    http.get(`${API.home}/m/home/weekDiscounts`).then((res) => {
      if (res.data.code === 200) {
        this.setState({
          dataList: res.data.data,
          isLoading: false,
xuzhenghua committed
34
        })
zhanghaozhe committed
35 36 37 38 39 40 41 42 43 44 45 46 47
      } else {
        Toast.info(res.data.msg, 2)
      }

    })
  }
  // 砍价专区
  bargain = () => {
    http.get(`${API.home}/m/home/bargainZone`).then((res) => {
      if (res.data.code === 200) {
        this.setState({
          dataList: JSON.stringify(res.data.data) == '{}' ? [] : res.data.data,
          isLoading: false,
xuzhenghua committed
48
        })
zhanghaozhe committed
49 50 51 52 53 54 55 56 57
      } else {
        Toast.info(res.data.msg, 2)
      }
    })
  }
  // 一键拼团
  group = () => {
    http.get(`${API.home}/m/home/grouponList`).then((res) => {
      if (res.data.code === 200) {
58
        this.setState({
zhanghaozhe committed
59 60
          dataList: res.data.data,
          isLoading: false,
61
        })
zhanghaozhe committed
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
      } else {
        Toast.info(res.data.msg, 2)
      }
    })
  }
  // tab 切换
  ontabclick = (tab, index) => {
    this.setState({
      courseStatus: index,
      isLoading: true,
    })
    switch (index) {
      case 0:
        this.specialSale()
        break
      case 1:
        this.bargain()
        break
      default:
        this.group()
xuzhenghua committed
82
    }
zhanghaozhe committed
83
  }
xuzhenghua committed
84

zhanghaozhe committed
85 86 87 88 89 90
  toCourseDetail = (id) => {
    const {dispatch, history} = this.props;
    // dispatch(getCourses(id, () => {
    history.push(`/detail?id=${id}`)
    // }));
  }
xuzhenghua committed
91

zhanghaozhe committed
92 93 94 95 96 97 98 99 100 101 102 103 104 105
  render() {
    const tabs = [
      {title: '限时特惠'},
      {title: '砍价专区'},
      {title: '一键拼团'},
    ]
    const {user = {}} = this.props;
    let isLogin = user.data && user.data.uid ? true : false;
    return (
      <div className='preferential'>
        <HeaderSearch isLogin={isLogin}/>
        <Loading isLoading={this.state.isLoading}>
          <div className='class-content'>
            <WhiteSpace/>
xuzhenghua committed
106

zhanghaozhe committed
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
            <Tabs
              tabs={tabs}
              animated={false}
              onChange={(tab, index) => this.ontabclick(tab, index)}
              swipeable={false}
              page={this.state.courseStatus}
              renderTabBar={props => <div className={'custom-tab-bar'}>
                <Tabs.DefaultTabBar {...props}/>
              </div>}
            >
            </Tabs>
            <div className='tabs'>
              {
                this.state.dataList.length > 0 ?
                  <ul>
                    {this.state.dataList.map((item, index) => {
                      const Info = (
                        <div className="info">
                          <p className='title'
                             onClick={() => this.toCourseDetail(item.course_id)}>
                            {/* <Link to={`/detail?id=${item.course_id}`}> */}
                            {item.course_title}
                            {/* </Link> */}
                          </p>
                          <p className='contact text-overflow-2'>{item.course_desc}</p>
                          <div className='des'>
                            {!item.is_buy &&
                            <p className="course-price">
                              {this.state.courseStatus === 0 &&
                              <span className='price'>特惠价:</span>
                              }
                              <span className="new">¥{item.price1}</span>
                              <span className="old">¥{item.price0}</span>
                            </p>
xuzhenghua committed
141
                            }
zhanghaozhe committed
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
                            {item.is_buy &&
                            <a className="isbuy">已购买</a>
                            }
                          </div>
                        </div>
                      )
                      const status = (
                        !item.is_buy &&
                        <div>
                          {this.state.courseStatus === 1 &&
                          <p className='course-status'>砍价减{item.bargain_price}</p>
                          }
                          {this.state.courseStatus === 2 &&
                          <p className='course-status'>拼团价{item.price}</p>
                          }
                          {
                            item.is_aist && <span className='return_cash'></span>
                          }
160
                        </div>
zhanghaozhe committed
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
                      )
                      return (
                        <VList
                          key={index}
                          img={item.image_name}
                          id={item.course_id}
                          status={status}
                          info={Info}
                          toDetail={this.toCourseDetail}
                        />
                      )
                    })}
                  </ul> : <div className={'notdata'}>特惠课程都去参加活动了,可以去活动页看看哦~</div>
              }

xuzhenghua committed
176
            </div>
zhanghaozhe committed
177 178 179 180 181 182
            <WhiteSpace/>
          </div>
        </Loading>
      </div>
    )
  }
xuzhenghua committed
183 184 185

}

186
export default Preferential;