Drew 6 years ago
parent
commit
0dfe49548d

+ 2 - 1
.prettierrc

@@ -1,3 +1,4 @@
 {
-  "singleQuote": true
+  "singleQuote": true,
+  "printWidth": 1000
 }

+ 11 - 2
.vscode/settings.json

@@ -1,5 +1,14 @@
 {
     "vetur.validation.script": false,
     "vetur.validation.style": false,
-    "vetur.validation.template": false
-}
+    "vetur.validation.template": false,
+    "vetur.format.defaultFormatterOptions": {
+        "js-beautify-html": {
+            "wrap_line_length": "1000",
+            "wrap-attributes": "preserve"
+        },
+        "prettyhtml": {
+            "printWidth": 1000
+        }
+    }
+}

+ 8 - 11
src/app.wpy

@@ -5,13 +5,8 @@
 <script>
 import wepy from 'wepy';
 import 'wepy-async-function';
-import {
-    getLocation,
-    getCity,
-    getCityId,
-    fetchLogin,
-    fetchUserInfo
-} from './utils/api.js';
+import { getLocation, getCity, getCityId } from './utils/api.js';
+import http from './utils/http.js';
 /* import fundebug from 'fundebug-wxjs'
 fundebug.init({
     apikey : '1b560844f6fbca8514dceaba8be9494df4a51a4cf8966a86b2c525074b78932b'
@@ -113,7 +108,7 @@ export default class extends wepy.app {
         let token = this.globalData.token;
 
         let userLogin = async params => {
-            await fetchUserInfo()
+            http.get('/user/my')
                 .then(user => {
                     wx.hideLoading();
                     this.globalData.userInfo = user;
@@ -124,7 +119,7 @@ export default class extends wepy.app {
                     this.observable.emit('login');
                 })
                 .catch(err => {
-                    console.log('登录接口异常fetchUserInfo:', err);
+                    console.log('登录接口异常:', err);
                     wx.showToast({
                         title: '获取信息失败,请检查你的网络设置',
                         icon: 'none',
@@ -154,10 +149,11 @@ export default class extends wepy.app {
                 })
                 .then(res => {
                     console.log('wx code::', res.code);
-                    return fetchLogin({ code: res.code });
+                    return http.post('/auth/maLogin', { code: res.code });
                 })
                 .then(res => {
                     this.globalData.token = token = res;
+                    http.setToken(res);
                     userLogin();
                 })
                 .catch(err => {
@@ -247,7 +243,8 @@ export default class extends wepy.app {
             datRes = await getCityId({ city: data.result.ad_info.city });
             this.globalData.location.current_city = {
                 ...res,
-                ...datRes
+                ...datRes,
+                city: datRes.regionName
             };
             this.globalData.locateFail = false;
 

+ 252 - 256
src/pages/cinemas/cinemas.wpy

@@ -8,7 +8,7 @@
         <view class="weui-navbar navbarIndex">
             <!-- City -->
             <view class="citySelection" @tap="clickNav">
-                <b>{{nav[0]}}<icon type="triangle"/></b>
+                <b>{{nav[0]}}<icon type="triangle" /></b>
             </view>
 
             <view wx:for="{{tabs}}" wx:key="{{key}}" id="{{index}}"
@@ -17,93 +17,96 @@
                 <view class="weui-navbar__title">{{item}}</view>
             </view>
             <!-- RegionsBar -->
-            <view wx:if="{{activeIndex==1 && !!regions[1]}}" class="thisShell {{onMore?'onMore':''}}">
-                <view wx:if="{{regions.length>4}}" class="more-cities"><b @tap.stop="bindMore">更多</b><i class="ico_arr"/></view>
-                <scroll-view
-                    scroll-x
-                    scroll-y
-                    scroll-left="{{scrollLeft}}"
-                    scroll-with-animation="{{scrollAnim}}"
-                    class="weui-navbar_">
-                    <view class="scrollHack"/>
-                    <view
-                        wx:for="{{regions}}"
-                        wx:key="{{key}}"
-                        id="{{index}}"
+            <view wx:if="{{activeIndex==1 && !!regions[1]}}"
+                class="thisShell {{onMore?'onMore':''}}">
+                <view wx:if="{{regions.length>4}}" class="more-cities"><b
+                        @tap.stop="bindMore">更多</b><i class="ico_arr" /></view>
+                <scroll-view scroll-x scroll-y scroll-left="{{scrollLeft}}"
+                    scroll-with-animation="{{scrollAnim}}" class="weui-navbar_">
+                    <view class="scrollHack" />
+                    <view wx:for="{{regions}}" wx:key="{{key}}" id="{{index}}"
                         data-curCity="{{!!(item.id == curCity.id)}}"
                         class="weui-navbar__item_ {{activeIndex_ == index ? 'weui-bar__item_on_' : ''}}"
                         @tap="tabClick_">
                         <view class="weui-navbar__title_">{{item}}</view>
                     </view>
-                    <view class="scrollHack"/>
+                    <view class="scrollHack" />
                 </scroll-view>
-                <view class="mask"/>
+                <view class="mask" />
+            </view>
+            <view class="weui-navbar__slider"
+                style="left: {{sliderLeft}}px; transform: translateX({{sliderOffset}}px); -webkit-transform: translateX({{sliderOffset}}px);">
             </view>
-            <view class="weui-navbar__slider" style="left: {{sliderLeft}}px; transform: translateX({{sliderOffset}}px); -webkit-transform: translateX({{sliderOffset}}px);"></view>
         </view>
         <view class="weui-tab__content">
             <view wx:if="{{!!locateFail}}" class="blackMargin">
-                <icon type="ico-Empty2" class=""/>
-                <button
-                    @tap="goToSelectCity"
-                    type="default" plain size="mini"
+                <icon type="ico-Empty2" class="" />
+                <button @tap="goToSelectCity" type="default" plain size="mini"
                     class="select_city">定位失败,请手动选择城市</button>
             </view>
             <!-- 电影列表 -->
-            <scroll-view
-                hidden="{{activeIndex != 0}}"
-                scroll-y
-                scroll-with-animation
-                enable-back-to-top="true"
-                scroll-top="{{scrollTop}}"
-                bindscrolltolower="lower"
-                style="height:92vh"
-                class="cinemas__list__wrapper">
-                <view wx:if="{{!!DataMovies && (DataMovies.subjects.length == 0)}}" class="blackMargin">
-                    <icon type="ico-Empty2" class=""/>
+            <scroll-view hidden="{{activeIndex != 0}}" scroll-y
+                scroll-with-animation enable-back-to-top="true"
+                scroll-top="{{scrollTop}}" bindscrolltolower="lower"
+                style="height:92vh" class="cinemas__list__wrapper">
+                <view
+                    wx:if="{{!!DataMovies && (DataMovies.subjects.length == 0)}}"
+                    class="blackMargin">
+                    <icon type="ico-Empty2" class="" />
                     <view>没有符合条件的影片</view>
                 </view>
 
-                <ul wx:if="{{!!DataMovies.subjects.length}}" class="movies__list" @tap="goToitem">
+                <ul wx:if="{{!!DataMovies.subjects.length}}"
+                    class="movies__list" @tap="goToitem">
                     <li wx:for="{{DataMovies.subjects}}" wx:key="index"
                         class="movies__list__item"
-                        data-subject_id="{{item.subject_id}}"
-                        >
+                        data-subject_id="{{item.subject_id}}">
                         <view class="movieInfo">
-                            <image class="movieInfo__poster" src="{{item.pic}}" mode="widthFix" lazy-load="true"/>
+                            <image class="movieInfo__poster"
+                                src="{{item.poster}}" mode="widthFix"
+                                lazy-load="true" />
                             <view class="movieInfo__detail">
-                                <h2 class="movieInfo__name">{{item.title}}</h2>
-                                <view wx:if="{{!!item.title_en}}" class="movieInfo__title_en">{{item.title_en}}</view>
-                                <view wx:if="{{!!item.director}}" class="movieInfo__p">导演:{{item.director}}</view>
-                                <view wx:if="{{!!item.actors.length}}" class="movieInfo__p">主演:<text wx:for="{{item.actors}}" wx:key="index">{{item}}</text></view>
+                                <h2 class="movieInfo__name">{{item.showName}}
+                                </h2>
+                                <view wx:if="{{!!item.showNameEn}}"
+                                    class="movieInfo__title_en">{{
+                                        item.showNameEn}}</view>
+                                <view wx:if="{{!!item.director}}"
+                                    class="movieInfo__p">导演:{{item.director}}
+                                </view>
+                                <view wx:if="{{!!item.leadingRole}}"
+                                    class="movieInfo__p">主演:{{item.leadingRole}}
+                                </view>
                             </view>
                             <view class="rightSidebar">
-                                <button size="mini">{{conpon_kind=='4' ? '购票' : '兑换'}}</button>
+                                <button
+                                    size="mini">{{coupon_type=='COUPON' ? '购票' : '兑换'}}</button>
                             </view>
                         </view>
                     </li>
                 </ul>
-                <view  wx:if="{{!!DataMovies.subjects.length}}" class="weui-loadmore weui-loadmore_line">
-                    <view class="weui-loadmore__tips weui-loadmore__tips_in-line">已经到底了</view>
+                <view wx:if="{{!!DataMovies.subjects.length}}"
+                    class="weui-loadmore weui-loadmore_line">
+                    <view
+                        class="weui-loadmore__tips weui-loadmore__tips_in-line">
+                        已经到底了</view>
                 </view>
             </scroll-view>
             <!-- 影院列表 -->
             <!-- style="{{!!onlyCinem ? 'height:82vh;'{{!!regions[1] ? 'top:130rpx' : ''}};" -->
-            <scroll-view
-                hidden="{{activeIndex != 1}}"
-                scroll-y
-                scroll-with-animation
-                enable-back-to-top="true"
-                scroll-top="{{scrollTop}}"
-                bindscrolltolower="lower"
+            <scroll-view hidden="{{activeIndex != 1}}" scroll-y
+                scroll-with-animation enable-back-to-top="true"
+                scroll-top="{{scrollTop}}" bindscrolltolower="lower"
                 style="{{!!onlyCinem ? 'height:92vh;' : 'height:82vh;top:130rpx'}};"
                 class="cinemas__list__wrapper">
-                <view wx:if="{{!!Data && (Data.cinemas.length == 0)}}" class="blackMargin">
-                    <icon type="ico-Empty2" class=""/>
+                <view wx:if="{{!!Data && (Data.cinemas.length == 0)}}"
+                    class="blackMargin">
+                    <icon type="ico-Empty2" class="" />
                     <view>没有符合条件的影院</view>
                 </view>
 
-                <ul wx:if="{{Data.cinemas.length > 0}}" @tap="goToitem" class="cinemas__list">
+                <ul wx:if="{{Data.cinemas.length > 0}}" @tap="goToitem"
+                    class="cinemas__list">
                     <li wx:for="{{Data.cinemas}}" wx:key="index"
                         class="cinemas__list__item"
                         data-cinema_id="{{item.cinema_id}}">
@@ -114,30 +117,30 @@
                         <div class="item__text">{{item.distance}}</div>
                     </li>
                 </ul>
-                <view wx:if="{{!!isMax && !!Data}}" class="weui-loadmore weui-loadmore_line">
-                    <view class="weui-loadmore__tips weui-loadmore__tips_in-line">已经到底了</view>
+                <view wx:if="{{!!isMax && !!Data}}"
+                    class="weui-loadmore weui-loadmore_line">
+                    <view
+                        class="weui-loadmore__tips weui-loadmore__tips_in-line">
+                        已经到底了</view>
                 </view>
             </scroll-view>
         </view>
         <!-- 筛选点击其他区域消失浮层 -->
-        <div
-            wx:if="{{onMore}}"
-            class="y-page__Wrapper"
-            @tap.stop="handleClickScroller"/>
+        <div wx:if="{{onMore}}" class="y-page__Wrapper"
+            @tap.stop="handleClickScroller" />
     </view>
 </template>
 <script>
-import wepy from 'wepy'
-import { fetchMovies, fetchCinemas } from '../../utils/api.js'
+import wepy from 'wepy';
+import { fetchMovies, fetchCinemas } from '../../utils/api.js';
 
 export default class Cinemas extends wepy.page {
     config = {
         navigationBarTitleText: '选择影院'
     };
-    components = {
-    };
+    components = {};
     data = {
-        conpon_kind: 0,
+        coupon_type: 0,
         onlyCinem: false,
         tabs: ['影片', '影院'],
         activeIndex: 0,
@@ -175,160 +178,163 @@ export default class Cinemas extends wepy.page {
 
     methods = {
         async tabClick(e) {
-            this.sliderOffset = e.currentTarget.offsetLeft
-            this.activeIndex = e.currentTarget.id
-            if(e.currentTarget.id==0){
-                    await this.fetchDataMovies('show')
-                }else{
-                    let start = this.start,
+            this.sliderOffset = e.currentTarget.offsetLeft;
+            this.activeIndex = e.currentTarget.id;
+            if (e.currentTarget.id == 0) {
+                await this.fetchDataMovies('show');
+            } else {
+                let start = this.start,
                     limit = this.limit,
-                    total = this.total
-                    await this.fetchData(start, limit, 'show')
+                    total = this.total;
+                await this.fetchData(start, limit, 'show');
             }
         },
-        clickNav (e){
-            if(e.target.id == 0){
-                this.curStatus = 0
-                this.cinemas__nav__item = 'cinemas__nav__item'
+        clickNav(e) {
+            if (e.target.id == 0) {
+                this.curStatus = 0;
+                this.cinemas__nav__item = 'cinemas__nav__item';
 
-                this.methods.goToSelectCity.call(this)
-                this.$apply()
+                this.methods.goToSelectCity.call(this);
+                this.$apply();
             }
         },
-        bindMore(){
-            this.onMore = !this.onMore
+        bindMore() {
+            this.onMore = !this.onMore;
             // this.forbiddenScroll = !this.forbiddenScroll
-            if(!!this.onMore){
-                this.scrollAnim = false
-                this.scrollLeft = this.scrollLeft - 0.1
-            } else{
-                this.scrollAnim = true
-                this.scrollLeft = this.scrollLeft + 0.1
+            if (!!this.onMore) {
+                this.scrollAnim = false;
+                this.scrollLeft = this.scrollLeft - 0.1;
+            } else {
+                this.scrollAnim = true;
+                this.scrollLeft = this.scrollLeft + 0.1;
             }
-            this.$apply()
+            this.$apply();
         },
         async tabClick_(e) {
             // 点击更多入口
-            if(this.onMore){
-                this.onMore=!this.onMore
+            if (this.onMore) {
+                this.onMore = !this.onMore;
                 setTimeout(() => {
                     wx.createSelectorQuery()
                         .select('.weui-bar__item_on_')
-                        .boundingClientRect((rect)=>{
+                        .boundingClientRect(rect => {
                             let left = rect.left,
-                                left_ = left<-2 ? -2 : left
-                            let scrollLeft = left_ - (this.windowWidth/2-75 || 116.5)
-                            this.scrollLeft = scrollLeft<-2 ? 0 : scrollLeft
-                            this.$apply()
-                    }).exec()
-                }, 200)
-
-            } else{
+                                left_ = left < -2 ? -2 : left;
+                            let scrollLeft = left_ - (this.windowWidth / 2 - 75 || 116.5);
+                            this.scrollLeft = scrollLeft < -2 ? 0 : scrollLeft;
+                            this.$apply();
+                        })
+                        .exec();
+                }, 200);
+            } else {
                 let left = e.currentTarget.offsetLeft,
-                    left_ = left<-2 ? -2 : left
-                let scrollLeft = left_ - (this.windowWidth/2-75 || 116.5)
-                this.scrollLeft = scrollLeft<-2 ? 0 : scrollLeft
+                    left_ = left < -2 ? -2 : left;
+                let scrollLeft = left_ - (this.windowWidth / 2 - 75 || 116.5);
+                this.scrollLeft = scrollLeft < -2 ? 0 : scrollLeft;
             }
-            this.activeIndex_ = e.currentTarget.id
-            
-            let id = e.currentTarget.id
-            this.region = id==0 ? '' : this.regions[id]
-            this.start = 0
-            console.log('region::',this.region)
+            this.activeIndex_ = e.currentTarget.id;
+
+            let id = e.currentTarget.id;
+            this.region = id == 0 ? '' : this.regions[id];
+            this.start = 0;
+            console.log('region::', this.region);
             let queryData = {
                 batch_id: this.batch_id,
                 subject_id: this.subject_id,
-                region: id==0 ? '' : this.regions[id],
+                region: id == 0 ? '' : this.regions[id],
                 start: 0,
                 limit: 20,
                 ...this.loc
+            };
+            let fetchData = await fetchCinemas(queryData);
+            this.total = fetchData.data.total;
+
+            console.log(queryData.limit, queryData.start, this.total, queryData.limit + queryData.start <= this.total);
+            if (queryData.limit + queryData.start <= this.total) {
+                this.isMax = false;
+            } else {
+                this.isMax = true;
             }
-            let fetchData = await fetchCinemas(queryData)
-                this.total = fetchData.data.total
 
-                console.log(
-                    queryData.limit,queryData.start,this.total,
-                    queryData.limit + queryData.start <= this.total
-                )
-            if(queryData.limit + queryData.start <= this.total){
-                this.isMax = false
-            } else{
-                this.isMax = true
-            }
-            
-            this.Data.cinemas = fetchData.data.cinemas
+            this.Data.cinemas = fetchData.data.cinemas;
             // this.fetchData(0, 20)
-            this.$apply()
+            this.$apply();
         },
         // 点击其它区域隐藏
         handleClickScroller() {
-            this.onMore = false
+            this.onMore = false;
             // if (this.curStatus == 0) return;
             // this.curStatus = 0
             // this.cinemas__nav__item = 'cinemas__nav__item'
         },
-        goToSelectCity(){
-            let batch_id = this.batch_id
-            let url = `/pages/locoation/locoation?batch_id=${batch_id}&loc=choose`
+        goToSelectCity() {
+            let batch_id = this.batch_id;
+            let url = `/pages/locoation/locoation?batch_id=${batch_id}&loc=choose`;
             wx.navigateTo({
                 url
             });
         },
         goToitem(e) {
-            let batch_id = this.batch_id
-            let cinema_id = !!e.target.dataset.cinema_id ? e.target.dataset.cinema_id : ''
-            let subject_id = !!e.target.dataset.subject_id ? `&subject_id=${e.target.dataset.subject_id}` : ''
+            let batch_id = this.batch_id;
+            let cinema_id = !!e.target.dataset.cinema_id ? e.target.dataset.cinema_id : '';
+            let subject_id = !!e.target.dataset.subject_id ? `&subject_id=${e.target.dataset.subject_id}` : '';
 
-            let subject_id_ = !!this.subject_id ? `&subject_id=${this.subject_id}` : ''
-            let conpon_kind = !!this.conpon_kind ? `&conpon_kind=${this.conpon_kind}` : ''
+            let subject_id_ = !!this.subject_id ? `&subject_id=${this.subject_id}` : '';
+            let coupon_type = !!this.coupon_type ? `&coupon_type=${this.coupon_type}` : '';
 
-            let usable_num = this.usable_num
-            let subjectOnly = !!this.subject_id ? `&subjectOnly=0` : 's'
-            let urlMovie = `/pages/moviedetails/moviedetails?batch_id=${batch_id}${conpon_kind}${subject_id}&subject_info=1&usable_num=${usable_num}`
-            let urlCinema = `/pages/session/session?batch_id=${batch_id}${conpon_kind}&cinema_id=${cinema_id}${subject_id_}&usable_num=${usable_num}${subjectOnly}`
-            
-            wx.navigateTo({
-                url: this.activeIndex==1 ? urlCinema : urlMovie
-            })
-        },
-    }
-        // 获取影片列表
-    async fetchDataMovies(show){
+            let usable_num = this.usable_num;
+            let subjectOnly = !!this.subject_id ? `&subjectOnly=0` : 's';
+            let urlMovie = `/pages/moviedetails/moviedetails?batch_id=${batch_id}${coupon_type}${subject_id}&subject_info=1&usable_num=${usable_num}`;
+            let urlCinema = `/pages/session/session?batch_id=${batch_id}${coupon_type}&cinema_id=${cinema_id}${subject_id_}&usable_num=${usable_num}${subjectOnly}`;
 
+            wx.navigateTo({
+                url: this.activeIndex == 1 ? urlCinema : urlMovie
+            });
+        }
+    };
+    // 获取影片列表
+    async fetchDataMovies(show) {
+        console.log(this.$parent.globalData);
         let current_city = this.$parent.globalData.location.current_city,
             choose_city = this.$parent.globalData.location.choose_city,
-            choose_city1 = !!current_city ? {lat:current_city.lat, lng:current_city.lng, ...choose_city} : choose_city
-        let locateFail = this.locateFail
-        this.loc = choose_city ? choose_city1 : current_city
-        this.nav[0] = !!this.loc ? this.loc.city : '城市选择'
-        this.$apply()
-        
-        if(locateFail !=null && !!locateFail){
-            return
+            choose_city1 = !!current_city
+                ? {
+                      lat: current_city.lat,
+                      lng: current_city.lng,
+                      ...choose_city
+                  }
+                : choose_city;
+        let locateFail = this.locateFail;
+        this.loc = choose_city ? choose_city1 : current_city;
+        this.nav[0] = !!this.loc ? this.loc.city : '城市选择';
+        this.$apply();
+
+        if (locateFail != null && !!locateFail) {
+            return;
         }
 
-        let data = {
-            batch_id: this.batch_id,
-            ...this.loc
-        }
-        
-        let fetchData = await fetchMovies(data)
+        let fetchData = await fetchMovies(this.loc.id, this.couponId);
 
-        this.DataMovies = fetchData.data
+        this.DataMovies = { subjects: fetchData };
 
-        this.$apply()
+        this.$apply();
     }
     // 获取影院列表
-    async fetchData(start, limit, show){
-
+    async fetchData(start, limit, show) {
         let current_city = this.$parent.globalData.location.current_city,
             choose_city = this.$parent.globalData.location.choose_city,
-            choose_city1 = !!current_city ? {lat:current_city.lat, lng:current_city.lng, ...choose_city} : choose_city
-        let locateFail = this.locateFail
-        this.loc = choose_city ? choose_city1 : current_city
-        this.nav[0] = !!this.loc ? this.loc.city : '城市选择'
-        if(locateFail !=null && !!locateFail){
-            return
+            choose_city1 = !!current_city
+                ? {
+                      lat: current_city.lat,
+                      lng: current_city.lng,
+                      ...choose_city
+                  }
+                : choose_city;
+        let locateFail = this.locateFail;
+        this.loc = choose_city ? choose_city1 : current_city;
+        this.nav[0] = !!this.loc ? this.loc.city : '城市选择';
+        if (locateFail != null && !!locateFail) {
+            return;
         }
         let data = {
             batch_id: this.batch_id,
@@ -337,133 +343,123 @@ export default class Cinemas extends wepy.page {
             start: start,
             limit: limit,
             ...this.loc
+        };
+        this.$apply();
+        let fetchData = await fetchCinemas(data);
+
+        if (!!this.Data && !show) {
+            this.Data.cinemas = [...this.Data.cinemas, ...fetchData.data.cinemas];
+        } else {
+            this.Data = fetchData.data;
         }
-        this.$apply()
-        let fetchData = await fetchCinemas(data)
-
-        if(!!this.Data && !show){
-            this.Data.cinemas = [
-                ...this.Data.cinemas,
-                ...fetchData.data.cinemas,
-            ]
-        } else{
-            this.Data = fetchData.data
-        }
-        if(!!fetchData.data){
-            this.start = fetchData.data.start
-            this.limit = fetchData.data.limit
-            this.total = fetchData.data.total
+        if (!!fetchData.data) {
+            this.start = fetchData.data.start;
+            this.limit = fetchData.data.limit;
+            this.total = fetchData.data.total;
         }
 
-        this.regions = fetchData.data.regions ? ['不限区域', ...fetchData.data.regions] : ['不限区域']
-        let timestamp = Date.parse(new Date())
-        let expiration = timestamp + 7200000
-        wx.setStorageSync('data_location', this.curCity)
-        wx.setStorageSync('data_location_expiration', expiration)
+        this.regions = fetchData.data.regions ? ['不限区域', ...fetchData.data.regions] : ['不限区域'];
+        let timestamp = Date.parse(new Date());
+        let expiration = timestamp + 7200000;
+        wx.setStorageSync('data_location', this.curCity);
+        wx.setStorageSync('data_location_expiration', expiration);
 
-        this.$apply()
+        this.$apply();
     }
     async onLoad(options) {
-        this.conpon_kind = options.conpon_kind
-        this.batch_id = options.batch_id
-        this.subject_id = options.subject_id
-        this.cinema_id = options.cinema_id
-        this.usable_num = options.usable_num
-
-        let timestamp = Date.parse(new Date())
-        let expiration = wx.getStorageSync('data_location_expiration')
-        let app_data = wx.getStorageSync('data_location')
-
-        if( !!this.subject_id && (this.cinema_id == null || this.cinema_id > 1)){
-            this.onlyCinem = true
-            this.activeIndex = 1
-        } else{
-            this.onlyCinem = false
-            this.activeIndex = 0
+        this.coupon_type = options.coupon_type;
+        this.batch_id = options.batch_id;
+        this.subject_id = options.subject_id;
+        this.cinema_id = options.cinema_id;
+        this.usable_num = options.usable_num;
+
+        let timestamp = Date.parse(new Date());
+        let expiration = wx.getStorageSync('data_location_expiration');
+        let app_data = wx.getStorageSync('data_location');
+
+        if (!!this.subject_id && (this.cinema_id == null || this.cinema_id > 1)) {
+            this.onlyCinem = true;
+            this.activeIndex = 1;
+        } else {
+            this.onlyCinem = false;
+            this.activeIndex = 0;
         }
-        this.$apply()
+        this.$apply();
     }
-    async onShow(){
-        let system = await wepy.getSystemInfo()
-        this.sliderLeft = system.windowWidth / 12
+    async onShow() {
+        let system = await wepy.getSystemInfo();
+        this.sliderLeft = system.windowWidth / 12;
 
-        if(this.$parent.globalData.loc == 'choose' && this.$parent.globalData.From == 'lockoation'){
-            this.region = ''
-            this.start = 0
+        if (this.$parent.globalData.loc == 'choose' && this.$parent.globalData.From == 'lockoation') {
+            this.region = '';
+            this.start = 0;
             // this.nav[1] = '区域选择'
             // this.activeIndex = 1
-            this.$apply()
+            this.$apply();
         }
-        let choose_city = this.$parent.globalData.location.choose_city
+        let choose_city = this.$parent.globalData.location.choose_city;
         let start = this.start,
             limit = this.limit,
-            total = this.total
+            total = this.total;
 
-        let locateFail = this.locateFail = this.$parent.globalData.locateFail
+        let locateFail = (this.locateFail = this.$parent.globalData.locateFail);
 
         // console.log(':::',this.$parent.globalData.locateFail)
         // 由排期页返回时不加载数据
-        if(this.$parent.globalData.From == 'session'){
+        if (this.$parent.globalData.From == 'session') {
             setTimeout(() => {
-                this.$parent.globalData.From = ''
-                console.log(this.$parent.globalData.From )
-                this.$apply()
+                this.$parent.globalData.From = '';
+                console.log(this.$parent.globalData.From);
+                this.$apply();
             }, 500);
         }
-        if(this.$parent.globalData.From != 'session'){
-
+        if (this.$parent.globalData.From != 'session') {
             // 首页入口时-定位失败时
-            if(locateFail !=null){
-                
-                if(this.activeIndex == 0){
-                    this.fetchDataMovies('show')
-                }else{
-                    this.fetchData(start, limit, 'show')
+            if (locateFail != null) {
+                if (this.activeIndex == 0) {
+                    this.fetchDataMovies('show');
+                } else {
+                    this.fetchData(start, limit, 'show');
                 }
-                return
+                return;
             }
             // 首页入口时-定位成功时
             // !!this.$parent.globalData.location.current_city && this.fetchData(start, limit, 'show')
-    
+
             // 非首页入口时
-            this.$parent.observable.on("location",
-                async ()=>{
-                    let locateFail = this.locateFail = await this.$parent.globalData.locateFail
-                    this.$apply()
-                    if(this.activeIndex == 0){
-                        this.fetchDataMovies('show')
-                    } else{
-                        
-                        this.fetchData(start, limit, 'show')
-                    }
-                })
+            this.$parent.observable.on('location', async () => {
+                let locateFail = (this.locateFail = await this.$parent.globalData.locateFail);
+                this.$apply();
+                if (this.activeIndex == 0) {
+                    this.fetchDataMovies('show');
+                } else {
+                    this.fetchData(start, limit, 'show');
+                }
+            });
         }
-
     }
 
     // 上拉加载
     async lower(e) {
-
-        if( !!this.lowerLoader || !!this.isMax ){
-            return
+        if (!!this.lowerLoader || !!this.isMax) {
+            return;
         }
 
         if (this.limit + this.start <= this.total) {
-            await this.fetchData(this.limit + this.start, this.limit)
-            this.lowerLoader = true
-        }else{
-            this.isMax = true
-            this.lowerLoader = false
-            return
+            await this.fetchData(this.limit + this.start, this.limit);
+            this.lowerLoader = true;
+        } else {
+            this.isMax = true;
+            this.lowerLoader = false;
+            return;
         }
-        setTimeout( () => {
-            this.lowerLoader = false
-        }, 100 )
-        this.$apply()
-
+        setTimeout(() => {
+            this.lowerLoader = false;
+        }, 100);
+        this.$apply();
     }
     async onReachBottom(e) {
-        await this.lower(e)
+        await this.lower(e);
     }
 }
 </script>

+ 263 - 284
src/pages/index/index.wpy

@@ -2,12 +2,12 @@
 @import './index';
 .userinfo {
     position: relative;
-    margin-bottom:50rpx;
+    margin-bottom: 50rpx;
     // padding:0 1em;
     // padding:0 1em;
-    .avatar{
-        display:flex;
-        align-items:center;
+    .avatar {
+        display: flex;
+        align-items: center;
     }
     .userinfo-avatar {
         width: 80rpx;
@@ -20,7 +20,7 @@
         font-size: 18px;
         font-weight: 400;
     }
-    .ico-info_circle{
+    .ico-info_circle {
         position: absolute;
         top: 20rpx;
         right: 0;
@@ -29,63 +29,61 @@
         align-items: center;
         width: 40rpx;
         height: 40rpx;
-        border: 1px solid #CACACA;
+        border: 1px solid #cacaca;
         border-radius: 50%;
-        color: #CACACA;
+        color: #cacaca;
         text-align: center;
         line-height: 1;
         font-size: 16px;
-        font-family: Arial, Roboto, system-ui,PingFang SC,STHeiti,sans-serif;
+        font-family: Arial, Roboto, system-ui, PingFang SC, STHeiti, sans-serif;
 
-        &:after{
+        &:after {
             // content: attr(data-text);
             content: 'i';
         }
     }
 }
-.Null{
-    .weui-cell{
-        flex-direction:column;
+.Null {
+    .weui-cell {
+        flex-direction: column;
     }
     .weui-cell__hd,
-    .weui-cell__bd{
+    .weui-cell__bd {
         width: 100%;
         margin: 20rpx 0;
     }
 }
-.allNull{
-    margin-bottom:100rpx;
+.allNull {
+    margin-bottom: 100rpx;
     text-align: center;
-    image{
-        display:block;
-        width:80vw;
-        margin:10vh auto 40rpx;
-        height:240rpx;
+    image {
+        display: block;
+        width: 80vw;
+        margin: 10vh auto 40rpx;
+        height: 240rpx;
     }
-    text{
+    text {
         font-size: 16px;
     }
-
 }
 
-.weui-cell_input{
+.weui-cell_input {
     // margin: 50rpx -30rpx;
     margin: 50rpx 0;
     padding: 0;
-    &::before{
+    &::before {
         display: none;
     }
 }
-.weui-cell{
+.weui-cell {
     padding: 20rpx 0;
 
-    
-    &__bd{
+    &__bd {
         position: relative;
-        color:@black;
+        color: @black;
         font-size: 18px;
         font-weight: bold;
-        .ico-cancel{
+        .ico-cancel {
             position: absolute;
             top: 50%;
             right: 15rpx;
@@ -97,117 +95,125 @@
             color: transparent;
 
             &:after,
-            &:before{
-                content: "";
+            &:before {
+                content: '';
                 position: absolute;
                 top: 50%;
                 left: 50%;
                 width: 60%;
                 height: 1px;
                 background: #fff;
-                transform: translate(-50%,-50%) rotate(45deg) scaleY(.5);
+                transform: translate(-50%, -50%) rotate(45deg) scaleY(0.5);
             }
-            &:before{
-                transform: translate(-50%,-50%) rotate(-45deg) scaleY(.5);
+            &:before {
+                transform: translate(-50%, -50%) rotate(-45deg) scaleY(0.5);
             }
         }
     }
 }
-.weui-cell__hd{
+.weui-cell__hd {
     margin-left: 20rpx;
-    button{
+    button {
         min-width: 140rpx;
-        box-shadow: 2px 2px 14px 0 rgba(0,0,0,.07);
+        box-shadow: 2px 2px 14px 0 rgba(0, 0, 0, 0.07);
         font-size: 14px;
     }
 }
-.weui-label{width: auto;}
-.weui-input{
+.weui-label {
+    width: auto;
+}
+.weui-input {
     height: 80rpx;
     padding: 0 2.5em 0 1.5em;
     line-height: 80rpx;
     border-radius: 80rpx;
-    background:#fff;
-    box-shadow: 2px 2px 14px 0 rgba(0,0,0,.07);
+    background: #fff;
+    box-shadow: 2px 2px 14px 0 rgba(0, 0, 0, 0.07);
     font-size: 14px;
     font-weight: normal;
 }
 
-.weui-cells_after-title{
+.weui-cells_after-title {
     margin: 40rpx 0 0;
     &::before,
-    &::after{
+    &::after {
         display: none;
     }
 }
-.orderListTitle{
+.orderListTitle {
     margin-top: 80rpx;
     padding-top: 30rpx;
     padding-bottom: 40rpx;
     border-top: 1rpx solid #ccc;
     border-bottom: 1rpx solid #ccc;
-    .weui-cell__ft{
-        top:  33rpx;
+    .weui-cell__ft {
+        top: 33rpx;
     }
-    .describe{
+    .describe {
         color: @grey;
         font-size: 14px;
     }
 }
-.helpText{
+.helpText {
     margin-top: 2.5em;
     padding-bottom: 1em;
-    color: #F16E24;
-    text-align:center;
+    color: #f16e24;
+    text-align: center;
 }
 </style>
 <template>
-    <view class="{{(!!DataList.total) ? 'GroupBuying container' : 'GroupBuying container Null'}}">
-        <Toast/>
+    <view
+        class="{{(!!DataList.total) ? 'GroupBuying container' : 'GroupBuying container Null'}}">
+        <Toast />
         <!-- 用户信息 -->
         <view class="userinfo">
             <!-- 已登录 -->
             <block wx:if="{{!!hasLogin && hasLogin!=null}}">
                 <view class="avatar">
-                    <image class="userinfo-avatar" src="{{userInfo.avatar }}" mode="aspectFit"/>
-                    <view class="userinfo-nickname">{{ userInfo.nickname }}</view>
+                    <image class="userinfo-avatar" src="{{userInfo.avatar }}"
+                        mode="aspectFit" />
+                    <view class="userinfo-nickname">{{ userInfo.nickname }}
+                    </view>
                 </view>
                 <i wx:if="{{!!DataList.total}}" class="ico-info_circle"
-                    @tap="goto"
-                    data-url="../help/help"
-                    data-alway/>
+                    @tap="goto" data-url="../help/help" data-alway />
             </block>
             <!-- 未登录时 -->
             <view wx:if="{{!hasLogin && hasLogin!=null}}" class="login">
                 <view class="login_decorate">
-                    <i class="planet"/>
-                    <i class="planet"/>
-                    <i class="planet"/>
-                    <i class="planet"/>
-                    <image src="{{loginImag_film}}" mode="aspectFit" lazy-load="false"/>
+                    <i class="planet" />
+                    <i class="planet" />
+                    <i class="planet" />
+                    <i class="planet" />
+                    <image src="{{loginImag_film}}" mode="aspectFit"
+                        lazy-load="false" />
                 </view>
                 <button size="defult" type="defult" form-type="submit"
-                  open-type="getUserInfo"
-                  bindgetuserinfo="bindLogin"
-                  @getuserinfo="getUserInfo">微信登录</button>
+                    open-type="getUserInfo" bindgetuserinfo="bindLogin"
+                    @getuserinfo="getUserInfo">微信登录</button>
             </view>
             <!-- 已登录没券没订单 -->
-            <view wx:if="{{(hasLogin!=null && !!hasLogin) && !whereFrom && !DataList.total}}" class="allNull">
-                <image src="{{loginImag}}" mode="aspectFit" lazy-load="false"/>
+            <view
+                wx:if="{{(hasLogin!=null && !!hasLogin) && !whereFrom && !DataList.total}}"
+                class="allNull">
+                <image src="{{loginImag}}" mode="aspectFit" lazy-load="false" />
                 <text>输入您的兑换码,开启光影之旅</text>
             </view>
             <!-- 已登录有、无信息 -->
-            <view wx:if="{{!!hasLogin && hasLogin!=null}}" class="weui-cell weui-cell_input">
+            <view wx:if="{{!!hasLogin && hasLogin!=null}}"
+                class="weui-cell weui-cell_input">
                 <view class="weui-cell__bd">
-                    <input class="weui-input"
-                        placeholder="输入您的兑换码"
+                    <input class="weui-input" placeholder="输入您的兑换码"
                         bindinput="onChangeCode"
-                        value="{{!coupon_code ? '' : coupon_code}}"/>
-                    <view wx:if="{{!!coupon_code}}" class="ico-cancel" @tap.stop="cancelInput">X</view>
+                        value="{{!coupon_code ? '' : coupon_code}}" />
+                    <view wx:if="{{!!coupon_code}}" class="ico-cancel"
+                        @tap.stop="cancelInput">X</view>
                 </view>
                 <view class="weui-cell__hd">
                     <button size="mini-" @tap="submitCouponCode">添加</button>
-                    <view wx:if="{{!DataList.total}}" @tap="goto" data-url="../help/help" data-alway class="helpText">了解换票</view>
+                    <view wx:if="{{!DataList.total}}" @tap="goto"
+                        data-url="../help/help" data-alway class="helpText">了解换票
+                    </view>
                 </view>
             </view>
 
@@ -215,35 +221,46 @@
 
         <!-- 主要信息区 -->
         <block wx:if="{{!!hasLogin && (DataList.total > 0)}}">
-            <view
-                @tap="goto"
-                data-url="vouchersList"
+            <view @tap="goto" data-url="vouchersList"
                 data-total="{{DataList.total}}"
                 class="weui-cells weui-cells_after-title">
                 <view class="weui-cell">
                     <view class="weui-cell__bd">我的兑换劵</view>
-                    <view
-                        wx:if="{{DataList.total>3}}"
-                        class="weui-cell__ft weui-cell__ft_in-access">查看全部({{DataList.total}})</view>
+                    <view wx:if="{{DataList.total>3}}"
+                        class="weui-cell__ft weui-cell__ft_in-access">
+                        查看全部({{DataList.total}})</view>
                 </view>
             </view>
 
             <view class="cardList">
-                <view wx:for="{{DataList.coupons}}" wx:key="{{item.index}}" class="cardList_item">
+                <view wx:for="{{DataList.coupons}}" wx:key="{{item.index}}"
+                    class="cardList_item">
                     <view>
-                        <navigator url="voucher?batch_id={{item.batch_id}}"
+                        <navigator url="voucher?couponId={{item.id}}"
                             class="weui-media-box weui-media-box_appmsg"
-                            data-kind="{{item.conpon_kind}}"
-                            data-hasUsed="{{item.coupon_status!=1 && item.coupon_status!=2 && item.coupon_status!=3}}"
+                            data-kind="{{item.type}}"
+                            data-hasUsed="{{item.count===item.usedCount}}"
                             hover-class="none">
-                            <view class="weui-media-box__hd weui-media-box__hd_in-appmsg">
-                                <image class="weui-media-box__thumb" mode="widthFix" src="{{item.subject_poster}}" />
+                            <view
+                                class="weui-media-box__hd weui-media-box__hd_in-appmsg">
+                                <image class="weui-media-box__thumb"
+                                    mode="widthFix"
+                                    src="{{item.pic}}" />
                             </view>
-                            <view class="weui-media-box__bd weui-media-box__bd_in-appmsg">
-                                <view class="weui-media-box__title">{{item.coupon_title}} <b wx:if="{{!!(item.total_num - item.used_num)}}" style="white-space: nowrap;">{{item.total_num - item.used_num}}张</b></view>
-                                <view class="weui-media-box__desc">有效期:{{item.start_date}}~{{item.end_date}}</view>
+                            <view
+                                class="weui-media-box__bd weui-media-box__bd_in-appmsg">
+                                <view class="weui-media-box__title">
+                                    {{item.name}} <b
+                                        wx:if="{{!!(item.count - item.usedCount)}}"
+                                        style="white-space: nowrap;">{{item.count - item.usedCount}}张</b>
+                                </view>
+                                <view class="weui-media-box__desc">
+                                    有效期:{{item.startDate}}~{{item.endDate}}
+                                </view>
                             </view>
-                            <view class="status" wx:if="{{item.coupon_status !=2 && item.coupon_status_cn}}">{{item.coupon_status_cn}}</view>
+                            <view class="status"
+                                wx:if="{{item.coupon_status !=2 && item.coupon_status_cn}}">
+                                {{item.coupon_status_cn}}</view>
                         </navigator>
                     </view>
                 </view>
@@ -251,43 +268,42 @@
             </view>
 
             <block wx:if="{{DataOrder.order_count > 0}}">
-                <view
-                    @tap="goto"
-                    data-url="ordersList"
-                    data-total="{{DataOrder.order_count}}"
-                    data-alway
+                <view @tap="goto" data-url="ordersList"
+                    data-total="{{DataOrder.order_count}}" data-alway
                     class="weui-cells weui-cells_after-title orderListTitle">
                     <view class="weui-cell">
                         <view class="weui-cell__bd">我的订单</view>
-                        <view class="weui-cell__ft weui-cell__ft_in-access">查看全部({{DataOrder.order_count}})</view>
+                        <view class="weui-cell__ft weui-cell__ft_in-access">
+                            查看全部({{DataOrder.order_count}})</view>
                     </view>
                     <view class="describe">查看取票码</view>
                 </view>
             </block>
         </block>
         <!-- 输入手机号弹层 -->
-        <Overlay wx:if="{{!!ifShowDiscountModal}}"
-            @childFn.user="parentFn"
+        <Overlay wx:if="{{!!ifShowDiscountModal}}" @childFn.user="parentFn"
             @submit.user="goVerifyDiscountCode"
             @childChangeFn.user="onChangeDiscount">
         </Overlay>
     </view>
 </template>
 <script>
-import wepy from 'wepy'
-import Overlay from '../../components/Overlay'
-import Toast from 'wepy-com-toast'
-import {iconWarning, icondSuccess} from '../../utils/icon.js'
+import wepy from 'wepy';
+import Overlay from '../../components/Overlay';
+import Toast from 'wepy-com-toast';
+import { iconWarning, icondSuccess } from '../../utils/icon.js';
 import {
     fecthVerifyDiscountCode,
     fecthVerifyDiscountList,
     fecthVerifyDiscount,
     fetchOrder,
     fetchOrderTotal,
-    fecthUserUpdate } from '../../utils/api.js'
+    fecthUserUpdate
+} from '../../utils/api.js';
+import http from '../../utils/http.js';
 
-let loginImag = '../../images/img_tickes.png'
-let loginImag_film = '../../images/ico_movie.png'
+let loginImag = '../../images/img_tickes.png';
+let loginImag_film = '../../images/ico_movie.png';
 
 export default class GroupBuying extends wepy.page {
     config = {
@@ -303,44 +319,43 @@ export default class GroupBuying extends wepy.page {
         Data: null,
         DataList: null,
         DataOrder: null,
-        coupon_code: null,
+        coupon_code: '',
         coupon_status: null,
         userInfo: null,
         hasLogin: null,
 
         phone: null,
-        ifDiscounts: false,         // 如果有兑换码功能
+        ifDiscounts: false, // 如果有兑换码功能
         ifShowDiscountModal: false, // 显示兑换码窗口
-        normalEnter: null,          // 首次进入走 onlond
+        normalEnter: null, // 首次进入走 onlond
 
         whereFrom: null,
-        retryTimes: 1,
+        retryTimes: 1
     };
-    computed = {
-    }
+    computed = {};
     methods = {
         goto(e) {
             let total = e.currentTarget.dataset.total,
                 url = e.currentTarget.dataset.url,
                 // 一直显示
                 alway = e.currentTarget.dataset.alway,
-                limit = 3
-                if (total >= limit || !!alway){
-                    wx.navigateTo({ url })
-                }
+                limit = 3;
+            if (total >= limit || !!alway) {
+                wx.navigateTo({ url });
+            }
         },
         // 监听验证码输入
         // ------------------------------
         onChangeCode(e) {
-            let val = e.detail.value
-            this.coupon_code = val
+            let val = e.detail.value;
+            this.coupon_code = val;
 
             if (val.length > 11) {
                 wx.showToast({
                     title: '请输入正确的兑换码',
                     icon: 'none',
                     duration: 3000
-                })
+                });
             }
             // this.$apply()
         },
@@ -351,168 +366,117 @@ export default class GroupBuying extends wepy.page {
             this.coupon_code = val
             console.log(e)
         }, */
