index.vue 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138
  1. <style lang="less" scoped>
  2. .add_assess {
  3. h5 {
  4. padding: 30px 35px 0 35px;
  5. margin-bottom: 20px;
  6. font-size: 14px;
  7. span {
  8. color: #ff545b;
  9. margin-right: 3px;
  10. }
  11. }
  12. .table_map {
  13. border-bottom: 10px solid #dee2ea;
  14. .table_top_box {
  15. display: flex;
  16. align-items: center;
  17. justify-content: space-between;
  18. padding: 0 37px;
  19. .table_top_box_left {
  20. display: flex;
  21. flex-wrap: wrap;
  22. /deep/.el-input--mini .el-input__inner {
  23. width: 200px;
  24. }
  25. .num_box {
  26. margin-left: 50px;
  27. /deep/ .el-input__inner {
  28. width: 40px;
  29. text-align: center;
  30. }
  31. .num {
  32. display: flex;
  33. /deep/.el-form-item__error {
  34. width: 100px;
  35. margin-left: -20px;
  36. }
  37. }
  38. }
  39. }
  40. }
  41. .move_btn {
  42. font-size: 14px;
  43. margin-left: 10px;
  44. display: flex;
  45. div {
  46. width: 12px;
  47. height: 16px;
  48. margin-right: 8px;
  49. img {
  50. width: 100%;
  51. height: 100%;
  52. cursor: pointer;
  53. }
  54. }
  55. }
  56. }
  57. /deep/ .el-form-item--mini.el-form-item,
  58. .el-form-item--small.el-form-item {
  59. margin-bottom: 0;
  60. }
  61. .hint_msg {
  62. font-size: 12px;
  63. color: red;
  64. margin-top: 14px;
  65. }
  66. .change_table_btns {
  67. width: 100%;
  68. margin-top: 20px;
  69. display: flex;
  70. justify-content: center;
  71. padding: 10px;
  72. box-sizing: border-box;
  73. border-top: 10px solid #dee2ea;
  74. div {
  75. width: 80px;
  76. height: 30px;
  77. line-height: 30px;
  78. border-radius: 2px;
  79. border: 1px solid #21cbc7;
  80. color: #21cbc7;
  81. font-size: 14px;
  82. padding: 0 5px;
  83. margin: 0 30px;
  84. cursor: pointer;
  85. &:nth-child(1) {
  86. &:hover {
  87. background: rgba(97, 218, 215, 0.1);
  88. }
  89. }
  90. &:nth-child(2) {
  91. border-color: #ff5b5b;
  92. color: #ff5b5b;
  93. &:hover {
  94. background: rgba(255, 91, 91, 0.1);
  95. }
  96. }
  97. }
  98. }
  99. .rich_text {
  100. padding: 10px 37px;
  101. }
  102. }
  103. .rich_text {
  104. }
  105. .quill-editor.ql-editor {
  106. padding-left: 0 !important;
  107. }
  108. /**富文本编辑器样式修改***/
  109. .ql-snow .ql-picker.ql-size .ql-picker-label::before,
  110. .ql-snow .ql-picker.ql-size .ql-picker-item::before,
  111. .ql-snow .ql-picker.ql-header .ql-picker-label::before,
  112. it .ql-editor,
  113. .quill-editor {
  114. padding-top: 0px !important;
  115. margin-top: -8px;
  116. min-height: 48px;
  117. p {
  118. padding-top: 8px;
  119. }
  120. }
  121. .ql-editor.ql-blank::before {
  122. padding-top: 0px;
  123. }
  124. .btns {
  125. margin-top: 20px;
  126. }
  127. /deep/ .el-input--mini {
  128. font-size: 14px;
  129. }
  130. /deep/ .el-form-item.is-success .el-input__inner,
  131. .el-form-item.is-success .el-textarea__inner {
  132. border-color: #c9c9c9 !important;
  133. }
  134. /deep/ .el-form-item.is-success .el-textarea__inner {
  135. border-color: #c9c9c9 !important;
  136. }
  137. /deep/ .el-form-item.is-success .el-textarea__inner {
  138. border-color: #c9c9c9 !important;
  139. }
  140. </style>
  141. <template>
  142. <div class="add_assess">
  143. <el-form
  144. size="mini"
  145. :model="scaleData"
  146. label-position="left"
  147. ref="scaleFormRef"
  148. >
  149. <div
  150. class="table_map"
  151. v-for="(table, tableIndex) in scaleData.klScaleParent"
  152. :key="tableIndex"
  153. >
  154. <h5><span>*</span>量表内容:</h5>
  155. <div class="table_top_box">
  156. <div class="table_top_box_left">
  157. <el-form-item
  158. label="标题:"
  159. label-width="70px"
  160. :prop="`klScaleParent[${tableIndex}].content`"
  161. :rules="rules.title"
  162. >
  163. <el-input
  164. :ref="`klScaleParent[${tableIndex}].content`"
  165. :id="`klScaleParent[${tableIndex}].content`"
  166. maxlength="20"
  167. v-model.trim="table.content"
  168. />
  169. </el-form-item>
  170. <div style="margin: 0 20px">
  171. <el-form-item label="内容类型:" label-width="100px">
  172. <el-select
  173. v-model="table.textType"
  174. placeholder="请选择"
  175. @change="initializationTableData($event, tableIndex)"
  176. >
  177. <el-option label="问题选项" :value="11"> </el-option>
  178. <el-option label="概述文本" :value="12"> </el-option>
  179. </el-select>
  180. </el-form-item>
  181. <div class="hint_msg">
  182. 注:内容类型修改后已填的所在标题下的内容将会清空
  183. </div>
  184. </div>
  185. <div v-if="table.textType === 11">
  186. <el-form-item label="结果类型:" label-width="100px">
  187. <el-radio-group
  188. v-model="table.resultType"
  189. @change="initializationTableData($event, tableIndex)"
  190. >
  191. <el-radio :label="2">直接结果</el-radio>
  192. <el-radio :label="1">计分结果</el-radio>
  193. </el-radio-group>
  194. </el-form-item>
  195. <div class="hint_msg">
  196. 注:结果类型修改后已填的所在标题下的内容将会清空
  197. </div>
  198. </div>
  199. <div
  200. class="num_box"
  201. v-if="table.resultType === 1 && table.textType === 11"
  202. >
  203. <div class="num">
  204. <el-form-item
  205. label="系数:"
  206. label-width="70px"
  207. :prop="`klScaleParent[${tableIndex}].factor`"
  208. :ref="`klScaleParent[${tableIndex}].factor`"
  209. :rules="rules.tableFactor"
  210. >
  211. <el-input
  212. type="number"
  213. maxlength="6"
  214. v-model.number="table.factor"
  215. />
  216. </el-form-item>
  217. <el-form-item
  218. label="常数:"
  219. label-width="70px"
  220. style="margin-left: 10px"
  221. :prop="`klScaleParent[${tableIndex}].constant`"
  222. :rules="rules.tableConstant"
  223. >
  224. <el-input
  225. :ref="`klScaleParent[${tableIndex}].constant`"
  226. type="number"
  227. maxlength="6"
  228. v-model.number="table.constant"
  229. />
  230. </el-form-item>
  231. </div>
  232. <div class="hint_msg">
  233. 注:结果类型修改后已填的所在标题下的内容将会清空
  234. </div>
  235. </div>
  236. </div>
  237. <div class="move_btn" v-if="scaleData.klScaleParent.length > 1">
  238. <div
  239. @click="CHANGE_TABLE({ tableIndex, type: 'up' })"
  240. @mouseover="moveTopHover = true"
  241. @mouseout="moveTopHover = false"
  242. v-if="tableIndex"
  243. title="上移"
  244. >
  245. <img
  246. :src="
  247. moveTopHover
  248. ? require('@/images/icon_hover_top.png')
  249. : require('@/images/icon_default_top.png')
  250. "
  251. alt=""
  252. />
  253. </div>
  254. <div
  255. v-if="tableIndex !== scaleData.klScaleParent.length - 1"
  256. @click="CHANGE_TABLE({ tableIndex, type: 'down' })"
  257. @mouseover="moveBottomHover = true"
  258. @mouseout="moveBottomHover = false"
  259. title="下移"
  260. >
  261. <img
  262. :src="
  263. moveBottomHover
  264. ? require('@/images/icon_hover_down.png')
  265. : require('@/images/icon_default_down.png')
  266. "
  267. alt=""
  268. />
  269. </div>
  270. </div>
  271. </div>
  272. <ScaleTable
  273. v-if="table.textType === 11"
  274. :tableData="table.klScaleSaveGroup"
  275. :tableIndex="tableIndex"
  276. :tableResultType="table.resultType"
  277. @CHANGE_FORM_DATA="CHANGE_FORM_DATA"
  278. @CHANGE_TABLE_ROW="CHANGE_TABLE_ROW"
  279. @CHANGE_ISSUE_CONTENT="CHANGE_ISSUE_CONTENT"
  280. ref="ScaleTable"
  281. />
  282. <div class="rich_text" v-if="table.textType === 12">
  283. <el-form-item
  284. label="概述:"
  285. label-width="70px"
  286. :ref="`klScaleParent[${tableIndex}].klScaleSaveGroup[0].content`"
  287. :prop="`klScaleParent[${tableIndex}].klScaleSaveGroup[0].content`"
  288. :rules="rules.fwbContent"
  289. >
  290. <!-- klScaleParent[${tableIndex}].klScaleSaveGroup[${scope.$index}].content -->
  291. <quillEditor
  292. v-model="table.klScaleSaveGroup[0].content"
  293. :options="editorOption"
  294. class="ql-editor"
  295. ref="quillEditor"
  296. @change="onEditorChange($event)"
  297. ></quillEditor>
  298. </el-form-item>
  299. </div>
  300. <div class="change_table_btns">
  301. <div @click="CHANGE_TABLE({ tableIndex, type: 1 })">
  302. <i class="el-icon-plus"></i>
  303. 新增标题
  304. </div>
  305. <div
  306. v-if="scaleData.klScaleParent.length > 1"
  307. @click="CHANGE_TABLE({ tableIndex, type: -1 })"
  308. >
  309. <i class="el-icon-minus"></i>
  310. 删除标题
  311. </div>
  312. </div>
  313. </div>
  314. </el-form>
  315. <el-form
  316. size="mini"
  317. :model="scoreresults"
  318. label-position="left"
  319. ref="ScoreResultsRef"
  320. >
  321. <ScoreResultsTable
  322. ref="ScoreResultsTable"
  323. v-if="ScoreResultsShow"
  324. :list="scoreresults.scoreresultsdatas"
  325. @CHANEG_SCORE_RESULT="CHANEG_SCORE_RESULT"
  326. />
  327. </el-form>
  328. <!-- 暂时用的按钮 -->
  329. <!-- <button
  330. style="position: fixed; bottom: 20px; right: 20px; font-size: 16px"
  331. @click="assessCommitTest"
  332. >
  333. 暂时用的按钮
  334. </button> -->
  335. </div>
  336. </template>
  337. <script>
  338. import ScaleTable from "./scale-table.vue";
  339. import "quill/dist/quill.core.css";
  340. import "quill/dist/quill.snow.css";
  341. import "quill/dist/quill.bubble.css";
  342. import { quillEditor, Quill } from "vue-quill-editor";
  343. import config from "@api/config";
  344. import { container, ImageExtend, QuillWatch } from "quill-image-extend-module";
  345. Quill.register("modules/ImageExtend", ImageExtend);
  346. import ScoreResultsTable from "./ScoreResultsTable.vue";
  347. import rules from "./rules";
  348. const defaultDate = {
  349. groupId: new Date().valueOf().toString(),
  350. issueId: new Date().valueOf().toString() + "-" + new Date().valueOf(),
  351. two_constant: 0,
  352. two_content: "",
  353. two_factor: 1,
  354. two_orderNo: 0,
  355. two_remark: "",
  356. two_resultType: null,
  357. two_ruleCode: "",
  358. two_score: 0,
  359. two_selectType: 21,
  360. two_status: 0,
  361. two_textType: 21,
  362. content: "",
  363. orderNo: 0,
  364. pushInfo: "",
  365. remark: "",
  366. result: "",
  367. ruleCode: "",
  368. score: null,
  369. status: 1,
  370. textType: 31
  371. };
  372. const defaultTable = {
  373. constant: 0,
  374. content: "",
  375. factor: 1,
  376. klScaleSaveGroup: [
  377. {
  378. ...defaultDate
  379. }
  380. ],
  381. orderNo: 0,
  382. remark: "string",
  383. resultType: 2,
  384. ruleCode: "string",
  385. score: null,
  386. status: 1,
  387. textType: 11
  388. };
  389. export default {
  390. components: { ScaleTable, quillEditor, ScoreResultsTable },
  391. props: {
  392. childScaleData: {
  393. default: null
  394. }
  395. },
  396. data() {
  397. return {
  398. rules: rules,
  399. moveTopHover: false,
  400. moveBottomHover: false,
  401. scaleData: {
  402. conceptId: 0,
  403. klScaleParent: [
  404. // 表格层
  405. {
  406. constant: 0,
  407. content: "",
  408. factor: 1,
  409. klScaleSaveGroup: [
  410. // 问题层+结果层(包括分组)
  411. {
  412. groupId: 0,
  413. issueId: 0,
  414. two_constant: 0,
  415. two_content: "",
  416. two_factor: 1,
  417. two_orderNo: 0,
  418. two_remark: "",
  419. two_resultType: null,
  420. two_ruleCode: "",
  421. two_score: 0,
  422. two_selectType: 21,
  423. two_status: 1,
  424. two_textType: 21,
  425. content: "",
  426. orderNo: 0,
  427. pushInfo: "",
  428. remark: "",
  429. result: "",
  430. ruleCode: "",
  431. score: null,
  432. status: 1,
  433. textType: 31
  434. }
  435. ],
  436. orderNo: 0,
  437. remark: "string",
  438. resultType: 2,
  439. ruleCode: "string",
  440. score: "",
  441. status: 1,
  442. textType: 11
  443. }
  444. ],
  445. modifier: "0"
  446. },
  447. toolbars: [
  448. [
  449. ["bold", "underline", "strike"],
  450. [{ list: "ordered" }, { list: "bullet" }],
  451. [{ script: "sub" }, { script: "super" }],
  452. [{ color: [] }, { background: [] }],
  453. [{ align: [] }],
  454. ["image"]
  455. ]
  456. ],
  457. editorOption: {
  458. modules: {
  459. ImageExtend: {
  460. loading: true,
  461. name: "upfile",
  462. size: 1,
  463. sizeError: () => {
  464. this.$message({
  465. showClose: true,
  466. message: "请上传 1M 以内的图片!",
  467. type: "warning"
  468. });
  469. },
  470. action: config.urls.promptServer,
  471. response: (res) => {
  472. if (res.code == "0") {
  473. return config.imgHost + res.data.url;
  474. } else {
  475. this.$message({
  476. showClose: true,
  477. message: res.msg,
  478. type: "warning"
  479. });
  480. }
  481. }
  482. },
  483. toolbar: {
  484. container: container,
  485. handlers: {
  486. image: function () {
  487. QuillWatch.emit(this.quill.id);
  488. }
  489. }
  490. }
  491. }
  492. },
  493. toolbarMode: 0,
  494. scoreresults: {
  495. scoreresultsdatas: [
  496. // todo me: 最后处理数据记得将orderNo设不唯一的值
  497. {
  498. content: {
  499. max: null,
  500. min: null
  501. },
  502. orderNo: null,
  503. pushInfo: "",
  504. remark: null,
  505. result: "",
  506. ruleCode: null,
  507. score: null,
  508. status: 2,
  509. textType: 31
  510. }
  511. ]
  512. }
  513. };
  514. },
  515. methods: {
  516. getElementTop(element) {
  517. console.log('element',element);
  518. var actualTop = element.offsetTop;
  519. var current = element.parentNode;
  520. console.log("actualTop", actualTop);
  521. console.log("current", current.offsetTop);
  522. while (current !== null) {
  523. actualTop += current.offsetTop;
  524. current = current.parentNode;
  525. }
  526. return actualTop;
  527. },
  528. getDom(ref) {
  529. // console.log("???", this.getElementTop(document.getElementById(ref)));
  530. return this.getElementTop(document.getElementById(ref));
  531. },
  532. CHANGE_ISSUE_CONTENT(data) {
  533. const { value, tableIndex, rowIndex, name } = data;
  534. console.log(value, tableIndex, rowIndex, name);
  535. const thisIssueId =
  536. this.scaleData.klScaleParent[tableIndex].klScaleSaveGroup[rowIndex]
  537. .issueId;
  538. console.log(thisIssueId);
  539. this.scaleData.klScaleParent[tableIndex].klScaleSaveGroup.forEach(
  540. (item) => {
  541. if (item.issueId === thisIssueId) item[name] = value;
  542. }
  543. );
  544. },
  545. onEditorChange(e) {
  546. e.quill.deleteText(1000, 4);
  547. // e.quill.getLength()>1000
  548. },
  549. assessCommitTest() {
  550. console.dir(this.formtParams());
  551. },
  552. formtParams() {
  553. // console.log("this.scaleData.klScaleParent");
  554. // console.dir(this.scaleData.klScaleParent);
  555. // 提交数据的处理 start....
  556. // 1. 新建一个整体对象
  557. const params = {
  558. conceptId: 0,
  559. klScaleParent: [],
  560. modifier: "0"
  561. };
  562. // 2. 遍历数据
  563. this.scaleData.klScaleParent.forEach((table, tableIndex) => {
  564. if (table.textType === 11) {
  565. // 3. 将第一层数据格式顺序放进新对象(对应一个表格的数据)
  566. params.klScaleParent.push({
  567. ...table,
  568. klScaleSaveGroup: []
  569. });
  570. // 4. 建立一个新数组 用于后边赋值 params.klScaleParent[tableIndex].klScaleSaveGroup = groupArr;
  571. let groupArr = [];
  572. // 5. 遍历数据 添加组、问题、以及选项。
  573. table.klScaleSaveGroup.forEach((group, groupIndex) => {
  574. const groupFindIndex = groupArr.findIndex((item) => {
  575. return item.groupNum === group.groupId;
  576. });
  577. // 6. 查看数组中有没有同组的,如果没有同组的,直接push
  578. if (groupFindIndex === -1) {
  579. groupArr.push({
  580. groupNum: group.groupId,
  581. klScaleSub: [
  582. {
  583. issueId: group.issueId,
  584. constant: group.two_constant,
  585. content: group.two_content,
  586. factor: group.two_factor,
  587. orderNo: 0,
  588. remark: group.two_remark,
  589. resultType: group.two_resultType,
  590. ruleCode: group.two_ruleCode,
  591. score: group.two_score,
  592. selectType: group.two_selectType,
  593. status: group.two_status,
  594. textType: group.two_textType,
  595. klScaleDetail: [
  596. {
  597. content: group.content,
  598. orderNo: 0,
  599. pushInfo: group.pushInfo,
  600. remark: group.remark,
  601. result: group.result,
  602. ruleCode: group.ruleCode,
  603. score: group.score,
  604. status: group.status,
  605. textType: group.textType
  606. }
  607. ]
  608. }
  609. ]
  610. });
  611. } else {
  612. // 7. 查看数组中有没有同组的,如果有,则判断同组的是否有issueId相同的
  613. const issueIdFindIndex = groupArr[
  614. groupFindIndex
  615. ].klScaleSub.findIndex(
  616. (issItem) => issItem.issueId === group.issueId
  617. );
  618. if (issueIdFindIndex === -1) {
  619. // 8. 如果没有相同的issueId,则在该组中添加当前项的问题
  620. groupArr[groupFindIndex].klScaleSub.push({
  621. issueId: group.issueId,
  622. constant: group.two_constant,
  623. content: group.two_content,
  624. factor: group.two_factor,
  625. orderNo: 0,
  626. remark: group.two_remark,
  627. resultType: group.two_resultType,
  628. ruleCode: group.two_ruleCode,
  629. score: group.two_score,
  630. selectType: group.two_selectType,
  631. status: group.two_status,
  632. textType: group.two_textType,
  633. klScaleDetail: [
  634. {
  635. content: group.content,
  636. orderNo: 0,
  637. pushInfo: group.pushInfo,
  638. remark: group.remark,
  639. result: group.result,
  640. ruleCode: group.ruleCode,
  641. score: group.score,
  642. status: group.status,
  643. textType: group.textType
  644. }
  645. ]
  646. });
  647. } else {
  648. // 9. 如果有相同的issueId,则在该组的该问题中,添加一个新的选项
  649. groupArr[groupFindIndex].klScaleSub[
  650. issueIdFindIndex
  651. ].klScaleDetail.push({
  652. content: group.content,
  653. orderNo: 0,
  654. pushInfo: group.pushInfo,
  655. remark: group.remark,
  656. result: group.result,
  657. ruleCode: group.ruleCode,
  658. score: group.score,
  659. status: group.status,
  660. textType: group.textType
  661. });
  662. }
  663. }
  664. });
  665. // 10. 将groupArr赋值到提交数据中
  666. params.klScaleParent[tableIndex].klScaleSaveGroup = groupArr;
  667. } else if (table.textType === 12) {
  668. // 文本类型单独处理
  669. // console.dir(table);
  670. params.klScaleParent.push({
  671. ...table,
  672. klScaleSaveGroup: [
  673. {
  674. groupNum: 0,
  675. klScaleSub: [
  676. {
  677. constant: 0,
  678. content: table.klScaleSaveGroup[0].content,
  679. factor: 0,
  680. orderNo: 0,
  681. remark: "string",
  682. resultType: null,
  683. ruleCode: "string",
  684. score: null,
  685. selectType: 0,
  686. status: 1,
  687. textType: 21,
  688. klScaleDetail: []
  689. }
  690. ]
  691. }
  692. ]
  693. });
  694. }
  695. });
  696. // 11.将得分结果中的content转成字符串 max和min
  697. const scoreresultPatam = this.scoreresults.scoreresultsdatas.map(
  698. (item, index) => {
  699. return {
  700. ...item,
  701. orderNo: index,
  702. content: JSON.stringify(item.content)
  703. };
  704. }
  705. );
  706. // 12. 创建一个得分结果的表格 并将数据赋值上
  707. const table = {
  708. constant: 0,
  709. content: "得分结果",
  710. factor: 0,
  711. klScaleSaveGroup: [
  712. {
  713. groupNum: 0,
  714. klScaleSub: [
  715. {
  716. constant: 0,
  717. content: "得分范围",
  718. factor: 0,
  719. klScaleDetail: [...scoreresultPatam],
  720. orderNo: 0,
  721. remark: "string",
  722. resultType: null,
  723. ruleCode: "string",
  724. score: null,
  725. selectType: 21,
  726. status: 2,
  727. textType: 21
  728. }
  729. ]
  730. }
  731. ],
  732. orderNo: 0,
  733. remark: "string",
  734. resultType: null,
  735. ruleCode: "string",
  736. score: null,
  737. status: 2,
  738. textType: 13
  739. };
  740. // 13. 将得分结果加入到提交数据中
  741. if (this.ScoreResultsShow) {
  742. params.klScaleParent.push(table);
  743. }
  744. // 14 提交数据设置新的orderNo,删除issueId
  745. params.klScaleParent.forEach((tableItem, tableIndex) => {
  746. tableItem.orderNo = tableIndex;
  747. tableItem.klScaleSaveGroup.forEach((groupItem, groupIndex) => {
  748. groupItem.groupNum = groupIndex;
  749. groupItem.klScaleSub.forEach((issueItem, issueIndex) => {
  750. issueItem.orderNo = issueIndex;
  751. issueItem.issueId && delete issueItem.issueId;
  752. issueItem.klScaleDetail.forEach((optionItem, optionIndex) => {
  753. optionItem.orderNo = optionIndex;
  754. });
  755. });
  756. });
  757. });
  758. return params;
  759. // 提交数据的处理 end....
  760. },
  761. // 提交 (父级调用)
  762. assessCommit() {
  763. // new Promise((resolve))
  764. let valid1 = new Promise((resolve, reject) => {
  765. this.$refs["scaleFormRef"].validate((valid, object, err) => {
  766. if (valid) {
  767. resolve(true);
  768. } else {
  769. reject({ type: "c", object });
  770. return false;
  771. }
  772. });
  773. });
  774. let valid2 = new Promise((resolve, reject) => {
  775. this.$refs["ScoreResultsRef"].validate((valid, object) => {
  776. if (valid) {
  777. resolve(true);
  778. } else {
  779. reject({ type: "c", object });
  780. return false;
  781. }
  782. });
  783. });
  784. if (this.ScoreResultsShow) {
  785. return [valid1, valid2];
  786. }
  787. return [valid1];
  788. },
  789. /**
  790. * 增/删/得分结果表格
  791. * @param type : 1:add 0:remove
  792. * @param index :当前行索引
  793. */
  794. CHANEG_SCORE_RESULT(type, index) {
  795. // 节流: 阻止用户频繁点击
  796. if (this.timer) return;
  797. this.timer = setTimeout(() => {
  798. clearTimeout(this.timer);
  799. this.timer = null;
  800. }, 500);
  801. if (type === 1) {
  802. this.scoreresults.scoreresultsdatas.splice(index + 1, 0, {
  803. content: {
  804. max: null,
  805. min: null
  806. },
  807. orderNo: null,
  808. pushInfo: "",
  809. remark: null,
  810. result: "",
  811. ruleCode: null,
  812. score: null,
  813. status: 2,
  814. textType: 31
  815. });
  816. } else {
  817. this.$delete(this.scoreresults.scoreresultsdatas, index);
  818. }
  819. },
  820. /**
  821. * 增/删/移动表格
  822. * @param tableIndex :当前表格
  823. * @param type :类型 1:新增;-1:删除;up:上移;down:下移
  824. */
  825. CHANGE_TABLE(val) {
  826. // 节流: 阻止用户频繁点击
  827. if (this.timer) return;
  828. this.timer = setTimeout(() => {
  829. clearTimeout(this.timer);
  830. this.timer = null;
  831. }, 500);
  832. const { tableIndex, type } = val;
  833. switch (type) {
  834. case 1:
  835. this.scaleData.klScaleParent.splice(
  836. tableIndex + 1,
  837. 0,
  838. JSON.parse(JSON.stringify(defaultTable))
  839. );
  840. break;
  841. case -1:
  842. this.$delete(this.scaleData.klScaleParent, tableIndex);
  843. break;
  844. case "up":
  845. const thisTable = this.scaleData.klScaleParent[tableIndex];
  846. const beforeTable = this.scaleData.klScaleParent[tableIndex - 1];
  847. this.$set(this.scaleData.klScaleParent, tableIndex - 1, thisTable);
  848. this.$set(this.scaleData.klScaleParent, tableIndex, beforeTable);
  849. break;
  850. case "down":
  851. const thisTable1 = this.scaleData.klScaleParent[tableIndex];
  852. const afterTable = this.scaleData.klScaleParent[tableIndex + 1];
  853. this.$set(this.scaleData.klScaleParent, tableIndex + 1, thisTable1);
  854. this.$set(this.scaleData.klScaleParent, tableIndex, afterTable);
  855. break;
  856. }
  857. },
  858. /**
  859. * 修改表格数据(添加、删除 :组、问题、选项)
  860. * @param type 类型:1/-1:新增/删除组; 2/-2:新增/删除问题; 3/-3:新增/删除选项
  861. * @param tableIndex 单个量表的index
  862. * @param rowIndex 表格 当前行的index
  863. * @param groupId 当前组id
  864. * @param issueId 当前问题id
  865. */
  866. CHANGE_TABLE_ROW(val) {
  867. // 节流: 阻止用户频繁点击
  868. if (this.timer) return;
  869. this.timer = setTimeout(() => {
  870. clearTimeout(this.timer);
  871. this.timer = null;
  872. }, 500);
  873. const { type, tableIndex, rowIndex, groupId, issueId } = val;
  874. const child = { ...defaultDate };
  875. switch (type) {
  876. case 1: //type 1: 添加组
  877. // 设置新的 groupId、issueId
  878. child.groupId = new Date().valueOf().toString();
  879. child.issueId = child.groupId + "-" + new Date().valueOf();
  880. // 使用当前的组id(groupId) 找到最后一个groupId为当前groupId的索引;
  881. let groupIndex;
  882. this.scaleData.klScaleParent[tableIndex].klScaleSaveGroup.forEach(
  883. (item, i) => {
  884. if (item.groupId === groupId) {
  885. groupIndex = i;
  886. }
  887. }
  888. );
  889. // 将新的组插入到当前组后边
  890. this.scaleData.klScaleParent[tableIndex].klScaleSaveGroup.splice(
  891. groupIndex + 1,
  892. 0,
  893. child
  894. );
  895. break;
  896. case 2: //type 2: 添加问题
  897. // 设置新的 groupId(相同的组id)、issueId
  898. child.groupId = groupId;
  899. child.issueId = child.groupId + "-" + new Date().valueOf();
  900. let issueIndex;
  901. // 使用当前的组id(issueId) 找到最后一个issueId为当前issueId的索引;
  902. this.scaleData.klScaleParent[tableIndex].klScaleSaveGroup.forEach(
  903. (item, i) => {
  904. if (item.issueId === issueId) {
  905. issueIndex = i;
  906. }
  907. }
  908. );
  909. // 将新的组插入到当前组后边
  910. this.scaleData.klScaleParent[tableIndex].klScaleSaveGroup.splice(
  911. issueIndex + 1,
  912. 0,
  913. child
  914. );
  915. break;
  916. case 3: //type 3: 添加选项
  917. // 设置新的 groupId(相同的组id)、issueId(相同的组问题id)
  918. child.groupId = groupId;
  919. child.issueId = issueId;
  920. // 添加相同问题的内容、常数、系数、选择
  921. const thisRowData =
  922. this.scaleData.klScaleParent[tableIndex].klScaleSaveGroup[rowIndex];
  923. child.two_content = thisRowData.content;
  924. child.two_factor = thisRowData.two_factor;
  925. child.two_constant = thisRowData.two_constant;
  926. child.two_selectType = thisRowData.two_selectType;
  927. // 将新的组插入到当前组后边
  928. this.scaleData.klScaleParent[tableIndex].klScaleSaveGroup.splice(
  929. rowIndex + 1,
  930. 0,
  931. child
  932. );
  933. break;
  934. case -1: //type -1: 删除组 => 删除所有组id为当前组id的数据
  935. const newTableBygroupId = this.scaleData.klScaleParent[
  936. tableIndex
  937. ].klScaleSaveGroup.filter((item) => item.groupId !== groupId);
  938. this.$set(
  939. this.scaleData.klScaleParent[tableIndex],
  940. "klScaleSaveGroup",
  941. newTableBygroupId
  942. );
  943. break;
  944. case -2: //type -2: 删除问题 => 删除所有问题id为当前问题id的数据
  945. const newTableByissueId = this.scaleData.klScaleParent[
  946. tableIndex
  947. ].klScaleSaveGroup.filter((item) => item.issueId !== issueId);
  948. this.$set(
  949. this.scaleData.klScaleParent[tableIndex],
  950. "klScaleSaveGroup",
  951. newTableByissueId
  952. );
  953. break;
  954. case -3: //type -3: 删除选项
  955. this.$delete(
  956. this.scaleData.klScaleParent[tableIndex].klScaleSaveGroup,
  957. rowIndex
  958. );
  959. break;
  960. }
  961. },
  962. CHANGE_FORM_DATA(tableIndex, rowIndex, name, val) {
  963. this.$set(
  964. this.scaleData.klScaleParent[tableIndex].klScaleSaveGroup[rowIndex],
  965. name,
  966. val
  967. );
  968. },
  969. // 清空选项
  970. initializationTableData(e, tableIndex) {
  971. this.$set(this.scaleData.klScaleParent[tableIndex], "klScaleSaveGroup", [
  972. { ...defaultDate }
  973. ]);
  974. },
  975. resizeTable() {
  976. this.$refs.ScaleTable.forEach((item) => {
  977. item.resizeTable();
  978. });
  979. this.$refs.ScoreResultsTable &&
  980. this.$refs.ScoreResultsTable.resizeTable();
  981. // this.$refs.ScaleTable.resizeTable();
  982. }
  983. },
  984. watch: {
  985. scaleData: {
  986. handler() {
  987. console.log("监听");
  988. },
  989. deep: true
  990. },
  991. childScaleData() {
  992. // console.log("child Mounted");
  993. // console.dir(this.childScaleData);
  994. if (this.childScaleData) {
  995. // 修改时的默认数据赋值 逻辑:遍历接口数据 赋值给结构体数据
  996. let obj = {
  997. ...this.data,
  998. klScaleParent: []
  999. };
  1000. delete obj.klScaleDetail;
  1001. let scoreresults = {
  1002. scoreresultsdatas: []
  1003. };
  1004. this.childScaleData.klScaleDetail.forEach((table, tableIndex) => {
  1005. console.log("?????");
  1006. if (table.textType === 13) {
  1007. // 计算结果
  1008. scoreresults.scoreresultsdatas = table.subMenuList[0].subMenuList;
  1009. scoreresults.scoreresultsdatas.forEach((item) => {
  1010. item.content = JSON.parse(item.content);
  1011. });
  1012. console.log(
  1013. "scoreresults.scoreresultsdatas",
  1014. scoreresults.scoreresultsdatas
  1015. );
  1016. } else if (table.textType === 11) {
  1017. // 选项
  1018. obj.klScaleParent.push({
  1019. constant: table.constant,
  1020. content: table.content,
  1021. factor: table.factor,
  1022. orderNo: table.orderNo,
  1023. remark: table.remark,
  1024. resultType: table.resultType,
  1025. ruleCode: table.ruleCode,
  1026. score: table.score,
  1027. status: table.status,
  1028. textType: table.textType,
  1029. klScaleSaveGroup: []
  1030. });
  1031. table.subMenuList.forEach((issueItem, issueIndex) => {
  1032. const arr = issueItem.subMenuList.map(
  1033. (optionItem, optionIndex) => {
  1034. return {
  1035. groupId: issueItem.groupNum,
  1036. issueId: optionItem.parentId,
  1037. two_constant: issueItem.constant,
  1038. two_content: issueItem.content,
  1039. two_factor: issueItem.factor,
  1040. two_orderNo: issueItem.orderNo,
  1041. two_remark: issueItem.remark,
  1042. two_resultType: issueItem.resultType,
  1043. two_ruleCode: issueItem.ruleCode,
  1044. two_score: issueItem.score,
  1045. two_selectType: issueItem.selectType,
  1046. two_status: issueItem.status,
  1047. two_textType: issueItem.textType,
  1048. content: optionItem.content,
  1049. orderNo: optionItem.orderNo,
  1050. pushInfo: optionItem.pushInfo,
  1051. remark: optionItem.remark,
  1052. result: optionItem.result,
  1053. ruleCode: optionItem.ruleCode,
  1054. score: optionItem.score,
  1055. status: optionItem.status,
  1056. textType: optionItem.textType
  1057. };
  1058. }
  1059. );
  1060. obj.klScaleParent[tableIndex].klScaleSaveGroup.push(...arr);
  1061. });
  1062. } else if (table.textType === 12) {
  1063. // 文本
  1064. obj.klScaleParent.push({
  1065. constant: table.constant,
  1066. content: table.content,
  1067. factor: table.factor,
  1068. orderNo: table.orderNo,
  1069. remark: table.remark,
  1070. resultType: table.resultType,
  1071. ruleCode: table.ruleCode,
  1072. score: table.score,
  1073. status: table.status,
  1074. textType: table.textType,
  1075. klScaleSaveGroup: [
  1076. {
  1077. two_constant: null,
  1078. two_content: null,
  1079. two_factor: null,
  1080. two_orderNo: null,
  1081. two_remark: null,
  1082. two_resultType: null,
  1083. two_ruleCode: null,
  1084. two_score: null,
  1085. two_selectType: null,
  1086. two_status: null,
  1087. two_textType: null,
  1088. content: table.subMenuList[0].content,
  1089. orderNo: table.subMenuList[0].groupNum,
  1090. pushInfo: table.subMenuList[0].pushInfo,
  1091. remark: table.subMenuList[0].remark,
  1092. result: table.subMenuList[0].result,
  1093. ruleCode: table.subMenuList[0].ruleCode,
  1094. score: table.subMenuList[0].score,
  1095. status: table.subMenuList[0].status,
  1096. textType: table.subMenuList[0].textType
  1097. }
  1098. ]
  1099. });
  1100. }
  1101. });
  1102. // console.dir(obj);
  1103. // console.dir(scoreresults);
  1104. this.scaleData = obj;
  1105. if (scoreresults.scoreresultsdatas.length)
  1106. this.scoreresults = scoreresults;
  1107. }
  1108. }
  1109. },
  1110. computed: {
  1111. // 判断是否需要得分结果
  1112. ScoreResultsShow() {
  1113. const index = this.scaleData.klScaleParent.findIndex(
  1114. (item) => item.resultType === 1
  1115. );
  1116. if (index === -1) {
  1117. return false;
  1118. }
  1119. return true;
  1120. }
  1121. },
  1122. created() {
  1123. this.editorOption.modules.toolbar.container =
  1124. this.toolbars[this.toolbarMode];
  1125. },
  1126. mounted() {}
  1127. };
  1128. </script>