123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458 |
- <template>
- <section class="content">
- <LinkTitlesCustom :currentPaths="['属性结构']" />
- <!-- 正文信息 -->
- <div class="box-body">
- <el-form
- :inline="true"
- :model="courseProperty"
- label-position="right"
- label-width="90px"
- >
- <el-row :gutter="10">
- <el-col :xs="7" :sm="7" :md="7" :lg="8">
- <el-form-item label="属性名称" class="pull-left">
- <el-input
- placeholder="请输入课程名称"
- v-model="courseProperty.name"
- :disabled="true"
- ></el-input>
- </el-form-item>
- </el-col>
- <el-col :xs="7" :sm="7" :md="7" :lg="8">
- <el-form-item label="课程名称">
- <el-select
- v-model="courseProperty.courseId"
- class="form_width"
- filterable
- :remote-method="getCourses"
- remote
- clearable
- :disabled="true"
- >
- <el-option
- v-for="item in courseInfoSelect"
- :label="item.courseInfo"
- :value="item.courseId"
- :key="item.courseId"
- >
- </el-option>
- </el-select>
- </el-form-item>
- </el-col>
- </el-row>
- <el-row :xs="7" :sm="7" :md="7" :lg="8">
- <div style="margin-left: 20px;">
- <el-form-item>
- <el-button type="primary" @click="insertParent" size="small"
- ><i class="el-icon-plus"></i> 新增一级</el-button
- >
- <el-button
- type="primary"
- size="small"
- @click="insertSon"
- :disabled="showSonButtton"
- ><i class="el-icon-plus"></i> 新增二级</el-button
- >
- <el-button
- type="primary"
- size="small"
- @click="updateProperty"
- :disabled="showButton"
- ><i class="el-icon-edit"></i>编辑</el-button
- >
- <el-button
- type="danger"
- size="small"
- @click="deleteProperty"
- :disabled="showButton"
- ><i class="el-icon-delete"></i> 删除</el-button
- >
- <el-button
- type="info"
- @click="moveUp"
- :disabled="showMoveButtton"
- size="small"
- ><i class="el-icon-arrow-up"></i> 上移</el-button
- >
- <el-button
- type="info"
- @click="moveDown"
- :disabled="showMoveButtton"
- size="small"
- ><i class="el-icon-arrow-down"></i> 下移</el-button
- >
- <el-button
- type="primary"
- icon="caret-left"
- @click="back"
- size="small"
- ><i class="el-icon-arrow-left"></i> 返 回</el-button
- >
- </el-form-item>
- </div>
- </el-row>
- </el-form>
- <el-tree
- :data="data"
- node-key="id"
- :props="defaultProps"
- :default-expanded-keys="ids"
- @node-click="handleNodeClick"
- ></el-tree>
- </div>
- <el-dialog :title="title" :visible.sync="propertyDialog">
- <el-form :model="propertyForm">
- <el-row v-show="parentName">
- <el-form-item label="一级名称">
- <el-input
- v-model="propertyForm.parentName"
- auto-complete="off"
- style="width: 220px;"
- @change="showTitle"
- ></el-input>
- <span style="color: red;" v-show="showParentName"
- >请输一级名称</span
- >
- </el-form-item>
- </el-row>
- <el-row v-show="sonName">
- <el-form-item label="二级名称">
- <el-input
- v-model="propertyForm.sonName"
- auto-complete="off"
- style="width: 220px;"
- @change="showTitle"
- ></el-input>
- <span style="color: red;" v-show="showSonName">请输二级名称</span>
- </el-form-item>
- </el-row>
- <el-row>
- <el-form-item label="名称备注">
- <el-input
- v-model="propertyForm.remark"
- auto-complete="off"
- style="width: 220px;"
- @change="showTitle"
- ></el-input>
- </el-form-item>
- </el-row>
- </el-form>
- <div slot="footer" class="dialog-footer">
- <el-button @click="propertyDialog = false">取 消</el-button>
- <el-button type="primary" @click="submit">确 定</el-button>
- </div>
- </el-dialog>
- </section>
- </template>
- <script>
- import { CORE_API, QUESTION_API } from "@/constants/constants";
- import LinkTitlesCustom from "@/components/LinkTitlesCustom.vue";
- export default {
- components: { LinkTitlesCustom },
- data() {
- return {
- courseProperty: {
- name: "",
- courseId: ""
- },
- courseList: [],
- ids: [],
- loading: false,
- parentName: false,
- sonName: false,
- propertyDialog: false,
- propertyForm: {
- parentName: "",
- sonName: "",
- remark: ""
- },
- property: {
- id: "",
- name: "",
- parentId: "",
- number: "",
- coursePropertyId: "",
- remark: ""
- },
- showButton: true,
- showSonButtton: true,
- showParentName: false,
- showSonName: false,
- data: [],
- defaultProps: {
- children: "propertyDtos",
- label: "name"
- },
- title: "新增属性",
- showMoveButtton: true
- };
- },
- methods: {
- //树形节点选中
- handleNodeClick(object) {
- //得到选中的节点
- console.log(object);
- this.showButton = false;
- //判断选中节点,如果是父节点,可以新增二级
- if (object.parentId === 0) {
- this.showSonButtton = false;
- this.showMoveButtton = false;
- } else {
- this.showSonButtton = true;
- this.showMoveButtton = true;
- }
- this.property.id = object.id;
- this.property.name = object.name;
- this.property.parentId = object.parentId;
- this.property.number = object.number;
- this.property.coursePropertyId = object.coursePropertyId;
- this.property.remark = object.remark;
- },
- //查询所有课程
- getCourses(query) {
- this.courseList = [];
- if (query) {
- this.courseLoading = true;
- this.$http.get(CORE_API + "/course/" + query).then(response => {
- var courseBean = response.data;
- this.courseList.push(courseBean);
- });
- } else {
- this.courseList = [];
- }
- },
- //查询
- searchProperty() {
- this.loading = true;
- var coursePropertyStorge = sessionStorage.getItem("courseProperty");
- if (typeof coursePropertyStorge == "string") {
- this.courseProperty = JSON.parse(coursePropertyStorge);
- this.getCourses(this.courseProperty.courseId);
- }
- this.$http
- .get(QUESTION_API + "/property/all/" + this.coursePropertyId)
- .then(response => {
- this.data = response.data;
- for (var i = 0; i < this.data.length; i++) {
- var property = this.data[i];
- this.ids.push(property.id);
- }
- this.loading = false;
- });
- },
- //新增一级
- insertParent() {
- this.title = "新增属性";
- this.showParentName = false;
- this.property = {
- id: "",
- name: "",
- parentId: 0,
- number: "",
- coursePropertyId: this.coursePropertyId,
- remark: ""
- };
- this.propertyForm.parentName = "";
- this.propertyForm.remark = "";
- this.sonName = false;
- this.parentName = true;
- this.propertyDialog = true;
- },
- //新增二级
- insertSon() {
- this.title = "新增属性";
- this.showSonName = false;
- //父对象id赋值
- this.property.parentId = this.property.id;
- this.property.id = "";
- this.property.name = "";
- this.property.remark = "";
- this.property.coursePropertyId = this.coursePropertyId;
- this.propertyForm.sonName = "";
- this.propertyForm.remark = "";
- this.parentName = false;
- this.sonName = true;
- this.propertyDialog = true;
- },
- //修改
- updateProperty() {
- this.title = "修改属性";
- //判断是父节点还是子节点
- if (this.property.parentId === 0) {
- this.propertyForm.parentName = this.property.name;
- this.propertyForm.remark = this.property.remark;
- this.sonName = false;
- this.parentName = true;
- } else {
- this.propertyForm.sonName = this.property.name;
- this.propertyForm.remark = this.property.remark;
- this.parentName = false;
- this.sonName = true;
- }
- this.propertyDialog = true;
- },
- //保存
- submit() {
- if (this.property.parentId === 0) {
- //非空判断
- if (!this.propertyForm.parentName) {
- this.showParentName = true;
- return 0;
- }
- this.property.name = this.propertyForm.parentName;
- } else {
- //非空判断
- if (!this.propertyForm.sonName) {
- this.showSonName = true;
- return 0;
- }
- this.property.name = this.propertyForm.sonName;
- }
- this.property.remark = this.propertyForm.remark;
- if (this.property.id) {
- this.$http
- .put(QUESTION_API + "/property/save", this.property)
- .then(() => {
- this.$notify({
- message: "修改成功",
- type: "success"
- });
- this.propertyDialog = false;
- this.searchProperty();
- })
- .catch(() => {
- this.$notify({
- type: "error",
- message: "名称重复,请重新命名"
- });
- });
- } else {
- this.$http
- .post(QUESTION_API + "/property/save", this.property)
- .then(() => {
- this.$notify({
- message: "新增成功",
- type: "success"
- });
- this.propertyDialog = false;
- this.searchProperty();
- })
- .catch(() => {
- this.$notify({
- type: "error",
- message: "名称重复,请重新命名"
- });
- });
- }
- this.showButton = true;
- this.showSonButtton = true;
- },
- //删除
- deleteProperty() {
- this.$confirm("确认删除试卷吗?", "提示", {
- type: "warning"
- }).then(() => {
- this.loading = true;
- this.$http
- .delete(
- QUESTION_API +
- "/property/delete/" +
- this.property.id +
- "/" +
- this.property.coursePropertyId
- )
- .then(() => {
- this.$notify({
- message: "删除成功",
- type: "success"
- });
- this.searchProperty();
- })
- .catch(() => {
- this.$notify({
- type: "error",
- message: "删除失败"
- });
- });
- });
- this.showButton = true;
- this.showSonButtton = true;
- },
- //效验
- showTitle() {
- if (this.propertyForm.parentName) {
- this.showParentName = false;
- }
- if (!this.propertyForm.parentName) {
- this.showParentName = true;
- }
- if (this.propertyForm.sonName) {
- this.showSonName = false;
- }
- if (!this.propertyForm.sonName) {
- this.showSonName = true;
- }
- },
- //返回
- back() {
- this.$router.push({
- path: "/questions/course_property/1"
- });
- },
- //上移
- moveUp() {
- this.$http
- .put(QUESTION_API + "/property/moveUp", this.property)
- .then(() => {
- this.searchProperty();
- this.showMoveButtton = true;
- })
- .catch(() => {
- this.$notify({
- type: "error",
- message: "无法上移"
- });
- this.showMoveButtton = true;
- });
- },
- //下移
- moveDown() {
- this.$http
- .put(QUESTION_API + "/property/moveDown", this.property)
- .then(() => {
- this.searchProperty();
- this.showMoveButtton = true;
- })
- .catch(() => {
- this.$notify({
- type: "error",
- message: "无法下移"
- });
- this.showMoveButtton = true;
- });
- }
- },
- computed: {
- courseInfoSelect() {
- var courseList = [];
- for (var i = 0; i < this.courseList.length; i++) {
- var courseInfo = {
- courseInfo:
- this.courseList[i].name + "(" + this.courseList[i].code + ")",
- courseId: this.courseList[i].id
- };
- courseList.push(courseInfo);
- }
- return courseList;
- }
- },
- created() {
- this.coursePropertyId = this.$route.params.id;
- this.searchProperty();
- }
- };
- </script>
|