detail.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. <template>
  2. <view class="detail-page">
  3. <LoadingSkeleton v-if="loading" :rows="4" />
  4. <ErrorState v-else-if="error" message="工单详情加载失败" @retry="loadDetail" />
  5. <EmptyState v-else-if="!order.id" icon="🔍" title="未找到该工单" desc="该工单可能已取消,可返回工作台查看" action-text="返回列表" @action="backToWorkbench" />
  6. <template v-else>
  7. <!-- 头部客户信息 -->
  8. <view class="head-card">
  9. <view class="head-top">
  10. <view class="head-no-wrap">
  11. <text class="order-no">{{ order.orderNo || '' }}</text>
  12. <text v-if="order.source === 'org_created'" class="source-tag">机构派单</text>
  13. </view>
  14. <text class="head-status" :style="{ background: statusBg(order.status) }">{{ statusText(order.status) }}</text>
  15. </view>
  16. <text class="family-name">{{ order.familyName || '客户家' }}</text>
  17. <text class="addr">{{ order.address || '地址待确认' }}</text>
  18. <view class="time-row" v-if="order.startAt">
  19. <text class="time-label">服务时间</text>
  20. <text class="time-value">{{ order.startAt }}{{ order.endAt ? ' ~ ' + order.endAt : '' }}</text>
  21. </view>
  22. <view class="time-row" v-if="order.remark">
  23. <text class="time-label">备注</text>
  24. <text class="time-value">{{ order.remark }}</text>
  25. </view>
  26. </view>
  27. <!-- 收入卡(服务人员最关心) -->
  28. <view class="money-card">
  29. <view class="money-col">
  30. <text class="money-label">本单到手</text>
  31. <text class="money-value">¥{{ fenToYuan(order.staffIncome) }}</text>
  32. </view>
  33. <view class="money-col">
  34. <text class="money-label">本单金额</text>
  35. <text class="money-value">¥{{ fenToYuan(order.amount) }}</text>
  36. </view>
  37. </view>
  38. <!-- 已到岗凭证 -->
  39. <view class="sec-card" v-if="order.status !== 'pending' && order.status !== 'accepted'">
  40. <view class="sec-head">
  41. <text class="sec-title">到岗凭证</text>
  42. <text v-if="order.arriveAt" class="sec-ok">✓ {{ order.arriveAt }}</text>
  43. </view>
  44. <image v-if="order.arrivePhoto" :src="order.arrivePhoto" class="arrive-photo" mode="aspectFit" />
  45. <text v-else-if="order.status === 'arrived' || order.status === 'doing' || order.status === 'done' || order.status === 'confirmed'" class="sec-empty">尚未上传门牌照</text>
  46. </view>
  47. <!-- 动作区:按状态只显示一步 -->
  48. <view class="action-card" v-if="order.status === 'pending'">
  49. <button class="main-btn" @click="doAccept">接这单</button>
  50. <text class="hint">接单后请准时上门,到岗时打卡</text>
  51. </view>
  52. <view class="action-card" v-if="order.status === 'accepted'">
  53. <button class="main-btn" @click="doArrive">到岗打卡</button>
  54. <text class="hint">到客户家后,拍照门牌并点击打卡(自动记录时间和位置)</text>
  55. </view>
  56. <view class="action-card" v-if="order.status === 'arrived' || order.status === 'doing'">
  57. <view class="sec-head">
  58. <text class="sec-title">本次服务内容</text>
  59. </view>
  60. <view v-if="order.items.length === 0" class="empty-box">
  61. <text class="sec-empty">本次服务无固定项目,完成拍照即可</text>
  62. </view>
  63. <view v-for="(item, idx) in order.items" :key="idx" class="item-row">
  64. <text class="item-name">{{ item.name }}</text>
  65. <view class="item-done">
  66. <text class="item-state" :style="{ color: item.done == 1 ? '#0E8A4F' : '#3B5A78' }">{{ item.done == 1 ? '✓ 已做' : '未做' }}</text>
  67. </view>
  68. </view>
  69. <view class="photo-grid">
  70. <view v-for="(p, pi) in order.finishPhotos" :key="pi" class="photo-cell">
  71. <image :src="p" class="photo-img" mode="aspectFill" />
  72. </view>
  73. <view class="photo-cell add-cell" @click="choosePhoto">
  74. <text class="add-text">+ 拍照</text>
  75. </view>
  76. </view>
  77. <button class="main-btn" @click="doFinish" :loading="finishing">完成服务</button>
  78. <text class="hint">完成后生成客户确认码,请客户核对</text>
  79. </view>
  80. <view class="action-card" v-if="order.status === 'done'">
  81. <view class="confirm-code-box">
  82. <text class="code-label">客户确认码</text>
  83. <text class="code-value">{{ order.clientConfirmCode }}</text>
  84. <text class="code-tip">请告知客户这 6 位数字,客户确认后即完成结算</text>
  85. </view>
  86. <view class="code-input-row">
  87. <input class="code-input" v-model="confirmCode" type="number" maxlength="6" placeholder="输入客户确认码" />
  88. <button class="confirm-btn" @click="doConfirm" :loading="confirming">确认</button>
  89. </view>
  90. <text class="hint">若客户不便操作,可请机构对接人代确认</text>
  91. </view>
  92. <view class="action-card" v-if="order.status === 'confirmed'">
  93. <view class="done-box">
  94. <text class="done-icon">✓</text>
  95. <text class="done-title">本单已完成</text>
  96. <text class="done-sub">¥{{ fenToYuan(order.staffIncome) }} 已计入收入</text>
  97. </view>
  98. <!-- M3 评价入口:confirmed 且未评过(后端 evalDone / 本地已提交记忆)才展示 -->
  99. <view v-if="!evalDone" class="eval-entry">
  100. <button class="main-btn eval-btn" @click="goEval">去评价</button>
  101. <text class="hint">评价仅服务人员可查看,用于档案沉淀</text>
  102. </view>
  103. <view v-else class="eval-done-box">
  104. <text class="eval-done-text">已评价 ✓ 感谢您的反馈</text>
  105. </view>
  106. </view>
  107. <view class="back-tip">
  108. <text class="back-text">有疑问请联系机构对接人</text>
  109. </view>
  110. </template>
  111. </view>
  112. </template>
  113. <script>
  114. import {
  115. getServiceOrderDetail,
  116. acceptServiceOrder,
  117. arriveServiceOrder,
  118. finishServiceOrder,
  119. confirmServiceOrder,
  120. uploadFile
  121. } from '@/utils/api.js'
  122. import LoadingSkeleton from '@/components/loading-skeleton.vue'
  123. import ErrorState from '@/components/error-state.vue'
  124. import EmptyState from '@/components/empty-state.vue'
  125. export default {
  126. components: { LoadingSkeleton, ErrorState, EmptyState },
  127. data() {
  128. return {
  129. orderId: null,
  130. order: {
  131. status: 'pending',
  132. items: [],
  133. finishPhotos: []
  134. },
  135. confirmCode: '',
  136. finishing: false,
  137. confirming: false,
  138. loading: true,
  139. error: false,
  140. locating: false
  141. }
  142. },
  143. computed: {
  144. // 是否已评价:后端 order/detail 无 evalDone 字段(M3 回执确认),只用本地提交记忆 evalSubmittedOrders
  145. evalDone() {
  146. var arr = uni.getStorageSync('evalSubmittedOrders')
  147. if (!Array.isArray(arr)) return false
  148. for (var i = 0; i < arr.length; i++) {
  149. if (String(arr[i]) === String(this.orderId)) return true
  150. }
  151. return false
  152. }
  153. },
  154. onLoad(options) {
  155. this.orderId = options.orderId || null
  156. this.loadDetail()
  157. },
  158. onShow() {
  159. this.loadDetail()
  160. },
  161. methods: {
  162. loadDetail() {
  163. if (!this.orderId) {
  164. this.loading = false
  165. return
  166. }
  167. this.loading = true
  168. this.error = false
  169. getServiceOrderDetail(this.orderId).then(res => {
  170. if (res && res.data) {
  171. this.order = res.data
  172. }
  173. }).catch(() => {
  174. this.error = true
  175. }).finally(() => {
  176. this.loading = false
  177. })
  178. },
  179. backToWorkbench() {
  180. var pages = getCurrentPages()
  181. if (pages.length > 1) {
  182. uni.navigateBack()
  183. } else {
  184. uni.switchTab({ url: '/pages/work/index' })
  185. }
  186. },
  187. doAccept() {
  188. var self = this
  189. uni.showModal({
  190. title: '确认接单',
  191. content: '接下后请准时上门。',
  192. success: function (r) {
  193. if (!r.confirm) return
  194. acceptServiceOrder(self.orderId).then(function (res) {
  195. if (res && res.code === 200) {
  196. uni.showToast({ title: '接单成功', icon: 'success' })
  197. self.loadDetail()
  198. } else {
  199. uni.showToast({ title: (res && res.message) || '接单失败', icon: 'none' })
  200. }
  201. }).catch(function () {
  202. uni.showToast({ title: '接单失败', icon: 'none' })
  203. })
  204. }
  205. })
  206. },
  207. doArrive() {
  208. var self = this
  209. if (this.locating) return
  210. this.locating = true
  211. uni.showLoading({ title: '定位中...' })
  212. uni.getLocation({
  213. type: 'gcj02',
  214. success: function (loc) {
  215. uni.hideLoading()
  216. self.locating = false
  217. var lat = loc.latitude
  218. var lng = loc.longitude
  219. self.pickPhoto(function (photoUrl) {
  220. if (!photoUrl) {
  221. uni.showToast({ title: '请先拍门牌照', icon: 'none' })
  222. return
  223. }
  224. arriveServiceOrder({
  225. orderId: self.orderId,
  226. lat: lat,
  227. lng: lng,
  228. photo: photoUrl
  229. }).then(function (res) {
  230. if (res && res.code === 200) {
  231. uni.showToast({ title: '已到岗', icon: 'success' })
  232. self.loadDetail()
  233. } else {
  234. uni.showToast({ title: (res && res.message) || '打卡失败', icon: 'none' })
  235. }
  236. }).catch(function () {
  237. uni.showToast({ title: '打卡失败', icon: 'none' })
  238. })
  239. })
  240. },
  241. fail: function () {
  242. uni.hideLoading()
  243. self.locating = false
  244. uni.showModal({
  245. title: '定位不可用',
  246. content: '无法获取位置,是否跳过定位直接拍照打卡?',
  247. success: function (r) {
  248. if (!r.confirm) return
  249. self.pickPhoto(function (photoUrl) {
  250. if (!photoUrl) {
  251. uni.showToast({ title: '请先拍门牌照', icon: 'none' })
  252. return
  253. }
  254. arriveServiceOrder({
  255. orderId: self.orderId,
  256. photo: photoUrl
  257. }).then(function (res) {
  258. if (res && res.code === 200) {
  259. uni.showToast({ title: '已到岗', icon: 'success' })
  260. self.loadDetail()
  261. } else {
  262. uni.showToast({ title: (res && res.message) || '打卡失败', icon: 'none' })
  263. }
  264. }).catch(function () {
  265. uni.showToast({ title: '打卡失败', icon: 'none' })
  266. })
  267. })
  268. }
  269. })
  270. }
  271. })
  272. },
  273. choosePhoto() {
  274. var self = this
  275. this.pickPhoto(function (photoUrl) {
  276. if (!photoUrl) return
  277. var cur = self.order.finishPhotos || []
  278. cur = cur.concat([photoUrl])
  279. self.order.finishPhotos = cur
  280. })
  281. },
  282. pickPhoto(cb) {
  283. var self = this
  284. uni.chooseImage({
  285. count: 1,
  286. success: function (res) {
  287. var filePath = res.tempFilePaths[0]
  288. uni.showLoading({ title: '上传中...' })
  289. uploadFile(filePath).then(function (resp) {
  290. uni.hideLoading()
  291. var url = resp && resp.data && resp.data.url
  292. if (url) {
  293. cb(url)
  294. } else {
  295. uni.showToast({ title: '上传失败', icon: 'none' })
  296. }
  297. }).catch(function () {
  298. uni.hideLoading()
  299. uni.showToast({ title: '上传失败', icon: 'none' })
  300. })
  301. }
  302. })
  303. },
  304. doFinish() {
  305. var self = this
  306. if (this.finishing) return
  307. this.finishing = true
  308. var items = JSON.stringify(this.order.items || [])
  309. var photos = (this.order.finishPhotos || []).join(',')
  310. finishServiceOrder({
  311. orderId: this.orderId,
  312. items: items,
  313. photos: photos
  314. }).then(function (res) {
  315. self.finishing = false
  316. if (res && res.code === 200) {
  317. uni.showModal({
  318. title: '服务完成',
  319. content: '客户确认码:' + (res.data && res.data.clientConfirmCode ? res.data.clientConfirmCode : ''),
  320. showCancel: false,
  321. success: function () {
  322. self.loadDetail()
  323. }
  324. })
  325. } else {
  326. uni.showToast({ title: (res && res.message) || '提交失败', icon: 'none' })
  327. }
  328. }).catch(function () {
  329. self.finishing = false
  330. uni.showToast({ title: '提交失败', icon: 'none' })
  331. })
  332. },
  333. doConfirm() {
  334. var self = this
  335. if (this.confirming) return
  336. if (!this.confirmCode) {
  337. uni.showToast({ title: '请输入确认码', icon: 'none' })
  338. return
  339. }
  340. this.confirming = true
  341. confirmServiceOrder({
  342. orderId: this.orderId,
  343. code: this.confirmCode
  344. }).then(function (res) {
  345. self.confirming = false
  346. if (res && res.code === 200) {
  347. uni.showToast({ title: '已完成', icon: 'success' })
  348. self.loadDetail()
  349. } else {
  350. uni.showToast({ title: (res && res.message) || '确认失败', icon: 'none' })
  351. }
  352. }).catch(function () {
  353. self.confirming = false
  354. uni.showToast({ title: '确认失败', icon: 'none' })
  355. })
  356. },
  357. goEval() {
  358. uni.navigateTo({ url: '/pages/eval/submit?orderId=' + this.orderId })
  359. },
  360. statusText(status) {
  361. if (status === 'accepted') return '已接单'
  362. if (status === 'arrived') return '已到岗'
  363. if (status === 'doing') return '服务中'
  364. if (status === 'done') return '待客户确认'
  365. if (status === 'confirmed') return '已完成'
  366. if (status === 'pending') return '待接单'
  367. return '进行中'
  368. },
  369. statusBg(status) {
  370. if (status === 'confirmed') return '#0E8A4F'
  371. if (status === 'done') return '#B9770E'
  372. if (status === 'pending') return '#2E6FA8'
  373. return '#3B5A78'
  374. },
  375. fenToYuan(fen) {
  376. var n = fen || 0
  377. return (n / 100).toFixed(2)
  378. }
  379. }
  380. }
  381. </script>
  382. <style scoped>
  383. .detail-page {
  384. min-height: 100vh;
  385. background: #F5FAFE;
  386. padding: 20rpx 24rpx 40rpx;
  387. }
  388. .head-card {
  389. background: #fff;
  390. border-radius: 20rpx;
  391. padding: 28rpx 26rpx;
  392. margin-bottom: 20rpx;
  393. border: 1px solid #E3ECF4;
  394. }
  395. .head-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12rpx; }
  396. .head-no-wrap { display: flex; align-items: center; }
  397. .order-no { font-size: 22rpx; color: #94A3B2; }
  398. .source-tag {
  399. margin-left: 12rpx;
  400. font-size: 20rpx;
  401. color: #B9770E;
  402. background: #FEF3E2;
  403. border: 1rpx solid #B9770E;
  404. border-radius: 8rpx;
  405. padding: 2rpx 12rpx;
  406. line-height: 1.5;
  407. }
  408. .head-status { font-size: 20rpx; color: #fff; padding: 3rpx 14rpx; border-radius: 20rpx; }
  409. .family-name { display: block; font-size: 36rpx; font-weight: 700; color: #1E3A5F; margin-bottom: 6rpx; }
  410. .addr { display: block; font-size: 25rpx; color: #3B5A78; margin-bottom: 14rpx; }
  411. .time-row { display: flex; margin-top: 8rpx; }
  412. .time-label { width: 130rpx; font-size: 24rpx; color: #3B5A78; }
  413. .time-value { flex: 1; font-size: 24rpx; color: #1E3A5F; }
  414. .money-card {
  415. background: #fff;
  416. border-radius: 20rpx;
  417. padding: 24rpx 26rpx;
  418. margin-bottom: 20rpx;
  419. display: flex;
  420. border: 1px solid #E3ECF4;
  421. }
  422. .money-col { flex: 1; display: flex; flex-direction: column; align-items: center; }
  423. .money-label { font-size: 23rpx; color: #3B5A78; }
  424. .money-value { font-size: 40rpx; font-weight: 700; color: #C0392B; margin-top: 4rpx; }
  425. .sec-card, .action-card {
  426. background: #fff;
  427. border-radius: 20rpx;
  428. padding: 24rpx 26rpx;
  429. margin-bottom: 20rpx;
  430. border: 1px solid #E3ECF4;
  431. }
  432. .sec-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14rpx; }
  433. .sec-title { font-size: 28rpx; font-weight: 700; color: #1F4E79; }
  434. .sec-ok { font-size: 24rpx; color: #0E8A4F; }
  435. .sec-empty { font-size: 24rpx; color: #94A3B2; }
  436. .arrive-photo { width: 100%; height: 300rpx; border-radius: 12rpx; }
  437. .empty-box { padding: 20rpx 0; }
  438. .item-row {
  439. display: flex;
  440. justify-content: space-between;
  441. align-items: center;
  442. padding: 16rpx 0;
  443. border-bottom: 1px solid #F5FAFE;
  444. }
  445. .item-name { font-size: 27rpx; color: #1E3A5F; }
  446. .item-state { font-size: 26rpx; }
  447. .photo-grid { display: flex; flex-wrap: wrap; margin: 18rpx 0; }
  448. .photo-cell { width: 190rpx; height: 190rpx; margin: 8rpx; border-radius: 12rpx; overflow: hidden; }
  449. .photo-img { width: 100%; height: 100%; }
  450. .add-cell {
  451. background: #E8F3FC;
  452. border: 1px dashed #C5DFF3;
  453. display: flex;
  454. align-items: center;
  455. justify-content: center;
  456. }
  457. .add-text { color: #2E6FA8; font-size: 30rpx; }
  458. .main-btn {
  459. margin-top: 16rpx;
  460. background: #2E6FA8;
  461. color: #fff;
  462. font-size: 30rpx;
  463. border-radius: 44rpx;
  464. line-height: 2.4;
  465. }
  466. .hint { display: block; font-size: 22rpx; color: #94A3B2; text-align: center; margin-top: 12rpx; }
  467. .confirm-code-box {
  468. background: #F0F6FB;
  469. border-radius: 14rpx;
  470. padding: 24rpx;
  471. text-align: center;
  472. margin-bottom: 20rpx;
  473. }
  474. .code-label { display: block; font-size: 24rpx; color: #3B5A78; }
  475. .code-value { display: block; font-size: 64rpx; font-weight: 700; letter-spacing: 12rpx; color: #1F4E79; margin: 8rpx 0; }
  476. .code-tip { display: block; font-size: 22rpx; color: #94A3B2; }
  477. .code-input-row { display: flex; align-items: center; }
  478. .code-input {
  479. flex: 1;
  480. height: 84rpx;
  481. background: #F7FAFD;
  482. border: 1px solid #E3ECF4;
  483. border-radius: 12rpx;
  484. padding: 0 20rpx;
  485. font-size: 32rpx;
  486. text-align: center;
  487. }
  488. .confirm-btn {
  489. margin-left: 16rpx;
  490. background: #0E8A4F;
  491. color: #fff;
  492. font-size: 28rpx;
  493. border-radius: 12rpx;
  494. height: 84rpx;
  495. line-height: 84rpx;
  496. padding: 0 40rpx;
  497. }
  498. .done-box { text-align: center; padding: 20rpx 0; }
  499. .done-icon { display: block; font-size: 72rpx; color: #0E8A4F; font-weight: 700; }
  500. .done-title { display: block; font-size: 32rpx; font-weight: 700; color: #1E3A5F; margin-top: 8rpx; }
  501. .done-sub { display: block; font-size: 25rpx; color: #3B5A78; margin-top: 8rpx; }
  502. .eval-entry {
  503. margin-top: 16rpx;
  504. border-top: 1rpx solid #F5FAFE;
  505. padding-top: 20rpx;
  506. }
  507. .eval-btn { margin-top: 0; }
  508. .eval-done-box {
  509. margin-top: 16rpx;
  510. border-top: 1rpx solid #F5FAFE;
  511. padding-top: 20rpx;
  512. text-align: center;
  513. }
  514. .eval-done-text {
  515. font-size: 26rpx;
  516. color: #0E8A4F;
  517. font-weight: 600;
  518. }
  519. .back-tip { text-align: center; padding: 16rpx 0; }
  520. .back-text { font-size: 23rpx; color: #94A3B2; }
  521. </style>