plat_cage_applications.vue 8.8 KB

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