TableSetItem.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <template>
  2. <div>
  3. <el-table :data="props.tableData" style="width: 100%">
  4. <el-table-column
  5. v-for="(item, index) in props.config"
  6. :key="index"
  7. :label="item?.label"
  8. :width="item?.width"
  9. >
  10. <template #default="{ row, $index }">
  11. <div v-if="item.prop == 'duration'" class="flex item-center">
  12. <!-- <el-select v-model="row.frequencyType" placeholder="">
  13. <el-option
  14. v-for="item in timeTypeList"
  15. :label="item.label"
  16. :value="item.value"
  17. :key="item.value"
  18. >
  19. </el-option>
  20. </el-select> -->
  21. <el-text>{{ timeTypeList[row.frequencyType]?.label }}</el-text>
  22. <el-input
  23. v-if="row.frequencyType !== 3"
  24. v-model="row.duration"
  25. clearable
  26. :placeholder="placeholderList[row.frequencyType]"
  27. class="ml-2"
  28. style="width: 200px"
  29. ></el-input>
  30. </div>
  31. <div v-else-if="item.prop == 'timePreview'">
  32. <span v-if="row.frequencyType == 2">
  33. <div v-for="(item, index) in getMonth(row.duration)" :key="index">
  34. {{ item }}
  35. </div>
  36. </span>
  37. <span v-else-if="row.frequencyType == 1 && row.duration">
  38. {{ previewTime(row.frequencyType, row.duration)?.label }} 每周
  39. </span>
  40. <span v-else-if="row.frequencyType == 3">{{ row.duration }}</span>
  41. <span v-else>{{
  42. previewTime(row.frequencyType, row.duration)?.label
  43. }}</span>
  44. </div>
  45. <!-- <div v-else-if="item.prop == 'frequency'">
  46. </div> -->
  47. <div v-else-if="item.prop == 'remark'">
  48. <el-input
  49. v-model="row.remark"
  50. placeholder="(选填)请输入备注信息"
  51. ></el-input>
  52. </div>
  53. <div v-else-if="item.prop == 'handle'">
  54. <el-button type="primary" link @click="handleRemove($index)"
  55. >移除</el-button
  56. >
  57. </div>
  58. <div v-else>
  59. {{ row[item.prop] }}
  60. </div>
  61. </template>
  62. </el-table-column>
  63. </el-table>
  64. </div>
  65. </template>
  66. <script lang="ts" setup>
  67. import { previewTime } from "@/utils/index";
  68. import moment from "moment";
  69. const emits = defineEmits(["remove"]);
  70. const props = defineProps({
  71. tableData: {
  72. type: Array,
  73. default: () => []
  74. },
  75. config: {
  76. type: Object,
  77. default: () => {}
  78. }
  79. });
  80. const timeTypeList = [
  81. {
  82. label: "每天",
  83. value: 0
  84. },
  85. {
  86. label: "每周",
  87. value: 1
  88. },
  89. {
  90. label: "每月",
  91. value: 2
  92. },
  93. {
  94. label: "指定时间",
  95. value: 3
  96. }
  97. ];
  98. const placeholderList = {
  99. 0: "请输入持续天数",
  100. 1: "请输入持续周数",
  101. 2: "请输入持续月数",
  102. 3: "请输入固定天数"
  103. };
  104. const handleRemove = index => {
  105. console.log("删除的下标", index);
  106. emits("remove");
  107. };
  108. const getMonth = count => {
  109. console.log(count);
  110. if (!count) return [];
  111. let date = [];
  112. for (let i = 0; i < count; i++) {
  113. date.push(
  114. moment()
  115. .add(i + 1, "months")
  116. .format("YYYY-MM-DD")
  117. );
  118. }
  119. console.log("date", date);
  120. return date;
  121. };
  122. </script>