orders.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  1. <template>
  2. <div class="container">
  3. <Breadcrumb :items="['menu.taobao', 'menu.taobao.orders']" />
  4. <a-card class="general-card" :title="$t('menu.taobao.orders')">
  5. <a-row>
  6. <a-col :flex="1">
  7. <a-form :model="formModel" :label-col-props="{ span: 8 }" :wrapper-col-props="{ span: 16 }"
  8. label-align="left">
  9. <a-row :gutter="24">
  10. <a-col :span="6">
  11. <a-form-item field="name" label="账号名">
  12. <selectAccount v-model="formModel.keyword" @change="changeCompany" />
  13. </a-form-item>
  14. </a-col>
  15. <a-col :span="6">
  16. <a-form-item field="tkStatus" label="订单状态">
  17. <a-select v-model="formModel.tkStatus" multiple :max-tag-count=1>
  18. <a-option :value="3">已结算</a-option>
  19. <a-option :value="12">已付款</a-option>
  20. <a-option :value="13">已失效</a-option>
  21. <a-option :value="14">已收货</a-option>
  22. </a-select>
  23. </a-form-item>
  24. </a-col>
  25. <a-col :span="6">
  26. <a-form-item field="query_date" :label="$t('searchTable.form.order_date')">
  27. <a-range-picker v-model="formModel.query_date" style="width: 100%"
  28. @change="changeDate" />
  29. </a-form-item>
  30. </a-col>
  31. <a-col :span="6">
  32. <a-form-item field="maxTotal" label="最大记录">
  33. <a-select v-model="formModel.maxTotal">
  34. <a-option :value="1000">1000</a-option>
  35. <a-option :value="10000">10000</a-option>
  36. <a-option :value="100000">10W</a-option>
  37. <a-option :value="1000000">100W</a-option>
  38. <a-option :value="10000000">1000W</a-option>
  39. </a-select>
  40. </a-form-item>
  41. </a-col>
  42. </a-row>
  43. </a-form>
  44. </a-col>
  45. <a-divider style="height: 32px" direction="vertical" />
  46. <a-col :flex="'86px'" style="text-align: right">
  47. <a-space direction="vertical" :size="18">
  48. <a-button type="primary" @click="search">
  49. <template #icon>
  50. <icon-search />
  51. </template>
  52. {{ $t('searchTable.form.search') }}
  53. </a-button>
  54. </a-space>
  55. </a-col>
  56. </a-row>
  57. <a-divider style="margin-top: 0" />
  58. <a-row style="margin-bottom: 16px">
  59. <a-col :span="12"> </a-col>
  60. <a-col :span="12" style="
  61. display: flex;
  62. align-items: center;
  63. justify-content: end;
  64. ">
  65. <a-tooltip :content="$t('searchTable.actions.refresh')">
  66. <div class="action-icon" @click="search"><icon-refresh size="18" /></div>
  67. </a-tooltip>
  68. <a-dropdown @select="handleSelectDensity">
  69. <a-tooltip :content="$t('searchTable.actions.density')">
  70. <div class="action-icon"><icon-line-height size="18" /></div>
  71. </a-tooltip>
  72. <template #content>
  73. <a-doption v-for="item in densityList" :key="item.value" :value="item.value"
  74. :class="{ active: item.value === size }">
  75. <span>{{ item.name }}</span>
  76. </a-doption>
  77. </template>
  78. </a-dropdown>
  79. <a-tooltip :content="$t('searchTable.actions.columnSetting')">
  80. <a-popover trigger="click" position="bl" @popup-visible-change="popupVisibleChange">
  81. <div class="action-icon"><icon-settings size="18" /></div>
  82. <template #content>
  83. <div id="tableSetting">
  84. <div v-for="(item, index) in showColumns" :key="item.dataIndex" class="setting">
  85. <div style="
  86. margin-right: 4px;
  87. cursor: move;
  88. ">
  89. <icon-drag-arrow />
  90. </div>
  91. <div>
  92. <a-checkbox v-model="item.checked" @change="
  93. handleChange(
  94. $event,
  95. item as TableColumnData,
  96. index
  97. )
  98. ">
  99. </a-checkbox>
  100. </div>
  101. <div class="title">
  102. {{
  103. item.title === '#'
  104. ? '序列号'
  105. : item.title
  106. }}
  107. </div>
  108. </div>
  109. </div>
  110. </template>
  111. </a-popover>
  112. </a-tooltip>
  113. </a-col>
  114. </a-row>
  115. <a-table row-key="id" :loading="loading" :pagination="pagination"
  116. :columns="(cloneColumns as TableColumnData[])" :scroll="scroll" :scrollbar="scrollbar"
  117. :data="renderData" :bordered="false" :size="size" @page-change="onPageChange">
  118. <template #orderInfo="{ record }">
  119. <a-list-item>
  120. <a-list-item-meta>
  121. <template #avatar>
  122. <a-avatar shape="square">
  123. <img alt="avatar" :src="record.itemImg" />
  124. </a-avatar>
  125. </template>
  126. <template #title>
  127. <a target="_blank" class="link" :href="record.mktItemLink">
  128. {{ record.itemTitle }}
  129. </a>
  130. </template>
  131. <template #description>
  132. <div class="text-3">
  133. <div>店铺名:{{ record.sellerShopTitle }}
  134. <a-tooltip>
  135. <a-tag>{{ record.tradeId }}</a-tag>
  136. <template #content>
  137. <div>父订单编号:{{ record.tradeParentId }}</div>
  138. <div> 子订单编号:{{ record.tradeId }}</div>
  139. </template>
  140. </a-tooltip>
  141. </div>
  142. <div> {{ record.tbPaidTime }}付款 </div>
  143. <div v-if="record.tkEarningTime != '0001-01-01 00:00:00'">
  144. {{ record.tkEarningTime }}结算
  145. </div>
  146. </div>
  147. </template>
  148. </a-list-item-meta>
  149. </a-list-item>
  150. </template>
  151. <template #alipayTotalPrice="{ record }">
  152. <span>¥{{ record.alipayTotalPrice }}</span>
  153. </template>
  154. <template #tkTotalRateForCommissionAndSdy="{ record }">
  155. {{ record.tkTotalRateForCommissionAndSdy }}%
  156. </template>
  157. <template #pubSharePreFee="{ record }">
  158. <div class="text-3">
  159. <div>付款预估佣金收入:<span class="money-sum">¥{{ record.pubSharePreFeeForCommission }}</span></div>
  160. <div>付款预估补贴收入:<span class="money-sum">¥{{ record.pubSharePreFeeForSdy }}</span></div>
  161. </div>
  162. </template>
  163. <template #totalCommissionFee="{ record }">
  164. <div class="text-3">
  165. <div>结算预估佣金收入:<span class="money-sum">¥{{ record.pubShareFeeForCommission }}</span></div>
  166. <div>结算预估补贴收入:<span class="money-sum">¥{{ record.pubShareFeeForSdy }}</span></div>
  167. </div>
  168. </template>
  169. <template #alimamaShareFee="{ record }">
  170. <div>¥{{ record.alimamaShareFee }}</div>
  171. </template>
  172. <template #last_time="{ record }">
  173. <div class="money-sum">{{ record.last_time }}</div>
  174. </template>
  175. </a-table>
  176. </a-card>
  177. </div>
  178. </template>
  179. <script lang="ts" setup>
  180. import { useRouter } from 'vue-router';
  181. import dayjs from 'dayjs';
  182. import { computed, ref, reactive, watch, nextTick } from 'vue';
  183. import { useI18n } from 'vue-i18n';
  184. import useLoading from '@/hooks/loading';
  185. import {
  186. queryTkOrders,
  187. TkOrderRecord,
  188. TkOrdersParams,
  189. } from '@/api/taobao';
  190. import { Pagination } from '@/types/global';
  191. import type {
  192. TableData,
  193. TableColumnData,
  194. } from '@arco-design/web-vue/es/table/interface';
  195. import cloneDeep from 'lodash/cloneDeep';
  196. import Sortable from 'sortablejs';
  197. import selectAccount from './components/selectAccount.vue';
  198. type SizeProps = 'mini' | 'small' | 'medium' | 'large';
  199. type Column = TableColumnData & { checked?: true };
  200. const props = defineProps({
  201. keyword: { type: String },
  202. tkStatus: { type: Array<number> },
  203. queryDate: { type: Array<string> }
  204. })
  205. const generateFormModel = () => {
  206. return {
  207. keyword: props.keyword || '',
  208. tkStatus: props.tkStatus || [3, 12, 13, 14],
  209. formModel: 1000,
  210. query_date: props.queryDate || [] as Array<string>,
  211. current: 1,
  212. pageSize: 20,
  213. maxTotal: 1000,
  214. sort: 'tkPaidTime',
  215. order: 'descending',
  216. };
  217. };
  218. const router = useRouter();
  219. const { loading, setLoading } = useLoading(true);
  220. const { t } = useI18n();
  221. const renderData = ref<TkOrderRecord[]>([]);
  222. const formModel = ref(generateFormModel());
  223. const cloneColumns = ref<Column[]>([]);
  224. const showColumns = ref<Column[]>([]);
  225. const size = ref<SizeProps>('medium');
  226. const scrollbar = ref(true);
  227. const scroll = {
  228. x: '100%',
  229. y: '100%',
  230. maxHeight: 'calc( 100vh - 420px)',
  231. };
  232. const basePagination: Pagination = {
  233. current: 1,
  234. pageSize: 20,
  235. };
  236. const pagination = reactive({
  237. ...basePagination,
  238. });
  239. const densityList = computed(() => [
  240. {
  241. name: t('searchTable.size.mini'),
  242. value: 'mini',
  243. },
  244. {
  245. name: t('searchTable.size.small'),
  246. value: 'small',
  247. },
  248. {
  249. name: t('searchTable.size.medium'),
  250. value: 'medium',
  251. },
  252. {
  253. name: t('searchTable.size.large'),
  254. value: 'large',
  255. },
  256. ]);
  257. const columns = computed<TableColumnData[]>(() => [
  258. {
  259. title: '订单信息',
  260. dataIndex: 'xAxis',
  261. slotName: 'orderInfo',
  262. fixed: 'left',
  263. width: 450,
  264. },
  265. {
  266. title: '订单状态',
  267. dataIndex: 'tkStatusText',
  268. width: 120,
  269. },
  270. {
  271. title: '订单金额',
  272. slotName: 'alipayTotalPrice',
  273. width: 100,
  274. align: 'right'
  275. },
  276. {
  277. title: '总提成率',
  278. dataIndex: 'tkTotalRateForCommissionAndSdy',
  279. slotName: 'tkTotalRateForCommissionAndSdy',
  280. width: 120,
  281. align: 'right'
  282. },
  283. {
  284. title: '付款预估收入',
  285. dataIndex: 'pubSharePreFee',
  286. slotName: 'pubSharePreFee',
  287. width: 220,
  288. align: 'right'
  289. },
  290. {
  291. title: '结算预估收入',
  292. dataIndex: 'totalCommissionFee',
  293. slotName: 'totalCommissionFee',
  294. width: 220,
  295. align: 'right'
  296. },
  297. {
  298. title: '平台技术服务费',
  299. dataIndex: 'alimamaShareFee',
  300. slotName: 'alimamaShareFee',
  301. width: 140,
  302. align: 'right'
  303. },
  304. {
  305. title: '最后更新时间',
  306. dataIndex: 'last_time',
  307. slotName: 'last_time',
  308. width: 100,
  309. align: 'right'
  310. },
  311. ]);
  312. // renderData.value.tkStatusText
  313. const fetchData = async (
  314. params: TkOrdersParams = {
  315. current: 1,
  316. pageSize: 20,
  317. maxTotal: 1000,
  318. sort: 'tkPaidTime',
  319. order: 'descending',
  320. }
  321. ) => {
  322. setLoading(true);
  323. try {
  324. const { data } = await queryTkOrders(params);
  325. console.log(data);
  326. if (!data) return;
  327. renderData.value = data.list;
  328. pagination.current = data.page;
  329. pagination.total = data.count;
  330. console.log(data);
  331. } catch (err) {
  332. console.log(err);
  333. } finally {
  334. setLoading(false);
  335. }
  336. };
  337. const search = () => {
  338. console.log(formModel.value)
  339. fetchData({
  340. ...basePagination,
  341. ...formModel.value,
  342. } as unknown as TkOrdersParams);
  343. };
  344. const onPageChange = (current: number) => {
  345. fetchData({
  346. ...basePagination,
  347. ...formModel.value,
  348. current
  349. });
  350. };
  351. fetchData({
  352. ...basePagination,
  353. ...formModel.value
  354. });
  355. const reset = () => {
  356. formModel.value = generateFormModel();
  357. };
  358. const changeCompany = (value: any) => {
  359. const reset = () => {
  360. formModel.value = generateFormModel();
  361. };
  362. formModel.value.keyword = value
  363. fetchData({
  364. ...basePagination,
  365. ...formModel.value,
  366. } as unknown as TkOrdersParams);
  367. };
  368. const changeStatus = (value: any) => {
  369. const reset = () => {
  370. formModel.value = generateFormModel();
  371. };
  372. console.log(value)
  373. formModel.value.tkStatus = value
  374. fetchData({
  375. ...basePagination,
  376. ...formModel.value,
  377. } as unknown as TkOrdersParams);
  378. };
  379. const changeDate = (value: any) => {
  380. const reset = () => {
  381. formModel.value = generateFormModel();
  382. };
  383. formModel.value.query_date = value
  384. fetchData({
  385. ...basePagination,
  386. ...formModel.value,
  387. } as unknown as TkOrdersParams);
  388. };
  389. const handleSelectDensity = (
  390. val: string | number | Record<string, any> | undefined,
  391. e: Event
  392. ) => {
  393. size.value = val as SizeProps;
  394. };
  395. const handleChange = (
  396. checked: boolean | (string | boolean | number)[],
  397. column: Column,
  398. index: number
  399. ) => {
  400. if (!checked) {
  401. cloneColumns.value = showColumns.value.filter(
  402. (item) => item.dataIndex !== column.dataIndex
  403. );
  404. } else {
  405. cloneColumns.value.splice(index, 0, column);
  406. }
  407. };
  408. const exchangeArray = <T extends Array<any>>(
  409. array: T,
  410. beforeIdx: number,
  411. newIdx: number,
  412. isDeep = false
  413. ): T => {
  414. const newArray = isDeep ? cloneDeep(array) : array;
  415. if (beforeIdx > -1 && newIdx > -1) {
  416. // 先替换后面的,然后拿到替换的结果替换前面的
  417. newArray.splice(
  418. beforeIdx,
  419. 1,
  420. newArray.splice(newIdx, 1, newArray[beforeIdx]).pop()
  421. );
  422. }
  423. return newArray;
  424. };
  425. const popupVisibleChange = (val: boolean) => {
  426. if (val) {
  427. nextTick(() => {
  428. const el = document.getElementById(
  429. 'tableSetting'
  430. ) as HTMLElement;
  431. const sortable = new Sortable(el, {
  432. onEnd(e: any) {
  433. const { oldIndex, newIndex } = e;
  434. exchangeArray(cloneColumns.value, oldIndex, newIndex);
  435. exchangeArray(showColumns.value, oldIndex, newIndex);
  436. },
  437. });
  438. });
  439. }
  440. };
  441. watch(
  442. () => columns.value,
  443. (val) => {
  444. cloneColumns.value = cloneDeep(val);
  445. cloneColumns.value.forEach((item, index) => {
  446. item.checked = true;
  447. });
  448. showColumns.value = cloneDeep(cloneColumns.value);
  449. },
  450. { deep: true, immediate: true }
  451. );
  452. </script>
  453. <script lang="ts">
  454. export default {
  455. name: 'tkOrders',
  456. };
  457. </script>
  458. <style scoped lang="less">
  459. .container {
  460. padding: 0 20px 20px 20px;
  461. }
  462. :deep(.arco-table-th) {
  463. &:last-child {
  464. .arco-table-th-item-title {
  465. margin-left: 16px;
  466. }
  467. }
  468. }
  469. .action-icon {
  470. margin-left: 12px;
  471. cursor: pointer;
  472. }
  473. .active {
  474. color: #0960bd;
  475. background-color: #e3f4fc;
  476. }
  477. .setting {
  478. display: flex;
  479. align-items: center;
  480. width: 200px;
  481. .title {
  482. margin-left: 12px;
  483. cursor: pointer;
  484. }
  485. }
  486. .arco-table-td,
  487. .arco-table-td div,
  488. .arco-table-td span {
  489. font-size: 12px !important;
  490. }
  491. .text-3 {
  492. color: var(--color-text-3);
  493. }
  494. .money-sum {
  495. color: var(--color-text-2) !important;
  496. }
  497. .link {
  498. color: var(--color-text-t);
  499. text-decoration: none;
  500. }
  501. .link:hover {
  502. color: blue;
  503. text-decoration: underline;
  504. }
  505. </style>