1.html 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. <template>
  2. <div class="app-container">
  3. <!-- 搜索栏 -->
  4. <el-form :model="queryParams" inline class="search-form">
  5. <el-form-item label="申请人">
  6. <el-input
  7. v-model="queryParams.applicant"
  8. placeholder="请输入申请人"
  9. clearable
  10. @keyup.enter="handleSearch"
  11. />
  12. </el-form-item>
  13. <el-form-item label="状态">
  14. <el-select
  15. v-model="queryParams.status"
  16. placeholder="全部状态"
  17. clearable
  18. >
  19. <el-option
  20. v-for="item in statusOptions"
  21. :key="item.value"
  22. :label="item.label"
  23. :value="item.value"
  24. />
  25. </el-select>
  26. </el-form-item>
  27. <el-form-item>
  28. <el-button type="primary" @click="handleSearch">查询</el-button>
  29. <el-button @click="resetQuery">重置</el-button>
  30. <el-button
  31. type="primary"
  32. @click="handleCreate"
  33. v-permission="'apply:create'"
  34. >
  35. 新建申请
  36. </el-button>
  37. </el-form-item>
  38. </el-form>
  39. <!-- 数据表格 -->
  40. <el-table
  41. :data="tableData"
  42. border
  43. v-loading="loading"
  44. element-loading-text="数据加载中..."
  45. >
  46. <el-table-column prop="applyNo" label="申请单号" width="180" fixed />
  47. <el-table-column prop="applicant" label="申请人" width="120" />
  48. <el-table-column prop="applyTime" label="申请时间" width="180" sortable />
  49. <el-table-column prop="specimenName" label="标本名称" min-width="150" />
  50. <el-table-column prop="specimenNo" label="标本编号" width="120" />
  51. <el-table-column prop="purpose" label="用途" show-overflow-tooltip />
  52. <el-table-column label="附件" width="120">
  53. <template #default="{ row }">
  54. <div v-if="row.attachments?.length">
  55. <el-tooltip
  56. v-for="(file, index) in row.attachments"
  57. :key="index"
  58. :content="file.name"
  59. >
  60. <el-link
  61. type="primary"
  62. :href="file.url"
  63. target="_blank"
  64. class="file-link"
  65. >
  66. <el-icon><Document /></el-icon>
  67. </el-link>
  68. </el-tooltip>
  69. </div>
  70. <span v-else>--</span>
  71. </template>
  72. </el-table-column>
  73. <el-table-column prop="status" label="状态" width="100">
  74. <template #default="{ row }">
  75. <el-tag
  76. :type="statusStyleMap[row.status]"
  77. effect="light"
  78. >
  79. {{ statusMap[row.status] }}
  80. </el-tag>
  81. </template>
  82. </el-table-column>
  83. <el-table-column label="操作" width="150" fixed="right">
  84. <template #default="{ row }">
  85. <el-button
  86. v-if="row.status === 0"
  87. type="danger"
  88. link
  89. @click="handleWithdraw(row)"
  90. v-permission="'apply:withdraw'"
  91. >
  92. 撤回
  93. </el-button>
  94. <el-button
  95. type="primary"
  96. link
  97. @click="handleDetail(row)"
  98. >
  99. 详情
  100. </el-button>
  101. </template>
  102. </el-table-column>
  103. </el-table>
  104. <!-- 分页 -->
  105. <el-pagination
  106. v-model:current-page="queryParams.pageNum"
  107. v-model:page-size="queryParams.pageSize"
  108. :total="total"
  109. :page-sizes="[10, 20, 50, 100]"
  110. layout="total, sizes, prev, pager, next, jumper"
  111. @size-change="getList"
  112. @current-change="getList"
  113. class="pagination"
  114. />
  115. <!-- 申请弹窗 -->
  116. <el-dialog
  117. v-model="dialogVisible"
  118. :title="dialogTitle"
  119. width="600px"
  120. :close-on-click-modal="false"
  121. >
  122. <el-form
  123. ref="formRef"
  124. :model="formData"
  125. :rules="rules"
  126. label-width="100px"
  127. label-position="right"
  128. >
  129. <el-form-item label="标本选择" prop="specimenId">
  130. <el-select
  131. v-model="formData.specimenId"
  132. placeholder="请选择标本"
  133. filterable
  134. remote
  135. :remote-method="searchSpecimen"
  136. :loading="specimenLoading"
  137. style="width: 100%"
  138. >
  139. <el-option
  140. v-for="item in specimenList"
  141. :key="item.id"
  142. :label="`${item.name} (${item.number})`"
  143. :value="item.id"
  144. />
  145. </el-select>
  146. </el-form-item>
  147. <el-form-item label="用途说明" prop="purpose">
  148. <el-input
  149. v-model="formData.purpose"
  150. type="textarea"
  151. :rows="4"
  152. placeholder="请输入详细的用途说明"
  153. show-word-limit
  154. maxlength="500"
  155. />
  156. </el-form-item>
  157. <el-form-item label="附件">
  158. <el-upload
  159. v-model:file-list="fileList"
  160. action="/api/upload"
  161. multiple
  162. :limit="3"
  163. :on-exceed="handleExceed"
  164. :before-upload="beforeUpload"
  165. :on-success="handleUploadSuccess"
  166. :on-error="handleUploadError"
  167. list-type="text"
  168. >
  169. <el-button type="primary">选择文件</el-button>
  170. <template #tip>
  171. <div class="upload-tip">
  172. 支持格式:PDF/DOC/DOCX/图片,单个文件不超过10MB
  173. </div>
  174. </template>
  175. </el-upload>
  176. </el-form-item>
  177. </el-form>
  178. <template #footer>
  179. <el-button @click="dialogVisible = false">取消</el-button>
  180. <el-button
  181. type="primary"
  182. @click="submitForm"
  183. :loading="submitting"
  184. >
  185. {{ submitting ? '提交中...' : '确认提交' }}
  186. </el-button>
  187. </template>
  188. </el-dialog>
  189. </div>
  190. </template>
  191. <script setup>
  192. import { ref, reactive, onMounted } from 'vue'
  193. import { ElMessage, ElMessageBox } from 'element-plus'
  194. import { Document } from '@element-plus/icons-vue'
  195. // 状态字典
  196. const statusMap = {
  197. 0: '待审核',
  198. 1: '已通过',
  199. 2: '已驳回',
  200. 3: '已撤回'
  201. }
  202. const statusStyleMap = {
  203. 0: 'warning',
  204. 1: 'success',
  205. 2: 'danger',
  206. 3: 'info'
  207. }
  208. const statusOptions = [
  209. { label: '全部', value: '' },
  210. { label: '待审核', value: 0 },
  211. { label: '已通过', value: 1 },
  212. { label: '已驳回', value: 2 },
  213. { label: '已撤回', value: 3 }
  214. ]
  215. // 数据加载状态
  216. const loading = ref(false)
  217. const submitting = ref(false)
  218. const specimenLoading = ref(false)
  219. // 表格数据
  220. const tableData = ref([])
  221. const total = ref(0)
  222. // 查询参数
  223. const queryParams = reactive({
  224. pageNum: 1,
  225. pageSize: 10,
  226. applicant: '',
  227. status: ''
  228. })
  229. // 表单数据
  230. const formData = reactive({
  231. specimenId: '',
  232. purpose: '',
  233. attachments: []
  234. })
  235. // 标本列表
  236. const specimenList = ref([])
  237. // 文件列表
  238. const fileList = ref([])
  239. // 表单验证规则
  240. const rules = {
  241. specimenId: [
  242. { required: true, message: '请选择标本', trigger: 'blur' }
  243. ],
  244. purpose: [
  245. { required: true, message: '请输入用途说明', trigger: 'blur' },
  246. { min: 10, message: '至少输入10个字符', trigger: 'blur' }
  247. ]
  248. }
  249. // 初始化加载
  250. onMounted(() => {
  251. getList()
  252. loadSpecimenList()
  253. })
  254. // 获取申请列表
  255. const getList = async () => {
  256. try {
  257. loading.value = true
  258. // 调用API接口
  259. const res = await fetchApplications(queryParams)
  260. tableData.value = res.data.list
  261. total.value = res.data.total
  262. } catch (error) {
  263. ElMessage.error('数据加载失败')
  264. } finally {
  265. loading.value = false
  266. }
  267. }
  268. // 搜索标本
  269. const searchSpecimen = async (query) => {
  270. if (!query) return
  271. try {
  272. specimenLoading.value = true
  273. const res = await searchSpecimens({ keyword: query })
  274. specimenList.value = res.data
  275. } finally {
  276. specimenLoading.value = false
  277. }
  278. }
  279. // 提交表单
  280. const submitForm = async () => {
  281. try {
  282. await formRef.value.validate()
  283. submitting.value = true
  284. // 处理附件
  285. const attachments = fileList.value.map(file => ({
  286. name: file.name,
  287. url: file.response?.data.url || ''
  288. }))
  289. await createApplication({
  290. ...formData,
  291. attachments
  292. })
  293. ElMessage.success('提交成功')
  294. dialogVisible.value = false
  295. getList()
  296. } catch (error) {
  297. console.error('提交失败:', error)
  298. } finally {
  299. submitting.value = false
  300. }
  301. }
  302. // 撤回申请
  303. const handleWithdraw = async (row) => {
  304. try {
  305. await ElMessageBox.confirm('确定要撤回该申请吗?', '提示', {
  306. type: 'warning'
  307. })
  308. await withdrawApplication(row.id)
  309. ElMessage.success('已撤回申请')
  310. getList()
  311. } catch (error) {
  312. if (error !== 'cancel') {
  313. ElMessage.error('撤回失败')
  314. }
  315. }
  316. }
  317. // 文件上传处理
  318. const beforeUpload = (file) => {
  319. const isAllowed = ['image/png', 'application/pdf', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document']
  320. .includes(file.type)
  321. const isLt10M = file.size / 1024 / 1024 < 10
  322. if (!isAllowed) {
  323. ElMessage.error('不支持的文件格式!')
  324. return false
  325. }
  326. if (!isLt10M) {
  327. ElMessage.error('文件大小不能超过10MB!')
  328. return false
  329. }
  330. return true
  331. }
  332. </script>
  333. <style scoped>
  334. .search-form {
  335. margin-bottom: 20px;
  336. }
  337. .file-link {
  338. margin-right: 8px;
  339. }
  340. .upload-tip {
  341. color: #666;
  342. font-size: 12px;
  343. margin-top: 8px;
  344. }
  345. .pagination {
  346. margin-top: 20px;
  347. justify-content: flex-end;
  348. }
  349. </style>