search.vue 7.88 KB
Newer Older
godwithdh's avatar
godwithdh committed
1 2
<template>
  <div class="searchComponent">
张锡奇's avatar
张锡奇 committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
      <!-- <group style="margin-top:0 !important;"> -->
          <div class="Content gradient" v-if="typeList.input || typeList.select">
            <div class="selector" v-if="typeList.select">
                <select :multiple="multiple" v-model="selectValue" @change="changeSelect($event)">
                    <option v-for="(item,index) in status" :key="index" :value="item.sStatus">{{item.sStatus || '全部'}}</option>
                </select>
            </div>
            <div class="_input" v-if="typeList.input">
                <input class="input" v-model="inputValue" :placeholder="placeholder" v-on:input="changeInput"/>
                <i class='iconfont icon-close' id="close" v-if="inputValue" @click='clearInputValue'></i>
            </div>
        </div>
        <div class="Content">
            <div class="Title">时间纬度</div>
            <div class="padding-left-15 btns">
godwithdh's avatar
godwithdh committed
18 19
                <button @click="changeDate(v)" v-for="(v,i) in btns" :key="i" :class="{active:v == selectDate}">
                    {{v}}
godwithdh's avatar
godwithdh committed
20
                </button>
张锡奇's avatar
张锡奇 committed
21 22 23 24
            </div>
        </div>
        <div class="Content" >
            <div class="Title">日期范围</div>
godwithdh's avatar
godwithdh committed
25 26
            <div style="flex:1;display:flex;" class="DATE">
                <div class="padding-left-15 dateTime">
godwithdh's avatar
godwithdh committed
27
                    <datetime :end-date="search.dEndDate" v-model="search.dBeginDate" format="YYYY-MM-DD" @on-confirm="searchData($event,1)"></datetime>
张锡奇's avatar
张锡奇 committed
28 29
                    <!-- <i class='iconfont icon-right'></i> -->
                </div>
godwithdh's avatar
godwithdh committed
30 31 32
                <span class="line"/>
                <div class="padding-right-15 dateTime">
                    <datetime :start-date="search.dBeginDate" v-model="search.dEndDate" format="YYYY-MM-DD" @on-confirm="searchData($event,2)"></datetime>
张锡奇's avatar
张锡奇 committed
33 34 35 36 37 38
                    <!-- <i class='iconfont icon-right'></i> -->
                </div>
            </div>
        </div>
        
      <!-- </group> -->
godwithdh's avatar
godwithdh committed
39 40 41 42 43 44 45 46 47 48 49 50
  </div>
</template>

<script>
import { Flexbox, FlexboxItem ,Search,Selector,XButton,Datetime,Group, Cell,Scroller,XHeader} from 'vux';
import Util from '@/libs/util.js'

export default {
  name: 'searchComponent',
  data () {
    return {
        btns:['本日','本周','本月','本年'],
godwithdh's avatar
godwithdh committed
51
        selectDate:"本月",
张锡奇's avatar
张锡奇 committed
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
        inputValue:'',
        selectValue:'全部'
    }
  },
  props:{
    search: {
        type: Object,
        default:function(){
            return {}
        }
    },
    status: {
        type: Array,
        default:function(){
            return []
        }
    },
    typeList:{
        type:Object,
        default:function(){
            return {
                input:false,
                select:false,
                btns:true,
                time:true
            }
        }
    },
    multiple:{
        type:Boolean,
        default:false
    },
    placeholder:{
        type:String,
        default:'请输入...'
godwithdh's avatar
godwithdh committed
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
    }
  },
  methods:{
      searchData(e,type){
          let dateList = this.btns.map(x=>Util.getDate(x));
          let endDate = Util.dateFormat(new Date(),'yyyy-MM-dd');
          if(type == 1){
              if(dateList.indexOf(e) != -1 && this.search.dEndDate == endDate){
                  this.active = dateList.indexOf(e);
              }else{
                  this.active = -1;
              }
          }else{
              if(endDate == e && dateList.indexOf(this.search.dBeginDate) != -1){
                  this.active = dateList.indexOf(e);
              }else{
                  this.active = -1;
              }
          }
          this.global.$emit('searchData');
      },
godwithdh's avatar
godwithdh committed
108 109 110 111 112
      changeDate(name){
        this.selectDate = name;
        this.search.dEndDate = Util.dateFormat(new Date(),'yyyy-MM-dd');
        this.search.dBeginDate = Util.getDate(name);
        this.global.$emit('searchData');
张锡奇's avatar
张锡奇 committed
113 114 115 116 117 118 119
      },
      changeSelect(e){
        this.selectValue = this.status[e.target.selectedIndex].sStatus;
        this.search.sStatus = this.selectValue;
        this.global.$emit('searchData');
      },
      changeInput(e){
张锡奇's avatar
张锡奇 committed
120
        this.search.searchvalue = this.inputValue;
张锡奇's avatar
张锡奇 committed
121 122 123 124
        this.global.$emit('searchData');
      },
      clearInputValue(e){
        this.inputValue = "";
张锡奇's avatar
张锡奇 committed
125
        this.search.searchvalue = this.inputValue;
张锡奇's avatar
张锡奇 committed
126
        this.global.$emit('searchData');
godwithdh's avatar
godwithdh committed
127 128
      }
  },
张锡奇's avatar
张锡奇 committed
129
  mounted(){
godwithdh's avatar
godwithdh committed
130
    window.DATA = this;
张锡奇's avatar
张锡奇 committed
131
  },
godwithdh's avatar
godwithdh committed
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
  components: {
    Search,
    Selector,
    Flexbox,
    FlexboxItem,
    XButton,
    Datetime,
    XHeader,
    Group, 
    Cell,
    Scroller
  },
}
</script>

