PropertyInfo.vue 12 KB

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