addTestXin.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  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 separator-class="el-icon-arrow-right">
  8. <el-breadcrumb-item :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>
  20. <span style="color: rgb(15, 126, 255)">新建表单</span>
  21. </el-breadcrumb-item>
  22. </el-breadcrumb>
  23. </div>
  24. <div class="r_pub_button_retrun" @click="retrunCourse">返回</div>
  25. </div>
  26. <div class="step_box" :style="{ width: steps == 2 && '100%' }">
  27. <setInfo v-if="steps == 1 && !loading" :oid="oid" :org="org" :steps.sync="steps" :title.sync="title"
  28. :testType.sync="testType" :see.sync="see" :cJson.sync="cJson" :typeid.sync="typeid" :brief.sync="brief" :juri.sync="juri" :overDate.sync="overDate" :juriList.sync="juriList"></setInfo>
  29. <editInfo v-if="steps == 2 && !loading" :oid="oid" :org="org" :steps.sync="steps" :title.sync="title"
  30. :cJson.sync="cJson" @save="save" @publish="publish"></editInfo>
  31. </div>
  32. </div>
  33. </div>
  34. </div>
  35. </template>
  36. <script>
  37. import setInfo from './setInfo/index.vue'
  38. import editInfo from './edit/index.vue'
  39. export default {
  40. components: {
  41. setInfo, editInfo
  42. },
  43. data() {
  44. return {
  45. userid: this.$route.query.userid,
  46. oid: this.$route.query.oid,
  47. org: this.$route.query.org,
  48. role: this.$route.query.role,
  49. cid: this.$route.query.cid,
  50. steps: 2,
  51. title: "",
  52. testType: [],
  53. see: false,
  54. cJson: [],
  55. loading:false,
  56. look:"",
  57. typeid:"",
  58. brief:"",
  59. juri:'0',
  60. overDate:"",
  61. juriList:"",
  62. }
  63. },
  64. watch: {
  65. steps(newValue, oldValue) {
  66. if (!this.title) {
  67. this.$message.error("请补充填写课程名称");
  68. this.steps = 1
  69. return;
  70. }
  71. // else if(!this.juriList.length){
  72. // this.$message.error("请选择权限")
  73. // this.steps = 1
  74. // return
  75. // }
  76. if (this.cid) {
  77. this.updateWork(this.look)
  78. } else {
  79. this.addWork();
  80. }
  81. }
  82. },
  83. methods: {
  84. retrunCourse() {
  85. this
  86. .$confirm("是否保存已编辑内容?", "提示", {
  87. confirmButtonText: "保存",
  88. cancelButtonText: "不保存",
  89. distinguishCancelAndClose: true,
  90. type: "warning",
  91. })
  92. .then(() => {
  93. if (this.cid == "" || this.cid == undefined) {
  94. if (this.title == "") {
  95. this.$message.error("请补充填写课程名称");
  96. return;
  97. }else {
  98. this.addWork(5);
  99. }
  100. // else if(!this.juriList.length){
  101. // this.$message.error("请选择权限")
  102. // return
  103. // }
  104. } else {
  105. if (this.title == "") {
  106. this.$message.error("请补充填写课程名称");
  107. return;
  108. }else {
  109. this.updateWork(5);
  110. }
  111. // else if(!this.juriList.length){
  112. // this.$message.error("请选择权限")
  113. // return
  114. // }
  115. }
  116. })
  117. .catch((v) => {
  118. console.log(v)
  119. if (v == "cancel") {
  120. this.goTo(
  121. "/test?userid=" +
  122. this.userid +
  123. "&oid=" +
  124. this.oid +
  125. "&org=" +
  126. this.org +
  127. "&role=" +
  128. this.role
  129. );
  130. }
  131. });
  132. },
  133. goTo(path) {
  134. this.$router.push(path);
  135. },
  136. addWork(look) {
  137. let params = [
  138. {
  139. uid: this.userid,
  140. title: this.title,
  141. brief: this.brief,
  142. cover: "",
  143. evaId: "",
  144. astudent: this.juri,
  145. see: this.see == true ? 1 : 0,
  146. chapters: JSON.stringify(this.cJson),
  147. template: "",
  148. courseType: JSON.stringify(this.testType),
  149. ateacher: "",
  150. inviteCode: "",
  151. typeid: this.typeid ? this.typeid : '',
  152. overtime: this.overDate ? this.formatTime(this.overDate) : '',
  153. j2: this.juriList.length ? this.juriList.join(",") : ''
  154. },
  155. ];
  156. this.ajax
  157. .post(this.$store.state.api + "addTestCourse", params)
  158. .then((res) => {
  159. this.cid = res.data.courseId;
  160. if(look == 5){
  161. this.$message.success("保存成功")
  162. this.goTo(
  163. "/test?userid=" +
  164. this.userid +
  165. "&oid=" +
  166. this.oid +
  167. "&org=" +
  168. this.org +
  169. "&role=" +
  170. this.role
  171. );
  172. }
  173. setTimeout(() => {
  174. this.getData(2);
  175. }, 1000);
  176. })
  177. .catch((err) => {
  178. this.$message.error("网络不佳");
  179. console.error(err);
  180. });
  181. },
  182. formatTime(timestamp) {
  183. const date = new Date(timestamp);
  184. const year = date.getFullYear();
  185. const month = String(date.getMonth() + 1).padStart(2, '0');
  186. const day = String(date.getDate()).padStart(2, '0');
  187. return `${year}-${month}-${day}`;
  188. },
  189. updateWork(look) {
  190. let params = [
  191. {
  192. cid: this.cid,
  193. title: this.title,
  194. brief: this.brief,
  195. cover: "",
  196. evaId: "",
  197. astudent: this.juri,
  198. see: this.see == true ? 1 : 0,
  199. chapters: JSON.stringify(this.cJson),
  200. uid: this.userid,
  201. courseType: JSON.stringify(this.testType),
  202. ateacher: "",
  203. inviteCode: "",
  204. look: look == 3 ? 2 : look == 4 ? this.look : look == 5 ? this.look : look,
  205. typeid: this.typeid ? this.typeid : '',
  206. overtime: this.overDate ? this.formatTime(this.overDate) : '',
  207. j2: this.juriList.length ? this.juriList.join(",") : ''
  208. },
  209. ];
  210. this.ajax
  211. .post(this.$store.state.api + "updateTestCourse", params)
  212. .then((res) => {
  213. if(look == 3){
  214. this.$message.success("发布成功")
  215. this.goTo(
  216. "/test?userid=" +
  217. this.userid +
  218. "&oid=" +
  219. this.oid +
  220. "&org=" +
  221. this.org +
  222. "&role=" +
  223. this.role
  224. );
  225. }else if(look == 4){
  226. this.$message.success("保存成功")
  227. }else if( look == 1 || look == 2){
  228. // this.$message.success("保存成功")
  229. }else if(look == 5){
  230. this.$message.success("保存成功")
  231. this.goTo(
  232. "/test?userid=" +
  233. this.userid +
  234. "&oid=" +
  235. this.oid +
  236. "&org=" +
  237. this.org +
  238. "&role=" +
  239. this.role
  240. );
  241. }
  242. setTimeout(() => {
  243. this.getData(2);
  244. }, 1000);
  245. })
  246. .catch((err) => {
  247. this.$message.error("网络不佳");
  248. console.error(err);
  249. });
  250. },
  251. getData(type) {
  252. if (this.cid == "" || this.cid == undefined) {
  253. console.log("这是新增课程");
  254. } else {
  255. if(type != 2){
  256. this.loading = true
  257. }
  258. let params = {
  259. cid: this.cid,
  260. };
  261. this.ajax
  262. .get(this.$store.state.api + "getTestCourseDetail", params)
  263. .then((res) => {
  264. this.cJson = JSON.parse(res.data[0][0].chapters);
  265. this.title = res.data[0][0].title;
  266. this.juri = res.data[0][0].juri ? res.data[0][0].juri : '0';
  267. this.overDate = res.data[0][0].overTime ? res.data[0][0].overTime : '';
  268. this.juriList = res.data[0][0].juri2 ? res.data[0][0].juri2.split(',') : [];
  269. this.see = res.data[0][0].open == 1 ? true : false;
  270. this.typeid = res.data[0][0].typeid;
  271. this.brief = res.data[0][0].brief;
  272. this.testType = [];
  273. for (var i = 0; i < res.data[1].length; i++) {
  274. this.testType.push(res.data[1][i].typeid);
  275. }
  276. console.log(this.testType);
  277. this.look = res.data[0][0].look
  278. this.$forceUpdate()
  279. if(type != 2){
  280. this.loading = false
  281. }
  282. })
  283. .catch((err) => {
  284. console.error(err);
  285. });
  286. }
  287. },
  288. save(look) {
  289. this.updateWork(look == 4 ? look : this.look)
  290. },
  291. publish() {
  292. this.updateWork(3)
  293. },
  294. },
  295. mounted () {
  296. this.getData();
  297. },
  298. }
  299. </script>
  300. <style scoped>
  301. .pb_content {
  302. height: 100% !important;
  303. /* margin: 0 20px 0 20px; */
  304. }
  305. .pb_content_body {
  306. width: 100% !important;
  307. height: 100%;
  308. }
  309. .right {
  310. height: 100%;
  311. width: 100%;
  312. display: flex;
  313. overflow: hidden;
  314. flex-direction: column;
  315. }
  316. .basic_box {
  317. margin: 0 auto;
  318. position: relative;
  319. padding: 0 20px 0 20px;
  320. }
  321. .courseTop {
  322. display: flex;
  323. flex-direction: row;
  324. justify-content: space-between;
  325. align-items: center;
  326. width: calc(100% - 40px);
  327. margin: 0 auto;
  328. padding: 10px 0;
  329. }
  330. .stepsNav {
  331. display: flex;
  332. flex-direction: row;
  333. justify-content: flex-start;
  334. align-items: center;
  335. }
  336. .step_box {
  337. width: calc(100% - 40px);
  338. margin: 0 auto;
  339. height: calc(100% - 38px);
  340. }
  341. </style>