logic.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. import { getMyOrders } from '@/api/fulfiller'
  2. import { getServiceList } from '@/api/service'
  3. export default {
  4. data() {
  5. return {
  6. currentTab: 0,
  7. tabs: ['待接送/服务', '配送/服务中', '已完成', '已拒绝'],
  8. typeFilterOptions: ['全部类型'],
  9. currentTypeFilterIdx: 0,
  10. activeDropdown: 0,
  11. hasTimeFilter: false,
  12. currentMonth: '2026年2月',
  13. weekDays: ['日', '一', '二', '三', '四', '五', '六'],
  14. calendarDays: [],
  15. selectedDateRange: [],
  16. allOrderList: [],
  17. serviceList: [],
  18. searchContent: '',
  19. startServiceTime: '',
  20. endServiceTime: '',
  21. showPetModal: false,
  22. currentPetInfo: {},
  23. showNavModal: false,
  24. navTargetItem: null,
  25. navTargetPointType: '',
  26. activeCallItem: null,
  27. showRemarkInput: false,
  28. remarkText: ''
  29. }
  30. },
  31. created() {
  32. this.initCalendar();
  33. },
  34. async onLoad() {
  35. await this.loadServiceList()
  36. await this.loadOrders()
  37. },
  38. onShow() {
  39. this.loadOrders()
  40. },
  41. watch: {
  42. currentTab() {
  43. this.loadOrders()
  44. },
  45. currentTypeFilterIdx() {
  46. this.loadOrders()
  47. }
  48. },
  49. computed: {
  50. orderList() {
  51. return this.allOrderList;
  52. }
  53. },
  54. methods: {
  55. async loadServiceList() {
  56. try {
  57. const res = await getServiceList()
  58. this.serviceList = res.data || []
  59. this.typeFilterOptions = ['全部类型', ...this.serviceList.map(s => s.name)]
  60. } catch (err) {
  61. console.error('获取服务类型失败:', err)
  62. }
  63. },
  64. async loadOrders() {
  65. try {
  66. const statusMap = { 0: 2, 1: 3, 2: 5, 3: null }
  67. const serviceId = this.currentTypeFilterIdx > 0 ? this.serviceList[this.currentTypeFilterIdx - 1]?.id : undefined
  68. const params = {
  69. status: statusMap[this.currentTab],
  70. content: this.searchContent || undefined,
  71. service: serviceId,
  72. startServiceTime: this.startServiceTime || undefined,
  73. endServiceTime: this.endServiceTime || undefined
  74. }
  75. console.log('订单列表请求参数:', params)
  76. const res = await getMyOrders(params)
  77. console.log('订单列表响应:', res)
  78. const orders = res.rows || []
  79. console.log('订单数量:', orders.length)
  80. this.allOrderList = orders.map(order => this.transformOrder(order, this.currentTab))
  81. } catch (err) {
  82. console.error('获取订单列表失败:', err)
  83. this.allOrderList = []
  84. }
  85. },
  86. transformOrder(order, tabIndex) {
  87. const service = this.serviceList.find(s => s.id === order.service)
  88. const serviceText = service?.name || '未知'
  89. const serviceIcon = service?.icon || '/static/icons/car.svg'
  90. const mode = service?.mode || 0
  91. const isRoundTrip = mode === 1
  92. // 根据 Tab 索引强制指定状态文字,忽略后端缺失的 status 字段
  93. let statusText = '接单'
  94. if (tabIndex === 0) {
  95. statusText = '接单' // 待接送/服务
  96. } else if (tabIndex === 1) {
  97. statusText = isRoundTrip ? '出发' : '开始' // 配送/服务中
  98. } else if (tabIndex === 2) {
  99. statusText = '已完成' // 已完成
  100. } else if (tabIndex === 3) {
  101. statusText = '已拒绝' // 已拒绝
  102. }
  103. return {
  104. id: order.id,
  105. type: isRoundTrip ? 1 : 2,
  106. typeText: serviceText,
  107. typeIcon: serviceIcon,
  108. statusText: statusText,
  109. price: (order.price / 100).toFixed(2),
  110. timeLabel: isRoundTrip ? '取货时间' : '服务时间',
  111. time: order.serviceTime || '',
  112. petAvatar: '/static/dog.png',
  113. petName: order.petName || '',
  114. petBreed: order.breed || '',
  115. startLocation: order.fromAddress || '',
  116. startAddress: order.fromAddress || '',
  117. startDistance: '0km',
  118. endLocation: (order.customerName || '') + ' ' + (order.customerPhone || ''),
  119. endAddress: order.toAddress || '',
  120. endDistance: '0km',
  121. serviceContent: order.remark || '',
  122. remark: order.remark || ''
  123. }
  124. },
  125. getDisplayStatus(item) {
  126. if (item.statusText === '已完成') return '已完成';
  127. if (item.statusText === '已拒绝') return '已拒绝';
  128. if (item.statusText === '接单') {
  129. return item.type === 1 ? '待接送' : '待服务';
  130. }
  131. return item.type === 1 ? '配送中' : '服务中';
  132. },
  133. getStatusClass(item) {
  134. let display = this.getDisplayStatus(item);
  135. if (display === '已完成') return 'finish';
  136. if (display === '已拒绝') return 'reject';
  137. if (display === '配送中' || display === '服务中') return 'processing';
  138. return 'highlight';
  139. },
  140. goToDetail(item) {
  141. uni.navigateTo({ url: `/pages/orders/detail?id=${item.id}` });
  142. },
  143. showPetProfile(item) {
  144. this.currentPetInfo = {
  145. ...item,
  146. petGender: 'M',
  147. petAge: '2岁',
  148. petWeight: '15kg',
  149. petPersonality: '活泼亲人,精力旺盛',
  150. petHobby: '喜欢追飞盘,爱吃肉干',
  151. petRemark: '肠胃较弱,不能乱喂零食;出门易爆冲,请拉紧牵引绳。',
  152. petTags: ['拉响警报', '不能吃鸡肉', '精力旺盛'],
  153. petLogs: [
  154. { date: '2026-02-09 14:00', content: '今天遛弯拉了两次粑粑,精神状态很好。', recorder: '王阿姨' },
  155. { date: '2026-02-08 10:30', content: '有些挑食,剩了小半碗狗粮。', recorder: '李师傅' },
  156. { date: '2026-02-05 09:00', content: '建档。', recorder: '系统记录' }
  157. ]
  158. };
  159. this.showPetModal = true;
  160. },
  161. closePetProfile() {
  162. this.showPetModal = false;
  163. },
  164. openNavigation(item, pointType) {
  165. this.navTargetItem = item;
  166. this.navTargetPointType = pointType;
  167. this.showNavModal = true;
  168. },
  169. closeNavModal() {
  170. this.showNavModal = false;
  171. },
  172. chooseMap(mapType) {
  173. let item = this.navTargetItem;
  174. let pointType = this.navTargetPointType;
  175. let name = pointType === 'start' ? item.startLocation : item.endLocation;
  176. let address = pointType === 'start' ? item.startAddress : item.endAddress;
  177. this.showNavModal = false;
  178. uni.openLocation({
  179. latitude: 30.52,
  180. longitude: 114.31,
  181. name: name || '目的地',
  182. address: address || '默认地址',
  183. success: function () {
  184. console.log('打开导航成功: ' + mapType);
  185. }
  186. });
  187. },
  188. toggleCallMenu(item) {
  189. if (this.activeCallItem === item) {
  190. this.activeCallItem = null;
  191. } else {
  192. this.activeCallItem = item;
  193. }
  194. },
  195. closeCallMenu() {
  196. this.activeCallItem = null;
  197. },
  198. doCall(type) {
  199. let phoneNum = ''
  200. if (type === 'merchant') {
  201. phoneNum = '18900008451'
  202. } else if (type === 'customer') {
  203. phoneNum = '13800000001'
  204. }
  205. if (phoneNum) {
  206. uni.makePhoneCall({ phoneNumber: phoneNum })
  207. }
  208. this.activeCallItem = null;
  209. },
  210. reportAbnormal(item) {
  211. uni.navigateTo({ url: '/pages/orders/anomaly?orderId=' + (item.id || '') });
  212. },
  213. toggleDropdown(idx) {
  214. if (this.activeDropdown === idx) {
  215. this.activeDropdown = 0;
  216. } else {
  217. this.activeDropdown = idx;
  218. }
  219. },
  220. closeDropdown() {
  221. this.activeDropdown = 0;
  222. },
  223. selectType(index) {
  224. this.currentTypeFilterIdx = index;
  225. this.closeDropdown();
  226. },
  227. initCalendar() {
  228. let days = [];
  229. for (let i = 1; i <= 28; i++) {
  230. days.push(i);
  231. }
  232. this.calendarDays = days;
  233. this.selectedDateRange = [2, 4];
  234. },
  235. prevMonth() { uni.showToast({ title: '上个月', icon: 'none' }); },
  236. nextMonth() { uni.showToast({ title: '下个月', icon: 'none' }); },
  237. selectDateItem(day) {
  238. if (this.selectedDateRange.length === 2) {
  239. this.selectedDateRange = [day];
  240. } else if (this.selectedDateRange.length === 1) {
  241. let start = this.selectedDateRange[0];
  242. if (day > start) {
  243. this.selectedDateRange = [start, day];
  244. } else if (day < start) {
  245. this.selectedDateRange = [day, start];
  246. } else {
  247. this.selectedDateRange = [];
  248. }
  249. } else {
  250. this.selectedDateRange = [day];
  251. }
  252. },
  253. getDateClass(day) {
  254. if (this.selectedDateRange.length === 0) return '';
  255. if (this.selectedDateRange.length === 1) {
  256. return day === this.selectedDateRange[0] ? 'is-start' : '';
  257. }
  258. let start = this.selectedDateRange[0];
  259. let end = this.selectedDateRange[1];
  260. if (day === start) return 'is-start';
  261. if (day === end) return 'is-end';
  262. if (day > start && day < end) return 'is-between';
  263. return '';
  264. },
  265. resetTimeFilter() {
  266. this.hasTimeFilter = false;
  267. this.selectedDateRange = [];
  268. uni.showToast({ title: '已重置服务时间', icon: 'none' });
  269. this.closeDropdown();
  270. },
  271. confirmTimeFilter() {
  272. if (this.selectedDateRange.length === 0) {
  273. uni.showToast({ title: '请先选择日期', icon: 'none' });
  274. return;
  275. }
  276. let text = this.selectedDateRange.length === 2 ?
  277. `${this.selectedDateRange[0]}日-${this.selectedDateRange[1]}日` :
  278. `${this.selectedDateRange[0]}日`;
  279. uni.showToast({ title: '已应用: ' + text, icon: 'none' });
  280. this.hasTimeFilter = true;
  281. this.closeDropdown();
  282. },
  283. getMainActionText(item) {
  284. return '查看详情';
  285. },
  286. mainAction(item) {
  287. uni.navigateTo({ url: `/pages/orders/detail?id=${item.id}` });
  288. },
  289. openRemarkInput() {
  290. this.remarkText = '';
  291. this.showRemarkInput = true;
  292. },
  293. closeRemarkInput() {
  294. this.showRemarkInput = false;
  295. this.remarkText = '';
  296. },
  297. submitRemark() {
  298. const text = this.remarkText.trim();
  299. if (!text) {
  300. uni.showToast({ title: '备注内容不能为空', icon: 'none' });
  301. return;
  302. }
  303. const now = new Date();
  304. const dateStr = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}-${String(now.getDate()).padStart(2, '0')} ${String(now.getHours()).padStart(2, '0')}:${String(now.getMinutes()).padStart(2, '0')}`;
  305. if (!this.currentPetInfo.petLogs) {
  306. this.$set(this.currentPetInfo, 'petLogs', []);
  307. }
  308. this.currentPetInfo.petLogs.unshift({
  309. date: dateStr,
  310. content: text,
  311. recorder: '我'
  312. });
  313. uni.showToast({ title: '备注已添加', icon: 'success' });
  314. this.closeRemarkInput();
  315. }
  316. }
  317. }