"use strict";
const common_vendor = require("../../../common/vendor.js");
const _sfc_main = {
  onPageScroll() {
    this.$refs.dropDown.init();
  },
  computed: {
    dropItem(name) {
      return (name2) => {
        const result = {};
        const find = this.result.find((item) => item.name === name2);
        if (find) {
          result.label = find.label;
          result.value = find.value;
        } else {
          result.label = this[name2].label;
          result.value = this[name2].value;
        }
        return result;
      };
    },
    // 获取当前下拉筛选项
    currentDropItem() {
      return this[this.activeName];
    }
  },
  data() {
    return {
      keyword: "",
      // 表示value等于这些值，就属于默认值
      defaultValue: ["all", "all", "all", "all"],
      // 筛选结果
      result: [],
      region: {
        label: "区域",
        value: "all",
        activeIndex: 0,
        color: "#333",
        activeColor: "#20CD7D",
        child: [{
          label: "全部区域",
          value: "all"
        }, {
          label: "湖南",
          value: "hunan"
        }, {
          label: "广州",
          value: "guangzhou"
        }]
      },
      rent: {
        label: "租金",
        value: "all",
        activeIndex: 0,
        color: "#333",
        activeColor: "#20CD7D",
        child: [{
          label: "全部",
          value: "all"
        }, {
          label: "0-2k",
          value: "2000"
        }, {
          label: "2k-4k",
          value: "4000"
        }, {
          label: "4k-6k",
          value: "6000"
        }, {
          label: "6k+",
          value: "6000+"
        }]
      },
      type: {
        label: "类型",
        value: "all",
        activeIndex: 0,
        color: "#333",
        activeColor: "#20CD7D",
        child: [{
          label: "全部",
          value: "all"
        }, {
          label: "闲置散居农房",
          value: "nongfang"
        }, {
          label: "鱼塘",
          value: "yutang"
        }, {
          label: "耕地",
          value: "gengdi"
        }]
      },
      duration: {
        label: "年限",
        value: "all",
        activeIndex: 0,
        color: "#333",
        activeColor: "#20CD7D",
        child: [{
          label: "全部",
          value: "all"
        }, {
          label: "5年内",
          value: "0-5"
        }, {
          label: "5-10年",
          value: "5-10"
        }, {
          label: "10-20年",
          value: "10-20"
        }]
      },
      activeName: "region",
      vip_type: {
        label: "VIP文档",
        value: 0,
        activeIndex: 0
      }
    };
  },
  methods: {
    onSearch() {
      this.$emit("onSearch", this.keyword);
    },
    change(e) {
      console.log("弹窗打开状态：", e);
    },
    /**
     * 点击每个筛选项回调
     * @param {Object} e { name, active, type } = e
     */
    selectMenu(e) {
      const {
        name,
        active,
        type
      } = e;
      this.activeName = name;
      if (type == 1) {
        this.clickItem({
          name: "vip_type",
          label: "VIP文档",
          value: e.active ? 1 : 0
        });
      } else {
        const find = this.result.find((item) => item.name == this.activeName);
        if (find) {
          const findIndex = this[this.activeName].child.findIndex((item) => item.label == find.label && item.value == find.value);
          this[this.activeName].activeIndex = findIndex;
        } else {
          this[this.activeName].activeIndex = 0;
        }
      }
    },
    /**
     * 点击菜单回调处理
     * @param {Object} item 选中项 { label,value } = e
     */
    clickItem(e) {
      let {
        label,
        value
      } = e;
      const findIndex = this.result.findIndex((item) => item.name == this.activeName);
      if (this.defaultValue.indexOf(value) > -1 && this[this.activeName].label) {
        label = this[this.activeName].label;
      }
      if (findIndex > -1) {
        this.$set(this.result, findIndex, {
          name: this.activeName,
          label,
          value
        });
      } else {
        this.result.push({
          name: this.activeName,
          label,
          value
        });
      }
      this.result = this.result.filter((item) => this.defaultValue.indexOf(item.value) == -1);
      console.info(this.result);
      this.$emit("onParent", this.result);
    }
  }
};
if (!Array) {
  const _easycom_uv_search2 = common_vendor.resolveComponent("uv-search");
  const _easycom_uv_drop_down_item2 = common_vendor.resolveComponent("uv-drop-down-item");
  const _easycom_uv_drop_down2 = common_vendor.resolveComponent("uv-drop-down");
  const _easycom_uv_drop_down_popup2 = common_vendor.resolveComponent("uv-drop-down-popup");
  (_easycom_uv_search2 + _easycom_uv_drop_down_item2 + _easycom_uv_drop_down2 + _easycom_uv_drop_down_popup2)();
}
const _easycom_uv_search = () => "../../../uni_modules/uv-search/components/uv-search/uv-search.js";
const _easycom_uv_drop_down_item = () => "../../../uni_modules/uv-drop-down/components/uv-drop-down-item/uv-drop-down-item.js";
const _easycom_uv_drop_down = () => "../../../uni_modules/uv-drop-down/components/uv-drop-down/uv-drop-down.js";
const _easycom_uv_drop_down_popup = () => "../../../uni_modules/uv-drop-down/components/uv-drop-down-popup/uv-drop-down-popup.js";
if (!Math) {
  (_easycom_uv_search + _easycom_uv_drop_down_item + _easycom_uv_drop_down + _easycom_uv_drop_down_popup)();
}
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  return {
    a: common_vendor.o(($event) => $options.onSearch()),
    b: common_vendor.o(($event) => $data.keyword = $event),
    c: common_vendor.p({
      placeholder: "搜索租房信息",
      showAction: false,
      modelValue: $data.keyword
    }),
    d: common_vendor.p({
      name: "region",
      type: "2",
      label: $options.dropItem("region").label,
      value: $options.dropItem("region").value
    }),
    e: common_vendor.p({
      name: "rent",
      type: "2",
      label: $options.dropItem("rent").label,
      value: $options.dropItem("rent").value
    }),
    f: common_vendor.p({
      name: "type",
      type: "2",
      label: $options.dropItem("type").label,
      value: $options.dropItem("type").value
    }),
    g: common_vendor.p({
      name: "duration",
      type: "2",
      label: $options.dropItem("duration").label,
      value: $options.dropItem("duration").value
    }),
    h: common_vendor.sr("dropDown", "1c0082b4-1"),
    i: common_vendor.o($options.selectMenu),
    j: common_vendor.p({
      sign: "dropDown_1",
      ["text-active-color"]: "#20CD7D",
      ["extra-icon"]: {
        name: "arrow-down-fill",
        color: "#666",
        size: "26rpx"
      },
      ["extra-active-icon"]: {
        name: "arrow-up-fill",
        color: "#20CD7D",
        size: "26rpx"
      },
      defaultValue: $data.defaultValue,
      ["custom-style"]: {
        padding: "0rpx 0rpx",
        borderBottom: "1rpx solid transparent"
      }
    }),
    k: common_vendor.o($options.clickItem),
    l: common_vendor.o($options.change),
    m: common_vendor.p({
      sign: "dropDown_1",
      ["click-overlay-on-close"]: true,
      currentDropItem: $options.currentDropItem
    })
  };
}
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
wx.createComponent(Component);
