123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372 |
- <template>
- <view class="container">
- <u-popup :show="show" :customStyle="{ width: '88vw' }" :overlayStyle="{ zIndex: '997' }" zIndex="998" mode="right"
- @close="close" :closeOnClickOverlay="true">
- <view v-if="isBar" :style="{ height: (tovw(CustomBar + (headTop - 0))) }" />
- <My_listbox :pullDown="false" ref="box">
- <view v-for="(it, i) in filter" :key="it.label">
- <view class="label">
- {{ it.label }}
- </view>
- <view class="value-box">
- <view class="item" v-for="(item, index) in it.list" :key="index"
- :class="it.selectIndex == index ? 'active' : ''" @click="changeValue(i, index)">
- {{ it.showKey ? item[it.showKey] : item }}
- </view>
- </view>
- </view>
- <block v-if="dateRange">
- <view class="label">
- 时间区间
- </view>
- <view class="date-box">
- <scroll-view :scroll-x="true">
- <view class="options">
- <view class="item" :class="day == 1 ? 'active' : ''" @click="fast(1)">
- 今天
- </view>
- <view class="item" :class="day == 7 ? 'active' : ''" @click="fast(7)">
- 7天
- </view>
- <view class="item" :class="day == 30 ? 'active' : ''" @click="fast(30)">
- 30天
- </view>
- <view style="width: 10px;" />
- <u-number-box :value="day" @change="valChange" />
- </view>
- </scroll-view>
- <view class="row" style="margin-top: 20px">
- <picker mode="date" class="date-box" :style="{ color: begindate ? '#333' : '#ddd' }"
- :value="begindate" data-name="begindate" :end="enddate" @change="onDateChange">
- {{ begindate || '开始日期' }}
- </picker>
- <view style="padding: 0 10px;">
- -
- </view>
- <picker mode="date" class="date-box" :style="{ color: enddate ? '#333' : '#ddd' }"
- :value="enddate" data-name="enddate" @change="onDateChange" :start="begindate">
- {{ enddate || '结束日期' }}
- </picker>
- </view>
- </view>
- <!--
- <view class="row">
- 区间:<picker mode="date" class="date-box" :style="{ color: begindate ? '#333' : '#ddd' }"
- :value="begindate" data-name="begindate" :start="start" :end="enddate" @change="onDateChange">
- {{ begindate || '开始日期' }}
- </picker>
- <view style="padding: 0 10px;">
- -
- </view>
- <picker mode="date" class="date-box" :style="{ color: enddate ? '#333' : '#ddd' }" :value="enddate"
- data-name="enddate" @change="onDateChange" :start="begindate">
- {{ enddate || '结束日期' }}
- </picker>
- </view>
- -->
- </block>
- </My_listbox>
- <view id="bottom">
- <view class="bottom">
- <view class="bot" @click="show = false" hover-class="navigator-hover">
- 关闭
- </view>
- <view v-if="isReset" @click="reset" class="bot reset" hover-class="navigator-hover">
- 重置
- </view>
- <view v-if="loading" class="bot confirm" hover-class="navigator-hover">
- <u-loading-icon color="#007aff" mode="semicircle" /> 查询中...
- </view>
- <view v-else class="bot confirm" @click="confirm" hover-class="navigator-hover">
- 确定
- </view>
- </view>
- <view class="safety" />
- </view>
- </u-popup>
- </view>
- </template>
- <script>
- import { formatTime } from "../utils/getTime";
- export default {
- name: 'My_filter',
- props: {
- isReset: {
- type: Boolean,
- default: true
- },
- isBar: {
- type: Boolean,
- default: true
- },
- headTop: {
- type: Number,
- default: 0
- },
- filter1: {
- type: Array,
- default: () => [{
- label: "筛选项",
- list: [{
- name: 1
- }, {
- name: 2
- }, {
- name: 3
- }],
- selectKey: "name",
- selectIndex: null,
- default: null,
- showKey: "name",
- key: "name",
- }]
- },
- dateRange: Boolean,
- start: String,
- onConfirm: Function
- },
- data() {
- return {
- show: false,
- CustomBar: this.CustomBar,
- day: 0,
- begindate: "",
- enddate: "",
- filter: [],
- loading: false
- };
- },
- methods: {
- open(num) {
- this.show = true;
- this.filter = this.filter1;
- setTimeout(() => {
- this.getHeight("#bottom", this, false).then(({ height }) => this.$refs.box.setHeight('minus', (height - 0) + (num - 0)))
- }, 100);
- },
- close() {
- this.show = false;
- this.loading = false;
- },
- changeValue(index1, index2) {
- let newltem = this.filter[index1];
- newltem.selectIndex = newltem.selectIndex == index2 ? null : index2;
- this.$set(this.filter, index1, newltem);
- },
- reset() {
- this.filter = this.filter.map(v => {
- v.selectIndex = v.default || null;
- return v
- });
- this.day = 0;
- this.begindate = "";
- this.enddate = "";
- },
- confirm() {
- let obj = {};
- this.filter.forEach(v => {
- let value = v.list[v.selectIndex] || "";
- if (value && v.selectKey) value = value[v.selectKey]
- obj[v.key] = value;
- })
- if (this.dateRange) {
- obj.begindate = this.begindate;
- obj.enddate = this.enddate;
- }
- this.loading = true;
- this.$emit("onConfirm", obj)
- },
- fast(num) {
- return new Promise((resolve) => {
- this.day = num;
- let now = new Date().getTime(),
- end = now + 86400000,
- beg = end - (num * 86400000);
- this.begindate = formatTime(new Date(beg)).split(' ')[0];
- this.enddate = formatTime(new Date(end)).split(' ')[0];
- resolve()
- })
- },
- valChange(e) {
- this.fast(e.value)
- },
- onDateChange(e) {
- this[e.target.dataset.name] = e.detail.value;
- if (this.begindate && this.enddate) {
- let end = new Date(this.enddate).getTime(),
- beg = new Date(this.begindate).getTime();
- this.day = (end - beg) / 86400000;
- }
- },
- },
- }
- </script>
- <style lang="scss" scoped>
- .label {
- line-height: 20px;
- font-size: 14px;
- color: #333333;
- padding: 15px 10px 10px;
- }
- .date-box {
- .options {
- display: flex;
- .item {
- display: flex;
- align-items: center;
- justify-content: center;
- background: #F5F5F5;
- border-radius: 4px;
- margin-left: 10px;
- font-size: 14px;
- color: #333333;
- overflow: hidden;
- box-sizing: border-box;
- padding: 6px 12px;
- flex-shrink: 0;
- }
- .active {
- background: #0B3F7E !important;
- color: #FFFFFF !important;
- }
- /deep/ .u-number-box__minus,
- /deep/.u-number-box__input,
- /deep/.u-number-box__plus {
- height: 30px !important;
- }
- /deep/ .u-number-box__input {
- width: 35px !important;
- }
- }
- .row {
- display: flex;
- align-items: center;
- font-size: 14px;
- color: #646566;
- padding: 10px;
- padding-top: 0;
- border-bottom: 1px solid #ddd;
- box-sizing: border-box;
- .date-box {
- flex: 1;
- height: 35px;
- line-height: 35px;
- background: #FFFFFF;
- border-radius: 4px;
- border: 1px solid #CCCCCC;
- font-size: 14px;
- padding-left: 10px;
- }
- }
- }
- .value-box {
- display: flex;
- flex-wrap: wrap;
- box-sizing: border-box;
- border-bottom: 1px solid #ddd;
- .item {
- display: flex;
- align-items: center;
- justify-content: center;
- width: 97px;
- height: 36px;
- background: #F5F5F5;
- border-radius: 4px;
- margin-left: 10px;
- margin-bottom: 10px;
- font-size: 14px;
- color: #333333;
- overflow: hidden;
- padding: 0 6px;
- box-sizing: border-box;
- }
- .active {
- background: #0B3F7E !important;
- color: #FFFFFF !important;
- }
- }
- .row {
- display: flex;
- align-items: center;
- font-size: 14px;
- color: #646566;
- padding: 10px;
- padding-top: 0;
- border-bottom: 1px solid #ddd;
- box-sizing: border-box;
- .date-box {
- flex: 1;
- height: 45px;
- line-height: 45px;
- background: #FFFFFF;
- border-radius: 4px;
- border: 1px solid #CCCCCC;
- font-size: 14px;
- padding-left: 10px;
- }
- }
- .bottom {
- display: flex;
- justify-content: space-between;
- align-content: center;
- width: 100%;
- border-top: 1px solid #ddd;
- padding: 10px;
- box-sizing: border-box;
- .bot {
- display: flex;
- justify-content: center;
- align-items: center;
- width: 93px;
- height: 45px;
- background: #FFFFFF;
- border-radius: 4px;
- border: 1px solid #CCCCCC;
- font-size: 15px;
- color: #666666;
- }
- .reset {
- border-color: #0B3F7E;
- color: #0B3F7E;
- }
- .confirm {
- border-color: #0B3F7E;
- background-color: #0B3F7E;
- color: #FFFFFF;
- }
- /deep/ .u-button {
- background: #FFFFFF;
- border-radius: 4px;
- margin: 0 !important;
- }
- /deep/ .u-button__text {
- font-size: 14px !important;
- }
- }
- </style>
|