SampleAppointList.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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="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 { showDialog, showNotify } from 'vant'
  134. const props = defineProps({
  135. instId: {
  136. type: Number,
  137. default: 0
  138. }
  139. })
  140. const sampleApi = useSampleApi()
  141. const activeNames = ref([])
  142. const state = reactive({
  143. loading: false,
  144. finished: false,
  145. appointList: [] as any[],
  146. queryForm: {
  147. pageNum: 1,
  148. pageSize: 10,
  149. instId: props.instId
  150. },
  151. total: 0,
  152. })
  153. const toParse = (str: string) => {
  154. try {
  155. return JSON.parse(str) || []
  156. } catch (e) {
  157. return []
  158. }
  159. }
  160. const testItemInfo = (test: any) => {
  161. return `检测项:${test.name},数量:${test.count}`
  162. }
  163. const itemsDialogShow = ref(false)
  164. const currentSampleItems = ref<any[]>([])
  165. const dialogTitle = ref('检测信息')
  166. const showSampleItem = (itemsStr: string, title: string = '检测信息') => {
  167. currentSampleItems.value = toParse(itemsStr)
  168. dialogTitle.value = title
  169. itemsDialogShow.value = true
  170. }
  171. const getStatusType = (key: string) => {
  172. let type = 'default'
  173. switch (key) {
  174. case '10': // 待审核
  175. type = 'warning'
  176. break
  177. case '20': // 已通过
  178. type = 'success'
  179. break
  180. case '30': // 已驳回
  181. type = 'danger'
  182. break
  183. case '50': // 已检测
  184. type = 'primary'
  185. break
  186. case '40': // 已取消
  187. case '11': // 已退回
  188. type = 'default'
  189. break
  190. }
  191. return type as 'primary' | 'success' | 'warning' | 'danger' | 'default'
  192. }
  193. const setStatus = (key: string) => {
  194. let str = ''
  195. switch (key) {
  196. case '10':
  197. str = '待审核'
  198. break
  199. case '11':
  200. str = '已退回'
  201. break
  202. case '20':
  203. str = '已通过'
  204. break
  205. case '30':
  206. str = '已驳回'
  207. break
  208. case '40':
  209. str = '已取消'
  210. break
  211. case '50':
  212. str = '已检测'
  213. break
  214. }
  215. return str
  216. }
  217. const handleCancelAppoint = (row: any) => {
  218. showDialog({
  219. title: '提示',
  220. message: '确认取消预约?',
  221. showCancelButton: true,
  222. })
  223. .then(async () => {
  224. const params = { id: row.id }
  225. const [err, res]: any = await to(sampleApi.userCancelAppoint(params))
  226. if (err) return
  227. if (res?.code === 200) {
  228. showNotify({ type: 'success', message: '取消成功' })
  229. state.queryForm.pageNum = 1
  230. state.appointList = []
  231. state.finished = false
  232. onLoad()
  233. }
  234. })
  235. .catch(() => {
  236. // on cancel
  237. })
  238. }
  239. const onLoad = async () => {
  240. state.loading = true
  241. state.queryForm.instId = props.instId
  242. const [err, res]: any = await to(sampleApi.getList(state.queryForm))
  243. state.loading = false
  244. if (err) {
  245. state.finished = true
  246. return
  247. }
  248. if (res?.code === 200) {
  249. const list = res?.data?.list || []
  250. if (state.queryForm.pageNum === 1) {
  251. state.appointList = list
  252. } else {
  253. state.appointList = [...state.appointList, ...list]
  254. }
  255. state.total = res?.data?.total || 0
  256. state.queryForm.pageNum++
  257. if (state.appointList.length >= state.total) {
  258. state.finished = true
  259. }
  260. } else {
  261. state.finished = true
  262. }
  263. }
  264. onMounted(() => {
  265. // onLoad will be triggered by van-list automatically initially
  266. })
  267. // Expose onLoad for parent component to call
  268. defineExpose({
  269. onLoad: () => {
  270. state.queryForm.pageNum = 1
  271. state.finished = false
  272. // Need to reset list? The onLoad usually appends...
  273. // If called from parent for refresh, we should probably reset.
  274. // Let's modify logic slightly or just set pageNum to 1 and empty list
  275. state.appointList = []
  276. onLoad()
  277. }
  278. })
  279. </script>
  280. <style lang="scss" scoped>
  281. * {
  282. box-sizing: border-box;
  283. }
  284. .panel-wrap {
  285. height: 100%;
  286. .data-list {
  287. .inst-item {
  288. border-radius: 10px;
  289. padding: 15px;
  290. box-shadow: -2px 0px 9px rgba(0, 0, 0, 0.12);
  291. margin-bottom: 20px;
  292. background-color: #fff;
  293. .equ-tit {
  294. width: 80px;
  295. min-width: 80px;
  296. }
  297. }
  298. }
  299. }
  300. .fontSize14 {
  301. font-size: 14px;
  302. }
  303. .bold {
  304. font-weight: bold;
  305. }
  306. .primary-color {
  307. color: #1989fa;
  308. }
  309. .price {
  310. color: #ee0a24;
  311. }
  312. .flex {
  313. display: flex;
  314. }
  315. .flex-between {
  316. justify-content: space-between;
  317. }
  318. .mb20 {
  319. margin-bottom: 20px;
  320. }
  321. .mb10 {
  322. margin-bottom: 10px;
  323. }
  324. .mr10 {
  325. margin-right: 10px;
  326. }
  327. .mt20 {
  328. margin-top: 20px;
  329. }
  330. .flex-col {
  331. flex-direction: column;
  332. }
  333. .pointer {
  334. cursor: pointer;
  335. }
  336. </style>