Page({

  data: {
    historyWords: ["华", "汇", "小区", "华汇小区", "小区5", "小区6", "小区7", ],
    popularWords: ["小区1", "小区2", "小区3", "小区4", "小区5", "小区6", "小区7", ],
    searchValue: '',
    dialog: {
      title: '确认删除当前历史记录',
      showCancelButton: true,
      message: '',
    },
    dialogShow: false,
  },

  deleteType: 0,
  deleteIndex: '',

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },
  confirm() {
    const {
      historyWords
    } = this.data;
    const {
      deleteType,
      deleteIndex
    } = this;
    historyWords.splice(deleteIndex, 1);
    if (deleteType === 0) {
      this.setData({
        historyWords,
        dialogShow: false,
      });
    } else {
      this.setData({
        historyWords: [],
        dialogShow: false
      });
    }
  },

  close() {
    this.setData({
      dialogShow: false
    });
  },
  handleClearHistory() {
    const {
      dialog
    } = this.data;
    this.deleteType = 1;
    this.setData({
      dialog: {
        ...dialog,
        message: '确认删除所有历史记录',
      },
      dialogShow: true,
    });
  },
  deleteCurr(e) {
    const {
      index
    } = e.currentTarget.dataset;
    const {
      dialog
    } = this.data;
    this.deleteIndex = index;
    this.setData({
      dialog: {
        ...dialog,
        message: '确认删除当前历史记录',
        deleteType: 0,
      },
      dialogShow: true,
    });
  },
  handleHistoryTap(e) {
    const {
      historyWords
    } = this.data;
    const {
      dataset
    } = e.currentTarget;
    const _searchValue = historyWords[dataset.index || 0] || '';
    if (_searchValue) {
      wx.navigateTo({
        url: `/page/home/pages/house/findgarden/findgarden?searchValue=${_searchValue}`,
      });
    }
  },
  handleSubmit(e) {
    const {
      value
    } = e.detail;
    if (value.length === 0) return;
    var pages = getCurrentPages();
    var prevPage = pages[pages.length - 2];
    prevPage.setData({
      searchData: {garden_name:value},
      value
    });
    wx.navigateBack({
      delta: -1
    });
  },
})