t-table.vue 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. overflow-x: scroll;
  69. }
  70. .t-table>>>t-tr {
  71. display: flex;
  72. }
  73. .t-table>>>t-tr:nth-child(2n) {
  74. background: #f5f5f5;
  75. }
  76. /* #ifdef H5 */
  77. .t-table>>>.t-tr:nth-child(2n) {
  78. background: #f5f5f5;
  79. }
  80. /* #endif */
  81. </style>