-        cancelInput(){
-            this.coupon_code = null
+        cancelInput() {
+            this.coupon_code = null;
             // this.$apply()
         },
 
         // 添加兑换码
         // {user_id:123, coupon_code: 'abc123'}
         // ------------------------------
-        async submitCouponCode(e){
-            let user_id = this.$parent.globalData.user_id
-            let phone = this.$parent.globalData.phone
-
-            if(!phone){
-                this.ifShowDiscountModal = true
-                this.$apply()
-                return
-            }
-
-            let user_infor = { user_id, phone }
-            let fd_code = {
-                ...user_infor,
-                coupon_code: this.coupon_code
-            }
-            let fd_list = {
-                ...fd_code,
-                start: 0,
-                limit: 3
-            }
-            let cclng = fd_code.coupon_code != null ? fd_code.coupon_code.length : 0
+        async submitCouponCode(e) {
+            let phone = this.$parent.globalData.phone;
 
-            if (cclng == 0) {
+            if (!/[0-9a-zA-Z]{11}/.test(this.coupon_code)) {
                 this.$invoke('Toast', 'show', {
-                    title: '请输入兑换码',
+                    title: '请输入正确的兑换码',
                     img: iconWarning,
                     duration: 1500
-                })
-                return
+                });
+                return;
             }
-            if (cclng != 11) {
-                this.coupon_code = null
-                this.$invoke('Toast', 'show', {
-                    title: '兑换码错误',
-                    img: iconWarning,
-                    duration: 1500
-                })
-                return
+
+            if (!phone) {
+                this.ifShowDiscountModal = true;
+                this.$apply();
+                return;
             }
-            let fetchData = await fecthVerifyDiscountCode(fd_code)
-                .then( async res =>{
-                    console.log('0兑换::',res)
-                    if( !!res.error){
-                        this.$invoke('Toast', 'show', {
-                            title: res.error,
-                            img: iconWarning,
-                            duration: 3000
-                        })
-                        return
-                    }
-                    // typeof res != Object
-                    if( !res.data && res.indexOf('<!DOCTYPE')!=-1){
-                        this.$invoke('Toast', 'show', {
-                            title: '数据请求错误',
-                            img: iconWarning,
-                            duration: 3000
-                        })
-                        return
-                    }
-                    let fetchDataList = await fecthVerifyDiscountList(fd_list)
-                    this.DataList = fetchDataList.data
-                    this.$apply()
 
+            http.get('/coupon/bind', {
+                code: this.coupon_code,
+                phone: this.$parent.globalData.phone
+            })
+                .then(async res => {
                     this.$invoke('Toast', 'show', {
                         title: '兑换码添加成功',
                         img: icondSuccess,
                         duration: 3000
-                    })
-                })
-                .catch(err =>{
-                    console.log('1兑换::',err)
-                    // errMsg: "request:fail timeout"
+                    });
 
+                    this.getCouponList();
+                })
+                .catch(e => {
+                    console.log(e);
                     this.$invoke('Toast', 'show', {
-                        title: err.errMsg || err,
+                        title: e.error,
                         img: iconWarning,
                         duration: 3000
-                    })
-                })
-                
-            this.coupon_code = null
-            
-            this.Data = fetchData
-            this.$apply()
+                    });
+                });
+
+            this.coupon_code = null;
+
+            this.$apply();
         },
         // 模态框 - 手机号输入
         // ------------------------------
