t-table.vue 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <template>
  2. <view class="t-table" :style="{ 'border-width': border + 'px', 'border-color': borderColor }">
  3. <slot />
  4. </view>
  5. </template>
  6. <script>
  7. export default {
  8. props: {
  9. border: {
  10. type: String,
  11. default: '1'
  12. },
  13. borderColor: {
  14. type: String,
  15. default: '#d0dee5'
  16. },
  17. isCheck: {
  18. type: Boolean,
  19. default: false
  20. }
  21. },
  22. provide() {
  23. return {
  24. table: this
  25. };
  26. },
  27. data() {
  28. return {};
  29. },
  30. created() {
  31. this.childrens = [];
  32. this.index = 0;
  33. },
  34. methods: {
  35. fire(e, index, len) {
  36. let childrens = this.childrens;
  37. console.log(childrens);
  38. // 全选
  39. if (index === 0) {
  40. childrens.map((vm, index) => {
  41. vm.checkboxData.checked = e;
  42. return vm;
  43. });
  44. } else {
  45. let isAll = childrens.find((n, ids) => ids !== 0 && !n.checkboxData.checked);
  46. childrens[0].checkboxData.checked = isAll ? false : true;
  47. }
  48. let fireArr = [];
  49. for (let i = 0; i < childrens.length; i++) {
  50. if (childrens[i].checkboxData.checked && i !== 0) {
  51. fireArr.push(childrens[i].checkboxData.value - 1);
  52. }
  53. }
  54. this.$emit('change', {
  55. detail: fireArr
  56. });
  57. }
  58. }
  59. };
  60. </script>
  61. <style scoped>
  62. .t-table {
  63. width: 100%;
  64. border: 1px #d0dee5 solid;
  65. border-left: none;
  66. border-top: none;
  67. box-sizing: border-box;
  68. }
  69. .t-table>>>t-tr {
  70. display: flex;
  71. }
  72. .t-table>>>t-tr:nth-child(2n) {
  73. background: #f5f5f5;
  74. }
  75. /* #ifdef H5 */
  76. .t-table>>>.t-tr:nth-child(2n) {
  77. background: #f5f5f5;
  78. }
  79. /* #endif */
  80. </style>