taskDetail.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. <template>
  2. <view class="sub-page">
  3. <TopBar title="任务详情" show-back />
  4. <view v-if="loading" class="py-10 text-center">
  5. <text class="empty-text">加载中...</text>
  6. </view>
  7. <view v-else-if="task" class="px-4 pt-3">
  8. <!-- 任务状态卡片 -->
  9. <view class="glass-card p-4">
  10. <view class="flex justify-between items-start mb-3">
  11. <view class="flex-1 min-w-0 mr-2">
  12. <text class="notice-title">{{ taskTitle }}</text>
  13. <view class="mt-2 flex items-center">
  14. <StatusTag :status="task.status" />
  15. <text v-if="isEmergency" class="emergency-tag ml-2">应急</text>
  16. </view>
  17. </view>
  18. <text class="meta-text flex-shrink-0">{{ task.taskNo }}</text>
  19. </view>
  20. <view v-if="task.address" class="meta-line mb-2">
  21. <text class="uni-icons uniui-location-filled meta-icon mr-2"></text>
  22. <text class="meta-value flex-1">{{ task.address }}</text>
  23. </view>
  24. <view class="meta-line">
  25. <text class="uni-icons uniui-clock-filled meta-icon mr-2"></text>
  26. <text class="meta-value">{{ serviceTimeText }}</text>
  27. </view>
  28. </view>
  29. <!-- 基本信息 -->
  30. <view class="glass-card">
  31. <view class="section-head">
  32. <view class="section-bar mr-2"></view>
  33. <text class="section-title flex-1">基本信息</text>
  34. </view>
  35. <view class="info-row">
  36. <text class="info-label">服务类型</text>
  37. <text class="info-value">{{ constructionTypeText }}</text>
  38. </view>
  39. <view class="info-row">
  40. <text class="info-label">客户名称</text>
  41. <text class="info-value">{{ customerName }}</text>
  42. </view>
  43. <view class="info-row">
  44. <text class="info-label">联系电话</text>
  45. <view class="flex items-center">
  46. <text class="info-value mr-2">{{ customerPhone || '-' }}</text>
  47. <button
  48. v-if="customerPhone"
  49. class="phone-circle"
  50. @click="callPhone(customerPhone)"
  51. >
  52. <text class="uni-icons uniui-phone-filled phone-icon"></text>
  53. </button>
  54. </view>
  55. </view>
  56. <view class="info-row">
  57. <text class="info-label">项目地址</text>
  58. <text class="info-value info-value-left">{{ task.address || '-' }}</text>
  59. </view>
  60. <view class="info-row">
  61. <text class="info-label">预约时间</text>
  62. <text class="info-value">{{ serviceTimeText }}</text>
  63. </view>
  64. <view class="info-row">
  65. <text class="info-label">紧急程度</text>
  66. <text class="info-value" :class="isEmergency ? 'urgent-text' : 'normal-text'">
  67. {{ urgencyText }}
  68. </text>
  69. </view>
  70. </view>
  71. <!-- 服务点信息 -->
  72. <view v-if="servicePoints.length > 0" class="glass-card">
  73. <view class="section-head">
  74. <view class="section-bar mr-2"></view>
  75. <text class="section-title flex-1">服务点信息</text>
  76. </view>
  77. <view
  78. v-for="(point, index) in servicePoints"
  79. :key="index"
  80. class="point-row"
  81. >
  82. <view class="flex justify-between items-center mb-2">
  83. <text class="point-name">{{ point.name }}</text>
  84. <text v-if="point.serviceType" class="type-tag">{{ point.serviceType }}</text>
  85. </view>
  86. <view v-if="point.address" class="flex items-center">
  87. <text class="uni-icons uniui-location-filled meta-icon mr-1"></text>
  88. <text class="meta-text">{{ point.address }}</text>
  89. </view>
  90. </view>
  91. </view>
  92. <!-- 处理记录 -->
  93. <view class="glass-card">
  94. <view class="section-head">
  95. <view class="section-bar mr-2"></view>
  96. <text class="section-title flex-1">处理记录</text>
  97. </view>
  98. <view class="pb-3 px-2">
  99. <Timeline :records="timelineRecords" />
  100. </view>
  101. </view>
  102. </view>
  103. <EmptyState v-else message="任务不存在" />
  104. </view>
  105. </template>
  106. <script setup lang="ts">
  107. import { ref, computed } from 'vue'
  108. import { onLoad } from '@dcloudio/uni-app'
  109. import { useTaskStore } from '@/stores/task'
  110. import TopBar from '@/components/common/TopBar.vue'
  111. import StatusTag from '@/components/common/StatusTag.vue'
  112. import EmptyState from '@/components/common/EmptyState.vue'
  113. import Timeline from '@/components/common/Timeline.vue'
  114. import type { TimelineRecord } from '@/components/common/Timeline.vue'
  115. import { getTaskDetail } from '@/api/task'
  116. import { getProjectDetail } from '@/api/project'
  117. import { formatDate } from '@/utils'
  118. import type { ServicePoint } from '@/types'
  119. const taskStore = useTaskStore()
  120. const task = ref<any>(null)
  121. const project = ref<any>(null)
  122. const loading = ref(false)
  123. const extra = computed(() => {
  124. if (!task.value?.extraData) return {} as any
  125. try {
  126. return JSON.parse(task.value.extraData)
  127. } catch {
  128. return {} as any
  129. }
  130. })
  131. const taskTitle = computed(() => {
  132. const t = task.value
  133. if (!t) return ''
  134. return t.taskName || extra.value.projectName || t.faultLocation || '未命名任务'
  135. })
  136. const isEmergency = computed(() => {
  137. const t = task.value
  138. if (!t) return false
  139. return t.taskType === 'emergency' || ['urgent', 'very_urgent'].includes(t.urgencyLevel)
  140. })
  141. const urgencyText = computed(() => {
  142. const map: Record<string, string> = { normal: '普通', urgent: '紧急', very_urgent: '特急' }
  143. const level = task.value?.urgencyLevel
  144. return level ? map[level] || level : '普通'
  145. })
  146. const constructionTypeText = computed(() => {
  147. const t = task.value
  148. if (!t) return '-'
  149. const map: Record<string, string> = { dredge: '疏通', clean: '清掏', inspect: '排查', repair: '维修', emergency: '应急' }
  150. return t.constructionType || (t.taskType ? map[t.taskType] || t.taskType : '-')
  151. })
  152. const serviceTimeText = computed(() => {
  153. const t = task.value
  154. if (!t) return '待定'
  155. const date = t.planDate || ''
  156. const rangeMap: Record<string, string> = { morning: '上午', afternoon: '下午', evening: '晚上' }
  157. const range = rangeMap[t.planTimeRange] || t.planTimeRange || ''
  158. return date || range ? `${date} ${range}`.trim() : '待定'
  159. })
  160. const customerName = computed(() => {
  161. return project.value?.customerName || extra.value.customerName || project.value?.primaryContactName || '-'
  162. })
  163. const customerPhone = computed(() => {
  164. return project.value?.customerPhone || extra.value.customerPhone || project.value?.primaryContactPhone || ''
  165. })
  166. const servicePoints = computed<ServicePoint[]>(() => {
  167. const raw = project.value?.servicePoints
  168. if (!raw) return []
  169. try {
  170. const list = typeof raw === 'string' ? JSON.parse(raw) : raw
  171. return Array.isArray(list) ? list : []
  172. } catch {
  173. return []
  174. }
  175. })
  176. const timelineRecords = computed<TimelineRecord[]>(() => {
  177. const logs: any[] = task.value?.logList || []
  178. return logs.map(log => ({
  179. action: log.operation || log.action || '状态更新',
  180. time: log.createTime ? formatDate(log.createTime, 'YYYY-MM-DD HH:mm') : '',
  181. operator: log.operatorName || '系统',
  182. role: log.operatorRole || roleFromOperationType(log.operationType),
  183. }))
  184. })
  185. function roleFromOperationType(type: string): string {
  186. const map: Record<string, string> = {
  187. create: 'sales',
  188. audit: 'dispatch',
  189. dispatch: 'dispatch',
  190. urge: 'sales',
  191. cancel: 'sales',
  192. }
  193. return map[type] || 'construction'
  194. }
  195. function callPhone(phone: string) {
  196. if (!phone) return
  197. uni.makePhoneCall({ phoneNumber: phone })
  198. }
  199. onLoad((options) => {
  200. if (options?.id) {
  201. loadDetail(Number(options.id))
  202. } else if (taskStore.currentTask) {
  203. // 兼容未携带 id 的入口:使用列表中已加载的任务数据
  204. task.value = taskStore.currentTask
  205. loadProject(taskStore.currentTask.projectId)
  206. }
  207. })
  208. async function loadDetail(taskId: number) {
  209. loading.value = true
  210. try {
  211. const res: any = await getTaskDetail(taskId)
  212. task.value = res
  213. loadProject(res?.projectId)
  214. } catch (e) {
  215. console.error('加载任务详情失败', e)
  216. } finally {
  217. loading.value = false
  218. }
  219. }
  220. function loadProject(projectId: number | string | undefined) {
  221. if (!projectId) return
  222. getProjectDetail(projectId)
  223. .then(p => { project.value = p })
  224. .catch(() => {})
  225. }
  226. </script>
  227. <style scoped>
  228. .sub-page {
  229. max-width: 430px;
  230. margin: 0 auto;
  231. min-height: 100vh;
  232. background-color: #f6fbf9;
  233. padding-bottom: 24px;
  234. }
  235. .glass-card {
  236. background-color: rgba(255, 255, 255, 0.85);
  237. backdrop-filter: blur(14px);
  238. -webkit-backdrop-filter: blur(14px);
  239. border: 1px solid rgba(164, 216, 152, 0.35);
  240. border-radius: 24px;
  241. box-shadow: 0 18px 50px -12px rgba(54, 143, 111, 0.28);
  242. overflow: hidden;
  243. margin-bottom: 12px;
  244. }
  245. .notice-title {
  246. display: block;
  247. font-size: 17px;
  248. font-weight: 700;
  249. color: #1f2937;
  250. line-height: 1.4;
  251. }
  252. .emergency-tag {
  253. padding: 2px 10px;
  254. border-radius: 999px;
  255. font-size: 11px;
  256. font-weight: 600;
  257. color: #ef4444;
  258. background-color: rgba(239, 68, 68, 0.1);
  259. }
  260. .meta-line {
  261. display: flex;
  262. align-items: center;
  263. }
  264. .meta-icon {
  265. font-size: 14px;
  266. color: #9ca3af;
  267. }
  268. .meta-text {
  269. font-size: 12px;
  270. color: #9ca3af;
  271. }
  272. .meta-value {
  273. font-size: 13px;
  274. color: #4b5563;
  275. }
  276. .section-head {
  277. display: flex;
  278. align-items: center;
  279. padding: 16px 16px 12px;
  280. }
  281. .section-bar {
  282. width: 4px;
  283. height: 16px;
  284. border-radius: 2px;
  285. background: linear-gradient(180deg, #368f6f 0%, #5ab8d0 100%);
  286. }
  287. .section-title {
  288. font-size: 16px;
  289. font-weight: 700;
  290. color: #1f2937;
  291. }
  292. .info-row {
  293. display: flex;
  294. align-items: center;
  295. justify-content: space-between;
  296. padding: 12px 16px;
  297. border-top: 1px solid rgba(164, 216, 152, 0.18);
  298. }
  299. .info-label {
  300. font-size: 13px;
  301. color: #9ca3af;
  302. flex-shrink: 0;
  303. margin-right: 12px;
  304. }
  305. .info-value {
  306. font-size: 13px;
  307. color: #1f2937;
  308. text-align: right;
  309. }
  310. .info-value-left {
  311. flex: 1;
  312. }
  313. .urgent-text {
  314. color: #ef4444;
  315. font-weight: 600;
  316. }
  317. .normal-text {
  318. color: #368f6f;
  319. }
  320. .point-row {
  321. padding: 13px 16px;
  322. border-top: 1px solid rgba(164, 216, 152, 0.18);
  323. }
  324. .point-name {
  325. font-size: 14px;
  326. font-weight: 600;
  327. color: #1f2937;
  328. }
  329. .type-tag {
  330. padding: 2px 10px;
  331. border-radius: 999px;
  332. font-size: 11px;
  333. font-weight: 600;
  334. color: #368f6f;
  335. background-color: rgba(164, 216, 152, 0.24);
  336. }
  337. .phone-circle {
  338. width: 28px;
  339. height: 28px;
  340. border-radius: 50%;
  341. flex-shrink: 0;
  342. display: flex;
  343. align-items: center;
  344. justify-content: center;
  345. background-color: rgba(164, 216, 152, 0.24);
  346. }
  347. .phone-icon {
  348. font-size: 13px;
  349. color: #368f6f;
  350. }
  351. .empty-text {
  352. font-size: 13px;
  353. color: #9ca3af;
  354. }
  355. </style>