plat_cage_applications.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. <template>
  2. <div class="facilities-dialog-container">
  3. <van-cell-group>
  4. <van-cell
  5. title="申请人姓名"
  6. :value="state.form.userName"
  7. />
  8. <van-cell
  9. title="课题名称"
  10. :value="state.form.projectGroupName"
  11. />
  12. <van-cell
  13. title="申请时间"
  14. :value="state.form.createdTime"
  15. />
  16. <van-cell
  17. title="申请状态"
  18. :value="state.form.approveStatus"
  19. />
  20. <van-cell
  21. title="申请笼位(个)"
  22. :value="state.form.number"
  23. />
  24. <van-cell title="开始使用时间">
  25. <template #value>
  26. <span>{{ dayjs(state.form.startDate).format('YYYY-MM-DD') }}</span>
  27. </template>
  28. </van-cell>
  29. <van-cell
  30. title="动物类别"
  31. :value="state.form.categoryName"
  32. />
  33. <van-cell
  34. title="品种品系"
  35. :value="state.form.variety"
  36. />
  37. <van-cell title="饲养区域" :value="LeavelList.find(i => i.id === state.form.level)?.name || '未选择'"/>
  38. <van-cell
  39. title="采购渠道"
  40. :value="checkProcurementChannels"
  41. />
  42. <van-cell
  43. title="雄性数量(只)"
  44. :value="state.form.maleNumber"
  45. />
  46. <van-cell
  47. title="雌性数量(只)"
  48. :value="state.form.famaleNumber"
  49. />
  50. <van-cell
  51. title="动物体重(g)"
  52. :value="state.form.weight.min === state.form.weight.max ? state.form.weight.max : `${state.form.weight.min} - ${state.form.weight.max}`"
  53. />
  54. <van-cell
  55. title="动物周龄(w)"
  56. :value="state.form.age.min === state.form.age.max ? state.form.age.max : `${state.form.age.min} - ${state.form.age.max}`"
  57. />
  58. <van-cell
  59. title="饲养总天数"
  60. :value="state.form.feedingDay"
  61. />
  62. <van-cell title="动物到达时间">
  63. <template #value>
  64. <span>{{ dayjs(state.form.comeTime).format('YYYY-MM-DD') }}</span>
  65. </template>
  66. </van-cell>
  67. <van-cell
  68. title="是否有特殊饲养要求"
  69. :value="checkSpecialFeedingRequirements"
  70. />
  71. <van-cell
  72. v-if="state.form.hasFeedingSpecial === FeedingSpecial.HAVE_FEEDING_SPECIAL"
  73. title="饲养要求描述"
  74. :value="state.form.feedingSpecialDesc"
  75. />
  76. <van-cell
  77. v-if="state.form.buyFrom==='20'"
  78. title="外购来源单位"
  79. :value="state.form.comeFromUnit"
  80. />
  81. <van-cell
  82. v-if="state.form.licenseNumberFile && state.form.buyFrom==='20'"
  83. title="生产许可证"
  84. >
  85. <template #value>
  86. <a
  87. :href="parseFileInfo(state.form.licenseNumberFile).url"
  88. target="_blank"
  89. class="file-link"
  90. >
  91. {{ parseFileInfo(state.form.licenseNumberFile).name }}
  92. </a>
  93. </template>
  94. </van-cell>
  95. <van-cell
  96. v-if="state.form.animalTestDateFile && state.form.buyFrom==='20'"
  97. title="近三月动物质量检测"
  98. >
  99. <template #value>
  100. <a
  101. :href="parseFileInfo(state.form.animalTestDateFile).url"
  102. target="_blank"
  103. class="file-link"
  104. >
  105. {{ parseFileInfo(state.form.animalTestDateFile).name }}
  106. </a>
  107. </template>
  108. </van-cell>
  109. <van-cell
  110. v-if="state.form.geneIdentificationFile && state.form.buyFrom==='20'"
  111. title="基因鉴定报告"
  112. >
  113. <template #value>
  114. <a
  115. :href="parseFileInfo(state.form.geneIdentificationFile).url"
  116. target="_blank"
  117. class="file-link"
  118. >
  119. {{ parseFileInfo(state.form.geneIdentificationFile).name }}
  120. </a>
  121. </template>
  122. </van-cell>
  123. <van-cell
  124. v-if="state.form.ethicsCheckFile"
  125. title="伦理审查表"
  126. >
  127. <template #value>
  128. <a
  129. :href="parseFileInfo(state.form.ethicsCheckFile).url"
  130. target="_blank"
  131. class="file-link"
  132. >
  133. {{ parseFileInfo(state.form.ethicsCheckFile).name }}
  134. </a>
  135. </template>
  136. </van-cell>
  137. <van-cell
  138. v-if="state.form.ethicsAdviceFile"
  139. title="伦理意见表"
  140. >
  141. <template #value>
  142. <a
  143. :href="parseFileInfo(state.form.ethicsAdviceFile).url"
  144. target="_blank"
  145. class="file-link"
  146. >
  147. {{ parseFileInfo(state.form.ethicsAdviceFile).name }}
  148. </a>
  149. </template>
  150. </van-cell>
  151. </van-cell-group>
  152. </div>
  153. </template>
  154. <script setup lang="ts" name="systemProDialog">
  155. import to from 'await-to-js'
  156. import { nextTick, reactive, watch, computed } from 'vue'
  157. import dayjs from 'dayjs'
  158. import { usePlatAnimalCageApplicationApi } from '/@/api/platform/animal'
  159. import { ProcurementChannels, FeedingSpecial } from '/@/constants/pageConstants'
  160. const checkProcurementChannels = computed(() => {
  161. return state.form.buyFrom === ProcurementChannels.PURCHASED_BY_OTHERS ? '动物房代购' : '自行购买'
  162. })
  163. const checkSpecialFeedingRequirements = computed(() => {
  164. return state.form.hasFeedingSpecial === FeedingSpecial.HAVE_FEEDING_SPECIAL ? '有' : '无'
  165. })
  166. // 定义子组件向父组件传值/事件
  167. const props = defineProps({
  168. code: { type: String, default: '' },
  169. })
  170. const approveStatusList = [
  171. {
  172. name: '待提交',
  173. id: 10,
  174. },
  175. {
  176. name: '审批中',
  177. id: 20,
  178. },
  179. {
  180. name: '通过',
  181. id: 30,
  182. },
  183. {
  184. name: '撤回',
  185. id: 35,
  186. },
  187. {
  188. name: '拒绝',
  189. id: 40,
  190. },
  191. ]
  192. const LeavelList = [
  193. { name: '普通级', id: 1 },
  194. { name: 'SPF级', id: 3 },
  195. // { name: '无菌级', id: 4 },
  196. ]
  197. // 解析范围字段
  198. const parseRangeField = (str: string) => {
  199. try {
  200. if (!str) return { min: 0, max: 0 };
  201. // 处理双重转义的情况
  202. const cleanStr = str.replace(/\\"/g, '"').replace(/^"|"$/g, '');
  203. const parsed = JSON.parse(cleanStr);
  204. return {
  205. min: parsed.min || 0,
  206. max: parsed.max || 0
  207. };
  208. } catch (e) {
  209. console.warn('解析范围字段失败:', str, e);
  210. return { min: 0, max: 0 };
  211. }
  212. };
  213. const platAnimalCageApplicationApi = usePlatAnimalCageApplicationApi()
  214. const state = reactive({
  215. form: {
  216. userName: '',
  217. number: 0,
  218. approveStatus: '',
  219. categoryName: '',
  220. variety: '',
  221. projectGroupName: '',
  222. createdTime: '',
  223. maleNumber: 0,
  224. famaleNumber: 0,
  225. weight: { min: null, max: null },
  226. age: { min: null, max: null },
  227. feedingDay: 0,
  228. buyFrom: '',
  229. comeTime: '',
  230. comeFromUnit: '',
  231. hasFeedingSpecial: '',
  232. feedingSpecialDesc: '',
  233. licenseNumberFile: '',
  234. animalTestDateFile: '',
  235. envTestDateFile: '',
  236. cageAppointFile: '',
  237. ethicsCheckFile: '',
  238. ethicsAdviceFile: '',
  239. geneIdentificationFile: '',
  240. startDate: '',
  241. level: '',
  242. },
  243. disabled: false,
  244. })
  245. // 解析附件字段,返回 { name, url }
  246. const parseFileInfo = (file: any): { name: string; url: string } => {
  247. const info = { name: '', url: '' }
  248. if (!file) return info
  249. try {
  250. if (typeof file === 'string') {
  251. const trimmed = file.trim()
  252. if ((trimmed.startsWith('{') && trimmed.endsWith('}')) || (trimmed.startsWith('[') && trimmed.endsWith(']'))) {
  253. const data = JSON.parse(trimmed)
  254. const pick = (d: any) => ({
  255. name: d?.name || d?.fileName || d?.originalName || d?.filename || '',
  256. url: d?.url || d?.fileUrl || d?.path || d?.filePath || '',
  257. })
  258. if (Array.isArray(data)) {
  259. const first = data[0] || {}
  260. return pick(first)
  261. }
  262. return pick(data)
  263. }
  264. // 普通字符串:可能是 URL 或文件名
  265. if (/^https?:\/\//.test(trimmed) || trimmed.includes('/') || trimmed.includes('\\')) {
  266. const segs = trimmed.split(/[\\\/]/)
  267. info.name = segs[segs.length - 1] || trimmed
  268. info.url = trimmed
  269. } else {
  270. info.name = trimmed
  271. }
  272. return info
  273. }
  274. if (typeof file === 'object') {
  275. info.name = file?.name || file?.fileName || file?.originalName || file?.filename || ''
  276. info.url = file?.url || file?.fileUrl || file?.path || file?.filePath || ''
  277. return info
  278. }
  279. } catch (e) {
  280. const s = String(file)
  281. const segs = s.split(/[\\\/]/)
  282. info.name = segs[segs.length - 1] || s
  283. info.url = s
  284. }
  285. return info
  286. }
  287. // 打开弹窗
  288. const initForm = async (code: string) => {
  289. const [err, res]: ToResponse = await to(platAnimalCageApplicationApi.getEntityById({ id: parseInt(code) }))
  290. if (err) return
  291. await nextTick()
  292. // 处理范围字段的JSON字符串
  293. const processedRow = {
  294. ...res?.data,
  295. age: parseRangeField(res?.data?.age),
  296. weight: parseRangeField(res?.data?.weight)
  297. };
  298. state.form = {
  299. ...processedRow,
  300. approveStatus: approveStatusList.find((item) => item.id == res?.data?.approveStatus)?.name,
  301. createdTime: dayjs(res?.data?.createdTime).format('YYYY-MM-DD'),
  302. }
  303. }
  304. watch(
  305. () => props.code,
  306. (val) => {
  307. initForm(val)
  308. },
  309. {
  310. deep: true,
  311. immediate: true,
  312. },
  313. )
  314. // 暴露变量
  315. defineExpose({
  316. initForm,
  317. })
  318. </script>
  319. <style lang="scss" scoped>
  320. .file-link {
  321. color: #1989fa;
  322. text-decoration: underline;
  323. }
  324. </style>