Calculate the total price of goods?

how to calculate the price of the selected item through checkbox?

clipboard.png

<template>
  <div>
    <bread-crumb :bread-crumb-list="breadCrumbList"></bread-crumb>
    <ul>
        <li class="bookItem" v-for="item in bookList" :key="item.id" style="text-align: left;">
            <el-checkbox-group v-model="checkList" @change="handleCheckedBooks">
                <el-checkbox :label="item.id">
                    <img class="bookImg" :src="item.book_url" style="width: 100px; height: 100px;">
                    <h3>{{item.book_title}}</h3>
                    <span class="price">{{item.book_price}}</span>
                    <div>
                      <el-input-number v-model="item.num" size="small" @change="handleChange" :min="1"></el-input-number>  
                    </div>
                </el-checkbox>
            </el-checkbox-group>
        </li>
    </ul>
    <div class="cart">
        <span></span>
        <span class="highLight">{{mount}}</span>
        <span></span>
        <span></span>
        <span class="highLight">{{total}}</span>
        <el-button type="primary" @click.stop="onOrder"></el-button>
    </div>
  </div>
</template>
<script>
import BreadCrumb from "@/components/common/BreadCrumb"
export default {
  components: {
    BreadCrumb
  },
  data () {
      return {
          breadCrumbList: [],
          bookList: [],
          radio: "0",
          checkList: [],
          num: 1,
          mount: 0,
          total: 0
      }
  },
  mounted () {
    this.breadCrumbList = [
        {title: ""},
        {title: ""},
        {title: ""}
    ],
    this.bookList = [{
        id: "0",
        book_url: require("../assets/images/book1.jpg"),
        book_title: "",
        book_price: "39",
        num: 0
        },{
        id: "1",
        book_url: require("../assets/images/book2.jpg"),
        book_title: "",
        book_price: "45",
        num: 0
        },{
        id: "2",
        book_url: require("../assets/images/book3.jpg"),
        book_title: "",
        book_price: "59",
        num: 0
        },{
        id: "3",
        book_url: require("../assets/images/book4.jpg"),
        book_title: "",
        book_price: "30",
        num: 0
        },{
        id: "4",
        book_url: require("../assets/images/book5.jpg"),
        book_title: "",
        book_price: "25",
        num: "0"
        },{
        id: "5",
        book_url: require("../assets/images/book6.jpg"),
        book_title: "",
        book_price: "69",
        num: 0
        }
    ]
  },
  methods: {
      onOrder () {
          
      },
      handleCheckedBooks () {
           console.log(this.checkList)
      },
      handleChange (val) {
        this.mountPP
        this.calcTotalMoney()
      },
      calcTotalMoney () {
          let totalMoney = 0
          this.checkList.forEach((item) => {
              totalMoney += item.num *item.book_price
          })
          this.total = totalMoney
      }
  }

}
< / script >
what"s going on now that checkList can only get the id of the selected item?

Sep.28,2021

your label defined id, that appears in checkList, that is, id;
to find the item in bookList through the id in checkList, and then simply add, subtract, multiply and divide.
clipboard.png


use the calculation attribute, specific code, you can debug it

computed:{
    totalMoney(){
        let a=0;
        this.bookList.forEach(v=>{
            a+=v.book_price*v.num
        })
        return a;
    }
}
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3cb1b-2bab0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3cb1b-2bab0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?