123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- list: [],
- shoopingtext: "", //搜索框的值
- history: false, //显示历史记录
- noneview: false, //显示未找到提示
- show: false, //显示商品列表
- sea: true,
- //title: false,
- historyArray: [], //历史记录数组,
- newArray: [], //添加历史记录数组
- },
- onInput: function (e) {
- // this.setData({ shoopingtext: e.detail.value });
- var searchtext = this.data.shoopingtext; //搜索框的值
- var sss = true;
- if (searchtext != "") {
- // //将搜索框的值赋给历史数组
- this.data.historyArray.push(searchtext);
- //模糊查询 循环查询数组中的title字段
- for (var index in this.data.list) {
- var num = this.data.list[index].title.indexOf(searchtext);
- let temp = "list[" + index + "].status";
- if (num != -1) {
- //不匹配的不显示
- this.setData({
- [temp]: 1,
- show: true,
- });
- sss = false; //隐藏未找到提示
- } else {
- this.setData({
- show: false,
- });
- }
- }
- this.setData({
- history: false, //隐藏历史记录
- noneview: sss, //隐藏未找到提示
- shoppinglist: true, //显示商品列表
- sea: false, //显示图片
- newArray: this.data.historyArray, //给新历史记录数组赋值
- });
- } else {
- this.setData({
- noneview: true, //显示未找到提示
- show: false, //隐藏商品列表
- sea: false,
- history: false, //隐藏历史记录
- });
- }
- this.setData({
- shoopingtext: "",
- });
- // console.log(this.data.shoopingtext);
- },
- shoppinginput: function (e) {
- //当删除input的值为空时
- if (e.detail.value == "") {
- this.setData({
- history: true, //显示历史记录
- shoppinglist: false, //隐藏商品列表
- sea: true,
- }); //所有商品列表的状态改为0
- for (var index in this.data.list) {
- let temp = "list[" + index + "].status";
- this.setData({
- [temp]: 0,
- });
- }
- }
- this.setData({
- shoopingtext: e.detail.value,
- });
- },
- delete: function () {
- wx.showModal({
- title: "删除",
- content: "您确定要删除全部的搜索历史吗?",
- complete: (res) => {
- if (res.cancel) {
- console.log('您已点击取消')
- }
- if (res.confirm) {
- this.setData({
- newArray: "",
- historyArray:[]
- });
- }
- },
- });
- },
- /**
- * 生命周期函数--监听页面加载
- */ onLoad(options) {
- wx.request({
- url:
- "https://www.fastmock.site/mock/883cd62177ae0a3a79638beccc3349da/api/order/list",
- success: (e) => {
- this.setData({
- list: e.data.data.list,
- });
- },
- });
- },
- });
|