history.vue 12 KB

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