123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- import { Component } from "react";
- import { View, Text, Image, Input } from "@tarojs/components";
- import { AtDivider, AtIcon, AtActivityIndicator } from "taro-ui";
- import "./index.less";
- import vip from "../../../images/earningsOrder/vip.png";
- import Taro from "@tarojs/taro";
- import { getEarningsOrderTab, getEarningsOrderList } from "../../../service";
- export default class Index extends Component {
- state = {
- current: 0,
- orderType: 2,//默认为推广订单
- value: "", //搜索值
- tabList: [{ title: "全部" }],
- page: 1, //页数
- loading: false, //加载状态
- totalPages: 1, // 添加总页数
- isNoMore: false,
- orderList: [],//订单列表
- userInfo: {},//个人信息
- };
- componentDidShow() {
- const { router } = Taro.getCurrentInstance();
- const params = router.params;
- this.setState({
- orderType: params.type||2,
- },()=>{
- this.getEarningsOrderTab();
- });
- }
- // 获取个人信息
- getUserInfo = async () => {
- const res = await getUserInfo();
- this.setState({ userInfo: res });
- }
- // 获取收益订单列表
- getEarningsOrderList = async (isRefresh) => {
- const { page } = this.state;
- this.setState({ loading: true });
- const res = await getEarningsOrderList({
- tab_name: this.state.tabList[this.state.current].title,
- page,
- page_size: 10,
- search_name: this.state.value,
- user_type:this.state.orderType
- });
- this.setState(
- (prevState) => ({
- orderList: isRefresh
- ? res.income_list
- : [...prevState.orderList, ...res.income_list],
- totalPages: res.total_pages,
- loading: false,
- isNoMore: res.total_pages <= page,
- }));
- };
- // 获取收益订单tab
- getEarningsOrderTab = async () => {
- const res = await getEarningsOrderTab();
- const newTabList = res.tabs.map((item) => ({
- title: item,
- }));
- this.setState({
- tabList: newTabList,
- },()=>{
- this.getEarningsOrderList(true);
- });
- };
- // 订单类型切换
- handleOrderTypeClick = (type) => {
- this.setState({ orderType: type, page: 1, value: '' },()=>{
- this.getEarningsOrderList(true);
- });
- };
- // tab切换
- handleTabClick = (index) => {
- this.setState({ current: index, page: 1, value: '' },()=>{
- this.getEarningsOrderList(true);
- });
- };
- // 输入
- handleChange = (e) => {
- const value = e.detail.value;
- this.setState({ value });
- };
- // 搜索
- handleSearch = () => {
- this.getEarningsOrderList(true);
- };
- // 复制
- handleCopy = async (text) => {
- try {
- await Taro.setClipboardData({
- data: text,
- });
- Taro.showToast({
- title: "内容已复制",
- icon: "success",
- duration: 2000,
- });
- } catch (error) {
- Taro.showToast({
- title: "复制失败",
- icon: "error",
- duration: 2000,
- });
- }
- };
- // 页面上拉触底
- onReachBottom = () => {
- const { page, totalPages, loading } = this.state;
- if (page < totalPages && !loading) {
- this.setState(
- (prevState) => ({ page: prevState.page + 1 }),
- () => this.getEarningsOrderList()
- );
- }
- };
- render() {
- const { current, tabList, value, orderList, loading, isNoMore, orderType } = this.state;
- return (
- <View className="index">
- {/* 订单类型切换 */}
- <View className="order-type-switch">
- <View className={`order-type-item ${orderType == 2 ? "active" : ""}`} onClick={() => this.handleOrderTypeClick(2)}>
- <Text>推广订单</Text>
- </View>
- <View className={`order-type-item ${orderType == 1 ? "active" : ""}`} onClick={() => this.handleOrderTypeClick(1)}>
- <Text>购买订单</Text>
- </View>
- </View>
- {/* tab切换 */}
- <View className="tab-container">
- {tabList.map((tab, index) => (
- <View
- key={index}
- className={`tab-item ${current === index ? "active" : ""}`}
- onClick={() => this.handleTabClick(index)}
- >
- <Text>{tab.title}</Text>
- {/* {tab.num > 0 && <Text className="tag">{tab.num}</Text>} */}
- </View>
- ))}
- </View>
- {/* 搜索 */}
- <View className="search-container">
- <View className="search-bar">
- <AtIcon
- className="search-icon"
- value="search"
- size="20"
- color="#ACACAC"
- ></AtIcon>
- <Input
- type="text"
- className="search-input"
- placeholder=""
- value={value}
- onInput={this.handleChange}
- />
- <View onClick={this.handleSearch} className="search-button">
- 搜索
- </View>
- </View>
- </View>
- {/* 订单列表 */}
- <View className="order-list">
- {orderList.map((item, index) => (
- <View className="order-item" key={index}>
- {/* 头部信息 */}
- {/* <View className="order-header">
- <View className="user-info">
- <Image className="avatar" src="" />
- <Text className="username">张三</Text>
- </View>
- <Text className="pay-status">{item.state_text}</Text>
- </View> */}
- {/* 订单信息 */}
- <View className="order-info">
- <View className="order-details">
- <View className="detail-item">
- <Text className="label">订单编号:</Text>
- <Text className="value">{item.order_number}</Text>
- <Text
- className="copy-text"
- onClick={() => this.handleCopy(item.order_number)}
- >
- 复制
- </Text>
- </View>
- <View className="detail-item">
- <Text className="label">下单时间:</Text>
- <Text className="value">{item.pay_time}</Text>
- </View>
- </View>
- {/* <View className="member-info">
- <Image className="member-icon" src={vip} />
- <Text className="member-text">闲鱼会员</Text>
- </View> */}
- </View>
- {/* 产品信息 */}
- <View className="product-info">
- <Image mode="aspectFill" className="product-image" src={item.item_pic_url} />
- <View className="product-details">
- <Text className="product-name">
- {item.item_title}
- </Text>
- {orderType == 2 && (
- <View className="promotion-info">
- <View className="tag">推广收入</View>
- <Text className="amount">¥{item.assess_amount_text}</Text>
- </View>
- )}
- <View className="payment-info">
- </View>
- <View className="payment-info">
- <Text className="label">实付金额:</Text>
- <Text className="amount">¥{item.actual_paid_fee}</Text>
- </View>
- </View>
- </View>
- </View>
- ))}
- </View>
- {/* 加载中 */}
- {loading && (
- <View className="loading">
- <AtActivityIndicator
- content="加载中..."
- isOpened={loading}
- mode="center"
- color="#fdf764"
- />
- </View>
- )}
- {/* 没有更多 */}
- {isNoMore && (
- <View className="no-more">
- <AtDivider fontSize={18} fontColor="#949494" content="我是有底线的" />
- </View>
- )}
- </View>
- );
- }
- }
|