PropertyInfo.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. <template>
  2. <section class="content">
  3. <LinkTitlesCustom :currentPaths="['属性结构']" />
  4. <!-- 正文信息 -->
  5. <div class="box-body">
  6. <el-form
  7. :inline="true"
  8. :model="courseProperty"
  9. label-position="right"
  10. label-width="90px"
  11. >
  12. <el-row :gutter="10">
  13. <el-col :xs="7" :sm="7" :md="7" :lg="8">
  14. <el-form-item label="属性名称" class="pull-left">
  15. <el-input
  16. placeholder="请输入课程名称"
  17. v-model="courseProperty.name"
  18. :disabled="true"
  19. ></el-input>
  20. </el-form-item>
  21. </el-col>
  22. <el-col :xs="7" :sm="7" :md="7" :lg="8">
  23. <el-form-item label="课程名称">
  24. <el-select
  25. v-model="courseProperty.courseId"
  26. class="form_width"
  27. filterable
  28. :remote-method="getCourses"
  29. remote
  30. clearable
  31. :disabled="true"
  32. >
  33. <el-option
  34. v-for="item in courseInfoSelect"
  35. :label="item.courseInfo"
  36. :value="item.courseId"
  37. :key="item.courseId"
  38. >
  39. </el-option>
  40. </el-select>
  41. </el-form-item>
  42. </el-col>
  43. </el-row>
  44. <el-row :xs="7" :sm="7" :md="7" :lg="8">
  45. <div style="margin-left: 20px;">
  46. <el-form-item>
  47. <el-button type="primary" @click="insertParent" size="small"
  48. ><i class="el-icon-plus"></i> 新增一级</el-button
  49. >
  50. <el-button
  51. type="primary"
  52. size="small"
  53. @click="insertSon"
  54. :disabled="showSonButtton"
  55. ><i class="el-icon-plus"></i> 新增二级</el-button
  56. >
  57. <el-button
  58. type="primary"
  59. size="small"
  60. @click="updateProperty"
  61. :disabled="showButton"
  62. ><i class="el-icon-edit"></i>编辑</el-button
  63. >
  64. <el-button
  65. type="danger"
  66. size="small"
  67. @click="deleteProperty"
  68. :disabled="showButton"
  69. ><i class="el-icon-delete"></i> 删除</el-button
  70. >
  71. <el-button
  72. type="info"
  73. @click="moveUp"
  74. :disabled="showMoveButtton"
  75. size="small"
  76. ><i class="el-icon-arrow-up"></i> 上移</el-button
  77. >
  78. <el-button
  79. type="info"
  80. @click="moveDown"
  81. :disabled="showMoveButtton"
  82. size="small"
  83. ><i class="el-icon-arrow-down"></i> 下移</el-button
  84. >
  85. <el-button
  86. type="primary"
  87. icon="caret-left"
  88. @click="back"
  89. size="small"
  90. ><i class="el-icon-arrow-left"></i> 返 回</el-button
  91. >
  92. </el-form-item>
  93. </div>
  94. </el-row>
  95. </el-form>
  96. <el-tree
  97. :data="data"
  98. node-key="id"
  99. :props="defaultProps"
  100. :default-expanded-keys="ids"
  101. @node-click="handleNodeClick"
  102. ></el-tree>
  103. </div>
  104. <el-dialog :title="title" :visible.sync="propertyDialog">
  105. <el-form :model="propertyForm">
  106. <el-row v-show="parentName">
  107. <el-form-item label="一级名称">
  108. <el-input
  109. v-model="propertyForm.parentName"
  110. auto-complete="off"
  111. style="width: 220px;"
  112. @change="showTitle"
  113. ></el-input>
  114. <span style="color: red;" v-show="showParentName"
  115. >请输一级名称</span
  116. >
  117. </el-form-item>
  118. </el-row>
  119. <el-row v-show="sonName">
  120. <el-form-item label="二级名称">
  121. <el-input
  122. v-model="propertyForm.sonName"
  123. auto-complete="off"
  124. style="width: 220px;"
  125. @change="showTitle"
  126. ></el-input>
  127. <span style="color: red;" v-show="showSonName">请输二级名称</span>
  128. </el-form-item>
  129. </el-row>
  130. <el-row>
  131. <el-form-item label="名称备注">
  132. <el-input
  133. v-model="propertyForm.remark"
  134. auto-complete="off"
  135. style="width: 220px;"
  136. @change="showTitle"
  137. ></el-input>
  138. </el-form-item>
  139. </el-row>
  140. </el-form>
  141. <div slot="footer" class="dialog-footer">
  142. <el-button @click="propertyDialog = false">取 消</el-button>
  143. <el-button type="primary" @click="submit">确 定</el-button>
  144. </div>
  145. </el-dialog>
  146. </section>
  147. </template>
  148. <script>
  149. import { CORE_API, QUESTION_API } from "@/constants/constants";
  150. import LinkTitlesCustom from "@/components/LinkTitlesCustom.vue";
  151. export default {
  152. components: { LinkTitlesCustom },
  153. data() {
  154. return {
  155. courseProperty: {
  156. name: "",
  157. courseId: ""
  158. },
  159. courseList: [],
  160. ids: [],
  161. loading: false,
  162. parentName: false,
  163. sonName: false,
  164. propertyDialog: false,
  165. propertyForm: {
  166. parentName: "",
  167. sonName: "",
  168. remark: ""
  169. },
  170. property: {
  171. id: "",
  172. name: "",
  173. parentId: "",
  174. number: "",
  175. coursePropertyId: "",
  176. remark: ""
  177. },
  178. showButton: true,
  179. showSonButtton: true,
  180. showParentName: false,
  181. showSonName: false,
  182. data: [],
  183. defaultProps: {
  184. children: "propertyDtos",
  185. label: "name"
  186. },
  187. title: "新增属性",
  188. showMoveButtton: true
  189. };
  190. },
  191. methods: {
  192. //树形节点选中
  193. handleNodeClick(object) {
  194. //得到选中的节点
  195. console.log(object);
  196. this.showButton = false;
  197. //判断选中节点,如果是父节点,可以新增二级
  198. if (object.parentId === 0) {
  199. this.showSonButtton = false;
  200. this.showMoveButtton = false;
  201. } else {
  202. this.showSonButtton = true;
  203. this.showMoveButtton = true;
  204. }
  205. this.property.id = object.id;
  206. this.property.name = object.name;
  207. this.property.parentId = object.parentId;
  208. this.property.number = object.number;
  209. this.property.coursePropertyId = object.coursePropertyId;
  210. this.property.remark = object.remark;
  211. },
  212. //查询所有课程
  213. getCourses(query) {
  214. this.courseList = [];
  215. if (query) {
  216. this.courseLoading = true;
  217. this.$http.get(CORE_API + "/course/" + query).then(response => {
  218. var courseBean = response.data;
  219. this.courseList.push(courseBean);
  220. });
  221. } else {
  222. this.courseList = [];
  223. }
  224. },
  225. //查询
  226. searchProperty() {
  227. this.loading = true;
  228. var coursePropertyStorge = sessionStorage.getItem("courseProperty");
  229. if (typeof coursePropertyStorge == "string") {
  230. this.courseProperty = JSON.parse(coursePropertyStorge);
  231. this.getCourses(this.courseProperty.courseId);
  232. }
  233. this.$http
  234. .get(QUESTION_API + "/property/all/" + this.coursePropertyId)
  235. .then(response => {
  236. this.data = response.data;
  237. for (var i = 0; i < this.data.length; i++) {
  238. var property = this.data[i];
  239. this.ids.push(property.id);
  240. }
  241. this.loading = false;
  242. });
  243. },
  244. //新增一级
  245. insertParent() {
  246. this.title = "新增属性";
  247. this.showParentName = false;
  248. this.property = {
  249. id: "",
  250. name: "",
  251. parentId: 0,
  252. number: "",
  253. coursePropertyId: this.coursePropertyId,
  254. remark: ""
  255. };
  256. this.propertyForm.parentName = "";
  257. this.propertyForm.remark = "";
  258. this.sonName = false;
  259. this.parentName = true;
  260. this.propertyDialog = true;
  261. },
  262. //新增二级
  263. insertSon() {
  264. this.title = "新增属性";
  265. this.showSonName = false;
  266. //父对象id赋值
  267. this.property.parentId = this.property.id;
  268. this.property.id = "";
  269. this.property.name = "";
  270. this.property.remark = "";
  271. this.property.coursePropertyId = this.coursePropertyId;
  272. this.propertyForm.sonName = "";
  273. this.propertyForm.remark = "";
  274. this.parentName = false;
  275. this.sonName = true;
  276. this.propertyDialog = true;
  277. },
  278. //修改
  279. updateProperty() {
  280. this.title = "修改属性";
  281. //判断是父节点还是子节点
  282. if (this.property.parentId === 0) {
  283. this.propertyForm.parentName = this.property.name;
  284. this.propertyForm.remark = this.property.remark;
  285. this.sonName = false;
  286. this.parentName = true;
  287. } else {
  288. this.propertyForm.sonName = this.property.name;
  289. this.propertyForm.remark = this.property.remark;
  290. this.parentName = false;
  291. this.sonName = true;
  292. }
  293. this.propertyDialog = true;
  294. },
  295. //保存
  296. submit() {
  297. if (this.property.parentId === 0) {
  298. //非空判断
  299. if (!this.propertyForm.parentName) {
  300. this.showParentName = true;
  301. return 0;
  302. }
  303. this.property.name = this.propertyForm.parentName;
  304. } else {
  305. //非空判断
  306. if (!this.propertyForm.sonName) {
  307. this.showSonName = true;
  308. return 0;
  309. }
  310. this.property.name = this.propertyForm.sonName;
  311. }
  312. this.property.remark = this.propertyForm.remark;
  313. if (this.property.id) {
  314. this.$http
  315. .put(QUESTION_API + "/property/save", this.property)
  316. .then(() => {
  317. this.$notify({
  318. message: "修改成功",
  319. type: "success"
  320. });
  321. this.propertyDialog = false;
  322. this.searchProperty();
  323. })
  324. .catch(() => {
  325. this.$notify({
  326. type: "error",
  327. message: "名称重复,请重新命名"
  328. });
  329. });
  330. } else {
  331. this.$http
  332. .post(QUESTION_API + "/property/save", this.property)
  333. .then(() => {
  334. this.$notify({
  335. message: "新增成功",
  336. type: "success"
  337. });
  338. this.propertyDialog = false;
  339. this.searchProperty();
  340. })
  341. .catch(() => {
  342. this.$notify({
  343. type: "error",
  344. message: "名称重复,请重新命名"
  345. });
  346. });
  347. }
  348. this.showButton = true;
  349. this.showSonButtton = true;
  350. },
  351. //删除
  352. deleteProperty() {
  353. this.$confirm("确认删除试卷吗?", "提示", {
  354. type: "warning"
  355. }).then(() => {
  356. this.loading = true;
  357. this.$http
  358. .delete(
  359. QUESTION_API +
  360. "/property/delete/" +
  361. this.property.id +
  362. "/" +
  363. this.property.coursePropertyId
  364. )
  365. .then(() => {
  366. this.$notify({
  367. message: "删除成功",
  368. type: "success"
  369. });
  370. this.searchProperty();
  371. })
  372. .catch(() => {
  373. this.$notify({
  374. type: "error",
  375. message: "删除失败"
  376. });
  377. });
  378. });
  379. this.showButton = true;
  380. this.showSonButtton = true;
  381. },
  382. //效验
  383. showTitle() {
  384. if (this.propertyForm.parentName) {
  385. this.showParentName = false;
  386. }
  387. if (!this.propertyForm.parentName) {
  388. this.showParentName = true;
  389. }
  390. if (this.propertyForm.sonName) {
  391. this.showSonName = false;
  392. }
  393. if (!this.propertyForm.sonName) {
  394. this.showSonName = true;
  395. }
  396. },
  397. //返回
  398. back() {
  399. this.$router.push({
  400. path: "/questions/course_property/1"
  401. });
  402. },
  403. //上移
  404. moveUp() {
  405. this.$http
  406. .put(QUESTION_API + "/property/moveUp", this.property)
  407. .then(() => {
  408. this.searchProperty();
  409. this.showMoveButtton = true;
  410. })
  411. .catch(() => {
  412. this.$notify({
  413. type: "error",
  414. message: "无法上移"
  415. });
  416. this.showMoveButtton = true;
  417. });
  418. },
  419. //下移
  420. moveDown() {
  421. this.$http
  422. .put(QUESTION_API + "/property/moveDown", this.property)
  423. .then(() => {
  424. this.searchProperty();
  425. this.showMoveButtton = true;
  426. })
  427. .catch(() => {
  428. this.$notify({
  429. type: "error",
  430. message: "无法下移"
  431. });
  432. this.showMoveButtton = true;
  433. });
  434. }
  435. },
  436. computed: {
  437. courseInfoSelect() {
  438. var courseList = [];
  439. for (var i = 0; i < this.courseList.length; i++) {
  440. var courseInfo = {
  441. courseInfo:
  442. this.courseList[i].name + "(" + this.courseList[i].code + ")",
  443. courseId: this.courseList[i].id
  444. };
  445. courseList.push(courseInfo);
  446. }
  447. return courseList;
  448. }
  449. },
  450. created() {
  451. this.coursePropertyId = this.$route.params.id;
  452. this.searchProperty();
  453. }
  454. };
  455. </script>