index.vue 40 KB

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