scale-table.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  1. <style lang="less" scoped>
  2. .scaleTable {
  3. min-height: 100px;
  4. .table_box {
  5. padding: 0 30px;
  6. }
  7. .btn_box {
  8. width: 100%;
  9. height: 100%;
  10. display: flex;
  11. align-items: center;
  12. justify-content: space-around;
  13. .btn_div {
  14. flex: 1;
  15. display: flex;
  16. align-items: center;
  17. justify-content: center;
  18. }
  19. img {
  20. width: 16px;
  21. height: 16px;
  22. cursor: pointer;
  23. }
  24. }
  25. .table_select_btn {
  26. display: flex;
  27. flex-direction: column;
  28. justify-content: center;
  29. align-items: center;
  30. /deep/ .el-button--text {
  31. padding: 3px 0;
  32. margin: 0;
  33. }
  34. }
  35. /deep/.el-input--mini .el-input__inner {
  36. width: 100%;
  37. }
  38. /deep/.el-table th {
  39. padding: 0;
  40. }
  41. }
  42. /deep/.el-table th,
  43. .el-table tr {
  44. height: 50px;
  45. background: #e3eaf4;
  46. }
  47. /deep/.el-table th {
  48. padding: 0;
  49. }
  50. .custom_table_header {
  51. vertical-align: middle;
  52. &::before {
  53. content: "*";
  54. color: red;
  55. font-size: 12px;
  56. margin-right: 4px;
  57. }
  58. }
  59. /deep/.el-form-item--mini.el-form-item,
  60. .el-form-item--small.el-form-item {
  61. padding: 18px 0;
  62. position: static;
  63. }
  64. /deep/ .el-textarea__inner {
  65. overflow-y: hidden;
  66. }
  67. .cell_center_box {
  68. /deep/ .el-input__inner {
  69. // width: 40px;
  70. text-align: center;
  71. }
  72. }
  73. /deep/.el-select--mini {
  74. width: 100%;
  75. }
  76. /deep/ .el-input--mini{
  77. font-size: 14px;
  78. }
  79. </style>
  80. <template>
  81. <div class="scaleTable" :id="`scaleTableRef[${tableIndex}]`">
  82. <div class="table_box">
  83. <el-table
  84. v-if="tableShow"
  85. :data="tableData"
  86. header-row-class-name="header_row_class_name"
  87. border
  88. style="width: 100%; margin: 20px 0"
  89. :span-method="objectSpanMethod"
  90. :ref="`scaleTableRef[${tableIndex}]`"
  91. >
  92. <el-table-column prop="issueId" label="组" width="70px">
  93. <template slot-scope="scope">
  94. <div class="btn_box">
  95. <div class="btn_div">
  96. <img
  97. @click="
  98. $emit('CHANGE_TABLE_ROW', {
  99. type: 1,
  100. tableIndex,
  101. rowIndex: scope.$index,
  102. groupId: scope.row.groupId
  103. })
  104. "
  105. src="../../../images/add-new-rule-sub.png"
  106. alt=""
  107. />
  108. </div>
  109. <div
  110. class="btn_div"
  111. v-if="imposeRestrictionsRemoveOnGroup(scope.row.groupId)"
  112. >
  113. <img
  114. @click="
  115. $emit('CHANGE_TABLE_ROW', {
  116. type: -1,
  117. tableIndex,
  118. groupId: scope.row.groupId
  119. })
  120. "
  121. src="../../../images/add-new-rule-del.png"
  122. alt=""
  123. />
  124. </div>
  125. </div>
  126. </template>
  127. </el-table-column>
  128. <el-table-column prop="groupId" label="问题" width="70px">
  129. <template slot-scope="scope">
  130. <div class="btn_box">
  131. <div class="btn_div">
  132. <img
  133. @click="
  134. $emit('CHANGE_TABLE_ROW', {
  135. type: 2,
  136. tableIndex,
  137. rowIndex: scope.$index,
  138. groupId: scope.row.groupId,
  139. issueId: scope.row.issueId
  140. })
  141. "
  142. src="../../../images/add-new-rule-sub.png"
  143. alt=""
  144. />
  145. </div>
  146. <div
  147. class="btn_div"
  148. v-if="
  149. imposeRestrictionsRemoveOnIssue({
  150. groupId: scope.row.groupId,
  151. issueId: scope.row.issueId
  152. })
  153. "
  154. >
  155. <img
  156. @click="
  157. $emit('CHANGE_TABLE_ROW', {
  158. type: -2,
  159. tableIndex,
  160. issueId: scope.row.issueId
  161. })
  162. "
  163. src="../../../images/add-new-rule-del.png"
  164. alt=""
  165. />
  166. </div>
  167. </div>
  168. </template>
  169. </el-table-column>
  170. <el-table-column prop="two_selectType" label="选择" width="70px">
  171. <template slot-scope="scope">
  172. <div class="table_select_btn">
  173. <el-button
  174. @click="handleSelectTypeBtn(scope.$index, 1)"
  175. :style="scope.row.two_selectType != 1 ? { color: '#999' } : ''"
  176. type="text"
  177. >单选</el-button
  178. >
  179. <el-button
  180. :style="scope.row.two_selectType != 2 ? { color: '#999' } : ''"
  181. @click="handleSelectTypeBtn(scope.$index, 2)"
  182. type="text"
  183. >多选</el-button
  184. >
  185. </div>
  186. </template>
  187. </el-table-column>
  188. <el-table-column prop="two_content" label="问题内容">
  189. <template slot="header">
  190. <div class="custom_table_header">问题内容</div>
  191. </template>
  192. <template slot-scope="scope">
  193. <el-form-item
  194. :prop="`klScaleParent[${tableIndex}].klScaleSaveGroup[${scope.$index}].two_content`"
  195. :rules="rules.issueContent"
  196. >
  197. <el-input
  198. :ref="`klScaleParent[${tableIndex}].klScaleSaveGroup[${scope.$index}].two_content`"
  199. type="textarea"
  200. rows="1"
  201. :autosize="true"
  202. resize="none"
  203. v-model="scope.row.two_content"
  204. clearable
  205. maxlength="300"
  206. placeholder="请输入"
  207. ></el-input>
  208. </el-form-item>
  209. </template>
  210. </el-table-column>
  211. <el-table-column
  212. prop="two_factor"
  213. label="系数"
  214. width="90px"
  215. v-if="tableResultType === 2"
  216. >
  217. <template slot-scope="scope">
  218. <div class="cell_center_box">
  219. <el-form-item
  220. :prop="`klScaleParent[${tableIndex}].klScaleSaveGroup[${scope.$index}].two_factor`"
  221. :rules="rules.issueFactor"
  222. >
  223. <el-input
  224. type="text"
  225. v-model.number="scope.row.two_factor"
  226. placeholder="请输入"
  227. ></el-input>
  228. </el-form-item>
  229. </div>
  230. </template>
  231. </el-table-column>
  232. <el-table-column
  233. prop="two_constant"
  234. label="常数"
  235. width="90px"
  236. v-if="tableResultType === 2"
  237. >
  238. <template slot-scope="scope">
  239. <div class="cell_center_box">
  240. <el-form-item
  241. :prop="`klScaleParent[${tableIndex}].klScaleSaveGroup[${scope.$index}].two_constant`"
  242. :rules="rules.issueConstant"
  243. >
  244. <el-input
  245. type="text"
  246. v-model.number="scope.row.two_constant"
  247. placeholder="请输入"
  248. style="text-align: center"
  249. ></el-input>
  250. </el-form-item>
  251. </div>
  252. </template>
  253. </el-table-column>
  254. <el-table-column prop="issueId" label="选项个数" width="80px">
  255. <template slot-scope="scope">
  256. <div>
  257. {{ optionLength(scope.row.issueId) }}
  258. </div>
  259. </template>
  260. </el-table-column>
  261. <el-table-column prop="orderNo" label="选项" width="70px">
  262. <template slot-scope="scope">
  263. <div class="btn_box">
  264. <div class="btn_div">
  265. <img
  266. @click="
  267. $emit('CHANGE_TABLE_ROW', {
  268. type: 3,
  269. tableIndex,
  270. rowIndex: scope.$index,
  271. groupId: scope.row.groupId,
  272. issueId: scope.row.issueId
  273. })
  274. "
  275. src="../../../images/add-new-rule-sub.png"
  276. alt=""
  277. />
  278. </div>
  279. <div
  280. class="btn_div"
  281. v-if="imposeRestrictionsRemoveOnOption(scope.row.issueId)"
  282. >
  283. <img
  284. @click="
  285. $emit('CHANGE_TABLE_ROW', {
  286. type: -3,
  287. tableIndex,
  288. rowIndex: scope.$index
  289. })
  290. "
  291. src="../../../images/add-new-rule-del.png"
  292. alt=""
  293. />
  294. </div>
  295. </div>
  296. </template>
  297. </el-table-column>
  298. <el-table-column
  299. prop="content"
  300. label="选项内容"
  301. :width="tableResultType === 1 ? '200px' : ''"
  302. >
  303. <template slot="header">
  304. <div class="custom_table_header">选项内容</div>
  305. </template>
  306. <template slot-scope="scope">
  307. <el-form-item
  308. :prop="`klScaleParent[${tableIndex}].klScaleSaveGroup[${scope.$index}].content`"
  309. :rules="rules.content"
  310. >
  311. <el-input
  312. :ref="`klScaleParent[${tableIndex}].klScaleSaveGroup[${scope.$index}].content`"
  313. type="textarea"
  314. rows="1"
  315. :autosize="true"
  316. resize="none"
  317. v-model="scope.row.content"
  318. clearable
  319. maxlength="300"
  320. placeholder="请输入"
  321. ></el-input>
  322. </el-form-item>
  323. </template>
  324. </el-table-column>
  325. <el-table-column
  326. prop="content"
  327. label="编码"
  328. :width="tableResultType === 1 ? '200px' : ''"
  329. v-if="tableResultType === 2"
  330. >
  331. <template slot-scope="scope">
  332. <el-form-item
  333. :prop="`klScaleParent[${tableIndex}].klScaleSaveGroup[${scope.$index}].ruleCode`"
  334. :rules="rules.ruleCode"
  335. ><el-select
  336. clearable
  337. remote
  338. filterable
  339. :remote-method="searchRuleCode"
  340. @focus="ruleCodeFocus(scope.$index)"
  341. v-model.trim="scope.row.ruleCode"
  342. >
  343. <el-option
  344. v-for="item in scope.row.ruleCodeList"
  345. :key="item.code"
  346. :label="item.code"
  347. :value="item.code"
  348. >
  349. </el-option>
  350. </el-select>
  351. </el-form-item>
  352. </template>
  353. </el-table-column>
  354. <el-table-column
  355. prop="content"
  356. label="分值"
  357. v-if="tableResultType === 2"
  358. >
  359. <template slot="header">
  360. <div class="custom_table_header">分值</div>
  361. </template>
  362. <template slot-scope="scope">
  363. <el-form-item
  364. :prop="`klScaleParent[${tableIndex}].klScaleSaveGroup[${scope.$index}].score`"
  365. :rules="rules.score"
  366. >
  367. <el-input
  368. type="text"
  369. maxlength="6"
  370. v-model.number="scope.row.score"
  371. clearable
  372. placeholder="请输入"
  373. ></el-input>
  374. </el-form-item>
  375. </template>
  376. </el-table-column>
  377. <el-table-column
  378. prop="result"
  379. label="结果"
  380. width="200px"
  381. v-if="tableResultType === 1"
  382. >
  383. <template slot="header">
  384. <div class="custom_table_header">结果</div>
  385. </template>
  386. <template slot-scope="scope">
  387. <el-form-item
  388. :prop="`klScaleParent[${tableIndex}].klScaleSaveGroup[${scope.$index}].result`"
  389. :rules="rules.result"
  390. >
  391. <el-input
  392. :ref="`klScaleParent[${tableIndex}].klScaleSaveGroup[${scope.$index}].result`"
  393. type="textarea"
  394. rows="1"
  395. :autosize="true"
  396. resize="none"
  397. v-model="scope.row.result"
  398. clearable
  399. maxlength="300"
  400. placeholder="请输入"
  401. ></el-input>
  402. </el-form-item>
  403. </template>
  404. </el-table-column>
  405. <el-table-column
  406. prop="pushInfo"
  407. label="建议"
  408. v-if="tableResultType === 1"
  409. >
  410. <template slot-scope="scope">
  411. <el-form-item
  412. :prop="`klScaleParent[${tableIndex}].klScaleSaveGroup[${scope.$index}].pushInfo`"
  413. :rules="rules.pushInfo"
  414. >
  415. <el-input
  416. :ref="`klScaleParent[${tableIndex}].klScaleSaveGroup[${scope.$index}].pushInfo`"
  417. type="textarea"
  418. rows="1"
  419. :autosize="true"
  420. resize="none"
  421. v-model="scope.row.pushInfo"
  422. clearable
  423. maxlength="500"
  424. placeholder="请输入"
  425. ></el-input>
  426. </el-form-item>
  427. </template>
  428. </el-table-column>
  429. </el-table>
  430. </div>
  431. </div>
  432. </template>
  433. <script>
  434. import rules from "./rules";
  435. import api from "@api/knowledgeTree.js";
  436. export default {
  437. name: "scaleTable",
  438. data() {
  439. return {
  440. tableShow: true,
  441. rules: rules,
  442. ruleCodeIndex: null
  443. };
  444. },
  445. methods: {
  446. resizeTable() {
  447. setTimeout(() => {
  448. this.tableData.forEach((item, index) => {
  449. this.$refs[
  450. `klScaleParent[${this.tableIndex}].klScaleSaveGroup[${index}].content`
  451. ] &&
  452. this.$refs[
  453. `klScaleParent[${this.tableIndex}].klScaleSaveGroup[${index}].content`
  454. ].resizeTextarea();
  455. this.$refs[
  456. `klScaleParent[${this.tableIndex}].klScaleSaveGroup[${index}].two_content`
  457. ] &&
  458. this.$refs[
  459. `klScaleParent[${this.tableIndex}].klScaleSaveGroup[${index}].two_content`
  460. ].resizeTextarea();
  461. this.$refs[
  462. `klScaleParent[${this.tableIndex}].klScaleSaveGroup[${index}].result`
  463. ] &&
  464. this.$refs[
  465. `klScaleParent[${this.tableIndex}].klScaleSaveGroup[${index}].result`
  466. ].resizeTextarea();
  467. this.$refs[
  468. `klScaleParent[${this.tableIndex}].klScaleSaveGroup[${index}].pushInfo`
  469. ] &&
  470. this.$refs[
  471. `klScaleParent[${this.tableIndex}].klScaleSaveGroup[${index}].pushInfo`
  472. ].resizeTextarea();
  473. });
  474. }, 500);
  475. },
  476. ruleCodeFocus(index) {
  477. this.ruleCodeIndex = index;
  478. },
  479. searchRuleCode(val) {
  480. api
  481. .searchRuleCode({ name: val === "" ? null : val, type: 1 })
  482. .then((res) => {
  483. if (res.data.code == "0") {
  484. this.$emit(
  485. "CHANGE_FORM_DATA",
  486. this.tableIndex,
  487. this.ruleCodeIndex,
  488. "ruleCodeList",
  489. res.data.data
  490. );
  491. }
  492. });
  493. },
  494. addGroup() {},
  495. // 单选、多选
  496. handleSelectTypeBtn(index, type) {
  497. this.$emit(
  498. "CHANGE_FORM_DATA",
  499. this.tableIndex,
  500. index,
  501. "two_selectType",
  502. type
  503. );
  504. },
  505. // 计算表格选项内容的值
  506. optionLength(val) {
  507. if (val || val === 0) {
  508. const accordWithThis = this.tableData.filter(
  509. (item) => item.issueId === val
  510. );
  511. return accordWithThis.length ? accordWithThis.length : 0;
  512. }
  513. },
  514. // 表格合并单元格逻辑
  515. getSpanArr(data) {
  516. this.spanArr = [];
  517. this.spanArr1 = [];
  518. for (var i = 0; i < data.length; i++) {
  519. if (i === 0) {
  520. // 如果是第一条记录(即索引是0的时候),向数组中加入1
  521. /** *
  522. * 例子:
  523. * name:1
  524. * name:1
  525. * name:2
  526. * name:2
  527. * 最终结果:spanArr = [2,0,2,0]
  528. */
  529. this.spanArr.push(1);
  530. this.pos = 0;
  531. this.spanArr1.push(1);
  532. this.pos1 = 0;
  533. } else {
  534. if (data[i].groupId === data[i - 1].groupId) {
  535. // 如果remark相等就累加,并且push 0
  536. this.spanArr[this.pos] += 1;
  537. this.spanArr.push(0);
  538. } else {
  539. // 不相等push 1,并且pos 要换成当前下标
  540. this.spanArr.push(1);
  541. this.pos = i;
  542. }
  543. if (data[i].issueId === data[i - 1].issueId) {
  544. // 如果remark相等就累加,并且push 0
  545. this.spanArr1[this.pos1] += 1;
  546. this.spanArr1.push(0);
  547. } else {
  548. // 不相等push 1,并且pos 要换成当前下标
  549. this.spanArr1.push(1);
  550. this.pos1 = i;
  551. }
  552. }
  553. }
  554. },
  555. objectSpanMethod({ row, column, rowIndex, columnIndex }) {
  556. if (columnIndex == 0) {
  557. const _row = this.spanArr[rowIndex];
  558. const _col = _row > 0 ? 1 : 0;
  559. return {
  560. rowspan: _row,
  561. colspan: _col
  562. };
  563. } else if (
  564. column.label == "问题" ||
  565. column.label == "选择" ||
  566. column.label == "问题内容" ||
  567. column.label == "系数" ||
  568. column.label == "常数" ||
  569. column.label == "选项个数"
  570. ) {
  571. const _row = this.spanArr1[rowIndex];
  572. const _col = _row > 0 ? 1 : 0;
  573. return {
  574. rowspan: _row,
  575. colspan: _col
  576. };
  577. }
  578. },
  579. // 删除组限制:剩余一组时隐藏删除按钮
  580. imposeRestrictionsRemoveOnGroup(groupId) {
  581. // 查找有没有其他组存在 如果为0的话则不存在
  582. const otherGroupLength = this.tableData.filter(
  583. (item) => item.groupId !== groupId
  584. ).length;
  585. return otherGroupLength;
  586. },
  587. // 删除问题限制:该组剩余一个问题时隐藏删除按钮
  588. imposeRestrictionsRemoveOnIssue(val) {
  589. const { groupId, issueId } = val;
  590. // 获取该组所有的issus
  591. const thisGroups = this.tableData.filter(
  592. (item) => item.groupId === groupId
  593. );
  594. // 查找该组有没有其他问题 otherIssueLength为0表示只有当前一个问题存在 所以隐藏删除按钮
  595. const otherIssueLength = thisGroups.filter(
  596. (item) => item.issueId !== issueId
  597. ).length;
  598. if (otherIssueLength) {
  599. return true;
  600. }
  601. return false;
  602. },
  603. // 删除选项限制:该问题剩余一个选项时隐藏删除按钮
  604. imposeRestrictionsRemoveOnOption(issueId) {
  605. // 查找同组的问题,如果只有一个问题则隐藏删除按钮
  606. const thisOptionByissueIdLenth = this.tableData.filter(
  607. (item) => item.issueId === issueId
  608. ).length;
  609. if (thisOptionByissueIdLenth > 1) {
  610. return true;
  611. }
  612. return false;
  613. }
  614. },
  615. created() {
  616. this.getSpanArr(this.tableData);
  617. },
  618. watch: {
  619. tableData: {
  620. handler() {
  621. this.getSpanArr(this.tableData);
  622. },
  623. deep: true
  624. },
  625. tableResultType() {
  626. this.tableShow = false;
  627. setTimeout(() => {
  628. this.tableShow = true;
  629. });
  630. }
  631. },
  632. props: {
  633. tableData: {
  634. default: []
  635. },
  636. tableIndex: {
  637. required: true
  638. },
  639. tableResultType: {
  640. required: true,
  641. default: 1
  642. }
  643. }
  644. };
  645. </script>