...
|
...
|
@@ -7,6 +7,7 @@ import {common as commonModel} from '../../models'; |
|
|
import './index.scss';
|
|
|
import { connect } from '@tarojs/redux';
|
|
|
import { loginAction, decodeUnionId, wechatUserIsBind } from '../../libs/login/login.js'
|
|
|
import getPrivateKey from '../../libs/request/getPrivateKey.js'
|
|
|
|
|
|
|
|
|
@connect(({ filterMenu }) => ({
|
...
|
...
|
@@ -42,74 +43,77 @@ export default class Index extends Component { |
|
|
navigationBarTitleText: 'UFO'
|
|
|
};
|
|
|
|
|
|
componentDidMount() {
|
|
|
let obj = {
|
|
|
page: {},
|
|
|
productList: {},
|
|
|
stopLoading: {}
|
|
|
};
|
|
|
|
|
|
// 初始化数据
|
|
|
this.state.tabs.map(item => {
|
|
|
let type = item.type;
|
|
|
|
|
|
obj.page[type] = 1;
|
|
|
obj.productList[type] = [];
|
|
|
obj.stopLoading[type] = false;
|
|
|
});
|
|
|
|
|
|
this.setState(obj, () => {
|
|
|
this.getProductData();
|
|
|
});
|
|
|
}
|
|
|
|
|
|
componentWillReceiveProps (nextProps) {
|
|
|
let curType = nextProps.filterMenu.curType;
|
|
|
let {productList} = this.state;
|
|
|
|
|
|
if (productList[curType].length === 0) {
|
|
|
this.getProductData(nextProps.filterMenu);
|
|
|
}
|
|
|
componentDidMount() {
|
|
|
let obj = {
|
|
|
page: {},
|
|
|
productList: {},
|
|
|
stopLoading: {}
|
|
|
};
|
|
|
|
|
|
// 初始化数据
|
|
|
this.state.tabs.map(item => {
|
|
|
let type = item.type;
|
|
|
|
|
|
obj.page[type] = 1;
|
|
|
obj.productList[type] = [];
|
|
|
obj.stopLoading[type] = false;
|
|
|
});
|
|
|
|
|
|
this.setState(obj, () => {
|
|
|
this.getProductData();
|
|
|
});
|
|
|
}
|
|
|
|
|
|
componentWillReceiveProps(nextProps) {
|
|
|
let curType = nextProps.filterMenu.curType;
|
|
|
let { productList } = this.state;
|
|
|
|
|
|
if (productList[curType].length === 0) {
|
|
|
this.getProductData(nextProps.filterMenu);
|
|
|
}
|
|
|
|
|
|
getProductData(obj) {
|
|
|
let {filterMenu} = this.props;
|
|
|
let {page, productList, stopLoading} = this.state;
|
|
|
obj = obj || filterMenu;
|
|
|
let type = obj.curType;
|
|
|
|
|
|
commonModel.search({
|
|
|
limit: 10,
|
|
|
type: type,
|
|
|
page: page[type]
|
|
|
}).then(ret => {
|
|
|
if (ret && ret.code === 200) {
|
|
|
let list = ret.data && ret.data.product_list || [];
|
|
|
|
|
|
if (list.length === 0) {
|
|
|
this.setState({
|
|
|
stopLoading: Object.assign(stopLoading, {[type]: true})
|
|
|
});
|
|
|
} else {
|
|
|
this.setState({
|
|
|
productList: Object.assign(productList, {[type]: [...productList[type], ...list]})
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
|
|
|
onScrollToLower() {
|
|
|
let {filterMenu} = this.props;
|
|
|
let {page} = this.state;
|
|
|
let type = filterMenu.curType;
|
|
|
|
|
|
if (!this.state.stopLoading[type]) {
|
|
|
this.setState({page: Object.assign(page, {[type]: page[type] + 1})}, () => {
|
|
|
this.getProductData();
|
|
|
});
|
|
|
}
|
|
|
|
|
|
async getProductData(obj) {
|
|
|
let { filterMenu } = this.props;
|
|
|
let { page, productList, stopLoading } = this.state;
|
|
|
obj = obj || filterMenu;
|
|
|
let type = obj.curType;
|
|
|
|
|
|
const pk = await getPrivateKey();
|
|
|
Taro.setStorage({ key: 'verifyKey', data: pk });
|
|
|
commonModel.search({
|
|
|
limit: 10,
|
|
|
type: type,
|
|
|
page: page[type]
|
|
|
}).then(ret => {
|
|
|
console.log(ret);
|
|
|
if (ret && ret.code === 200) {
|
|
|
let list = ret.data && ret.data.product_list || [];
|
|
|
|
|
|
if (list.length === 0) {
|
|
|
this.setState({
|
|
|
stopLoading: Object.assign(stopLoading, { [type]: true })
|
|
|
});
|
|
|
} else {
|
|
|
this.setState({
|
|
|
productList: Object.assign(productList, { [type]: [...productList[type], ...list] })
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
|
|
|
onScrollToLower() {
|
|
|
let { filterMenu } = this.props;
|
|
|
let { page } = this.state;
|
|
|
let type = filterMenu.curType;
|
|
|
|
|
|
if (!this.state.stopLoading[type]) {
|
|
|
this.setState({ page: Object.assign(page, { [type]: page[type] + 1 }) }, () => {
|
|
|
this.getProductData();
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// gotoNative() {
|
|
|
// Taro.navigateTo({
|
...
|
...
|
|