fromtableDetails.vue 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. <template>
  2. <div>
  3. <el-table
  4. ref="tableRef"
  5. :cell-style="{ padding: '0px', fontSize: '12px' }"
  6. :header-cell-style="tableHeaderCellStyle"
  7. :data="tableData"
  8. :border="true"
  9. show-summary
  10. :summary-method="summaryMethod"
  11. style="width: 100%"
  12. @selection-change="handleSelectionChange"
  13. @row-click="rowClick"
  14. :row-style="rowStyle"
  15. :row-class-name="rowClassName"
  16. >
  17. <el-table-column fixed="left" type="selection" width="50"> </el-table-column>
  18. <el-table-column type="index" width="40" style="text-align: center"> </el-table-column>
  19. <el-table-column prop="descr" label="摘要" width="auto" style="padding: 0">
  20. <template slot-scope="{ row }">
  21. <!-- type="textarea"-->
  22. <el-input
  23. style="width: 100%"
  24. type="text"
  25. v-model="row.descr"
  26. size="small"
  27. autocomplete="off"
  28. clearable
  29. placeholder="请输入摘要"
  30. :disabled="disabled"
  31. >
  32. </el-input>
  33. </template>
  34. </el-table-column>
  35. <el-table-column prop="accountCode" label="科目代码" width="360px">
  36. <template slot-scope="{ row }">
  37. <div
  38. style="display: flex; align-items: center; justify-content: space-between"
  39. >
  40. <search-query
  41. style="width: 100%"
  42. :datalist="accountData"
  43. :selectValue="row.accountCode"
  44. :filterable="true"
  45. :clearable="true"
  46. :remote="true"
  47. :buttonIf="false"
  48. :desc="true"
  49. :forParameter="{ key: 'code', label: 'code', value: 'code', desc: 'fullName' }"
  50. :disabled="disabled"
  51. @corpFocus="accountsListfun"
  52. @remoteMethod="accountsListfun"
  53. @corpChange="corpChange($event, 'accountId', row)"
  54. >
  55. </search-query>
  56. <el-tooltip v-if="!disabled &&(row.isEmpl===1 || row.isCorp === 1 || row.isDept === 1 || row.isItem === 1)" class="item" effect="dark" content="核算项目" placement="top">
  57. <el-button size="mini" type="primary" icon="el-icon-edit" circle @click="auxiliaryAccountingfun(row)" :disabled="disabled"></el-button>
  58. </el-tooltip>
  59. <el-tooltip v-if="!disabled && row.isDc === 1" class="item" effect="dark" content="预收/预付核销" placement="top">
  60. <el-button size="mini" type="primary" icon="el-icon-scissors" circle @click="showOffRecordsfun(row)" :disabled="disabled"></el-button>
  61. </el-tooltip>
  62. </div>
  63. <div style="display: flex">
  64. <!-- _【职员】 _【部门】 _【客户】-->
  65. <span>{{
  66. (row.accountCnName ? row.accountCnName : " ") +
  67. (row.isEmpl === 1 && row.emplName ? "/" + row.emplName : "") +
  68. (row.isDept === 1 && row.deptName ? "/" + row.deptName : "") +
  69. (row.isCorp === 1 && row.corpShortName ? "/" + row.corpShortName : "") +
  70. (row.isItem === 1 ? "/" + row.itemClassify + "-" + (row.itemName ? row.itemName : "") : "")
  71. }}</span>
  72. </div>
  73. </template>
  74. </el-table-column>
  75. <el-table-column prop="dc" label="方向" width="50px" style="padding: 0; text-align: center;" align="center">
  76. <template slot-scope="{ row }">
  77. <span>{{ row.dc == 'D' ? '借' : '贷' }}</span>
  78. </template>
  79. </el-table-column>
  80. <el-table-column label="本币金额">
  81. <el-table-column prop="amountDr" label="借方" width="120px">
  82. <template slot-scope="{ row }">
  83. <el-input-number
  84. style="width: 100%"
  85. v-model="row.amountDr"
  86. size="small"
  87. autocomplete="off"
  88. :disabled="row.curCode !== 'CNY' || !row.accountId || disabled"
  89. placeholder="请输入借方"
  90. :precision="2"
  91. @change="amountBlur(row, 'D')"
  92. @keydown.native="handleKeydown($event, row,'amountDr')"
  93. :controls="false"
  94. >
  95. </el-input-number>
  96. </template>
  97. </el-table-column>
  98. <el-table-column prop="amountCr" label="货方" width="120px">
  99. <template slot-scope="{ row }">
  100. <el-input-number
  101. style="width: 100%"
  102. v-model="row.amountCr"
  103. size="small"
  104. autocomplete="off"
  105. :disabled="row.curCode !== 'CNY' || !row.accountId || disabled"
  106. placeholder="请输入货方"
  107. :precision="2"
  108. @change="amountBlur(row, 'C')"
  109. @keydown.native="handleKeydown($event, row,'amountCr')"
  110. :controls="false"
  111. >
  112. </el-input-number>
  113. </template>
  114. </el-table-column>
  115. </el-table-column>
  116. <el-table-column label="外币金额">
  117. <el-table-column prop="curCode" label="币种" width="50px" align="center"> </el-table-column>
  118. <el-table-column prop="exrate" label="汇率" width="100px">
  119. <template slot-scope="{ row }">
  120. <el-input-number
  121. v-if="row.curCode === 'USD'"
  122. style="width: 100%; border: none;"
  123. v-model="row.exrate"
  124. size="small"
  125. autocomplete="off"
  126. clearable
  127. placeholder="请输入借方"
  128. :precision="4"
  129. @change="amountBlur(row, 'exrate')"
  130. :disabled="disabled"
  131. :controls="false"
  132. >
  133. </el-input-number>
  134. <!-- {{ row.exrate }}-->
  135. <span v-else></span>
  136. </template>
  137. </el-table-column>
  138. <el-table-column prop="amountDrUsd" label="借方" width="120px">
  139. <template slot-scope="{ row }">
  140. <el-input-number
  141. v-if="row.curCode === 'USD' && row.changeMode !== 'd'"
  142. style="width: 100%; text-align: right"
  143. v-model="row.amountDrUsd"
  144. size="small"
  145. autocomplete="off"
  146. :disabled="row.curCode === 'CNY' || !row.accountId || disabled"
  147. clearable
  148. placeholder="请输入借方"
  149. :precision="2"
  150. @change="amountUSDBlur(row, 'Dusd')"
  151. :controls="false"
  152. >
  153. </el-input-number>
  154. <span v-else></span>
  155. </template>
  156. </el-table-column>
  157. <el-table-column prop="amountCrUsd" label="货方" width="120px">
  158. <template slot-scope="{ row }">
  159. <el-input-number
  160. v-if="row.curCode === 'USD' && row.changeMode !== 'd'"
  161. style="width: 100%"
  162. v-model="row.amountCrUsd"
  163. size="small"
  164. autocomplete="off"
  165. :disabled="row.curCode === 'CNY' || !row.accountId || disabled"
  166. clearable
  167. placeholder="请输入货方"
  168. :precision="2"
  169. @change="amountUSDBlur(row, 'Cusd')"
  170. :controls="false"
  171. >
  172. </el-input-number>
  173. <span v-else></span>
  174. </template>
  175. </el-table-column>
  176. </el-table-column>
  177. <!--
  178. <el-table-column prop="remarks" label="备注" width="200px">
  179. <template slot-scope="{ row }">
  180. <el-input
  181. style="width: 100%;"
  182. type="textarea"
  183. v-model="row.remarks"
  184. size="small"
  185. autocomplete="off"
  186. clearable
  187. placeholder="请输入备注"
  188. :disabled="disabled"
  189. >
  190. </el-input>
  191. </template>
  192. </el-table-column>
  193. -->
  194. <el-table-column v-if="!disabled" label="操作" fixed="right" width="100px">
  195. <template slot-scope="scope">
  196. <el-tooltip class="item" effect="dark" content="添加" placement="top">
  197. <el-button
  198. size="mini"
  199. type="primary"
  200. icon="el-icon-plus"
  201. circle
  202. @click="addRowsfun(scope.row, scope.$index)"
  203. :disabled="disabled"
  204. ></el-button>
  205. </el-tooltip>
  206. <el-tooltip class="item" effect="dark" :content="scope.row.changeMode === 'd' ? '恢复' : '删除'" placement="top">
  207. <el-button
  208. size="mini"
  209. type="danger"
  210. icon="el-icon-delete"
  211. circle
  212. @click="deletefun(scope.row, scope.$index)"
  213. :disabled="disabled"
  214. ></el-button>
  215. </el-tooltip>
  216. </template>
  217. </el-table-column>
  218. </el-table>
  219. </div>
  220. </template>
  221. <script>
  222. import SearchQuery from "@/components/iosbasic-data/searchquery.vue";
  223. import { accountsList } from "@/api/iosBasicData/accounts";
  224. import { bcurrencyGetExrate } from "@/api/iosBasicData/rateManagement";
  225. import { dateFormat } from "@/util/date";
  226. export default {
  227. components: { SearchQuery },
  228. data() {
  229. return {
  230. accountData: [], // 科目数据
  231. };
  232. },
  233. props: {
  234. assemblyForm: {
  235. type: Object,
  236. default: {},
  237. },
  238. tableData: {
  239. type: Array,
  240. default: [],
  241. },
  242. handleSelectionData: {
  243. type: Array,
  244. default: [],
  245. },
  246. disabled: {
  247. type: Boolean,
  248. default: false,
  249. },
  250. },
  251. async created() {
  252. this.accountsListfun();
  253. // this.option = await this.getColumnData(this.getColumnName(321.1), this.optionBack);
  254. },
  255. methods: {
  256. forceNumber(s, d){
  257. let N = Number(s);
  258. return isNaN(N) ? 0.00 : Number(N.toFixed(d ? d : 2));
  259. },
  260. // 自定义合计
  261. summaryMethod(param) {
  262. const { columns, data } = param;
  263. const sums = [];
  264. columns.forEach((column, index) => {
  265. if (index === 2) {
  266. sums[index] = "合计";
  267. return;
  268. }
  269. const values = data.map((item) => item.changeMode === 'd' ? 0.00 : Number(item[column.property]));
  270. // 显示列的统计 金额
  271. let arr = ["amountDr", "amountCr", "amountDrUsd", "amountCrUsd"];
  272. // 判断是否有这个数据
  273. if (arr.indexOf(column.property) != -1) {
  274. if (!values.every((value) => isNaN(value))) {
  275. sums[index] = values.reduce((prev, curr) => {
  276. const value = Number(curr);
  277. if (!isNaN(value)) {
  278. return prev + curr;
  279. } else {
  280. return prev;
  281. }
  282. }, 0);
  283. sums[index] = sums[index].toFixed(2); // 把合计的参数保留两位小数
  284. // sums[index] += " 元";
  285. } else {
  286. sums[index] = " ";
  287. }
  288. }
  289. });
  290. return sums;
  291. },
  292. handleKeydown(e, row, name){
  293. console.log("handleKeydown", e, name);
  294. if (e.key === "=") {
  295. e.preventDefault();
  296. // amountDr,amountCr
  297. let amtDr = 0.0,
  298. amtCr = 0.0;
  299. this.tableData.forEach(item => {
  300. if (item !== row) {
  301. amtDr = this.forceNumber(amtDr + this.forceNumber(item.amountDr, 2), 2);
  302. amtCr = this.forceNumber(amtCr + this.forceNumber(item.amountCr, 2), 2);
  303. }
  304. });
  305. console.log("amtDr", amtDr, "amtCr", amtCr);
  306. if (name === "amountDr") {
  307. this.$set(row, "amountCr", 0.0);
  308. this.$set(row, name, this.forceNumber(amtCr - amtDr, 2));
  309. }
  310. if (name === "amountCr") {
  311. this.$set(row, "amountDr", 0.0);
  312. this.$set(row, name, this.forceNumber(amtDr - amtCr, 2));
  313. }
  314. if (row.curCode === "USD") {
  315. this.$set(row, "exrate", this.forceNumber(row.exrate, 4));
  316. if (row.exrate.toFixed(4) === "0.0000") {
  317. this.$set(row, "exrate", 1);
  318. }
  319. this.$set(row, "amountDrUsd", this.forceNumber(this.forceNumber(row.amountDr, 2) / row.exrate, 2));
  320. this.$set(row, "amountCrUsd", this.forceNumber(this.forceNumber(row.amountCr, 2) / row.exrate, 2));
  321. }else{
  322. this.$set(row, "exrate", 1);
  323. this.$set(row, "amountDrUsd", 0.00);
  324. this.$set(row, "amountCrUsd", 0.00);
  325. }
  326. }
  327. },
  328. // 借方/贷方 本币的计算
  329. amountBlur(row, name) {
  330. console.log("amountBlur", row, name);
  331. if (name == "D") {
  332. this.$set(row, "amountCr", 0);
  333. }
  334. if (name == "C") {
  335. this.$set(row, "amountDr", 0);
  336. }
  337. // if (name == 'Dusd') {
  338. // this.$set(row,'amountCrUsd',0)
  339. // }
  340. // if (name == 'Cusd') {
  341. // this.$set(row,'amountDrUsd',0)
  342. // }
  343. if (row.curCode == "USD") {
  344. this.$set(row, "exrate", row.exrate ? Number(row.exrate) : 1);
  345. this.$set(row, "amountCr", row.amountCr ? Number(row.amountCr) : 0);
  346. this.$set(row, "amountDr", row.amountDr ? Number(row.amountDr) : 0);
  347. this.$set(row, "amountCrUsd", (row.amountCr / row.exrate).toFixed(2));
  348. this.$set(row, "amountDrUsd", (row.amountDr / row.exrate).toFixed(2));
  349. }
  350. },
  351. // 外币的计算
  352. amountUSDBlur(row, name) {
  353. console.log("amountUSDBlur", row, name);
  354. if (name == "Dusd") {
  355. this.$set(row, "amountCrUsd", 0);
  356. }
  357. if (name == "Cusd") {
  358. this.$set(row, "amountDrUsd", 0);
  359. }
  360. this.$set(row, "exrate", row.exrate ? Number(row.exrate) : 1);
  361. this.$set(row, "amountCrUsd", row.amountCrUsd ? Number(row.amountCrUsd) : 0);
  362. this.$set(row, "amountDrUsd", row.amountDrUsd ? Number(row.amountDrUsd) : 0);
  363. this.$set(row, "amountCr", (row.amountCrUsd * row.exrate).toFixed(2));
  364. this.$set(row, "amountDr", (row.amountDrUsd * row.exrate).toFixed(2));
  365. },
  366. // 获取科目类型数据
  367. accountsListfun(code, ref) {
  368. console.log("accountsListfun", code, ref);
  369. // isManual == 1 的允许手工添加
  370. accountsList(1, 10, { code, isDetail: 1, isManual: 1 }).then((res) => {
  371. this.accountData = res.data.data.records;
  372. if(code && this.accountData.length===1){
  373. if(ref){
  374. ref.corpChange(this.accountData[0].code)
  375. ref.visible = false
  376. }
  377. }
  378. });
  379. },
  380. // 行删除
  381. deletefun(row, index) {
  382. this.$emit("deletefun", row, index);
  383. },
  384. // 行添加
  385. addRowsfun(row, index) {
  386. this.$emit("addRowsfun", row, index);
  387. },
  388. // 辅助核算
  389. auxiliaryAccountingfun(row) {
  390. if (!row.accountId) {
  391. return this.$message.warning("请先选择科目代码");
  392. }
  393. this.$emit("auxiliaryAccountingfun", row);
  394. },
  395. showOffRecordsfun (row){
  396. if (!row.accountId) {
  397. return this.$message.warning("请先选择科目代码");
  398. }
  399. let amt = this.forceNumber(row.curCode!=="CNY" ? (row.dc==="D" ? row.amountCrUsd : row.amountDrUsd) : (row.dc==="D" ? row.amountCr : row.amountDr), 2)
  400. if(amt<=0.00){
  401. return this.$message.warning("请先输入核销金额!");
  402. }
  403. this.$emit("showOffRecordsfun", row);
  404. },
  405. // 下拉回调
  406. corpChange(value, name, row) {
  407. let found = false;
  408. if (name === "accountId") {
  409. for (let item of this.accountData) {
  410. if (item.code == value) {
  411. found = true;
  412. console.log(item, item.id);
  413. this.$set(row, "accountId", item.id);
  414. this.$set(row, "accountCode", item.code);
  415. this.$set(row, "accountCnName", item.cnName);
  416. this.$set(row, "accountEnName", item.enName);
  417. this.$set(row, "accountFullName", item.fullName);
  418. this.$set(row, "accountLevel", item.level);
  419. this.$set(row, "accountProperty", item.property);
  420. this.$set(row, "dc", item.dc);
  421. // 币种
  422. this.$set(row, "curCode", item.curCode==="USD" ? item.curCode : "CNY");
  423. // 汇率
  424. this.$set(row, "exrate", item.exrate);
  425. // 其他
  426. this.$set(row, "isForeign", item.isForeign);
  427. this.$set(row, "isQuantity", item.isQuantity);
  428. this.$set(row, "isCorp", item.isCorp);
  429. this.$set(row, "isDept", item.isDept);
  430. this.$set(row, "isEmpl", item.isEmpl);
  431. this.$set(row, "isItem", item.isItem);
  432. this.$set(row, "itemClassifyId", item.itemClassifyId);
  433. this.$set(row, "itemClassify", item.itemClassify);
  434. this.$set(row, "isDc", item.isDc);
  435. this.$set(row, "isArAp", item.isArAp);
  436. // 打开弹窗
  437. this.$emit("auxiliaryAccountingfun", row);
  438. }
  439. }
  440. if (!found) {
  441. console.log("not found");
  442. this.$set(row, "accountId", 0);
  443. this.$set(row, "accountCode", "");
  444. this.$set(row, "accountCnName", "");
  445. this.$set(row, "accountEnName", "");
  446. this.$set(row, "accountFullName", "");
  447. this.$set(row, "accountLevel", 0);
  448. this.$set(row, "accountProperty", 0);
  449. this.$set(row, "dc", "");
  450. // 币种
  451. this.$set(row, "curCode", "");
  452. // 汇率
  453. // 其他
  454. this.$set(row, "isForeign", 0);
  455. this.$set(row, "isQuantity", 0);
  456. this.$set(row, "isCorp", 0);
  457. this.$set(row, "isDept", 0);
  458. this.$set(row, "isEmpl", 0);
  459. this.$set(row, "isItem", 0);
  460. this.$set(row, "itemClassifyId", 0);
  461. this.$set(row, "itemClassify", "");
  462. this.$set(row, "isDc", 0);
  463. this.$set(row, "isArAp", 0);
  464. this.$set(row, "exrate", 0);
  465. }
  466. if (row.curCode === "USD") {
  467. bcurrencyGetExrate({
  468. date: this.assemblyForm.voucherDate ? this.assemblyForm.voucherDate.slice(0, 10) + " 00:00:00" : dateFormat(new Date(), "yyyy-MM-dd") + " 00:00:00", // 凭证日期
  469. dc: row.dc,
  470. type: 1,
  471. }).then((res) => {
  472. for (let item of res.data.data) {
  473. if (item.code === row.curCode) {
  474. this.$set(row, "exrate", this.forceNumber(item.exrate, 4));
  475. this.$set(row, "amountDr", this.forceNumber(row.amountDr, 2))
  476. this.$set(row, "amountCr", this.forceNumber(row.amountCr, 2))
  477. this.$set(row, "amountDrUsd", this.forceNumber(row.amountDrUsd, 2))
  478. this.$set(row, "amountCrUsd", this.forceNumber(row.amountCrUsd, 2))
  479. if(row.amountDrUsd!==0.00){
  480. this.$set(row, "amountCrUsd", 0.00)
  481. this.$set(row, "amountCr", 0.00)
  482. this.$set(row, "amountDr", this.forceNumber(row.amountDrUsd * item.exrate, 2))
  483. }else{
  484. this.$set(row, "amountDrUsd", 0.00)
  485. this.$set(row, "amountDr", 0.00)
  486. this.$set(row, "amountCr", this.forceNumber(row.amountCrUsd * item.exrate, 2))
  487. }
  488. }
  489. }
  490. });
  491. } else {
  492. this.$set(row, "exrate", 0);
  493. this.$set(row, "amountDrUsd", 0.00);
  494. this.$set(row, "amountCrUsd", 0.00);
  495. }
  496. }
  497. console.log(row);
  498. },
  499. // 表头样式
  500. tableHeaderCellStyle({ row, column, rowIndex, columnIndex }) {
  501. return "padding:4px 0px;fontSize:12px;color:#000;background:#ecf5ff;text-align:center";
  502. },
  503. // 列表多选
  504. // 多选选择的数据
  505. handleSelectionChange(arr) {
  506. this.$emit("handleSelectionChange", arr);
  507. },
  508. // 监听点击表格事件
  509. rowClick(row, column, event) {
  510. let refsElTable = this.$refs.tableRef; // 获取表格对象
  511. if (this.CtrlDown) {
  512. refsElTable.toggleRowSelection(row); // ctrl多选 如果点击两次同样会取消选中
  513. return;
  514. }
  515. if (this.shiftOrAltDown && this.handleSelectionData.length > 0) {
  516. // 通过rowIndex判断已选择的行中最上面和最下面的是哪行,再对比按住shift/alt点击的当前行得到新的最上面和最下面的行,把这两行中间的行进行循环选中。
  517. let topAndBottom = this.getTopAndBottom(row, this.bottomSelectionRow, this.topSelectionRow);
  518. refsElTable.clearSelection(); //先清空 不然会导致在这两行中间之外的行状态不变
  519. for (let index = topAndBottom.top; index <= topAndBottom.bottom; index++) {
  520. //选中两行之间的所有行
  521. refsElTable.toggleRowSelection(this.tableData[index], true);
  522. }
  523. } else {
  524. let findRow = this.handleSelectionData.find((c) => c.rowIndex == row.rowIndex); //找出当前选中行
  525. //如果只有一行且点击的也是这一行则取消选择 否则清空再选中当前点击行
  526. if (findRow && this.handleSelectionData.length === 1) {
  527. refsElTable.toggleRowSelection(row, false);
  528. return;
  529. }
  530. // refsElTable.clearSelection(); // 清空之前选择的数据(如果放开,选择之前会变成单选)
  531. refsElTable.toggleRowSelection(row); // 调用选中行方法
  532. }
  533. },
  534. // 行的 style 的回调方法
  535. rowStyle({ row, rowIndex }) {
  536. // 直接在一个对象上定义一个新属性,或者修改一个对象的现有属性,并返回此对象
  537. // object: 要添加或者修改属性的目标对象;prop: 要定义或修改属性的名称;descript: 是一个对象,里面是我们上述的对象属性的特性;
  538. Object.defineProperty(row, "rowIndex", {
  539. //给每一行添加不可枚举属性rowIndex来标识当前行
  540. value: rowIndex, // 设置age的值,不设置的话默认为undefined
  541. writable: true, // 表示属性的值true可以修改,false不可以被修改
  542. enumerable: false, // 设置为false表示不能通过 for-in 循环返回
  543. // configurable: false, // configurable 设置为 false,意味着这个属性不能从对象上删除
  544. });
  545. },
  546. keyDown(event) {
  547. let key = event.keyCode;
  548. if (key == 17) this.CtrlDown = true;
  549. if (key == 16 || key == 18) this.shiftOrAltDown = true;
  550. },
  551. keyUp(event) {
  552. let key = event.keyCode;
  553. if (key == 17) this.CtrlDown = false;
  554. if (key == 16 || key == 18) this.shiftOrAltDown = false;
  555. },
  556. // 文章说明 https://www.jianshu.com/p/48f2c522d2a2
  557. getTopAndBottom(row, bottom, top) {
  558. let n = row.rowIndex,
  559. mx = bottom.rowIndex,
  560. mi = top.rowIndex;
  561. if (n > mx) {
  562. return {
  563. top: mi,
  564. bottom: n,
  565. };
  566. } else if (n < mx && n > mi) {
  567. return {
  568. top: mi,
  569. bottom: n,
  570. };
  571. } else if (n < mi) {
  572. return {
  573. top: n,
  574. bottom: mx,
  575. };
  576. } else if (n == mi || n == mx) {
  577. return {
  578. top: mi,
  579. bottom: mx,
  580. };
  581. }
  582. },
  583. // 给选中行加上current-row这个class类,所以要使用row-class-name这个属性(其实给每一行添加rowIndex也可以用这个属性),
  584. // 判断方式也是通过判断rowIndex对比
  585. rowClassName({ row, rowIndex }) {
  586. let rowName = "",
  587. findRow = this.handleSelectionData.find((c) => c.rowIndex === row.rowIndex);
  588. if (findRow) {
  589. rowName = "current-row "; // elementUI 默认高亮行的class类 不用再样式了^-^,也可通过css覆盖改变背景颜色
  590. }
  591. return rowName; //也可以再加上其他类名 如果有需求的话
  592. },
  593. },
  594. mounted() {
  595. // 按住ctrl实现多选 设置监听keydown事件,以及keyup事件,
  596. addEventListener("keydown", this.keyDown, false);
  597. addEventListener("keyup", this.keyUp, false);
  598. },
  599. beforeDestroy() {
  600. //解绑
  601. removeEventListener("keydown", this.keyDown);
  602. removeEventListener("keyup", this.keyUp);
  603. },
  604. computed: {
  605. //实时得到最上行和最下行
  606. bottomSelectionRow() {
  607. if (this.handleSelectionData.length == 0) return null;
  608. return this.handleSelectionData.reduce((start, end) => {
  609. return start.rowIndex > end.rowIndex ? start : end;
  610. });
  611. },
  612. topSelectionRow() {
  613. if (this.handleSelectionData.length == 0) return null;
  614. return this.handleSelectionData.reduce((start, end) => {
  615. return start.rowIndex < end.rowIndex ? start : end;
  616. });
  617. },
  618. },
  619. };
  620. </script>
  621. <style scoped>
  622. ::v-deep input::-webkit-outer-spin-button,
  623. ::v-deep input::-webkit-inner-spin-button {
  624. -webkit-appearance: none !important;
  625. }
  626. ::v-deep input[type="number"] {
  627. -moz-appearance: textfield !important;
  628. }
  629. ::v-deep .el-table td {
  630. padding: 0;
  631. }
  632. ::v-deep .el-table .cell{
  633. padding-left: 2px !important;
  634. padding-right: 2px !important;
  635. }
  636. ::v-deep .el-input-number .el-input__inner {
  637. text-align: right;
  638. }
  639. ::v-deep .el-input__inner {
  640. /* border: none !important; */
  641. }
  642. </style>