grid-form.vue 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <template>
  2. <view class="grid-from">
  3. <view
  4. class="grid-from-item"
  5. v-for="(col, index) in _columns"
  6. :key="index"
  7. @click.stop="handleClickField(col.key)"
  8. >
  9. <view class="grid-from-item-label">{{ col.title }}</view>
  10. <view class="grid-from-item-value">{{ getFieldValue(col) }}</view>
  11. </view>
  12. </view>
  13. </template>
  14. <script>
  15. export default {
  16. props: {
  17. /**
  18. * title: 标题
  19. * key: key值
  20. * formatter: 格式化函数
  21. * isShow: 显/隐函数
  22. */
  23. columns: {
  24. type: Array,
  25. default: () => [],
  26. },
  27. formData: {
  28. type: Object,
  29. default: () => {},
  30. },
  31. },
  32. computed: {
  33. _columns() {
  34. return this.columns.filter((col) => {
  35. if (col.isShow && col.isShow instanceof Function) {
  36. return col.isShow(col.key, { ...this.formData }, col);
  37. }
  38. return true;
  39. });
  40. },
  41. },
  42. methods: {
  43. /**
  44. * 点击事件
  45. * @param {String} key 字段名
  46. */
  47. handleClickField(key) {
  48. this.$emit("handleClickField", key, { ...this.formData });
  49. },
  50. getFieldValue(col) {
  51. const formData = { ...this.formData };
  52. if (col.formatter && col.formatter instanceof Function) {
  53. return col.formatter(col.key, formData, col);
  54. }
  55. return formData[col.key] || "-";
  56. },
  57. },
  58. };
  59. </script>
  60. <style lang="scss" scoped>
  61. .grid-from {
  62. display: grid;
  63. grid-template-columns: 33% 33% 33%;
  64. padding: 0 24rpx;
  65. &-item {
  66. font-family: "PingFang SC";
  67. font-weight: 400;
  68. margin-top: 24rpx;
  69. &-label {
  70. color: #999;
  71. font-size: 24rpx;
  72. margin-bottom: 16rpx;
  73. }
  74. &-value {
  75. color: #000;
  76. font-size: 28rpx;
  77. }
  78. }
  79. }
  80. </style>