index.jsx 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. import { Component } from "react";
  2. import { View, Text, Image, Input } from "@tarojs/components";
  3. import { AtDivider, AtIcon, AtActivityIndicator } from "taro-ui";
  4. import "./index.less";
  5. import vip from "../../../images/earningsOrder/vip.png";
  6. import Taro from "@tarojs/taro";
  7. import { getEarningsOrderTab, getEarningsOrderList } from "../../../service";
  8. export default class Index extends Component {
  9. state = {
  10. current: 0,
  11. orderType: 2,//默认为推广订单
  12. value: "", //搜索值
  13. tabList: [{ title: "全部" }],
  14. page: 1, //页数
  15. loading: false, //加载状态
  16. totalPages: 1, // 添加总页数
  17. isNoMore: false,
  18. orderList: [],//订单列表
  19. userInfo: {},//个人信息
  20. };
  21. componentDidShow() {
  22. const { router } = Taro.getCurrentInstance();
  23. const params = router.params;
  24. this.setState({
  25. orderType: params.type||2,
  26. },()=>{
  27. this.getEarningsOrderTab();
  28. });
  29. }
  30. // 获取个人信息
  31. getUserInfo = async () => {
  32. const res = await getUserInfo();
  33. this.setState({ userInfo: res });
  34. }
  35. // 获取收益订单列表
  36. getEarningsOrderList = async (isRefresh) => {
  37. const { page } = this.state;
  38. this.setState({ loading: true });
  39. const res = await getEarningsOrderList({
  40. tab_name: this.state.tabList[this.state.current].title,
  41. page,
  42. page_size: 10,
  43. search_name: this.state.value,
  44. user_type:this.state.orderType
  45. });
  46. this.setState(
  47. (prevState) => ({
  48. orderList: isRefresh
  49. ? res.income_list
  50. : [...prevState.orderList, ...res.income_list],
  51. totalPages: res.total_pages,
  52. loading: false,
  53. isNoMore: res.total_pages <= page,
  54. }));
  55. };
  56. // 获取收益订单tab
  57. getEarningsOrderTab = async () => {
  58. const res = await getEarningsOrderTab();
  59. const newTabList = res.tabs.map((item) => ({
  60. title: item,
  61. }));
  62. this.setState({
  63. tabList: newTabList,
  64. },()=>{
  65. this.getEarningsOrderList(true);
  66. });
  67. };
  68. // 订单类型切换
  69. handleOrderTypeClick = (type) => {
  70. this.setState({ orderType: type, page: 1, value: '' },()=>{
  71. this.getEarningsOrderList(true);
  72. });
  73. };
  74. // tab切换
  75. handleTabClick = (index) => {
  76. this.setState({ current: index, page: 1, value: '' },()=>{
  77. this.getEarningsOrderList(true);
  78. });
  79. };
  80. // 输入
  81. handleChange = (e) => {
  82. const value = e.detail.value;
  83. this.setState({ value });
  84. };
  85. // 搜索
  86. handleSearch = () => {
  87. this.getEarningsOrderList(true);
  88. };
  89. // 复制
  90. handleCopy = async (text) => {
  91. try {
  92. await Taro.setClipboardData({
  93. data: text,
  94. });
  95. Taro.showToast({
  96. title: "内容已复制",
  97. icon: "success",
  98. duration: 2000,
  99. });
  100. } catch (error) {
  101. Taro.showToast({
  102. title: "复制失败",
  103. icon: "error",
  104. duration: 2000,
  105. });
  106. }
  107. };
  108. // 页面上拉触底
  109. onReachBottom = () => {
  110. const { page, totalPages, loading } = this.state;
  111. if (page < totalPages && !loading) {
  112. this.setState(
  113. (prevState) => ({ page: prevState.page + 1 }),
  114. () => this.getEarningsOrderList()
  115. );
  116. }
  117. };
  118. render() {
  119. const { current, tabList, value, orderList, loading, isNoMore, orderType } = this.state;
  120. return (
  121. <View className="index">
  122. {/* 订单类型切换 */}
  123. <View className="order-type-switch">
  124. <View className={`order-type-item ${orderType == 2 ? "active" : ""}`} onClick={() => this.handleOrderTypeClick(2)}>
  125. <Text>推广订单</Text>
  126. </View>
  127. <View className={`order-type-item ${orderType == 1 ? "active" : ""}`} onClick={() => this.handleOrderTypeClick(1)}>
  128. <Text>购买订单</Text>
  129. </View>
  130. </View>
  131. {/* tab切换 */}
  132. <View className="tab-container">
  133. {tabList.map((tab, index) => (
  134. <View
  135. key={index}
  136. className={`tab-item ${current === index ? "active" : ""}`}
  137. onClick={() => this.handleTabClick(index)}
  138. >
  139. <Text>{tab.title}</Text>
  140. {/* {tab.num > 0 && <Text className="tag">{tab.num}</Text>} */}
  141. </View>
  142. ))}
  143. </View>
  144. {/* 搜索 */}
  145. <View className="search-container">
  146. <View className="search-bar">
  147. <AtIcon
  148. className="search-icon"
  149. value="search"
  150. size="20"
  151. color="#ACACAC"
  152. ></AtIcon>
  153. <Input
  154. type="text"
  155. className="search-input"
  156. placeholder=""
  157. value={value}
  158. onInput={this.handleChange}
  159. />
  160. <View onClick={this.handleSearch} className="search-button">
  161. 搜索
  162. </View>
  163. </View>
  164. </View>
  165. {/* 订单列表 */}
  166. <View className="order-list">
  167. {orderList.map((item, index) => (
  168. <View className="order-item" key={index}>
  169. {/* 头部信息 */}
  170. {/* <View className="order-header">
  171. <View className="user-info">
  172. <Image className="avatar" src="" />
  173. <Text className="username">张三</Text>
  174. </View>
  175. <Text className="pay-status">{item.state_text}</Text>
  176. </View> */}
  177. {/* 订单信息 */}
  178. <View className="order-info">
  179. <View className="order-details">
  180. <View className="detail-item">
  181. <Text className="label">订单编号:</Text>
  182. <Text className="value">{item.order_number}</Text>
  183. <Text
  184. className="copy-text"
  185. onClick={() => this.handleCopy(item.order_number)}
  186. >
  187. 复制
  188. </Text>
  189. </View>
  190. <View className="detail-item">
  191. <Text className="label">下单时间:</Text>
  192. <Text className="value">{item.pay_time}</Text>
  193. </View>
  194. </View>
  195. {/* <View className="member-info">
  196. <Image className="member-icon" src={vip} />
  197. <Text className="member-text">闲鱼会员</Text>
  198. </View> */}
  199. </View>
  200. {/* 产品信息 */}
  201. <View className="product-info">
  202. <Image mode="aspectFill" className="product-image" src={item.item_pic_url} />
  203. <View className="product-details">
  204. <Text className="product-name">
  205. {item.item_title}
  206. </Text>
  207. {orderType == 2 && (
  208. <View className="promotion-info">
  209. <View className="tag">推广收入</View>
  210. <Text className="amount">¥{item.assess_amount_text}</Text>
  211. </View>
  212. )}
  213. <View className="payment-info">
  214. </View>
  215. <View className="payment-info">
  216. <Text className="label">实付金额:</Text>
  217. <Text className="amount">¥{item.actual_paid_fee}</Text>
  218. </View>
  219. </View>
  220. </View>
  221. </View>
  222. ))}
  223. </View>
  224. {/* 加载中 */}
  225. {loading && (
  226. <View className="loading">
  227. <AtActivityIndicator
  228. content="加载中..."
  229. isOpened={loading}
  230. mode="center"
  231. color="#fdf764"
  232. />
  233. </View>
  234. )}
  235. {/* 没有更多 */}
  236. {isNoMore && (
  237. <View className="no-more">
  238. <AtDivider fontSize={18} fontColor="#949494" content="我是有底线的" />
  239. </View>
  240. )}
  241. </View>
  242. );
  243. }
  244. }