AddForm.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  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. <DocumentAttachmentBody
  72. ref="bodyRef"
  73. v-model="attachmentForm"
  74. :is-text-mode="isDetail"
  75. title="乙方有效证件"
  76. description="乙方:有效身份证件复印件(正反面复印)及户口本复印件(户主页和本人页)"
  77. :elder-id="dataForm.elderId"
  78. :elder-name="dataForm.elderName"
  79. fun-name="乙方有效证件"
  80. />
  81. </div>
  82. </div>
  83. <template #footer>
  84. <el-button @click="handleClosed">关闭</el-button>
  85. <el-button type="success" size="small" v-show="isDetail" @click="handlePrint"
  86. >打印/导出</el-button
  87. >
  88. <el-button
  89. style="margin-left: 22px; margin-right: 30px"
  90. v-loading="formLoading"
  91. type="primary"
  92. v-show="!isDetail"
  93. @click="submitForm"
  94. >确定</el-button
  95. >
  96. </template>
  97. </el-drawer>
  98. <Teleport to="body">
  99. <div v-if="isPrint" class="print-container">
  100. <div class="print-org-name">{{ orgName }}</div>
  101. <DocumentAttachmentBody
  102. v-model="attachmentForm"
  103. :is-text-mode="true"
  104. title="乙方有效证件"
  105. description="乙方:有效身份证件复印件(正反面复印)及户口本复印件(户主页和本人页)"
  106. :elder-id="dataForm.elderId"
  107. :elder-name="dataForm.elderName"
  108. fun-name="乙方有效证件"
  109. />
  110. </div>
  111. </Teleport>
  112. </template>
  113. <script lang="ts" setup>
  114. import { ref, reactive, computed, nextTick } from 'vue'
  115. import dayjs from 'dayjs'
  116. import DocumentAttachmentBody from '../components/DocumentAttachmentBody.vue'
  117. import { useUserStore } from '@/store/modules/user'
  118. import { findLabelById } from '@/utils/dict'
  119. import {
  120. partyBIdentificationDocument_create,
  121. partyBIdentificationDocument_update,
  122. partyBIdentificationDocument_getById
  123. } from '@/api/elderly/contracts'
  124. const message = useMessage()
  125. const { t } = useI18n()
  126. const userStore = useUserStore()
  127. const title = ref('')
  128. const dialogVisible = ref(false)
  129. const formLoading = ref(false)
  130. const selectElderRef = ref()
  131. const bodyRef = ref()
  132. const isDetail = ref(false)
  133. const isPrint = ref(false)
  134. const orgName = computed(
  135. () =>
  136. findLabelById(userStore.getOrgTenant?.options || [], dataForm.value.tenantId) ||
  137. userStore.getTenantName ||
  138. ''
  139. )
  140. let dataForm = ref({
  141. id: undefined,
  142. elderName: '',
  143. elderId: '',
  144. bedNumber: '',
  145. checkInTime: '',
  146. contractNumber: '',
  147. tenantId: undefined
  148. })
  149. const elderUp = (e) => {
  150. dataForm.value.elderName = e.elderName
  151. dataForm.value.elderId = e.id
  152. dataForm.value.bedNumber = e.bedName || ''
  153. dataForm.value.checkInTime = e.checkInTime
  154. dataForm.value.contractNumber = e.contractNumber || e.fileNumber
  155. attachmentForm.value.elderName = e.elderName
  156. }
  157. const attachmentForm = ref({
  158. elderName: '',
  159. images: []
  160. })
  161. const form = reactive({
  162. recorder: '',
  163. recordDate: ''
  164. })
  165. const open = async (tenantId, id?: any, detail: boolean = false) => {
  166. resetForm()
  167. dialogVisible.value = true
  168. dataForm.value.tenantId = tenantId
  169. isDetail.value = detail
  170. if (id) {
  171. title.value = detail ? '详情-乙方有效证件' : '编辑-乙方有效证件'
  172. dataForm.value.id = id
  173. await loadAttachmentData(id)
  174. } else {
  175. title.value = '新增-乙方有效证件'
  176. }
  177. }
  178. const loadAttachmentData = async (id: number) => {
  179. try {
  180. const res = await partyBIdentificationDocument_getById(id)
  181. if (res) {
  182. dataForm.value.elderName = res.elderName || ''
  183. dataForm.value.elderId = res.elderId || ''
  184. dataForm.value.bedNumber = res.bedNumber || ''
  185. form.recorder = res.recorder || ''
  186. form.recordDate = res.recordDate ? dayjs(res.recordDate).toDate() : ''
  187. if (res.content) {
  188. try {
  189. const contentData = JSON.parse(res.content)
  190. attachmentForm.value = { ...attachmentForm.value, ...contentData }
  191. } catch (e) {
  192. console.error('解析乙方有效证件内容失败', e)
  193. }
  194. }
  195. await selectElderRef.value?.upData(res.elderName, res.elderId)
  196. }
  197. } catch (error) {
  198. message.error('加载数据失败')
  199. }
  200. }
  201. defineExpose({ open })
  202. const emit = defineEmits(['success'])
  203. const submitForm = async () => {
  204. if (formLoading.value) {
  205. return
  206. }
  207. formLoading.value = true
  208. try {
  209. const bodyForm = bodyRef.value?.form || attachmentForm.value
  210. const content = JSON.stringify({ ...bodyForm })
  211. const tempParams = {
  212. id: dataForm.value.id,
  213. elderId: dataForm.value.elderId,
  214. elderName: dataForm.value.elderName,
  215. bedNumber: dataForm.value.bedNumber,
  216. recorder: form.recorder,
  217. recordDate: form.recordDate ? dayjs(form.recordDate).format('YYYY-MM-DD') : '',
  218. content: content,
  219. signYi: '',
  220. signBing: '',
  221. signDate: '',
  222. tenantId: dataForm.value.tenantId
  223. }
  224. let res
  225. if (dataForm.value.id) {
  226. res = await partyBIdentificationDocument_update(tempParams)
  227. } else {
  228. res = await partyBIdentificationDocument_create(tempParams)
  229. }
  230. if (res) {
  231. message.success(dataForm.value.id ? t('common.updateSuccess') : t('common.createSuccess'))
  232. dialogVisible.value = false
  233. emit('success')
  234. }
  235. } finally {
  236. setTimeout(() => {
  237. formLoading.value = false
  238. }, 500)
  239. }
  240. }
  241. const resetForm = () => {
  242. dataForm.value = {
  243. id: undefined,
  244. elderName: '',
  245. elderId: '',
  246. bedNumber: '',
  247. checkInTime: '',
  248. contractNumber: '',
  249. tenantId: undefined
  250. }
  251. form.recorder = ''
  252. form.recordDate = ''
  253. attachmentForm.value = {
  254. elderName: '',
  255. images: []
  256. }
  257. }
  258. const handleClosed = () => {
  259. dialogVisible.value = false
  260. resetForm()
  261. }
  262. const handlePrint = async () => {
  263. isPrint.value = true
  264. await nextTick()
  265. await new Promise((resolve) => setTimeout(resolve, 1500))
  266. window.print()
  267. setTimeout(() => {
  268. isPrint.value = false
  269. }, 500)
  270. }
  271. </script>
  272. <style scoped lang="scss">
  273. .form-title {
  274. text-align: center;
  275. font-size: 20px;
  276. width: 100%;
  277. margin-bottom: 20px;
  278. }
  279. .attack-risk-form {
  280. max-width: 1200px;
  281. margin: 0 auto;
  282. background: #fff;
  283. .form-body {
  284. border: 1px solid #333;
  285. padding: 15px;
  286. }
  287. }
  288. .row {
  289. margin-bottom: 12px;
  290. display: flex;
  291. flex-direction: row;
  292. align-items: center;
  293. text {
  294. text-align: right;
  295. margin-right: 4px;
  296. width: 82px;
  297. }
  298. }
  299. </style>
  300. <style lang="scss">
  301. .print-container {
  302. display: none;
  303. }
  304. @media print {
  305. html,
  306. body {
  307. background: #fff !important;
  308. margin: 0 !important;
  309. padding: 0 !important;
  310. overflow: visible !important;
  311. }
  312. body > *:not(.print-container) {
  313. display: none !important;
  314. }
  315. body > .print-container {
  316. display: block !important;
  317. }
  318. .print-container .print-org-name {
  319. text-align: start;
  320. font-size: 14px;
  321. margin-bottom: 12px;
  322. }
  323. .print-container > *:not(.print-org-name) {
  324. width: 210mm !important;
  325. max-width: none !important;
  326. margin: 0 !important;
  327. padding: 0 !important;
  328. box-sizing: border-box !important;
  329. }
  330. @page {
  331. size: 210mm 297mm;
  332. margin: 16mm;
  333. }
  334. }
  335. </style>