AddForm.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. <template>
  2. <el-drawer
  3. v-model="dialogVisible"
  4. :title="title"
  5. resizable
  6. :close-on-click-modal="false"
  7. :close-on-press-escape="false"
  8. :destroy-on-close="true"
  9. size="70%"
  10. :before-close="handleClosed"
  11. >
  12. <div class="attack-risk-form">
  13. <h1 class="form-title">机构服务范围及收费标准(附件)</h1>
  14. <!-- 基本信息 -->
  15. <el-row :gutter="40">
  16. <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12" class="row">
  17. <text>长者姓名</text>
  18. <search-the-elderly
  19. ref="selectElderRef"
  20. :disabled="isDetail"
  21. @update_elder="elderUp"
  22. v-model="dataForm.elderName"
  23. :tId="dataForm.tenantId"
  24. />
  25. </el-col>
  26. <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12" class="row">
  27. <text>档案号</text>
  28. <el-input v-if="!isDetail" v-model="dataForm.contractNumber" disabled />
  29. <el-text v-else disabled="">{{ dataForm.contractNumber }}</el-text>
  30. </el-col>
  31. </el-row>
  32. <el-row :gutter="40">
  33. <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12" class="row">
  34. <text>入院日期</text>
  35. <el-input
  36. v-if="!isDetail"
  37. :model-value="
  38. dayjs(dataForm.checkInTime).format('YYYY-MM-DD') == 'Invalid Date'
  39. ? ''
  40. : dayjs(dataForm.checkInTime).format('YYYY-MM-DD')
  41. "
  42. disabled
  43. />
  44. <el-text v-else disabled="">{{
  45. dayjs(dataForm.checkInTime).format('YYYY-MM-DD')
  46. }}</el-text>
  47. </el-col>
  48. <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12" class="row">
  49. <text>床位号</text>
  50. <el-input v-if="!isDetail" v-model="dataForm.bedNumber" disabled />
  51. <el-text v-else disabled="">{{ dataForm.bedNumber }}</el-text>
  52. </el-col>
  53. </el-row>
  54. <el-row :gutter="40">
  55. <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12" class="row">
  56. <text>记录人</text>
  57. <el-input :disabled="isDetail" v-model="form.recorder" />
  58. </el-col>
  59. <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12" class="row">
  60. <text>记录日期</text>
  61. <el-date-picker
  62. :disabled="isDetail"
  63. v-model="form.recordDate"
  64. type="date"
  65. style="width: 100%"
  66. />
  67. </el-col>
  68. </el-row>
  69. <!-- 内容区域 -->
  70. <div class="form-body">
  71. <ServiceChargingStandardsBody
  72. ref="bodyRef"
  73. v-model="serviceChargingForm"
  74. :is-text-mode="isDetail"
  75. />
  76. </div>
  77. </div>
  78. <template #footer>
  79. <el-button @click="handleClosed">关闭</el-button>
  80. <el-button type="success" size="small" v-show="isDetail" @click="handlePrint"
  81. >打印/导出</el-button
  82. >
  83. <el-button
  84. style="margin-left: 22px; margin-right: 30px"
  85. v-loading="formLoading"
  86. type="primary"
  87. v-show="!isDetail"
  88. @click="submitForm"
  89. >确定</el-button
  90. >
  91. </template>
  92. </el-drawer>
  93. <Teleport to="body">
  94. <div v-if="isPrint" class="print-container">
  95. <div class="print-org-name">{{ orgName }}</div>
  96. <ServiceChargingStandardsBody v-model="serviceChargingForm" :is-text-mode="true" />
  97. </div>
  98. </Teleport>
  99. </template>
  100. <script lang="ts" setup>
  101. import { ref, reactive, computed, nextTick } from 'vue'
  102. import dayjs from 'dayjs'
  103. import ServiceChargingStandardsBody from '../components/ServiceChargingStandardsBody.vue'
  104. import { useUserStore } from '@/store/modules/user'
  105. import { findLabelById } from '@/utils/dict'
  106. import {
  107. serviceChargingStandards_create,
  108. serviceChargingStandards_update,
  109. serviceChargingStandards_getById
  110. } from '@/api/elderly/contracts'
  111. const message = useMessage()
  112. const { t } = useI18n()
  113. const userStore = useUserStore()
  114. const title = ref('')
  115. const dialogVisible = ref(false)
  116. const formLoading = ref(false)
  117. const selectElderRef = ref()
  118. const bodyRef = ref()
  119. const isDetail = ref(false)
  120. const isPrint = ref(false)
  121. const orgName = computed(
  122. () =>
  123. findLabelById(userStore.getOrgTenant?.options || [], dataForm.value.tenantId) ||
  124. userStore.getTenantName ||
  125. ''
  126. )
  127. let dataForm = ref({
  128. id: undefined,
  129. elderName: '',
  130. elderId: '',
  131. bedNumber: '',
  132. checkInTime: '',
  133. contractNumber: '',
  134. tenantId: undefined
  135. })
  136. const elderUp = (e) => {
  137. dataForm.value.elderName = e.elderName
  138. dataForm.value.elderId = e.id
  139. dataForm.value.bedNumber = e.bedName || ''
  140. dataForm.value.checkInTime = e.checkInTime
  141. dataForm.value.contractNumber = e.contractNumber || e.fileNumber
  142. serviceChargingForm.value.elderName = e.elderName
  143. }
  144. const serviceChargingForm = ref({
  145. elderName: '',
  146. signatorySign: '',
  147. signDate: ''
  148. })
  149. const form = reactive({
  150. recorder: '',
  151. recordDate: ''
  152. })
  153. const open = async (tenantId, id?: any, detail: boolean = false) => {
  154. resetForm()
  155. dialogVisible.value = true
  156. dataForm.value.tenantId = tenantId
  157. isDetail.value = detail
  158. if (id) {
  159. title.value = detail ? '详情-机构服务范围及收费标准' : '编辑-机构服务范围及收费标准'
  160. dataForm.value.id = id
  161. await loadServiceChargingData(id)
  162. } else {
  163. title.value = '新增-机构服务范围及收费标准'
  164. }
  165. }
  166. const loadServiceChargingData = async (id: number) => {
  167. try {
  168. const res = await serviceChargingStandards_getById(id)
  169. if (res) {
  170. dataForm.value.elderName = res.elderName || ''
  171. dataForm.value.elderId = res.elderId || ''
  172. dataForm.value.bedNumber = res.bedNumber || ''
  173. form.recorder = res.recorder || ''
  174. form.recordDate = res.recordDate ? dayjs(res.recordDate).toDate() : ''
  175. if (res.content) {
  176. try {
  177. const contentData = JSON.parse(res.content)
  178. serviceChargingForm.value = { ...serviceChargingForm.value, ...contentData }
  179. } catch (e) {
  180. console.error('解析机构服务范围及收费标准内容失败', e)
  181. }
  182. }
  183. await selectElderRef.value?.upData(res.elderName, res.elderId)
  184. }
  185. } catch (error) {
  186. message.error('加载数据失败')
  187. }
  188. }
  189. defineExpose({ open })
  190. const emit = defineEmits(['success'])
  191. const submitForm = async () => {
  192. if (formLoading.value) {
  193. return
  194. }
  195. formLoading.value = true
  196. try {
  197. const bodyForm = bodyRef.value?.form || serviceChargingForm.value
  198. const content = JSON.stringify({ ...bodyForm })
  199. const tempParams = {
  200. id: dataForm.value.id,
  201. elderId: dataForm.value.elderId,
  202. elderName: dataForm.value.elderName,
  203. bedNumber: dataForm.value.bedNumber,
  204. recorder: form.recorder,
  205. recordDate: form.recordDate ? dayjs(form.recordDate).format('YYYY-MM-DD') : '',
  206. content: content,
  207. signYi: bodyForm.signatorySign || '',
  208. signBing: '',
  209. signDate: bodyForm.signDate || '',
  210. tenantId: dataForm.value.tenantId
  211. }
  212. let res
  213. if (dataForm.value.id) {
  214. res = await serviceChargingStandards_update(tempParams)
  215. } else {
  216. res = await serviceChargingStandards_create(tempParams)
  217. }
  218. if (res) {
  219. message.success(dataForm.value.id ? t('common.updateSuccess') : t('common.createSuccess'))
  220. dialogVisible.value = false
  221. emit('success')
  222. }
  223. } finally {
  224. setTimeout(() => {
  225. formLoading.value = false
  226. }, 500)
  227. }
  228. }
  229. const resetForm = () => {
  230. dataForm.value = {
  231. id: undefined,
  232. elderName: '',
  233. elderId: '',
  234. bedNumber: '',
  235. checkInTime: '',
  236. contractNumber: '',
  237. tenantId: undefined
  238. }
  239. form.recorder = ''
  240. form.recordDate = ''
  241. serviceChargingForm.value = {
  242. elderName: '',
  243. signatorySign: '',
  244. signDate: ''
  245. }
  246. }
  247. const handleClosed = () => {
  248. dialogVisible.value = false
  249. resetForm()
  250. }
  251. const handlePrint = async () => {
  252. isPrint.value = true
  253. await nextTick()
  254. await new Promise((resolve) => setTimeout(resolve, 1500))
  255. window.print()
  256. setTimeout(() => {
  257. isPrint.value = false
  258. }, 500)
  259. }
  260. </script>
  261. <style scoped lang="scss">
  262. .form-title {
  263. text-align: center;
  264. font-size: 20px;
  265. width: 100%;
  266. margin-bottom: 20px;
  267. }
  268. .attack-risk-form {
  269. max-width: 1200px;
  270. margin: 0 auto;
  271. background: #fff;
  272. .form-body {
  273. border: 1px solid #333;
  274. padding: 15px;
  275. }
  276. }
  277. .row {
  278. margin-bottom: 12px;
  279. display: flex;
  280. flex-direction: row;
  281. align-items: center;
  282. text {
  283. text-align: right;
  284. margin-right: 4px;
  285. width: 82px;
  286. }
  287. }
  288. </style>
  289. <style lang="scss">
  290. .print-container {
  291. display: none;
  292. }
  293. @media print {
  294. html,
  295. body {
  296. background: #fff !important;
  297. margin: 0 !important;
  298. padding: 0 !important;
  299. overflow: visible !important;
  300. }
  301. body > *:not(.print-container) {
  302. display: none !important;
  303. }
  304. body > .print-container {
  305. display: block !important;
  306. }
  307. .print-container .print-org-name {
  308. text-align: start;
  309. font-size: 14px;
  310. margin-bottom: 12px;
  311. }
  312. .print-container > *:not(.print-org-name) {
  313. width: 210mm !important;
  314. max-width: none !important;
  315. margin: 0 !important;
  316. padding: 0 !important;
  317. box-sizing: border-box !important;
  318. }
  319. @page {
  320. size: 210mm 297mm;
  321. margin: 16mm;
  322. }
  323. }
  324. </style>