ConfigureTable.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  1. <template>
  2. <div class="nutrition-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" style="margin-bottom: 5px">
  9. <el-select v-model="product.nutritionProductId" placeholder="请选择" @change="changeProductSelect">
  10. <el-option
  11. v-for="pn in productNutritionList"
  12. :key="pn.id"
  13. :label="pn.productName"
  14. :value="pn.id + '_' + row.sn + '_' + index"
  15. ></el-option>
  16. </el-select>
  17. <div class="action-buttons">
  18. <el-button class="icon-btn" @click="addProduct(row)">
  19. <el-icon>
  20. <Plus />
  21. </el-icon>
  22. </el-button>
  23. <el-button class="icon-btn" @click="removeProduct(row, index)">
  24. <el-icon>
  25. <Delete />
  26. </el-icon>
  27. </el-button>
  28. </div>
  29. </div>
  30. </div>
  31. </template>
  32. </el-table-column>
  33. <el-table-column label="用量/次" width="150" align="center">
  34. <template #default="{row}">
  35. <div class="dosage-group">
  36. <div v-for="(product, index) in row.products" :key="index" class="dosage-input">
  37. <el-input
  38. v-model="product.dosePerTime"
  39. placeholder="请输入"
  40. class="input-center"
  41. @input="dosePerTimeInput(product.dosePerTime, row.sn + '_' + index)"
  42. />
  43. <span class="unit">g</span>
  44. </div>
  45. </div>
  46. </template>
  47. </el-table-column>
  48. <el-table-column label="餐次时间" width="500">
  49. <template #default="{row}">
  50. <div class="time-slots">
  51. <div class="time-row">
  52. <div class="time-group">
  53. <el-checkbox v-model="row.timeSlots[0].checked" @change="changeTimeSelection(row.timeSlots[0].checked, row.sn)" />
  54. <el-time-select
  55. v-model="row.timeSlots[0].time"
  56. start="00:00"
  57. step="00:30"
  58. end="23:30"
  59. placeholder="选择时间"
  60. :disabled="!row.timeSlots[0].checked"
  61. />
  62. </div>
  63. <div class="time-group">
  64. <el-checkbox v-model="row.timeSlots[1].checked" @change="changeTimeSelection(row.timeSlots[1].checked, row.sn)" />
  65. <el-time-select
  66. v-model="row.timeSlots[1].time"
  67. start="00:00"
  68. step="00:30"
  69. end="23:30"
  70. placeholder="选择时间"
  71. :disabled="!row.timeSlots[1].checked"
  72. />
  73. </div>
  74. <div class="time-group">
  75. <el-checkbox v-model="row.timeSlots[2].checked" @change="changeTimeSelection(row.timeSlots[2].checked, row.sn)" />
  76. <el-time-select
  77. v-model="row.timeSlots[2].time"
  78. start="00:00"
  79. step="00:30"
  80. end="23:30"
  81. placeholder="选择时间"
  82. :disabled="!row.timeSlots[2].checked"
  83. />
  84. </div>
  85. </div>
  86. <div class="time-row">
  87. <div class="time-group">
  88. <el-checkbox v-model="row.timeSlots[3].checked" @change="changeTimeSelection(row.timeSlots[3].checked, row.sn)" />
  89. <el-time-select
  90. v-model="row.timeSlots[3].time"
  91. start="00:00"
  92. step="00:30"
  93. end="23:30"
  94. placeholder="选择时间"
  95. :disabled="!row.timeSlots[3].checked"
  96. />
  97. </div>
  98. <div class="time-group">
  99. <el-checkbox v-model="row.timeSlots[4].checked" @change="changeTimeSelection(row.timeSlots[4].checked, row.sn)" />
  100. <el-time-select
  101. v-model="row.timeSlots[4].time"
  102. start="00:00"
  103. step="00:30"
  104. end="23:30"
  105. placeholder="选择时间"
  106. :disabled="!row.timeSlots[4].checked"
  107. />
  108. </div>
  109. <div class="time-group">
  110. <el-checkbox v-model="row.timeSlots[5].checked" @change="changeTimeSelection(row.timeSlots[5].checked, row.sn)" />
  111. <el-time-select
  112. v-model="row.timeSlots[5].time"
  113. start="00:00"
  114. step="00:30"
  115. end="23:30"
  116. placeholder="选择时间"
  117. :disabled="!row.timeSlots[5].checked"
  118. />
  119. </div>
  120. </div>
  121. </div>
  122. </template>
  123. </el-table-column>
  124. <el-table-column label="频次" width="120" align="center">
  125. <template #default="{row}">
  126. <span>一天{{ row.frequency }}次</span>
  127. </template>
  128. </el-table-column>
  129. <el-table-column label="首日" width="150" align="center">
  130. <template #default="{row}">
  131. <el-input v-model="row.firstDay" @input="firstDayInput(row.firstDay, row.sn)">
  132. <template #append>次</template>
  133. </el-input>
  134. </template>
  135. </el-table-column>
  136. <el-table-column label="用量/日" width="100" align="center">
  137. <template #default="{row}">
  138. <div class="daily-dosage" v-for="(product, index) in row.products" :key="index">
  139. <span>{{ product.dosePerDay }}</span>
  140. <span class="unit">{{ product.productSpecUnit }}</span>
  141. </div>
  142. </template>
  143. </el-table-column>
  144. <el-table-column label="使用天数" width="200" align="center">
  145. <template #default="{row}">
  146. <div class="daily-size">
  147. <el-input-number v-model="row.usageDays" :min="1" @change="changeUsageDays(row.usageDays, row.sn)" />
  148. </div>
  149. </template>
  150. </el-table-column>
  151. <el-table-column label="用量/总" width="100" align="center">
  152. <template #default="{row}">
  153. <div class="daily-dosage" v-for="(product, index) in row.products" :key="index">
  154. <span>{{ product.totalDose }}</span>
  155. <span class="unit">{{ product.productSpecUnit }}</span>
  156. </div>
  157. </template>
  158. </el-table-column>
  159. <el-table-column label="规格" width="100" align="center">
  160. <template #default="{row}">
  161. <div class="daily-dosage" v-for="(product, index) in row.products" :key="index">
  162. <span>{{ product.specification }}</span>
  163. </div>
  164. </template>
  165. </el-table-column>
  166. <el-table-column label="用法" width="150" align="center">
  167. <template #default="{row}">
  168. <el-select v-model="row.usage" placeholder="请选择" @change="changeUsage(row.usage, row.sn)">
  169. <el-option v-for="dict in default_usage" :key="dict.value" :label="dict.label" :value="dict.value"></el-option>
  170. </el-select>
  171. </template>
  172. </el-table-column>
  173. <el-table-column label="制剂液量/次" width="170" align="center">
  174. <template #default="{row}">
  175. <el-input v-model="row.preparationVolumePerTime" @change="changePreparationVolumePerTime(row.preparationVolumePerTime, row.sn)">
  176. <template #append>ml</template>
  177. </el-input>
  178. </template>
  179. </el-table-column>
  180. <el-table-column label="制剂浓度/次" width="100" align="center">
  181. <template #default="{row}">
  182. <div class="daily-dosage">
  183. <span>{{ row.preparationConcentrationPerTime }}</span>
  184. <span class="unit">%</span>
  185. </div>
  186. </template>
  187. </el-table-column>
  188. <el-table-column label="能量密度/次" width="200" align="center">
  189. <template #default="{row}">
  190. <el-input v-model="row.energyDensityPerTime" @change="changeEnergyDensityPerTime(row.energyDensityPerTime, row.sn)">
  191. <template #append>kcal/ml</template>
  192. </el-input>
  193. </template>
  194. </el-table-column>
  195. <el-table-column label="处方备注" width="200" align="center">
  196. <template #default="{row}">
  197. <template v-for="(product, index) in row.products">
  198. <el-input
  199. v-model="product.prescriptionRemark"
  200. :maxlength="100"
  201. :show-word-limit="true"
  202. @change="changePrescriptionRemark(product.prescriptionRemark, row.sn)"
  203. />
  204. </template>
  205. </template>
  206. </el-table-column>
  207. <el-table-column label="每日热量" width="100" align="center">
  208. <template #default="{row}">
  209. <div class="daily-dosage" v-for="(product, index) in row.products" :key="index">
  210. <span>{{ product.dailyCalories }}</span>
  211. </div>
  212. </template>
  213. </el-table-column>
  214. <el-table-column label="金额" width="100" align="center">
  215. <template #default="{row}">
  216. <div class="daily-dosage" v-for="(product, index) in row.products" :key="index">
  217. <span>{{ product.amount }}</span>
  218. </div>
  219. </template>
  220. </el-table-column>
  221. <el-table-column label="操作" width="160" align="center" fixed="right">
  222. <template #default="{$index}">
  223. <div class="operation-cell">
  224. <el-button type="primary" link @click="copyRow($index)">复制餐次</el-button>
  225. <el-button type="danger" link @click="deleteRow($index)">删除</el-button>
  226. </div>
  227. </template>
  228. </el-table-column>
  229. </el-table>
  230. <div class="table-footer">
  231. <el-button type="primary" class="add-prescription-btn" @click="addNewRow">
  232. <el-icon>
  233. <CirclePlus />
  234. </el-icon>
  235. 开具多处方
  236. </el-button>
  237. </div>
  238. </div>
  239. </template>
  240. <script setup lang="ts">
  241. import {ref} from 'vue';
  242. import {Plus, Delete, CirclePlus} from '@element-plus/icons-vue';
  243. import {listEnteralNutrition, getEnteralNutrition, delEnteralNutrition, addEnteralNutrition, updateEnteralNutrition} from '@/api/patients/nutrition';
  244. import {EnteralNutritionVO, EnteralNutritionQuery, EnteralNutritionForm} from '@/api/patients/nutrition/types';
  245. import {listNutrition, listAllNutrition} from '@/api/warehouse/productNutrition/index';
  246. import {NutritionVO, NutritionQuery, NutritionForm} from '@/api/warehouse/productNutrition/types';
  247. const prop = defineProps({
  248. modelValue: {
  249. type: String,
  250. default: () => undefined
  251. }
  252. });
  253. watch(
  254. () => prop.modelValue,
  255. async (val: string) => {
  256. if (!val || val.trim().length == 0) {
  257. return;
  258. }
  259. let arr = JSON.parse(val);
  260. if (Array.isArray(arr) && arr.length == 0) {
  261. tableData.value = [];
  262. }
  263. },
  264. {deep: true, immediate: true}
  265. );
  266. const {proxy} = getCurrentInstance() as ComponentInternalInstance;
  267. const {default_usage} = toRefs<any>(proxy?.useDict('default_usage'));
  268. let productNutritionList = ref<NutritionVO[]>([]);
  269. let tableId = ref<number>(0);
  270. const getProductNutritionList = async () => {
  271. const res = await listAllNutrition();
  272. productNutritionList.value = res.rows;
  273. };
  274. interface TimeSlot {
  275. checked: boolean;
  276. time: string;
  277. }
  278. interface TableRow extends EnteralNutritionForm {
  279. products: EnteralNutritionForm[];
  280. timeSlots: TimeSlot[];
  281. sn: number;
  282. tableId: number;
  283. }
  284. // 创建默认行数据的函数
  285. const createDefaultRow = (): TableRow => ({
  286. products: [{specification: '', totalDose: '', dosePerDay: ''}],
  287. timeSlots: [
  288. {checked: true, time: '08:00'},
  289. {checked: false, time: '08:30'},
  290. {checked: true, time: '12:00'},
  291. {checked: false, time: '12:30'},
  292. {checked: true, time: '18:00'},
  293. {checked: false, time: '18:30'}
  294. ],
  295. usageDays: 1,
  296. frequency: 3,
  297. firstDay: 2,
  298. sn: 0,
  299. tableId: tableId.value++
  300. });
  301. const emit = defineEmits(['change']);
  302. // 示例数据
  303. const tableData = ref<TableRow[]>([createDefaultRow()]);
  304. // 新增行
  305. const addNewRow = () => {
  306. let row: TableRow = createDefaultRow();
  307. row.sn = tableData.value.length;
  308. tableData.value.push(row);
  309. emit('change', JSON.stringify(tableData.value));
  310. };
  311. const changeProductSelect = async (id: string) => {
  312. let arr = id.split('_');
  313. for (let item of productNutritionList.value) {
  314. if (item.id.toString() != arr[0]) {
  315. continue;
  316. }
  317. let row = tableData.value[Number(arr[1])];
  318. let pt = row.products[Number(arr[2])];
  319. pt.specification=item.productSpec;
  320. pt.dosePerTime=null;
  321. pt.dailyCalories=null;
  322. pt.productSpecUnit=item.productSpecUnit;
  323. pt.amount=null;
  324. row.usage=item.defaultUsage;
  325. pt.totalDose='0' ;
  326. pt.dosePerDay='0';
  327. pt.firstDay=Math.ceil(row.frequency/2.0);
  328. break;
  329. }
  330. emit('change', JSON.stringify(tableData.value));
  331. };
  332. // 新增产品输入框
  333. const addProduct = (row: TableRow) => {
  334. row.products.push({});
  335. };
  336. // 删除产品输入框
  337. const removeProduct = (row: TableRow, index: number) => {
  338. // 如果删除后只剩一个输入框,删除整行
  339. if (row.products.length <= 1) {
  340. const rowIndex = tableData.value.findIndex((item) => item === row);
  341. if (rowIndex !== -1) {
  342. tableData.value.splice(rowIndex, 1);
  343. }
  344. emit('change', JSON.stringify(tableData.value));
  345. } else {
  346. // 否则只删除当前输入框
  347. row.products.splice(index, 1);
  348. }
  349. };
  350. // 复制行
  351. const copyRow = (index: number) => {
  352. const newRow = JSON.parse(JSON.stringify(tableData.value[index]));
  353. newRow.tableId = tableId.value++;
  354. tableData.value.splice(index + 1, 0, newRow);
  355. tableData.value.forEach((item, index) => {
  356. item.sn = index;
  357. item.products.forEach((ch, idx) => {
  358. if (ch.nutritionProductId) {
  359. let arr = ch.nutritionProductId.split('_');
  360. ch.nutritionProductId = arr[0] + '_' + index + '_' + idx;
  361. }
  362. });
  363. });
  364. emit('change', JSON.stringify(tableData.value));
  365. };
  366. // 删除行
  367. const deleteRow = (index: number) => {
  368. tableData.value.splice(index, 1);
  369. tableData.value.forEach((item, index) => {
  370. item.sn = index;
  371. });
  372. emit('change', JSON.stringify(tableData.value));
  373. };
  374. const changeUsageDays = (value: string, sn: string) => {
  375. changeTimeSelection(null, sn);
  376. };
  377. const changeUsage = (value: string, sn: string) => {
  378. changeTimeSelection(null, sn);
  379. };
  380. const changePreparationVolumePerTime = (value: string, sn:string) => {
  381. changeTimeSelection(null,sn);
  382. }
  383. const changeEnergyDensityPerTime = (value: string, sn:string) => {
  384. changeTimeSelection(null,sn);
  385. }
  386. const changePrescriptionRemark = (value: string, sn: string) => {
  387. changeTimeSelection(null, sn);
  388. };
  389. const firstDayInput = (value: string, sn: string) => {
  390. changeTimeSelection(null, sn);
  391. };
  392. const changeTimeSelection = (value: string, sn: string) => {
  393. let row = tableData.value[sn];
  394. let frequency = 0;
  395. row.timeSlots.forEach((item) => {
  396. if (item.checked) {
  397. frequency++;
  398. }
  399. })
  400. row.frequency=frequency;
  401. if(value!=null){
  402. row.firstDay=Math.ceil(row.frequency/2.0);
  403. }
  404. row.products.forEach((pt) => {
  405. if (!pt.dosePerTime || pt.dosePerTime.trim().length == 0) {
  406. return;
  407. }
  408. let arr = pt.nutritionProductId.split('_');
  409. for (let item of productNutritionList.value) {
  410. if (item.id.toString() != arr[0]) {
  411. continue;
  412. }
  413. let val = (item.calorie * row.frequency * Number(pt.dosePerTime)) / 100.0;
  414. pt.dailyCalories = val.toFixed(4);
  415. let firstDay = Number(row.firstDay.toString());
  416. val = (row.frequency * (row.usageDays - 1) + firstDay) * item.configSalePrice * Number(pt.dosePerTime);
  417. pt.amount = Math.round(val * 100) / 100;
  418. val = (row.frequency * (row.usageDays - 1) + firstDay) * Number(pt.dosePerTime);
  419. pt.totalDose = val.toFixed(4);
  420. val = row.frequency * Number(pt.dosePerTime);
  421. pt.dosePerDay = val.toFixed(4);
  422. break;
  423. }
  424. });
  425. emit('change', JSON.stringify(tableData.value));
  426. };
  427. const dosePerTimeInput = (value: string, str: string) => {
  428. let arr = str.split('_');
  429. let row = tableData.value[Number(arr[0])];
  430. let pt = row.products[Number(arr[1])];
  431. if (!pt.dosePerTime || pt.dosePerTime.trim().length == 0) {
  432. pt.dailyCalories = null;
  433. pt.amount = null;
  434. return;
  435. }
  436. arr = pt.nutritionProductId.split('_');
  437. for (let item of productNutritionList.value) {
  438. if (item.id.toString() != arr[0]) {
  439. continue;
  440. }
  441. let val = (item.calorie * row.frequency * Number(pt.dosePerTime)) / 100.0;
  442. pt.dailyCalories = val.toFixed(4);
  443. let firstDay = Number(row.firstDay.toString());
  444. val = (row.frequency * (row.usageDays - 1) + firstDay) * item.configSalePrice * Number(pt.dosePerTime);
  445. pt.amount = Math.round(val * 100) / 100;
  446. val = (row.frequency * (row.usageDays - 1) + firstDay) * Number(pt.dosePerTime);
  447. pt.totalDose = val.toFixed(4);
  448. val = row.frequency * Number(pt.dosePerTime);
  449. pt.dosePerDay = val.toFixed(4);
  450. break;
  451. }
  452. emit('change', JSON.stringify(tableData.value));
  453. };
  454. onMounted(() => {
  455. getProductNutritionList();
  456. });
  457. </script>
  458. <style lang="scss" scoped>
  459. .nutrition-table {
  460. :deep(.el-table) {
  461. // 表头样式
  462. .el-table__header {
  463. th {
  464. background-color: #f5f7fa;
  465. color: #606266;
  466. font-weight: 500;
  467. padding: 8px 0;
  468. height: 40px;
  469. }
  470. }
  471. // 表格行样式
  472. .el-table__row {
  473. td {
  474. padding: 4px 8px;
  475. }
  476. }
  477. }
  478. // 产品输入框组样式
  479. .product-group {
  480. display: flex;
  481. flex-direction: column;
  482. gap: 8px;
  483. .product-row {
  484. display: flex;
  485. align-items: center;
  486. gap: 8px;
  487. .el-input {
  488. flex: 1;
  489. }
  490. .action-buttons {
  491. display: flex;
  492. gap: 1px;
  493. .icon-btn {
  494. padding: 6px;
  495. height: 32px;
  496. border: 1px solid #dcdfe6;
  497. &:hover {
  498. border-color: var(--el-color-primary);
  499. color: var(--el-color-primary);
  500. }
  501. .el-icon {
  502. font-size: 14px;
  503. }
  504. }
  505. }
  506. }
  507. }
  508. // 用量输入框组样式
  509. .dosage-group {
  510. display: flex;
  511. flex-direction: column;
  512. gap: 8px;
  513. .dosage-input {
  514. display: flex;
  515. align-items: center;
  516. justify-content: center;
  517. gap: 4px;
  518. .input-center {
  519. width: 100px;
  520. :deep(.el-input__inner) {
  521. text-align: center;
  522. }
  523. }
  524. .unit {
  525. color: #909399;
  526. font-size: 14px;
  527. flex-shrink: 0;
  528. }
  529. }
  530. }
  531. // 餐次时间样式
  532. .time-slots {
  533. display: flex;
  534. flex-direction: column;
  535. gap: 8px;
  536. .time-row {
  537. display: flex;
  538. gap: 8px;
  539. .time-group {
  540. display: flex;
  541. align-items: center;
  542. gap: 4px;
  543. :deep(.el-checkbox) {
  544. margin-right: 0;
  545. .el-checkbox__label {
  546. display: none;
  547. }
  548. }
  549. :deep(.el-time-select) {
  550. .el-input {
  551. width: 120px;
  552. }
  553. .el-input__wrapper {
  554. padding: 0 8px;
  555. border-radius: 2px;
  556. box-shadow: 0 0 0 1px #dcdfe6 inset;
  557. &:hover:not(.is-disabled) {
  558. box-shadow: 0 0 0 1px #c0c4cc inset;
  559. }
  560. &.is-disabled {
  561. background-color: #f5f7fa;
  562. box-shadow: 0 0 0 1px #e4e7ed inset;
  563. .el-input__inner {
  564. color: #909399;
  565. -webkit-text-fill-color: #909399;
  566. }
  567. }
  568. }
  569. .el-input__inner {
  570. height: 32px;
  571. text-align: center;
  572. font-size: 14px;
  573. color: #606266;
  574. }
  575. }
  576. }
  577. }
  578. }
  579. .daily-dosage,
  580. .days {
  581. display: flex;
  582. align-items: center;
  583. justify-content: center;
  584. gap: 4px;
  585. .unit {
  586. color: #909399;
  587. font-size: 14px;
  588. }
  589. }
  590. .operation-cell {
  591. display: flex;
  592. justify-content: center;
  593. gap: 12px;
  594. .el-button {
  595. padding: 4px 8px;
  596. }
  597. }
  598. .table-footer {
  599. height: 50px;
  600. border: 1px solid var(--el-table-border-color);
  601. border-top: none;
  602. display: flex;
  603. align-items: center;
  604. justify-content: center;
  605. background-color: #f5f7fa;
  606. .add-prescription-btn {
  607. display: flex;
  608. align-items: center;
  609. gap: 4px;
  610. height: 32px;
  611. padding: 0 16px;
  612. font-size: 14px;
  613. background-color: var(--el-color-primary-light-8);
  614. color: var(--el-color-primary);
  615. border: none;
  616. &:hover {
  617. background-color: var(--el-color-primary-light-9);
  618. }
  619. .el-icon {
  620. font-size: 16px;
  621. }
  622. }
  623. }
  624. .stop-date {
  625. display: flex;
  626. align-items: center;
  627. gap: 8px;
  628. margin-bottom: 16px;
  629. .required {
  630. color: #f56c6c;
  631. font-size: 14px;
  632. }
  633. .label {
  634. color: #606266;
  635. font-size: 14px;
  636. }
  637. .days {
  638. color: #f56c6c;
  639. font-size: 14px;
  640. }
  641. }
  642. }
  643. :deep(.daily-size div) {
  644. width: 100px;
  645. }
  646. </style>