|
@@ -0,0 +1,135 @@
|
|
|
+<template>
|
|
|
+ <div id="searchBar" style="margin:10px 0px">
|
|
|
+ <up-row>
|
|
|
+ <up-col :span="12">
|
|
|
+ <u-search v-model="obj.name" :show-action="true" actionText="更多" :animation="true" :clearable="true"
|
|
|
+ placeholder="请输入商品名称" @search="toSearch" @custom="showMoreFilter"></u-search>
|
|
|
+ </up-col>
|
|
|
+ </up-row>
|
|
|
+ <u-popup :show="show" mode="right">
|
|
|
+ <view class="search__input">
|
|
|
+ <up-row>
|
|
|
+ <up-col :span="12">
|
|
|
+ <up-input placeholder="请输入商品名称" v-model="obj.name"></up-input>
|
|
|
+ </up-col>
|
|
|
+ </up-row>
|
|
|
+ </view>
|
|
|
+ <view class="search__input">
|
|
|
+ <up-row>
|
|
|
+ <up-col :span="12">
|
|
|
+ <u-cell :title="obj.brand" :label="getLabel('brand')" :isLink="true" arrowDirection="right"
|
|
|
+ @click="toSelect('brand')"></u-cell>
|
|
|
+ </up-col>
|
|
|
+ </up-row>
|
|
|
+ </view>
|
|
|
+ <view class="search__input">
|
|
|
+ <up-row>
|
|
|
+ <up-col :span="12">
|
|
|
+ <u-cell :title="obj.spec" :label="getLabel('spec')" :isLink="true" arrowDirection="right"
|
|
|
+ @click="toSelect('spec')"></u-cell>
|
|
|
+ </up-col>
|
|
|
+ </up-row>
|
|
|
+ </view>
|
|
|
+ <view class="search__input">
|
|
|
+ <up-row gutter="10" justify="around">
|
|
|
+ <up-col span="4">
|
|
|
+ <up-button @click="searchCancel">取消</up-button>
|
|
|
+ </up-col>
|
|
|
+ <up-col span="4">
|
|
|
+ <up-button @click="toMultSearch" type="primary">查询</up-button>
|
|
|
+ </up-col>
|
|
|
+ </up-row>
|
|
|
+ </view>
|
|
|
+ </u-popup>
|
|
|
+ <u-action-sheet :actions="selectionList" :title="selectionTitle" :show="sheetShow"
|
|
|
+ @select="sheetClick"></u-action-sheet>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script setup>
|
|
|
+import { ref, defineEmits, getCurrentInstance, onMounted } from 'vue';
|
|
|
+const $emit = defineEmits(['toFilterSearch'])
|
|
|
+let obj = ref({});
|
|
|
+let show = ref(false);
|
|
|
+let brandSelection = ref([]);
|
|
|
+let specSelection = ref([]);
|
|
|
+let selectionList = ref([]);
|
|
|
+let selection = ref(''); // brand,spec
|
|
|
+let selectionTitle = ref('请选择');
|
|
|
+let sheetShow = ref(false);
|
|
|
+const $api = getCurrentInstance()?.appContext.config.globalProperties.$api;
|
|
|
+// #region 更多内容查询
|
|
|
+const showMoreFilter = () => {
|
|
|
+ show.value = true;
|
|
|
+}
|
|
|
+const searchCancel = () => {
|
|
|
+ delete obj.value.brand;
|
|
|
+ delete obj.value.spec;
|
|
|
+ show.value = false;
|
|
|
+}
|
|
|
+const toMultSearch = () => {
|
|
|
+ $emit('toFilterSearch', obj.value)
|
|
|
+ show.value = false;
|
|
|
+}
|
|
|
+// #endregion
|
|
|
+
|
|
|
+/**商品名称搜索框向上提交查询 */
|
|
|
+const toSearch = () => {
|
|
|
+ $emit('toFilterSearch', { name: obj.value.name })
|
|
|
+}
|
|
|
+
|
|
|
+// #region 品牌与规格选项请求及渲染
|
|
|
+onMounted(() => {
|
|
|
+ searchCondition();
|
|
|
+})
|
|
|
+const searchCondition = async () => {
|
|
|
+ const res = await $api('/perfume/getSelection', 'GET')
|
|
|
+ if (res.errcode !== 0) return;
|
|
|
+ const noChoose = { name: '不选择', value: undefined }
|
|
|
+ const { brandList = [], specList = [] } = res.data;
|
|
|
+ brandSelection.value = brandList.map(i => ({ name: i, value: i }));
|
|
|
+ brandSelection.value.unshift(noChoose)
|
|
|
+ specSelection.value = specList.map(i => ({ name: i, value: i }));
|
|
|
+ specSelection.value.unshift(noChoose)
|
|
|
+}
|
|
|
+const getLabel = (type) => {
|
|
|
+ const val = obj.value[type]
|
|
|
+ if (!val && type === 'brand') return '请选择商品品牌'
|
|
|
+ if (!val && type === 'spec') return '请选择商品规格'
|
|
|
+}
|
|
|
+// #endregion
|
|
|
+// #region sheet选择框操作
|
|
|
+const toSelect = (type) => {
|
|
|
+ selection.value = type;
|
|
|
+ let list = [];
|
|
|
+ let tit = '请选择'
|
|
|
+ if (type === 'brand') {
|
|
|
+ list = brandSelection.value
|
|
|
+ tit = `${tit}商品品牌`
|
|
|
+ }
|
|
|
+ else if (type === 'spec') {
|
|
|
+ list = specSelection.value
|
|
|
+ tit = `${tit}商品规格`
|
|
|
+ }
|
|
|
+ selectionList.value = list;
|
|
|
+ selectionTitle.value = tit;
|
|
|
+ sheetShow.value = true;
|
|
|
+}
|
|
|
+const sheetClick = (data) => {
|
|
|
+ obj.value[selection.value] = data.value
|
|
|
+ closeSheet();
|
|
|
+}
|
|
|
+const closeSheet = () => {
|
|
|
+ selection.value = undefined;
|
|
|
+ selectionList.value = [];
|
|
|
+ selectionTitle.value = '请选择'
|
|
|
+ sheetShow.value = false;
|
|
|
+}
|
|
|
+// #endregion
|
|
|
+</script>
|
|
|
+
|
|
|
+<style scoped>
|
|
|
+.search__input {
|
|
|
+ margin: 10px 5px;
|
|
|
+}
|
|
|
+</style>
|