PropertyInfo.vue 12 KB

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