ScanResultTable.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <template>
  2. <el-table
  3. class="scan-result-table"
  4. :data="datas"
  5. @cell-click="studentClickHandle"
  6. >
  7. <el-table-column type="expand" class-name="td-expand" width="22">
  8. <template slot-scope="scope">
  9. <el-table
  10. :data="scope.row.papers"
  11. :show-header="false"
  12. class="scan-result-expand-table"
  13. :row-class-name="extendRowClassName"
  14. @cell-click="paperClickHandle"
  15. >
  16. <el-table-column width="22" class-name="td-checkbox" align="center">
  17. <template slot-scope="subScope">
  18. <el-checkbox
  19. v-model="subScope.row.select"
  20. @change="paperSelectionChange(scope.row)"
  21. ></el-checkbox>
  22. </template>
  23. </el-table-column>
  24. <el-table-column
  25. label="文件名"
  26. prop="filename"
  27. class-name="cursor-column"
  28. >
  29. <template slot-scope="subScope">
  30. 第{{ subScope.$index + 1 }}张
  31. </template>
  32. </el-table-column>
  33. <el-table-column
  34. class-name="action-column"
  35. label="操作"
  36. align="center"
  37. width="50"
  38. >
  39. <template slot-scope="subScope">
  40. <el-button
  41. class="btn-danger"
  42. type="text"
  43. icon="el-icon-error"
  44. @click.stop="toDeletePaper(scope.row, subScope.row)"
  45. >
  46. </el-button>
  47. </template>
  48. </el-table-column>
  49. </el-table>
  50. </template>
  51. </el-table-column>
  52. <el-table-column width="22" class-name="td-checkbox" align="center">
  53. <template slot-scope="scope">
  54. <el-checkbox
  55. v-model="scope.row.select"
  56. @change="rowSelectionChange(scope.row)"
  57. ></el-checkbox>
  58. </template>
  59. </el-table-column>
  60. <el-table-column
  61. prop="studentCode"
  62. label="学号"
  63. class-name="cursor-column"
  64. :width="isNormalTab ? 120 : undefined"
  65. ></el-table-column>
  66. <el-table-column
  67. v-if="isNormalTab"
  68. prop="studentName"
  69. label="姓名"
  70. ></el-table-column>
  71. <el-table-column prop="paperCount" align="center" label="张数" width="50">
  72. <template slot-scope="scope">
  73. {{ scope.row.papers.length }}
  74. </template>
  75. </el-table-column>
  76. <el-table-column
  77. class-name="action-column"
  78. align="center"
  79. label="操作"
  80. width="50"
  81. >
  82. <template slot-scope="scope">
  83. <el-button
  84. class="btn-danger"
  85. type="text"
  86. @click.stop="toDeleteUser(scope.row)"
  87. >
  88. 删除
  89. </el-button>
  90. </template>
  91. </el-table-column>
  92. </el-table>
  93. </template>
  94. <script>
  95. import { deleteFiles } from "../../../plugins/imageOcr";
  96. export default {
  97. name: "scan-result-table",
  98. props: {
  99. tableData: {
  100. type: Array,
  101. default() {
  102. return [];
  103. },
  104. },
  105. tab: {
  106. type: String,
  107. default: "normal",
  108. },
  109. },
  110. data() {
  111. return { selectList: [], datas: [] };
  112. },
  113. computed: {
  114. isNormalTab() {
  115. return this.tab === "normal";
  116. },
  117. },
  118. watch: {
  119. tableData: {
  120. immediate: true,
  121. handler(val) {
  122. if (val) this.datas = val;
  123. },
  124. },
  125. datas(val) {
  126. this.$emit("update:tableData", val);
  127. },
  128. },
  129. methods: {
  130. // table action
  131. rowSelectionChange(row) {
  132. row.papers.forEach((p) => (p.select = row.select));
  133. this.updateSelectList();
  134. },
  135. paperSelectionChange(row) {
  136. const paperSelected = !row.papers.some((p) => !p.select);
  137. row.select = paperSelected;
  138. this.updateSelectList();
  139. },
  140. extendRowClassName({ row }) {
  141. const curImageUrl = this.$parent.curPaper.url.replace("file:///", "");
  142. if (
  143. row.frontOriginImgPath === curImageUrl ||
  144. row.versoOriginImgPath === curImageUrl
  145. ) {
  146. return "tr-active";
  147. }
  148. return "";
  149. },
  150. updateSelectList() {
  151. const selectList = [];
  152. this.datas.forEach((row) => {
  153. const selectPapers = row.papers.filter((p) => p.select);
  154. if (selectPapers.length) {
  155. selectList.push({
  156. ...row,
  157. papers: selectPapers,
  158. });
  159. }
  160. });
  161. this.selectList = selectList;
  162. this.$emit("select-change", this.selectList);
  163. },
  164. clearSelection() {
  165. this.datas.forEach((row) => {
  166. row.select = false;
  167. row.papers.forEach((p) => (p.select = false));
  168. });
  169. this.selectList = [];
  170. this.$emit("select-change", this.selectList);
  171. },
  172. async toDeleteUser(row) {
  173. const res = await this.$confirm(
  174. `确定要删除学生【${row.studentName || row.studentCode}】所有数据吗?`,
  175. "警告",
  176. {
  177. type: "warning",
  178. }
  179. ).catch(() => {});
  180. if (res !== "confirm") return;
  181. const selectedFiles = row.papers
  182. .map((item) => [item.frontOriginImgPath, item.versoOriginImgPath])
  183. .flat();
  184. deleteFiles(selectedFiles);
  185. this.datas = this.datas.filter(
  186. (item) => item.studentCode !== row.studentCode
  187. );
  188. this.updateSelectList();
  189. this.$emit("delete-paper", selectedFiles);
  190. },
  191. async toDeletePaper(row, paper) {
  192. const res = await this.$confirm(`确定要删除当前图片吗?`, "警告", {
  193. type: "warning",
  194. }).catch(() => {});
  195. if (res !== "confirm") return;
  196. const selectedFiles = [
  197. paper.frontOriginImgPath,
  198. paper.versoOriginImgPath,
  199. ];
  200. deleteFiles(selectedFiles);
  201. row.papers = row.papers.filter((item) => item.id !== paper.id);
  202. if (!row.papers.length) {
  203. this.datas = this.datas.filter(
  204. (item) => item.studentCode !== row.studentCode
  205. );
  206. }
  207. this.updateSelectList();
  208. this.$emit("delete-paper", selectedFiles);
  209. },
  210. studentClickHandle(row, column) {
  211. if (column.property !== "studentCode") return;
  212. const curPapers = row.papers
  213. .map((item) => [item.frontOriginImgPath, item.versoOriginImgPath])
  214. .flat();
  215. const curPaperIndex = 0;
  216. this.$emit("row-click", {
  217. curPaperIndex,
  218. curPapers,
  219. });
  220. },
  221. paperClickHandle(paper, column) {
  222. if (column.property !== "filename") return;
  223. const row = this.datas.find((item) =>
  224. item.papers.some((elem) => elem.id === paper.id)
  225. );
  226. if (!row) return;
  227. const curPapers = row.papers
  228. .map((item) => [item.frontOriginImgPath, item.versoOriginImgPath])
  229. .flat();
  230. const curPaperIndex = curPapers.findIndex(
  231. (item) => item === paper.frontOriginImgPath
  232. );
  233. this.$emit("row-click", {
  234. curPaperIndex,
  235. curPapers,
  236. });
  237. },
  238. },
  239. };
  240. </script>