|
@@ -61,10 +61,11 @@
|
|
|
</tr>
|
|
</tr>
|
|
|
</thead>
|
|
</thead>
|
|
|
<tbody>
|
|
<tbody>
|
|
|
- <tr v-for="(item,index) in tableData" >
|
|
|
|
|
|
|
+ <!-- <tr @click="checkLine(item.id)" :class="{'active':item.isCheck}" v-for="(item,index) in tableData" > -->
|
|
|
|
|
+ <tr @click="item.isCheck = !item.isCheck" :class="{'active':item.isCheck}" v-for="(item,index) in tableData" >
|
|
|
<th scope="row">{{index+1}}</th>
|
|
<th scope="row">{{index+1}}</th>
|
|
|
<td>
|
|
<td>
|
|
|
- <input type="checkbox">
|
|
|
|
|
|
|
+ <input type="checkbox" :checked="item.isCheck">
|
|
|
</td>
|
|
</td>
|
|
|
<td>{{item.name}}</td>
|
|
<td>{{item.name}}</td>
|
|
|
<td>{{item.price}}</td>
|
|
<td>{{item.price}}</td>
|
|
@@ -73,7 +74,7 @@
|
|
|
</th>
|
|
</th>
|
|
|
</tr>
|
|
</tr>
|
|
|
<th scope="row" colspan="3">总价</th>
|
|
<th scope="row" colspan="3">总价</th>
|
|
|
- <td>0</td>
|
|
|
|
|
|
|
+ <td>{{totalPrice}}</td>
|
|
|
<td>
|
|
<td>
|
|
|
<button type="button" class="btn btn-primary btn-sm">删除选中</button>
|
|
<button type="button" class="btn btn-primary btn-sm">删除选中</button>
|
|
|
</td>
|
|
</td>
|
|
@@ -118,6 +119,20 @@
|
|
|
goodsName:"",
|
|
goodsName:"",
|
|
|
goodsPrice:""
|
|
goodsPrice:""
|
|
|
},
|
|
},
|
|
|
|
|
+ computed:{
|
|
|
|
|
+ // 计算选中商品的总价
|
|
|
|
|
+ totalPrice(){
|
|
|
|
|
+ let total = 0;
|
|
|
|
|
+ // 1. 先筛选出选中的商品
|
|
|
|
|
+ this.tableData.forEach((item) => {
|
|
|
|
|
+ if(item.isCheck){
|
|
|
|
|
+ total += item.price;
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ // 2. 返回总价
|
|
|
|
|
+ return total;
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
methods:{
|
|
methods:{
|
|
|
// 搜索
|
|
// 搜索
|
|
|
searchFun(){
|
|
searchFun(){
|
|
@@ -150,6 +165,18 @@
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+ },
|
|
|
|
|
+ // 单行选中
|
|
|
|
|
+ checkLine(id){
|
|
|
|
|
+ console.log(id);
|
|
|
|
|
+ // 根据id值进行匹配修改isCheck
|
|
|
|
|
+ let newData = this.tableData.map((item)=>{
|
|
|
|
|
+ if(item.id == id){
|
|
|
|
|
+ item.isCheck = !item.isCheck
|
|
|
|
|
+ }
|
|
|
|
|
+ return item;
|
|
|
|
|
+ })
|
|
|
|
|
+ this.tableData = newData;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|