-        goVerifyDiscountCode(e){
-
-            if (this.phone == null){
+        goVerifyDiscountCode(e) {
+            if (this.phone == null) {
                 wx.showToast({
                     title: '请输入正确的手机号',
                     icon: 'none',
                     duration: 2000
-                })
-                return
-            }
-            this.$parent.globalData.phone = this.phone
-            this.methods.parentFn.call(this)
-            if(!this.coupon_code){
-                wx.showToast({
-                    title: '请输入兑换码',
-                    icon: 'none',
-                    duration: 2000
-                })
-                return
+                });
+                return;
             }
+            this.$parent.globalData.phone = this.phone;
+            this.methods.parentFn.call(this);
             setTimeout(() => {
-                this.methods.submitCouponCode.call(this)
-            }, 0)
+                this.methods.submitCouponCode.call(this);
+            }, 0);
         },
         // 模态组件-关闭
-        parentFn(a){
+        parentFn(a) {
+            this.ifShowDiscountModal = false;
+            a == 'close' && (this.phone = null);
 
-            this.ifShowDiscountModal = false
-            ;(a=='close') && (this.phone = null)
-
-            this.$apply()
+            this.$apply();
         },
         // 监听输入
-        onChangeDiscount(e){
-            let phone = e.detail.value
-            let reg = /^[0-9]{11}$/
-          
+        onChangeDiscount(e) {
+            let phone = e.detail.value;
+            let reg = /^[0-9]{11}$/;
+
             if (phone.length >= 11 && !reg.test(phone)) {
                 wx.showToast({
                     title: '请输入正确的手机号',
                     icon: 'none',
                     duration: 2000
-                })
-                return
+                });
+                return;
             }
             if (reg.test(phone)) {
-                this.phone = phone
+                this.phone = phone;
             }
         }
     };
