diff --git a/src/component/filteredShopComponent/filteredShopComponent.js b/src/component/filteredShopComponent/filteredShopComponent.js
index 6a9ad31..cda10c5 100644
--- a/src/component/filteredShopComponent/filteredShopComponent.js
+++ b/src/component/filteredShopComponent/filteredShopComponent.js
@@ -32,10 +32,11 @@ class recommondShop extends Component {
isOpenVoucher: false,
isOpenConsult: false,
consultTip: '',
- voucherResponseMsg: '',
- voucherCanConsult: false,
+ voucherResponseMsg: 'i am voucherResponseMsg',
userName: Taro.getStorageSync('user_identity').username || '',
userPhone: Taro.getStorageSync('user_identity').userphone || '',
+ canConsult: false
+
}
}
goToShop(value) {
@@ -44,20 +45,28 @@ class recommondShop extends Component {
})
}
// api 优惠卷请求
- getVoucherInfo({ user = "某某人", phone = "18950295811", shops = ["808"], source_type = 4, flag = false, source_class = "1", source_level = 1 }) {
+ getVoucherInfo({ user = this.state.userName,
+ phone = this.state.userPhone,
+ shops = [this.props.shop.shop_id],
+ source_type = 4,
+ flag = false,
+ source_level = this.props.categoryLevel }) {
Taro.request({
url: URL.GetVoucherInfo,
method: 'POST',
dataType: 'json',
data: {
- user: user,
- phone: phone,
- shops: shops,
- source_type: source_type,
- flag: flag,
- source_class: source_class,
- source_level: source_level
+ data: JSON.stringify({
+ user: user,
+ phone: phone,
+ shops: shops,
+ source_type: source_type,
+ flag: flag,
+ source_level: source_level
+ })
},
+
+
header: {
'content-type': 'application/x-www-form-urlencoded',
'X-Requested-With': 'XMLHttpRequest',
@@ -67,7 +76,7 @@ class recommondShop extends Component {
.then(res => {
this.setState({
voucherResponseMsg: res.data.tips,
- voucherCanConsult: res.data.canConsult
+ canConsult: res.data.canConsult,
})
console.log('优惠卷请求', res)
})
@@ -75,18 +84,27 @@ class recommondShop extends Component {
}
// api 咨询信息
- getConsultInfo({ user = "某某人", phone = "18950295811", shops = ["1306"], source_type = "2", flag = false, source_level = 1 }) {
+ getConsultInfo({
+ user = this.state.userName,
+ phone = this.state.userPhone,
+ shops = [this.props.shop.shop_id],
+ source_type = "2",
+ flag = false,
+ source_level = this.props.categoryLevel,
+ }) {
Taro.request({
url: URL.GetConsultInfo,
method: 'POST',
dataType: 'json',
data: {
- user: user,
- phone: phone,
- shops: shops,
- source_type: source_type,
- flag: flag,
- source_level: source_level
+ data: JSON.stringify({
+ user: user,
+ phone: phone,
+ shops: shops,
+ source_type: source_type,
+ flag: flag,
+ source_level: source_level,
+ })
},
header: {
'content-type': 'application/x-www-form-urlencoded',
@@ -100,7 +118,12 @@ class recommondShop extends Component {
})
}
// api 购买咨询 BuyConsult
- buyConsult({ user = "某某人", phone = "18950295811", shops = ["1306"], source_type = "2", source_level = 1, coupons_flag = 0 }) {
+ buyConsult({ user = this.state.userName,
+ phone = this.state.userPhone,
+ shops = [this.props.shop.shop_id],
+ source_type = "2",
+ source_level = 1,
+ coupons_flag = 0 }) {
Taro.request({
url: URL.BuyConsult,
method: 'POST',
@@ -123,7 +146,7 @@ class recommondShop extends Component {
})
.then(res => {
console.log('购买咨询请求成功', res)
- if (res.statusCode === 200) {
+ if (res.data.err_code === 0) {
Taro.showToast({ title: '咨询成功', icon: 'success' })
} else {
Taro.showToast({ title: res.data.err_msg, icon: 'none' })
@@ -134,38 +157,39 @@ class recommondShop extends Component {
})
}
-
-
+
+
// 咨询弹框。取消。确认
isOpenConsult() {
this.setState({
isOpenConsult: true,
- userName: Taro.getStorageSync('user_identity').username,
- userPhone: Taro.getStorageSync('user_identity').userphone,
+
+ }, () => {
+ this.getConsultInfo({})
})
- this.getConsultInfo({})
+
}
consultModalClose() {
this.setState({ isOpenConsult: false })
}
consultModalConfirm() {
- if(!this.state.userName){
+ if (!this.state.userName) {
Taro.showToast({
title: '请填写姓名',
icon: 'none',
- })
-
- }else if(!this.state.userPhone){
+ })
+
+ } else if (!this.state.userPhone) {
Taro.showToast({
title: '请填写电话',
icon: 'none',
- })
-
- }else{
+ })
+
+ } else {
this.setState({ isOpenConsult: false })
this.buyConsult({ user: this.state.userName, phone: this.state.userPhone })
}
-
+
}
handleInputCsultName(e) {
this.setState({ userName: e.detail.value })
@@ -177,14 +201,21 @@ class recommondShop extends Component {
console.log('从voucherposter件传回来的值', value)
this.setState({ isOpenVoucher: value })
}
- isOpenVoucher(){
- this.setState({isOpenVoucher:true})
+ isOpenVoucher() {
+
+ this.setState({
+ isOpenVoucher: true,
+ userName: Taro.getStorageSync('user_identity').username,
+ userPhone: Taro.getStorageSync('user_identity').userphone
+ }, () => {
+ this.getVoucherInfo({})
+ })
}
componentWillReceiveProps(nextProps) {
//console.log(this.props, nextProps)
}
componentDidMount() {
-
+ console.log('this.props', this.props)
}
componentWillUnmount() { }
@@ -194,6 +225,7 @@ class recommondShop extends Component {
render() {
+
const title = this.props.shop.shop_name
const imgUrl = URL.Base + this.props.shop.goods[0].goods_url
const price = this.props.shop.goods[0].goods_price
@@ -247,20 +279,24 @@ class recommondShop extends Component {
/>
-
+
+// {this.props.canConsult?:}
return (
{consultModalElement}
diff --git a/src/component/filteredShopComponent/voucherPosterComponent/voucherPosterComponent.js b/src/component/filteredShopComponent/voucherPosterComponent/voucherPosterComponent.js
index f30e1ae..a9a287d 100644
--- a/src/component/filteredShopComponent/voucherPosterComponent/voucherPosterComponent.js
+++ b/src/component/filteredShopComponent/voucherPosterComponent/voucherPosterComponent.js
@@ -17,13 +17,20 @@ class VoucherPoster extends Component {
constructor() {
super(...arguments);
this.state = {
- voucherName: this.props.userName,
- voucherPhone: this.props.userPhone,
+ voucherName: this.props.name,
+ voucherPhone: this.props.phone,
+
voucherPosterImage: 'background-image:url(' + URL.Base + '/Public/images/store/m_yhq.png);'
}
}
// api 购买咨询 BuyConsult
- buyConsult({ user = "某某人", phone = "18950295811", shops = ["1306"], source_type = "2", source_level = 1, coupons_flag = 0 }) {
+ buyConsult({
+ user = this.state.voucherName,
+ phone = this.state.voucherPhone,
+ shops = [this.props.shopId],
+ source_type = '4',
+ source_level = this.props.categoryLevel,
+ coupons_flag = '1' }) {
Taro.request({
url: URL.BuyConsult,
method: 'POST',
@@ -46,7 +53,6 @@ class VoucherPoster extends Component {
})
.then(res => {
console.log('购买咨询请求成功', res)
-
if (res.data.err_code === 0) {
Taro.showToast({
title: '领取成功',
@@ -57,9 +63,9 @@ class VoucherPoster extends Component {
this.passDataToParent()
}, 1500);
- }else if (res.data.err_code === 88888) {
- loginExpired(res)
- } else {
+ } else if (res.data.err_code === 88888) {
+ loginExpired(res)
+ } else {
Taro.showToast({
title: res.data.err_msg,
icon: 'none',
@@ -78,13 +84,13 @@ class VoucherPoster extends Component {
title: '请填写姓名',
icon: 'none',
})
- } else if (!this.state.voucherPhone) {
+ } else if (this.state.voucherPhone.length !== 11) {
Taro.showToast({
- title: '请填写电话号码',
+ title: '请填正确的电话号码',
icon: 'none',
})
} else {
- this.buyConsult({ user: this.state.voucherName, phone: this.state.voucherPhone })
+ this.buyConsult({})
}
@@ -101,10 +107,7 @@ class VoucherPoster extends Component {
this.props.onPassDataToChild(false)
}
componentWillReceiveProps(nextProps) {
- this.setState({
- voucherName: nextProps.userName,
- voucherPhone: nextProps.userPhone,
- })
+
}
componentDidMount() {
@@ -118,6 +121,7 @@ class VoucherPoster extends Component {
componentDidHide() { }
render() {
+ console.log('i am poster')
return (
{/* */}
@@ -133,21 +137,16 @@ class VoucherPoster extends Component {
联系人:
-
+
-
联系电话:
-
+
-
-
-
-
- {this.props.voucherResponseMsg}
+ {this.props.canConsult ? '' : this.props.voucherResponseMsg}
diff --git a/src/component/goodsTypeInteractionComp/goodsTypeInteractionComp.js b/src/component/goodsTypeInteractionComp/goodsTypeInteractionComp.js
index 24f12ba..af67340 100644
--- a/src/component/goodsTypeInteractionComp/goodsTypeInteractionComp.js
+++ b/src/component/goodsTypeInteractionComp/goodsTypeInteractionComp.js
@@ -42,15 +42,25 @@ class GoodsTypeInteractionComp extends Component {
.then(res => {
if (res.data.err_code === 0) {
console.log('商品分类目录', res)
-
+
const recursionInteractionData=this.recursionInteraction(res.data.data)
+ maxDepth=0
+ initialDataArray=[]
+
this.recursionInitialized(res.data.data) //
+ const depthInArray=this.recursionDepth(res.data.data)
+ console.log('depthInArray',depthInArray)
+ console.log('initialDataArray',initialDataArray)
+ for(let i=initialDataArray.length;i {
- initialDataArray=[]// 把全局变变量赋值给state之后,初始化商品分类为空, 不然第二次进去的时候会自动添加进去
+ // 把全局变变量赋值给state之后,初始化商品分类为空, 不然第二次进去的时候会自动添加进去
// console.log('联动数据', this.state.interactionMultiArray)
// console.log('初始化数据', this.state.initailMultiArray)
@@ -107,7 +117,6 @@ class GoodsTypeInteractionComp extends Component {
for (let item of data) {
arrayTem.push({ name: item.class_name, id: item.class_id })
}
-
}
if(data[0].children.length){
this.recursionInitialized(data[0].children)
@@ -126,7 +135,7 @@ class GoodsTypeInteractionComp extends Component {
if (items.children) {
arrayTem[arrayTem.length - 1].children = this.recursionInteraction(items.children)
} else {
- arrayTem[arrayTem.length - 1].children = [{ name: '', id: '' }]
+ arrayTem[arrayTem.length - 1].children = [{ name: '--', id: '' }]
}
}
return arrayTem // 返回联动数据
@@ -178,9 +187,6 @@ class GoodsTypeInteractionComp extends Component {
for (let index in data.multiArray[0]) {
const indexNumber = Number(index)
if (indexNumber === data.multiIndex[0]) {
- // data.multiArray[1] = this.state.interactionMultiArray[indexNumber].children
- // data.multiArray[2] = this.state.interactionMultiArray[indexNumber].children[0].children
- // data.multiArray[3] = this.state.interactionMultiArray[indexNumber].children[0].children[0].children
data.multiArray[1] = this.state.interactionMultiArray[indexNumber].children
data.multiArray[2] = this.state.interactionMultiArray[indexNumber].children[data.multiIndex[1]].children
data.multiArray[3] = this.state.interactionMultiArray[indexNumber].children[data.multiIndex[1]].children[data.multiIndex[2]].children
diff --git a/src/component/goodsTypeInteractionComp/goodsTypeInteractionComp.scss b/src/component/goodsTypeInteractionComp/goodsTypeInteractionComp.scss
index b801983..b4d4705 100644
--- a/src/component/goodsTypeInteractionComp/goodsTypeInteractionComp.scss
+++ b/src/component/goodsTypeInteractionComp/goodsTypeInteractionComp.scss
@@ -24,7 +24,7 @@
.first-col{
font-weight: normal;
- margin-left: 2%
+ margin-left: 10%
}
.second-col{
font-weight: normal;
diff --git a/src/component/interactionComponent/interactionComponent.js b/src/component/interactionComponent/interactionComponent.js
index 053db69..8077912 100644
--- a/src/component/interactionComponent/interactionComponent.js
+++ b/src/component/interactionComponent/interactionComponent.js
@@ -41,25 +41,23 @@ class Interaction extends Component {
}
}).then(res => {
if (res.data.err_code === 0) {
- console.log('行业分类目录', res)
+
let initailMultiArray = this.recursionInitialized(res.data.data)
- initialDataArray[1].unshift({ name: '全部', id: '-1' }) // 默认
+ initailMultiArray[1].unshift({ name: '全部', id: '-1' })
+ initailMultiArray[0] = [{ name: '--', id: '' }]
+ console.log('initailMultiArray', initailMultiArray)
+
+
this.setState({
- initailMultiArray: [initailMultiArray[1]], //initailMultiArray.reverse(),
- interactionMultiArray: [{ name: '全部', id: '-1', children: [{ name: '', id: '' }] }, ...this.recursionInteraction(res.data.data)],
+ initailMultiArray: initailMultiArray.reverse(), //initailMultiArray.reverse(),
+ interactionMultiArray: [{ name: '全部', id: '-1', children: [{ name: '--', id: '' }] }, ...this.recursionInteraction(res.data.data)],
multiIndex: this.recursionDepth(res.data.data),
-
}, () => {
- console.log('interactionMultiArray',this.state.interactionMultiArray)
- initialDataArray = []// 把全局变变量赋值给state之后,初始化商品分类为空, 不然第二次进去的时候会自动添加进去
- // console.log('联动数据', this.state.interactionMultiArray)
- // console.log('初始化数据', this.state.initailMultiArray)
+ initialDataArray = []
+ })
-
- }) // 用递归来整理无限层次的数据
-
- }else if (res.data.err_code === 88888) {
- loginExpired(res)
+ } else if (res.data.err_code === 88888) {
+ // loginExpired(res)
} else {
console.log('行业分类请求没有成功', res)
}
@@ -75,9 +73,9 @@ class Interaction extends Component {
for (let items of data) {
arrayTem.push({ name: items.class_name, id: items.class_id })
if (items.child.length) {
- arrayTem[arrayTem.length - 1].children = [{ name: '可选', id: '' }, ...this.recursionInteraction(items.child)]
+ arrayTem[arrayTem.length - 1].children = [{ name: '--', id: '' }, ...this.recursionInteraction(items.child)]
} else {
- arrayTem[arrayTem.length - 1].children = [{ name: '', id: '' }]
+ arrayTem[arrayTem.length - 1].children = [{ name: '--', id: '' }]
}
}
return arrayTem // 返回联动数据
@@ -90,7 +88,9 @@ class Interaction extends Component {
if (data.length) {
for (let item of data) {
arrayTem.push({ name: item.class_name, id: item.class_id })
- item.child.length ? childrenHolderArray.push(...item.child) : null
+ if (data.indexOf(item) === 0) {
+ item.child.length ? childrenHolderArray.push(...item.child) : null
+ }
}
this.recursionInitialized(childrenHolderArray)
}
@@ -113,7 +113,7 @@ class Interaction extends Component {
}
bindMultiPickerCol(e) {
console.log('修改的列为', e.detail.column, ',值为', e.detail.value)
-
+
const data = {
multiArray: this.state.initailMultiArray,
multiIndex: this.state.multiIndex
@@ -124,7 +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)
+ console.log('datat', data)
}
}
}
diff --git a/src/pages/goodsPublish/goodsPublish.js b/src/pages/goodsPublish/goodsPublish.js
index 156aee4..aaaa74d 100644
--- a/src/pages/goodsPublish/goodsPublish.js
+++ b/src/pages/goodsPublish/goodsPublish.js
@@ -391,7 +391,7 @@ class GoodsPublish extends Component {
diff --git a/src/pages/home/home.js b/src/pages/home/home.js
index 2c99f25..2f9f60c 100644
--- a/src/pages/home/home.js
+++ b/src/pages/home/home.js
@@ -189,7 +189,6 @@ class Home extends Component {
Taro.showLoading({
title: '加载中'
})
- console.log('item', item)
this.setState({ parentClass: item.class_id, childClass: item.class_id, supplyLevel: 1, subCate: item.children || [] }, () => {
this.getShops({})
})
@@ -382,6 +381,8 @@ class Home extends Component {
return
}) : 没有更多了
const subCateElementsArray = this.state.subCate.length ? this.state.subCate.map((item, index) => {
diff --git a/src/pages/myDemandSupplyEdit/myDemandSupplyEdit.js b/src/pages/myDemandSupplyEdit/myDemandSupplyEdit.js
index bd06756..4fec13b 100644
--- a/src/pages/myDemandSupplyEdit/myDemandSupplyEdit.js
+++ b/src/pages/myDemandSupplyEdit/myDemandSupplyEdit.js
@@ -412,7 +412,7 @@ class MyDemandSupplyEdit extends Component {
@@ -423,7 +423,7 @@ class MyDemandSupplyEdit extends Component {
diff --git a/src/pages/myGoodsEdit/myGoodsEdit.js b/src/pages/myGoodsEdit/myGoodsEdit.js
index 16dd722..0fb7823 100644
--- a/src/pages/myGoodsEdit/myGoodsEdit.js
+++ b/src/pages/myGoodsEdit/myGoodsEdit.js
@@ -443,7 +443,7 @@ class MyGoodsEdit extends Component {
diff --git a/src/pages/myNeeds/myNeeds.js b/src/pages/myNeeds/myNeeds.js
index 3b651d2..78393b3 100644
--- a/src/pages/myNeeds/myNeeds.js
+++ b/src/pages/myNeeds/myNeeds.js
@@ -69,15 +69,15 @@ class MyNeeds extends Component {
state: state
})
} : {
- param: JSON.stringify({
- curr_page: curr_page,
- page_count: page_count,
- sd_type: sd_type,
- sd_title: sd_title,
- update_dateL: update_dateL,
- update_dateU: update_dateU,
- class_id: class_id,
- })
+ param: JSON.stringify({
+ curr_page: curr_page,
+ page_count: page_count,
+ sd_type: sd_type,
+ sd_title: sd_title,
+ update_dateL: update_dateL,
+ update_dateU: update_dateU,
+ class_id: class_id,
+ })
}
Taro.request({
@@ -104,33 +104,35 @@ class MyNeeds extends Component {
} else {
this.setState({ isAddToList: false })
this.setState({
- allNeedsList: res.data.supplys,
- totalNeeds:Number(res.data.count)
+ allNeedsList: res.data.supplys,
+ totalNeeds: Number(res.data.count)
})
}
} else {
- if(this.state.isAddToList){
+ if (this.state.isAddToList) {
this.setState({ isAddToList: false })
Taro.showToast({
title: '没有更多了',
icon: 'none'
})
- }else{
- this.setState({allNeedsList:[],totalNeeds:0})
+ } else {
+ this.setState({ allNeedsList: [], totalNeeds: 0 })
}
-
- }
- } else {
- if(JSON.parse(res.data).err_code===88888){
- loginExpired(res)
- }else{
- Taro.showToast({
- title: res.data.err_msg,
- icon: 'none'
- })
}
-
+ } else if (JSON.parse(res.data).err_code === 88888) {
+ const response={data:JSON.parse(res.data)}
+ loginExpired(response)
+
+ }
+ else {
+
+ Taro.showToast({
+ title: res.data.err_msg,
+ icon: 'none'
+ })
+
+
}
})
@@ -163,9 +165,9 @@ class MyNeeds extends Component {
this.getMyNeedsList({
})
}, 1500);
- }else if (res.data.err_code === 88888) {
+ } else if (res.data.err_code === 88888) {
loginExpired(res)
- } else {
+ } else {
Taro.showToast({
title: res.data.err_msg,
icon: 'none',
@@ -250,10 +252,10 @@ class MyNeeds extends Component {
})
}
goToMyNeedsViewPage(Id) {
- Taro.navigateTo({
- url: '/pages/grabOrderPage/grabOrderPage?orderId=' + Id
- })
-
+ Taro.navigateTo({
+ url: '/pages/grabOrderPage/grabOrderPage?orderId=' + Id
+ })
+
}
goToMyNeedsEditPage(id) {
Taro.navigateTo({
@@ -292,8 +294,8 @@ class MyNeeds extends Component {
if (!Taro.getStorageSync('userInfo').user_id) {
LoginService()
return
+ }
}
- }
componentDidHide() { }
@@ -454,7 +456,7 @@ class MyNeeds extends Component {
{/* 我的需求信息 */}
{
- {this.state.allNeedsList.length?myNeedsListArrayElement:没有更多了}
+ {this.state.allNeedsList.length ? myNeedsListArrayElement : 没有更多了}
}
{this.state.isShowTopNav ? : null}
diff --git a/src/pages/myNeedsEdit/myNeedsEdit.js b/src/pages/myNeedsEdit/myNeedsEdit.js
index 7707117..5d8ea04 100644
--- a/src/pages/myNeedsEdit/myNeedsEdit.js
+++ b/src/pages/myNeedsEdit/myNeedsEdit.js
@@ -462,7 +462,7 @@ class MyNeedsEdit extends Component {
@@ -473,7 +473,7 @@ class MyNeedsEdit extends Component {
diff --git a/src/pages/myNeedsPublish/myNeedsPublish.js b/src/pages/myNeedsPublish/myNeedsPublish.js
index 5f85660..1a7b00e 100644
--- a/src/pages/myNeedsPublish/myNeedsPublish.js
+++ b/src/pages/myNeedsPublish/myNeedsPublish.js
@@ -27,8 +27,8 @@ class MyNeedsPublish extends Component {
needsType: [{ name: '业主需求', id: '4' }, { name: '效果图', id: '5' }],
needsTypeSelected: { name: '业主需求', id: '4' },
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: [], // 上传的图片
@@ -337,7 +337,7 @@ class MyNeedsPublish extends Component {
@@ -348,7 +348,7 @@ class MyNeedsPublish extends Component {
diff --git a/src/pages/shop/shop.js b/src/pages/shop/shop.js
index 2930ea5..f55452d 100644
--- a/src/pages/shop/shop.js
+++ b/src/pages/shop/shop.js
@@ -318,7 +318,7 @@ class Shop extends Component {
})
.then(res => {
Taro.hideLoading()
- if (res.data.err_msg === 0) {
+ if (res.data.err_code === 0) {
this.setState({
shopDescriptionData: res.data,
shopName: res.data.data.shop_name,
diff --git a/src/pages/supplyDemandPublish/supplyDemandPublish.js b/src/pages/supplyDemandPublish/supplyDemandPublish.js
index 2b566c9..bb1283d 100644
--- a/src/pages/supplyDemandPublish/supplyDemandPublish.js
+++ b/src/pages/supplyDemandPublish/supplyDemandPublish.js
@@ -280,7 +280,8 @@ class SupplyDemand extends Component {
- *供求类型: {this.state.demandingSupplyCateSelected.name}
+ *供求类型:
+ {this.state.demandingSupplyCateSelected.name}
@@ -288,7 +289,8 @@ class SupplyDemand extends Component {
- **
+
@@ -341,7 +343,7 @@ class SupplyDemand extends Component {
diff --git a/src/todo list.txt b/src/todo list.txt
index 204af61..d5bd069 100644
--- a/src/todo list.txt
+++ b/src/todo list.txt
@@ -19,52 +19,372 @@ bug: 商品编辑 增加图片后 图片顺序乱了
等待后台--- 单个我的商品页面的图片顺序,单个我的需求页面的接口, 当个我哦的需求编辑页面的接口
+import Taro, { Component } from '@tarojs/taro'
+import { View, Text } from '@tarojs/components'
- const selfAndAvailable = localStoageUserId === this.state.userId && this.state.stateId === '1' &&
-
-
-
-
-
-
-
-
+import { Picker } from 'taro-ui'
+
+import './goodsTypeInteractionComp.scss'
+import loginExpired from '../../util/loginExpired'
+
+let maxDepth = 0
+let initialDataArray = []
+class GoodsTypeInteractionComp extends Component {
+
+ config = {
+ navigationBarTitleText: 'goodsTypeInteractionComp'
+ }
+ constructor() {
+ super(...arguments);
+
+ this.state = {
+ ///---行业分类 开始
+ initailMultiArray: [[{ class_name: '选择商品分类', class_id: '' }], [], []], // 初始化底部数据
+ multiIndex: [0, 0, 0, 0],// 默认联动列数为4个并且每一列都是第一行
+ interactionMultiArray: [],// 联动
+
+
+ ///---行业分类 结束
+ }
+
+ }
+ //商品目录请求api GetShopCategoryList
+ getProductCateList(url) {
+ Taro.request({
+ url: url,
+ method: 'POST',
+ dataType: 'json',
+ header: {
+ 'content-type': 'application/x-www-form-urlencoded',
+ 'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'),
+ 'X-Requested-With': 'XMLHttpRequest'
+ }
+ })
+ .then(res => {
+ if (res.data.err_code === 0) {
+ console.log('商品分类目录', res)
+
+ const recursionInteractionData=this.recursionInteraction(res.data.data)
+ this.recursionInitialized(res.data.data) //
+ console.log('initialDataArray',initialDataArray.reverse())
+ this.setState({
+ interactionMultiArray: recursionInteractionData,
+ multiIndex: this.recursionDepth(res.data.data),
+ initailMultiArray:initialDataArray.reverse()
+ }, () => {
+ initialDataArray=[]// 把全局变变量赋值给state之后,初始化商品分类为空, 不然第二次进去的时候会自动添加进去
+ // console.log('联动数据', this.state.interactionMultiArray)
+ // console.log('初始化数据', this.state.initailMultiArray)
+
+
+ }) // 用递归来整理无限层次的数据
+ // 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,
+ icon: 'none'
+ })
+ }
+ }
+ )
+ .catch(error => {
+ console.log('商品分类请求错误', error)
+ })
+ }
+
+
+
+
+ //联动确认
+ bindMultiPickerChange(e) {
+ // 如果没有上商品 那就不执行
+ if(Taro.getStorageSync('shopInfo').shop_id){
+ this.setState({
+ multiIndex: e.detail.value.map(item => { if (item === null) { item = 0 } return item })
+ }, () => {
+ // console.log('picker发送选择改变,携带值为', this.state.multiIndex)
+ this.returnResultToParent()
+
+ })
+ }
+ }
+ returnResultToParent() {
+ let selected = this.state.interactionMultiArray
+ for (let index of this.state.multiIndex) {
+ if (selected[index].children[0].id) {
+ selected = selected[index].children
+ } else {
+ this.props.onPassDataToChild(selected[index])
+ break
+ }
+ }
+ }
+ // 递归整理无限层初始数据,将整理好的数据赋值给initialDataArray
+ recursionInitialized(data) {
+ const arrayTem = []
+ if (data.length) {
+ for (let item of data) {
+ arrayTem.push({ name: item.class_name, id: item.class_id })
+ }
+ }
+ if(data[0].children.length){
+ this.recursionInitialized(data[0].children)
+ }
+ initialDataArray.push(arrayTem)
+ return arrayTem
+ }
+
+
+
+ // 递归整理无限层联动数据
+ recursionInteraction(data) {
+ let arrayTem = []
+ for (let items of data) {
+ arrayTem.push({ name: items.class_name, id: items.class_id })
+ if (items.children) {
+ arrayTem[arrayTem.length - 1].children = this.recursionInteraction(items.children)
+ } else {
+ arrayTem[arrayTem.length - 1].children = [{ name: '', id: '' }]
+ }
+ }
+ return arrayTem // 返回联动数据
+ // return arrayTem
+ }
+ // 递归整理无限层初始数据
+ // recursionInitialized(data) {
+ // const arrayTem = []
+ // const childrenHolderArray = []
+ // if (data.length) {
+ // for (let item of data) {
+ // arrayTem.push({ name: item.class_name, id: item.class_id })
+ // item.children ? childrenHolderArray.push(...item.children) : null
+ // }
+ // this.recursionInitialized(childrenHolderArray)
+ // }
+
+ // arrayTem.length ? initialDataArray.push(arrayTem) : null // 数组为空则不添加
+ // return initialDataArray
+ // }
+
+ // 递归整理无限层初始数据
+ recursionDepth(data) {
+ const arrayTem = []
+ const childrenHolderArray = []
+ if (data.length) {
+ for (let item of data) {
+ arrayTem.push({ name: item.class_name, id: item.class_id })
+ item.children ? childrenHolderArray.push(...item.children) : null
+ }
+ this.recursionDepth(childrenHolderArray)
+ maxDepth += 1
+ }
+ return new Array(maxDepth).fill(0)
+ }
+
+ // 触动联动筛选
+ 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
+ }
+ data.multiIndex[e.detail.column] = e.detail.value
+
+
+ if (e.detail.column == 0) {
+ for (let index in data.multiArray[0]) {
+ const indexNumber = Number(index)
+ if (indexNumber === data.multiIndex[0]) {
+ // data.multiArray[1] = this.state.interactionMultiArray[indexNumber].children
+ // data.multiArray[2] = this.state.interactionMultiArray[indexNumber].children[0].children
+ // data.multiArray[3] = this.state.interactionMultiArray[indexNumber].children[0].children[0].children
+ data.multiArray[1] = this.state.interactionMultiArray[indexNumber].children
+ data.multiArray[2] = this.state.interactionMultiArray[indexNumber].children[data.multiIndex[1]].children
+ data.multiArray[3] = this.state.interactionMultiArray[indexNumber].children[data.multiIndex[1]].children[data.multiIndex[2]].children
+ }
+ }
+ } else if (e.detail.column == 1) {
+ for (let index in data.multiArray[1]) {
+ const indexNumber = Number(index)
+ if (indexNumber === data.multiIndex[1]) {
+ data.multiArray[2] = this.state.interactionMultiArray[data.multiIndex[0]].children[indexNumber].children
+ }
+ }
+ }
+ else if (e.detail.column == 2) {
+ for (let index in data.multiArray[2]) {
+ const indexNumber = Number(index)
+ if (indexNumber === data.multiIndex[2]) {
+ data.multiArray[3] = this.state.interactionMultiArray[data.multiIndex[0]].children[data.multiIndex[1]].children[indexNumber].children
+ }
+ }
+ }
+
+ // switch (e.detail.column) {// 移动了第几列
+ // case 0:
+ // switch (data.multiIndex[0]) { // 第一个index 是多少
+ // case 0:
+ // data.multiArray[1] = this.state.interactionMultiArray[0].children
+ // data.multiArray[2]=this.state.interactionMultiArray[0].children[0].children
+ // break
+ // case 1:
+ // data.multiArray[1] = this.state.interactionMultiArray[1].children
+ // break
+ // case 2:
+ // data.multiArray[1] = this.state.interactionMultiArray[2].children
+ // break
+ // case 3:
+ // data.multiArray[1] = this.state.interactionMultiArray[3].children
+ // break
+ // case 4:
+ // data.multiArray[1] = this.state.interactionMultiArray[4].children
+ // break
+ // }
+ // data.multiIndex[1] = 0
+ // data.multiIndex[2] = 0
+ // data.multiIndex[3] = 0
+ // break
+ // case 1:
+ // switch (data.multiIndex[0]) {
+ // case 0:
+
+ // break
+ // case 1:
+ // switch (data.multiIndex[1]) {
+ // case 0:
+ // data.multiArray[2] = this.state.interactionMultiArray[1].children[0].children
+ // break
+ // case 1:
+ // data.multiArray[2] = this.state.interactionMultiArray[1].children[1].children
+ // break
+ // case 2:
+ // data.multiArray[2] = this.state.interactionMultiArray[1].children[2].children
+ // break
+ // case 3:
+ // data.multiArray[2] = this.state.interactionMultiArray[1].children[3].children ? this.state.interactionMultiArray[1].children[3].children : [{ class_name: '' }]
+ // break
+ // }
+ // break
+ // case 2:
+ // switch (data.multiIndex[1]) {
+ // case 0:
+ // data.multiArray[2] = this.state.interactionMultiArray[2].children[0].children
+ // break
+ // case 1:
+ // data.multiArray[2] = this.state.interactionMultiArray[2].children[1].children
+ // break
+ // case 2:
+ // data.multiArray[2] = this.state.interactionMultiArray[2].children[2].children
+ // break
+ // case 3:
+ // data.multiArray[2] = this.state.interactionMultiArray[2].children[3].children
+ // break
+ // case 4:
+ // data.multiArray[2] = this.state.interactionMultiArray[2].children[4].children
+ // break
+ // case 5:
+ // data.multiArray[2] = this.state.interactionMultiArray[2].children[5].children
+ // break
+ // }
+ // break
+ // case 3:
+ // switch (data.multiIndex[1]) {
+ // case 0:
+ // data.multiArray[2] = this.state.interactionMultiArray[3].children[0].children
+ // break
+ // case 1:
+ // data.multiArray[2] = this.state.interactionMultiArray[3].children[1].children
+ // break
+ // case 2:
+ // data.multiArray[2] = this.state.interactionMultiArray[3].children[2].children
+ // break
+ // case 3:
+ // data.multiArray[2] = this.state.interactionMultiArray[3].children[3].children
+ // break
+ // case 3:
+ // data.multiArray[2] = this.state.interactionMultiArray[3].children[3].children
+ // break
+ // }
+ // break
+ // case 4:
+ // switch (data.multiIndex[1]) {
+ // case 0:
+ // data.multiArray[2] = this.state.interactionMultiArray[4].children[0].children
+ // break
+ // case 1:
+ // data.multiArray[2] = this.state.interactionMultiArray[4].children[1].children
+ // break
+ // case 2:
+ // data.multiArray[2] = this.state.interactionMultiArray[4].children[2].children
+ // break
+
+ // }
+ // break
+
+ // }
+ // data.multiIndex[2] = 0
+ // data.multiIndex[3] = 0
+ // break
+ // }
+ this.setState({ multiIndex: data.multiIndex })
+ }
+
+ componentDidMount() {
+
+ if(Taro.getStorageSync('shopInfo').shop_id){
+ this.getProductCateList(this.props.url)
+ }else{
+
+ }
+
+ }
+ // 当然父组件有新的props的 会从新渲染组件
+ componentWillReceiveProps(nextProps) {
+
+ }
+ componentWillUnmount() { }
+
+ componentDidShow() { }
+
+ componentDidHide() { }
+
+ render() {
+ return (
+
+
+
+
+ *
+ 商品分类:
+
+ {this.props.selectedValue.name}
+
+
+ {/* {this.state.initailMultiArray[0].length? {this.state.initailMultiArray[0][this.state.multiIndex[0]].name}:null}
+ {this.state.initailMultiArray[1].length?{this.state.initailMultiArray[1][this.state.multiIndex[1]].name}:null}
+ {this.state.initailMultiArray[2].length?{this.state.initailMultiArray[2][this.state.multiIndex[2]].name}:null} */}
+
+
+
+
-
-
-
-
- const selfAndUnAvaialble = localStoageUserId === this.state.userId && this.state.stateId != '1' &&
-
-
-
-
-
-
-
- const Avaialble = this.state.stateId === '1' &&
-
-
- const Unavailable = this.state.stateId === '2' &&
-
-
- const SoldOut = this.state.stateId === '3' &&
-
-
+ )
+ }
+}
+
+export default GoodsTypeInteractionComp
- const ButtonElement = selfAndAvailable || selfAndUnAvaialble || Avaialble || Unavailable || SoldOut