VUE3中Element table表頭動(dòng)態(tài)展示合計(jì)信息
一、背景
原型上需要對(duì)兩個(gè)字段動(dòng)態(tài)合計(jì),輸出摘要信息
原先想到是的Element的 :summary-method,發(fā)現(xiàn)不是動(dòng)態(tài),所以換監(jiān)聽(tīng)來(lái)實(shí)現(xiàn)
二、vue代碼
<el-table v-model="loading" :data="itemList"> <el-table-column label="藥品名稱(chēng)" prop="drugName" fixed min-width="100px" :show-overflow-tooltip="true"/> <el-table-column label="規(guī)格" prop="drugSpec" :show-overflow-tooltip="true"/> <el-table-column label="批號(hào)" prop="batchNo" :show-overflow-tooltip="true"/> <el-table-column label="賬面數(shù)" prop="batchStockDesc" min-width="90px"/> <el-table-column label="盤(pán)存數(shù)" align="center"> <el-table-column prop="stocktakeQty" min-width="150px"> <template v-slot="scope"> <el-input-number :disabled="!canEdit" v-model="scope.row.stocktakeQty" :min="0" controls-position="right" size="small"/> </template> </el-table-column> <el-table-column label="單位" prop="unit" min-width="90px"> <template #default="scope"> <dict-tag :options="bd_plat_drug_unit" :value="scope.row.unit" :showValue="false"/> </template> </el-table-column> <el-table-column prop="stocktakeTinyqty" min-width="150px"> <template v-slot="scope"> <el-input-number :disabled="!canEdit" v-model="scope.row.stocktakeTinyqty" :min="0" controls-position="right" size="small"/> </template> </el-table-column> <el-table-column label="小單位" prop="tinyUnit" min-width="90px"> <template #default="scope"> <dict-tag :options="bd_plat_drug_unit" :value="scope.row.tinyUnit" :showValue="false"/> </template> </el-table-column> </el-table-column> <el-table-column label="零售" align="center"> <el-table-column label="零售價(jià)" prop="retailPrice" min-width="100px" :show-overflow-tooltip="true" align="right"/> <el-table-column label="盤(pán)前金額" prop="totalRetail" min-width="100px" :show-overflow-tooltip="true" align="right"/> <el-table-column label="盤(pán)后金額" prop="afterTotalRetail" min-width="100px" :show-overflow-tooltip="true" align="right"> <template v-slot="scope"> {{ scope.row.afterTotalRetail = computeTotalMoney(scope.row.stocktakeQty, scope.row.stocktakeTinyqty, scope.row.packageQty, scope.row.retailPrice) }} </template> </el-table-column> <el-table-column label="成本損溢金額" prop="totalLossoverRetail" min-width="120px" align="right"> <template v-slot="scope"> {{ scope.row.totalLossoverRetail = computeDifferenceMoney(scope.row.stocktakeQty, scope.row.stocktakeTinyqty, scope.row.packageQty, scope.row.retailPrice, scope.row.totalRetail) }} </template> </el-table-column> </el-table-column> <el-table-column label="成本" align="center"> <el-table-column label="采購(gòu)價(jià)" prop="purchasePrice" min-width="100px" :show-overflow-tooltip="true" align="right"/> <el-table-column label="盤(pán)前金額" prop="totalPurchase" min-width="100px" :show-overflow-tooltip="true" align="right"/> <el-table-column label="盤(pán)后金額" prop="afterTotalPurchase" min-width="100px" :show-overflow-tooltip="true" align="right"> <template v-slot="scope"> {{ scope.row.afterTotalPurchase = computeTotalMoney(scope.row.stocktakeQty, scope.row.stocktakeTinyqty, scope.row.packageQty, scope.row.purchasePrice) }} </template> </el-table-column> <el-table-column label="成本損溢金額" prop="totalLossoverPurchase" min-width="120px" :show-overflow-tooltip="true" align="right"> <template v-slot="scope"> {{ scope.row.totalLossoverPurchase = computeDifferenceMoney(scope.row.stocktakeQty, scope.row.stocktakeTinyqty, scope.row.packageQty, scope.row.purchasePrice, scope.row.totalPurchase) }} </template> </el-table-column> </el-table-column> <el-table-column label="生產(chǎn)企業(yè)" prop="firmName" min-width="80px" :show-overflow-tooltip="true"/> <el-table-column label="產(chǎn)地" prop="producerName" min-width="80px" :show-overflow-tooltip="true"/> <el-table-column label="庫(kù)位碼" prop="locationCode" min-width="100px" :show-overflow-tooltip="true"/> <el-table-column label="操作" fixed="right" min-width="60px" align="center" v-if="canEdit" class-name="small-padding fixed-width"> <template #default="scope"> <el-button link type="primary" icon="Delete" title="刪除" @click="handleDelete(scope.row)"/> </template> </el-table-column> </el-table>
其中代碼,賦值給totalLossoverRetail 才能保證,后期監(jiān)聽(tīng)時(shí)數(shù)據(jù)有發(fā)生變化
{{ scope.row.totalLossoverRetail = computeDifferenceMoney(scope.row.stocktakeQty, scope.row.stocktakeTinyqty, scope.row.packageQty, scope.row.retailPrice, scope.row.totalRetail) }}
三、方法代碼
watch(itemList, () => { console.log(itemList.value, 'itemList') let totalLossoverRetail = 0 let totalLossoverPurchase = 0 itemList.value.forEach(item => { totalLossoverRetail = Number(totalLossoverRetail) + Number(item.totalLossoverRetail); totalLossoverPurchase = Number(totalLossoverPurchase) + Number(item.totalLossoverPurchase); }) sumDescription.value = '成本損溢金額 ' + totalLossoverPurchase + ' 零售損溢金額 ' + totalLossoverRetail }, {deep: true});
其中開(kāi)啟深度監(jiān)聽(tīng)
四、效果
到此這篇關(guān)于VUE3中Element table表頭動(dòng)態(tài)展示合計(jì)信息的文章就介紹到這了,更多相關(guān)VUE3 Element table動(dòng)態(tài)表頭內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Vue中Table組件行內(nèi)右鍵菜單實(shí)現(xiàn)方法(基于 vue + AntDesign)
這篇文章主要介紹了Vue中Table組件行內(nèi)右鍵菜單實(shí)現(xiàn)方法,該項(xiàng)目是基于 vue + AntDesign的,具體實(shí)例代碼給大家介紹的非常詳細(xì) ,需要的朋友可以參考下2019-11-11axios對(duì)請(qǐng)求各種異常情況處理的封裝方法
今天小編就為大家分享一篇axios對(duì)請(qǐng)求各種異常情況處理的封裝方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-09-09基于vue.js仿淘寶收貨地址并設(shè)置默認(rèn)地址的案例分析
這篇文章主要介紹了基于vue.js仿淘寶收貨地址并設(shè)置默認(rèn)地址的案例分析,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-08-08vant的Loading加載動(dòng)畫(huà)組件的使用(通過(guò)接口拿數(shù)據(jù)時(shí)顯示加載狀態(tài))
這篇文章主要介紹了vant的Loading加載動(dòng)畫(huà)組件的使用,通過(guò)接口拿數(shù)據(jù)時(shí)顯示加載狀態(tài),本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2024-01-01Vue使用pinia管理數(shù)據(jù)pinia持久化存儲(chǔ)問(wèn)題
這篇文章主要介紹了Vue使用pinia管理數(shù)據(jù)pinia持久化存儲(chǔ)問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-03-03淺談Vuex的this.$store.commit和在Vue項(xiàng)目中引用公共方法
這篇文章主要介紹了淺談Vuex的this.$store.commit和在Vue項(xiàng)目中引用公共方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-07-07