模糊查找

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
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
<!DOCTYPE html>
<html>
 
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title></title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <style>
        #form {
            text-align: center;
        }
 
        table,
        th,
        td {
            border: 1px solid #7a7979;
        }
 
        table {
            margin: 10px auto;
            border-collapse: collapse;
        }
 
        th,
        td {
            padding: 15px;
        }
 
        tr:last-child {
            text-align: left;
        }
 
        button {
            padding: 10px;
            background-color: rgb(74, 170, 138);
            color: #fff;
            border-radius: 5px;
            border: none;
            cursor: pointer;
        }
 
        #header {
            margin: 0 auto;
            display: flex;
            width: 300px;
            height: 40px;
 
        }
 
        input {
            flex: 1;
            margin: 0 20px;
            border-radius: 5px;
            border: 1px solid #757575;
 
        }
 
        span {
            line-height: 40px;
        }
    </style>
</head>
 
<body>
    <div id="app">
        <info-table :titles="titles" :info="info" @fn="fatherdel" @fn1="fathersearch" @fn2="show">
 
        </info-table>
    </div>
 
    <template id="temp">
        <div id="form">
            <div id="header">
                <span>名称</span><input type="text" @input="clearfn" v-model="searchStr"><button
                    @click="search">查询</button>
            </div>
            <table>
                <tr>
                    <th v-for="item in titles">{{item}}</th>
                </tr>
                <tr v-for="item,index in info" v-show="item.is_show">
                    <td>{{item.id}}</td>
                    <td>{{item.title}}</td>
                    <td>{{item.price_info.toFixed(2)}}</td>
                    <td><button @click="del(index)">删除</button></td>
                </tr>
                <tr>
                    <td colspan="4">总价为:{{total | Rformat}}</td>
                </tr>
            </table>
 
        </div>
    </template>
 
    <script>
 
        let infoTable = {
            template: '#temp',
            props: ['titles', 'info'],
            data() {
                return {
                    searchStr: ''
                }
            },
            filters: {
                Rformat(val) {
                    return '¥' + val.toFixed(2) + '元'
                }
            },
            methods: {
                del(i) {
                    this.$emit('fn', i)
                },
                search() {
                    this.$emit('fn1', this.searchStr)
                },
                clearfn() {
                    if (this.searchStr) {
                        return
                    }
 
                    this.$emit('fn2')
                }
 
            },
            computed: {
                total: {
                    get() {
                        // var rets = this.info.filter((item, index, self) => {
                        //     return item.is_show
                        // })
 
                        var ret = this.info.reduce((pre, cur, index, self) => {
                            return cur.is_show ? pre + cur.price_info : pre
                        }, 0)
 
                        return ret
                    },
                    set(newVal) {
                        console.log(newVal);
                    }
                }
            }
        }
 
        new Vue({
            el: '#app',
            data: {
                titles: ["ID", "主标题", "起步价格", "操作"],
                info: [{
                    "id": 287,
                    "title": "严选新式样板间",
                    "price_info": 29.9,
                    "is_show": true
                }, {
                    "id": 286,
                    "title": "无“油”无虑的甜蜜酥脆",
                    "price_info": 45,
                    "is_show": true
                }, {
                    "id": 283,
                    "title": "孩子成长中少不了的一双鞋",
                    "price_info": 78,
                    "is_show": true
                }, {
                    "id": 282,
                    "title": "成就一室笋香1",
                    "price_info": 121,
                    "is_show": true
                }, {
                    "id": 281,
                    "title": "条纹新风尚",
                    "price_info": 29,
                    "is_show": true
                }, {
                    "id": 277,
                    "title": "治愈生活的满怀柔软",
                    "price_info": 66.78,
 
                    "is_show": true
                }, {
                    "id": 274,
                    "title": "没有软木拖,怎么过夏天",
                    "price_info": 50.99,
                    "is_show": true
                }, {
                    "id": 272,
                    "title": "料理也要精细简单",
                    "price_info": 69,
                    "is_show": true
                }, {
                    "id": 271,
                    "title": "选式新懒人",
                    "price_info": 15.3,
                    "is_show": true
                }, {
                    "id": 268,
                    "title": "米饭好吃的秘诀:会呼吸的锅",
                    "price_info": 20.1,
                    "is_show": true
                }]
            },
            components: {
                infoTable
            },
            methods: {
                fatherdel(i) {
                    this.info.splice(i, 1)
                },
                fathersearch(val) {
                    this.info.forEach(item => {
                        item.is_show = item.title.includes(val) ? true : false
                    });
                },
                show() {
                    this.info.forEach(item => {
                        item.is_show = true
                    });
                }
            }
        })
    </script>
</body>
 
</html>

  

posted @   Gawaine  阅读(44)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
点击右上角即可分享
微信分享提示