-    Coupon_status(status){
-        this.coupon_status = true
-        this.$apply()
+    Coupon_status(status) {
+        this.coupon_status = true;
+        this.$apply();
     }
 
     // 获取用户信息
     async getUserInfo() {
-        var r = await wepy.getUserInfo()
-        let _data={
+        var r = await wepy.getUserInfo();
+        let _data = {
             user_id: this.$parent.globalData.user_id,
             iv: r.iv,
             cookie: this.$parent.globalData.cookie,
             encrypteddata: r.encryptedData,
             avatar: r.userInfo.avatarUrl,
             nickname: r.userInfo.nickName,
-            source: "tpp"
-        }
+            source: 'tpp'
+        };
         this.userInfo = {
             avatar: r.userInfo.avatarUrl,
             nickname: r.userInfo.nickName,
@@ -522,92 +486,107 @@ export default class GroupBuying extends wepy.page {
             language: r.userInfo.language,
             country: r.userInfo.country,
             gender: r.userInfo.gender
+        };
+        this.$parent.globalData.userInfo = this.userInfo;
+
+        this.retryTimes++;
+        await fecthUserUpdate(_data).then(res => {
+            this.$parent.globalData.hasLogin = this.hasLogin = true;
+            this.$parent.globalData.user_id = res.id;
+            this.$apply();
+        });
+
+        if (!this.$parent.globalData.user_id && this.retryTimes <= 20) {
+            setTimeout(() => this.getUserInfo(), 400);
         }
-        this.$parent.globalData.userInfo = this.userInfo
-
-        this.retryTimes ++
-        await fecthUserUpdate(_data)
-            .then(res=>{
-                this.$parent.globalData.hasLogin = this.hasLogin = true
-                this.$parent.globalData.user_id = res.id
-                this.$apply()
-            })
-
-        if(!this.$parent.globalData.user_id && (this.retryTimes <= 20)){
-            setTimeout(()=>this.getUserInfo(),400)
-        }
-
     }
 
-    async synchrodata(){
-
-        console.log("synchrodata:::",this.hasLogin, this.$parent.globalData.hasLogin)
-        console.log("synchrodata-user:::", this.$parent.globalData.user, this.$parent.globalData.userInfo)
+    getCouponList() {
+        return http
+            .get('/coupon/list', {
+                page: 0,
+                size: 3
+            })
+            .then(res => {
+                this.DataList = {
+                    coupons: res.content,
+                    total: res.totalElements
+                };
+                this.$apply();
+                return Promise.resolve();
+            });
+    }
 
-        if(this.hasLogin != null && this.hasLogin == false){
-            this.$apply()
-            return
+    async synchrodata() {
+        console.log(
+            'synchrodata:::',
+            this.hasLogin,
+            this.$parent.globalData.hasLogin
+        );
+        console.log(
+            'synchrodata-user:::',
+            this.$parent.globalData.user,
+            this.$parent.globalData.userInfo
+        );
+
+        if (this.hasLogin != null && this.hasLogin == false) {
+            this.$apply();
+            return;
         }
-        this.hasLogin = this.$parent.globalData.userInfo.hasLogin
-        
-        this.user_avatar = this.$parent.globalData.userInfo.avatar
-        this.user_nickname = this.$parent.globalData.userInfo.nickname
-        this.user_id = this.$parent.globalData.user_id
+        this.hasLogin = this.$parent.globalData.userInfo.hasLogin;
 
-        this.userInfo = this.$parent.globalData.userInfo
+        this.user_avatar = this.$parent.globalData.userInfo.avatar;
+        this.user_nickname = this.$parent.globalData.userInfo.nickname;
+        this.user_id = this.$parent.globalData.user_id;
 
-        let user_id = {
-            user_id: this.$parent.globalData.user_id
-        }
-        let fd_list = {
-            ...user_id,
-            start: 0,
-            limit: 3
-        }
+        this.userInfo = this.$parent.globalData.userInfo;
 
         // 获取优惠列表
-        let fetchDataList = await fecthVerifyDiscountList(fd_list)
-        this.DataList = fetchDataList.data
+        this.getCouponList();
+
         // 获取订单数量
-        let fetchDataOrderTotal = await fetchOrderTotal(user_id)
-        this.DataOrder = fetchDataOrderTotal.data
+        let fetchDataOrderTotal = await fetchOrderTotal();
+        this.DataOrder = fetchDataOrderTotal.data;
 
-        this.$apply()
+        this.$apply();
     }
 
-    onLoad(o){
-        this.whereFrom = o.whereFrom
-        console.log("onLoad",!!this.whereFrom)
+    onLoad(o) {
+        this.whereFrom = o.whereFrom;
+        console.log('onLoad', !!this.whereFrom);
         // wx.onAccelerometerChange(res => {
         //     console.log(res.x)
         //     console.log(res.y)
         //     console.log(res.z)
         // });
-        
-        
     }
-    async onShow(){
-        if( !!this.$parent.globalData.hasLogin ){
-            console.log("onShow",this.hasLogin,this.$parent.globalData.hasLogin)
-            this.hasLogin = this.$parent.globalData.hasLogin
-            await this.synchrodata()
-            return
+    async onShow() {
+        if (!!this.$parent.globalData.hasLogin) {
+            console.log(
+                'onShow',
+                this.hasLogin,
+                this.$parent.globalData.hasLogin
+            );
+            this.hasLogin = this.$parent.globalData.hasLogin;
+            await this.synchrodata();
+            return;
         }
-        this.$parent.observable.on('login',
-            ()=>{
-                console.log("onShow-1",this.hasLogin,this.$parent.globalData.hasLogin)
-                this.hasLogin = this.$parent.globalData.hasLogin
-                !!this.$parent.globalData.hasLogin && (
-                    this.synchrodata()
-                )
-            })
+        this.$parent.observable.on('login', () => {
+            console.log(
+                'onShow-1',
+                this.hasLogin,
+                this.$parent.globalData.hasLogin
+            );
+            this.hasLogin = this.$parent.globalData.hasLogin;
+            !!this.$parent.globalData.hasLogin && this.synchrodata();
+        });
     }
     onShareAppMessage() {
         return {
             title: this.$parent.globalData.Share.title,
             path: this.$parent.globalData.Share.path,
             imageUrl: this.$parent.globalData.Share.imageUrl
-        }
+        };
     }
     // coupon_status
     // (1, 即将到期)(2,'')(3,即将开始)(4,已使用)(5,已过期)

+ 132 - 123
src/pages/index/voucher.wpy

@@ -1,37 +1,44 @@
 <style lang="less">
 @import './index';
-.cp-wrapper{
+.cp-wrapper {
     overflow: hidden;
 }
-.Voucher{
-    &.container{
-        padding:0;
+.Voucher {
+    &.container {
+        padding: 0;
     }
-    &_top{
-        background-color: #F6F7F7;
+    &_top {
+        background-color: #f6f7f7;
         // margin-left: -@gap;
         // margin-right: -@gap;
         padding: 20rpx @gap;
 
-        .weui-media-box{
-            &:after{
-                background-image:
-                    radial-gradient(circle at center 0%,#F6F7F7 20rpx, transparent 0),
-                    radial-gradient(circle at center 100%,#ececec 20rpx, transparent 0),
-                    linear-gradient(#F6F7F7 20px, transparent 10px);
+        .weui-media-box {
+            &:after {
+                background-image: radial-gradient(
+                        circle at center 0%,
+                        #f6f7f7 20rpx,
+                        transparent 0
+                    ),
+                    radial-gradient(
+                        circle at center 100%,
+                        #ececec 20rpx,
+                        transparent 0
+                    ),
+                    linear-gradient(#f6f7f7 20px, transparent 10px);
             }
         }
     }
-    .weui-media-box__title{
+    .weui-media-box__title {
         font-size: 16px;
     }
 
-    .weui-navbar{
+    .weui-navbar {
         position: relative;
         width: 80%;
         margin: 0 auto;
         border: none;
-        &:after{
+        &:after {
             content: '';
             position: absolute;
             left: -80rpx;
@@ -41,45 +48,45 @@
             background: #fff;
             border-bottom: @borderColor solid 1rpx;
         }
-        
+
         &.hasTop {
             position: fixed;
         }
     }
-    .weui-tab__panel{
+    .weui-tab__panel {
         padding: 10rpx @gap 0;
     }
-    .weui-navbar__item{
+    .weui-navbar__item {
         z-index: 1;
         margin: 0;
         padding: 12px 8px;
-        color:@black;
+        color: @black;
         font-weight: bold;
-        &.weui-bar__item_on{
+        &.weui-bar__item_on {
             color: @main-color;
             font-weight: bold;
-            .weui-navbar__title{
+            .weui-navbar__title {
                 font-weight: inherit;
-            }        
+            }
         }
     }
-    .weui-navbar__title{
+    .weui-navbar__title {
         font-size: 14px;
         font-weight: normal;
     }
-    .weui-navbar__slider{
+    .weui-navbar__slider {
         width: 30px;
         background: @main-color;
         border-radius: 3px;
     }
     .page__title {
-        margin-top:1.5em;
+        margin-top: 1.5em;
         font-weight: bold;
-        line-height:1;
+        line-height: 1;
     }
 
     .page__desc {
-        display:inline-block;
+        display: inline-block;
         margin-top: 1em;
         color: #888;
         text-align: left;
@@ -95,7 +102,10 @@
     height: 45px;
     border-radius: 50%;
     background: rgba(0, 0, 0, 0.5)
-        data-uri('image/svg+xml;charset=UTF-8', '../../../common/images/icon/home.svg')
+        data-uri(
+            'image/svg+xml;charset=UTF-8',
+            '../../../common/images/icon/home.svg'
+        )
         no-repeat 50% 50%;
     background-size: 60% auto;
     color: #fff;
@@ -103,83 +113,95 @@
 </style>
 <template>
     <view class="Voucher container cp-wrapper">
-        <view class="cp-body-" style="display:flex; flex: 1; flex-direction:column; width:inherit;">
+        <view class="cp-body-"
+            style="display:flex; flex: 1; flex-direction:column; width:inherit;">
             <view class="Voucher_top">
-                <navigator
-                    class="weui-media-box weui-media-box_appmsg"
-                    data-kind="{{Data.conpon_kind}}"
-                    data-hasUsed="{{!!Data.status ? (Data.status!=1 && Data.status!=2 && Data.status!=3) : 'flase'}}" hover-class="none">
-                    <view class="weui-media-box__hd weui-media-box__hd_in-appmsg">
-                        <image class="weui-media-box__thumb" mode="widthFix" src="{{Data.subject_poster}}" />
+                <view class="weui-media-box weui-media-box_appmsg">
+                    <view
+                        class="weui-media-box__hd weui-media-box__hd_in-appmsg">
+                        <image class="weui-media-box__thumb" mode="widthFix"
+                            src="{{couponInfo.pic}}" />
                     </view>
-                    <view class="weui-media-box__bd weui-media-box__bd_in-appmsg">
-                        <view class="weui-media-box__title">{{Data.coupon_title}}</view>
-                        <view class="weui-media-box__desc">有效期:{{Data.start_date}}~{{Data.end_date}}</view>
+                    <view
+                        class="weui-media-box__bd weui-media-box__bd_in-appmsg">
+                        <view class="weui-media-box__title">
+                            {{couponInfo.name}}</view>
+                        <view class="weui-media-box__desc">
+                            有效期:{{couponInfo.startDate}}~{{couponInfo.endDate}}
+                        </view>
                         <view class="count">
-                            <em>{{Data.total_num}}<small>张</small></em>
-                            <b wx:if="{{Data.used_num != 0}}">已使用{{Data.used_num}}张</b>
+                            <em>{{couponInfo.count-couponInfo.usedCount}}<small>张</small></em>
+                            <b
+                                wx:if="{{couponInfo.usedCount != 0}}">已使用{{couponInfo.usedCount}}张</b>
                         </view>
                     </view>
                     <view wx:if="{{Data.status !=2 && Data.status_cn}}"
                         class="status">{{Data.status_cn}}</view>
-                </navigator>
+                </view>
             </view>
 
-            <view class="weui-tab" style="display:flex; flex: 1; flex-direction:column;" >
+            <view class="weui-tab"
+                style="display:flex; flex: 1; flex-direction:column;">
                 <view class="weui-navbar {{hasTop ? 'hasTop' : ''}}">
                     <view wx:for="{{tabs}}" wx:key="{{key}}" id="{{index}}"
                         class="weui-navbar__item {{activeIndex == index ? 'weui-bar__item_on' : ''}}"
                         @tap="tabClick">
                         <view class="weui-navbar__title">{{item}}</view>
                     </view>
-                    <view class="weui-navbar__slider" style="left: {{sliderLeft}}px; transform: translateX({{sliderOffset}}px); -webkit-transform: translateX({{sliderOffset}}px);"></view>
+                    <view class="weui-navbar__slider"
+                        style="left: {{sliderLeft}}px; transform: translateX({{sliderOffset}}px); -webkit-transform: translateX({{sliderOffset}}px);">
+                    </view>
                 </view>
                 <view class="weui-tab__panel cp-body">
-                    <view class="weui-tab__content" hidden="{{activeIndex != 0}}">
+                    <view class="weui-tab__content"
+                        hidden="{{activeIndex != 0}}">
                         <view class="page__title">有效时间</view>
-                        <view class="page__desc">{{Data.start_date}}~{{Data.end_date}}</view>
+                        <view class="page__desc">
+                            {{couponInfo.startDate}}~{{couponInfo.endDate}}
+                        </view>
                         <view class="page__title">使用城市及影院</view>
-                        <text class="page__desc">{{Data.coupon_range}}</text>
+                        <text class="page__desc">{{couponInfo.useRange}}</text>
                         <!-- 客服 -->
                         <!-- <button class="customer_service" open-type="contact" data-title="客服"/> -->
                     </view>
-                    <view class="weui-tab__content" hidden="{{activeIndex != 1}}">
-                        <text class="page__desc">{{Data.coupon_explain}}</text>
+                    <view class="weui-tab__content"
+                        hidden="{{activeIndex != 1}}">
+                        <text
+                            class="page__desc">{{couponInfo.explanation}}</text>
                     </view>
 
                 </view>
             </view>
 
-
         </view>
-        <view wx:if="{{Data.status == 1 || Data.status == 2}}" class="cp-footer">
-            <button size="large" @tap="goto">{{Data.conpon_kind=='4' ? '去购票' : '兑换电影票'}}</button>
+        <view wx:if="{{couponInfo.count > couponInfo.usedCount}}"
+            class="cp-footer">
+            <button size="large" @tap="goto">兑换电影票</button>
         </view>
 
         <!-- 返回首页 -->
-        <view class="backHome" @tap.stop="goToHome"/>
+        <view class="backHome" @tap.stop="goToHome" />
     </view>
 </template>
 <script>
-import wepy from 'wepy'
-import { fecthVerifyDiscount } from '../../utils/api.js'
+import wepy from 'wepy';
+import http from '../../utils/http.js';
 const sliderWidth = 65; // 需要设置slider的宽度,用于计算中间位置
 
 export default class GroupBuying extends wepy.page {
     config = {
         // navigationBarTitleText: '攒片集采'
     };
-    components = {
-    };
+    components = {};
     data = {
         tabs: ['适用范围', '使用说明'],
         activeIndex: 0,
         sliderOffset: 0,
         sliderLeft: 20,
-        usable_num: 0,
-        Data: null,
-        status: '',
-        
+        couponInfo: {
+            count: 0,
+            usedCount: 0
+        }
         // hasUsed: false
     };
     methods = {
@@ -187,96 +209,83 @@ export default class GroupBuying extends wepy.page {
             this.sliderOffset = e.currentTarget.offsetLeft;
             this.activeIndex = e.currentTarget.id;
         },
-        async goto(e){
+        async goto(e) {
             // let loc = await this.$parent.globalData.location
             // await this.Data
-            let batch_id = this.Data.batch_id,
-                conpon_kind = this.Data.conpon_kind,
+            let couponId = this.couponInfo.id,
+                coupon_type = this.couponInfo.type,
                 // subject_ids.length == 0 不限制影片
                 // subject_ids.length >= 1 限制影片
-                subject_id_ = this.Data.subject_ids.length >=1 ? this.Data.subject_ids[0] : 0,
-                
+                subject_id_ =
+                    this.couponInfo.shows && this.couponInfo.shows.length > 0
+                        ? this.couponInfo.shows[0].id
+                        : 0,
                 // cinema_ids.length == 0 // 不限制影院
                 // cinema_ids.length >= 1 // 限制影院
-                cinema_id_ = this.Data.cinema_ids.length >= 1 ? this.Data.cinema_ids.length : 0,
-                usable_num = this.usable_num,
-            
+                cinema_id_ =
+                    this.couponInfo.cinemas &&
+                    this.couponInfo.cinemas.length > 0
+                        ? this.couponInfo.cinemas[0].id
+                        : '',
+                usable_num = this.couponInfo.count - this.couponInfo.usedCount,
                 subject_id = !!subject_id_ ? `&subject_id=${subject_id_}` : '',
                 cinema_id = !!cinema_id_ ? `&cinema_id=${cinema_id_}` : '',
-                Url0 = `/pages/cinemas/cinemas?batch_id=${batch_id}&conpon_kind=${conpon_kind}${subject_id}${cinema_id}&usable_num=${usable_num}`,
-                Url1 = `/pages/session/session?batch_id=${batch_id}&conpon_kind=${conpon_kind}${subject_id}&cinema_id=${this.Data.cinema_ids[0]}&usable_num=${usable_num}`
-                
-                let url
-
-                // if( subject_id==0 && cinema_id_==1){
-
-                // }
-                // url: (!!subject_id && cinema_id_==1) ? Url1 : Url0
+                Url0 = `/pages/cinemas/cinemas?couponId=${couponId}&coupon_type=${coupon_type}${subject_id}${cinema_id}&usable_num=${usable_num}`,
+                Url1 = `/pages/session/session?couponId=${couponId}&coupon_type=${coupon_type}${subject_id}&cinema_id=${cinema_id_}&usable_num=${usable_num}`;
 
             wx.navigateTo({
-                url: cinema_id_==1 ? Url1 : Url0
-            })
+                url: cinema_id_ ? Url1 : Url0
+            });
         },
         goToHome() {
             wx.navigateBack({
                 delta: 2
-            })
-        },
+            });
+        }
     };
-    async onLoad(options){
-        let system = await wepy.getSystemInfo()
+    async onLoad(options) {
+        let system = await wepy.getSystemInfo();
         // let system = await this.$parent.globalData.system
 
         // console.log(system)
         this.sliderLeft =
             (system.windowWidth / this.tabs.length - sliderWidth) / 2;
         this.sliderOffset =
-            system.windowWidth / this.tabs.length * this.activeIndex;
+            (system.windowWidth / this.tabs.length) * this.activeIndex;
 
-        let data = {
-            user_id: await this.$parent.globalData.user_id,
-            batch_id: options.batch_id
-        }
+        http.get(`/coupon/detail/${options.couponId}`).then(res => {
+            this.couponInfo = res;
+            this.$apply();
+        });
 
-        let fetchData = await fecthVerifyDiscount(data)
-                        // .then(res =>{
-                        //     if( !!res.error ){
-                        //         wx.showToast({
-                        //             title: res.error,
-                        //             icon: 'none',
-                        //             duration: 5000
-                        //         })
-                        //         return
-                        //     }
-                        //     wx.showToast({
-                        //         title: res.data,
-                        //         icon: 'none',
-                        //         duration: 5000
-                        //     })
-                            
-                        // })
-                        // .catch(err =>{
-                        //     wx.showToast({
-                        //         title: err,
-                        //         icon: 'none',
-                        //         duration: 5000
-                        //     })
-                        // })
-        this.Data = fetchData.data.coupon
-        let total_num = fetchData.data.coupon.total_num,
-            used_num = fetchData.data.coupon.used_num,
-            status = fetchData.data.coupon.status
+        // .then(res =>{
+        //     if( !!res.error ){
+        //         wx.showToast({
+        //             title: res.error,
+        //             icon: 'none',
+        //             duration: 5000
+        //         })
+        //         return
+        //     }
+        //     wx.showToast({
+        //         title: res.data,
+        //         icon: 'none',
+        //         duration: 5000
+        //     })
 
-        if( status == 1 || status == 2 ){
-            this.usable_num = total_num - used_num
-        }
+        // })
+        // .catch(err =>{
+        //     wx.showToast({
+        //         title: err,
+        //         icon: 'none',
+        //         duration: 5000
+        //     })
+        // })
         // console.log(this.Data)
         // console.log('222',fetchData.data.coupon)
-
-        this.$apply();
     }
-    onShow(){
-        this.$parent.globalData.From = ''
+    onShow() {
+        this.$parent.globalData.From = '';
     }
 }
 </script>

+ 194 - 201
src/pages/locoation/locoation.wpy

@@ -26,14 +26,14 @@
     height: 70rpx;
     // padding: 0 40rpx;
     border-radius: 35rpx;
-    border: 1rpx solid #F16F24;
+    border: 1rpx solid #f16f24;
     line-height: 70rpx;
     text-align: center;
-    color: #F16F24;
+    color: #f16f24;
 
-    overflow:hidden;
-    white-space:nowrap;
-    text-overflow:ellipsis;
+    overflow: hidden;
+    white-space: nowrap;
+    text-overflow: ellipsis;
 }
 .lab_city {
     height: 106rpx;
@@ -41,7 +41,7 @@
     border-bottom: 1rpx solid #e0e4e8;
     color: #656a6f;
 
-    &:last-child{
+    &:last-child {
         border: none;
     }
 }
@@ -65,67 +65,66 @@
     font-size: 12px;
     text-align: center;
 }
-.hot_cities{
+.hot_cities {
     display: flex;
     flex-flow: row wrap;
     padding: 20rpx 0 20rpx (@gap - 10);
     padding-right: 0;
 
-    .lab_curCityName{
+    .lab_curCityName {
         // width:27%;
         margin: 10rpx;
-        border-color:#ccc;
-        color:#555;
+        border-color: #ccc;
+        color: #555;
         white-space: nowrap;
     }
 }
-.topCn{ font-size: 10px;text-align: center; }
-
+.topCn {
+    font-size: 10px;
+    text-align: center;
+}
 
-.page__bd{
+.page__bd {
     // position:fixed;
     position: relative;
-    left:0;
-    right:0;
-    top:0;
+    left: 0;
+    right: 0;
+    top: 0;
     // height:180rpx;
     height: 13.5vh;
-    z-index:999;
-
+    z-index: 999;
 }
-.searchbar-result{
+.searchbar-result {
     margin-top: 0;
     font-size: 14px;
 
-    .weui-cell{
+    .weui-cell {
         padding: 30rpx;
         padding-left: @gap;
         // 下边线
-        &:before{
+        &:before {
             left: 0;
         }
     }
 }
-.searchbar-result:before{
+.searchbar-result:before {
     display: none;
 }
 
-.valueInp{
-    color: #F16F24;
+.valueInp {
+    color: #f16f24;
 }
-.weui-icon-clear{
+.weui-icon-clear {
     bottom: 0;
-    display:flex;
-    align-items:center;
-    padding:7px 13px;
-
+    display: flex;
+    align-items: center;
+    padding: 7px 13px;
 }
-.weui-search-bar{
+.weui-search-bar {
     padding: 40rpx @gap;
-    background: #F6F7F7;
+    background: #f6f7f7;
     border: none;
-    &__box{
-        
+    &__box {
     }
 }
 .weui-icon-search_in-box {
@@ -133,52 +132,50 @@
     top: 26rpx;
 }
 
-.weui-search-bar__form{
-    border-radius:80rpx;
-
+.weui-search-bar__form {
+    border-radius: 80rpx;
 }
 .weui-search-bar__input,
-.weui-search-bar__label{
+.weui-search-bar__label {
     height: 80rpx;
     // padding:0 2.5em 0 1.5em;
-    line-height:84rpx;
-    border-radius:80rpx;
-    background:#fff;
-
+    line-height: 84rpx;
+    border-radius: 80rpx;
+    background: #fff;
 }
-.weui-search-bar__cancel-btn{
-    width:100rpx;
-    margin-right:-20px;
-    color:#656a6f;
+.weui-search-bar__cancel-btn {
+    width: 100rpx;
+    margin-right: -20px;
+    color: #656a6f;
     line-height: 80rpx;
 }
-.searchbar-result{
+.searchbar-result {
     position: absolute;
     z-index: 9;
     top: 100%;
     left: 0;
     right: 0;
-    overflow-y:auto;
-    -webkit-overflow-scrolling:touch;
+    overflow-y: auto;
+    -webkit-overflow-scrolling: touch;
     height: calc(100vh - 40px);
-    background: rgba(255,255,255,.8);
+    background: rgba(255, 255, 255, 0.8);
 }
-.icon_cur{
+.icon_cur {
     position: absolute;
-    top:50%;
+    top: 50%;
     right: 80rpx;
     width: 28rpx;
     height: 16rpx;
-    transform:translateY(-60%) rotate(-45deg);
-    border-bottom: 2px solid #F16F24;
-    border-left: 2px solid #F16F24;
+    transform: translateY(-60%) rotate(-45deg);
+    border-bottom: 2px solid #f16f24;
+    border-left: 2px solid #f16f24;
 }
 
-.ShowCities{
+.ShowCities {
     .container,
-    .lab_right{
-        filter:blur(4px);
-        opacity:.4;
+    .lab_right {
+        filter: blur(4px);
+        opacity: 0.4;
         pointer-events: none;
     }
 }
@@ -190,7 +187,7 @@
             <view class="weui-search-bar">
                 <view class="weui-search-bar__form">
                     <view class="weui-search-bar__box">
-                        <icon class="weui-icon-search_in-box" type="search" size="14"/>
+                        <icon class="weui-icon-search_in-box" type="search" size="14" />
                         <input class="weui-search-bar__input"
                             placeholder="输入城市名"
                             value="{{inputVal}}"
@@ -198,11 +195,11 @@
                             bindinput="inputTyping" />
 
                         <view class="weui-icon-clear" wx:if="{{inputVal.length > 0}}" bindtap="clearInput">
-                            <icon type="clear" size="14"/>
+                            <icon type="clear" size="14" />
                         </view>
                     </view>
                     <label class="weui-search-bar__label" hidden="{{inputShowed}}" bindtap="showInput">
-                        <icon class="weui-icon-search" type="search" size="14"/>
+                        <icon class="weui-icon-search" type="search" size="14" />
                         <view class="weui-search-bar__text">城市搜索</view>
                     </label>
                 </view>
@@ -217,7 +214,7 @@
                     @tap.stop="handleClickCity">
                     <view class="weui-cell__bd">
                         <text wx:for="{{item.city}}" class="{{item.isKey?'valueInp':''}}" wx:key="index">{{item.content}}</text>
-                        <text wx:if="{{item.id==curCity.city_id}}" class='icon_cur'/>
+                        <text wx:if="{{item.id==curCity.city_id}}" class='icon_cur' />
                     </view>
                 </view>
             </view>
@@ -232,7 +229,7 @@
                         @tap='handleClickCity'>{{curCity.city}}</view>
                 </view>
             </black>
-            <black wx:if="{{history_cities.length!=0}}">  
+            <black wx:if="{{history_cities.length!=0}}">
                 <view class='lab_title' id="zj">最近访问城市</view>
                 <view class="hot_cities">
                     <view class='lab_curCityName'
@@ -242,7 +239,7 @@
                         @tap='handleClickCity'>{{item.city}}</view>
                 </view>
             </black>
-            <black wx:if="{{hot_cities.length!=0}}"> 
+            <black wx:if="{{hot_cities.length!=0}}">
                 <view class='lab_title' id="rm">{{bind_cities ? '城市列表' : '热门城市'}}</view>
                 <view class="hot_cities">
                     <view class='lab_curCityName'
@@ -252,7 +249,7 @@
                         @tap='handleClickCity'>{{item.city}}</view>
                 </view>
             </black>
-            
+
             <view wx:for="{{letters}}" wx:key="index" id="{{item}}">
                 <view class='lab_title'>{{item}}</view>
                 <view class='lab_cityContainer'>
@@ -262,10 +259,10 @@
                         data-city="{{item}}"
                         @tap='handleClickCity'>{{item.city}}</view>
                 </view>
-                
+
             </view>
-            
-        </scroll-view> 
+
+        </scroll-view>
         <view wx:if="{{!bind_cities}}" class='lab_right'>
             <view @tap='handleTap' data-item="dw" class="topCn">定位</view>
             <view @tap='handleTap' data-item="zj" class="topCn">最近</view>
@@ -277,12 +274,12 @@
 
 <script>
 import wepy from 'wepy';
-import { fetchCities, fetchTogetherCities, fetchSearchCities } from '../../utils/api.js'
+import { fetchCities, fetchTogetherCities, fetchSearchCities } from '../../utils/api.js';
 
 export default class eventTicket extends wepy.page {
     config = {
-        navigationBarTitleText: '选择城市',
-    }
+        navigationBarTitleText: '选择城市'
+    };
     data = {
         inputShowed: false,
         inputVal: '',
@@ -291,7 +288,7 @@ export default class eventTicket extends wepy.page {
         curCity: {},
         curId: '',
         cities: [],
-        letters: [] ,
+        letters: [],
         hot_cities: [],
         history_cities: [],
         search_cities: [],
@@ -301,116 +298,115 @@ export default class eventTicket extends wepy.page {
     };
     components = {};
     methods = {
-
-        showInput () {
-            this.inputShowed = true
+        showInput() {
+            this.inputShowed = true;
         },
-        hideInput () {
-            this.inputVal = ''
-            this.inputShowed = false
-            this.isShowCities = false
-            this.search_cities = []
+        hideInput() {
+            this.inputVal = '';
+            this.inputShowed = false;
+            this.isShowCities = false;
+            this.search_cities = [];
         },
-        clearInput () {
-            this.inputVal = ''
-            this.isShowCities = false
-            this.search_cities = []
+        clearInput() {
+            this.inputVal = '';
+            this.isShowCities = false;
+            this.search_cities = [];
         },
-        inputTyping (e) {
-            let data = e.detail.value.trim()
-            let pattern = /^[\u4E00-\u9FA5]{1,5}$/
-            if( pattern.test(data) ){
-                this.inputVal = e.detail.value
-                fetchSearchCities(data)
-                    .then(res => {
-                        if(res.code =='success'){
-                            let cities = res.cities
-                            if(cities.length<=0){
-                                this.isShowCities = false
-                                this.search_cities = cities
+        inputTyping(e) {
+            let data = e.detail.value.trim();
+            let pattern = /^[\u4E00-\u9FA5]{1,5}$/;
+            if (pattern.test(data)) {
+                this.inputVal = e.detail.value;
+                fetchSearchCities(data).then(res => {
+                    if (res.code == 'success') {
+                        let cities = res.cities;
+                        if (cities.length <= 0) {
+                            this.isShowCities = false;
+                            this.search_cities = cities;
 
-                                wx.showToast({
-                                    title: '未找到匹配的城市',
-                                    icon: "none"
-                                })
-                                this.$apply()
-                                return
-                            }
-                            cities = cities.map(item =>{
-                                item.city = this.changeText(item.city, data)
-                                return item
-                            })
-                            this.isShowCities = true
-                            this.search_cities = cities
-                            this.$apply()
-                        }else{
                             wx.showToast({
-                                title: res.error,
-                                icon: "none"
-                            })
+                                title: '未找到匹配的城市',
+                                icon: 'none'
+                            });
+                            this.$apply();
+                            return;
                         }
-                        console.log('searchCities:',this.search_cities)
-                    })
-            }else{
-                this.isShowCities = false
+                        cities = cities.map(item => {
+                            item.city = this.changeText(item.city, data);
+                            return item;
+                        });
+                        this.isShowCities = true;
+                        this.search_cities = cities;
+                        this.$apply();
+                    } else {
+                        wx.showToast({
+                            title: res.error,
+                            icon: 'none'
+                        });
+                    }
+                    console.log('searchCities:', this.search_cities);
+                });
+            } else {
+                this.isShowCities = false;
                 wx.showToast({
                     title: '请输入中文城市名',
                     icon: 'none',
                     duration: 2000
-                })
+                });
             }
-
         },
-        handleTap(e) {//点击字母滑动
+        handleTap(e) {
+            //点击字母滑动
             this.setData({
                 curId: e.target.dataset.item
             });
         },
-        
-        handleClickCity(e) {// 点击城市
-            let city = e.currentTarget.dataset.city
+
+        handleClickCity(e) {
+            // 点击城市
+            let city = e.currentTarget.dataset.city;
             // {
             //     city: "北京"
             //     city_id : 3
             //     pin_yin : "BEIJING"
             // }
             // 如果是搜索城市
-            if (typeof(city.city)!='string'){
-                city.city_id = city.id
-                city.name = ""
-                city.city.map(item=>{
-                    city.name += item.content
-                })
-                city.city = city.name
+            if (typeof city.city != 'string') {
+                city.city_id = city.id;
+                city.name = '';
+                city.city.map(item => {
+                    city.name += item.content;
+                });
+                city.city = city.name;
             }
-            this.$parent.globalData.location.choose_city = { ...city }
+            this.$parent.globalData.location.choose_city = { ...city };
             // this.$parent.globalData.location.current_city = {...city}
-            this.$parent.globalData.locateFail = false
-
-            let cities = [...this.history_cities]
-            let clickCity = cities.find( item =>item.city_id === city.city_id )
-            if(!clickCity){
-                if(cities.length<4){
-                    cities.unshift(city)
-                }else{
-                    cities.pop()
-                    cities.unshift(city)
+            this.$parent.globalData.locateFail = false;
+
+            let cities = [...this.history_cities];
+            let clickCity = cities.find(item => item.city_id === city.city_id);
+            if (!clickCity) {
+                if (cities.length < 4) {
+                    cities.unshift(city);
+                } else {
+                    cities.pop();
+                    cities.unshift(city);
                 }
             }
-            this.history_cities = cities
-            this.$parent.globalData.location.history_cities = this.history_cities
+            this.history_cities = cities;
+            this.$parent.globalData.location.history_cities = this.history_cities;
 
-            if(this.loc == 'choose'){
+            if (this.loc == 'choose') {
                 // this.$parent.globalData.location.current_city = city
-                this.$parent.globalData.location.isChangeCity = false
-                this.$parent.globalData.loc = 'choose'
-                this.$apply()
-                console.log("locationThis.location::",this.$parent.globalData.location)
+                this.$parent.globalData.location.isChangeCity = false;
+                this.$parent.globalData.loc = 'choose';
+                this.$apply();
+                console.log('locationThis.location::', this.$parent.globalData.location);
             }
-            if(this.loc !== 'choose'){
-                this.$parent.globalData.location.isChangeCity = true
+            if (this.loc !== 'choose') {
+                this.$parent.globalData.location.isChangeCity = true;
             }
-            this.$apply()
+            this.$apply();
 
             // let pages = getCurrentPages()
             // let prevPage = pages[ pages.length - 2 ]
@@ -418,81 +414,78 @@ export default class eventTicket extends wepy.page {
 
             wx.navigateBack({
                 delta: 1
-            })
+            });
         }
     };
 
     async onLoad(options) {
-        this.loc = options.loc
-        let bind_cinema = options.bind_cinema
-        let subject_id = options.subject_id
-        let batch_id = options.batch_id
+        this.loc = options.loc;
+        let bind_cinema = options.bind_cinema;
+        let subject_id = options.subject_id;
+        let batch_id = options.batch_id;
 
-        let data = { batch_id }
-        
-        let that = this
-        let curCity = await this.$parent.globalData.location.current_city
+        let data = { batch_id };
 
-        this.curCity = curCity
+        let that = this;
+        let curCity = await this.$parent.globalData.location.current_city;
 
-        if( bind_cinema==='true' ){
-            await fetchTogetherCities(data)
-                .then(res=>{
-                    that.hot_cities = res.data.bind_cities
-            })
-            this.bind_cities = true
-            that.$apply()
-            return
+        this.curCity = curCity;
+
+        if (bind_cinema === 'true') {
+            await fetchTogetherCities(data).then(res => {
+                that.hot_cities = res.data.bind_cities;
+            });
+            this.bind_cities = true;
+            that.$apply();
+            return;
         }
 
-        await fetchCities(data).then( res=> {
-            let all_cities = res.data.all_cities
-            this.hot_cities = res.data.hot_cities
+        await fetchCities(data).then(res => {
+            let all_cities = res.all_cities;
+            this.hot_cities = res.hot_cities;
 
-            let cities = {}
+            let cities = {};
             for (let item in all_cities) {
-                cities[item] = []
+                cities[item] = [];
                 all_cities[item].map(city => {
                     // if (!!curCity && (city.id != curCity.id)) {
-                        //     cities[item].push(city)
+                    //     cities[item].push(city)
                     //     return
                     // }else{
-                        cities[item].push(city)
+                    cities[item].push(city);
                     // }
                 });
             }
-            let letters = Object.keys(cities)
-            this.cities = all_cities
-            this.letters = letters
+            let letters = Object.keys(cities);
+            this.cities = all_cities;
+            this.letters = letters;
 
-            this.$apply()
-        })
-
-        this.$apply()
+            this.$apply();
+        });
 
+        this.$apply();
     }
-    onShow(){
-        this.$parent.globalData.From = 'lockoation'
-        this.history_cities = this.$parent.globalData.location.history_cities || []
-        this.$apply()
+    onShow() {
+        this.$parent.globalData.From = 'lockoation';
+        this.history_cities = this.$parent.globalData.location.history_cities || [];
+        this.$apply();
     }
-    changeText (curStr,testStr){
-        let index = curStr.indexOf(testStr)
+    changeText(curStr, testStr) {
+        let index = curStr.indexOf(testStr);
         let length = testStr.length;
-        let ary = curStr.split("");
-        ary = ary.map((item,cur)=>{
+        let ary = curStr.split('');
+        ary = ary.map((item, cur) => {
             let obj = {
-                content:item
-            }
-            if(cur>=index&&cur<index+length){
-                obj.isKey = true
-            }else{
-                obj.isKey = false 
+                content: item
+            };
+            if (cur >= index && cur < index + length) {
+                obj.isKey = true;
+            } else {
+                obj.isKey = false;
             }
-            return obj
-        }) 
+            return obj;
+        });
         return ary;
     }
-
 }
 </script>

+ 4 - 4
src/utils/api.js

@@ -119,7 +119,7 @@ function fecthApplyPolling(order_id) {
 // /tpp/location/all_cities
 // ------------------
 function fetchCities(data) {
-    return API.GET(`${BASE_URL}/location/all_cities`, data, {
+    return API.GET(`${BASE_URL}/location/allCity`, data, {
         toast: { duration: 1000 }
     });
 }
@@ -170,9 +170,9 @@ function getCityId(data) {
 // 影片列表:
 /** get /tpp/city/<city_code>/subjects
  */
-function fetchMovies(data) {
+function fetchMovies(cityId, couponId) {
     return API.GET(
-        `${BASE_URL}/city/${data.city_id}/subjects?batch_id=${data.batch_id}`,
+        `${BASE_URL}/show/city/${cityId}/?couponId=${couponId||''}`,
         {},
         { toast: { duration: 10000 } }
     );
@@ -205,7 +205,7 @@ function fetchCinemas(data) {
     get /tpp/order/count?user_id=1036
 ----------------------- */
 function fetchOrderTotal(data) {
-    return API.GET(`${BASE_URL}/order/count?user_id=${data.user_id}`, data, {
+    return API.GET(`${BASE_URL}/order/count`, data, {
         toast: { duration: 2000 }
     });
 }

+ 1 - 1
src/utils/config.js

@@ -1,5 +1,5 @@
 const HOST = 'https://movieplusplus.com'
-const BASE_URL = 'http://localhost:8080'
+const BASE_URL = 'http://192.168.50.132:8080'
 const API = HOST + '/api/v3'
 const APIv2 = HOST + '/api/v2'
 

+ 121 - 0
src/utils/http.js

@@ -0,0 +1,121 @@
+import { BASE_URL } from './config.js';
+import 'wepy-async-function';
+function parseUrl(url) {
+    let _baseUrl = BASE_URL;
+    if (url.startsWith('http')) {
+        return url;
+    }
+    if (!_baseUrl.endsWith('/')) {
+        _baseUrl += '/';
+    }
+    if (url.startsWith('/')) {
+        url = url.slice(1);
+    }
+    return _baseUrl + url;
+}
+export default {
+    setToken(token) {
+        wx.setStorageSync('token', token);
+        this.token = token;
+    },
+    clearToken() {
+        this.token = '';
+        wx.removeStorageSync('token');
+        console.log('clear token');
+    },
+    getToken() {
+        if (!this.token) {
+            try {
+                this.token = wx.getStorageSync('token');
+            } catch (e) {}
+        }
+        return this.token;
+    },
+    get(url, params, options) {
+        options = options || {};
+        return new Promise((resolve, reject) => {
+            wx.request({
+                method: 'GET',
+                url: parseUrl(url),
+                data: params,
+                dataType: 'json',
+                header: {
+                    Authorization: this.getToken()
+                        ? 'Bearer ' + this.getToken()
+                        : '',
+                    ...(options.header || {})
+                },
+                success(res) {
+                    if (res && res.statusCode === 200) {
+                        resolve(res.data);
+                    } else {
+                        reject(res.data);
+                    }
+                },
+                fail(err) {
+                    reject(err);
+                }
+            });
+        });
+    },
+    post(url, data, options) {
+        options = options || {};
+        return new Promise((resolve, reject) => {
+            wx.request({
+                method: 'post',
+                url: parseUrl(url),
+                data: data,
+                dataType: 'json',
+                header: {
+                    'content-type': 'application/x-www-form-urlencoded',
+                    Authorization: this.getToken()
+                        ? 'Bearer ' + this.getToken()
+                        : '',
+                    ...(options.header || {})
+                },
+                success(res) {
+                    if (res && res.statusCode === 200) {
+                        resolve(res.data);
+                    } else {
+                        reject(res);
+                    }
+                },
+                fail(err) {
+                    reject(err);
+                }
+            });
+        });
+    },
+    uploadFile(filePath, options) {
+        options = options || {};
+        return new Promise((resolve, reject) => {
+            wx.uploadFile({
+                url: baseUrl + '/upload/file',
+                filePath: filePath,
+                name: 'file',
+                header: {
+                    'content-type': 'application/x-www-form-urlencoded',
+                    Authorization: this.getToken()
+                        ? 'Bearer ' + this.getToken()
+                        : '',
+                    ...(options.header || {})
+                },
+                formData: options.formData || {},
+                success(res) {
+                    if (res && res.statusCode === 200) {
+                        try {
+                            resolve(JSON.parse(res.data));
+                        } catch (e) {
+                            reject(e);
+                        }
+                    } else {
+                        reject(res);
+                    }
+                },
+                fail(err) {
+                    reject(err);
+                }
+            });
+        });
+    }
+};

+ 0 - 1
src/utils/request.js

@@ -35,7 +35,6 @@ export const request = (method = 'GET') => (url, data = {}, options = {}) => {
             fail: err => {
                 reject(err);
             },
-
             complete: () => {
                 // setTimeout(()=>{
                 wx.hideToast();