123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748 |
- <template>
- <div class="pb_content" style="background: #F0F2F5;" v-loading="loading || isloading">
- <div class="pb_content_body" style="position: relative; margin: 0">
- <div class="right">
- <div class="courseTop" :style="`justify-content: ${isN==1?'flex-end':'space-between'};`">
- <div class="stepsNav" v-if="isN !=1">
- <el-breadcrumb separator-class="el-icon-arrow-right">
- <el-breadcrumb-item :to="{
- path:
- '/testPerson?userid=' +
- userid +
- '&oid=' +
- oid +
- '&org=' +
- org +
- '&role=' +
- role,
- }" v-if="type == 3">个人中心</el-breadcrumb-item>
- <el-breadcrumb-item :to="{
- path:
- '/testStudent?userid=' +
- userid +
- '&oid=' +
- oid +
- '&org=' +
- org +
- '&role=' +
- role +
- '&isN=' +
- isN +
- '&tcid=' +
- tcid ,
- }" v-else>表单中心</el-breadcrumb-item>
- <el-breadcrumb-item>
- <span style="color: rgb(15, 126, 255)">{{ title }}</span>
- </el-breadcrumb-item>
- </el-breadcrumb>
- </div>
- <div class="r_pub_button_retrun" @click="retrunCourse">返回</div>
- </div>
- <div class="step_box">
- <div class="edit_top" :style="isN==1?'border-bottom:none;justify-content:space-between;padding:10px':''">
- <div v-if="isN==1" class="edit_title" :style=" isN==1? 'margin-left : 12px' : ''">提交记录</div>
- <div class="op_btn">
- <el-button type="primary" :style=" isN==1? 'padding: 5px 10px;' : ''" size="small" @click="autoFill" v-if="(showAutoFillBtn && isN!=1)">智能填写</el-button>
- <el-button type="primary" :style=" isN==1? 'padding: 5px 10px;' : ''" size="small" @click="refresh" v-if="isReset">刷新</el-button>
- <el-button :type="isN!=1?'primary':'info'" :style=" isN==1? 'padding: 5px 10px;' : ''" size="small" @click="reset">重置</el-button>
- <el-button type="primary" :style=" isN==1? 'padding: 5px 10px;' : ''" size="small" @click="save" v-if="(type != 3 && isN!=1)">保存</el-button>
- <el-button type="primary" :style=" isN==1? 'padding: 5px 10px;' : ''" size="small" @click="publish">提交</el-button>
- </div>
- </div>
- <topicVue :cJson.sync="cJson" :title="title" :brief="brief" ref="topicVue" v-if="!loading"
- @getTestWorkByCid="getTestWorkByCid" @publish2="publish2" :tid="tid" :gcourseid="gcourseid"></topicVue>
- </div>
- </div>
- </div>
- </div>
- </template>
- <script>
- import topicVue from './component/topic.vue';
- export default {
- components: {
- topicVue
- },
- data() {
- return {
- userid: this.$route.query.userid,
- oid: this.$route.query.oid,
- org: this.$route.query.org,
- role: this.$route.query.role,
- cid: this.$route.query.cid,
- tid: this.$route.query.tid,
- type: this.$route.query.type,
- updateType: this.$route.query.type,
- isN: this.$route.query.isN,
- tcid: this.$route.query.tcid,
- steps: 1,
- title: "",
- brief: "",
- testType: [],
- see: false,
- cJson: [],
- cJson2: [],
- loading: false,
- look: "",
- isReset: false,
- isloading: false,
- courseid: '',
- gcourseid: this.$route.query.courseid
- }
- },
- computed:{
- showAutoFillBtn(){
- let _json = this.JSONSetting(this.cJson)
- return _json.filter(i=>i.type==3).length>0;
- }
- },
- methods: {
- retrunCourse() {
- this
- .$confirm("是否确认返回?", "提示", {
- confirmButtonText: "确认",
- cancelButtonText: "取消",
- distinguishCancelAndClose: true,
- type: "warning",
- })
- .then(() => {
- if (this.type == 3) {
- this.goTo(
- "/testPerson?userid=" +
- this.userid +
- "&oid=" +
- this.oid +
- "&org=" +
- this.org +
- "&role=" +
- this.role
- );
- } else {
- this.goTo(
- "/testStudent?userid=" +
- this.userid +
- "&oid=" +
- this.oid +
- "&org=" +
- this.org +
- "&role=" +
- this.role +
- "&isN=" +
- this.isN +
- "&tcid=" +
- this.tcid
- );
- }
- })
- .catch((v) => {
- });
- },
- goTo(path) {
- this.$router.push(path);
- },
- reset() {
- this
- .$confirm("是否将已经填写的内容重置?", "提示", {
- confirmButtonText: "确定",
- cancelButtonText: "取消",
- type: "warning",
- })
- .then(() => {
- if(this.tid){
- this.deleteTest(this.tid)
- }else{
- if(this.courseid){
- this.cJson = this.setCourseid(JSON.parse(JSON.stringify(this.cJson2)));
- }else{
- this.cJson = JSON.parse(JSON.stringify(this.cJson2));
- }
- this.loading = true
- this.isReset = false
- setTimeout(() => {
- this.loading = false
- }, 0);
- this.$forceUpdate()
- }
- })
- .catch(() => {
- });
- },
- refresh() {
- this
- .$confirm("是否将现在的题目刷新成最新的题目", "提示", {
- confirmButtonText: "确定",
- cancelButtonText: "取消",
- type: "warning",
- })
- .then(() => {
- if(this.tid){
- this.deleteTest(this.tid)
- }else{
- if(this.courseid){
- this.cJson = this.setCourseid(JSON.parse(JSON.stringify(this.cJson2)));
- }else{
- this.cJson = JSON.parse(JSON.stringify(this.cJson2));
- }
- this.loading = true
- this.isReset = false
- setTimeout(() => {
- this.loading = false
- }, 0);
- this.$forceUpdate()
- }
- })
- .catch(() => {
- });
- },
- getTestWorks() {
- let params = {
- cid: this.cid,
- uid: this.userid,
- };
- this.ajax
- .get(this.$store.state.api + "getTestWorks", params)
- .then((res) => {
- // this.cJson = JSON.parse(res.data[0][0].chapters);
- if (res.data[2].length) {
- this.cJson = JSON.parse(res.data[2][0].courseJson)
- let cJson = this.setJSON(JSON.parse(JSON.stringify(this.cJson)))
- let cJson2 = this.setJSON(this.setJson2(JSON.parse(JSON.stringify(this.cJson2))))
- if (JSON.stringify(cJson) != JSON.stringify(cJson2)) {
- this.isReset = true
- }
- }
- this.$forceUpdate()
- this.loading = false
- })
- .catch((err) => {
- this.loading = false
- console.error(err);
- });
- },
- getTestWorks2() {
- let params = {
- cid: this.cid,
- tid: this.tid,
- };
- this.ajax
- .get(this.$store.state.api + "getTestWorks2", params)
- .then((res) => {
- // this.cJson = JSON.parse(res.data[0][0].chapters);
- if (res.data[2].length) {
- this.cJson = JSON.parse(res.data[2][0].courseJson)
- let cJson = this.setJSON(JSON.parse(JSON.stringify(this.cJson)))
- let cJson2 = this.setJSON(this.setJson2(JSON.parse(JSON.stringify(this.cJson2))))
- if (JSON.stringify(cJson) != JSON.stringify(cJson2)) {
- this.isReset = true
- }
- }
- this.$forceUpdate()
- this.loading = false
- })
- .catch((err) => {
- this.loading = false
- console.error(err);
- });
- },
- getTestWorkByCid(courseid) {
- this.isloading = true
- this.courseid = courseid
- let params = {
- cid: this.cid,
- uid: this.userid,
- };
- let _courseid = courseid
- this.ajax
- .get(this.$store.state.api + "selectTestWorksCid", params)
- .then((res) => {
- if (res.data[0].length) {
- console.log(res.data[0]);
- let rData = res.data[0]
- this.tid = ''
- aa: for (var i = 0; i < rData.length; i++) {
- let rDataJson = this.JSONSetting(JSON.parse(rData[i].courseJson))
- let _json = JSON.parse(rData[i].courseJson)
- for (var j = 0; j < rDataJson.length; j++) {
- let _param = rDataJson[j]
- if (_param.type == 6 && _param.json.answer2 && _param.json.answer2 == _courseid) {
- console.log(_json);
- this.cJson = _json
- let cJson = this.setJSON(JSON.parse(JSON.stringify(this.cJson)))
- let cJson2 = this.setJSON(this.setJson2(JSON.parse(JSON.stringify(this.cJson2))))
- if (JSON.stringify(cJson) != JSON.stringify(cJson2)) {
- this.isReset = true
- }
- this.tid = rData[i].id
- this.$forceUpdate()
- break aa;
- }
- }
- }
- if (!this.tid) {
- this.cJson = this.setJSON(this.setCourseid(JSON.parse(JSON.stringify(this.cJson2))))
- }
- }else{
- this.tid = ''
- this.cJson = this.setJSON(this.setCourseid(JSON.parse(JSON.stringify(this.cJson2))))
- }
- this.$forceUpdate()
- this.isloading = false
- })
- .catch((err) => {
- this.isloading = false
- console.error(err);
- });
- },
- JSONSetting(json) {
- let _json = json
- let array = []
- _json.filter((item) => {
- if (item.array) {
- item.array = item.array.filter((item2) => {
- if (item2.ttype == 1 && item2.json) {
- array.push(item2)
- }
- if (item2.array) {
- item2.array = item2.array.filter((item3) => {
- if (item3.ttype == 1 && item3.json) {
- array.push(item3)
- }
- return item3;
- });
- }
- return item2;
- });
- }
- if (item.ttype == 1 && item.json) {
- array.push(item)
- }
- console.log(item.array);
- return item;
- });
- console.log(array);
- return array;
- },
- setJSON(json) {
- return json.filter((item) => {
- if (item.array) {
- item.array = item.array.filter((item2) => {
- if (item2.ttype == 1 && item2.json) {
- delete item2.json.answer2
- delete item2.json.score2
- delete item2.json.file
- }
- if (item2.array) {
- item2.array = item2.array.filter((item3) => {
- if (item3.ttype == 1 && item3.json) {
- delete item3.json.answer2
- delete item3.json.score2
- delete item3.json.file
- }
- return item3;
- });
- }
- return item2;
- });
- } else if (item.ttype == 1 && item.json) {
- delete item.json.answer2
- delete item.json.score2
- delete item.json.file
- }
- return item
- console.log(item.array);
- });
- },
- setJson2(json) {
- let _json = json;
- // this.type = _json[0].ttype;
- let checkArray = _json.filter((item) => {
- if (item.array) {
- item.array = item.array.filter((item2) => {
- if (item2.ttype == 1 && item2.json && !item2.json.answer2) {
- item2.json.answer2 = [];
- }
- if (item2.array) {
- item2.array = item2.array.filter((item3) => {
- if (item3.ttype == 1 && item3.json && !item3.json.answer2) {
- item3.json.answer2 = [];
- }
- return item3;
- });
- }
- return (
- (item2.ttype != 1 && item2.array.length > 0) || item2.ttype == 1
- );
- });
- }
- if (item.ttype == 1 && item.json && !item.json.answer2) {
- item.json.answer2 = [];
- }
- console.log(item.array);
- return (item.ttype != 1 && item.array.length > 0) || item.ttype == 1;
- });
- console.log(checkArray);
- return checkArray;
- },
- setCourseid(json) {
- let _json = json;
- // this.type = _json[0].ttype;
- let checkArray = _json.filter((item) => {
- if (item.array) {
- item.array = item.array.filter((item2) => {
- if (item2.ttype == 1 && item2.json && !item2.json.answer2 && item2.type != 6 && item2.type != 7 && item2.type != 8) {
- item2.json.answer2 = [];
- }else if(item2.type == 6){
- item2.json.answer2 = this.courseid ? this.courseid : '';
- }else if(item2.type == 7 || item2.type == 8){
- item2.json.answer2 = '';
- }
- if (item2.array) {
- item2.array = item2.array.filter((item3) => {
- if (item3.ttype == 1 && item3.json && !item3.json.answer2 && item3.type != 6 && item3.type != 7 && item3.type != 8) {
- item3.json.answer2 = [];
- }else if(item3.type == 6){
- item3.json.answer2 = this.courseid ? this.courseid : '';
- }else if(item3.type == 7 || item3.type == 8){
- item3.json.answer2 = '';
- }
- return item3;
- });
- }
- return (
- (item2.ttype != 1 && item2.array.length > 0) || item2.ttype == 1
- );
- });
- }
- if (item.ttype == 1 && item.json && !item.json.answer2 && item.type != 6 && item.type != 6 && item.type != 7 && item.type != 8) {
- item.json.answer2 = [];
- }else if(item.type == 6){
- item.json.answer2 = this.courseid ? this.courseid : '';
- }else if(item.type == 7 || item.type == 8){
- item.json.answer2 = '';
- }
- console.log(item.array);
- return (item.ttype != 1 && item.array.length > 0) || item.ttype == 1;
- });
- console.log(checkArray);
- return checkArray;
- },
- getData() {
- this.loading = true
- let params = {
- cid: this.cid,
- };
- this.ajax
- .get(this.$store.state.api + "getTestCourseDetail", params)
- .then((res) => {
- this.cJson = JSON.parse(res.data[0][0].chapters);
- this.cJson2 = JSON.parse(res.data[0][0].chapters);
- this.title = res.data[0][0].title;
- this.brief = res.data[0][0].brief;
- this.see = res.data[0][0].open == 1 ? true : false;
- this.testType = [];
- for (var i = 0; i < res.data[1].length; i++) {
- this.testType.push(res.data[1][i].typeid);
- }
- console.log(this.testType);
- this.look = res.data[0][0].look
- if(this.isN!=1){
- if (this.type == 3) {
- this.getTestWorks2()
- } else {
- this.getTestWorks()
- }
- }else{
- this.loading = false;
- this.isReset = true;
- }
- this.$forceUpdate();
- })
- .catch((err) => {
- this.loading = false
- console.error(err);
- });
- },
- save() {
- let cjson = this.$refs['topicVue'].checkArray
- console.log(cjson);
- let params = [
- {
- uid: this.userid,
- cid: this.cid,
- cjson: JSON.stringify(cjson),
- type: '1',
- },
- ];
- this.ajax
- .post(this.$store.state.api + "addTestWorks", params)
- .then((res) => {
- this.$message.success('保存成功')
- this.goTo(
- "/testStudent?userid=" +
- this.userid +
- "&oid=" +
- this.oid +
- "&org=" +
- this.org +
- "&role=" +
- this.role +
- "&isN=" +
- this.isN +
- "&tcid=" +
- this.tcid
- );
- })
- .catch((err) => {
- this.$message.error("网络不佳");
- console.error(err);
- });
- },
- publish() {
- let cjson = this.$refs['topicVue'].checkArray
- console.log(cjson);
- let _uid = ''
- if(this.isN == 1){
- _uid = this.tcid
- }else {
- _uid = (this.tid) ? this.tid : this.userid
- }
- let params = [
- {
- uid: _uid,
- cid: this.cid,
- cjson: JSON.stringify(cjson),
- type: '2',
- },
- ];
- this.ajax
- .post(this.$store.state.api + ((this.tid) ? "addTestWorks2" : "addTestWorks"), params)
- .then((res) => {
- this.$message.success('提交成功')
- if (this.type == 3) {
- this.goTo(
- "/testPerson?userid=" +
- this.userid +
- "&oid=" +
- this.oid +
- "&org=" +
- this.org +
- "&role=" +
- this.role
- );
- } else {
- this.goTo(
- "/testStudent?userid=" +
- this.userid +
- "&oid=" +
- this.oid +
- "&org=" +
- this.org +
- "&role=" +
- this.role +
- "&isN=" +
- this.isN +
- "&tcid=" +
- this.tcid
- );
- }
- })
- .catch((err) => {
- this.$message.error("网络不佳");
- console.error(err);
- });
- },
- publish2() {
- this.isloading = true
- let cjson = this.$refs['topicVue'].checkArray
- let _cjson = this.JSONSetting(JSON.parse(JSON.stringify(cjson)));
- let pan = this.panJSON(_cjson)
- if(!pan){
- setTimeout(() => {
- this.isloading = false
- }, 500);
- return
- }
- console.log(cjson);
- let params = [
- {
- uid: (this.tid) ? this.tid : this.userid,
- cid: this.cid,
- cjson: JSON.stringify(cjson),
- type: '2',
- },
- ];
- this.ajax
- .post(this.$store.state.api + ((this.tid) ? "addTestWorks2" : "addTestWorks"), params)
- .then((res) => {
- this.$message.success('保存成功')
- setTimeout(() => {
- this.isloading = false
- }, 500);
- })
- .catch((err) => {
- this.$message.error("网络不佳");
- this.isloading = false
- console.error(err);
- });
- },
- panJSON(array){
- var pan = 0
- for(var i = 0; i < array.length; i++){
- if(array[i].type != 6){
- let param = array[i].json
- if(array[i].type == 5 && param.file && param.file.length > 0){
- pan++
- }else if(param.answer2.length || typeof(param.answer2) == 'number'){
- pan++
- }
- }
- }
- if(pan > 0){
- return true
- }else {
- return false
- }
- },
- deleteTest(tid) {
- let _this = this;
- let params = [
- {
- tid: tid
- }
- ];
- _this.ajax
- .post(_this.$store.state.api + "deleteTestCourseWorks", params)
- .then(res => {
- this.getTestWorkByCid(this.courseid)
- })
- .catch(err => {
- console.error(err);
- });
- },
- autoFill(){
- this
- .$confirm("这将覆盖原有的内容,是否继续?", "提示", {
- confirmButtonText: "确定",
- cancelButtonText: "取消",
- type: "warning",
- })
- .then(() => {
- console.log(this.$refs['topicVue'])
- this.$refs['topicVue'].autoFillGapV();
- })
- .catch(() => {
- });
- }
- },
- mounted() {
- this.getData();
- },
- }
- </script>
- <style scoped>
- .pb_content {
- height: 100% !important;
- /* margin: 0 20px 0 20px; */
- }
- .pb_content_body {
- width: 100% !important;
- height: 100%;
- }
- .right {
- height: 100%;
- width: 100%;
- display: flex;
- overflow: hidden;
- flex-direction: column;
- }
- .basic_box {
- margin: 0 auto;
- position: relative;
- padding: 0 20px 0 20px;
- }
- .courseTop {
- display: flex;
- flex-direction: row;
- justify-content: space-between;
- align-items: center;
- width: calc(100% - 40px);
- margin: 0 auto;
- padding: 10px 0;
- }
- .stepsNav {
- display: flex;
- flex-direction: row;
- justify-content: flex-start;
- align-items: center;
- }
- .step_box {
- width: calc(100%);
- margin: 0 auto;
- height: calc(100% - 38px);
- }
- .edit_top {
- height: 50px;
- background: #fff;
- display: flex;
- align-items: center;
- justify-content: flex-end;
- position: relative;
- /* padding: 0 30px; */
- padding-right: 10px;
- border-top: 2px solid #eee;
- border-bottom: 2px solid #eee;
- width: 95%;
- margin: 0 auto;
- box-sizing: border-box;
- }
- .edit_title{
- font-size: 22px;
- margin-left: 30px;
- position: relative;
- }
- .edit_title::after{
- content: "";
- width: 5px;
- height: 100%;
- background-color: #078DFF;
- border-radius: 2px;
- position: absolute;
- left: -10px;
- top: 0;
- }
- </style>
|