MaterialTable.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  1. <template>
  2. <div class="material-table">
  3. <el-table :data="tableData" border :max-height="600">
  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="material-group">
  8. <div class="material-row" style="margin-bottom:10px;">
  9. <el-select v-model="row.consumableId" placeholder="请选择" @change="changeConsumableSelect">
  10. <el-option v-for="pn in suppliesList" :key="pn.id" :label="pn.suppliesName"
  11. :value="pn.id+'_'+row.sn"></el-option>
  12. </el-select>
  13. </div>
  14. </div>
  15. </template>
  16. </el-table-column>
  17. <el-table-column label="规格" width="100" align="center">
  18. <template #default="{row}">
  19. <div class="spec-group">
  20. <span>{{ row.specification }}</span>
  21. </div>
  22. </template>
  23. </el-table-column>
  24. <el-table-column label="用量/次" width="200" align="center">
  25. <template #default="{row}">
  26. <div class="dosage-group">
  27. <div class="dosage-input">
  28. <el-input v-model="row.dosePerTime" placeholder="请输入" class="input-center" @input="dosePerTimeInput(row.dosePerTime,row.sn)">
  29. <template #append>袋</template>
  30. </el-input>
  31. </div>
  32. </div>
  33. </template>
  34. </el-table-column>
  35. <el-table-column label="频次" width="100" align="center">
  36. <template #default="{row}">
  37. <span>一天{{row.frequency}}次</span>
  38. </template>
  39. </el-table-column>
  40. <el-table-column label="用量/日" width="100" align="center">
  41. <template #default="{row}">
  42. <span>{{ row.dosePerDay }}</span>
  43. <span class="unit">袋</span>
  44. </template>
  45. </el-table-column>
  46. <el-table-column label="使用天数" width="100" align="center">
  47. <template #default="{row}">
  48. <span>{{ row.usageDays }}天</span>
  49. </template>
  50. </el-table-column>
  51. <el-table-column label="首日" width="80" align="center">
  52. <template #default="{row}">
  53. <span>{{ row.firstDay }}次</span>
  54. </template>
  55. </el-table-column>
  56. <el-table-column label="数量" width="80" align="center">
  57. <template #default="{row}">
  58. <span>{{ row.quantity }}袋</span>
  59. </template>
  60. </el-table-column>
  61. <el-table-column label="处方备注" width="200" align="center">
  62. <template #default="{row}">
  63. <el-input v-model="row.prescriptionRemark" :maxlength="100" :show-word-limit="true" @change="prescriptionRemark"/>
  64. </template>
  65. </el-table-column>
  66. <el-table-column label="金额" width="80" align="center">
  67. <template #default="{row}">
  68. <span>{{ row.amount }}</span>
  69. </template>
  70. </el-table-column>
  71. </el-table>
  72. <div class="table-footer">
  73. <div class="left-buttons">
  74. <el-button type="primary" plain>登为个人模板</el-button>
  75. <el-button type="primary" plain>批量添加营养品</el-button>
  76. <el-button type="primary" plain>处方模板</el-button>
  77. </div>
  78. <div class="right-summary">
  79. <div class="summary-list">
  80. <div class="summary-item">
  81. <span class="label">处方费用:</span>
  82. <span class="value">¥{{ nutritionalFee + otherlFee }}</span>
  83. </div>
  84. <div class="summary-item">
  85. <span class="label">营养配置费:</span>
  86. <span class="value">¥{{ prescriptionFee }}</span>
  87. </div>
  88. <div class="summary-item total">
  89. <span class="label">总计:</span>
  90. <span class="value">¥{{ totalFee+otherlFee }}</span>
  91. </div>
  92. </div>
  93. </div>
  94. </div>
  95. </div>
  96. </template>
  97. <script setup lang="ts">
  98. import {ref,defineProps} from 'vue';
  99. import { listAll } from '@/api/warehouse/suppliesManage';
  100. import { SuppliesManageVO } from '@/api/warehouse/suppliesManage/types';
  101. import { listNutritionConsumable, getNutritionConsumable, delNutritionConsumable, addNutritionConsumable, updateNutritionConsumable } from '@/api/patients/nutritionConsumable';
  102. import {NutritionConsumableForm } from '@/api/patients/nutritionConsumable/types';
  103. let prescriptionFee=ref(1.0);
  104. let nutritionalFee=ref(0.0);
  105. let otherlFee=ref(0.0);
  106. let totalFee=ref(1.0);
  107. const emit = defineEmits(['change']);
  108. const prop=defineProps({
  109. modelValue: {
  110. type: String,
  111. default: () => undefined
  112. },
  113. });
  114. interface TableRow extends NutritionConsumableForm {
  115. sn?: number;
  116. tableId?: number;
  117. }
  118. // 示例数据
  119. const tableData = ref<TableRow[]>([
  120. {
  121. firstDay: 1,
  122. frequency: 3,
  123. dosePerTime: 1,
  124. dosePerDay: 3,
  125. usageDays: 1,
  126. quantity: 1,
  127. sn: 0,
  128. tableId: 0
  129. }
  130. ]);
  131. let suppliesList=ref<SuppliesManageVO[]>([]);
  132. const getSuppliesList = async () => {
  133. const res = await listAll();
  134. suppliesList.value = res.rows;
  135. }
  136. const changeConsumableSelect = async (id: string) => {
  137. let arr=id.split('_');
  138. for (let item of suppliesList.value) {
  139. let row = tableData.value[Number(arr[1])];
  140. if (item.id.toString() != arr[0]) {
  141. otherlFee.value+=item.sellPrice * row.quantity;;
  142. continue
  143. }
  144. let dosePerTime = 0;
  145. if (row.dosePerTime) {
  146. dosePerTime = row.dosePerTime;
  147. }
  148. row.specification=item.suppliesSpec;
  149. row.dosePerDay = row.frequency * dosePerTime;
  150. row.quantity = ((row.usageDays - 1) * row.frequency + row.firstDay) * dosePerTime;
  151. if (row.consumableId) {
  152. let consumableId = row.consumableId.split('_')[0];
  153. for (let item of suppliesList.value) {
  154. if (item.id.toString() != consumableId) {
  155. continue
  156. }
  157. row.amount = item.sellPrice * row.quantity;
  158. break;
  159. }
  160. }
  161. break;
  162. }
  163. otherlFee.value=0;
  164. tableData.value.forEach(row => {
  165. if(row.amount){
  166. otherlFee.value+=row.amount;
  167. }
  168. });
  169. emit('change',JSON.stringify(tableData.value))
  170. };
  171. watch(
  172. () => prop.modelValue,
  173. async (val: string) => {
  174. if (!val || val.trim().length == 0) {
  175. return;
  176. }
  177. let configData = JSON.parse(val);
  178. let tableDataMap = {}
  179. tableData.value.forEach((item: any) => {
  180. tableDataMap[item.tableId] = item;
  181. });
  182. const newTableList = ref<TableRow[]>([]);
  183. prescriptionFee.value = 0;
  184. totalFee.value = 0;
  185. otherlFee.value = 0;
  186. nutritionalFee.value = 0;
  187. prescriptionFee.value+=configData.length;
  188. totalFee.value+=configData.length;
  189. configData.forEach((item: any) => {
  190. item.products.forEach(pd => {
  191. if (pd.amount) {
  192. nutritionalFee.value += pd.amount;
  193. totalFee.value += pd.amount;
  194. }
  195. });
  196. let row: TableRow = {
  197. frequency: Number(item.frequency),
  198. usageDays: Number(item.usageDays),
  199. firstDay: Number(item.firstDay),
  200. dosePerTime: 1,
  201. tableId: item.tableId,
  202. sn: newTableList.value.length
  203. };
  204. let tmpData = tableDataMap[item.tableId];
  205. if (tmpData) {
  206. row = tmpData;
  207. }
  208. let dosePerTime=0;
  209. if (row.dosePerTime) {
  210. dosePerTime = row.dosePerTime;
  211. }
  212. row.frequency = Number(item.frequency);
  213. row.usageDays = Number(item.usageDays);
  214. row.firstDay = Number(item.firstDay);
  215. row.dosePerDay = item.frequency * dosePerTime;
  216. row.quantity = ((row.usageDays - 1) * row.frequency + row.firstDay) * dosePerTime;
  217. if (row.consumableId) {
  218. let consumableId = row.consumableId.split('_')[0];
  219. for (let item of suppliesList.value) {
  220. if (item.id.toString() != consumableId) {
  221. continue
  222. }
  223. row.amount = item.sellPrice * row.quantity;
  224. break;
  225. }
  226. }
  227. if(row.amount){
  228. otherlFee.value+=row.amount;
  229. }
  230. newTableList.value.push(row);
  231. });
  232. tableData.value = newTableList.value;
  233. emit('change', JSON.stringify(tableData.value));
  234. },
  235. { deep: true, immediate: true }
  236. );
  237. const dosePerTimeInput = (value: string, sn: number) => {
  238. let row = tableData.value[sn];
  239. let dosePerTime=0;
  240. if (row.dosePerTime) {
  241. dosePerTime=row.dosePerTime;
  242. }
  243. row.dosePerDay = row.frequency * dosePerTime;
  244. row.quantity = ((row.usageDays - 1) * row.frequency + row.firstDay) * dosePerTime;
  245. otherlFee.value=0;
  246. if (row.consumableId) {
  247. let consumableId = row.consumableId.split('_')[0];
  248. for (let item of suppliesList.value) {
  249. if (item.id.toString() != consumableId) {
  250. otherlFee.value+=item.sellPrice * row.quantity;
  251. continue
  252. }
  253. row.amount = item.sellPrice * row.quantity;
  254. otherlFee.value+=row.amount;
  255. break;
  256. }
  257. }
  258. otherlFee.value=0;
  259. tableData.value.forEach(row => {
  260. if(row.amount){
  261. otherlFee.value+=row.amount;
  262. }
  263. });
  264. emit('change', JSON.stringify(tableData.value))
  265. };
  266. const prescriptionRemark = (value: string) => {
  267. emit('change',JSON.stringify(tableData.value))
  268. };
  269. onMounted(() => {
  270. getSuppliesList();
  271. });
  272. </script>
  273. <style lang="scss" scoped>
  274. .material-table {
  275. :deep(.el-table) {
  276. // 表头样式
  277. .el-table__header {
  278. th {
  279. background-color: #f5f7fa;
  280. color: #606266;
  281. font-weight: 500;
  282. padding: 8px 0;
  283. height: 40px;
  284. }
  285. }
  286. // 表格行样式
  287. .el-table__row {
  288. td {
  289. padding: 4px 8px;
  290. }
  291. }
  292. }
  293. // 耗材输入框组样式
  294. .material-group {
  295. display: flex;
  296. flex-direction: column;
  297. gap: 8px;
  298. .material-row {
  299. display: flex;
  300. align-items: center;
  301. gap: 8px;
  302. .el-input {
  303. flex: 1;
  304. }
  305. }
  306. }
  307. // 规格组样式
  308. .spec-group {
  309. display: flex;
  310. flex-direction: column;
  311. gap: 20px;
  312. padding: 8px 0;
  313. span {
  314. color: #606266;
  315. font-size: 14px;
  316. }
  317. }
  318. // 用量输入框组样式
  319. .dosage-group {
  320. display: flex;
  321. flex-direction: column;
  322. gap: 8px;
  323. .dosage-input {
  324. display: flex;
  325. align-items: center;
  326. justify-content: center;
  327. gap: 4px;
  328. .input-center {
  329. width: 100px;
  330. :deep(.el-input__inner) {
  331. text-align: center;
  332. }
  333. }
  334. .unit {
  335. color: #909399;
  336. font-size: 14px;
  337. flex-shrink: 0;
  338. }
  339. }
  340. }
  341. // 餐次时间样式
  342. .time-slots {
  343. display: flex;
  344. flex-direction: column;
  345. gap: 8px;
  346. .time-row {
  347. display: flex;
  348. gap: 8px;
  349. .time-group {
  350. display: flex;
  351. align-items: center;
  352. gap: 4px;
  353. :deep(.el-checkbox) {
  354. margin-right: 0;
  355. .el-checkbox__label {
  356. display: none;
  357. }
  358. }
  359. :deep(.el-time-select) {
  360. .el-input {
  361. width: 120px;
  362. }
  363. .el-input__wrapper {
  364. padding: 0 8px;
  365. border-radius: 2px;
  366. box-shadow: 0 0 0 1px #dcdfe6 inset;
  367. &:hover:not(.is-disabled) {
  368. box-shadow: 0 0 0 1px #c0c4cc inset;
  369. }
  370. &.is-disabled {
  371. background-color: #f5f7fa;
  372. box-shadow: 0 0 0 1px #e4e7ed inset;
  373. .el-input__inner {
  374. color: #909399;
  375. -webkit-text-fill-color: #909399;
  376. }
  377. }
  378. }
  379. .el-input__inner {
  380. height: 32px;
  381. text-align: center;
  382. font-size: 14px;
  383. color: #606266;
  384. }
  385. }
  386. }
  387. }
  388. }
  389. // 操作按钮样式
  390. :deep(.el-button--link) {
  391. height: 28px;
  392. padding: 0 8px;
  393. font-size: 13px;
  394. &.el-button--primary {
  395. color: var(--el-color-primary);
  396. &:hover {
  397. color: var(--el-color-primary-light-3);
  398. }
  399. }
  400. &.el-button--danger {
  401. color: var(--el-color-danger);
  402. &:hover {
  403. color: var(--el-color-danger-light-3);
  404. }
  405. }
  406. }
  407. .table-footer {
  408. display: flex;
  409. justify-content: space-between;
  410. align-items: flex-start;
  411. margin-top: 16px;
  412. .left-buttons {
  413. display: flex;
  414. gap: 12px;
  415. .el-button {
  416. height: 32px;
  417. padding: 0 16px;
  418. font-size: 14px;
  419. }
  420. }
  421. .right-summary {
  422. min-width: 200px;
  423. .summary-list {
  424. display: flex;
  425. flex-direction: column;
  426. align-items: flex-end;
  427. gap: 4px;
  428. .summary-item {
  429. display: flex;
  430. align-items: center;
  431. justify-content: flex-end;
  432. gap: 8px;
  433. text-align: right;
  434. .label {
  435. font-size: 16px;
  436. color: #606266;
  437. }
  438. .value {
  439. font-size: 20px;
  440. color: #606266;
  441. min-width: 80px;
  442. text-align: right;
  443. }
  444. &.total {
  445. margin-top: 4px;
  446. .label,
  447. .value {
  448. color: #f56c6c;
  449. font-weight: 500;
  450. }
  451. }
  452. }
  453. }
  454. }
  455. }
  456. }
  457. </style>