Browse Source

保存勾选状态的同时勾选、取消勾选交互修改

admin_version1.0_2025_06_26
zq 2 weeks ago
parent
commit
f2411a59bb
  1. 474
      src/views/AddNewTreatment.vue

474
src/views/AddNewTreatment.vue

@ -30,15 +30,18 @@
<el-checkbox @change="handleSelectAllChange1" v-model="selectAll" <el-checkbox @change="handleSelectAllChange1" v-model="selectAll"
:indeterminate="isIndeterminate">全选</el-checkbox> :indeterminate="isIndeterminate">全选</el-checkbox>
</div> </div>
<span class="totalCount">{{ projectList.length }}已选{{ selectedCount }}</span> <span class="totalCount">{{ displayedProjectCount }}已选{{ selectedCount }}</span>
</div> </div>
<div class="flex-between mb32 mt32"> <div class="flex-between mb32 mt32">
<div class="tabProject flex"> <div class="tabProject flex">
<div :class="['tab-item ', projectSearchId == item.id ? 'active' : '']" <div :class="['tab-item point', projectSearchId == 'all' ? 'active' : '']"
v-for="item in Object.values(projectTagData)" :key="item.name">{{ item.name }}</div> @click="selectTag('all')">全部分类</div>
<div :class="['tab-item point', projectSearchId == item.id ? 'active' : '']"
@click="selectTag(item.id)" v-for="item in Object.values(projectTagData)"
:key="item.name">{{ item.name }}</div>
</div> </div>
<div class="right flex"> <div class="right flex" v-show="false">
<GuipFormItem label="搜索项目"> <GuipFormItem label="搜索项目">
<GuipInput slot="formDom" ref="GuipInput" width="280px" v-model="projectSearchName" <GuipInput slot="formDom" ref="GuipInput" width="280px" v-model="projectSearchName"
placeholder="请输入" @blur="inputBlur"> placeholder="请输入" @blur="inputBlur">
@ -48,34 +51,24 @@
</div> </div>
</div> </div>
<GuipTable :tableData="sortedProjectList" style="width: 100%" ref="multipleTable" max-height="600px" <GuipTable :tableData="sortedProjectList" style="width: 100%" ref="multipleTable" max-height="600px"
@selection-change="handleSelectionChange" :loading="loading"> @selection-change="handleSelectionChange" :loading="loading" @select="handleSelect">
<el-table-column type="selection" label="选择" width="150"></el-table-column> <el-table-column type="selection" label="选择" width="150"></el-table-column>
<el-table-column prop="name" label="项目名称" min-width="150"></el-table-column> <el-table-column prop="name" label="项目名称" min-width="150"></el-table-column>
<el-table-column label="次数" min-width="150px" prop="num"> <el-table-column label="次数" min-width="150px" prop="num">
<template slot-scope="scope"> <template slot-scope="scope">
<GuipInput width="90%" v-if="package_id && scope.row.num" v-model="scope.row.num" <GuipInput width="90%" v-if="package_id && scope.row.num" v-model="scope.row.num"
min="1" @change="changeNums(scope.row)" />
<GuipInput width="90%" v-else v-model="scope.row.unit_num" min="1"
@change="changeNums(scope.row)" /> @change="changeNums(scope.row)" />
<GuipInput width="90%" v-else v-model="scope.row.unit_num"
@change="changeNums(scope.row)" />
</template>
</el-table-column>
<el-table-column prop="price" label="项目价格" min-width="150">
<template slot-scope="scope">
<GuipInput width="90%" v-model="scope.row.price" @change="changePrice(scope.row)" />
</template> </template>
</el-table-column> </el-table-column>
<el-table-column prop="price" label="项目价格" min-width="150"></el-table-column>
<el-table-column prop="classify_id" label="分类" min-width="150"> <el-table-column prop="classify_id" label="分类" min-width="150">
<template slot-scope="scope"> <template slot-scope="scope">
<GuipSelect width="90%" v-model="scope.row.classify_id" {{ projectTagData[scope.row.classify_id].name }}
@change="changeClassify(scope.row)" prop="classify_id" :options="projectTagData"
valueKey="id" labelKey="name" />
</template> </template>
</el-table-column> </el-table-column>
</GuipTable> </GuipTable>
<!-- <el-pagination background @size-change='handleSizeChange' @current-change='handleCurrentChange'
:current-page="currentPage" :page-size=pageSize layout="prev, pager, next,jumper"
:total="treatMentList.length">
</el-pagination> -->
</el-form> </el-form>
</div> </div>
</div> </div>
@ -98,8 +91,9 @@
</div> </div>
<div class="flex content"> <div class="flex content">
<span>套餐项目</span> <span>套餐项目</span>
<div class="column"> <div class="column gap10 project_list">
<span v-for="item in selectedRows" :key="item.id">{{ item.name }} {{ item.nums }}</span> <span v-for="item in sortedProjectRows" :key="item.id">{{ item.name }} {{ item.num || item.unit_num
}}</span>
</div> </div>
</div> </div>
</GuipDialog> </GuipDialog>
@ -113,7 +107,7 @@ import GuipTable from '@/components/GuipTable.vue';
import GuipDialog from '@/components/GuipDialog.vue'; import GuipDialog from '@/components/GuipDialog.vue';
import GuipInput from '@/components/GuipInput.vue'; import GuipInput from '@/components/GuipInput.vue';
import GuipButton from '@/components/GuipButton.vue'; import GuipButton from '@/components/GuipButton.vue';
import GuipSelect from '@/components/GuipSelect.vue'; // import GuipSelect from '@/components/GuipSelect.vue';
export default { export default {
// //
name: '', name: '',
@ -123,7 +117,7 @@ export default {
GuipInput, GuipInput,
GuipDialog, GuipDialog,
GuipButton, GuipButton,
GuipSelect, // GuipSelect,
GuipTable GuipTable
}, },
@ -136,10 +130,11 @@ export default {
pageSize: 10, pageSize: 10,
isIndeterminate: false, isIndeterminate: false,
projectSearchName: '', projectSearchName: '',
projectSearchId: '0', projectSearchId: 'all',
loading: false, loading: false,
treatMentList: [],// treatMentList: [],//
projectList: [],// projectList: [],//
projectTagData: [],
// { // {
// 27:{ // 27:{
// classify_name:"", // classify_name:"",
@ -155,14 +150,15 @@ export default {
// } // }
// }, // },
selectedRows: [], selectedRows: [],
sortedProjectRows: [],
siteForm: { siteForm: {
create_time: "2025-05-29 17:08:29", create_time: "",
depart_id: "1", depart_id: "",
doctor_id: "1", doctor_id: "",
id: "1", id: "",
name: "调理套餐", name: "",
price: "1500.00", price: "",
status: "1" status: ""
}, },
siteFormrules: { siteFormrules: {
name: [ name: [
@ -172,27 +168,51 @@ export default {
{ required: true, message: '请输入套餐价格', trigger: 'blur' } { required: true, message: '请输入套餐价格', trigger: 'blur' }
], ],
}, },
projectTagData: [],
package_id: '', package_id: '',
doctor_id: '', doctor_id: '',
depart_id: '', depart_id: '',
} }
}, },
computed: { computed: {
...mapState(['pageTitle']), ...mapState(['pageTitle']),
sortedProjectList() { sortedProjectList() {
return [...this.projectList].sort((a, b) => { // sort
// sort let sortedList = [...this.projectList].sort((a, b) => {
if (a.sort && !b.sort) return -1; if (a.sort && !b.sort) return -1;
if (!a.sort && b.sort) return 1; if (!a.sort && b.sort) return 1;
// sortsort
if (a.sort && b.sort) return a.sort - b.sort; if (a.sort && b.sort) return a.sort - b.sort;
// sort
return 0; return 0;
}); });
// projectSearchId
if (this.projectSearchId === 'all') {
return sortedList;
} else {
return sortedList.filter(item => item.classify_id == this.projectSearchId);
}
},
//
displayedProjectCount() {
return this.sortedProjectList.length;
},
},
watch: {
projectSearchId() {
this.$nextTick(() => {
this.setSelectedRows();
});
},
projectList: {
deep: true,
handler() {
this.$nextTick(() => {
this.setSelectedRows();
});
}
} }
}, },
mounted() { mounted() {
const { package_id, doctor_id, depart_id } = this.$route.query; // doctorId const { package_id, doctor_id, depart_id } = this.$route.query; // doctorId
this.package_id = package_id; this.package_id = package_id;
@ -207,8 +227,45 @@ export default {
this.fetchProjectData(); this.fetchProjectData();
}, },
methods: { methods: {
//
// initSelectedItems() {
if (!this.package_id) {
this.selectedRows = [];
this.sortedProjectRows = []
return;
}
// treatMentList
this.treatMentList.forEach(treatment => {
const foundItem = this.projectList.find(item => item.id == treatment.project_id);
if (foundItem && !this.selectedRows.some(r => r.id === foundItem.id)) {
foundItem.num = treatment.num;
foundItem.sort = treatment.sort;
this.selectedRows.push(foundItem);
}
});
this.sortedProjectRows = [...this.selectedRows]
this.setSelectedRows();
},
// //
setSelectedRows() {
this.$nextTick(() => {
if (!this.$refs.multipleTable?.$refs.guiptable) return;
//
this.$refs.multipleTable.$refs.guiptable.clearSelection();
this.selectedRows = [];//
// console.log(this.selectedRows, this.sortedProjectRows, 'sortedProjectList==');
//
this.sortedProjectList.forEach(row => {
if (this.sortedProjectRows.some(selected => selected.id === row.id)) {
this.$refs.multipleTable.$refs.guiptable.toggleRowSelection(row, true);
}
});
});
},
getInitData() { getInitData() {
this.$http('POST', '/api/admin/get_project_package_info', { this.$http('POST', '/api/admin/get_project_package_info', {
depart_id: this.depart_id, depart_id: this.depart_id,
@ -226,134 +283,151 @@ export default {
console.error(error, 'error') console.error(error, 'error')
}) })
}, },
// mounted fetchProjectData
fetchProjectData() { fetchProjectData() {
this.$http('POST', '/api/admin/get_project_list', { this.$http('POST', '/api/admin/get_project_list', {
depart_id: this.depart_id, depart_id: this.depart_id,
doctor_id: this.doctor_id doctor_id: this.doctor_id
}).then(response => { }).then(response => {
if (response.code == 0) { if (response.code == 0) {
this.projectTagData = response.data.classify;// this.projectTagData = response.data.classify;
this.projectList = Object.values(response.data.list).map(item => { this.projectList = Object.values(response.data.list).map(item => ({
return { ...item,
...item, checked: false
checked: false }));
}
});// //
if (this.package_id && this.selectedRows.length === 0) {
if (this.package_id) {// this.initSelectedItems();
this.treatMentList.forEach(item => {
this.projectList.forEach(item1 => {
if (item.project_id == item1.id) {
item1.checked = true;
item1.num = item.num;
item1.sort = item.sort;
//
this.$nextTick(() => {
this.$refs.multipleTable.$refs.guiptable.toggleRowSelection(item1, true);
this.selectedRows.push(item1)
this.updateSelectionState();
});
}
})
})
// this.$nextTick(() => {
// if (this.projectList.length >= 2) {
// const defaultSelected = this.projectList.filter(item => item.checked === true);
// defaultSelected.forEach(row => {
// this.$refs.multipleTable.$refs.guiptable.toggleRowSelection(row, true);
// });
// this.selectedRows = defaultSelected;
// this.updateSelectionState();
// }
// });
} }
} }
}).catch(error => { });
console.error(error, 'error')
})
},
changeChecked() {
}, },
inputBlur(val) { inputBlur(val) {
// //
this.$http('POST', '/supernew/ajax_get_type_batch_list', { // this.$http('POST', '/supernew/ajax_get_type_batch_list', {
projectSearchId: this.projectSearchId, // projectSearchId: this.projectSearchId,
search: this.projectSearchName // search: this.projectSearchName
}).then(response => { // }).then(response => {
if (response.code == 0) { // if (response.code == 0) {
this.dialogVisible = false; // this.dialogVisible = false;
} // }
}).catch(error => { // }).catch(error => {
console.error(error, 'error') // console.error(error, 'error')
}) // })
console.log(val, '----搜索'); console.log(val, '----搜索');
}, },
updateSelectionState() { updateSelectionState() {
const allSelected = this.selectedRows.length === this.projectList.length; const currentViewSelected = this.sortedProjectList.filter(row =>
const noneSelected = this.selectedRows.length === 0; this.selectedRows.some(selected => selected.id === row.id)
);
const allSelected = currentViewSelected.length === this.sortedProjectList.length;
const noneSelected = currentViewSelected.length === 0;
this.selectAll = allSelected; this.selectAll = allSelected;
this.isIndeterminate = !noneSelected && !allSelected; this.isIndeterminate = !noneSelected && !allSelected;
this.selectedCount = this.selectedRows.length; this.selectedCount = this.sortedProjectRows.length;
}, },
handleSelect(selection, row) {
// console.log(':', row);
// console.log(':', selection);
if (this.sortedProjectRows.includes(row)) {
// console.log('',this.sortedProjectRows);
let index = this.sortedProjectRows.findIndex((item) => item.id === row.id);
if (index > -1) {
this.sortedProjectRows.splice(index, 1)
}
} else {
this.sortedProjectRows.push(row)
}
},
handleSelectAll(selection) {
console.log('全选/取消全选:', selection);
},
// //
handleSelectionChange(rows) { handleSelectionChange(rows) {
this.selectedRows = rows; // console.log(rows, '=======---handleSelectionChange');
// ID
const currentViewIds = this.sortedProjectList.map(r => r.id);
//
const preservedSelections = this.selectedRows.filter(
row => !currentViewIds.includes(row.id)
);
//
// console.log(preservedSelections,currentViewIds,rows,'=currentViewIds===');
this.selectedRows = [...preservedSelections, ...rows];
// console.log(this.selectedRows, 'selectedRows===');
// let arr = [...new Set([...this.selectedRows, ...this.sortedProjectRows])]
// console.log(arr,'arr,22');
// this.selectedRows.forEach(row => {
// if (!this.sortedProjectRows.some(selected => selected.id === row.id)) {
// this.$refs.multipleTable.$refs.guiptable.toggleRowSelection(row, true);
// }
// });
// if(this.)
this.updateSelectionState(); this.updateSelectionState();
}, },
handleSelectAllChange1(val) { handleSelectAllChange1(val) {
const currentViewRows = this.sortedProjectList;
if (val) { if (val) {
// //
const unselectedRows = this.projectList.filter( currentViewRows.forEach(row => {
row => !this.selectedRows1.includes(row) // selectedRows
); if (!this.selectedRows.some(r => r.id === row.id)) {
unselectedRows.forEach(row => { this.selectedRows.push(row);
this.$refs.multipleTable1.$refs.guiptable.toggleRowSelection(row, true); }
// sortedProjectRows
if (!this.sortedProjectRows.some(r => r.id === row.id)) {
this.sortedProjectRows.push(row);
}
}); });
} else { } else {
// //
this.selectedRows.forEach(row => { currentViewRows.forEach(row => {
this.$refs.multipleTable1.$refs.guiptable.toggleRowSelection(row, false); // selectedRows
this.selectedRows = this.selectedRows.filter(r => r.id !== row.id);
// sortedProjectRows
this.sortedProjectRows = this.sortedProjectRows.filter(r => r.id !== row.id);
}); });
} }
// console.log(':', {
// selectedRows: this.selectedRows,
// sortedProjectRows: this.sortedProjectRows
// });
//
this.$nextTick(() => {
this.setSelectedRows();
this.updateSelectionState();
});
},
//
selectTag(id) {
this.projectSearchId = id === 'all' ? 'all' : id;
// this.setSelectedRows();
this.updateSelectionState();
}, },
// / // /
// //
// //
// //
changeNums(row) { changeNums(row) {
if (row.sort) { this.changeSelectStatus(row)
this.editorProjectInfo({ num: row.num, project_id: row.id })
} else {
this.changeSelectStatus(row)
}
},
//
changeClassify(row) {
if (row.sort) {
this.editorProjectInfo({ classify_id: row.classify_id, project_id: row.id })
} else {
this.changeSelectStatus(row)
}
},
//
changePrice(row) {
if (row.sort) {
this.editorProjectInfo({ price: row.price, project_id: row.id })
} else {
this.changeSelectStatus(row)
}
}, },
changeSelectStatus(row) { changeSelectStatus(row) {
this.$refs.multipleTable.$refs.guiptable.toggleRowSelection(row, true); //
if (!this.selectedRows.includes(row)) {
this.$refs.multipleTable.$refs.guiptable.toggleRowSelection(row, true);
}
row.checked = true row.checked = true
// selectedRows // selectedRows
if (!this.selectedRows.includes(row)) { if (!this.selectedRows.includes(row)) {
@ -364,7 +438,8 @@ export default {
}, },
// //
editorProjectInfo(props) { editorProjectInfo(props) {
// console.log(props, '====---');
if (this.package_id) props.package_id = this.package_id
this.$http('POST', '/api/admin/edit_project', { this.$http('POST', '/api/admin/edit_project', {
...props, ...props,
depart_id: this.depart_id, depart_id: this.depart_id,
@ -372,7 +447,12 @@ export default {
}).then(response => { }).then(response => {
if (response.code == 0) { if (response.code == 0) {
this.$Message.success('修改成功') this.$Message.success('修改成功')
this.getInitData() //
// if(this.package_id){
// this.getInitData()
// }else{
// this.fetchProjectData()
// }
} }
}).catch(error => { }).catch(error => {
console.error(error, 'error') console.error(error, 'error')
@ -385,51 +465,38 @@ export default {
this.dialogVisible = false; this.dialogVisible = false;
}, },
handleConfirm() { handleConfirm() {
let project_infos = [];
this.selectedRows.forEach(item => {
project_infos.push({ project_id: item.id, num: item.num || item.unit_num })
})
let props = {
name: this.siteForm.name,
price: this.siteForm.price,
project_infos: JSON.stringify(project_infos)
}
if (this.package_id) props.package_id = this.package_id
// //
this.$http('POST', '/supernew/ajax_get_type_batch_list', { this.$http('POST', '/api/admin/set_project_package', {
depart_id: this.depart_id,
doctor_id: this.doctor_id,
...props
}).then(response => { }).then(response => {
if (response.code == 0) { if (response.code == 0) {
this.$Message.success('保存成功')
this.dialogVisible = false; this.dialogVisible = false;
this.$router.push({
name: '医院信息',
query: { doctor_id: this.doctor_id, depart_id: this.depart_id }
})
} }
}).catch(error => { }).catch(error => {
console.error(error, 'error') console.error(error, 'error')
}) })
}, },
handleClear(value) { handleClear(value) {
// this.handleInput('') this.projectSearchName = ''
console.log(value, 'value===qinghcu'); console.log(value, 'value===qinghcu');
}, },
handleSelectAllChange(val) {
console.log(this.$refs.multipleTable, 'multipleTable-');
if (val) {
//
const unselectedRows = this.projectList.filter(
row => !this.selectedRows.includes(row)
);
unselectedRows.forEach(row => {
this.$refs.multipleTable.$refs.guiptable.toggleRowSelection(row, true);
});
} else {
//
this.selectedRows.forEach(row => {
this.$refs.multipleTable.$refs.guiptable.toggleRowSelection(row, false);
});
}
},
// //
// handleSelectionChange(rows) {
// this.selectedRows = rows;
// //
// const allSelected = rows.length === this.treatMentList.length;
// const noneSelected = rows.length === 0;
// this.selectAll = allSelected;
// this.isIndeterminate = !noneSelected && !allSelected;
// },
handleSizeChange(val) { handleSizeChange(val) {
this.pageSize = val this.pageSize = val
this.getData() this.getData()
@ -438,69 +505,27 @@ export default {
this.currentPage = val this.currentPage = val
this.getData() this.getData()
}, },
changeSelect(value) {
console.log(value, '--');
},
btnClick() {
},
handleRemove(file, fileList) {
console.log(file, fileList);
},
handlePreview(file) {
console.log(file);
},
//
handleAvatarSuccess(res, file) {
this.imageUrl1 = URL.createObjectURL(file.raw);
},
beforeAvatarUpload(file) {
const isJPG = file.type === 'image/jpeg' || file.type === 'image/png';
const isLt2M = file.size / 1024 / 1024 < 2;
if (!isJPG) {
this.$message.error('上传头像图片只能是 JPG 或 PNG 格式!');
}
if (!isLt2M) {
this.$message.error('上传头像图片大小不能超过 2MB!');
}
return isJPG && isLt2M;
},
changeNormalWeixin() {
},
changeSelectWeixin(item, flag) {
if (flag) {
this.select_placeholder_weixin = this.options_weixin_null.desc;
return
}
this.selectedItem = { ...item };
console.log(this.selectedItem, 'this.selectedItem====');
},
//
domain_radioChange(type) {
console.log(type, '--');
},
onSwitchChange(data) {
console.log(data, '---');
},
submitForm(form) {
this.$refs[form].validate((valid) => {
console.log(this[form], '======formxinxi');
if (valid) {
alert('提交成功!');
} else {
return false;
}
});
},
cancelClick() { cancelClick() {
this.$router.push({ this.$router.push({
name: '医院信息', name: '医院信息',
query: { doctor_id: this.doctor_id,depart_id:this.depart_id } query: { doctor_id: this.doctor_id, depart_id: this.depart_id }
}) })
}, },
confirmClick() { confirmClick() {
this.dialogVisible = true; console.log(this.sortedProjectList, 'sortedProjectList==');
console.log(this.sortedProjectRows, 'sortedProjectRows==');
// //
this.$refs['siteForm1'].validate((valid) => {
if (valid) {
if (this.selectedRows.length == 0) {
this.$Message('请选择套餐项目')
return
}
this.dialogVisible = true;
} else {
return false;
}
});
} }
} }
@ -534,6 +559,11 @@ export default {
} }
} }
.project_list {
max-height: 200px;
overflow-y: auto;
}
.totalCount { .totalCount {
font-size: 12px; font-size: 12px;
font-weight: normal; font-weight: normal;

Loading…
Cancel
Save