index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. <script setup lang="tsx">
  2. import { nextTick, reactive, ref, unref, useTemplateRef, watch } from 'vue';
  3. import { NImage, NTag } from 'naive-ui';
  4. import { fetchGetAfterSalesOrderList, fetchGetAfterSalesStatusNum } from '@/service/api/delivery/after-sales-order';
  5. import { fetchGetLoginUserList } from '@/service/api/common';
  6. import { useAppStore } from '@/store/modules/app';
  7. import { defaultTransform, useNaivePaginatedTable } from '@/hooks/common/table';
  8. import { useAuth } from '@/hooks/business/auth';
  9. import { copyTextToClipboard } from '@/utils/zt';
  10. import { commonExport } from '@/utils/common';
  11. import { $t } from '@/locales';
  12. import { useForm } from '@/components/zt/Form/hooks/useForm';
  13. import NormalMoadl from '../normal-order/component/normal-modal.vue';
  14. import { dvyStatus, orderStatus } from '../normal-order/normal-order';
  15. import { SearchForm, TypeText, refundEnum, refundStatus } from './after-sales-order';
  16. import OrderModal from './order-modal.vue';
  17. const appStore = useAppStore();
  18. const checkedRowKeys = ref([]);
  19. const activeTab = ref(0);
  20. const statusList = ref<{ label: string; value: number; num?: number; key: string }[]>([]);
  21. const orderMoadl = useTemplateRef('orderMoadl');
  22. const AfterSalesModal = useTemplateRef('AfterSalesModal');
  23. const channelIdList = ref([]);
  24. const [registerSearchForm, { getFieldsValue, setFieldsValue }] = useForm({
  25. schemas: [
  26. {
  27. field: 'channelIdList',
  28. label: '所属企业',
  29. component: 'ApiSelect',
  30. componentProps: {
  31. api: () => fetchGetLoginUserList(),
  32. labelFeild: 'channelName',
  33. valueFeild: 'id',
  34. multiple: true,
  35. onUpdateValue: () => {
  36. nextTick(() => {
  37. handleSearch();
  38. });
  39. },
  40. getOptions: async (options: any) => {
  41. await setFieldsValue({ channelIdList: [options[0].id] });
  42. handleSearch();
  43. }
  44. }
  45. },
  46. ...SearchForm
  47. ],
  48. showAdvancedButton: false,
  49. labelWidth: 120,
  50. layout: 'horizontal',
  51. size: 'small',
  52. gridProps: {
  53. cols: '1 xl:4 s:1 l:3',
  54. itemResponsive: true
  55. },
  56. collapsedRows: 1
  57. });
  58. const searchForm = ref();
  59. const searchParams = reactive({
  60. current: 1,
  61. size: 10
  62. });
  63. const { columns, data, loading, getData, mobilePagination } = useNaivePaginatedTable({
  64. api: () => fetchGetAfterSalesOrderList({ ...searchParams, returnMoneySts: activeTab.value, ...unref(searchForm) }),
  65. transform: response => defaultTransform(response),
  66. immediate: false,
  67. paginationProps: {
  68. pageSizes: import.meta.env.VITE_PAGE_SIZE.split(',').map(Number)
  69. },
  70. onPaginationParamsChange: params => {
  71. searchParams.current = Number(params.page);
  72. searchParams.size = Number(params.pageSize);
  73. },
  74. columns: () => [
  75. {
  76. key: 'orderItems',
  77. title: '商品',
  78. align: 'left',
  79. width: 280,
  80. colSpan: (_rowData, _rowIndex) => 2,
  81. render: row => {
  82. const statusKey = row.returnMoneySts as keyof typeof refundStatus;
  83. const statusText = refundStatus[statusKey] || '暂无售后';
  84. return (
  85. <div>
  86. <div class={'mb3 flex items-center'}>
  87. <n-tag>
  88. <div class={'flex items-center'}>
  89. 退款编号:{row.refundSn}
  90. <div onClick={() => copyTextToClipboard(row.refundSn)}>
  91. <svgIcon icon={'bxs:copy'} class={'mx-3 cursor-pointer text-[#f97316]'}></svgIcon>
  92. </div>
  93. 订单编号:{row.orderNumber}
  94. <div onClick={() => copyTextToClipboard(row.orderNumber)}>
  95. <svgIcon icon={'bxs:copy'} class={'mx-3 cursor-pointer text-[#f97316]'}></svgIcon>
  96. </div>
  97. 申请时间:
  98. {row.applyTime} 门店名称 {row.shopName}
  99. </div>
  100. </n-tag>
  101. </div>
  102. {row.orderRefundSkuList?.map(item => {
  103. return (
  104. <div class={'mb-3 h-80px flex items-center'}>
  105. <NImage src={item.pic} class="h-[80px] min-w-80px w-[80px]" lazy />
  106. <div class={'ml12px flex-1'}>
  107. <div class={'w-full flex items-center justify-between'}>
  108. <div class={'w200px'}>
  109. <n-ellipsis class={'w250px'}>
  110. <span class={'w-full text-left text-15px font-semibold'}>{item.skuName}</span>
  111. </n-ellipsis>
  112. </div>
  113. <div class={'w150px pl30px text-left'}>
  114. <div class={'text-16px font-semibold'}>¥{item.skuPrice} </div>
  115. </div>
  116. </div>
  117. <div class={'mb2 w-full flex items-center justify-between'}>
  118. <div class={'w200px text-gray'}>规格:{item.spec || '--'} </div>
  119. <div class={'w150px pl30px text-left text-gray'}>x{item.productCount} </div>
  120. </div>
  121. <NTag type={statusKey == refundEnum.REFUND_SUCCESS ? 'success' : 'error'}>{statusText}</NTag>
  122. </div>
  123. </div>
  124. );
  125. })}
  126. </div>
  127. );
  128. }
  129. },
  130. {
  131. key: 'deptName',
  132. title: '单价(元)/数量',
  133. align: 'center',
  134. width: 100
  135. },
  136. {
  137. key: 'actualTotal',
  138. title: '实付金额(元)',
  139. align: 'center',
  140. width: 120,
  141. render: row => {
  142. // 后端不算,让前端算
  143. const actualTotal = row.orderRefundSkuList?.reduce((acc, item) => {
  144. return acc + Number(item.skuPrice) * Number(item.productCount);
  145. }, 0);
  146. const goodsTotalCount = row.orderRefundSkuList?.reduce((acc, item) => {
  147. return acc + Number(item.productCount);
  148. }, 0);
  149. return (
  150. <div class={'mt7'}>
  151. <div class={'text-16px text-#ff0000 font-semibold'}>{actualTotal?.toFixed(2)} 元</div>
  152. <div>共 {goodsTotalCount} 件</div>
  153. </div>
  154. );
  155. }
  156. },
  157. {
  158. key: 'refundAmount',
  159. title: '退款金额',
  160. align: 'center',
  161. width: 120,
  162. render: row => {
  163. // 后端不算,让前端算
  164. const actualTotal = row.orderRefundSkuList?.reduce((acc, item) => {
  165. return acc + Number(item.skuPrice) * Number(item.productCount);
  166. }, 0);
  167. const goodsTotalCount = row.orderRefundSkuList?.reduce((acc, item) => {
  168. return acc + Number(item.productCount);
  169. }, 0);
  170. return (
  171. <div class={'mt7'}>
  172. <div class={'text-16px text-#ff0000 font-semibold'}>{actualTotal?.toFixed(2)} 元</div>
  173. <div>共 {goodsTotalCount} 件</div>
  174. </div>
  175. );
  176. }
  177. },
  178. {
  179. title: '商品状况',
  180. key: 'goods',
  181. width: 220,
  182. align: 'center',
  183. render: row => {
  184. return (
  185. <div class={'mt7'}>
  186. <div class={'text-16px font-semibold'}>{TypeText[Number(row.applyType) - 1] || '未知状况'} </div>
  187. <div class={'text-#ff0000'}> {row.buyerReason} </div>
  188. </div>
  189. );
  190. }
  191. },
  192. {
  193. key: 'dvyType',
  194. title: '订单类型',
  195. align: 'center',
  196. width: 120,
  197. render: row => {
  198. return <NTag class={'mt7'}>{dvyStatus[row.dvyType as keyof typeof dvyStatus] || '未知类型'}</NTag>;
  199. }
  200. },
  201. {
  202. key: 'status',
  203. title: '订单状态',
  204. align: 'center',
  205. width: 250,
  206. render: row => {
  207. const statusKey = row.hbOrderStatus as keyof typeof orderStatus;
  208. const statusText = orderStatus[statusKey] || '未知状态';
  209. return <NTag class={'mt7'}>{statusText}</NTag>;
  210. }
  211. },
  212. {
  213. key: 'createTime',
  214. title: '售后状态',
  215. align: 'center',
  216. width: 160,
  217. render: row => {
  218. const statusKey = row.returnMoneySts as keyof typeof refundStatus;
  219. const statusText = refundStatus[statusKey] || '暂无售后';
  220. return <NTag class={'mt7'}>{statusText}</NTag>;
  221. }
  222. },
  223. {
  224. key: 'operate',
  225. title: $t('common.operate'),
  226. align: 'center',
  227. width: 160,
  228. fixed: 'right',
  229. render: row => {
  230. return (
  231. <div class={'mt7'}>
  232. <n-button size="small" type="primary" ghost onClick={() => handleOpenMoadl(row)}>
  233. 查看订单
  234. </n-button>
  235. <n-button
  236. size="small"
  237. class={appStore.isMobile ? ' mt2' : 'ml2'}
  238. type="primary"
  239. ghost
  240. onClick={() => AfterSalesModal.value?.handleOpenOrder(row.refundId)}
  241. >
  242. 售后详情
  243. </n-button>
  244. </div>
  245. );
  246. }
  247. }
  248. ]
  249. });
  250. function handleOpenMoadl(row: Api.delivery.OrderRefund) {
  251. if (!row.orderNumber) {
  252. window.$message?.error('订单异常');
  253. return;
  254. }
  255. orderMoadl.value?.open(String(row.orderNumber));
  256. }
  257. async function getNums() {
  258. const form = getFieldsValue();
  259. const params = {
  260. ...form,
  261. channelIdList: channelIdList.value,
  262. startTime: form.createTime ? form.createTime[0] : null,
  263. endTime: form.createTime ? form.createTime[1] : null,
  264. createTime: null
  265. };
  266. const { data: keyData } = await fetchGetAfterSalesStatusNum(params);
  267. if (!keyData) return;
  268. const orderStatusList = [
  269. {
  270. label: '全部',
  271. value: 0,
  272. key: 'allCount'
  273. },
  274. {
  275. label: '买家申请',
  276. value: refundEnum.BUYER_APPLY,
  277. key: 'sellerApplyCount'
  278. },
  279. {
  280. label: '卖家拒绝',
  281. value: refundEnum.SELLER_REFUSE,
  282. key: 'sellerRejectCount'
  283. },
  284. {
  285. label: '买家发货',
  286. value: refundEnum.SELLER_AGREE,
  287. key: 'sellerAcceptCount'
  288. },
  289. {
  290. label: '卖家收货',
  291. value: refundEnum.BUYER_DELIVERY,
  292. key: 'buyerDeliveryCount'
  293. },
  294. {
  295. label: '退款成功',
  296. value: refundEnum.REFUND_SUCCESS,
  297. key: 'refundCompleteCount'
  298. },
  299. {
  300. label: '撤回申请',
  301. value: refundEnum.REVOKE_APPLY,
  302. key: 'withdrawApplyCount'
  303. }
  304. ];
  305. const updatedOrderStatusList = orderStatusList.map(item => {
  306. if (Object.hasOwn(keyData, item.key)) {
  307. return {
  308. ...item,
  309. num: keyData[item.key]
  310. };
  311. }
  312. return item;
  313. });
  314. statusList.value = updatedOrderStatusList;
  315. }
  316. watch(
  317. () => [activeTab.value],
  318. () => {
  319. searchParams.current = 1;
  320. getData();
  321. }
  322. );
  323. function handleSearch() {
  324. const form = getFieldsValue();
  325. if (form.createTime) {
  326. form.startTime = form.createTime[0];
  327. form.endTime = form.createTime[1];
  328. delete form.createTime;
  329. }
  330. searchForm.value = form;
  331. channelIdList.value = form.channelIdList;
  332. getData();
  333. getNums();
  334. }
  335. function handleReset() {
  336. searchForm.value = getFieldsValue();
  337. searchForm.value.channelIdList = channelIdList.value;
  338. setFieldsValue({ channelIdList: channelIdList.value });
  339. getData();
  340. getNums();
  341. }
  342. async function handleExport() {
  343. loading.value = true;
  344. try {
  345. await commonExport(
  346. '/platform/orderRefund/export',
  347. { ...getFieldsValue(), returnMoneySts: activeTab.value },
  348. '售后订单列表.xlsx'
  349. );
  350. } finally {
  351. loading.value = false;
  352. }
  353. }
  354. </script>
  355. <template>
  356. <div class="flex-col-stretch gap-16px overflow-hidden lt-sm:overflow-auto">
  357. <NCard :bordered="false" size="small">
  358. <NCollapse display-directive="show" default-expanded-names="search">
  359. <NCollapseItem title="搜索" name="search">
  360. <BasicForm @register-form="registerSearchForm" @submit="handleSearch" @reset="handleReset" />
  361. </NCollapseItem>
  362. </NCollapse>
  363. </NCard>
  364. <NCard :bordered="false" size="small" class="card-wrapper sm:flex-1-hidden">
  365. <template #header>
  366. <div class="mr3">售后列表</div>
  367. <NScrollbar x-scrollable>
  368. <div class="flex items-center">
  369. <div class="max-w-800px">
  370. <NTabs v-model:value="activeTab" type="line" animated display-directive="show">
  371. <NTab
  372. v-for="item in statusList"
  373. :key="item.value"
  374. :name="item.value"
  375. :tab="`${item.label}(${item.num})`"
  376. ></NTab>
  377. </NTabs>
  378. </div>
  379. </div>
  380. </NScrollbar>
  381. </template>
  382. <template #header-extra>
  383. <NButton
  384. v-if="useAuth().hasAuth('order:user:export')"
  385. size="small"
  386. type="primary"
  387. class="ml20px mt30px"
  388. ghost
  389. :disabled="data.length == 0"
  390. :loading="loading"
  391. @click="handleExport"
  392. >
  393. <template #icon>
  394. <SvgIcon icon="mingcute:file-export-line"></SvgIcon>
  395. </template>
  396. 导出
  397. </NButton>
  398. </template>
  399. <NDataTable
  400. v-model:checked-row-keys="checkedRowKeys"
  401. :columns="columns"
  402. :data="data"
  403. size="small"
  404. :flex-height="!appStore.isMobile"
  405. :scroll-x="1800"
  406. :loading="loading"
  407. :row-key="row => row.refundId"
  408. remote
  409. class="sm:h-full"
  410. :pagination="mobilePagination"
  411. />
  412. <NormalMoadl ref="orderMoadl" @finish="handleReset"></NormalMoadl>
  413. <OrderModal ref="AfterSalesModal"></OrderModal>
  414. </NCard>
  415. </div>
  416. </template>
  417. <style scoped lang="scss"></style>