| | |
| | | <template> |
| | | <li class="todo-item"> |
| | | <checkbox-group @change="onRadioChange" v-model="checkedIds"> |
| | | <label class="radio-option" v-for="(item, index) in todoItem" :key="item.HID" v-show="item.是否启用"> |
| | | <checkbox @change="onCheckboxChange(item.HID)"/> |
| | | <checkbox-group v-for="(item, index) in todoItem" :key="item.HID" @change="onCheckboxChange(item.是否选中,item.HID) "> |
| | | <label class="radio-option" v-show="item.是否启用"> |
| | | <checkbox :checked="item.是否选中" /> |
| | | <text class="item-text" >{{item.代码项目}}</text> |
| | | <button class="delete-btn" @click="deleteItem(item)">删除</button> |
| | | </label> |
| | |
| | | uni.$emit("deleteItem", item.HID); |
| | | console.log("删除项ID:", item.HID); |
| | | }, |
| | | onCheckboxChange(checked, HID) |
| | | { |
| | | console.log("当前选中项ID:",checked, HID); |
| | | uni.$emit("changeItem",checked, HID); |
| | | } |
| | | }, |
| | | |
| | | } |
| | |
| | | button.delete-btn::after { |
| | | border: none; |
| | | } |
| | | </style>我希望通过watch获取到所有勾选的HID |
| | | </style> |
| | |
| | | <template> |
| | | <view class="todo-footer"> |
| | | <radio-group> |
| | | |
| | | <radio /> |
| | | <!-- <radio /> --> |
| | | <span><span>已完成{{ completedCount }}</span>/总共{{ total }}</span> |
| | | <button @click="clearAllobj">清除已完成</button> |
| | | |
| | |
| | | |
| | | <script> |
| | | export default { |
| | | props: { |
| | | todoList: { |
| | | type: Array, |
| | | required: true |
| | | } |
| | | }, |
| | | data() { |
| | | return { |
| | | completedCount: 0, |
| | | total: 0, |
| | | |
| | | } |
| | | }, |
| | | computed: { |
| | | // completedCount() { |
| | | // return this.todoList.filter(item => item.completed).length; |
| | | // }, |
| | | // total() { |
| | | // return this.todoList.length; |
| | | // } |
| | | completedCount() { |
| | | return this.todoList.filter(item => item.是否选中).length; |
| | | }, |
| | | total() { |
| | | return this.todoList.filter(item => item.是否启用).length; |
| | | } |
| | | }, |
| | | methods: { |
| | | |
| | | clearAllobj() |
| | | { |
| | | if(confirm("确定要清除已完成的事项吗?")) |
| | | { |
| | | this.$emit("clearAll"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | </script> |
| | |
| | | <Header @missionAdded="onMissionAdded"></Header> |
| | | |
| | | <HList :todoList="contentList"></HList> |
| | | <Hfooter></Hfooter> |
| | | <Hfooter :todoList="contentList" @clearAll="clearAll"></Hfooter> |
| | | </view> |
| | | </template> |
| | | |
| | |
| | | 是否启用: element.是否启用, |
| | | 是否可编辑: element.是否可编辑, |
| | | 是否禁用: element.是否禁用, |
| | | 是否选中:false |
| | | }; |
| | | }); |
| | | this.empty = this.todoList.length === 0; |
| | |
| | | }); |
| | | |
| | | }, |
| | | deleteMission(deleteID) { |
| | | let res= CommonUtils.doRequest2Sync({ |
| | | deleteMission(deleteID) { |
| | | return CommonUtils.doRequest2Sync({ |
| | | url: '/ZWDBController/deleteTODOS', |
| | | data: { |
| | | user: localStorage.getItem('HUserName'), |
| | |
| | | }); |
| | | console.log("删除项ID:", deleteID); |
| | | }, |
| | | itemChanged(checkedID) |
| | | itemChanged(checked, HID) |
| | | { |
| | | |
| | | console.log("状态变化项ID:", checkedID); |
| | | } |
| | | |
| | | console.log("状态变化项ID:", checked, HID); |
| | | const checktodo=this.contentList.find(item => item.HID === HID); |
| | | checktodo.是否选中=!checked; |
| | | console.log("最后ID:", checktodo.是否选中, HID); |
| | | }, |
| | | async clearAll() { |
| | | const completedItems = this.contentList.filter(item => item.是否选中); |
| | | for (let item of completedItems) { |
| | | try { |
| | | await this.deleteMission(item.HID); |
| | | await this.sleep(300); |
| | | } catch (e) { |
| | | console.error('删除失败', e); |
| | | } |
| | | } |
| | | console.log('所有已完成项已删除'); |
| | | }, |
| | | sleep(ms) { |
| | | return new Promise(resolve => setTimeout(resolve, ms)); |
| | | } |
| | | }, |
| | | mounted() { |
| | | uni.$on("deleteItem", this.deleteMission); |
| | | uni.$on("changeItem", this.itemChanged); |
| | | uni.$on("changeItem", (checked, HID) => { |
| | | this.itemChanged(checked, HID); |
| | | }); |
| | | }, |
| | | beforeDestroy() { |
| | | uni.$off("deleteItem", this.deleteMission); |
| | | uni.$off("changeItem", this.itemChanged); |
| | | uni.$off("changeItem", (checked, HID) => { |
| | | this.itemChanged(checked, HID); |
| | | }); |
| | | }, |
| | | } |
| | | </script> |