table.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <template>
  2. <div class="table">
  3. <div class="th">
  4. <div
  5. class="td width"
  6. :class="{ special: item.name.length === 3 || item.name.length > 4 }"
  7. v-for="item in tableHeader"
  8. :key="item.props"
  9. >
  10. {{ item.name }}
  11. </div>
  12. </div>
  13. <div class="tr-wrap" v-for="(item, index) in tableData" :key="index">
  14. <div v-if="type==0" class="tr" :class="{ 'special-tr': hideText }">
  15. <div class="td" v-for="(ele, idx) in tableHeader" :key="idx + 'id'">
  16. <el-icon @click="handleDelete(index)" v-show="idx===0&&isEdit" class="delete-icon" color="#FF2323"><RemoveFilled /></el-icon>
  17. <span v-if="!isEdit">{{ item[ele.props] }}</span>
  18. <template v-else>
  19. <span v-if="ele.name==='执行方式'">人工</span>
  20. <el-select remote-show-suffix v-else class="select" v-model="item[ele.props]">
  21. <el-option v-for="optionItem in item.list" :key="optionItem.name" :label="optionItem.name" :value="optionItem.name" />
  22. </el-select>
  23. </template>
  24. </div>
  25. </div>
  26. <div v-else class="tr collapse" :class="{ 'special-tr': hideText }">
  27. <div class="td" :class="{'collapse-td':ele.name==='执行方式'}" v-for="(ele, idx) in tableHeader" :key="idx + 'id'">
  28. <el-icon @click="handleDelete(index)" v-show="idx===0&&isEdit" class="delete-icon" color="#FF2323"><RemoveFilled /></el-icon>
  29. <div v-if="!isEdit" :class="{'special-td':idx>1}">
  30. <div>{{ item[ele.props]||'测试数据' }}</div>
  31. <div class="txt" v-show="idx>1">1111</div>
  32. </div>
  33. <template v-else>
  34. <div :class="{'special-td':idx>1}">
  35. <template v-if="ele.name==='执行方式'">
  36. <div>人工</div>
  37. <div class="txt" v-show="idx>1">无人机</div>
  38. </template>
  39. <template v-else>
  40. <el-select :class="['select',{'ml':idx>1}]" v-model="item[ele.props]">
  41. <el-option v-for="optionItem in item.list" :key="optionItem.name" :label="optionItem.name" :value="optionItem.name" />
  42. </el-select>
  43. <el-select v-show="idx>1" :class="['select','txt',{'ml':idx>1}]" v-model="item[ele.props]">
  44. <el-option v-for="optionItem in item.list" :key="optionItem.name" :label="optionItem.name" :value="optionItem.name" />
  45. </el-select>
  46. </template>
  47. </div>
  48. </template>
  49. </div>
  50. </div>
  51. <div class="box-textarea" v-if="!hideText">
  52. <el-input
  53. :disabled="!isEdit"
  54. class="textarea"
  55. v-model="textarea"
  56. :rows="1"
  57. type="textarea"
  58. placeholder="这是是用药注意事项的备注,省略1000字"
  59. />
  60. </div>
  61. </div>
  62. </div>
  63. </template>
  64. <script setup>
  65. import { ref } from "vue";
  66. const props = defineProps({
  67. tableData: {
  68. type: Array,
  69. defalut: [],
  70. required:true
  71. },
  72. tableHeader: {
  73. type: Array,
  74. defalut: [],
  75. required:true
  76. },
  77. hideText: {
  78. type: Boolean,
  79. defalut: true,
  80. },
  81. isEdit: {
  82. type: Boolean,
  83. defalut: true,
  84. },
  85. type: {
  86. type: [String,Number],
  87. defalut:0,
  88. required:true
  89. },
  90. });
  91. const emit = defineEmits(['handleDelete'])
  92. const handleDelete = (index) =>{
  93. emit('handleDelete',index)
  94. }
  95. const textarea = ref("");
  96. const list = ref([
  97. {
  98. name: "营养",
  99. },
  100. {
  101. name: "Action 2",
  102. },
  103. {
  104. name: "Action 3",
  105. },
  106. ]);
  107. </script>
  108. <style lang="scss" scoped>
  109. .table {
  110. border: 1px solid #444444;
  111. border-radius: 5px;
  112. .th,
  113. .tr {
  114. display: flex;
  115. align-items: center;
  116. color: #727272;
  117. height: 46px;
  118. font-size: 14px;
  119. justify-content: space-around;
  120. .td {
  121. display: flex;
  122. align-items: center;
  123. justify-content: center;
  124. text-align: center;
  125. width: 25%;
  126. height: 100%;
  127. color: #cecece;
  128. }
  129. }
  130. .collapse{
  131. height: 80px;
  132. border: 1px solid #444444;
  133. margin: 12px 8px;
  134. border-radius: 6px;
  135. .collapse-td{
  136. border-left: 1px solid #444444;
  137. border-right: 1px solid #444444;
  138. }
  139. }
  140. .special-td{
  141. width: 100%;
  142. height: 100%;
  143. div{
  144. width: 100%;
  145. height: 50%;
  146. line-height: 40px;
  147. }
  148. .txt{
  149. border-top: 1px solid #444444;
  150. }
  151. }
  152. .th {
  153. background: rgba(255, 255, 255, 0.04);
  154. .width {
  155. width: 40px;
  156. }
  157. .special {
  158. width: 60px;
  159. }
  160. }
  161. .special-tr {
  162. .td {
  163. width: auto;
  164. }
  165. }
  166. .delete-icon{
  167. margin-right: 4px;
  168. cursor: pointer;
  169. }
  170. .tr-wrap + .tr-wrap {
  171. border-top: 1px solid #444444;
  172. }
  173. }
  174. .select {
  175. width: 50px !important;
  176. &.ml{
  177. padding: 0 15px;
  178. }
  179. ::v-deep {
  180. .el-select__wrapper {
  181. background: transparent;
  182. padding: 0;
  183. box-shadow: none;
  184. }
  185. .el-select__placeholder,
  186. .el-select__caret {
  187. color: #ffd489;
  188. }
  189. }
  190. }
  191. .box-textarea {
  192. border-radius: 4px;
  193. padding: 10px;
  194. background: rgba(255, 255, 255, 0.05);
  195. margin: 0 8px 10px 8px;
  196. .textarea {
  197. ::v-deep {
  198. .el-textarea__inner {
  199. background: transparent;
  200. box-shadow: none;
  201. color: #fff;
  202. padding: 0;
  203. }
  204. }
  205. }
  206. }
  207. </style>