search.js 4.3 KB
"use strict";
var common_vendor = require("../../common/vendor.js");
var api_index = require("../../api/index.js");
require("../../utils/request.js");
if (!Array) {
  const _easycom_u_navbar2 = common_vendor.resolveComponent("u-navbar");
  _easycom_u_navbar2();
}
const _easycom_u_navbar = () => "../../uni_modules/uview-plus/components/u-navbar/u-navbar.js";
if (!Math) {
  (_easycom_u_navbar + search + shops)();
}
const search = () => "../../componets/searchBox.js";
const shops = () => "../../componets/shops.js";
const _sfc_main = {
  setup(__props) {
    let keyWord = common_vendor.ref("");
    let historyrecord = common_vendor.ref([]);
    let shopList = common_vendor.ref([]);
    let searchRes = common_vendor.ref(false);
    common_vendor.ref("");
    common_vendor.ref(1);
    common_vendor.ref(1);
    common_vendor.onLoad(() => {
      getRecords();
    });
    const serachHistroy = (item) => {
      keyWord.value = item;
      getSearchs(item);
    };
    const clearHistory = () => {
      common_vendor.index.showModal({
        title: "\u63D0\u793A",
        content: "\u662F\u5426\u6E05\u7A7A\u5386\u53F2\u8BB0\u5F55",
        success: function(res) {
          if (res.confirm) {
            getDelRecords();
            common_vendor.index.showToast({ title: "\u6E05\u7A7A\u6210\u529F" });
            common_vendor.index.removeStorage({
              key: "searchRecords"
            });
          } else if (res.cancel) {
            console.log("\u7528\u6237\u70B9\u51FB\u53D6\u6D88");
          }
        }
      });
    };
    const doSearchs = (keyword) => {
      if (keyword.trim() != "") {
        getSearchs(keyword);
      }
    };
    const input = (data) => {
      searchRes.value = false;
      shopList.value = [];
    };
    const getSearchs = async (keyWord2) => {
      try {
        const res = await api_index.getSearch(keyWord2);
        shopList.value = res.goods.concat(res.tjgoods);
        searchRes.value = shopList.value.length == 0 ? true : false;
        getRecords();
        console.log("getSearch", res);
      } catch (err) {
        console.log("getSearch", err);
      }
    };
    const getRecords = async () => {
      try {
        const res = await api_index.getRecord();
        historyrecord.value = res;
        console.log("getRecord", res);
      } catch (err) {
        common_vendor.index.showToast({ title: err, icon: "none" });
        console.log("getRecord", err);
      }
    };
    const getDelRecords = async () => {
      try {
        const res = await api_index.getDelRecord();
        getRecords();
        console.log("getDelRecord", res);
      } catch (err) {
        common_vendor.index.showToast({ title: err, icon: "none" });
        console.log("getDelRecord", err);
      }
    };
    common_vendor.onReachBottom(() => {
      if (this.page != this.lastPage) {
        this.page = this.page + 1;
        this.getSearch(1);
      } else {
        common_vendor.index.showToast({
          title: "\u6682\u65E0\u66F4\u591A\u5546\u54C1~",
          icon: "none"
        });
      }
    });
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: common_vendor.p({
          bgColor: "#F6F8FA",
          title: "\u641C\u7D22",
          placeholder: true,
          autoBack: true
        }),
        b: common_vendor.o(doSearchs),
        c: common_vendor.o(input),
        d: common_vendor.p({
          keyWord: common_vendor.unref(keyWord),
          disabled: false
        }),
        e: !common_vendor.unref(shopList).length && !common_vendor.unref(searchRes)
      }, !common_vendor.unref(shopList).length && !common_vendor.unref(searchRes) ? {
        f: common_vendor.o(clearHistory),
        g: common_vendor.f(common_vendor.unref(historyrecord), (item, index, i0) => {
          return {
            a: common_vendor.t(item),
            b: index,
            c: common_vendor.o(($event) => serachHistroy(item))
          };
        })
      } : {}, {
        h: _ctx.index,
        i: common_vendor.p({
          list: common_vendor.unref(shopList),
          shopWidth: 344,
          shopHeight: 344
        }),
        j: common_vendor.unref(searchRes)
      }, common_vendor.unref(searchRes) ? {} : {});
    };
  }
};
var MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__file", "D:/vue/\u5927\u5065\u5EB7\u5546\u57CE/healthMall/pages/index/search.vue"]]);
wx.createPage(MiniProgramPage);