addTest.vue 20 KB

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