From 0ba97660072471499d9a6a3935a304603053e12e Mon Sep 17 00:00:00 2001 From: Maoqiang Zheng Date: Wed, 20 Feb 2019 16:59:06 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BB=E5=85=A5=E8=BF=87=E6=9C=9F=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../filteredShopComponent.js | 4 +- .../voucherPosterComponent.js | 7 +- .../goodsTypeInteractionComp.js | 9 +- .../interactionComponent.js | 11 +- .../shopTypeInteractionComp.js | 36 ++--- src/pages/allDemanding/allDemanding.js | 15 +- src/pages/goods/goods.js | 2 +- src/pages/goodsPublish/goodsPublish.js | 48 ++---- src/pages/grabOrderPage/grabOrderPage.js | 57 ++++--- src/pages/home/home.js | 7 +- .../myDemandSupplyEdit/myDemandSupplyEdit.js | 58 ++++--- src/pages/myGoodList/myGoodList.js | 10 +- src/pages/myGoodsEdit/myGoodsEdit.js | 51 ++++-- src/pages/myNeeds/myNeeds.js | 16 +- src/pages/myNeedsEdit/myNeedsEdit.js | 23 ++- src/pages/myNeedsPublish/myNeedsPublish.js | 27 ++-- src/pages/myNeedsView/myNeedsView.js | 95 +++++------ src/pages/mySupplyDemand/mySupplyDemand.js | 34 ++-- src/pages/shop/shop.js | 38 ++--- .../supplyDemandPublish.js | 21 +-- .../supplyDemandView/supplyDemandView.js | 150 +++++++++--------- src/{ => util}/LoginService.js | 41 +++-- src/util/loginExpired.js | 14 ++ src/util/weChatLogin.js | 75 +++++++++ src/weChatLogin.js | 73 --------- 25 files changed, 488 insertions(+), 434 deletions(-) rename src/{ => util}/LoginService.js (74%) create mode 100644 src/util/loginExpired.js create mode 100644 src/util/weChatLogin.js delete mode 100644 src/weChatLogin.js diff --git a/src/component/filteredShopComponent/filteredShopComponent.js b/src/component/filteredShopComponent/filteredShopComponent.js index 24cce53..6a9ad31 100644 --- a/src/component/filteredShopComponent/filteredShopComponent.js +++ b/src/component/filteredShopComponent/filteredShopComponent.js @@ -177,6 +177,9 @@ class recommondShop extends Component { console.log('从voucherposter件传回来的值', value) this.setState({ isOpenVoucher: value }) } + isOpenVoucher(){ + this.setState({isOpenVoucher:true}) + } componentWillReceiveProps(nextProps) { //console.log(this.props, nextProps) } @@ -250,7 +253,6 @@ class recommondShop extends Component { return ( - {voucherModalElement} {consultModalElement} { console.log('购买咨询请求成功', res) - if (res.data.err_msg === 'success') { + if (res.data.err_code === 0) { Taro.showToast({ title: '领取成功', icon: 'success', @@ -56,7 +57,9 @@ class VoucherPoster extends Component { this.passDataToParent() }, 1500); - } else { + }else if (res.data.err_code === 88888) { + loginExpired(res) + } else { Taro.showToast({ title: res.data.err_msg, icon: 'none', diff --git a/src/component/goodsTypeInteractionComp/goodsTypeInteractionComp.js b/src/component/goodsTypeInteractionComp/goodsTypeInteractionComp.js index 3c7b942..24f12ba 100644 --- a/src/component/goodsTypeInteractionComp/goodsTypeInteractionComp.js +++ b/src/component/goodsTypeInteractionComp/goodsTypeInteractionComp.js @@ -1,11 +1,10 @@ - - import Taro, { Component } from '@tarojs/taro' import { View, Text } from '@tarojs/components' import { Picker } from 'taro-ui' import './goodsTypeInteractionComp.scss' +import loginExpired from '../../util/loginExpired' let maxDepth = 0 let initialDataArray = [] @@ -41,9 +40,9 @@ class GoodsTypeInteractionComp extends Component { } }) .then(res => { - - if (res.data.err_msg === 'success') { + if (res.data.err_code === 0) { console.log('商品分类目录', res) + const recursionInteractionData=this.recursionInteraction(res.data.data) this.recursionInitialized(res.data.data) // this.setState({ @@ -59,6 +58,8 @@ class GoodsTypeInteractionComp extends Component { }) // 用递归来整理无限层次的数据 // console.log('联动数据', this.recursionInteraction(res.data.data)) // console.log('初始数据', this.recursionInitialized(res.data.data).reverse()) + }else if (res.data.err_code === 88888) { + loginExpired(res) } else { Taro.showToast({ title: res.data.err_msg, diff --git a/src/component/interactionComponent/interactionComponent.js b/src/component/interactionComponent/interactionComponent.js index 12dda9a..053db69 100644 --- a/src/component/interactionComponent/interactionComponent.js +++ b/src/component/interactionComponent/interactionComponent.js @@ -5,6 +5,7 @@ import { View, Text } from '@tarojs/components' import { Picker } from 'taro-ui' import './interactionComponent.scss' +import loginExpired from '../../util/loginExpired'; let maxDepth = 0 @@ -39,7 +40,7 @@ class Interaction extends Component { 'X-Requested-With': 'XMLHttpRequest' } }).then(res => { - if (res.data.err_msg === 'success') { + if (res.data.err_code === 0) { console.log('行业分类目录', res) let initailMultiArray = this.recursionInitialized(res.data.data) initialDataArray[1].unshift({ name: '全部', id: '-1' }) // 默认 @@ -49,6 +50,7 @@ class Interaction extends Component { multiIndex: this.recursionDepth(res.data.data), }, () => { + console.log('interactionMultiArray',this.state.interactionMultiArray) initialDataArray = []// 把全局变变量赋值给state之后,初始化商品分类为空, 不然第二次进去的时候会自动添加进去 // console.log('联动数据', this.state.interactionMultiArray) // console.log('初始化数据', this.state.initailMultiArray) @@ -56,6 +58,8 @@ class Interaction extends Component { }) // 用递归来整理无限层次的数据 + }else if (res.data.err_code === 88888) { + loginExpired(res) } else { console.log('行业分类请求没有成功', res) } @@ -90,7 +94,6 @@ class Interaction extends Component { } this.recursionInitialized(childrenHolderArray) } - arrayTem.length ? initialDataArray.push(arrayTem) : null // 数组为空则不添加 return initialDataArray } @@ -110,7 +113,7 @@ class Interaction extends Component { } bindMultiPickerCol(e) { console.log('修改的列为', e.detail.column, ',值为', e.detail.value) - console.log(this.state.initailMultiArray) + const data = { multiArray: this.state.initailMultiArray, multiIndex: this.state.multiIndex @@ -121,6 +124,7 @@ class Interaction extends Component { const indexNumber = Number(index) if (indexNumber === data.multiIndex[0]) { data.multiArray[1] = this.state.interactionMultiArray[indexNumber].children + console.log('datat',data) } } } @@ -148,7 +152,6 @@ class Interaction extends Component { componentDidMount() { - this.getIndustryTypeList(this.props.url) } // 当然父组件有新的props的 会从新渲染组件 diff --git a/src/component/shopTypeInteractionComp/shopTypeInteractionComp.js b/src/component/shopTypeInteractionComp/shopTypeInteractionComp.js index 72a3d51..fac51fb 100644 --- a/src/component/shopTypeInteractionComp/shopTypeInteractionComp.js +++ b/src/component/shopTypeInteractionComp/shopTypeInteractionComp.js @@ -4,6 +4,7 @@ import { View, Text } from '@tarojs/components' import { Picker } from 'taro-ui' import './shopTypeInteractionComp.scss' +import loginExpired from '../../util/loginExpired'; class ShopTypeInteractionComp extends Component { @@ -40,22 +41,22 @@ class ShopTypeInteractionComp extends Component { // console.log('店铺分类目录', res) // this.formatIndustryType(res.data.data) // this.formatIndustTypeInit(res.data.data) - if (res.data.err_msg === 'success') { + if (res.data.err_code === 0) { if (res.data.data === null) { return } console.log('店铺分类目录', res) + if(!Taro.getStorageSync('shopTypeObject')){ + Taro.setStorageSync('shopTypeObject',res.data.data) + } this.setState({ - interactionMultiArray: this.recursionInteraction(res.data.data), - initailMultiArray: this.recursionInitialized(res.data.data) + interactionMultiArray: this.interactionData(res.data.data), + initailMultiArray: this.initializedData(res.data.data), }, () => { // this.passDataToParent(this.state.initailMultiArray) //返回初始选项在 在商品编辑页面 - if (this.props.shopTypeId) { - const foundData = this.findDataByShopTypeId(this.props.shopTypeId) - this.passDataToParent(foundData) - } + // console.log('联动数据', this.state.interactionMultiArray) // console.log('初始化数据', this.state.initailMultiArray) @@ -63,6 +64,8 @@ class ShopTypeInteractionComp extends Component { }) // 用递归来整理无限层次的数据 + }else if (res.data.err_code === 88888) { + loginExpired(res) } else { console.log('店铺分类目录获取失败', res) } @@ -72,21 +75,10 @@ class ShopTypeInteractionComp extends Component { console.log('店铺分类请求错误', error) }) } - findDataByShopTypeId() { - console.log('id', this.props.shopTypeId, this.state.initailMultiArray) - let result = '' - this.state.initailMultiArray.forEach(items => { - items.forEach(item => { - if (item.id === this.props.shopTypeId) { - result = item - } - }) - }) - return result - } + // 递归整理无限层联动数据 - recursionInteraction(data) { + interactionData(data) { let parentArrayHolder = [] const keys = Object.keys(data) for (let key of keys) { @@ -102,7 +94,7 @@ class ShopTypeInteractionComp extends Component { return parentArrayHolder } // 递归整理无限层初始数据 - recursionInitialized(data) { + initializedData(data) { let outter = [] let inner = [] const keys = Object.keys(data) @@ -163,7 +155,7 @@ class ShopTypeInteractionComp extends Component { // 当然父组件有新的props的 会从新渲染组件 componentWillReceiveProps(nextProps) { - + } componentWillUnmount() { } diff --git a/src/pages/allDemanding/allDemanding.js b/src/pages/allDemanding/allDemanding.js index 043f96f..2413e6d 100644 --- a/src/pages/allDemanding/allDemanding.js +++ b/src/pages/allDemanding/allDemanding.js @@ -5,6 +5,7 @@ import CopyrightComponent from '../../component/copyrightComponent/copyrightComp import ScrollToTopComponent from '../../component/scrollToTopComponent/scrollToTopComponent' import InteractionComponent from '../../component/interactionComponent/interactionComponent' +import loginExpired from '../../util/loginExpired' import URL from '../../serviceAPI.config' import './allDemanding.scss' @@ -72,7 +73,7 @@ class AllDemanding extends Component { }) .then(res => { Taro.hideLoading() - if (res.data.err_msg === 'success') { + if (res.data.err_code === 0) { if (res.data.supplys) { if (this.state.isAddToList) { this.setState({ supplys: this.state.supplys.concat(res.data.supplys), isAddToList: false }) @@ -90,7 +91,9 @@ class AllDemanding extends Component { } } - } else { + } else if (res.data.err_code === 88888) { + loginExpired(res) + }else { Taro.showToast({ title: res.data.err_msg, icon: 'none', @@ -145,8 +148,12 @@ class AllDemanding extends Component { title: res.data.err_msg === 'success' ? '抢单成功' : res.data.err_msg, icon: res.data.err_msg === 'success' ? 'success' : 'none' }) - this.searchDemanding({ curr_page:1 }) - } else { + this.searchDemanding({ curr_page: 1 }) + } else if (res.data.err_code === 88888) { + loginExpired(res) + } + else { + Taro.showToast({ title: res.data.err_msg, icon: 'none' diff --git a/src/pages/goods/goods.js b/src/pages/goods/goods.js index df21e10..59dc996 100644 --- a/src/pages/goods/goods.js +++ b/src/pages/goods/goods.js @@ -4,7 +4,7 @@ import { View, Text, Image, Swiper, SwiperItem } from '@tarojs/components' import { AtTabs, AtTabsPane, AtSegmentedControl, AtIcon, Picker } from 'taro-ui' import CopyrightComponent from '../../component/copyrightComponent/copyrightComponent' -import LoginService from '../../LoginService' +import LoginService from '../../util/LoginService' import URL from '../../serviceAPI.config' import './goods.scss' diff --git a/src/pages/goodsPublish/goodsPublish.js b/src/pages/goodsPublish/goodsPublish.js index f0b9aad..156aee4 100644 --- a/src/pages/goodsPublish/goodsPublish.js +++ b/src/pages/goodsPublish/goodsPublish.js @@ -7,11 +7,12 @@ import CopyrightComponent from '../../component/copyrightComponent/copyrightComp import ShopTypeInteractionComp from '../../component/shopTypeInteractionComp/shopTypeInteractionComp' import GoodsTypeInteractionComp from '../../component/goodsTypeInteractionComp/goodsTypeInteractionComp' -import LoginService from '../../LoginService' +import LoginService from '../../util/LoginService' import URL from '../../serviceAPI.config' import './goodsPublish.scss' +import loginExpired from '../../util/loginExpired'; class GoodsPublish extends Component { @@ -94,7 +95,8 @@ class GoodsPublish extends Component { }) .then(res => { Taro.hideLoading() - if (res.data.err_msg === 'success') { + console.log('发布消息', res) + if (res.data.err_code === 0) { Taro.showToast({ title: '发布成功', @@ -115,6 +117,8 @@ class GoodsPublish extends Component { } }, 1000); + } else if (res.data.err_code === 88888) { + loginExpired(res) } else { Taro.showToast({ @@ -122,27 +126,11 @@ class GoodsPublish extends Component { icon: 'none', duration: 1000 }) - } - - console.log('上传商品', res) } ) - .catch(error => { - Taro.hideLoading() - Taro.showToast({ - title: '保存失败', - icon: 'none', - duration: 1000 - }) - }) } - - - - - productNameChange(event) { this.setState({ productName: event @@ -181,8 +169,8 @@ class GoodsPublish extends Component { }, success(response) { const responseData = JSON.parse(response.data) - console.log('responseData',responseData) - if (responseData.err_code===0) { + console.log('responseData', responseData) + if (responseData.err_code === 0) { const imagePath = URL.Base + responseData.file_path const newPickerImageUrl = that.state.pickerImageUrl.concat({ url: imagePath }) const newImageInfo = that.state.ImagesInfo.concat(responseData) @@ -193,7 +181,7 @@ class GoodsPublish extends Component { duration: 2000 }) }) - + } else { Taro.showToast({ title: responseData.err_msg, @@ -201,7 +189,7 @@ class GoodsPublish extends Component { duration: 1500 }) } - + } }) } @@ -218,10 +206,7 @@ class GoodsPublish extends Component { } publishButtonHandler() { - if (!Taro.getStorageSync('userInfo').user_id) { - LoginService() - return - } + if (this.state.productName && this.state.productPrice && this.state.productUnit && @@ -249,10 +234,7 @@ class GoodsPublish extends Component { } } publishAndNewButton() { - if (!Taro.getStorageSync('userInfo').user_id) { - LoginService() - return - } + if (this.state.productName && this.state.productPrice && this.state.productUnit && @@ -316,10 +298,10 @@ class GoodsPublish extends Component { componentWillUnmount() { } componentDidShow() { - if(!Taro.getStorageSync('shopInfo').shop_id&&Taro.getStorageSync('userInfo').user_id){ + if (!Taro.getStorageSync('shopInfo').shop_id && Taro.getStorageSync('userInfo').user_id) { Taro.showToast({ - title:'您还没有店铺,不能使用该功能,快去申请吧', - icon:'none' + title: '您还没有店铺,不能使用该功能,快去申请吧', + icon: 'none' }) } } diff --git a/src/pages/grabOrderPage/grabOrderPage.js b/src/pages/grabOrderPage/grabOrderPage.js index 1bce6bb..04bed15 100644 --- a/src/pages/grabOrderPage/grabOrderPage.js +++ b/src/pages/grabOrderPage/grabOrderPage.js @@ -8,6 +8,7 @@ import URL from '../../serviceAPI.config' import RenderingView from './renderingView/renderingView' import CopyrightComponent from '../../component/copyrightComponent/copyrightComponent' import './grabOrderPage.scss' +import loginExpired from '../../util/loginExpired'; class GrabOrderPage extends Component { @@ -53,20 +54,34 @@ class GrabOrderPage extends Component { }) .then(res => { console.log('抢单详情获取成功', res) - this.setState({ - type: res.data.sdInfo.class_name, - title: res.data.sdInfo.sd_title, - browsing: res.data.sdInfo.browse_times, - contactName: res.data.sdInfo.user_name, - contactNumber: res.data.sdInfo.user_phone, - address: res.data.sdInfo.user_address, - content: res.data.sdInfo.sd_desc, - images: res.data.sdInfo.file_path, - stateId: res.data.sdInfo.state, - stateName: res.data.sdInfo.state_name, - userId: res.data.sdInfo.user_id, - renderingImage: res.data.sdInfo.render_pics || [] - }) + if (res.data.err_code === 0) { + this.setState({ + type: res.data.sdInfo.class_name, + title: res.data.sdInfo.sd_title, + browsing: res.data.sdInfo.browse_times, + contactName: res.data.sdInfo.user_name, + contactNumber: res.data.sdInfo.user_phone, + address: res.data.sdInfo.user_address, + content: res.data.sdInfo.sd_desc, + images: res.data.sdInfo.file_path, + stateId: res.data.sdInfo.state, + stateName: res.data.sdInfo.state_name, + userId: res.data.sdInfo.user_id, + renderingImage: res.data.sdInfo.render_pics || [] + }) + } else if (res.data.err_code === 88888) { + Taro.clearStorageSync() + Taro.showToast({ + title: res.data.err_msg, + icon: 'none' + }) + setTimeout(() => { + Taro.reLaunch({ + url: '/pages/home/home' + }) + }, 1500); + } + } ) .catch(error => { @@ -89,7 +104,7 @@ class GrabOrderPage extends Component { } }) .then(res => { - if (res.data.err_msg === 'success') { + if (res.data.err_code === 0) { Taro.showToast({ title: '抢单成功', icon: 'success', @@ -101,6 +116,8 @@ class GrabOrderPage extends Component { }) }, 1500); + } else if (res.data.err_code === 88888) { + loginExpired(res) } else { Taro.showToast({ title: res.data.err_msg, @@ -194,7 +211,7 @@ class GrabOrderPage extends Component { } }).then(res => { - if (res.data.err_msg === "success") { + if (res.data.err_code === 0) { Taro.showToast({ title: '删除成功', icon: 'success', @@ -205,6 +222,8 @@ class GrabOrderPage extends Component { url: '/pages/myNeeds/myNeeds' }) }, 1500); + } else if (res.data.err_code === 88888) { + loginExpired(res) } else { Taro.showToast({ title: res.data.err_msg, @@ -292,9 +311,9 @@ class GrabOrderPage extends Component { const imageElementArray = this.state.images.map((item, index) => { return - - - + + + }) diff --git a/src/pages/home/home.js b/src/pages/home/home.js index eda2307..2c99f25 100644 --- a/src/pages/home/home.js +++ b/src/pages/home/home.js @@ -5,8 +5,8 @@ import FilteredShopComponent from '../../component/filteredShopComponent/filtere import ScrollToTopComponent from '../../component/scrollToTopComponent/scrollToTopComponent' import CopyrightComponent from '../../component/copyrightComponent/copyrightComponent' -import LoginService from '../../LoginService' -import weChatLogin from '../../weChatLogin' +import LoginService from '../../util/LoginService' +import weChatLogin from '../../util/weChatLogin' import URL from '../../serviceAPI.config' import './home.scss' @@ -265,10 +265,9 @@ class Home extends Component { componentDidMount() { // 页面加载后 得到首页的基本信息和推荐店铺的信息 Taro.showLoading({ title: '加载中' }) - if (!Taro.getStorageSync('userInfo').user_id) { + if(!Taro.getStorageSync('userInfo').user_id){ weChatLogin() } - this.getShops({}) this.getHomeCategoriesInfo() diff --git a/src/pages/myDemandSupplyEdit/myDemandSupplyEdit.js b/src/pages/myDemandSupplyEdit/myDemandSupplyEdit.js index e99a812..bd06756 100644 --- a/src/pages/myDemandSupplyEdit/myDemandSupplyEdit.js +++ b/src/pages/myDemandSupplyEdit/myDemandSupplyEdit.js @@ -8,6 +8,7 @@ import URL from '../../serviceAPI.config' import './myDemandSupplyEdit.scss' +import loginExpired from '../../util/loginExpired'; @@ -56,28 +57,28 @@ class MyDemandSupplyEdit extends Component { }) .then(res => { console.log('供求详情获取成功', res) - const selectedType = this.state.demandingSupplyCate.filter(item => item.id == res.data.sdInfo.sd_type)[0] - const selectedState = this.state.demandingSupplyState.filter(item => item.id == res.data.sdInfo.state)[0] - const imageFile = res.data.sdInfo.file_path.map(item => { return { url: URL.Base + item.file_path } }) - this.setState({ - demandSupplyId: res.data.sdInfo.sd_id, - demandingSupplyCateSelected: selectedType, - title: res.data.sdInfo.sd_title, - contactName: res.data.sdInfo.user_name, - contactNumber: res.data.sdInfo.user_phone, - contactAddress: res.data.sdInfo.user_address, - content: res.data.sdInfo.sd_desc, - demandingSupplyStateSelected: selectedState, - pickerImageUrl: imageFile, - ImagesInfo: res.data.sdInfo.file_path, - }) - Taro.hideLoading() - } - - ) - .catch(error => { - console.log('供求详情获取失败', error) + if (res.data.err_code === 0) { + const selectedType = this.state.demandingSupplyCate.filter(item => item.id == res.data.sdInfo.sd_type)[0] + const selectedState = this.state.demandingSupplyState.filter(item => item.id == res.data.sdInfo.state)[0] + const imageFile = res.data.sdInfo.file_path.map(item => { return { url: URL.Base + item.file_path } }) + this.setState({ + demandSupplyId: res.data.sdInfo.sd_id, + demandingSupplyCateSelected: selectedType, + title: res.data.sdInfo.sd_title, + contactName: res.data.sdInfo.user_name, + contactNumber: res.data.sdInfo.user_phone, + contactAddress: res.data.sdInfo.user_address, + content: res.data.sdInfo.sd_desc, + demandingSupplyStateSelected: selectedState, + pickerImageUrl: imageFile, + ImagesInfo: res.data.sdInfo.file_path, + }) + Taro.hideLoading() + } else if (res.data.err_code === 88888) { + loginExpired(res) + } }) + } @@ -147,6 +148,8 @@ class MyDemandSupplyEdit extends Component { }, 1000); }) + } else if (res.data.err_code === 88888) { + loginExpired(res) } else { Taro.showToast({ title: res.data.err_msg, @@ -219,7 +222,7 @@ class MyDemandSupplyEdit extends Component { } }) .then(res => { - if (res.data.err_msg == 'success') { + if (res.data.err_code == 0) { Taro.showToast({ title: '删除成功' }).then(() => { @@ -230,6 +233,8 @@ class MyDemandSupplyEdit extends Component { }, 1500); }) + } else if (res.data.err_code === 88888) { + loginExpired(res) } else { Taro.showToast({ @@ -239,13 +244,6 @@ class MyDemandSupplyEdit extends Component { } } ) - .catch(error => { - - Taro.showToast({ - title: '删除失败', - icon: 'none' - }) - }) } // 修改供求类型 demandingSupplyCate = e => { @@ -345,7 +343,7 @@ class MyDemandSupplyEdit extends Component { componentDidHide() { } - render() { + render() { // 提示模态弹窗element const modalMessageConfirmElement = 提示 diff --git a/src/pages/myGoodList/myGoodList.js b/src/pages/myGoodList/myGoodList.js index 35d40b7..1161a7e 100644 --- a/src/pages/myGoodList/myGoodList.js +++ b/src/pages/myGoodList/myGoodList.js @@ -8,6 +8,7 @@ import URL from '../../serviceAPI.config' import './myGoodList.scss' +import loginExpired from '../../util/loginExpired'; class MyGoodList extends Component { @@ -259,7 +260,6 @@ class MyGoodList extends Component { }).then(res => { let responseData = JSON.parse(res.data) if (responseData.err_code === 0) { - this.setState({ isCheckAll: false, currPageParam: 1, @@ -272,7 +272,9 @@ class MyGoodList extends Component { duration: 1500 }) }) - } else { + }else if (responseData.err_code === 88888) { + loginExpired(res) + } else { Taro.showToast({ title: responseData.err_msg, icon: 'none', @@ -314,7 +316,9 @@ class MyGoodList extends Component { }) }) - } else { + }else if (responseData.err_code === 88888) { + loginExpired(res) + } else { Taro.showToast({ title: responseData.err_msg, icon: 'none', diff --git a/src/pages/myGoodsEdit/myGoodsEdit.js b/src/pages/myGoodsEdit/myGoodsEdit.js index 258471a..16dd722 100644 --- a/src/pages/myGoodsEdit/myGoodsEdit.js +++ b/src/pages/myGoodsEdit/myGoodsEdit.js @@ -7,6 +7,7 @@ import CopyrightComponent from '../../component/copyrightComponent/copyrightComp import URL from '../../serviceAPI.config' import './myGoodsEdit.scss' +import loginExpired from '../../util/loginExpired'; class MyGoodsEdit extends Component { config = { @@ -16,8 +17,6 @@ class MyGoodsEdit extends Component { super(...arguments) this.state = { shopTypeSelected: { name: '全部', id: '' }, - shopTypeId: '', - shopTypeList: {},//店铺分类列表 productName: '', productPrice: '', productUnit: '', @@ -30,6 +29,7 @@ class MyGoodsEdit extends Component { isSaveAndNewBUtton: false,// 是否点击了保存新增按钮 } } + //获取商品信息api GetProductInfo getGoodsInfo() { Taro.request({ @@ -46,7 +46,7 @@ class MyGoodsEdit extends Component { } }) .then(res => { - if (res.data.err_msg === 'success') { + if (res.data.err_code === 0) { console.log('商品详情获取成功', res) const imageFile = res.data.goodsFiles.map((item) => { @@ -62,18 +62,34 @@ class MyGoodsEdit extends Component { // } // } // } - this.setState({ - productName: res.data.goods.goods_name, - productPrice: res.data.goods.goods_price, - productUnit: res.data.goods.goods_unit, - productDescript: res.data.goods.goods_profiles, - pickerImageUrl: imageFile, - ImagesInfo: res.data.goodsFiles, - shopTypeId: res.data.goods.shop_class_id, - goodsTypeParam: res.data.goods.class_id, - goodId: res.data.goods.goods_id, - }) + + if (Taro.getStorageSync('shopTypeObject')) { + let selectedValue = '' + const shopTypeObject = Taro.getStorageSync('shopTypeObject') + for (let key in shopTypeObject) { + for (let item of shopTypeObject[key].c) { + if (item.id === res.data.goods.shop_class_id) { + selectedValue = {name:item.n,id:item.id} + } + } + } + this.setState({ + productName: res.data.goods.goods_name, + productPrice: res.data.goods.goods_price, + productUnit: res.data.goods.goods_unit, + productDescript: res.data.goods.goods_profiles, + pickerImageUrl: imageFile, + ImagesInfo: res.data.goodsFiles, + shopTypeSelected: selectedValue, + goodsTypeParam: res.data.goods.class_id, + goodId: res.data.goods.goods_id, + }) + + } + + } else if (res.data.err_code === 88888) { + loginExpired(res) } } @@ -141,7 +157,7 @@ class MyGoodsEdit extends Component { }) .then(res => { Taro.hideLoading() - + if (res.data.err_code === 0) { Taro.showToast({ title: '保存成功', @@ -160,6 +176,8 @@ class MyGoodsEdit extends Component { } }, 1000); }) + } else if (res.data.err_code === 88888) { + loginExpired(res) } else { Taro.hideLoading() Taro.showToast({ @@ -337,6 +355,7 @@ class MyGoodsEdit extends Component { componentDidMount() { this.getGoodsInfo() + } componentWillReceiveProps(nextProps) { @@ -351,7 +370,6 @@ class MyGoodsEdit extends Component { render() { - return ( @@ -412,7 +430,6 @@ class MyGoodsEdit extends Component { shopId={Taro.getStorageSync('shopInfo').shop_id} selectedValue={this.state.shopTypeSelected} onPassDataToChild={this.getDataFromShopChild.bind(this)} - shopTypeId={this.state.shopTypeId} > {/* 店铺分类结束 */} diff --git a/src/pages/myNeeds/myNeeds.js b/src/pages/myNeeds/myNeeds.js index 7b21d81..3b651d2 100644 --- a/src/pages/myNeeds/myNeeds.js +++ b/src/pages/myNeeds/myNeeds.js @@ -6,9 +6,10 @@ import URL from '../../serviceAPI.config' import ScrollToTopComponent from '../../component/scrollToTopComponent/scrollToTopComponent' import InteractionComponent from '../../component/interactionComponent/interactionComponent' import CopyrightComponent from '../../component/copyrightComponent/copyrightComponent' -import LoginService from '../../LoginService' +import LoginService from '../../util/LoginService' import './myNeeds.scss' +import loginExpired from '../../util/loginExpired'; class MyNeeds extends Component { @@ -92,7 +93,7 @@ class MyNeeds extends Component { }).then(res => { Taro.hideLoading() console.log('我的需求列表', res) - if (res.data.err_msg === "success") { + if (res.data.err_code === 0) { if (res.data.supplys) { // 查看res.data 里面是否有supplys 这个key if (this.state.isAddToList) { // 如果是上拉 this.setState({ @@ -121,10 +122,7 @@ class MyNeeds extends Component { } } else { if(JSON.parse(res.data).err_code===88888){ - Taro.showToast({ - title: JSON.parse(res.data).err_msg, - icon: 'none' - }) + loginExpired(res) }else{ Taro.showToast({ @@ -155,7 +153,7 @@ class MyNeeds extends Component { } }).then(res => { console.log('删除我的列表', res) - if (res.data.err_msg === "success") { + if (res.data.err_code === 0) { Taro.showToast({ title: '删除成功', icon: 'success', @@ -165,7 +163,9 @@ class MyNeeds extends Component { this.getMyNeedsList({ }) }, 1500); - } else { + }else if (res.data.err_code === 88888) { + loginExpired(res) + } else { Taro.showToast({ title: res.data.err_msg, icon: 'none', diff --git a/src/pages/myNeedsEdit/myNeedsEdit.js b/src/pages/myNeedsEdit/myNeedsEdit.js index 092b85c..7707117 100644 --- a/src/pages/myNeedsEdit/myNeedsEdit.js +++ b/src/pages/myNeedsEdit/myNeedsEdit.js @@ -7,6 +7,7 @@ import InteractionComponent from '../../component/interactionComponent/interacti import CopyrightComponent from '../../component/copyrightComponent/copyrightComponent' import URL from '../../serviceAPI.config' import './myNeedsEdit.scss' +import loginExpired from '../../util/loginExpired'; class MyNeedsEdit extends Component { @@ -60,6 +61,7 @@ class MyNeedsEdit extends Component { // const selectedType = this.state.demandingSupplyCate.filter(item => item.id == res.data.sdInfo.sd_type)[0] // const selectedState = this.state.needsState.filter(item => item.id == res.data.sdInfo.state)[0] if (res.data.err_code === 0) { + let industryType = {} const classId = res.data.sdInfo.class_id for (let outter of res.data.supplyTree) { @@ -102,12 +104,15 @@ class MyNeedsEdit extends Component { pickerImageUrl: imageFile, ImagesInfo: res.data.sdInfo.file_path, }) - Taro.hideLoading() - } else { + + }else if (JSON.parse(res.data).err_code === 88888) { + loginExpired(res) + } else { Taro.showToast({ - title: res.data.err_msg, + title: JSON.parse(res.data).err_msg, icon: 'none' }) + } } ) @@ -176,7 +181,9 @@ class MyNeedsEdit extends Component { } }, 1500); }) - } else { + }else if (res.data.err_code === 88888) { + loginExpired(res) + } else { Taro.showToast({ title: '保存失败', icon: 'none', @@ -251,7 +258,7 @@ class MyNeedsEdit extends Component { } }).then(res => { console.log('删除我的列表', res) - if (res.data.err_msg === "success") { + if (res.data.err_code === 0) { Taro.showToast({ title: '删除成功', icon: 'success', @@ -263,7 +270,9 @@ class MyNeedsEdit extends Component { }) }, 1000); - } else { + }else if (res.data.err_code === 88888) { + loginExpired(res) + } else { Taro.showToast({ title: res.data.err_msg, icon: 'none', @@ -368,8 +377,6 @@ class MyNeedsEdit extends Component { componentDidMount() { - - Taro.showLoading({ title: '加载中' }) this.getMyNeedEditInfo() } componentWillReceiveProps(nextProps) { diff --git a/src/pages/myNeedsPublish/myNeedsPublish.js b/src/pages/myNeedsPublish/myNeedsPublish.js index a427c37..5f85660 100644 --- a/src/pages/myNeedsPublish/myNeedsPublish.js +++ b/src/pages/myNeedsPublish/myNeedsPublish.js @@ -1,6 +1,6 @@ import Taro, { Component } from '@tarojs/taro' -import { View, Text, Button,Input } from '@tarojs/components' +import { View, Text, Button, Input } from '@tarojs/components' import { AtInput, AtImagePicker, AtTextarea, Picker } from 'taro-ui' import CopyrightComponent from '../../component/copyrightComponent/copyrightComponent' @@ -9,6 +9,7 @@ import InteractionComponent from '../../component/interactionComponent/interacti import './myNeedsPublish.scss' +import loginExpired from '../../util/loginExpired'; @@ -32,7 +33,7 @@ class MyNeedsPublish extends Component { content: '', pickerImageUrl: [], // 上传的图片 ImagesInfo: [],// 后台传回来的图片信息 - + isPublishAndNew: false,//是否点击发布新增按钮 } } @@ -80,7 +81,7 @@ class MyNeedsPublish extends Component { }) .then(res => { console.log('上传需求', res) - if (res.data.err_msg === 'success') { + if (res.data.err_code === 0) { Taro.showToast({ title: '发布成功', icon: 'success', @@ -89,18 +90,18 @@ class MyNeedsPublish extends Component { setTimeout(() => { if (this.state.isPublishAndNew) { Taro.navigateTo({ - url: '/pages/myNeedsPublish/myNeedsPublish' + url: '/pages/myNeedsPublish/myNeedsPublish' }) - } else { + } else { Taro.navigateTo({ - url: '/pages/myNeedsEdit/myNeedsEdit?id=' + res.data.sd_id + url: '/pages/myNeedsEdit/myNeedsEdit?id=' + res.data.sd_id }) - } - - + } }, 1500); }) + } else if (res.data.err_code === 88888) { + loginExpired(res) } else { Taro.showToast({ title: res.data.err_msg, @@ -253,10 +254,10 @@ class MyNeedsPublish extends Component { // Taro.showLoading({title:'加载中'}) // this.getSupplyDemandInfo() // 如果路由参数为1 就默认显示 效果图,反之 显示业主需求 - const isRenderingPic=this.$router.params.id + const isRenderingPic = this.$router.params.id console.log(parseInt(isRenderingPic)) - if(parseInt(isRenderingPic)){ - this.setState({needsTypeSelected:{ name: '效果图', id: '5' }}) + if (parseInt(isRenderingPic)) { + this.setState({ needsTypeSelected: { name: '效果图', id: '5' } }) } } componentWillReceiveProps(nextProps) { @@ -327,7 +328,7 @@ class MyNeedsPublish extends Component { onInput={this.contactNumberChange.bind(this)} /> - + 联系地址: diff --git a/src/pages/myNeedsView/myNeedsView.js b/src/pages/myNeedsView/myNeedsView.js index 2473925..93c7e59 100644 --- a/src/pages/myNeedsView/myNeedsView.js +++ b/src/pages/myNeedsView/myNeedsView.js @@ -1,13 +1,14 @@ import Taro, { Component } from '@tarojs/taro' import { View, Text, Image, Button } from '@tarojs/components' -import { AtIcon, AtModal, AtModalHeader, AtModalContent, AtModalAction } from 'taro-ui' +import { AtIcon, AtModal, AtModalHeader, AtModalContent, AtModalAction } from 'taro-ui' import URL from '../../serviceAPI.config' import CopyrightComponent from '../../component/copyrightComponent/copyrightComponent' import './myNeedsView.scss' +import loginExpired from '../../util/loginExpired'; @@ -35,14 +36,14 @@ class SupplyDemandView extends Component { content: '',//描述 pickerImageUrl: [], ImagesInfo: [], - isShowAllButtons:true// 是否显示所有按钮 + isShowAllButtons: true// 是否显示所有按钮 } } //获取需求信息api getSingleMyNeedInfo() { Taro.request({ - // url: URL.EditMyNeeds, - url: URL.supplyDemandDetails, + // url: URL.EditMyNeeds, + url: URL.supplyDemandDetails, method: 'GET', dataType: 'json', data: { @@ -59,7 +60,7 @@ class SupplyDemandView extends Component { // const selectedType = this.state.demandingSupplyCate.filter(item => item.id == res.data.sdInfo.sd_type)[0] // const selectedState = this.state.needsState.filter(item => item.id == res.data.sdInfo.state)[0] Taro.hideLoading() - if(res.data.err_msg==='success'){ + if (res.data.err_code === 0) { let industryType = {} const classId = res.data.sdInfo.class_id for (let outter of res.data.supplyTree) { @@ -78,7 +79,7 @@ class SupplyDemandView extends Component { break } } - + // const needsType = this.state.needsType.filter(item => { // return item.id === res.data.sdInfo.sd_type // })[0] @@ -100,19 +101,19 @@ class SupplyDemandView extends Component { pickerImageUrl: imageFile, ImagesInfo: res.data.sdInfo.file_path, isDeleteModal: false, - }) - - }else{ + } else if (res.data.err_code === 88888) { + loginExpired(res) + } else { this.setState({ - isShowAllButtons:false + isShowAllButtons: false }) Taro.showToast({ - title:res.data.err_msg, - icon:'none' + title: res.data.err_msg, + icon: 'none' }) } - + } @@ -139,7 +140,7 @@ class SupplyDemandView extends Component { } }).then(res => { console.log('删除我的列表', res) - if (res.data.err_msg === "success") { + if (res.data.err_code === 0) { Taro.showToast({ title: '删除成功', icon: 'success', @@ -148,6 +149,8 @@ class SupplyDemandView extends Component { setTimeout(() => { this.goToMyNeedsPage() }, 1500); + } else if (res.data.err_code === 88888) { + loginExpired(res) } else { Taro.showToast({ title: res.data.err_msg, @@ -215,12 +218,12 @@ class SupplyDemandView extends Component { // const imageArrayElement = this.state.ImagesInfo.map((item, index) => { // return // }) - const imageArrayElement=this.state.ImagesInfo.map((item, index) => { + const imageArrayElement = this.state.ImagesInfo.map((item, index) => { return - + - }) - + }) + return ( @@ -228,7 +231,7 @@ class SupplyDemandView extends Component { {deleteModalWindowElement} 行业分类: - {this.state.industryTypeSelected.name?this.state.industryTypeSelected.name:'--'} + {this.state.industryTypeSelected.name ? this.state.industryTypeSelected.name : '--'} 需求标题: @@ -255,9 +258,9 @@ class SupplyDemandView extends Component { {this.state.content} - {this.state.ImagesInfo.length?业主需求图片::null} - {imageArrayElement} - + {this.state.ImagesInfo.length ? 业主需求图片: : null} + {imageArrayElement} + @@ -270,40 +273,40 @@ class SupplyDemandView extends Component { :null } */} - {this.state.isShowAllButtons? + {this.state.isShowAllButtons ? - - - - - + + + - - - - : - - + + - - - - } + : + + + + + + + } diff --git a/src/pages/mySupplyDemand/mySupplyDemand.js b/src/pages/mySupplyDemand/mySupplyDemand.js index 2aceb26..775d087 100644 --- a/src/pages/mySupplyDemand/mySupplyDemand.js +++ b/src/pages/mySupplyDemand/mySupplyDemand.js @@ -5,7 +5,8 @@ import URL from '../../serviceAPI.config' import ScrollToTopComponent from '../../component/scrollToTopComponent/scrollToTopComponent' import CopyrightComponent from '../../component/copyrightComponent/copyrightComponent' -import LoginService from '../../LoginService' +import LoginService from '../../util/LoginService' +import loginExpired from '../../util/loginExpired' import './mySupplyDemand.scss' @@ -69,7 +70,7 @@ class MySupplyDemand extends Component { }).then(res => { Taro.hideLoading() console.log('我的供求列表', res) - if (res.data.err_msg === "success") { + if (res.data.err_code === 0) { if (this.state.isAddToList) { if (res.data.supplys.length && res.data.count !== '0') { this.setState({ allDemandSupply: this.state.allDemandSupply.concat(res.data.supplys) }, () => { @@ -94,7 +95,11 @@ class MySupplyDemand extends Component { } } - } else { + } else if (res.data.err_code === 88888) { + loginExpired(res) + } + else { + Taro.showToast({ title: res.data.err_msg, icon: 'none', @@ -130,7 +135,7 @@ class MySupplyDemand extends Component { } }) .then(res => { - if (res.data.err_msg == 'success') { + if (res.data.err_code == 0) { console.log('删除成功') Taro.showToast({ title: '删除成功' @@ -138,8 +143,9 @@ class MySupplyDemand extends Component { this.getMySupplyDemand({}) }) + } else if (res.data.err_code === 88888) { + loginExpired(res) } else { - Taro.showToast({ title: res.data.err_msg, icon: 'none' @@ -149,13 +155,7 @@ class MySupplyDemand extends Component { } ) - .catch(error => { - - Taro.showToast({ - title: '删除失败', - icon: 'none' - }) - }) + } // 新增我的供求 @@ -249,7 +249,7 @@ class MySupplyDemand extends Component { componentWillMount() { - + } componentWillReceiveProps(nextProps) { console.log(this.props, nextProps) @@ -262,15 +262,15 @@ class MySupplyDemand extends Component { } componentWillUnmount() { } - componentDidShow() { + componentDidShow() { if (!Taro.getStorageSync('userInfo').user_id) { LoginService() return } - if(!Taro.getStorageSync('shopInfo').shop_id&&Taro.getStorageSync('userInfo').user_id){ + if (!Taro.getStorageSync('shopInfo').shop_id && Taro.getStorageSync('userInfo').user_id) { Taro.showToast({ - title:'您还没有店铺,不能使用该功能,快去申请吧', - icon:'none' + title: '您还没有店铺,不能使用该功能,快去申请吧', + icon: 'none' }) } } diff --git a/src/pages/shop/shop.js b/src/pages/shop/shop.js index 0e0b704..2930ea5 100644 --- a/src/pages/shop/shop.js +++ b/src/pages/shop/shop.js @@ -119,8 +119,6 @@ class Shop extends Component { console.log('筛选项目成功', res) Taro.hideLoading() this.formatFilterData(res.data).then(data => { - console.log('data', data) - this.setState({ sideFilterdata: data, mainType: data.mainType, @@ -275,6 +273,7 @@ class Shop extends Component { }) .then(res => { console.log('searchGood', res) + Taro.hideLoading() if (res.data.goods && res.data.goods.length) { if (this.state.isAddToList) { @@ -319,21 +318,24 @@ class Shop extends Component { }) .then(res => { Taro.hideLoading() + if (res.data.err_msg === 0) { + this.setState({ + shopDescriptionData: res.data, + shopName: res.data.data.shop_name, + shopAddress: res.data.data.shop_address, + contactName: res.data.userRes.name, + contactNumber: res.data.userRes.phone, + shopDescription: res.data.data.shop_desc, + latitude: res.data.data.shop_map.split(',')[1], + longitude: res.data.data.shop_map.split(',')[0], + }) + } else { + Taro.showToast({ + title: res.data.err_msg, + icon: 'none' + }) - this.setState({ - shopDescriptionData: res.data, - shopName: res.data.data.shop_name, - shopAddress: res.data.data.shop_address, - contactName: res.data.userRes.name, - contactNumber: res.data.userRes.phone, - shopDescription: res.data.data.shop_desc, - latitude: res.data.data.shop_map.split(',')[1], - longitude: res.data.data.shop_map.split(',')[0], - - }, () => { - // console.log(this.state.shopDescriptionData) - }) - + } } ) } @@ -803,8 +805,8 @@ class Shop extends Component { - diff --git a/src/pages/supplyDemandPublish/supplyDemandPublish.js b/src/pages/supplyDemandPublish/supplyDemandPublish.js index 8bf40c9..2b566c9 100644 --- a/src/pages/supplyDemandPublish/supplyDemandPublish.js +++ b/src/pages/supplyDemandPublish/supplyDemandPublish.js @@ -4,15 +4,13 @@ import { View, Text, Button, Input } from '@tarojs/components' import { AtInput, AtImagePicker, AtTextarea, Picker } from 'taro-ui' import CopyrightComponent from '../../component/copyrightComponent/copyrightComponent' -import LoginService from '../../LoginService' +import LoginService from '../../util/LoginService' import URL from '../../serviceAPI.config' import './supplyDemandPublish.scss' - - +import loginExpired from '../../util/loginExpired'; class SupplyDemand extends Component { - config = { navigationBarTitleText: '供求发布' } @@ -24,8 +22,8 @@ class SupplyDemand extends Component { demandingSupplyState: [{ name: '上架', id: '1' }, { name: '下架', id: '0' }], // 状态选择 demandingSupplyStateSelected: { name: '上架', id: '1' },// 当前状态 title: '', - contactName: Taro.getStorageSync('user_identity').username, - contactNumber: Taro.getStorageSync('user_identity').userphone, + contactName: Taro.getStorageSync('user_identity').username||'', + contactNumber: Taro.getStorageSync('user_identity').userphone||'', contactAddress: '', content: '', pickerImageUrl: [], // 上传的图片 @@ -96,7 +94,10 @@ class SupplyDemand extends Component { } }, 1000); }) - } else { + } else if (res.data.err_code === 88888) { + loginExpired(res) + } + else { Taro.showToast({ title: res.data.err_msg, icon: 'none', @@ -261,10 +262,10 @@ class SupplyDemand extends Component { LoginService() return } - if(!Taro.getStorageSync('shopInfo').shop_id&&Taro.getStorageSync('userInfo').user_id){ + if (!Taro.getStorageSync('shopInfo').shop_id && Taro.getStorageSync('userInfo').user_id) { Taro.showToast({ - title:'您还没有店铺,不能使用该功能,快去申请吧', - icon:'none' + title: '您还没有店铺,不能使用该功能,快去申请吧', + icon: 'none' }) } } diff --git a/src/pages/supplyDemandView/supplyDemandView.js b/src/pages/supplyDemandView/supplyDemandView.js index 05a5e72..d535937 100644 --- a/src/pages/supplyDemandView/supplyDemandView.js +++ b/src/pages/supplyDemandView/supplyDemandView.js @@ -1,13 +1,14 @@ import Taro, { Component } from '@tarojs/taro' -import { View, Text, Image,Button } from '@tarojs/components' -import { AtIcon,AtModal, AtModalHeader, AtModalContent, AtModalAction } from 'taro-ui' +import { View, Text, Image, Button } from '@tarojs/components' +import { AtIcon, AtModal, AtModalHeader, AtModalContent, AtModalAction } from 'taro-ui' import URL from '../../serviceAPI.config' import CopyrightComponent from '../../component/copyrightComponent/copyrightComponent' import './supplyDemandView.scss' +import loginExpired from '../../util/loginExpired'; @@ -19,7 +20,7 @@ class SupplyDemandView extends Component { constructor() { super(...arguments) this.state = { - demandingSupplyCate: [{name:'需求',id:'1'}, {name:'供求',id:'2'}, {name:'人才',id:'3'}], //供求类型选择 + demandingSupplyCate: [{ name: '需求', id: '1' }, { name: '供求', id: '2' }, { name: '人才', id: '3' }], //供求类型选择 type: '', title: '', browsing: '', @@ -28,7 +29,7 @@ class SupplyDemandView extends Component { address: '', content: '', images: [], - isDeleteModal:false + isDeleteModal: false } } //获取商品信息api GetProductInfo @@ -48,74 +49,71 @@ class SupplyDemandView extends Component { }) .then(res => { console.log('供求详情获取成功', res) + if (res.data.err_code === 0) { + const selectedType = this.state.demandingSupplyCate.filter(item => item.id === res.data.sdInfo.sd_type)[0].name + this.setState({ + type: selectedType, + title: res.data.sdInfo.sd_title, + browsing: res.data.sdInfo.browse_times, + contactName: res.data.sdInfo.user_name, + contactNumber: res.data.sdInfo.user_phone, + address: res.data.sdInfo.user_address, + content: res.data.sdInfo.sd_desc, + images: res.data.sdInfo.file_path, + itemId: res.data.sdInfo.sd_id + }) + Taro.hideLoading() + } else if (res.data.err_code === 88888) { + loginExpired(res) + } - - const selectedType=this.state.demandingSupplyCate.filter(item=> item.id===res.data.sdInfo.sd_type)[0].name - this.setState({ - type: selectedType, - title: res.data.sdInfo.sd_title, - browsing: res.data.sdInfo.browse_times, - contactName: res.data.sdInfo.user_name, - contactNumber: res.data.sdInfo.user_phone, - address: res.data.sdInfo.user_address, - content: res.data.sdInfo.sd_desc, - images: res.data.sdInfo.file_path, - itemId:res.data.sdInfo.sd_id - }) - Taro.hideLoading() } ) - .catch(error => { - console.log('供求详情获取失败', error) - }) + } - // 删除我的供求api - onDelete({ sdID = 0 }) { + // 删除我的供求api + onDelete({ sdID = 0 }) { Taro.request({ - url: URL.DeleteDemandSupply, - method: 'POST', - dataType: 'json', - data: { - sdID: sdID - }, - header: { - 'content-type': 'application/x-www-form-urlencoded', - 'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'), - 'X-Requested-With': 'XMLHttpRequest' - } + url: URL.DeleteDemandSupply, + method: 'POST', + dataType: 'json', + data: { + sdID: sdID + }, + header: { + 'content-type': 'application/x-www-form-urlencoded', + 'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'), + 'X-Requested-With': 'XMLHttpRequest' + } }) - .then(res => { - if (res.data.err_msg == 'success') { - console.log('删除成功') - Taro.showToast({ - title: '删除成功', - icon:'success', - duration:1500 - }).then(() => { - setTimeout(() => { - this.goToMySDPage() - }, 1500); - }) + .then(res => { + if (res.data.err_code == 0) { + console.log('删除成功') + Taro.showToast({ + title: '删除成功', + icon: 'success', + duration: 1500 + }).then(() => { + setTimeout(() => { + this.goToMySDPage() + }, 1500); + }) - } else { + } else if (res.data.err_code === 88888) { + loginExpired(res) + } else { - Taro.showToast({ - title: res.data.err_msg, - icon: 'none' - }) - - } + Taro.showToast({ + title: res.data.err_msg, + icon: 'none' + }) } - ) - .catch(error => { - Taro.showToast({ - title: '删除失败', - icon: 'none' - }) - }) -} + } + ) + + } goToSDPublishPage() { Taro.reLaunch({ url: '/pages/supplyDemandPublish/supplyDemandPublish',// 供求发布页面 @@ -124,21 +122,21 @@ class SupplyDemandView extends Component { // 跳转到我的供求编辑页面 goToMyDSEditPage() { Taro.navigateTo({ - url: '/pages/myDemandSupplyEdit/myDemandSupplyEdit?sdId=' + this.state.itemId + url: '/pages/myDemandSupplyEdit/myDemandSupplyEdit?sdId=' + this.state.itemId }) -} + } goToMySDPage() { Taro.reLaunch({ url: '/pages/mySupplyDemand/mySupplyDemand',//我的供求页面 }) } - makeAPhoneCall(){ + makeAPhoneCall() { Taro.makePhoneCall({ phoneNumber: this.state.contactNumber }) } - + deleteButton() { this.setState({ isDeleteModal: true }) } @@ -152,7 +150,7 @@ class SupplyDemandView extends Component { componentDidMount() { - Taro.showLoading({title:'加载中'}) + Taro.showLoading({ title: '加载中' }) this.getSupplyDemandInfo() } componentWillReceiveProps(nextProps) { @@ -174,15 +172,15 @@ class SupplyDemandView extends Component { }) const deleteModalWindowElement = - 提示 - - 确认删除{this.state.needsItem.sd_title}? + 提示 + + 确认删除{this.state.needsItem.sd_title}? - - + + return ( - {deleteModalWindowElement} + {deleteModalWindowElement} 供求类型: {this.state.type} @@ -220,22 +218,22 @@ class SupplyDemandView extends Component { - - - - diff --git a/src/LoginService.js b/src/util/LoginService.js similarity index 74% rename from src/LoginService.js rename to src/util/LoginService.js index 77d8ef7..b0320d2 100644 --- a/src/LoginService.js +++ b/src/util/LoginService.js @@ -1,27 +1,26 @@ import Taro from '@tarojs/taro' -import URL from './serviceAPI.config' -//用户信息姓名和电话号码接口 -const setUserInfoToStorage=()=>{ - Taro.request({ - url: URL.ShopWxStore, - header: { - 'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'), - } - }) - .then(res => { - if (res.data.err_msg === 'success') { - Taro.setStorageSync('user_identity', { username: res.data.otherData.userName, userphone: res.data.otherData.userPhone }) +// //用户信息姓名和电话号码接口 +// const setUserInfoToStorage=()=>{ +// Taro.request({ +// url: URL.ShopWxStore, +// header: { +// 'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'), +// } +// }) +// .then(res => { +// if (res.data.err_msg === 'success') { +// Taro.setStorageSync('user_identity', { username: res.data.otherData.userName, userphone: res.data.otherData.userPhone }) - } else { - Taro.showToast({ - title: res.data.err_msg, - icon: 'none', - duration: 1500 - }) - } - }) -} +// } else { +// Taro.showToast({ +// title: res.data.err_msg, +// icon: 'none', +// duration: 1500 +// }) +// } +// }) +// } diff --git a/src/util/loginExpired.js b/src/util/loginExpired.js new file mode 100644 index 0000000..e08f09e --- /dev/null +++ b/src/util/loginExpired.js @@ -0,0 +1,14 @@ +import Taro from '@tarojs/taro' + + export default function loginExpired(res){ + Taro.clearStorageSync() + Taro.showToast({ + title: res.data.err_msg, + icon: 'none' + }) + setTimeout(() => { + Taro.reLaunch({ + url: '/pages/home/home' + }) + }, 1500); +} \ No newline at end of file diff --git a/src/util/weChatLogin.js b/src/util/weChatLogin.js new file mode 100644 index 0000000..0ec42ca --- /dev/null +++ b/src/util/weChatLogin.js @@ -0,0 +1,75 @@ +import Taro from '@tarojs/taro' +import URL from '../serviceAPI.config' + +//用户信息姓名和电话号码接口 +const setUserInfoToStorage = () => { + Taro.request({ + url: URL.ShopWxStore, + header: { + 'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'), + } + }) + .then(res => { + if (res.data.err_msg === 'success') { + Taro.setStorageSync('user_identity', { username: res.data.otherData.userName, userphone: res.data.otherData.userPhone }) + + } else { + Taro.showToast({ + title: res.data.err_msg, + icon: 'none', + duration: 1500 + }) + } + }) +} + + + +// 异步函数登入api +export default function login() { + Taro.login({ + success(res) { + if (res.code) { + // 发起网络请求 + console.log('手机端微信code:', res.code) + Taro.request({ + url: URL.Login, + method: 'POST', + dataType: 'json', + data: { + code: res.code + }, + header: { + 'content-type': 'application/x-www-form-urlencoded', + } + }) + .then(response => { + if (response.data.err_code === 0) { + console.log('微信登入成功', response) + Taro.showToast({ + title: '微信登入成功', + icon: 'success', + duration: 2000 + }) + Taro.setStorageSync('session_id', response.data.session_id) + Taro.setStorageSync('shopInfo', response.data.shop_info) + Taro.setStorageSync('userInfo', response.data.user_info) + setUserInfoToStorage() + } else { + Taro.showToast({ + title: '微信登入失败', + icon: 'none', + duration: 2000 + }) + // Taro.clearStorageSync() + } + + } + ) + } + else { + console.log('登录失败!' + res.errMsg) + } + } + }) +} \ No newline at end of file diff --git a/src/weChatLogin.js b/src/weChatLogin.js deleted file mode 100644 index 499101e..0000000 --- a/src/weChatLogin.js +++ /dev/null @@ -1,73 +0,0 @@ -import Taro from '@tarojs/taro' -import URL from './serviceAPI.config' - -//用户信息姓名和电话号码接口 -const setUserInfoToStorage=()=>{ - Taro.request({ - url: URL.ShopWxStore, - header: { - 'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'), - } - }) - .then(res => { - if (res.data.err_msg === 'success') { - Taro.setStorageSync('user_identity', { username: res.data.otherData.userName, userphone: res.data.otherData.userPhone }) - - } else { - Taro.showToast({ - title: res.data.err_msg, - icon: 'none', - duration: 1500 - }) - } - }) -} - - - -// 异步函数登入api -export default function login() { - Taro.login({ - success(res) { - if (res.code) { - // 发起网络请求 - console.log('手机端微信code:',res.code) - Taro.request({ - url: URL.Login, - method: 'POST', - dataType: 'json', - data: { - code: res.code - }, - header: { - 'content-type': 'application/x-www-form-urlencoded', - } - }) - .then(response => { - if (response.data.err_code === 0) { - console.log('微信登入成功', response) - Taro.showToast({ - title: '微信登入成功', - icon: 'success', - duration: 2000 - }) - Taro.setStorageSync('session_id', response.data.session_id) - Taro.setStorageSync('shopInfo', response.data.shop_info) - Taro.setStorageSync('userInfo', response.data.user_info) - setUserInfoToStorage() - }else{ - Taro.showToast({ - title: '微信登入失败', - icon: 'none', - duration: 2000 - }) - } - } - ) - } - else { - console.log('登录失败!' + res.errMsg) - } - } - }) -} \ No newline at end of file