history.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. <template>
  2. <view class="common-page" style="padding: 0;">
  3. <view class="header">
  4. <u-navbar title="历史工单" :border="false" fixed safe-area-inset-top>
  5. <template #left>
  6. <u-icon name="arrow-left" color="#333333" size="20" @click="goBack"></u-icon>
  7. </template>
  8. </u-navbar>
  9. </view>
  10. <view class="content" v-if="workOrderDetail">
  11. <!-- 工单信息 -->
  12. <view class="info-section">
  13. <view class="info-row">
  14. <text class="label">快递单号:</text>
  15. <text class="value">{{ workOrderDetail.waybillCode }}</text>
  16. </view>
  17. <view class="info-row" v-if="workOrderDetail.orderId">
  18. <text class="label">订单编号:</text>
  19. <text class="value link-text" @click="goToOrderDetail">{{ workOrderDetail.orderId }}</text>
  20. </view>
  21. <view class="info-row">
  22. <text class="label">任务类型:</text>
  23. <text class="value">{{ workOrderDetail.taskTypeName || '-' }}</text>
  24. </view>
  25. <view class="info-row">
  26. <text class="label">验货状态:</text>
  27. <text class="value">{{ workOrderDetail.inspectionStatusName || '-' }}</text>
  28. </view>
  29. <view class="info-row">
  30. <text class="label">任务详情:</text>
  31. <text class="value">{{ workOrderDetail.deatil || '-' }}</text>
  32. </view>
  33. <view class="info-row">
  34. <text class="label">创建人:</text>
  35. <text class="value">{{ workOrderDetail.createUserName || '-' }}</text>
  36. </view>
  37. <view class="info-row">
  38. <text class="label">创建时间:</text>
  39. <text class="value">{{ formatTime(workOrderDetail.createTime) }}</text>
  40. </view>
  41. <view class="info-row">
  42. <text class="label">任务状态:</text>
  43. <text class="value status-text" :class="'status-' + workOrderDetail.status">{{ getStatusText(workOrderDetail.status) }}</text>
  44. </view>
  45. <view class="info-row">
  46. <text class="label">指派人:</text>
  47. <text class="value">{{ workOrderDetail.handleUsers.map(item => item.userName).join(',') || '-' }}</text>
  48. </view>
  49. <!-- 图片展示 -->
  50. <view class="image-list" v-if="workOrderDetail.imgInfo && workOrderDetail.imgInfo.imgUrlList.length > 0">
  51. <image
  52. v-for="(img, index) in workOrderDetail.imgInfo.imgUrlList"
  53. :key="index"
  54. :src="img"
  55. mode="aspectFill"
  56. class="work-order-image"
  57. @click="previewImage(index)"
  58. ></image>
  59. </view>
  60. </view>
  61. </view>
  62. <!-- 工单变更记录 -->
  63. <TrackRecord :records="records" />
  64. <!-- 底部操作按钮 -->
  65. <view class="fixed-bottom" v-if="showButtons">
  66. <template v-if="isCreator">
  67. <!-- 创建人按钮 -->
  68. <template v-if="workOrderDetail.status === 1 || workOrderDetail.status === 2 || workOrderDetail.status === 3">
  69. <!-- 待处理、处理中、仓库处理状态 -->
  70. <u-button type="warning" size="large" text="编辑" @click="handleEdit"></u-button>
  71. <u-button type="primary" size="large" text="完成" @click="handleFinish"></u-button>
  72. <u-button type="error" size="large" text="作废" @click="handleCancel"></u-button>
  73. </template>
  74. <template v-else-if="workOrderDetail.status === 4 || workOrderDetail.status === 5">
  75. <!-- 已完成、已作废状态 -->
  76. <u-button type="primary" size="large" text="重开" @click="handleReopen"></u-button>
  77. </template>
  78. </template>
  79. <template v-else>
  80. <!-- 被指派人按钮 -->
  81. <template v-if="workOrderDetail.status === 1 || workOrderDetail.status === 2 || workOrderDetail.status === 3">
  82. <!-- 未处理、处理中、仓库处理状态 -->
  83. <u-button type="warning" size="large" text="编辑" @click="handleEdit"></u-button>
  84. <u-button type="primary" size="large" text="完成" @click="handleFinish"></u-button>
  85. </template>
  86. <!-- 已完成、已作废状态无操作按钮 -->
  87. </template>
  88. </view>
  89. </view>
  90. </template>
  91. <script setup>
  92. import { ref, computed, onMounted } from 'vue'
  93. import { onLoad } from '@dcloudio/uni-app'
  94. import TrackRecord from '@/pages/order/components/track-record.vue'
  95. const workOrderId = ref('')
  96. const orderType = ref('') // 1-卖书 2-回收
  97. const waybillCode = ref('')
  98. const orderId = ref('')
  99. const workOrderDetail = ref(null)
  100. const currentUserId = ref(null)
  101. const records = ref([])
  102. // 判断是否为创建人
  103. const isCreator = computed(() => {
  104. if (!workOrderDetail.value || !currentUserId.value) return false
  105. return workOrderDetail.value.createUserId === currentUserId.value
  106. })
  107. // 是否显示按钮
  108. const showButtons = computed(() => {
  109. if (!workOrderDetail.value) return false
  110. const status = workOrderDetail.value.status
  111. // 状态:1-待处理 2-处理中 3-仓库处理 4-完成 5-作废
  112. return [1, 2, 3, 4, 5].includes(status)
  113. })
  114. // 获取状态文本
  115. const getStatusText = (status) => {
  116. const statusMap = {
  117. 1: '待处理',
  118. 2: '处理中',
  119. 3: '仓库处理',
  120. 4: '已完成',
  121. 5: '已作废'
  122. }
  123. return statusMap[status] || '未知状态'
  124. }
  125. // 格式化时间
  126. const formatTime = (time) => {
  127. if (!time) return '-'
  128. return time.replace('T', ' ').substring(0, 19)
  129. }
  130. // 获取工单详情
  131. const getWorkOrderDetail = async () => {
  132. try {
  133. uni.showLoading({ title: '加载中...' })
  134. const res = await uni.$u.http.get('/app/workOrder/getWorkOrderDetail', {
  135. params: { workOrderId: workOrderId.value }
  136. })
  137. if (res.code === 200 && res.data) {
  138. workOrderDetail.value = res.data
  139. records.value = res.data.changeRecords || []
  140. } else {
  141. uni.$u.toast(res.msg || '获取工单详情失败')
  142. }
  143. } catch (error) {
  144. console.error(error)
  145. uni.$u.toast('网络错误')
  146. } finally {
  147. uni.hideLoading()
  148. }
  149. }
  150. // 预览图片
  151. const previewImage = (index) => {
  152. if (workOrderDetail.value?.imgInfo) {
  153. const urls = Array.isArray(workOrderDetail.value.imgInfo) ? workOrderDetail.value.imgInfo : workOrderDetail.value.imgInfo.split(',')
  154. if (urls.length > 0) {
  155. uni.previewImage({
  156. urls: urls,
  157. current: index
  158. })
  159. }
  160. }
  161. }
  162. // 返回上一页
  163. const goBack = () => {
  164. uni.navigateBack()
  165. }
  166. // 跳转到订单详情
  167. const goToOrderDetail = () => {
  168. if (!workOrderDetail.value?.orderId) return
  169. uni.navigateTo({
  170. url: `/pages/index/detail/index?id=${workOrderDetail.value.orderId}`
  171. })
  172. }
  173. // 编辑工单
  174. const handleEdit = () => {
  175. uni.navigateTo({
  176. url: `/pages/order/${orderType.value == 1 ? 'mall' : 'recycle'}/created?waybillCode=${waybillCode.value}&orderId=${orderId.value}&workOrderId=${workOrderId.value}&mode=edit`
  177. })
  178. }
  179. // 完成工单
  180. const handleFinish = async () => {
  181. uni.showModal({
  182. title: '提示',
  183. content: '确定要完成该工单吗?',
  184. success: async (res) => {
  185. if (res.confirm) {
  186. try {
  187. uni.showLoading({ title: '提交中...' })
  188. const result = await uni.$u.http.post('/app/workOrder/finish', {
  189. ids: [workOrderId.value]
  190. })
  191. if (result.code === 200) {
  192. uni.$u.ttsModule.speak('提交成功')
  193. uni.$u.toast('操作成功')
  194. getWorkOrderDetail()
  195. } else {
  196. uni.$u.toast(result.msg || '操作失败')
  197. }
  198. } catch (error) {
  199. console.error(error)
  200. uni.$u.toast('网络错误')
  201. } finally {
  202. uni.hideLoading()
  203. }
  204. }
  205. }
  206. })
  207. }
  208. // 作废工单
  209. const handleCancel = async () => {
  210. uni.showModal({
  211. title: '提示',
  212. content: '确定要作废该工单吗?',
  213. success: async (res) => {
  214. if (res.confirm) {
  215. try {
  216. uni.showLoading({ title: '提交中...' })
  217. const result = await uni.$u.http.post('/app/workOrder/cancel', {
  218. id: workOrderId.value
  219. })
  220. if (result.code === 200) {
  221. uni.$u.ttsModule.speak('操作成功')
  222. uni.$u.toast('操作成功')
  223. getWorkOrderDetail()
  224. } else {
  225. uni.$u.toast(result.msg || '操作失败')
  226. }
  227. } catch (error) {
  228. console.error(error)
  229. uni.$u.toast('网络错误')
  230. } finally {
  231. uni.hideLoading()
  232. }
  233. }
  234. }
  235. })
  236. }
  237. // 重开工单(重新打开已完成的工单)
  238. const handleReopen = async () => {
  239. uni.showModal({
  240. title: '提示',
  241. content: '确定要重开该工单吗?',
  242. success: async (res) => {
  243. if (res.confirm) {
  244. try {
  245. uni.showLoading({ title: '提交中...' })
  246. const result = await uni.$u.http.post('/app/workOrder/reopen', {
  247. id: workOrderId.value
  248. })
  249. if (result.code === 200) {
  250. uni.$u.ttsModule.speak('操作成功')
  251. uni.$u.toast('操作成功')
  252. getWorkOrderDetail()
  253. } else {
  254. uni.$u.toast(result.msg || '操作失败')
  255. }
  256. } catch (error) {
  257. console.error(error)
  258. uni.$u.toast('网络错误')
  259. } finally {
  260. uni.hideLoading()
  261. }
  262. }
  263. }
  264. })
  265. }
  266. onLoad((options) => {
  267. workOrderId.value = options.workOrderId
  268. orderType.value = options.type
  269. waybillCode.value = options.waybillCode || ''
  270. orderId.value = options.orderId || ''
  271. // 获取当前用户ID(这里需要从用户信息中获取,暂时使用固定值或从缓存读取)
  272. const userInfo = uni.getStorageSync('userInfo') || {}
  273. currentUserId.value = userInfo.userId || null
  274. // 加载工单详情
  275. getWorkOrderDetail()
  276. })
  277. </script>
  278. <style lang="scss" scoped>
  279. .content {
  280. padding-top: 12px;
  281. border-radius: 0;
  282. /* #ifdef APP-PLUS */
  283. padding-top: 100px;
  284. /* #endif */
  285. }
  286. .info-section {
  287. background-color: #ffffff;
  288. padding: 20px;
  289. margin-bottom: 12px;
  290. }
  291. .info-row {
  292. display: flex;
  293. align-items: flex-start;
  294. margin-bottom: 16px;
  295. line-height: 1.5;
  296. &:last-child {
  297. margin-bottom: 0;
  298. }
  299. }
  300. .label {
  301. color: #666;
  302. font-size: 28rpx;
  303. width: 160rpx;
  304. flex-shrink: 0;
  305. }
  306. .value {
  307. color: #333;
  308. font-size: 28rpx;
  309. flex: 1;
  310. word-break: break-all;
  311. }
  312. .link-text {
  313. color: #2979ff;
  314. cursor: pointer;
  315. &:active {
  316. opacity: 0.7;
  317. }
  318. }
  319. .status-text {
  320. &.status-1 {
  321. color: #e6a23c; // 待处理 - 橙色
  322. }
  323. &.status-2 {
  324. color: #409eff; // 处理中 - 蓝色
  325. }
  326. &.status-3 {
  327. color: #909399; // 仓库处理 - 灰色
  328. }
  329. &.status-4 {
  330. color: #67c23a; // 已完成 - 绿色
  331. }
  332. &.status-5 {
  333. color: #f56c6c; // 已作废 - 红色
  334. }
  335. }
  336. .image-list {
  337. display: flex;
  338. flex-wrap: wrap;
  339. gap: 20rpx;
  340. margin-top: 20rpx;
  341. }
  342. .work-order-image {
  343. width: 180rpx;
  344. height: 180rpx;
  345. border-radius: 8rpx;
  346. }
  347. </style>