<style lang="less">
    .searchComponent{
张锡奇's avatar
张锡奇 committed
149 150 151 152 153 154 155
        .Content{
            min-height:40px;padding:0 10px;background:white;
            display: flex;
            align-items: center;
            .Title{
                width:50px;text-align:center;font-size:12px;
            }
godwithdh's avatar
godwithdh committed
156 157 158 159 160 161 162 163 164 165 166
            >.DATE{
                justify-content: space-around;
                >.line{
                    width: 20px;
                    margin:0 -50px;
                    background: #03f315;
                    height: 4px;
                    align-self: center;
                    border-radius: 50px;
                }
            }
张锡奇's avatar
张锡奇 committed
167 168 169 170
        }
        .gradient{
            background: linear-gradient(90deg,#8470FF, #2d8cf0, #00B2EE)
        }
godwithdh's avatar
godwithdh committed
171 172 173
        .btns{
            text-align: right;
            font-size:12px;
张锡奇's avatar
张锡奇 committed
174
            flex:1;
godwithdh's avatar
godwithdh committed
175 176 177 178 179 180
            button{
                height: 20px;
                width: 50px;
                border: 1px solid grey;
                border-radius: 50px;
                margin-left:10px;
张锡奇's avatar
张锡奇 committed
181
                box-sizing: border-box;
godwithdh's avatar
godwithdh committed
182 183 184 185
            }
            .active{
                color:#5E9AFE;
                border:1px solid #5E9AFE;
张锡奇's avatar
张锡奇 committed
186 187 188 189 190 191 192
                box-sizing: border-box;
            }
        }
        .dateTime{
            a{
                display: flex;
                align-items: center;
godwithdh's avatar
godwithdh committed
193 194 195
            }
        }
        /deep/ .vux-cell-value{
张锡奇's avatar
张锡奇 committed
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
            font-size:12px !important;
        }
        /deep/ .weui-cell__ft{
            display: flex;
            justify-content: flex-end;
            align-items: center;
        }
        .selector{
            select{
                width:100%;
            }
            border-radius: 0;
            font-size: 12px;
            padding: 5px 20px 5px 10px;
            width: 100px;
            // background: #ddd;
            background:rgba(255,255,525,0.3);
            border-top-left-radius: 5px;
            border-bottom-left-radius: 5px;
            height:30px;
            position: relative;
            transition: all 0.3ms;
            display: flex;
            align-items: center;
            border-right:0.5px solid #8a8a8a;
        }
        .selector:after{
            content:'';
            position: absolute;
            top:12px;
            right:5px;
            width: 5px;
            height: 5px;
            border: 5px solid;
            border-color: #666 transparent transparent transparent;
            box-sizing: border-box;
        }
        ._input {
            flex: 1;
            // border: 1px solid #ccc;
            box-sizing: border-box;
            border-left: 0;
            border-top-right-radius: 5px;
            border-bottom-right-radius: 5px;
            padding: 0 25px 0 5px;
            height:30px;
godwithdh's avatar
godwithdh committed
242
            font-size:12px;
张锡奇's avatar
张锡奇 committed
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
            position: relative;
            box-sizing: border-box;
            background:rgba(255,255,525,0.3);
            input{
                height:100%;
                width:100%;
            }
            input::-webkit-input-placeholder {
                /* placeholder颜色  */
                color: black;
            }
            .iconfont{
                position: absolute;
                right:0;
                width:25px;
                height:100%;
                top: 0;
                font-size: 15px;
                display: flex;
                justify-content: center;
                align-items: center;
                color:red;
            }
godwithdh's avatar
godwithdh committed
266 267 268
        }
    }
</style>