import { Component } from "react"; import { View, Image, Text, Input } from "@tarojs/components"; import Taro from "@tarojs/taro"; import "./index.less"; import iconOne from "../../../images/calculator/iconOne.png"; import iconTwo from "../../../images/calculator/iconTwo.png"; import iconThree from "../../../images/calculator/iconThree.png"; import { getCalculatorData, getCalculatorSearch, } from "../../../service/activity"; export default class Index extends Component { state = { wishList: [], wish: "", // 心愿 price: "", // 价格 }; componentDidMount() { this.getCalculator(); // 计算捡漏 } // 计算捡漏 getCalculator = async () => { const res = await getCalculatorData(); this.setState({ wishList: res, }); }; // 搜索捡漏 getCalculatorSearch = async () => { if (!this.state.wish.trim()) { Taro.showToast({ title: "请输入您想要捡漏的物品或服务", icon: "none", }); return; } if (!this.state.price.trim()) { Taro.showToast({ title: "请输入您预期的价格", icon: "none", }); return; } Taro.showLoading({ title: "正在计算...", }); try { const res = await getCalculatorSearch({ keyword: this.state.wish, money: this.state.price, }); Taro.navigateTo({ url: `/pages/calculatorSub/calculatorResult/index?isSearch=${ res.is_search }&&list=${encodeURIComponent(JSON.stringify(res.goods_list))}`, }); } finally { Taro.hideLoading(); } }; // 心愿输入框改变 handleWishChange = (e) => { this.setState({ wish: e.detail.value, }); }; // 价格输入框改变 handlePriceChange = (e) => { if (e.detail.value < 1 && e.detail.value.trim() !== "") { e.detail.value = 1; } this.setState({ price: e.detail.value, }); }; render() { return ( {/* 底部 */} {/* 输入内容区域 */} 您想要的物品或服务 例: 输入机票不如输入从深圳到北京的机票 您预期的价格 注意:我们是认真的! 捡漏计算 {/* 底部捡漏列表 */} TA们捡了哪些漏 {this.state.wishList.length > 0 && this.state.wishList.map((item, index) => ( TA想要“{item.jianlou_title}”,捡漏{item.reserve_price}元 ))} ); } }