From 44b115b1c30e16489e13a8503c894ac31a2e6078 Mon Sep 17 00:00:00 2001 From: xinzhedeai <2291006094@qq.com> Date: Mon, 17 Mar 2025 10:57:57 +0800 Subject: [PATCH] =?UTF-8?q?add:=E7=BB=9F=E8=AE=A1=E6=95=B0=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/checklist.html | 79 +++++++++++++++++++++++++++++++++------------- 1 file changed, 57 insertions(+), 22 deletions(-) diff --git a/src/checklist.html b/src/checklist.html index 0f8ed3d..78b473b 100644 --- a/src/checklist.html +++ b/src/checklist.html @@ -113,7 +113,7 @@ <div id="app"> <div class="checklist-container"> <div> - {{ checkData[checkPageIndex].title }} + {{ checkData[checkPageIndex].title }} </div> <div v-for="(item, index) in checkData[checkPageIndex]['checkList']" :key="item.id" class="check-item"> <div class="item-header"> @@ -162,13 +162,8 @@ <van-cell-group> <van-cell>鏂囦欢:<span style="color: red;">(鏍煎紡png/jpg/jpeg)</span> <div> - <van-uploader - style="width: 80px; height:80px;" - v-model="item.photos" - :max-count="3" - :after-read="handleFileUpload" - class="uploader-wrapper" - /> + <van-uploader style="width: 80px; height:80px;" v-model="item.photos" :max-count="3" + :after-read="handleFileUpload" class="uploader-wrapper" /> </div> </van-cell> </van-cell-group> @@ -179,24 +174,28 @@ :after-read="handleFileUpload" class="uploader-wrapper" /> --> - - <van-cell-group> - <van-cell > + + <van-cell-group> + <van-cell> <div> - <van-field label-align="right" readonly clickable label="鏁存敼鏈熼檺" :value="`${item.deadlineDays}澶� 鎴嚦鏁存敼鏃ユ湡锛�${item.deadlineDate}`" - @click="showDeadlinePicker = true; currentItem=item" /> + <van-field label-align="right" readonly clickable label="鏁存敼鏈熼檺" + :value="`${item.deadlineDays}澶� 鎴嚦鏁存敼鏃ユ湡锛�${item.deadlineDate}`" + @click="showDeadlinePicker = true; currentItem=item" /> </div> </van-cell> </van-cell-group> - - + + </div> </div> </div> <div> - <van-button v-show="checkPageIndex<3" type="primary" size="small" @click="checkPageIndex++">涓嬩竴椤�</van-button> - <van-button>{{ }}</van-button> + <van-button v-show="checkPageIndex<3" type="primary" size="small" + @click="checkPageIndex++">涓嬩竴椤�</van-button> + <van-button>{{ notNullCount }}/{{totalItems}} {{noCount}}</van-button> + + </div> <!-- 鏁存敼澶╂暟閫夋嫨鍣� --> <van-popup v-model="showDeadlinePicker" position="bottom"> @@ -226,7 +225,7 @@ photos: [], deadlineDays: '', deadlineDate: '' - },{ + }, { id: 1, title: '妫€鏌ラ」鐩� 2', selected: null, @@ -299,8 +298,32 @@ deadlineDate: '' }], }, - + ] + + function countSelectedNo(result) { // 鑾峰彇 checkList 涓� selected 涓� 'no' 鐨勫璞′釜鏁� + return result.reduce((total, category) => { + return total + category.checkList.filter(item => item.selected === 'no').length; + }, 0); + } + function getTotalCheckListItems(result) { // 鑾峰彇鎵€鏈� checkList 瀛愬厓绱犵殑鎬绘暟 + return result.reduce((total, category) => { + console.log(category, 'category') + return total + category.checkList.length; + }, 0); + } + function countSelectedNotNull(result) { // 鑾峰彇 checkList 涓� selected 涓嶄负 null 鐨勪釜鏁� + return result.reduce((total, category) => { + return total + category.checkList.filter(item => item.selected !== null).length; + }, 0); + } + // 缁熻鍚勪釜鐘舵€佹暟閲� + // 璋冪敤鏂规硶 + const noCount = countSelectedNo(checkData); // selected=no 鐨勪釜鏁� + const totalItems = getTotalCheckListItems(checkData); // checkList 瀛愬厓绱犳€绘暟 + const notNullCount = countSelectedNotNull(checkData); // selected 涓嶄负 null 鐨勪釜鏁� + + // 鍒濆鍖栨鏌ラ」鏁版嵁缁撴瀯 function createCheckItem(id) { return { @@ -314,7 +337,10 @@ description: '', photos: [], deadlineDays: '', - deadlineDate: '' + deadlineDate: '', + + + } } @@ -325,17 +351,26 @@ deadlineOptions: ['1', '3', '5', '7'], currentEditingItem: null, checkList: Array.from({ length: 40 }, (_, i) => createCheckItem(i + 1)), - checkData, + checkData, // 鎻愪氦缁欏悗绔紝鍥剧墖浣跨敤vant缁撴瀯锛宐ase64锛屽悗绔鐞嗭紝涓嶈蛋鐖卞北涓滀腑鍙般€傦紙鏁版嵁閲忓ぇ锛侊級 checkPageIndex: 0, currentItem: null, + + noCount, + totalItems, + notNullCount, }, - watch:{ + watch: { checkData: { handler(newVal) { const snapshot = JSON.parse(JSON.stringify(newVal)); // const snapshot = JSON.stringify(newVal); console.log('鍏ㄩ噺鍙樺寲:', snapshot); + this.noCount = countSelectedNo(newVal); // selected=no 鐨勪釜鏁� + this.totalItems = getTotalCheckListItems(newVal); // checkList 瀛愬厓绱犳€绘暟 + this.notNullCount = countSelectedNotNull(newVal); // selected 涓嶄负 null 鐨勪釜鏁� + + }, deep: true }, -- 2.22.0