SampleAppointList.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. <template>
  2. <div class="panel-wrap">
  3. <van-empty v-if="state.appointList.length === 0 && state.finished" description="暂无预约记录" />
  4. <van-list v-else v-model:loading="state.loading" :finished="state.finished" finished-text="没有更多了" @load="onLoad"
  5. class="data-list">
  6. <div class="inst-item mb20" v-for="(v, index) in state.appointList" :key="index">
  7. <div class="flex flex-between mb20">
  8. <div>
  9. <div class="mr10">
  10. <span class="fontSize14 primary-color bold">{{ v.instName }}</span>
  11. </div>
  12. </div>
  13. <!-- Status Tag moved here -->
  14. </div>
  15. <div class="flex mb20">
  16. <div class="equ-tit">
  17. <span class="fontSize14 bold">送样时间:</span>
  18. </div>
  19. <div>
  20. <span class="fontSize14">{{ formatDate(new Date(v.deliverTime), 'YYYY-mm-dd HH:MM') }}</span>
  21. </div>
  22. </div>
  23. <div class="flex mb20">
  24. <div class="equ-tit">
  25. <span class="fontSize14 bold">检测时间:</span>
  26. </div>
  27. <div>
  28. <span class="fontSize14">{{ formatDate(new Date(v.testTime), 'YYYY-mm-dd HH:MM') }}</span>
  29. </div>
  30. </div>
  31. <div class="flex mb20">
  32. <div class="equ-tit">
  33. <span class="fontSize14 bold">样品数:</span>
  34. </div>
  35. <div>
  36. <span class="fontSize14">{{ v.sampleNum }}</span>
  37. </div>
  38. </div>
  39. <div class="flex mb20">
  40. <div class="equ-tit">
  41. <span class="fontSize14 bold">申请人:</span>
  42. </div>
  43. <div>
  44. <span class="fontSize14">{{ v.userName }}</span>
  45. </div>
  46. </div>
  47. <div class="flex mb20">
  48. <div class="equ-tit">
  49. <span class="fontSize14 bold">状态:</span>
  50. </div>
  51. <van-tag :type="getStatusType(v.deliverStatus)">{{ setStatus(v.deliverStatus) }}</van-tag>
  52. </div>
  53. <!-- Detection Info Clickable -->
  54. <div class="flex mb20" v-if="v.sampleItem !== '[]' || v.testSampleItem">
  55. <div class="equ-tit">
  56. <span class="fontSize14 bold">检测信息:</span>
  57. </div>
  58. <div>
  59. <span v-if="v.sampleItem" class="fontSize14 primary-color pointer mr10"
  60. @click="showSampleItem(v.sampleItem, '预约信息')">预约检测项目</span>
  61. <span v-if="v.testSampleItem" class="fontSize14 primary-color pointer"
  62. @click="showSampleItem(v.testSampleItem, '实测信息')">实测检测项目</span>
  63. </div>
  64. </div>
  65. <div class="flex mb20" v-if="v.testResultName">
  66. <div class="equ-tit">
  67. <span class="fontSize14 bold">检测结果:</span>
  68. </div>
  69. <div style="flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;">
  70. <span class="fontSize14 primary-color pointer">
  71. <a :href="getFileUrl(v.testResult)" target="_blank" class="file-link">
  72. {{ v.testResultName }}
  73. </a>
  74. </span>
  75. </div>
  76. </div>
  77. <div v-if="v.order">
  78. <van-collapse v-model="activeNames">
  79. <van-collapse-item title="收费明细" :name="v.id">
  80. <div class="flex mb10">
  81. <div class="equ-tit">
  82. <span class="fontSize14 bold">计费编号:</span>
  83. </div>
  84. <div>
  85. <span class="fontSize14">{{ v.order.fboCode }}</span>
  86. </div>
  87. </div>
  88. <div class="flex mb10">
  89. <div class="equ-tit">
  90. <span class="fontSize14 bold">收费:</span>
  91. </div>
  92. <div>
  93. <span class="fontSize14 price">¥{{ v.order.fboActualAmount }}</span>
  94. </div>
  95. </div>
  96. <div class="flex mb10">
  97. <div class="equ-tit">
  98. <span class="fontSize14 bold">预估费用:</span>
  99. </div>
  100. <div>
  101. <span class="fontSize14 price">¥{{ v.order.fboExpectedAmount }}</span>
  102. </div>
  103. </div>
  104. </van-collapse-item>
  105. </van-collapse>
  106. </div>
  107. <!-- Cancel Button moved to bottom -->
  108. <div class="flex mt20" style="justify-content: flex-end;"
  109. v-if="v.deliverStatus == '10'">
  110. <van-button class="scan-txt" plain type="danger" size="small" @click.stop="handleCancelAppoint(v)">
  111. 取消预约
  112. </van-button>
  113. </div>
  114. </div>
  115. </van-list>
  116. <!-- Dialog for Sample Items -->
  117. <van-dialog v-model:show="itemsDialogShow" :title="dialogTitle">
  118. <div class="dialog-content">
  119. <div class="flex mb10 flex-col" style="padding: 10px;">
  120. <div class="flex mb4" v-for="(test, idx) in currentSampleItems" :key="idx">
  121. <span class="fontSize14">{{ testItemInfo(test) }}</span>
  122. </div>
  123. </div>
  124. </div>
  125. </van-dialog>
  126. </div>
  127. </template>
  128. <script lang="ts" setup>
  129. import { reactive, ref, onMounted } from 'vue'
  130. import { useSampleApi } from '/@/api/instr/sample'
  131. import to from 'await-to-js'
  132. import { formatDate } from '/@/utils/formatTime'
  133. import { getFileUrl } from '/@/utils/url'
  134. import { showDialog, showNotify } from 'vant'
  135. const props = defineProps({
  136. instId: {
  137. type: Number,
  138. default: 0
  139. }
  140. })
  141. const sampleApi = useSampleApi()
  142. const activeNames = ref([])
  143. const state = reactive({
  144. loading: false,
  145. finished: false,
  146. appointList: [] as any[],
  147. queryForm: {
  148. pageNum: 1,
  149. pageSize: 10,
  150. instId: props.instId
  151. },
  152. total: 0,
  153. })
  154. const toParse = (str: string) => {
  155. try {
  156. return JSON.parse(str) || []
  157. } catch (e) {
  158. return []
  159. }
  160. }
  161. const testItemInfo = (test: any) => {
  162. return `检测项:${test.name},数量:${test.count}`
  163. }
  164. const itemsDialogShow = ref(false)
  165. const currentSampleItems = ref<any[]>([])
  166. const dialogTitle = ref('检测信息')
  167. const showSampleItem = (itemsStr: string, title: string = '检测信息') => {
  168. currentSampleItems.value = toParse(itemsStr)
  169. dialogTitle.value = title
  170. itemsDialogShow.value = true
  171. }
  172. const getStatusType = (key: string) => {
  173. let type = 'default'
  174. switch (key) {
  175. case '10': // 待审核
  176. type = 'warning'
  177. break
  178. case '20': // 已通过
  179. type = 'success'
  180. break
  181. case '30': // 已驳回
  182. type = 'danger'
  183. break
  184. case '50': // 已检测
  185. type = 'primary'
  186. break
  187. case '40': // 已取消
  188. case '11': // 已退回
  189. type = 'default'
  190. break
  191. }
  192. return type as 'primary' | 'success' | 'warning' | 'danger' | 'default'
  193. }
  194. const setStatus = (key: string) => {
  195. let str = ''
  196. switch (key) {
  197. case '10':
  198. str = '待审核'
  199. break
  200. case '11':
  201. str = '已退回'
  202. break
  203. case '20':
  204. str = '已通过'
  205. break
  206. case '30':
  207. str = '已驳回'
  208. break
  209. case '40':
  210. str = '已取消'
  211. break
  212. case '50':
  213. str = '已检测'
  214. break
  215. }
  216. return str
  217. }
  218. const handleCancelAppoint = (row: any) => {
  219. showDialog({
  220. title: '提示',
  221. message: '确认取消预约?',
  222. showCancelButton: true,
  223. })
  224. .then(async () => {
  225. const params = { id: row.id }
  226. const [err, res]: any = await to(sampleApi.userCancelAppoint(params))
  227. if (err) return
  228. if (res?.code === 200) {
  229. showNotify({ type: 'success', message: '取消成功' })
  230. state.queryForm.pageNum = 1
  231. state.appointList = []
  232. state.finished = false
  233. onLoad()
  234. }
  235. })
  236. .catch(() => {
  237. // on cancel
  238. })
  239. }
  240. const onLoad = async () => {
  241. state.loading = true
  242. state.queryForm.instId = props.instId
  243. const [err, res]: any = await to(sampleApi.getList(state.queryForm))
  244. state.loading = false
  245. if (err) {
  246. state.finished = true
  247. return
  248. }
  249. if (res?.code === 200) {
  250. const list = res?.data?.list || []
  251. if (state.queryForm.pageNum === 1) {
  252. state.appointList = list
  253. } else {
  254. state.appointList = [...state.appointList, ...list]
  255. }
  256. state.total = res?.data?.total || 0
  257. state.queryForm.pageNum++
  258. if (state.appointList.length >= state.total) {
  259. state.finished = true
  260. }
  261. } else {
  262. state.finished = true
  263. }
  264. }
  265. onMounted(() => {
  266. // onLoad will be triggered by van-list automatically initially
  267. })
  268. // Expose onLoad for parent component to call
  269. defineExpose({
  270. onLoad: () => {
  271. state.queryForm.pageNum = 1
  272. state.finished = false
  273. // Need to reset list? The onLoad usually appends...
  274. // If called from parent for refresh, we should probably reset.
  275. // Let's modify logic slightly or just set pageNum to 1 and empty list
  276. state.appointList = []
  277. onLoad()
  278. }
  279. })
  280. </script>
  281. <style lang="scss" scoped>
  282. * {
  283. box-sizing: border-box;
  284. }
  285. .panel-wrap {
  286. height: 100%;
  287. .data-list {
  288. .inst-item {
  289. border-radius: 10px;
  290. padding: 15px;
  291. box-shadow: -2px 0px 9px rgba(0, 0, 0, 0.12);
  292. margin-bottom: 20px;
  293. background-color: #fff;
  294. .equ-tit {
  295. width: 80px;
  296. min-width: 80px;
  297. }
  298. }
  299. }
  300. }
  301. .fontSize14 {
  302. font-size: 14px;
  303. }
  304. .bold {
  305. font-weight: bold;
  306. }
  307. .primary-color {
  308. color: #1989fa;
  309. }
  310. .price {
  311. color: #ee0a24;
  312. }
  313. .flex {
  314. display: flex;
  315. }
  316. .flex-between {
  317. justify-content: space-between;
  318. }
  319. .mb20 {
  320. margin-bottom: 20px;
  321. }
  322. .mb10 {
  323. margin-bottom: 10px;
  324. }
  325. .mr10 {
  326. margin-right: 10px;
  327. }
  328. .mt20 {
  329. margin-top: 20px;
  330. }
  331. .flex-col {
  332. flex-direction: column;
  333. }
  334. .pointer {
  335. cursor: pointer;
  336. }
  337. </style>