项目管理表单更新

This commit is contained in:
Yuanjianghong 2021-11-28 23:51:14 +08:00
parent 3c4dc139ac
commit 72e59de845
4 changed files with 292 additions and 280 deletions

View File

@ -8,8 +8,8 @@ const courseApi = {
// updateStatus: 'sys/menu/updateStatus', // updateStatus: 'sys/menu/updateStatus',
list: '/courseManagement/course/listPage', list: '/courseManagement/course/listPage',
coursewareList:'/courseManagement/course/courseware/details', coursewareList:'/courseManagement/course/courseware/details',
questionList:'/courseManagement/course/questionList' questionList:'/courseManagement/course/questionList',
listByClass:'/courseManagement/course/list',
} }
export function courseAdd (params) { export function courseAdd (params) {
@ -19,13 +19,13 @@ export function courseAdd (params) {
data: params data: params
}) })
} }
// export function menuGet (params) { export function listByClass (params) {
// return request({ return request({
// url: menuApi.get, url: courseApi.listByClass,
// method: 'post', method: 'get',
// data: params params: params
// }) })
// } }
// export function menuUpdate (params) { // export function menuUpdate (params) {
// return request({ // return request({
// url: menuApi.update, // url: menuApi.update,

View File

@ -8,7 +8,7 @@
</template> </template>
<a-space direction="vertical" style="width: 100%"> <a-space direction="vertical" style="width: 100%">
<a-space direction="horizontal"> <a-space direction="horizontal">
<span>总课时{{ totalHours }}, 总学时要求{{ totalLearnHours }}, 总题目数量{{ totalTopicNum }} </span> <span>总课时{{ totalHours }}H , 总学时要求{{ totalLearnHours }}H , 总题目数量{{ totalTopicNum }} </span>
课程名: 课程名:
<a-input v-model="queryParam.courseName" style="width: 100%" /> <a-input v-model="queryParam.courseName" style="width: 100%" />
<a-button type="primary" icon="search" @click="$refs.table.refresh(true)">查询</a-button> <a-button type="primary" icon="search" @click="$refs.table.refresh(true)">查询</a-button>
@ -46,8 +46,8 @@
</template> </template>
</span> </span>
</s-table> </s-table>
<project-course-select ref="CourseSelect"></project-course-select>
</a-space> </a-space>
<project-course-select ref="CourseSelect" @selectKeyDataSubmit="selectKeyDataChange"></project-course-select>
</a-card> </a-card>
</template> </template>
@ -86,8 +86,8 @@ export default {
{ title: '序号', key: 'id', dataIndex: 'id', width: 60, scopedSlots: { customRender: 'serial' } }, { title: '序号', key: 'id', dataIndex: 'id', width: 60, scopedSlots: { customRender: 'serial' } },
{ title: '课程编号', dataIndex: 'courseNo', key: 'courseNo' }, { title: '课程编号', dataIndex: 'courseNo', key: 'courseNo' },
{ title: '课程名称', dataIndex: 'courseName', key: 'courseName' }, { title: '课程名称', dataIndex: 'courseName', key: 'courseName' },
{ title: '课时', dataIndex: 'courseHours', key: 'courseHours', customRender: (text) => text + '' }, { title: '课时', dataIndex: 'courseHours', key: 'courseHours', customRender: (text) => text + 'H' },
{ title: '学时要求', dataIndex: 'learnHours', key: 'learnHours', customRender: (text) => text + '' }, { title: '学时要求', dataIndex: 'learnHours', key: 'learnHours', customRender: (text) => text + 'H' },
{ title: '题量', dataIndex: 'topicNumber', key: 'topicNumber' }, { title: '题量', dataIndex: 'topicNumber', key: 'topicNumber' },
// { title: '', dataIndex: 'projectName', key: 'projectName' }, // { title: '', dataIndex: 'projectName', key: 'projectName' },
{ title: '操作', width: 200, align: 'center', scopedSlots: { customRender: 'action' } }, { title: '操作', width: 200, align: 'center', scopedSlots: { customRender: 'action' } },
@ -96,11 +96,13 @@ export default {
if (this.$route.query.projectId) { if (this.$route.query.projectId) {
/** 编辑进来的有项目id */ /** 编辑进来的有项目id */
return getCourseList(this.$route.query.projectId).then((res) => { return getCourseList(this.$route.query.projectId).then((res) => {
this.calc(res.data)
return res.data return res.data
}) })
} else { } else {
/** 新建的没有项目id传当前的所选的课程id */ /** 新建的没有项目id传当前的所选的课程id */
return getCourseListByCourseIds(Object.assign(parameter, this.queryParam)).then((res) => { return getCourseListByCourseIds(Object.assign(parameter, this.queryParam)).then((res) => {
this.calc(res.data)
return res.data return res.data
}) })
} }
@ -113,6 +115,17 @@ export default {
watch: {}, watch: {},
// //
methods: { methods: {
//
calc(data){
this.totalHours = 0
this.totalLearnHours = 0
this.totalTopicNum = 0
data.forEach((item)=>{
this.totalHours = this.totalHours + parseInt(item.courseHours)
this.totalLearnHours = this.totalLearnHours + parseInt(item.learnHours)
this.totalTopicNum = this.totalTopicNum + parseInt(item.topicNumber)
})
},
// //
toNext() { toNext() {
this.form.lessonIds = [] this.form.lessonIds = []
@ -138,33 +151,21 @@ export default {
}, },
//ids //ids
initIds() { initIds() {
let str = this.projectForm.lessonIds.join(',') console.log('this.projectForm.lessonIds',this.projectForm.lessonIds)
let str = '';
if(this.projectForm.lessonIds) str = this.projectForm.lessonIds.join(',')
// let str = this.projectForm.lessonIds.join(',') || []
console.log('initIds', str) console.log('initIds', str)
if (str) { if (str) {
this.queryParam.ids = str this.queryParam.ids = str
} }
}, },
/**查询了列表数据 */ //list
getProjectCourseList() { selectKeyDataChange(childValue){
// if (this.$route.query.projectId) { console.log('list page - selectKeyDataSubmit',childValue)
// /** id */ this.queryParam.ids = childValue
// getCourseList(this.$route.query.projectId).then((res) => { this.$refs.table.refresh(true)
// if (res.code == 200) { }
// // this.data1 = res.data
// return res
// }
// })
// } else {
// /** idid */
// getCourseListByCourseIds(this.queryParam.ids.join(',')).then((res)=>{
// if (res.code == 200) {
// // this.data1 = res.data
// // console.log(this.data1)
// return res
// }
// })
// }
},
}, },
// - 访this // - 访this

View File

@ -3,161 +3,188 @@
id="modal" id="modal"
:title="modalTitle" :title="modalTitle"
:width="1500" :width="1500"
:height="750" height="auto"
:visible="visible" :visible="visible"
:confirmLoading="confirmLoading"
:destroyOnClose="true"
@ok="handleSubmit" @ok="handleSubmit"
@cancel="handleCancel" @cancel="handleCancel"
> >
<a-card :bordered="false" title="项目课程选择">
<a-row type="flex" justify="center" align="top"> <a-row type="flex" justify="center" align="top">
<a-col :span="4"> <a-col :span="4" id="tree">
<a-menu v-model="current" mode="horizontal" @click="handleMenuClick"> <a-page-header title="单位列表" sub-title="" />
<a-menu-item key="sys">系统课程</a-menu-item>
<a-menu-item key="self">自制课程</a-menu-item>
</a-menu>
<a-tree <a-tree
:replace-fields="replaceFields" :treeData="treeData"
:expanded-keys="expandedKeys"
:auto-expand-parent="autoExpandParent"
:tree-data="treeData"
@expand="onExpand"
@select="onSelect" @select="onSelect"
:defaultExpandAll="true"
:defaultExpandedKeys="defaultExpandedKeys"
:replaceFields="replaceFields"
> >
<a-icon slot="switcherIcon" type="down" />
</a-tree> </a-tree>
</a-col> </a-col>
<a-col :span="20"> <a-col :span="20" id="content">
<div id="content"> <a-page-header title="课程选择" sub-title="" />
<a-transfer <a-col :span="18" id="table">
:data-source="courseList.courseData" <a-form layout="inline">
:titles="['待选课程', '已选课程']" <a-row>
:target-keys="courseList.targetKeys" <a-form-item label="课程名称">
:selected-keys="courseList.selectedKeys" <a-input v-model="queryParam.name" placeholder="请输入课程名称" />
:render="(item) => item.title" </a-form-item>
:disabled="courseList.disabled" <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
@change="handleChange" </a-row>
@selectChange="handleSelectChange" </a-form>
@scroll="handleScroll" <s-table
:list-style="{ ref="table"
width: '408px', :columns="columns"
height: '500px', :data="loadData"
}" :rowKey="(record) => record.id"
:rowSelection="{ selectedRowKeys: selectedRowKeys, selectedRows: selectedRows, onChange: onSelectChange }"
> >
<template <span slot="serial" slot-scope="text, record, index">
slot="children" {{ index + 1 }}
slot-scope="{ </span>
props: { direction, filteredItems, selectedKeys, disabled: listDisabled }, </s-table>
on: { itemSelectAll, itemSelect }, </a-col>
}" <a-col :span="6" id="select">
> <p>点击列表项取消选择或<a @click="removeAllSelece">清空所有</a></p>
<a-table <a-list size="small" :data-source="selectedRows" :rowKey="(item) => item.id">
:row-selection="getRowSelection({ disabled: listDisabled, selectedKeys, itemSelectAll, itemSelect })" <a-list-item slot="renderItem" slot-scope="item" @click="changeList({ item })">
:columns="direction === 'left' ? courseList.leftColumns : courseList.rightColumns" {{ item.courseName + '' + item.courseCode + '' }}
:data-source="filteredItems" </a-list-item>
size="default" </a-list>
:style="{ pointerEvents: listDisabled ? 'none' : null }" </a-col>
:custom-row="
({ key, disabled: itemDisabled }) => ({
on: {
click: () => {
if (itemDisabled || listDisabled) return
itemSelect(key, !selectedKeys.includes(key))
},
},
})
"
/>
</template>
</a-transfer>
</div>
</a-col> </a-col>
</a-row> </a-row>
</a-card>
</a-modal> </a-modal>
</template> </template>
<script> <script>
// jsjsjson
// import from ''
import { coursewareClassList } from '@/api/course/courseware' import { coursewareClassList } from '@/api/course/courseware'
import { getCourseList } from '@/api/course/course' import { listByClass } from '@/api/course/course'
import difference from 'lodash/difference' import { STable } from '@/components'
//jsjsjson const rootParentId = 0
//import from ''
// const coData = [];
const leftTableColumns = [{dataIndex: 'courseCode', title: '课程编号', },{dataIndex: 'courseName', title: '课程名称', },]
const rightTableColumns = [ {dataIndex: 'courseCode',title: '课程编号',},{dataIndex: 'courseName',title: '课程名称',},]
export default { export default {
//import使 // import使
components: { components: {
coursewareClassList, STable,
difference,
getCourseList,
}, },
props: {}, props: {},
data() { data() {
// //
return { return {
replaceFields: { visible: false, //
children: 'children',
title: 'name',
key: 'id',
},
visible: false,
confirmLoading: false,
current: ['sys'],
modalTitle: '', modalTitle: '',
//
queryParam: { name: '', classType: 0 },
replaceFields: { children: 'children', title: 'name', key: 'id', value: 'id' },
expandedKeys: [], expandedKeys: [],
searchValue: '',
autoExpandParent: true, autoExpandParent: true,
defaultExpandedKeys: [],
selectedRowKeys: [],
selectedRows: [],
treeData: [], treeData: [],
courseList: { treeDataOne: [],
queryParam: {}, columns: [
courseData: [], { title: '序号', key: 'id', dataIndex: 'id', width: 60, scopedSlots: { customRender: 'serial' } },
targetKeys: [], { title: '课程编号', dataIndex: 'courseCode' },
selectedKeys: [], { title: '课程名称', dataIndex: 'courseName' },
disabled: false, ],
leftColumns: leftTableColumns, //
rightColumns: rightTableColumns, loadData: (parameter) => {
return listByClass(Object.assign(parameter, this.queryParam)).then((res) => {
return res
})
}, },
} }
}, },
// data // data
computed: {}, computed: {
//data hasSelected() {
return this.selectedRowKeys.length > 0
},
},
// data
watch: {}, watch: {},
// //
methods: { methods: {
// //
edit(record) { edit(record) {
console.log(record) console.log('课程选择打开了', record)
this.modalTitle = '选择课程' this.modalTitle = '选择课程'
this.visible = true this.visible = true
this.formLoading = false
}, },
handleCancel() { handleCancel() {
console.log('课程选择关闭') console.log('课程选择关闭')
this.visible = false this.visible = false
this.formLoading = false
}, },
handleSubmit() { handleSubmit() {
console.log('课程选择提交了') console.log('课程选择提交了',this.selectedRowKeys)
this.visible = false this.visible = false
this.formLoading = false if (this.selectedRowKeys) this.$emit('selectKeyDataSubmit',this.selectedRowKeys.join(','));
this.$parent.queryParam.ids = this.courseList.selectedKeys.join(",") else this.$emit('selectKeyDataSubmit','');
this.$parent.$refs.table.refresh(true);
}, },
/** 表格行选中后触发 */
onSelectChange(selectedRowKeys, selectedRows) {
console.log('selectedRowKeys changed: ', selectedRowKeys)
console.log('选择的表格数据 : ', selectedRows)
this.selectedRowKeys = this.uniqueKeys([...this.selectedRowKeys, ...selectedRowKeys])
this.selectedRows = this.unique([...this.selectedRows, ...selectedRows])
},
//
unique(arr) {
const res = new Map()
return arr.filter((arr) => !res.has(arr.id) && res.set(arr.id, 1))
},
//key
uniqueKeys(arr) {
const res = new Map()
return arr.filter((arr) => !res.has(arr) && res.set(arr, 1))
},
//
changeList(item) {
console.log('列表点击删除列表项 : ', item)
this.selectedRows = this.selectedRows.filter(function (i) {
return i.id != item.item.id
})
this.selectedRowKeys = this.selectedRowKeys.filter(function (i) {
return i != item.item.id
})
},
//
removeAllSelece() {
this.selectedRowKeys = []
this.selectedRows = []
},
//
onSelect(selectedKey, info) {
console.log('onSelect-------', selectedKey, info)
this.queryParam.classType = selectedKey.toString()
// this.orgId = selectedKey.toString()
this.$refs.table.refresh(true)
},
//使
onExpand(expandedKeys) { onExpand(expandedKeys) {
this.expandedKeys = expandedKeys this.expandedKeys = expandedKeys
this.autoExpandParent = false this.autoExpandParent = false
}, },
// //
handleMenuClick(e) { queryCourseList() {
console.log('key============', e.key) console.log('this.treeDataOne-------', this.treeDataOne)
this.getCourseTreeData(e.key) listByClass({ classType: this.treeDataOne[0] || 0 }).then((res) => {
console.log(this.treeData) this.courseData = res.data
})
}, },
// //
getCourseTreeData(key) { getCourseTreeData(key) {
@ -165,6 +192,8 @@ export default {
//list🌲 //list🌲
const list2tree1 = (list, parentId) => { const list2tree1 = (list, parentId) => {
return list.filter((item) => { return list.filter((item) => {
//
if (this.treeDataOne) this.treeDataOne.push(item.id)
if (item.parentId === parentId) { if (item.parentId === parentId) {
item.children = list2tree1(list, item.id) item.children = list2tree1(list, item.id)
return true return true
@ -172,78 +201,31 @@ export default {
return false return false
}) })
} }
this.treeData = list2tree1(res.data, -1) this.treeData = list2tree1(res.data, -1)
}) })
}, },
onSelect(selectedKeys, e) {},
handleChange(nextTargetKeys, direction, moveKeys) {
this.courseList.targetKeys = nextTargetKeys
console.log('targetKeys: ', nextTargetKeys)
console.log('direction: ', direction)
console.log('moveKeys: ', moveKeys)
},
handleSelectChange(sourceSelectedKeys, targetSelectedKeys) {
this.courseList.selectedKeys = [...sourceSelectedKeys, ...targetSelectedKeys]
console.log('sourceSelectedKeys: ', sourceSelectedKeys)
console.log('targetSelectedKeys: ', targetSelectedKeys)
},
handleScroll(direction, e) {
console.log('direction:', direction)
console.log('target:', e.target)
},
getRowSelection({ disabled, selectedKeys, itemSelectAll, itemSelect }) {
return {
getCheckboxProps: (item) => ({ props: { disabled: disabled || item.disabled } }),
onSelectAll(selected, selectedRows) {
const treeSelectedKeys = selectedRows.filter((item) => !item.disabled).map(({ key }) => key)
const diffKeys = selected
? difference(treeSelectedKeys, selectedKeys)
: difference(selectedKeys, treeSelectedKeys)
itemSelectAll(diffKeys, selected)
},
onSelect({ key }, selected) {
itemSelect(key, selected)
},
selectedRowKeys: selectedKeys,
}
},
//
queryCourseList() {
getCourseList(this.courseList.queryParam).then((res) => {
if (res.code == 200) {
res.data.map(function (currentValue, index, arr) {
this.courseList.courseData.push({
key: currentValue.id,
courseCode: currentValue.courseCode,
courseName: currentValue.courseName,
})
})
}
})
},
}, },
// - 访this
created() { created() {
this.handleMenuClick(); this.getCourseTreeData()
// this.queryCourseList(); },
}, // - 访this // - 访DOM
mounted() {}, // - 访DOM mounted() {},
beforeCreate() {}, // - // -
beforeMount() {}, // - beforeCreate() {},
beforeUpdate() {}, // - // -
updated() {}, // - beforeMount() {},
beforeDestroy() {}, // - // -
destroyed() {}, // - beforeUpdate() {},
activated() {}, //keep-alive // -
updated() {},
// -
beforeDestroy() {},
// -
destroyed() {},
// keep-alive
activated() {},
} }
</script> </script>
<style scoped> <style scoped>
#content {
background-color: rgb(202, 221, 188);
width: 100%;
height: 100%;
}
</style> </style>

View File

@ -14,19 +14,17 @@
<a-transfer <a-transfer
class="tree-transfer" class="tree-transfer"
:data-source="dataSource" :data-source="dataSource"
:titles="['全部单位列表', '已经选中单位']"
:target-keys="targetKeys" :target-keys="targetKeys"
:render="(item) => item.title" :render="(item) => item.title"
:operations="['选 中', '取 消']" :show-select-all="false"
:show-select-all="true"
:filter-option="filterOption"
@change="onChange" @change="onChange"
> >
<template slot="children" slot-scope="{ props: { direction, selectedKeys }, on: { itemSelect, itemSelectAll } }"> <template slot="children" slot-scope="{ props: { direction, selectedKeys }, on: { itemSelect } }">
<a-tree <a-tree
v-if="direction === 'left'" v-if="direction === 'left'"
blockNode blockNode
checkable checkable
checkStrictly
defaultExpandAll defaultExpandAll
:checkedKeys="[...selectedKeys, ...targetKeys]" :checkedKeys="[...selectedKeys, ...targetKeys]"
:treeData="treeData" :treeData="treeData"
@ -46,112 +44,143 @@
</a-card> </a-card>
</template> </template>
<script> <script>
// jsjsjson
// import from ''
import { orgList } from '@/api/org/org' import { orgList } from '@/api/org/org'
import { listToTree } from '@/utils/util' import { listToTree } from '@/utils/util'
// const treeData = [
function handleTreeData(data, targetKeys = []) { { key: '0-0', title: '0-0' },
data.forEach((item) => { {
item['disabled'] = targetKeys.includes(item.key) key: '0-1',
if (item.children) { title: '0-1',
handleTreeData(item.children, targetKeys) children: [
} { key: '0-1-0', title: '0-1-0' },
{ key: '0-1-1', title: '0-1-1' },
],
},
{ key: '0-2', title: '0-3' },
]
const transferDataSource = []
function flatten(list = []) {
list.forEach((item) => {
transferDataSource.push(item)
flatten(item.children)
}) })
return data
} }
flatten(JSON.parse(JSON.stringify(treeData)))
function isChecked(selectedKeys, eventKey) { function isChecked(selectedKeys, eventKey) {
return selectedKeys.indexOf(eventKey) !== -1; return selectedKeys.indexOf(eventKey) !== -1
} }
//
// function handleTreeData(data, targetKeys = []) {
// data.forEach((item) => {
// item['disabled'] = targetKeys.includes(item.key)
// if (item.children) {
// handleTreeData(item.children, targetKeys)
// }
// })
// return data
// }
export default { export default {
props: { // import使
projectForm: { components: {},
type: Object, props: { projectForm: { type: Object } },
},
},
data() { data() {
//
return { return {
form: this.projectForm, form: this.projectForm,
targetKeys: [], targetKeys: this.projectForm.unitIds || [],
dataSource: [], dataSource: transferDataSource,
treeData: [], // treeData() {return handleTreeData(treeData, this.targetKeys)},
checkedKeys:[], treeData: []
} }
}, },
created() { // data
console.log('第2个表单创建了') computed: {},
this.getSourceList() // data
}, watch: {},
computed: { //
treeDataComputed() {
return handleTreeData(treeData, this.targetKeys)
},
},
methods: { methods: {
onChange(targetKeys) {
console.log('Target Keys:', targetKeys)
this.targetKeys = targetKeys
},
onChecked(_, e, checkedKeys, itemSelect) {
const { eventKey } = e.node
itemSelect(eventKey, !isChecked(checkedKeys, eventKey))
},
// //
getSourceList(orgType) { getSourceList(orgType) {
return orgList({ orgType: orgType || 1 }).then((res) => { orgList({ orgType: orgType || 1 }).then((res) => {
if (res.data) { if (res.data) {
this.dataSource = []
res.data.forEach((item) => { res.data.forEach((item) => {
this.dataSource.push({ this.dataSource.push({
key: item.id, id: item.id,
key: item.id.toString(),
title: item.name, title: item.name,
children: [], children: [],
pid: item.pid pid: item.pid,
}) })
}) })
console.log('dataSource', this.dataSource) console.log('dataSource', this.dataSource)
this.treeData = listToTree(this.dataSource, [], 0) this.treeData = listToTree(this.dataSource, [], 0)
console.log('treeData', this.treeData)
} }
}) })
}, },
// //
toNext() { toNext() {
this.form.unitIds = this.targetKeys this.form.unitIds = this.targetKeys
console.log('toNext', this.form) console.log('toNext', this.form)
this.$emit('nextStep', this.form) this.$emit('nextStep', this.form)
}, },
// //
toPrep() { toPrep() {
this.form.unitIds = this.targetKeys this.form.unitIds = this.targetKeys
console.log('toPrep', this.form) console.log('toPrep', this.form)
this.$emit('prevStep', this.form) this.$emit('prevStep', this.form)
}, },
onChange(targetKeys) {
console.log('Target Keys:', targetKeys)
this.targetKeys = targetKeys
// this.form = targetKeys
}, },
onChecked(_, e, checkedKeys, itemSelect) { // - 访this
const { eventKey } = e.node created() {
itemSelect(eventKey, !isChecked(checkedKeys, eventKey)) console.log('第2个表单创建了')
this.getSourceList()
console.log('form',this.form)
}, },
//使
filterOption(value, tree) {
console.log('filterOption:', value, tree)
// getParentKey(value, tree) {
if (!value) return
for (let i = 0; i < tree.length; i++) { // - 访DOM
const node = tree[i] mounted() {},
// -
if (node.children) { beforeCreate() {},
if (node.children.some((item) => item.title.indexOf(value) > -1)) { // -
this.expandedKeys.push(node.key) beforeMount() {},
} // -
beforeUpdate() {},
this.filterOption(value, node.children) // -
} updated() {},
} // -
}, beforeDestroy() {},
}, // -
destroyed() { destroyed() {
console.log('第2个表单销毁了') console.log('第2个表单销毁了')
}, },
// keep-alive
activated() {},
} }
</script> </script>
<style scoped>
.tree-transfer .ant-transfer-list:first-child {
width: 50%;
flex: none;
}
</style>