manualCreated.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. <template>
  2. <div class="mc_box">
  3. <div class="mc_addBox">
  4. <div class="mc_addBox_add">
  5. <div class="title">请添加题目类型与数量</div>
  6. <div class="select">
  7. <el-select v-model="topicType" placeholder="题目类型" clearable class="e-select">
  8. <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
  9. </el-option>
  10. </el-select>
  11. <el-input v-model="number" placeholder="请输入题目数量" size="normal" clearable @change="numberPan"
  12. class="e-input"></el-input>
  13. <img src="@/assets/icon/new/addStage.png" class="e-img" @click="addCheck" />
  14. </div>
  15. </div>
  16. <div class="mc_addBox_add">
  17. <div class="title">请添加题目类型与数量</div>
  18. <div class="btnBox">
  19. <el-button type="primary" size="mini" v-for="item in buttonOptions" :key="item.type" class="e-button"
  20. @click="addQtype(item.type)">{{ item.name }}</el-button>
  21. </div>
  22. </div>
  23. </div>
  24. <div class="mc_checkBox">
  25. <checkOrder :checkC.sync="checkC" :checkJson="checkJson" @changeJson="changeJson"></checkOrder>
  26. <div class="e_btn">
  27. <el-button type="primary" size="mini" @click="nextSteps()">下一步</el-button>
  28. </div>
  29. </div>
  30. </div>
  31. </template>
  32. <script>
  33. import checkOrder from '../components/checkOrder.vue';
  34. import minxinVue from '../minxins/minxin';
  35. export default {
  36. mixins:[minxinVue],
  37. components: {
  38. checkOrder,
  39. },
  40. props: {
  41. manualJson: {
  42. type: Array
  43. }
  44. },
  45. data() {
  46. return {
  47. topicType: "",
  48. number: "",
  49. checkJson: [
  50. // {
  51. // ttype: 1, //题目分类 1普通题目 2分组 3分页
  52. // type: 1, //题型分类 1选择题, 2问答题 3填空题 4添加文档
  53. // array:[] //题目
  54. // }
  55. ],
  56. checkC: "",
  57. };
  58. },
  59. watch: {
  60. // checkJson :{
  61. // handler: function (newVal, oldVal) {
  62. // this.$emit("update:manualJson", newVal)
  63. // },
  64. // deep: true,
  65. // }
  66. },
  67. methods: {
  68. numberPan() {
  69. if (/[^\d]/.test(this.number)) {
  70. this.$message.error("请填写数字");
  71. this.number = "";
  72. }
  73. },
  74. changeJson(json) {
  75. this.checkJson = json;
  76. this.$emit("update:cJson", json);
  77. },
  78. addCheck() {
  79. if (!this.topicType) {
  80. this.$message.error("请选择题目类型");
  81. return;
  82. }
  83. if (!this.number) {
  84. this.$message.error("请填写题目数量");
  85. return;
  86. }
  87. let type = 1;
  88. if (this.checkJson.length > 0) {
  89. for (var i = 0; i < this.checkJson.length; i++) {
  90. if (this.checkJson[i].ttype == 2) {
  91. type = 2;
  92. } else if (this.checkJson[i].ttype == 3) {
  93. type = 3;
  94. }
  95. }
  96. }
  97. if (this.checkC) {
  98. let _check = this.checkC.replace('x', '').split("-")
  99. let _json = this.checkJson[_check[0]]
  100. let json = {
  101. ttype: 1,
  102. type: this.topicType
  103. }
  104. if (_json.array) {
  105. if (type == 3 && _check.length == 2) {
  106. if (this.checkJson[_check[0]].array[_check[1]].array) {
  107. for (var i = 0; i < this.number; i++) {
  108. this.checkJson[_check[0]].array[_check[1]].array.push(json)
  109. }
  110. } else {
  111. for (var i = 0; i < this.number; i++) {
  112. this.checkJson[_check[0]].array.splice((_check[1]) + 1, 0, json)
  113. }
  114. }
  115. } else if (type == 3 && _check.length == 3) {
  116. for (var i = 0; i < this.number; i++) {
  117. this.checkJson[_check[0]].array[_check[1]].array.splice((_check[2]) + 1, 0, json)
  118. }
  119. } else if (type == 2 && _check.length == 2) {
  120. for (var i = 0; i < this.number; i++) {
  121. this.checkJson[_check[0]].array.splice((_check[1]) + 1, 0, json)
  122. }
  123. } else if (type == 2 && _check.length == 1) {
  124. for (var i = 0; i < this.number; i++) {
  125. this.checkJson[_check[0]].array.push(json)
  126. }
  127. } else if (type == 3 && _check.length == 1) {
  128. if(this.checkJson[_check[0]].array[0] && this.checkJson[_check[0]].array[0].array){
  129. for (var i = 0; i < this.number; i++) {
  130. this.checkJson[_check[0]].array[0].array.push(json)
  131. }
  132. }else{
  133. for (var i = 0; i < this.number; i++) {
  134. this.checkJson[_check[0]].array.push(json)
  135. }
  136. }
  137. }
  138. } else {
  139. for (var i = 0; i < this.number; i++) {
  140. this.checkJson.splice(parseInt(_check[0]) + 1, 0, json);
  141. }
  142. }
  143. } else {
  144. if (type == 1) {
  145. for (var i = 0; i < this.number; i++) {
  146. this.checkJson.push({
  147. ttype: 1,
  148. type: this.topicType
  149. });
  150. }
  151. } else if (type == 3 || type == 2) {
  152. this.$message.error("请选中分页或者分组添加题目");
  153. return;
  154. }
  155. }
  156. this.topicType = "";
  157. this.number = "";
  158. this.$emit("update:manualJson", this.checkJson);
  159. },
  160. addQtype(type) {
  161. if (type == 1) {
  162. let type = 1;
  163. if (this.checkJson.length > 0) {
  164. for (var i = 0; i < this.checkJson.length; i++) {
  165. if (this.checkJson[i].ttype == 1) {
  166. type = 2;
  167. } else if (this.checkJson[i].ttype == 3) {
  168. type = 3;
  169. }
  170. }
  171. }
  172. let json = {
  173. ttype: 2,
  174. array: [],
  175. isopen: true
  176. }
  177. if (type == 1) {
  178. if (this.checkC) {
  179. let _check = this.checkC.replace('x', '').split("-")
  180. this.checkJson.splice(parseInt(_check[0]) + 1, 0, json);
  181. } else {
  182. this.checkJson.push(json);
  183. }
  184. } else if (type == 2) {
  185. this.checkJson = [
  186. {
  187. ttype: 2,
  188. array: this.depthCopy(this.checkJson),
  189. isopen: true
  190. }
  191. ];
  192. } else if (type == 3) {
  193. if (this.checkC) {
  194. let _check = this.checkC.replace('x', '').split("-")
  195. if (_check.length > 1 && this.checkJson[_check[0]].array[0] && this.checkJson[_check[0]].array[0].array) {
  196. this.checkJson[_check[0]].array.splice(parseInt(_check[1]) + 1, 0, json);
  197. } else if (this.checkJson[_check[0]].array[0] && !this.checkJson[_check[0]].array[0].array) {
  198. this.checkJson[_check[0]].array = [
  199. {
  200. ttype: 2,
  201. array: this.depthCopy(this.checkJson[_check[0]].array),
  202. isopen: true
  203. }
  204. ]
  205. } else {
  206. this.checkJson[_check[0]].array.push(json);
  207. }
  208. } else {
  209. this.$message.error("请选中分页添加分组");
  210. return;
  211. }
  212. }
  213. } else if (type == 2) {
  214. let type = 1;
  215. if (this.checkJson.length > 0) {
  216. for (var i = 0; i < this.checkJson.length; i++) {
  217. if (this.checkJson[i].ttype == 1 || this.checkJson[i].ttype == 2) {
  218. type = 2;
  219. }
  220. }
  221. }
  222. if (type == 1) {
  223. let json = {
  224. ttype: 3,
  225. array: [],
  226. isopen: true
  227. }
  228. if (this.checkC) {
  229. let _check = this.checkC.replace('x', '').split("-")
  230. this.checkJson.splice(parseInt(_check[0]) + 1, 0, json);
  231. } else {
  232. this.checkJson.push(json);
  233. }
  234. } else {
  235. this.checkJson = [
  236. {
  237. ttype: 3,
  238. array: this.depthCopy(this.checkJson),
  239. isopen: true
  240. }
  241. ];
  242. }
  243. }
  244. this.$emit("update:manualJson", this.checkJson);
  245. },
  246. depthCopy(s) {
  247. return JSON.parse(JSON.stringify(s));
  248. },
  249. nextSteps(){
  250. this.$emit("nextSteps")
  251. }
  252. },
  253. created() {
  254. this.checkJson = this.depthCopy(this.manualJson);
  255. }
  256. };
  257. </script>
  258. <style scoped>
  259. .mc_box {
  260. width: 90%;
  261. margin: 10px auto;
  262. display: flex;
  263. }
  264. .mc_addBox {
  265. width: 400px;
  266. border: 1px solid #898989;
  267. border-radius: 8px;
  268. padding: 20px 20px;
  269. box-sizing: border-box;
  270. height: 350px;
  271. }
  272. .mc_addBox_add {}
  273. .mc_addBox_add+.mc_addBox_add {
  274. margin-top: 10px;
  275. }
  276. .mc_addBox_add .title {
  277. margin-bottom: 10px;
  278. }
  279. .mc_addBox_add .select {
  280. display: flex;
  281. align-items: center;
  282. }
  283. .mc_addBox_add .btnBox {}
  284. .mc_addBox_add .select .e-select {}
  285. .mc_addBox_add .select .e-input {
  286. margin-left: 10px;
  287. }
  288. .mc_addBox_add .select .e-img {
  289. cursor: pointer;
  290. width: 20px;
  291. margin-left: 10px;
  292. }
  293. .mc_addBox_add .btnBox .e-button {}
  294. .mc_checkBox {
  295. width: calc(100% - 420px);
  296. margin-left: 20px;
  297. border: 1px solid #898989;
  298. border-radius: 8px;
  299. padding: 20px;
  300. box-sizing: border-box;
  301. display: flex;
  302. flex-direction: column;
  303. }
  304. .e_btn{
  305. width: 100%;
  306. margin-top: auto;
  307. display: flex;
  308. justify-content: flex-end;
  309. }
  310. </style>