index.vue 34 KB

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