addTest.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  1. <template>
  2. <div class="pb_content" style="background: #F0F2F5;" v-loading="loading">
  3. <div class="pb_content_body" style="position: relative; margin: 0">
  4. <div class="right">
  5. <div class="courseTop" v-if="gotype">
  6. <div
  7. class="r_pub_button_retrun"
  8. @click="retrunCourse"
  9. >
  10. 返回
  11. </div>
  12. </div>
  13. <div class="courseTop" v-else>
  14. <div class="stepsNav">
  15. <el-breadcrumb separator-class="el-icon-arrow-right">
  16. <el-breadcrumb-item v-if="!back" :to="{
  17. path:
  18. '/test?userid=' +
  19. userid +
  20. '&oid=' +
  21. oid +
  22. '&org=' +
  23. org +
  24. '&role=' +
  25. role,
  26. }">表单管理</el-breadcrumb-item>
  27. <el-breadcrumb-item v-else-if="back=='sass'" :to="{
  28. path:
  29. '/sassPlatform?userid=' +
  30. userid +
  31. '&oid=' +
  32. oid +
  33. '&org=' +
  34. org +
  35. '&role=' +
  36. role,
  37. }">sass平台</el-breadcrumb-item>
  38. <el-breadcrumb-item>
  39. <span style="color: rgb(15, 126, 255)">新建表单</span>
  40. </el-breadcrumb-item>
  41. </el-breadcrumb>
  42. </div>
  43. <div class="r_pub_button_retrun" @click="retrunCourse">返回</div>
  44. </div>
  45. <div class="step_box" :style="{ width: steps == 2 && '100%' }">
  46. <editInfo v-if="steps == 2 && !loading" :oid="oid" :org="org" :steps.sync="steps" :fileData.sync="fileData"
  47. :title.sync="title" :brief.sync="brief" :cJson.sync="cJson" @save="save" @publish="publish">
  48. </editInfo>
  49. </div>
  50. </div>
  51. </div>
  52. <el-dialog title="发布表单" :visible.sync="dialogVisible" width="550px" @close="dialogVisible = false" class="eld">
  53. <setInfo :oid="oid" :org="org" :steps.sync="steps" :title.sync="title" :testType.sync="testType"
  54. :see.sync="see" :cJson.sync="cJson" :typeid.sync="typeid" :brief.sync="brief" :juri.sync="juri"
  55. :overDate.sync="overDate" :juriList.sync="juriList" :typeInfo.sync="typeInfo" :origin="origin">
  56. </setInfo>
  57. <span slot="footer" class="dialog-footer">
  58. <el-button type="primary" @click="updateWork(3)">发 布 </el-button>
  59. </span>
  60. </el-dialog>
  61. </div>
  62. </template>
  63. <script>
  64. import setInfo from './setInfo/index.vue'
  65. import editInfo from './edit/index.vue'
  66. export default {
  67. components: {
  68. setInfo, editInfo
  69. },
  70. data() {
  71. return {
  72. gotype:sessionStorage.getItem('gotype'),
  73. userid: this.$route.query.userid,
  74. oid: this.$route.query.oid,
  75. org: this.$route.query.org,
  76. role: this.$route.query.role,
  77. cid: this.$route.query.cid,
  78. back: this.$route.query.back,
  79. steps: 2,
  80. title: "",
  81. testType: [],
  82. see: false,
  83. cJson: [],
  84. loading: false,
  85. look: "",
  86. typeid: "",
  87. brief: "",
  88. juri: '0',
  89. overDate: "",
  90. juriList: [],
  91. typeInfo: [],
  92. dialogVisible: false,
  93. origin: "",
  94. fileData:null,
  95. }
  96. },
  97. watch: {
  98. cid(newValue, oldValue){
  99. let url = "https://beta.cloud.cocorobo.cn/#/testDetail?testid=" + newValue
  100. this.origin = url
  101. },
  102. steps(newValue, oldValue) {
  103. if (!this.title) {
  104. this.$message.error("请补充填写课程名称");
  105. this.steps = 1
  106. return;
  107. }
  108. // else if(!this.juriList.length){
  109. // this.$message.error("请选择权限")
  110. // this.steps = 1
  111. // return
  112. // }
  113. if (this.cid) {
  114. this.updateWork(this.look)
  115. } else {
  116. this.addWork();
  117. }
  118. }
  119. },
  120. methods: {
  121. retrunCourse() {
  122. this
  123. .$confirm("退出当前页面将不保存已编辑内容,是否确定返回", "提示", {
  124. confirmButtonText: "确定",
  125. cancelButtonText: "取消",
  126. distinguishCancelAndClose: true,
  127. type: "warning",
  128. })
  129. .then(() => {
  130. console.log(this.back)
  131. if(!this.back){
  132. this.goTo(
  133. "/test?userid=" +
  134. this.userid +
  135. "&oid=" +
  136. this.oid +
  137. "&org=" +
  138. this.org +
  139. "&role=" +
  140. this.role
  141. );
  142. }else if(this.back == 'sass'){
  143. this.goTo(
  144. "/sassPlatform?userid=" +
  145. this.userid +
  146. "&oid=" +
  147. this.oid +
  148. "&org=" +
  149. this.org +
  150. "&role=" +
  151. this.role
  152. );
  153. }
  154. // if (this.cid == "" || this.cid == undefined) {
  155. // if (this.title == "") {
  156. // this.$message.error("请补充填写课程名称");
  157. // return;
  158. // } else {
  159. // this.addWork(5);
  160. // }
  161. // // else if(!this.juriList.length){
  162. // // this.$message.error("请选择权限")
  163. // // return
  164. // // }
  165. // } else {
  166. // if (this.title == "") {
  167. // this.$message.error("请补充填写课程名称");
  168. // return;
  169. // } else {
  170. // this.updateWork(5);
  171. // }
  172. // // else if(!this.juriList.length){
  173. // // this.$message.error("请选择权限")
  174. // // return
  175. // // }
  176. // }
  177. })
  178. .catch((v) => {
  179. console.log(v)
  180. // if (v == "cancel" && !this.back) {
  181. // this.goTo(
  182. // "/test?userid=" +
  183. // this.userid +
  184. // "&oid=" +
  185. // this.oid +
  186. // "&org=" +
  187. // this.org +
  188. // "&role=" +
  189. // this.role
  190. // );
  191. // }else if(this.back == 'sass'){
  192. // this.goTo(
  193. // "/sassPlatform?userid=" +
  194. // this.userid +
  195. // "&oid=" +
  196. // this.oid +
  197. // "&org=" +
  198. // this.org +
  199. // "&role=" +
  200. // this.role
  201. // );
  202. // }
  203. });
  204. },
  205. goTo(path) {
  206. this.$router.push(path);
  207. },
  208. addWork(look, callback) {
  209. let j3 = []
  210. if (this.typeInfo.length) {
  211. this.typeInfo.forEach(e => {
  212. j3.push(e.value)
  213. })
  214. }
  215. let params = [
  216. {
  217. uid: this.userid,
  218. title: this.title,
  219. brief: this.brief,
  220. cover: JSON.stringify(this.fileData),
  221. evaId: "",
  222. astudent: this.juri,
  223. see: this.see == true ? 1 : 0,
  224. chapters: JSON.stringify(this.cJson),
  225. template: "",
  226. courseType: JSON.stringify(this.testType),
  227. ateacher: "",
  228. inviteCode: "",
  229. typeid: this.typeid ? this.typeid : '',
  230. overtime: this.overDate ? this.formatTime(this.overDate) : '',
  231. j2: this.juriList.length ? this.juriList.join(",") : '',
  232. j3: j3.length ? j3.join(",") : '',
  233. },
  234. ];
  235. this.ajax
  236. .post(this.$store.state.api + "addTestCourse3", params)
  237. .then((res) => {
  238. this.cid = res.data.courseId;
  239. if (look == 5) {
  240. this.$message.success("保存成功")
  241. if(!this.back){
  242. this.goTo(
  243. "/test?userid=" +
  244. this.userid +
  245. "&oid=" +
  246. this.oid +
  247. "&org=" +
  248. this.org +
  249. "&role=" +
  250. this.role
  251. );
  252. }else if(back == 'sass'){
  253. this.goTo(
  254. "/sassPlatform?userid=" +
  255. this.userid +
  256. "&oid=" +
  257. this.oid +
  258. "&org=" +
  259. this.org +
  260. "&role=" +
  261. this.role
  262. );
  263. }
  264. }
  265. // setTimeout(() => {
  266. // this.getData(2);
  267. // }, 1000);
  268. callback ? callback() : ''
  269. })
  270. .catch((err) => {
  271. this.$message.error("网络不佳");
  272. console.error(err);
  273. });
  274. },
  275. formatTime(timestamp) {
  276. const date = new Date(timestamp);
  277. const year = date.getFullYear();
  278. const month = String(date.getMonth() + 1).padStart(2, '0');
  279. const day = String(date.getDate()).padStart(2, '0');
  280. return `${year}-${month}-${day}`;
  281. },
  282. updateWork(look) {
  283. let j3 = []
  284. if (this.typeInfo.length) {
  285. this.typeInfo.forEach(e => {
  286. j3.push(e.value)
  287. })
  288. }
  289. let params = [
  290. {
  291. cid: this.cid,
  292. title: this.title,
  293. brief: this.brief,
  294. cover: JSON.stringify(this.fileData),
  295. evaId: "",
  296. astudent: this.juri,
  297. see: this.see == true ? 1 : 0,
  298. chapters: JSON.stringify(this.cJson),
  299. uid: this.userid,
  300. courseType: JSON.stringify(this.testType),
  301. ateacher: "",
  302. inviteCode: "",
  303. look: look == 3 ? 2 : look == 4 ? this.look : look == 5 ? this.look : look,
  304. typeid: this.typeid ? this.typeid : '',
  305. overtime: this.overDate ? this.formatTime(this.overDate) : '',
  306. j2: this.juriList.length ? this.juriList.join(",") : '',
  307. j3: j3.length ? j3.join(",") : '',
  308. },
  309. ];
  310. this.ajax
  311. .post(this.$store.state.api + "updateTestCourse3", params)
  312. .then((res) => {
  313. if (look == 3) {
  314. this.$message.success("发布成功")
  315. if(!this.back){
  316. this.goTo(
  317. "/test?userid=" +
  318. this.userid +
  319. "&oid=" +
  320. this.oid +
  321. "&org=" +
  322. this.org +
  323. "&role=" +
  324. this.role
  325. );
  326. }else if(this.back == 'sass'){
  327. this.goTo(
  328. "/sassPlatform?userid=" +
  329. this.userid +
  330. "&oid=" +
  331. this.oid +
  332. "&org=" +
  333. this.org +
  334. "&role=" +
  335. this.role
  336. );
  337. }
  338. } else if (look == 4) {
  339. this.$message.success("保存成功")
  340. } else if (look == 1 || look == 2) {
  341. // this.$message.success("保存成功")
  342. } else if (look == 5) {
  343. this.$message.success("保存成功")
  344. if(!this.back){
  345. this.goTo(
  346. "/test?userid=" +
  347. this.userid +
  348. "&oid=" +
  349. this.oid +
  350. "&org=" +
  351. this.org +
  352. "&role=" +
  353. this.role
  354. );
  355. }else if(this.back == 'sass'){
  356. this.goTo(
  357. "/sassPlatform?userid=" +
  358. this.userid +
  359. "&oid=" +
  360. this.oid +
  361. "&org=" +
  362. this.org +
  363. "&role=" +
  364. this.role
  365. );
  366. }
  367. }
  368. setTimeout(() => {
  369. this.getData(2);
  370. }, 1000);
  371. })
  372. .catch((err) => {
  373. this.$message.error("网络不佳");
  374. console.error(err);
  375. });
  376. },
  377. getData(type) {
  378. if (this.cid == "" || this.cid == undefined) {
  379. console.log("这是新增课程");
  380. } else {
  381. if (type != 2) {
  382. this.loading = true
  383. }
  384. let params = {
  385. cid: this.cid,
  386. };
  387. this.ajax
  388. .get(this.$store.state.api + "getTestCourseDetail", params)
  389. .then((res) => {
  390. this.cJson = JSON.parse(res.data[0][0].chapters);
  391. this.title = res.data[0][0].title;
  392. this.juri = res.data[0][0].juri ? res.data[0][0].juri : '0';
  393. this.overDate = res.data[0][0].overTime ? res.data[0][0].overTime : '';
  394. this.juriList = res.data[0][0].juri2 ? res.data[0][0].juri2.split(',') : [];
  395. let juri3 = res.data[0][0].juri3 ? res.data[0][0].juri3.split(',') : [];
  396. if (juri3.length > 0) {
  397. this.typeInfo.forEach(e => {
  398. let array2 = []
  399. for (var i = 0; i < e.child.length; i++) {
  400. array2.push(e.child[i].id)
  401. }
  402. e.value = this.arrayToArray(juri3, array2)[0]
  403. })
  404. }
  405. this.see = res.data[0][0].open == 1 ? true : false;
  406. this.typeid = res.data[0][0].typeid;
  407. this.brief = res.data[0][0].brief;
  408. this.fileData = res.data[0][0].cover?JSON.parse(res.data[0][0].cover):null;
  409. this.testType = [];
  410. for (var i = 0; i < res.data[1].length; i++) {
  411. this.testType.push(res.data[1][i].typeid);
  412. }
  413. console.log(this.testType);
  414. this.look = res.data[0][0].look
  415. this.$forceUpdate()
  416. if (type != 2) {
  417. this.loading = false
  418. }
  419. })
  420. .catch((err) => {
  421. console.error(err);
  422. });
  423. }
  424. },
  425. save(look) {
  426. if (!this.title) {
  427. this.$message.error("请补充填写课程名称");
  428. return;
  429. }
  430. if (this.cid) {
  431. this.updateWork(look == 4 ? look : this.look)
  432. } else {
  433. this.addWork();
  434. }
  435. // this.updateWork(5)
  436. },
  437. publish() {
  438. if (!this.title) {
  439. this.$message.error("请补充填写课程名称");
  440. return;
  441. }
  442. if (this.cid) {
  443. this.dialogVisible = true
  444. } else {
  445. this.addWork(this.look, ()=>{
  446. this.dialogVisible = true
  447. });
  448. }
  449. // this.updateWork(3)
  450. },
  451. //获取分类类名
  452. getTypeInfo() {
  453. this.loading = true
  454. let params = {
  455. oid: this.oid
  456. };
  457. this.ajax
  458. .get(this.$store.state.api + "selectPerInfoAllTea", params)
  459. .then((res) => {
  460. this.typeInfo = res.data[0];
  461. let typeInfo = res.data[1];
  462. this.typeInfo.forEach((e) => {
  463. e.child = [];
  464. e.value = '';
  465. typeInfo.forEach((i) => {
  466. if (e.id == i.parentid) {
  467. e.child.push({ id: i.id, name: i.name })
  468. }
  469. })
  470. })
  471. this.loading = false
  472. console.log(this.typeInfo, "typeInfo");
  473. this.getData();
  474. })
  475. .catch((err) => {
  476. console.error(err);
  477. });
  478. },
  479. arrayToArray(arrayo, arrayt) {
  480. let array1 = arrayo;
  481. let array2 = arrayt;
  482. let commonElements = [];
  483. for (let i = 0; i < array1.length; i++) {
  484. for (let j = 0; j < array2.length; j++) {
  485. if (array1[i] === array2[j]) {
  486. commonElements.push(array1[i]);
  487. }
  488. }
  489. }
  490. return commonElements;
  491. },
  492. },
  493. mounted() {
  494. if(this.cid){
  495. let url = "https://beta.cloud.cocorobo.cn/#/testDetail?testid=" + this.cid
  496. this.origin = url
  497. }
  498. this.getTypeInfo();
  499. },
  500. }
  501. </script>
  502. <style scoped>
  503. .pb_content {
  504. height: 100% !important;
  505. /* margin: 0 20px 0 20px; */
  506. }
  507. .pb_content_body {
  508. width: 100% !important;
  509. height: 100%;
  510. }
  511. .right {
  512. height: 100%;
  513. width: 100%;
  514. display: flex;
  515. overflow: hidden;
  516. flex-direction: column;
  517. }
  518. .basic_box {
  519. margin: 0 auto;
  520. position: relative;
  521. padding: 0 20px 0 20px;
  522. }
  523. .courseTop {
  524. display: flex;
  525. flex-direction: row;
  526. justify-content: space-between;
  527. align-items: center;
  528. width: calc(100% - 40px);
  529. margin: 0 auto;
  530. padding: 10px 0;
  531. }
  532. .stepsNav {
  533. display: flex;
  534. flex-direction: row;
  535. justify-content: flex-start;
  536. align-items: center;
  537. }
  538. .step_box {
  539. width: calc(100% - 40px);
  540. margin: 0 auto;
  541. height: calc(100% - 38px);
  542. }
  543. .eld >>> .el-dialog__header{
  544. border-bottom: 1px solid #E7E7E7;
  545. }
  546. .eld >>> .el-dialog__body {
  547. padding: 0 20px;
  548. color: unset;
  549. }
  550. </style>