index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. <template>
  2. <div class="order-evaluation-container">
  3. <PageTitle title="订单评价" />
  4. <StatusTabs v-model="activeMainTab" :tabs="mainTabs" type="line" />
  5. <!-- <div class="search-bar">
  6. <el-input v-model="queryParams.keyword" placeholder="搜索" style="width: 260px" clearable>
  7. <template #prefix
  8. ><el-icon><Search /></el-icon
  9. ></template>
  10. </el-input>
  11. <div style="width: 260px">
  12. <el-date-picker
  13. v-model="queryParams.dateRange"
  14. type="daterange"
  15. range-separator="—"
  16. start-placeholder="开始日期"
  17. end-placeholder="结束日期"
  18. style="width: 260px"
  19. />
  20. </div>
  21. </div>
  22. <div class="filter-bar">
  23. <el-tree-select
  24. v-model="queryParams.department"
  25. style="width: 160px"
  26. :data="deptList"
  27. :props="{ value: 'deptId', label: 'deptName', children: 'children' }"
  28. value-key="deptId"
  29. placeholder="下单部门"
  30. check-strictly
  31. :render-after-expand="false"
  32. clearable
  33. >
  34. </el-tree-select>
  35. <el-select v-model="queryParams.status" placeholder="状态" style="width: 160px" clearable>
  36. <el-option v-for="dict in order_status" :key="dict.value" :label="dict.label" :value="dict.value" />
  37. </el-select>
  38. <el-select v-model="queryParams.payType" placeholder="支付方式" style="width: 160px" clearable>
  39. <el-option v-for="dict in pay_method" :key="dict.value" :label="dict.label" :value="dict.value" />
  40. </el-select>
  41. </div>-->
  42. <div class="order-list">
  43. <div v-for="(order, orderIndex) in orderList" :key="orderIndex" class="order-card">
  44. <div class="order-header flex-row-between">
  45. <div class="flex-row-start">
  46. <span class="order-time">{{ order.orderTime }}</span>
  47. <span class="order-no">订单号:{{ order.orderNo }}</span>
  48. </div>
  49. <div class="flex-row-start">
  50. <!-- <div class="expand-btn" @click="handleViewDetail(order)">
  51. <span style="margin-right: 5px; margin-bottom: 2px">订单详情</span>
  52. <el-icon><ArrowRight /></el-icon>
  53. </div> -->
  54. <div class="open-btn" v-if="order.products && order.products.length > 1" @click="order.expanded = !order.expanded">
  55. <span style="margin-right: 5px"> {{ order.expanded ? '收起' : '展开' }}</span>
  56. <el-icon v-if="order.expanded"><ArrowUp /></el-icon>
  57. <el-icon v-else><ArrowDown /></el-icon>
  58. </div>
  59. </div>
  60. </div>
  61. <div class="product-list">
  62. <div
  63. v-for="(product, productIndex) in order.expanded ? order.products : order.products.slice(0, 1)"
  64. :key="productIndex"
  65. class="product-row"
  66. >
  67. <div class="product-info-cell">
  68. <div class="product-image">
  69. <el-image :src="product.image" fit="contain">
  70. <template #error
  71. ><div class="image-placeholder">
  72. <el-icon :size="30" color="#ccc"><Picture /></el-icon></div
  73. ></template>
  74. </el-image>
  75. </div>
  76. <div class="product-detail">
  77. <div class="product-name ellipsis">{{ product.name }}</div>
  78. <div class="product-spec">{{ product.spec1 }} | {{ product.spec2 }}</div>
  79. <div class="product-price">¥{{ product.price }}</div>
  80. </div>
  81. <div class="product-quantity">x{{ product.quantity }}</div>
  82. </div>
  83. <div class="amount-cell" v-if="productIndex === 0">
  84. <div class="amount-info">
  85. <span class="label">支付款:</span><span class="value highlight">¥{{ order.payAmount }}</span>
  86. </div>
  87. <div class="amount-info">
  88. <span class="label">{{ order.payMethod }}</span>
  89. </div>
  90. </div>
  91. <div class="status-cell" v-if="productIndex === 0">
  92. <span class="status-text success">{{ order.statusText }}</span>
  93. </div>
  94. <div class="action-cell" v-if="productIndex === 0">
  95. <el-button v-if="activeMainTab === '0'" type="primary" link @click="handleEvaluate(order)">评价</el-button>
  96. <el-button v-if="activeMainTab === '1'" type="primary" link @click="handleFollowUpEvaluate(order)">追评</el-button>
  97. <el-button v-if="activeMainTab === '2'" type="primary" link @click="handleViewEvaluation(order)">查看评价</el-button>
  98. </div>
  99. </div>
  100. <!-- 显示更多商品提示 -->
  101. <div v-if="!order.expanded && order.products.length > 1" class="more-products-hint">
  102. 该订单共 {{ order.products.length }} 件商品,点击展开查看全部
  103. </div>
  104. </div>
  105. </div>
  106. <el-empty v-if="orderList.length === 0" description="暂无订单" />
  107. </div>
  108. </div>
  109. </template>
  110. <script setup lang="ts">
  111. import { ref, reactive, computed, onMounted, getCurrentInstance, toRefs, ComponentInternalInstance, watch } from 'vue';
  112. import { useRouter } from 'vue-router';
  113. import { Search, Edit, ChatDotRound, Document, ArrowRight, Picture, Plus } from '@element-plus/icons-vue';
  114. import { ElMessage } from 'element-plus';
  115. import { PageTitle, StatusTabs } from '@/components';
  116. import { getOrderList, getOrderProducts, getEvalutionList } from '@/api/pc/enterprise/order';
  117. import type { OrderMain, OrderStatusStats } from '@/api/pc/enterprise/orderTypes';
  118. import { getDeptTree } from '@/api/pc/organization';
  119. import { DeptInfo } from '@/api/pc/organization/types';
  120. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  121. const { order_status, pay_method } = toRefs<any>(proxy?.useDict('order_status', 'pay_method'));
  122. const router = useRouter();
  123. const activeMainTab = ref('0');
  124. const deptList = ref([]);
  125. const mainTabs = [
  126. { key: '0', label: '待评价', icon: Edit },
  127. { key: '1', label: '待追评', icon: ChatDotRound },
  128. { key: '2', label: '已评价', icon: Document }
  129. ];
  130. const queryParams = reactive({ keyword: '', dateRange: null, department: '', status: '', payType: '', evaluationStatus: '' });
  131. const pendingOrders = ref([]);
  132. const followUpOrders = ref([]);
  133. const evaluatedOrders = ref([]);
  134. const orderList = computed(() => {
  135. if (activeMainTab.value === '0') return pendingOrders.value;
  136. else if (activeMainTab.value === '1') return followUpOrders.value;
  137. else return evaluatedOrders.value;
  138. });
  139. // 根据订单状态获取状态文本
  140. const getStatusText = (status: string) => {
  141. const statusMap: Record<string, string> = {
  142. '0': '待支付',
  143. '1': '待确认',
  144. '2': '待发货',
  145. '3': '部分发货',
  146. '4': '发货完成',
  147. '5': '已完成',
  148. '6': '已关闭',
  149. '7': '已取消'
  150. };
  151. return statusMap[status] || status;
  152. };
  153. // 获取支付方式文本
  154. const getPayMethodText = (payType: string) => {
  155. const payMethod = pay_method.value?.find((item: any) => item.value === payType);
  156. return payMethod ? payMethod.label : payType;
  157. };
  158. // 加载订单商品
  159. const loadOrderProducts = async (orderId: number) => {
  160. try {
  161. const res = await getOrderProducts([orderId]);
  162. if (res.code === 200 && res.rows) {
  163. return res.rows.map((product: any) => ({
  164. id: product.id,
  165. productId: product.productId,
  166. name: product.productName || '',
  167. productName: product.productName || '',
  168. spec1: product.productUnit || '',
  169. spec2: product.productNo || '',
  170. price: product.orderPrice || 0,
  171. quantity: product.orderQuantity || 0,
  172. image: product.productImage || '',
  173. productImg: product.productImage || ''
  174. }));
  175. }
  176. return [];
  177. } catch (error) {
  178. console.error('加载订单商品失败:', error);
  179. return [];
  180. }
  181. };
  182. // 获取订单列表
  183. const getorders = async () => {
  184. try {
  185. const params: any = {
  186. pageNum: 1,
  187. pageSize: 100
  188. };
  189. if (queryParams.keyword) params.orderNo = queryParams.keyword;
  190. if (queryParams.dateRange && queryParams.dateRange.length === 2) {
  191. params.params = {
  192. beginTime: queryParams.dateRange[0],
  193. endTime: queryParams.dateRange[1]
  194. };
  195. }
  196. if (queryParams.department) params.department = queryParams.department;
  197. if (queryParams.status) params.orderStatus = queryParams.status;
  198. if (queryParams.payType) params.payType = queryParams.payType;
  199. // 根据当前标签页设置评价状态
  200. params.evaluationStatus = activeMainTab.value;
  201. const res = await getEvalutionList(params);
  202. if (res.code === 200 && res.rows) {
  203. // 转换订单数据并加载商品信息
  204. const orders = await Promise.all(
  205. res.rows.map(async (order: any) => {
  206. const products = await loadOrderProducts(order.orderId);
  207. return {
  208. orderId: order.orderId || 0,
  209. orderTime: order.createTime || '',
  210. orderNo: order.orderNo || '',
  211. payAmount: order.totalAmount || 0,
  212. payMethod: getPayMethodText(order.payType || ''),
  213. statusText: getStatusText(order.orderStatus || ''),
  214. orderStatus: order.orderStatus || '',
  215. products: products,
  216. expanded: false, // 默认收起状态
  217. evaluationStatus: order.evaluationStatus || '0' // 评价状态
  218. };
  219. })
  220. );
  221. // 根据当前标签页设置对应的订单列表
  222. if (activeMainTab.value === '0') {
  223. pendingOrders.value = orders;
  224. } else if (activeMainTab.value === '1') {
  225. followUpOrders.value = orders;
  226. } else {
  227. evaluatedOrders.value = orders;
  228. }
  229. }
  230. } catch (error) {
  231. console.error('获取订单列表失败:', error);
  232. ElMessage.error('获取订单列表失败');
  233. }
  234. };
  235. // 监听标签页切换,重新获取数据
  236. watch(activeMainTab, () => {
  237. getorders();
  238. });
  239. // 加载部门树
  240. const loadDeptTree = async () => {
  241. try {
  242. const res = await getDeptTree();
  243. if (res.code === 200 && res.data) {
  244. deptList.value = res.data;
  245. if (Array.isArray(res.data)) {
  246. const treeData = proxy?.handleTree<DeptInfo>(res.data, 'deptId', 'parentId');
  247. deptList.value = treeData || res.data;
  248. } else {
  249. deptList.value = [];
  250. }
  251. }
  252. } catch (error) {
  253. console.error('获取部门树失败:', error);
  254. ElMessage.error('获取部门树失败');
  255. }
  256. };
  257. const handleViewDetail = (order: any) => {
  258. router.push(`/order/orderManage/detail?orderId=${order.id}`);
  259. };
  260. const navigateToEvaluation = (order: any, type: number) => {
  261. router.push({
  262. path: '/order/orderEvaluation/evaluation',
  263. query: {
  264. orderId: order.orderId,
  265. orderNo: order.orderNo,
  266. orderTime: order.orderTime,
  267. type: type
  268. },
  269. state: {
  270. products: JSON.stringify(order.products)
  271. }
  272. } as any);
  273. };
  274. const handleEvaluate = (order: any) => {
  275. navigateToEvaluation(order, 1);
  276. };
  277. const handleFollowUpEvaluate = (order: any) => {
  278. navigateToEvaluation(order, 2);
  279. };
  280. const handleViewEvaluation = (order: any) => {
  281. navigateToEvaluation(order, 3);
  282. };
  283. // 页面加载时获取订单列表
  284. onMounted(() => {
  285. loadDeptTree();
  286. getorders();
  287. });
  288. </script>
  289. <style scoped lang="scss">
  290. .order-evaluation-container {
  291. padding: 20px;
  292. background: #fff;
  293. min-height: 100%;
  294. width: 100%;
  295. margin-bottom: 20px;
  296. }
  297. .search-bar {
  298. display: flex;
  299. align-items: center;
  300. gap: 15px;
  301. margin-bottom: 15px;
  302. }
  303. .filter-bar {
  304. display: flex;
  305. align-items: center;
  306. gap: 10px;
  307. margin-bottom: 20px;
  308. .filter-label {
  309. font-size: 14px;
  310. color: #666;
  311. }
  312. }
  313. .order-list {
  314. .order-card {
  315. border: 1px solid #eee;
  316. border-radius: 4px;
  317. margin-bottom: 15px;
  318. overflow: hidden;
  319. .order-header {
  320. display: flex;
  321. align-items: center;
  322. gap: 15px;
  323. padding: 12px 15px;
  324. background: #f9f9f9;
  325. border-bottom: 1px solid #eee;
  326. font-size: 13px;
  327. color: #666;
  328. .open-btn {
  329. color: #364153;
  330. margin-left: 10px;
  331. cursor: pointer;
  332. }
  333. .expand-btn {
  334. color: #165dff;
  335. margin-left: 10px;
  336. cursor: pointer;
  337. }
  338. .order-time {
  339. color: #333;
  340. }
  341. .expand-btn {
  342. margin-left: auto;
  343. margin-right: 10px;
  344. }
  345. .detail-btn {
  346. margin-left: 0;
  347. }
  348. }
  349. .product-list {
  350. .product-row {
  351. display: flex;
  352. border-bottom: 1px solid #f5f5f5;
  353. &:last-child {
  354. border-bottom: none;
  355. }
  356. }
  357. .product-cell {
  358. padding: 15px;
  359. display: flex;
  360. flex-direction: column;
  361. justify-content: center;
  362. }
  363. .product-info-cell {
  364. display: flex;
  365. flex: 1;
  366. padding: 15px;
  367. gap: 15px;
  368. .product-image {
  369. width: 80px;
  370. height: 80px;
  371. background: #f5f5f5;
  372. border-radius: 4px;
  373. overflow: hidden;
  374. flex-shrink: 0;
  375. .el-image {
  376. width: 100%;
  377. height: 100%;
  378. }
  379. .image-placeholder {
  380. width: 100%;
  381. height: 100%;
  382. display: flex;
  383. align-items: center;
  384. justify-content: center;
  385. }
  386. }
  387. .product-detail {
  388. flex: 1;
  389. .product-name {
  390. font-size: 14px;
  391. color: #333;
  392. margin-bottom: 5px;
  393. }
  394. .product-spec {
  395. font-size: 12px;
  396. color: #999;
  397. margin-bottom: 10px;
  398. }
  399. .product-price {
  400. font-size: 16px;
  401. font-weight: bold;
  402. color: #e60012;
  403. }
  404. }
  405. .product-quantity {
  406. font-size: 13px;
  407. color: #666;
  408. }
  409. }
  410. .amount-cell {
  411. width: 200px;
  412. padding: 15px;
  413. .amount-info {
  414. margin-bottom: 5px;
  415. .label {
  416. font-size: 12px;
  417. color: #999;
  418. }
  419. .value {
  420. font-size: 14px;
  421. color: #333;
  422. &.highlight {
  423. font-size: 16px;
  424. font-weight: bold;
  425. color: #e60012;
  426. }
  427. }
  428. }
  429. }
  430. .status-cell {
  431. width: 80px;
  432. align-items: center;
  433. padding: 15px;
  434. .status-text {
  435. font-size: 13px;
  436. font-weight: 500;
  437. &.success {
  438. color: #e60012;
  439. }
  440. }
  441. }
  442. .action-cell {
  443. padding: 15px;
  444. width: 80px;
  445. align-items: center;
  446. }
  447. }
  448. .more-products-hint {
  449. padding: 10px 15px;
  450. background: #f5f5f5;
  451. font-size: 12px;
  452. color: #666;
  453. text-align: center;
  454. border-top: 1px solid #f0f0f0;
  455. }
  456. }
  457. }
  458. </style>