logic.js 13 KB

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