index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. <template>
  2. <view class="work-page">
  3. <!-- 收入速览:钱在最上方,这是健康服务人员最关心的 -->
  4. <view class="income-card" @click="goEarnings">
  5. <view class="income-left">
  6. <text class="income-label">本月到手</text>
  7. <text class="income-value">¥{{ monthIncomeText }}</text>
  8. </view>
  9. <view class="income-right">
  10. <text class="income-sub">累计 ¥{{ totalIncomeText }}</text>
  11. <text class="income-sub">待确认 ¥{{ pendingIncomeText }}</text>
  12. <text class="income-arrow">›</text>
  13. </view>
  14. </view>
  15. <!-- 加载骨架 / 错误态 -->
  16. <LoadingSkeleton v-if="loading" :rows="4" />
  17. <ErrorState v-else-if="error" message="工单数据加载失败" @retry="reload" />
  18. <template v-else>
  19. <!-- 今日上门 -->
  20. <view class="group">
  21. <view class="group-head">
  22. <text class="group-title">今日上门</text>
  23. <text class="group-count">{{ todayList.length }} 单</text>
  24. </view>
  25. <view v-if="todayList.length === 0" class="empty-box">
  26. <text class="empty-text">今天没有安排,接单后就会出现在这里</text>
  27. </view>
  28. <view v-for="item in todayList" :key="item.id" class="order-card" @click="goDetail(item)">
  29. <view class="order-top">
  30. <view class="order-time-wrap">
  31. <text class="order-time">{{ item.startAt || item.orderDate }}</text>
  32. <text v-if="item.source === 'org_created'" class="source-tag">机构派单</text>
  33. </view>
  34. <text class="order-status" :style="{ background: statusBg(item.status) }">{{ statusText(item.status) }}</text>
  35. </view>
  36. <text class="order-family">{{ item.familyName || '客户家' }}</text>
  37. <text class="order-address">{{ item.address || '地址待确认' }}</text>
  38. <view class="order-bottom">
  39. <text class="order-type">{{ typeText(item.serviceType) }}</text>
  40. <text class="order-money">¥{{ incomeText(item.staffIncome) }}</text>
  41. </view>
  42. </view>
  43. </view>
  44. <!-- 待接单 -->
  45. <view class="group">
  46. <view class="group-head">
  47. <text class="group-title">待接单</text>
  48. <text class="group-count">{{ pendingList.length }} 单</text>
  49. </view>
  50. <view v-if="pendingList.length === 0" class="empty-box">
  51. <text class="empty-text">暂时没有新单,有新单会通知您</text>
  52. </view>
  53. <view v-for="item in pendingList" :key="item.id" class="order-card pending-card">
  54. <view class="order-top">
  55. <view class="order-time-wrap">
  56. <text class="order-time">{{ item.orderDate }} {{ item.startAt || '' }}</text>
  57. <text v-if="item.source === 'org_created'" class="source-tag">机构派单</text>
  58. </view>
  59. <text class="order-status" :style="{ background: statusBg(item.status) }">待接单</text>
  60. </view>
  61. <text class="order-family">{{ item.familyName || '客户家' }}</text>
  62. <text class="order-address">{{ item.address || '地址待确认' }}</text>
  63. <view class="order-bottom">
  64. <text class="order-type">{{ typeText(item.serviceType) }}</text>
  65. <text class="order-money">¥{{ incomeText(item.staffIncome) }}</text>
  66. </view>
  67. <button class="accept-btn" @click.stop="doAccept(item)">接这单</button>
  68. </view>
  69. </view>
  70. <!-- 进行中 -->
  71. <view class="group">
  72. <view class="group-head">
  73. <text class="group-title">进行中</text>
  74. <text class="group-count">{{ doingList.length }} 单</text>
  75. </view>
  76. <view v-if="doingList.length === 0" class="empty-box">
  77. <text class="empty-text">暂无进行中的单</text>
  78. </view>
  79. <view v-for="item in doingList" :key="item.id" class="order-card" @click="goDetail(item)">
  80. <view class="order-top">
  81. <view class="order-time-wrap">
  82. <text class="order-time">{{ item.orderDate }} {{ item.startAt || '' }}</text>
  83. <text v-if="item.source === 'org_created'" class="source-tag">机构派单</text>
  84. </view>
  85. <text class="order-status" :style="{ background: statusBg(item.status) }">{{ statusText(item.status) }}</text>
  86. </view>
  87. <text class="order-family">{{ item.familyName || '客户家' }}</text>
  88. <text class="order-address">{{ item.address || '地址待确认' }}</text>
  89. <view class="order-bottom">
  90. <text class="order-type">{{ typeText(item.serviceType) }}</text>
  91. <text class="order-money">¥{{ incomeText(item.staffIncome) }}</text>
  92. </view>
  93. </view>
  94. </view>
  95. <!-- 已完成 -->
  96. <view class="group">
  97. <view class="group-head">
  98. <text class="group-title">已完成</text>
  99. <text class="group-count">{{ doneList.length }} 单</text>
  100. </view>
  101. <view v-if="doneList.length === 0" class="empty-box">
  102. <text class="empty-text">还没有完成的单</text>
  103. </view>
  104. <view v-for="item in doneList" :key="item.id" class="order-card" @click="goDetail(item)">
  105. <view class="order-top">
  106. <view class="order-time-wrap">
  107. <text class="order-time">{{ item.orderDate }}</text>
  108. <text v-if="item.source === 'org_created'" class="source-tag">机构派单</text>
  109. </view>
  110. <text class="order-status" :style="{ background: statusBg(item.status) }">{{ statusText(item.status) }}</text>
  111. </view>
  112. <text class="order-family">{{ item.familyName || '客户家' }}</text>
  113. <view class="order-bottom">
  114. <text class="order-type">{{ item.arriveAt ? '到岗 ' + item.arriveAt : '' }}</text>
  115. <text class="order-money">¥{{ incomeText(item.staffIncome) }}</text>
  116. </view>
  117. </view>
  118. </view>
  119. <view class="footer-tip">
  120. <text class="footer-text">有疑问请联系机构对接人</text>
  121. </view>
  122. </template>
  123. </view>
  124. </template>
  125. <script>
  126. import { getMyServiceOrders, getServiceEarnings, acceptServiceOrder } from '@/utils/api.js'
  127. import LoadingSkeleton from '@/components/loading-skeleton.vue'
  128. import ErrorState from '@/components/error-state.vue'
  129. export default {
  130. components: { LoadingSkeleton, ErrorState },
  131. data() {
  132. return {
  133. todayList: [],
  134. pendingList: [],
  135. doingList: [],
  136. doneList: [],
  137. totalIncome: 0,
  138. monthIncome: 0,
  139. pendingIncome: 0,
  140. loading: true,
  141. error: false
  142. }
  143. },
  144. computed: {
  145. totalIncomeText() {
  146. return this.fenToYuan(this.totalIncome)
  147. },
  148. monthIncomeText() {
  149. return this.fenToYuan(this.monthIncome)
  150. },
  151. pendingIncomeText() {
  152. return this.fenToYuan(this.pendingIncome)
  153. }
  154. },
  155. onShow() {
  156. this.loadOrders()
  157. this.loadEarnings()
  158. },
  159. reload() {
  160. this.loadOrders()
  161. this.loadEarnings()
  162. },
  163. methods: {
  164. loadOrders() {
  165. this.loading = true
  166. this.error = false
  167. getMyServiceOrders().then(res => {
  168. if (!res || !res.data) return
  169. const groups = res.data
  170. this.todayList = this.pickGroup(groups, 'today')
  171. this.pendingList = this.pickGroup(groups, 'pending')
  172. this.doingList = this.pickGroup(groups, 'doing')
  173. this.doneList = this.pickGroup(groups, 'done')
  174. }).catch(() => {
  175. this.error = true
  176. }).finally(() => {
  177. this.loading = false
  178. })
  179. },
  180. loadEarnings() {
  181. getServiceEarnings().then(res => {
  182. if (!res || !res.data) return
  183. this.totalIncome = res.data.totalIncome || 0
  184. this.monthIncome = res.data.monthIncome || 0
  185. this.pendingIncome = res.data.pendingIncome || 0
  186. }).catch(() => {})
  187. },
  188. pickGroup(groups, key) {
  189. for (var i = 0; i < groups.length; i++) {
  190. if (groups[i].key === key) {
  191. return groups[i].list || []
  192. }
  193. }
  194. return []
  195. },
  196. doAccept(item) {
  197. var self = this
  198. uni.showModal({
  199. title: '确认接单',
  200. content: '接下这单后,请在服务时间准时上门。',
  201. success: function (res) {
  202. if (!res.confirm) return
  203. acceptServiceOrder(item.id).then(function (r) {
  204. if (r && r.code === 200) {
  205. uni.showToast({ title: '接单成功', icon: 'success' })
  206. self.loadOrders()
  207. self.loadEarnings()
  208. } else {
  209. uni.showToast({ title: (r && r.message) || '接单失败', icon: 'none' })
  210. }
  211. }).catch(function () {
  212. uni.showToast({ title: '接单失败', icon: 'none' })
  213. })
  214. }
  215. })
  216. },
  217. goDetail(item) {
  218. uni.navigateTo({ url: '/pages/work/detail?orderId=' + item.id })
  219. },
  220. goEarnings() {
  221. uni.navigateTo({ url: '/pages/work/earnings' })
  222. },
  223. statusText(status) {
  224. if (status === 'accepted') return '已接单'
  225. if (status === 'arrived') return '已到岗'
  226. if (status === 'doing') return '服务中'
  227. if (status === 'done') return '待客户确认'
  228. if (status === 'confirmed') return '已完成'
  229. if (status === 'pending') return '待接单'
  230. return '进行中'
  231. },
  232. statusBg(status) {
  233. if (status === 'confirmed') return '#0E8A4F'
  234. if (status === 'done') return '#B9770E'
  235. if (status === 'pending') return '#2E6FA8'
  236. return '#3B5A78'
  237. },
  238. typeText(type) {
  239. if (type === 'cleaning') return '保洁'
  240. if (type === 'care') return '照护'
  241. if (type === 'escort') return '陪诊'
  242. if (type === 'meal') return '助餐'
  243. return '上门服务'
  244. },
  245. fenToYuan(fen) {
  246. var n = fen || 0
  247. return (n / 100).toFixed(2)
  248. },
  249. incomeText(fen) {
  250. return this.fenToYuan(fen)
  251. }
  252. }
  253. }
  254. </script>
  255. <style scoped>
  256. .work-page {
  257. min-height: 100vh;
  258. background: #F5FAFE;
  259. padding: 20rpx 24rpx 40rpx;
  260. }
  261. .income-card {
  262. background: linear-gradient(135deg, #1F4E79, #2E6FA8);
  263. border-radius: 20rpx;
  264. padding: 32rpx 28rpx;
  265. display: flex;
  266. justify-content: space-between;
  267. align-items: center;
  268. margin-bottom: 24rpx;
  269. }
  270. .income-left { display: flex; flex-direction: column; }
  271. .income-label { font-size: 24rpx; color: rgba(255,255,255,0.8); }
  272. .income-value { font-size: 52rpx; font-weight: 700; color: #fff; line-height: 1.3; }
  273. .income-right { display: flex; flex-direction: column; align-items: flex-end; position: relative; }
  274. .income-sub { font-size: 22rpx; color: rgba(255,255,255,0.82); line-height: 1.7; }
  275. .income-arrow { position: absolute; right: -4rpx; top: 50%; transform: translateY(-50%); font-size: 34rpx; color: rgba(255,255,255,0.6); }
  276. .group { margin-bottom: 28rpx; }
  277. .group-head {
  278. display: flex;
  279. justify-content: space-between;
  280. align-items: baseline;
  281. margin-bottom: 14rpx;
  282. padding: 0 4rpx;
  283. }
  284. .group-title { font-size: 30rpx; font-weight: 700; color: #1F4E79; }
  285. .group-count { font-size: 24rpx; color: #3B5A78; }
  286. .empty-box {
  287. background: #fff;
  288. border-radius: 16rpx;
  289. padding: 34rpx 24rpx;
  290. text-align: center;
  291. border: 1px solid #E3ECF4;
  292. }
  293. .empty-text { font-size: 26rpx; color: #94A3B2; }
  294. .order-card {
  295. background: #fff;
  296. border-radius: 16rpx;
  297. padding: 24rpx 24rpx 20rpx;
  298. margin-bottom: 16rpx;
  299. border: 1px solid #E3ECF4;
  300. }
  301. .pending-card { border-color: #C5DFF3; }
  302. .order-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12rpx; }
  303. .order-time-wrap { display: flex; align-items: center; }
  304. .order-time { font-size: 26rpx; color: #2E6FA8; font-weight: 600; }
  305. .source-tag {
  306. margin-left: 12rpx;
  307. font-size: 20rpx;
  308. color: #B9770E;
  309. background: #FEF3E2;
  310. border: 1rpx solid #B9770E;
  311. border-radius: 8rpx;
  312. padding: 2rpx 12rpx;
  313. line-height: 1.5;
  314. }
  315. .order-status { font-size: 20rpx; color: #fff; padding: 3rpx 14rpx; border-radius: 20rpx; }
  316. .order-family { display: block; font-size: 32rpx; font-weight: 700; color: #1E3A5F; margin-bottom: 6rpx; }
  317. .order-address { display: block; font-size: 25rpx; color: #3B5A78; margin-bottom: 14rpx; }
  318. .order-bottom { display: flex; justify-content: space-between; align-items: center; }
  319. .order-type { font-size: 24rpx; color: #3B5A78; }
  320. .order-money { font-size: 34rpx; font-weight: 700; color: #C0392B; }
  321. .accept-btn {
  322. margin-top: 18rpx;
  323. background: #2E6FA8;
  324. color: #fff;
  325. font-size: 30rpx;
  326. border-radius: 44rpx;
  327. line-height: 2.4;
  328. }
  329. .footer-tip { text-align: center; padding: 20rpx 0; }
  330. .footer-text { font-size: 23rpx; color: #94A3B2; }
  331. </style>