PackageTable.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  1. <template>
  2. <div class="package-table">
  3. <el-table :data="tableData" border>
  4. <el-table-column type="index" label="组号" width="60" align="center" />
  5. <el-table-column label="营养产品" min-width="300">
  6. <template #default="{row}">
  7. <div class="product-group">
  8. <div v-for="(product, index) in row.products" :key="index" class="product-row">
  9. <el-input v-model="product.value" placeholder="请选择" />
  10. <div class="action-buttons">
  11. <el-button class="icon-btn" @click="addProduct(row)">
  12. <el-icon><Plus /></el-icon>
  13. </el-button>
  14. <el-button class="icon-btn" @click="deleteProduct(row, index)">
  15. <el-icon><Delete /></el-icon>
  16. </el-button>
  17. </div>
  18. </div>
  19. </div>
  20. </template>
  21. </el-table-column>
  22. <el-table-column label="数量" width="150" align="center">
  23. <template #default="{row}">
  24. <div class="quantity-group">
  25. <div v-for="(product, index) in row.products" :key="index" class="quantity-input">
  26. <el-input v-model="product.quantity" placeholder="请输入" class="input-center" />
  27. <span class="unit">袋</span>
  28. </div>
  29. </div>
  30. </template>
  31. </el-table-column>
  32. <el-table-column label="用量/次" width="150" align="center">
  33. <template #default="{row}">
  34. <div class="dosage-group">
  35. <div v-for="(product, index) in row.products" :key="index" class="dosage-input">
  36. <el-input v-model="product.dosage" placeholder="请输入" class="input-center" />
  37. <span class="unit">g</span>
  38. </div>
  39. </div>
  40. </template>
  41. </el-table-column>
  42. <el-table-column label="餐次时间" width="500">
  43. <template #default="{row}">
  44. <div class="time-slots">
  45. <div class="time-row">
  46. <div class="time-group">
  47. <el-checkbox v-model="row.timeSlots[0].checked" />
  48. <el-time-select
  49. v-model="row.timeSlots[0].time"
  50. start="06:00"
  51. step="00:30"
  52. end="22:00"
  53. placeholder="选择时间"
  54. :disabled="!row.timeSlots[0].checked"
  55. />
  56. </div>
  57. <div class="time-group">
  58. <el-checkbox v-model="row.timeSlots[1].checked" />
  59. <el-time-select
  60. v-model="row.timeSlots[1].time"
  61. start="06:00"
  62. step="00:30"
  63. end="22:00"
  64. placeholder="选择时间"
  65. :disabled="!row.timeSlots[1].checked"
  66. />
  67. </div>
  68. <div class="time-group">
  69. <el-checkbox v-model="row.timeSlots[2].checked" />
  70. <el-time-select
  71. v-model="row.timeSlots[2].time"
  72. start="06:00"
  73. step="00:30"
  74. end="22:00"
  75. placeholder="选择时间"
  76. :disabled="!row.timeSlots[2].checked"
  77. />
  78. </div>
  79. </div>
  80. <div class="time-row">
  81. <div class="time-group">
  82. <el-checkbox v-model="row.timeSlots[3].checked" />
  83. <el-time-select
  84. v-model="row.timeSlots[3].time"
  85. start="06:00"
  86. step="00:30"
  87. end="22:00"
  88. placeholder="选择时间"
  89. :disabled="!row.timeSlots[3].checked"
  90. />
  91. </div>
  92. <div class="time-group">
  93. <el-checkbox v-model="row.timeSlots[4].checked" />
  94. <el-time-select
  95. v-model="row.timeSlots[4].time"
  96. start="06:00"
  97. step="00:30"
  98. end="22:00"
  99. placeholder="选择时间"
  100. :disabled="!row.timeSlots[4].checked"
  101. />
  102. </div>
  103. <div class="time-group">
  104. <el-checkbox v-model="row.timeSlots[5].checked" />
  105. <el-time-select
  106. v-model="row.timeSlots[5].time"
  107. start="06:00"
  108. step="00:30"
  109. end="22:00"
  110. placeholder="选择时间"
  111. :disabled="!row.timeSlots[5].checked"
  112. />
  113. </div>
  114. </div>
  115. </div>
  116. </template>
  117. </el-table-column>
  118. <el-table-column label="频次" width="120" align="center">
  119. <template #default>
  120. <span>一天3次</span>
  121. </template>
  122. </el-table-column>
  123. <el-table-column label="首日" width="100" align="center">
  124. <template #default="{row}">
  125. <div class="first-day">
  126. <el-input-number v-model="row.firstDayTimes" :min="1" :max="10" size="small" controls-position="right" />
  127. <span class="unit">次</span>
  128. </div>
  129. </template>
  130. </el-table-column>
  131. <el-table-column label="用量/日" width="100" align="center">
  132. <template #default="{row}">
  133. <span>{{ row.dailyDosage }}g</span>
  134. </template>
  135. </el-table-column>
  136. <el-table-column label="使用天数" width="120" align="center">
  137. <template #default="{row}">
  138. <div class="days">
  139. <el-input-number v-model="row.days" :min="1" :max="99" size="small" controls-position="right" />
  140. <span class="unit">天</span>
  141. </div>
  142. </template>
  143. </el-table-column>
  144. <el-table-column label="操作" width="160" align="center" fixed="right">
  145. <template #default="{$index}">
  146. <div class="operation-cell">
  147. <el-button type="primary" link @click="copyRow($index)">复制餐次</el-button>
  148. <el-button type="danger" link @click="deleteRow($index)">删除</el-button>
  149. </div>
  150. </template>
  151. </el-table-column>
  152. </el-table>
  153. <!-- 添加营养产品按钮 -->
  154. <div class="add-product">
  155. <el-button type="primary" class="add-btn" @click="addRow">
  156. <el-icon><CirclePlus /></el-icon>
  157. 添加营养产品
  158. </el-button>
  159. </div>
  160. <!-- 底部按钮和总计 -->
  161. <div class="table-footer">
  162. <div class="left-buttons">
  163. <el-button type="primary" plain>存为个人模板</el-button>
  164. <el-button type="primary" plain>批量添加营养品</el-button>
  165. <el-button type="primary" plain>处方模板</el-button>
  166. </div>
  167. <div class="right-summary">
  168. <div class="summary-list">
  169. <div class="summary-item">
  170. <span class="label">处方费用:</span>
  171. <span class="value">¥0.00</span>
  172. </div>
  173. <div class="summary-item total">
  174. <span class="label">总计:</span>
  175. <span class="value">¥0.00</span>
  176. </div>
  177. </div>
  178. </div>
  179. </div>
  180. </div>
  181. </template>
  182. <script setup lang="ts">
  183. import {ref} from 'vue';
  184. import {Plus, Delete, CirclePlus} from '@element-plus/icons-vue';
  185. interface TimeSlot {
  186. checked: boolean;
  187. time: string;
  188. }
  189. interface Product {
  190. value: string;
  191. quantity: string;
  192. dosage: string;
  193. }
  194. interface TableRow {
  195. products: Product[];
  196. timeSlots: TimeSlot[];
  197. firstDayTimes: number;
  198. dailyDosage: number;
  199. days: number;
  200. }
  201. // 创建默认行数据
  202. const createDefaultRow = (): TableRow => ({
  203. products: [
  204. {
  205. value: '',
  206. quantity: '',
  207. dosage: ''
  208. }
  209. ],
  210. timeSlots: [
  211. {checked: false, time: '08:00'},
  212. {checked: false, time: '08:30'},
  213. {checked: false, time: '12:00'},
  214. {checked: false, time: '12:30'},
  215. {checked: false, time: '18:00'},
  216. {checked: false, time: '18:30'}
  217. ],
  218. firstDayTimes: 2,
  219. dailyDosage: 2.0,
  220. days: 1
  221. });
  222. // 表格数据
  223. const tableData = ref<TableRow[]>([createDefaultRow()]);
  224. // 添加产品输入框
  225. const addProduct = (row: TableRow) => {
  226. row.products.push({
  227. value: '',
  228. quantity: '',
  229. dosage: ''
  230. });
  231. };
  232. // 删除产品输入框
  233. const deleteProduct = (row: TableRow, index: number) => {
  234. if (row.products.length <= 1) {
  235. // 如果只剩一个输入框,删除整行
  236. const rowIndex = tableData.value.findIndex((item) => item === row);
  237. if (rowIndex !== -1) {
  238. tableData.value.splice(rowIndex, 1);
  239. }
  240. } else {
  241. // 否则只删除当前输入框
  242. row.products.splice(index, 1);
  243. }
  244. };
  245. // 复制行
  246. const copyRow = (index: number) => {
  247. const newRow = JSON.parse(JSON.stringify(tableData.value[index]));
  248. tableData.value.splice(index + 1, 0, newRow);
  249. };
  250. // 删除行
  251. const deleteRow = (index: number) => {
  252. if (tableData.value.length === 1) return;
  253. tableData.value.splice(index, 1);
  254. };
  255. // 添加行
  256. const addRow = () => {
  257. tableData.value.push(createDefaultRow());
  258. };
  259. </script>
  260. <style lang="scss" scoped>
  261. .package-table {
  262. :deep(.el-table) {
  263. .el-table__header {
  264. th {
  265. background-color: #f5f7fa;
  266. color: #606266;
  267. font-weight: 500;
  268. padding: 8px 0;
  269. height: 40px;
  270. }
  271. }
  272. .el-table__row {
  273. td {
  274. padding: 4px 8px;
  275. }
  276. }
  277. }
  278. .product-group {
  279. display: flex;
  280. flex-direction: column;
  281. gap: 8px;
  282. .product-row {
  283. display: flex;
  284. align-items: center;
  285. gap: 8px;
  286. .el-input {
  287. flex: 1;
  288. }
  289. .action-buttons {
  290. display: flex;
  291. gap: 1px;
  292. .icon-btn {
  293. padding: 6px;
  294. height: 32px;
  295. border: 1px solid #dcdfe6;
  296. &:hover {
  297. border-color: var(--el-color-primary);
  298. color: var(--el-color-primary);
  299. }
  300. .el-icon {
  301. font-size: 14px;
  302. }
  303. }
  304. }
  305. }
  306. }
  307. .quantity-group,
  308. .dosage-group {
  309. display: flex;
  310. flex-direction: column;
  311. gap: 8px;
  312. .quantity-input,
  313. .dosage-input {
  314. display: flex;
  315. align-items: center;
  316. justify-content: center;
  317. gap: 4px;
  318. height: 32px;
  319. .input-center {
  320. width: 80px;
  321. :deep(.el-input__inner) {
  322. text-align: center;
  323. }
  324. }
  325. .unit {
  326. color: #909399;
  327. font-size: 14px;
  328. }
  329. }
  330. }
  331. .time-slots {
  332. display: flex;
  333. flex-direction: column;
  334. gap: 8px;
  335. .time-row {
  336. display: flex;
  337. gap: 8px;
  338. .time-group {
  339. display: flex;
  340. align-items: center;
  341. gap: 4px;
  342. :deep(.el-checkbox) {
  343. margin-right: 0;
  344. .el-checkbox__label {
  345. display: none;
  346. }
  347. }
  348. :deep(.el-time-select) {
  349. .el-input {
  350. width: 120px;
  351. }
  352. .el-input__wrapper {
  353. padding: 0 8px;
  354. border-radius: 2px;
  355. box-shadow: 0 0 0 1px #dcdfe6 inset;
  356. &:hover:not(.is-disabled) {
  357. box-shadow: 0 0 0 1px #c0c4cc inset;
  358. }
  359. &.is-disabled {
  360. background-color: #f5f7fa;
  361. box-shadow: 0 0 0 1px #e4e7ed inset;
  362. .el-input__inner {
  363. color: #909399;
  364. -webkit-text-fill-color: #909399;
  365. }
  366. }
  367. }
  368. .el-input__inner {
  369. height: 32px;
  370. text-align: center;
  371. font-size: 14px;
  372. color: #606266;
  373. }
  374. }
  375. }
  376. }
  377. }
  378. .operation-cell {
  379. display: flex;
  380. justify-content: center;
  381. gap: 12px;
  382. }
  383. .add-product {
  384. display: flex;
  385. justify-content: center;
  386. margin-top: 16px;
  387. padding: 12px 0;
  388. background-color: #f5f7fa;
  389. border: 1px solid var(--el-table-border-color);
  390. border-top: none;
  391. .add-btn {
  392. display: flex;
  393. align-items: center;
  394. gap: 4px;
  395. height: 32px;
  396. padding: 0 16px;
  397. font-size: 14px;
  398. background-color: var(--el-color-primary-light-8);
  399. color: var(--el-color-primary);
  400. border: none;
  401. &:hover {
  402. background-color: var(--el-color-primary-light-9);
  403. }
  404. .el-icon {
  405. font-size: 16px;
  406. }
  407. }
  408. }
  409. .table-footer {
  410. display: flex;
  411. justify-content: space-between;
  412. align-items: flex-start;
  413. margin-top: 16px;
  414. padding: 16px;
  415. border: 1px solid var(--el-table-border-color);
  416. border-top: 1px solid var(--el-table-border-color);
  417. .left-buttons {
  418. display: flex;
  419. gap: 12px;
  420. .el-button {
  421. height: 32px;
  422. padding: 0 16px;
  423. font-size: 14px;
  424. }
  425. }
  426. .right-summary {
  427. min-width: 200px;
  428. .summary-list {
  429. display: flex;
  430. flex-direction: column;
  431. align-items: flex-end;
  432. gap: 4px;
  433. .summary-item {
  434. display: flex;
  435. align-items: center;
  436. justify-content: flex-end;
  437. gap: 8px;
  438. text-align: right;
  439. .label {
  440. font-size: 16px;
  441. color: #606266;
  442. }
  443. .value {
  444. font-size: 20px;
  445. color: #606266;
  446. min-width: 80px;
  447. text-align: right;
  448. }
  449. &.total {
  450. margin-top: 4px;
  451. .label,
  452. .value {
  453. color: #f56c6c;
  454. font-weight: 500;
  455. }
  456. }
  457. }
  458. }
  459. }
  460. }
  461. }
  462. </style>