list.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  1. <template>
  2. <div class="container">
  3. <Breadcrumb :items="['menu.jd', 'menu.jd.list']" />
  4. <a-card class="general-card" :title="$t('menu.jd.list')">
  5. <a-row>
  6. <a-col :flex="1">
  7. <a-form :model="formModel" :label-col-props="{ span: 6 }" :wrapper-col-props="{ span: 18 }"
  8. label-align="left">
  9. <a-row :gutter="16">
  10. <a-col :span="8">
  11. <a-form-item field="name" label="账号名">
  12. <a-input v-model="formModel.name" placeholder="输入关键词搜索" />
  13. </a-form-item>
  14. </a-col>
  15. <a-col :span="8">
  16. <a-form-item field="lastTime" :label="$t('searchTable.form.lastTime')">
  17. <a-range-picker v-model="formModel.lastTime" style="width: 100%" />
  18. </a-form-item>
  19. </a-col>
  20. <a-col :span="8">
  21. <a-form-item field="status" :label="$t('searchTable.form.status')">
  22. <a-select v-model="formModel.status" :options="statusOptions" :placeholder="$t('searchTable.form.selectDefault')
  23. " />
  24. </a-form-item>
  25. </a-col>
  26. </a-row>
  27. </a-form>
  28. </a-col>
  29. <a-divider style="height: 38px" direction="vertical" />
  30. <a-col :flex="'86px'" style="text-align: right">
  31. <a-space direction="vertical" :size="18">
  32. <a-button type="primary" @click="search">
  33. <template #icon>
  34. <icon-search />
  35. </template>
  36. {{ $t('searchTable.form.search') }}
  37. </a-button>
  38. </a-space>
  39. </a-col>
  40. </a-row>
  41. <a-divider style="margin-top: 0" />
  42. <a-row style="margin-bottom: 16px">
  43. <a-col :span="12">
  44. <a-space>
  45. <a-button type="primary">
  46. <template #icon>
  47. <icon-plus />
  48. </template>
  49. {{ $t('searchTable.operation.create') }}
  50. </a-button>
  51. </a-space>
  52. </a-col>
  53. <a-col :span="12" style="
  54. display: flex;
  55. align-items: center;
  56. justify-content: end;
  57. ">
  58. <a-tooltip :content="$t('searchTable.actions.refresh')">
  59. <div class="action-icon" @click="search"><icon-refresh size="18" /></div>
  60. </a-tooltip>
  61. <a-dropdown @select="handleSelectDensity">
  62. <a-tooltip :content="$t('searchTable.actions.density')">
  63. <div class="action-icon"><icon-line-height size="18" /></div>
  64. </a-tooltip>
  65. <template #content>
  66. <a-doption v-for="item in densityList" :key="item.value" :value="item.value"
  67. :class="{ active: item.value === size }">
  68. <span>{{ item.name }}</span>
  69. </a-doption>
  70. </template>
  71. </a-dropdown>
  72. <a-tooltip :content="$t('searchTable.actions.columnSetting')">
  73. <a-popover trigger="click" position="bl" @popup-visible-change="popupVisibleChange">
  74. <div class="action-icon"><icon-settings size="18" /></div>
  75. <template #content>
  76. <div id="tableSetting">
  77. <div v-for="(item, index) in showColumns" :key="item.dataIndex" class="setting">
  78. <div style="
  79. margin-right: 4px;
  80. cursor: move;
  81. ">
  82. <icon-drag-arrow />
  83. </div>
  84. <div>
  85. <a-checkbox v-model="item.checked" @change="
  86. handleChange(
  87. $event,
  88. item as TableColumnData,
  89. index
  90. )
  91. ">
  92. </a-checkbox>
  93. </div>
  94. <div class="title">
  95. {{
  96. item.title === '#'
  97. ? '序列号'
  98. : item.title
  99. }}
  100. </div>
  101. </div>
  102. </div>
  103. </template>
  104. </a-popover>
  105. </a-tooltip>
  106. </a-col>
  107. </a-row>
  108. <a-table row-key="id" :loading="loading" :pagination="pagination" :summary="true" summary-text="汇总"
  109. :columns="(cloneColumns as TableColumnData[])" :data="renderData" :bordered="{ headerCell: true }"
  110. :size="size" @page-change="onPageChange">
  111. <template #index="{ record }">
  112. {{ record.id }}
  113. </template>
  114. <template #name="{ record }">
  115. <a-list-item-meta>
  116. <template #title>
  117. {{ record.company }}
  118. <a-tag color="blue" v-if="record.work_mode == 1">网站推广</a-tag>
  119. <a-tag color="orange" v-else-if="record.work_mode == 2">媒体导购</a-tag>
  120. <a-tag color="purple" v-else>爬虫</a-tag>
  121. </template>
  122. <template #description>
  123. {{ record.description }}
  124. </template>
  125. </a-list-item-meta>
  126. </template>
  127. <template #hourly_calls_limit="{ record }">
  128. <a-tag bordered
  129. :color="record.current_hourly_calls > record.hourly_calls_limit && record.hourly_calls_limit > 0 ? 'red' : ''">
  130. {{ record.current_hourly_calls }} /
  131. {{ record.hourly_calls_limit }}
  132. </a-tag>
  133. </template>
  134. <template #daily_calls_limit="{ record }">
  135. <a-tag bordered
  136. :color="record.current_daily_calls > record.daily_calls_limit && record.daily_calls_limit > 0 ? 'red' : ''">
  137. {{ record.current_daily_calls }} /
  138. {{ record.daily_calls_limit }}
  139. </a-tag>
  140. </template>
  141. <template #nodeName="{ record }">
  142. <a-tag color="gray">{{ record.end_point }} - {{ record.nodeName }} </a-tag>
  143. </template>
  144. <template #status="{ record }">
  145. <a-tag v-if="record.status" bordered color="green" @click="changeStatus(record.id, false)">
  146. <template #icon>
  147. <icon-check />
  148. </template>
  149. 在线
  150. </a-tag>
  151. <a-tag v-else bordered color="" @click="changeStatus(record.id, true)">
  152. <template #icon>
  153. <icon-stop />
  154. </template>
  155. 下线
  156. </a-tag>
  157. </template>
  158. <template #actions="{ record }">
  159. <a-tag v-if="record.enable_parse" size="small" bordered color="red"
  160. @click="changeAttr(record.id, 'enable_parse', false)">
  161. 转链
  162. </a-tag>
  163. <a-tag v-else size="small" bordered color="" @click="changeAttr(record.id, 'enable_parse', true)">
  164. 转链
  165. </a-tag>
  166. <span style="margin: 5px;">
  167. <a-tag v-if="record.enable_coupon" size="small" bordered color="orange"
  168. @click="changeAttr(record.id, 'enable_coupon', false)">
  169. 优惠券
  170. </a-tag>
  171. <a-tag v-else size="small" bordered color=""
  172. @click="changeAttr(record.id, 'enable_coupon', true)">
  173. 优惠券
  174. </a-tag>
  175. </span>
  176. </template>
  177. <template #time="{ record }">
  178. <div style="color:gray;">
  179. <div>注册:{{ dayjs(record.create_time).format('MM-DD HH:mm') }}</div>
  180. <div>更新:{{ dayjs(record.last_time).format('MM-DD HH:mm') }}</div>
  181. <div v-if="dayjs().diff(dayjs(record.login_time), 'hours') < 48">
  182. 登录:{{ dayjs(record.login_time).format('MM-DD HH:mm') }}</div>
  183. </div>
  184. </template>
  185. <template #summary-cell="{ column, record }">
  186. <div style="margin:10px auto" v-if="column.slotName == 'hourly_calls_limit'">
  187. {{ numberFormat(record.current_hourly_calls) }}
  188. </div>
  189. <div style="margin:10px auto" v-if="column.slotName == 'daily_calls_limit'">
  190. {{ numberFormat(record.current_daily_calls) }}
  191. </div>
  192. <template v-if="column.dataIndex == 'today_clickNum' ||
  193. column.dataIndex == 'today_orderNum' ||
  194. column.dataIndex == 'today_finishOrderNum' ||
  195. column.dataIndex == 'today_finishCosPrice'">
  196. <div>{{ numberFormat(record[column.dataIndex]) }}</div>
  197. </template>
  198. <template v-if="column.dataIndex == 'today_cosPrice' ||
  199. column.dataIndex == 'today_finishCosFee' ||
  200. column.dataIndex == 'today_cosFee'">
  201. <div>{{ amountFormat(record[column.dataIndex]) }}</div>
  202. </template>
  203. </template>
  204. <template #time_range="{ record }">
  205. <WorkHourModel :record="record" @change="search" />
  206. </template>
  207. </a-table>
  208. </a-card>
  209. </div>
  210. </template>
  211. <script lang="ts" setup>
  212. import { useRouter } from 'vue-router';
  213. import { computed, ref, reactive, watch, nextTick } from 'vue';
  214. import { useI18n } from 'vue-i18n';
  215. import dayjs from 'dayjs';
  216. import useLoading from '@/hooks/loading';
  217. import { queryJdPool, JdPoolRecord, JdPoolParams, JdUpdateAccountModel, JdUpdateAccount } from '@/api/jd';
  218. import { Pagination } from '@/types/global';
  219. import { Message } from '@arco-design/web-vue';
  220. import type { SelectOptionData } from '@arco-design/web-vue/es/select/interface';
  221. import type { TableColumnData } from '@arco-design/web-vue/es/table/interface';
  222. import cloneDeep from 'lodash/cloneDeep';
  223. import Sortable from 'sortablejs';
  224. import { numberFormat, amountFormat } from '@/utils/util';
  225. import WorkHourModel from './components/WorkHourModel.vue';
  226. type SizeProps = 'mini' | 'small' | 'medium' | 'large';
  227. type Column = TableColumnData & { checked?: true };
  228. const generateFormModel = () => {
  229. return {
  230. name: '',
  231. lastTime: [],
  232. status: '',
  233. sort: 'status',
  234. order: 'descending',
  235. };
  236. };
  237. const router = useRouter();
  238. const { loading, setLoading } = useLoading(true);
  239. const { t } = useI18n();
  240. const renderData = ref<JdPoolRecord[]>([]);
  241. const formModel = ref(generateFormModel());
  242. const cloneColumns = ref<Column[]>([]);
  243. const showColumns = ref<Column[]>([]);
  244. const size = ref<SizeProps>('small');
  245. const basePagination: Pagination = {
  246. current: 1,
  247. pageSize: 50,
  248. };
  249. const pagination = reactive({
  250. ...basePagination,
  251. });
  252. const densityList = computed(() => [
  253. {
  254. name: t('searchTable.size.mini'),
  255. value: 'mini',
  256. },
  257. {
  258. name: t('searchTable.size.small'),
  259. value: 'small',
  260. },
  261. {
  262. name: t('searchTable.size.medium'),
  263. value: 'medium',
  264. },
  265. {
  266. name: t('searchTable.size.large'),
  267. value: 'large',
  268. },
  269. ]);
  270. const columns = computed<TableColumnData[]>(() => [
  271. {
  272. title: '#',
  273. dataIndex: 'index',
  274. slotName: 'index',
  275. width: 50,
  276. },
  277. {
  278. title: '账号名',
  279. dataIndex: 'name',
  280. slotName: 'name',
  281. width: 250,
  282. },
  283. {
  284. title: '工作时间',
  285. dataIndex: 'time_range',
  286. slotName: 'time_range',
  287. align: 'right',
  288. width: 200,
  289. },
  290. {
  291. title: '当日推广效果',
  292. children: [
  293. {
  294. title: '点击量',
  295. dataIndex: 'today_clickNum',
  296. width: 100,
  297. align: 'right',
  298. render: (e: any) => numberFormat(e.record.today_clickNum)
  299. },
  300. {
  301. title: '有效订单',
  302. dataIndex: 'today_orderNum',
  303. width: 100,
  304. align: 'right',
  305. render: (e: any) => numberFormat(e.record.today_orderNum)
  306. },
  307. {
  308. title: '订单金额',
  309. dataIndex: 'today_cosPrice',
  310. width: 150,
  311. align: 'right',
  312. render: (e: any) => amountFormat(e.record.today_cosPrice)
  313. },
  314. // {
  315. // title: '完成收益',
  316. // dataIndex: 'today_finishCosFee',
  317. // width: 100,
  318. // align: 'right',
  319. // render: (e: any) => amountFormat(e.record.today_finishCosFee)
  320. // },
  321. // {
  322. // title: '完成订单量',
  323. // dataIndex: 'today_finishOrderNum',
  324. // width: 100,
  325. // align: 'right',
  326. // render: (e: any) => numberFormat(e.record.today_finishOrderNum)
  327. // },
  328. // {
  329. // title: '完成订单量',
  330. // dataIndex: 'today_finishCosPrice',
  331. // width: 100,
  332. // align: 'right',
  333. // render: (e: any) => numberFormat(e.record.today_finishCosPrice)
  334. // },
  335. {
  336. title: '预估收入',
  337. dataIndex: 'today_cosFee',
  338. width: 150,
  339. align: 'right',
  340. render: (e: any) => amountFormat(e.record.today_cosFee)
  341. },
  342. //
  343. ]
  344. },
  345. {
  346. title: '小时调用',
  347. slotName: 'hourly_calls_limit',
  348. dataIndex: 'current_hourly_calls',
  349. align: 'right',
  350. width: 120,
  351. },
  352. {
  353. title: '当日调用',
  354. slotName: 'daily_calls_limit',
  355. dataIndex: 'current_daily_calls',
  356. align: 'right',
  357. width: 150,
  358. },
  359. {
  360. title: '运行节点',
  361. slotName: 'nodeName',
  362. width: 120,
  363. },
  364. {
  365. title: '状态',
  366. slotName: 'status',
  367. width: 100,
  368. },
  369. {
  370. title: '分类',
  371. slotName: 'actions',
  372. width: 200,
  373. align: 'center',
  374. },
  375. {
  376. title: '时间',
  377. slotName: 'time',
  378. width: 170,
  379. },
  380. ]);
  381. const statusOptions = computed<SelectOptionData[]>(() => [
  382. {
  383. label: '全部',
  384. value: '',
  385. },
  386. {
  387. label: '在线',
  388. value: 'online',
  389. },
  390. {
  391. label: '下线',
  392. value: 'offline',
  393. },
  394. ]);
  395. const fetchData = async (
  396. params: JdPoolParams = {
  397. current: 1,
  398. pageSize: 50,
  399. sort: 'status',
  400. order: 'descending',
  401. getTotal: true,
  402. }
  403. ) => {
  404. setLoading(true);
  405. try {
  406. const { data } = await queryJdPool(params);
  407. if (!data) return;
  408. // const { data } = await queryJdPool(params);
  409. renderData.value = data.list;
  410. pagination.current = data.page;
  411. pagination.total = data.count;
  412. } catch (err) {
  413. console.log(err);
  414. // you can report use errorHandler or other
  415. } finally {
  416. setLoading(false);
  417. }
  418. };
  419. const changeItem = async (data: JdPoolRecord) => {
  420. router.push({ name: 'updateCookies' });
  421. };
  422. const billView = async (data: JdPoolRecord) => {
  423. router.push({ name: 'taobao_bill_dailys', query: { name: data.company } });
  424. };
  425. const changeStatus = async (id: number, val: any) => {
  426. const args = {
  427. id,
  428. name: 'status',
  429. val
  430. } as JdUpdateAccountModel;
  431. setLoading(true);
  432. try {
  433. const { data } = await JdUpdateAccount(args);
  434. console.log(data, data.msg);
  435. const msg = data.msg || '更新成功!';
  436. if (data.success) {
  437. Message.success(msg);
  438. fetchData();
  439. } else {
  440. Message.error(data.msg);
  441. }
  442. } catch (e) { console.log(e) }
  443. setLoading(false);
  444. };
  445. const changeAttr = async (id: number, name: string, val: any) => {
  446. const args = {
  447. id,
  448. name,
  449. val
  450. } as JdUpdateAccountModel;
  451. setLoading(true);
  452. try {
  453. const { data } = await JdUpdateAccount(args);
  454. console.log(data, data.msg);
  455. const msg = data.msg || '更新成功!';
  456. if (data.success) {
  457. Message.success(msg);
  458. fetchData();
  459. } else {
  460. Message.error(data.msg);
  461. }
  462. } catch (e) { console.log(e) }
  463. setLoading(false);
  464. };
  465. const search = () => {
  466. fetchData({
  467. ...basePagination,
  468. ...formModel.value,
  469. } as unknown as JdPoolParams);
  470. };
  471. const onPageChange = (current: number) => {
  472. fetchData({ ...basePagination, current });
  473. };
  474. fetchData();
  475. const reset = () => {
  476. formModel.value = generateFormModel();
  477. };
  478. const handleSelectDensity = (
  479. val: string | number | Record<string, any> | undefined,
  480. e: Event
  481. ) => {
  482. size.value = val as SizeProps;
  483. };
  484. const handleChange = (
  485. checked: boolean | (string | boolean | number)[],
  486. column: Column,
  487. index: number
  488. ) => {
  489. if (!checked) {
  490. cloneColumns.value = showColumns.value.filter(
  491. (item) => item.dataIndex !== column.dataIndex
  492. );
  493. } else {
  494. cloneColumns.value.splice(index, 0, column);
  495. }
  496. };
  497. const exchangeArray = <T extends Array<any>>(
  498. array: T,
  499. beforeIdx: number,
  500. newIdx: number,
  501. isDeep = false
  502. ): T => {
  503. const newArray = isDeep ? cloneDeep(array) : array;
  504. if (beforeIdx > -1 && newIdx > -1) {
  505. // 先替换后面的,然后拿到替换的结果替换前面的
  506. newArray.splice(
  507. beforeIdx,
  508. 1,
  509. newArray.splice(newIdx, 1, newArray[beforeIdx]).pop()
  510. );
  511. }
  512. return newArray;
  513. };
  514. const popupVisibleChange = (val: boolean) => {
  515. if (val) {
  516. nextTick(() => {
  517. const el = document.getElementById(
  518. 'tableSetting'
  519. ) as HTMLElement;
  520. const sortable = new Sortable(el, {
  521. onEnd(e: any) {
  522. const { oldIndex, newIndex } = e;
  523. exchangeArray(cloneColumns.value, oldIndex, newIndex);
  524. exchangeArray(showColumns.value, oldIndex, newIndex);
  525. },
  526. });
  527. });
  528. }
  529. };
  530. watch(
  531. () => columns.value,
  532. (val) => {
  533. cloneColumns.value = cloneDeep(val);
  534. cloneColumns.value.forEach((item, index) => {
  535. item.checked = true;
  536. });
  537. showColumns.value = cloneDeep(cloneColumns.value);
  538. },
  539. { deep: true, immediate: true }
  540. );
  541. </script>
  542. <script lang="ts">
  543. export default {
  544. name: 'SearchTable',
  545. };
  546. </script>
  547. <style scoped lang="less">
  548. .container {
  549. padding: 0 20px 20px 20px;
  550. }
  551. :deep(.arco-table-th) {
  552. &:last-child {
  553. .arco-table-th-item-title {
  554. margin-left: 16px;
  555. }
  556. }
  557. }
  558. .action-icon {
  559. margin-left: 12px;
  560. cursor: pointer;
  561. }
  562. .active {
  563. color: #0960bd;
  564. background-color: #e3f4fc;
  565. }
  566. .setting {
  567. display: flex;
  568. align-items: center;
  569. width: 200px;
  570. .title {
  571. margin-left: 12px;
  572. cursor: pointer;
  573. }
  574. }
  575. </style>