You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

675 lines
20 KiB

  1. <script setup>
  2. import { computed, onMounted, ref } from 'vue'
  3. import { dayjs, ElMessage } from 'element-plus'
  4. import request from '@/util/http.js'
  5. import API from '@/util/http.js'
  6. import moment from 'moment'
  7. import { ar } from 'element-plus/es/locales.mjs'
  8. // 之后整理一下
  9. const defaultTime = [
  10. new Date(2000, 1, 1, 0, 0, 0),
  11. new Date(2000, 2, 1, 23, 59, 59),
  12. ]
  13. /*
  14. ====================工具方法==============================
  15. */
  16. // 时间格式化
  17. const formatTime = (val) => val ? dayjs(val).format('YYYY-MM-DD HH:mm:ss') : ''
  18. /*
  19. ====================数据=================================
  20. */
  21. //这是获取用户信息的接口
  22. const adminData = ref({})
  23. // 充值明细表格
  24. const tableData = ref([])
  25. // 搜索articleVideo 表单
  26. const beanConsumeArticle = ref({
  27. jwcode: null,
  28. dept: "",
  29. type: "",
  30. payMode: "",
  31. articleId: "",
  32. articleName: "",
  33. author: "",
  34. startTime: '',
  35. endTime: '',
  36. })
  37. // 频道列表
  38. const channels = ref([])
  39. // 抽离类型选项到响应式数组
  40. const consumeTypes = ref([
  41. { label: '打赏', value: 9 },
  42. { label: '打赏', value: 10 },
  43. { label: '付费购买', value: 11 },
  44. ])
  45. // 处理 payMode 选择变化
  46. const handlePayModeChange = (value) => {
  47. beanConsumeArticle.value.payMode = value;
  48. // 触发搜索
  49. ConsumeSelectBy();
  50. }
  51. //------------------------
  52. // 标记当前激活的时间范围按钮
  53. const activeTimeRange = ref('')
  54. // 日期选择器变化时清除按钮激活状态
  55. const handleDatePickerChange = () => {
  56. activeTimeRange.value = ''
  57. }
  58. // 搜索对象
  59. const getObj = ref({
  60. pageNum: 1,
  61. pageSize: 50
  62. })
  63. //分页总条目
  64. const total = ref(100)
  65. // 搜索对象时间
  66. const getTime = ref({
  67. startTime: '',
  68. endTime: ''
  69. })
  70. // 搜索地区列表
  71. const dept = ref([])
  72. // 获取地区列表的方法
  73. const getDept = async function () {
  74. try {
  75. // 发送请求获取地区列表
  76. const result = await request({
  77. // url: '/general/dept',
  78. url: '/beanConsume/getDept', // todo 换成实际接口地址
  79. data: { account: adminData.value.account }
  80. })
  81. console.log('请求地区列表成功', result)
  82. // 存储地区数据
  83. dept.value = result.data
  84. console.log('地区数据', dept.value)
  85. } catch (error) {
  86. console.log('请求地区列表失败', error)
  87. ElMessage({
  88. type: 'error',
  89. message: '获取地区列表失败,请稍后重试'
  90. })
  91. }
  92. }
  93. // // 频道模糊查询方法
  94. // const filterChannel = (query) => {
  95. // if (query) {
  96. // return channels.value.filter(item => item.toLowerCase().includes(query.toLowerCase()));
  97. // }
  98. // return channels.value;
  99. // };
  100. // 新增排序字段和排序方式
  101. const sortField = ref('')
  102. const sortOrder = ref('')
  103. // 合计数
  104. const permanentBean = ref(0)
  105. const freeBean = ref(0)
  106. const totalNum = ref(0)
  107. /*
  108. ====================方法=================================
  109. */
  110. // 获取登录用户信息
  111. const getAdminData = async function () {
  112. try {
  113. const result = await request({
  114. url: '/admin/userinfo',
  115. data: {}
  116. })
  117. adminData.value = result
  118. console.log('请求成功', result)
  119. console.log('用户信息', adminData.value)
  120. } catch (error) {
  121. console.log('请求失败', error)
  122. }
  123. }
  124. const ConsumeSelectBy = async function (val) {
  125. try {
  126. // 搜索参数页码赋值
  127. if (typeof val === 'number') {
  128. getObj.value.pageNum = val
  129. }
  130. // 搜索参数时间赋值
  131. if (getTime.value != null) {
  132. if (getTime.value.startTime != '' && getTime.value.endTime != '') {
  133. beanConsumeArticle.value.startTime = formatTime(getTime.value[0])
  134. beanConsumeArticle.value.endTime = formatTime(getTime.value[1])
  135. }
  136. } else {
  137. beanConsumeArticle.value.startTime = ''
  138. beanConsumeArticle.value.endTime = ''
  139. }
  140. beanConsumeArticle.value.sortField = sortField.value
  141. beanConsumeArticle.value.sortOrder = sortOrder.value
  142. console.log('搜索参数_时间', beanConsumeArticle.value.startTime)
  143. console.log('搜索参数1', getObj.value)
  144. console.log('搜索参数2', beanConsumeArticle.value)
  145. // 发送POST请求
  146. const result = await request({
  147. url: '/beanConsume/selectArticleBy',
  148. data: {
  149. pageNum: getObj.value.pageNum,
  150. pageSize: getObj.value.pageSize,
  151. beanConsumeArticle: {
  152. ...beanConsumeArticle.value,
  153. jwcode: beanConsumeArticle.value.jwcode,
  154. dept: beanConsumeArticle.value.dept,
  155. payMode: beanConsumeArticle.value.payMode,
  156. articleId: beanConsumeArticle.value.articleId,
  157. articleName: beanConsumeArticle.value.articleName,
  158. author: beanConsumeArticle.value.author,
  159. startTime: beanConsumeArticle.value.startTime,
  160. endTime: beanConsumeArticle.value.endTime,
  161. sortField: beanConsumeArticle.value.sortField,
  162. sortOrder: beanConsumeArticle.value.sortOrder,
  163. }
  164. }
  165. })
  166. console.log('请求成功4', sortField)
  167. console.log('接口响应结果', result); // 打印接口响应结果
  168. if (result.code === 200 && result.data && result.data.list) {
  169. // 过滤返回的数据,确保 type 值符合 payMode 规则
  170. const filteredList = result.data.list.filter(item => {
  171. if (beanConsumeArticle.value.payMode === '0') {
  172. return [9, 10].includes(Number(item.type));
  173. } else if (beanConsumeArticle.value.payMode === '1') {
  174. return Number(item.type) === 11;
  175. }
  176. return true;
  177. });
  178. tableData.value = filteredList;
  179. }
  180. // 合计数的接口
  181. // 复制一份 beanConsumeArticle.value 并设置固定的 payType 值 8是文章的
  182. const sumConsumeParams = {
  183. payType: 8, // 固定传入 payType 值 8
  184. beanConsumeArticle: {
  185. ...beanConsumeArticle.value,
  186. }
  187. };
  188. // 发送 POST 请求获取合计数
  189. const resultTotalGold = await request({
  190. url: '/beanConsume/sumConsumeGold',
  191. data: sumConsumeParams
  192. });
  193. console.log("总计", resultTotalGold);
  194. const data = resultTotalGold.data || resultTotalGold;
  195. console.log('请求成功3', resultTotalGold.data)
  196. console.log('permanentBean3', data.permanentBean)
  197. // 返回字段为 permanentBean、freeBean、totalNum
  198. permanentBean.value = Number(data.permanentBean) || 0;
  199. freeBean.value = Number(data.freeBean) || 0;
  200. totalNum.value = Number(data.totalNum) || 0;
  201. // 存储分页总数
  202. total.value = result.data.total
  203. console.log('total', total.value)
  204. } catch (error) {
  205. console.log('请求失败', error)
  206. }
  207. }
  208. // 搜索
  209. const search = function () {
  210. getObj.value.pageNum = 1
  211. if (beanConsumeArticle.value.jwcode) {
  212. const numRef = /^\d{1,9}$/;
  213. if (!numRef.test(beanConsumeArticle.value.jwcode)) {
  214. ElMessage.error('请检查精网号格式')
  215. return
  216. }
  217. }
  218. if (beanConsumeArticle.value.articleId) {
  219. const numRef = /^\d{1,9}$/;
  220. if (!numRef.test(beanConsumeArticle.value.articleId)) {
  221. ElMessage.error('请检查文章ID格式')
  222. return
  223. }
  224. }
  225. ConsumeSelectBy()
  226. }
  227. // 重置
  228. const reset = function () {
  229. console.log('文章/视频的重置')
  230. beanConsumeArticle.value.jwcode = null
  231. beanConsumeArticle.value.dept = ''
  232. beanConsumeArticle.value.type = ''
  233. beanConsumeArticle.value.payMode = ''
  234. beanConsumeArticle.value.articleId = ''
  235. beanConsumeArticle.value.articleName = ''
  236. beanConsumeArticle.value.author = ''
  237. beanConsumeArticle.value.startTime = ''
  238. beanConsumeArticle.value.endTime = ''
  239. sortField.value = ''
  240. sortOrder.value = ''
  241. getTime.value = {}
  242. activeTimeRange.value = '' // 清除激活状态
  243. // 点完重置后,重新请求数据
  244. ConsumeSelectBy()
  245. console.log(' beanConsumeArticle', beanConsumeArticle.value)
  246. }
  247. // 今天
  248. const getToday = function () {
  249. const today = dayjs()
  250. const startTime = today.startOf('day').format('YYYY-MM-DD HH:mm:ss')
  251. const endTime = today.endOf('day').format('YYYY-MM-DD HH:mm:ss')
  252. getTime.value = [startTime, endTime]
  253. console.log('getTime', getTime.value)
  254. activeTimeRange.value = 'today' // 标记当前激活状态
  255. ConsumeSelectBy()
  256. }
  257. // 昨天
  258. const getYesterday = function () {
  259. const today = dayjs()
  260. const startTime = today.subtract(1, 'day').startOf('day').format('YYYY-MM-DD HH:mm:ss')
  261. const endTime = today.subtract(1, 'day').endOf('day').format('YYYY-MM-DD HH:mm:ss')
  262. getTime.value = [startTime, endTime]
  263. console.log('getTime', getTime.value)
  264. activeTimeRange.value = 'yesterday' // 标记当前激活状态
  265. ConsumeSelectBy()
  266. }
  267. // 近7天
  268. const get7Days = function () {
  269. const today = dayjs()
  270. const startTime = today.subtract(6, 'day').startOf('day').format('YYYY-MM-DD HH:mm:ss')
  271. const endTime = today.endOf('day').format('YYYY-MM-DD HH:mm:ss')
  272. getTime.value = [startTime, endTime]
  273. console.log('getTime', getTime.value)
  274. activeTimeRange.value = '7days' // 标记当前激活状态
  275. ConsumeSelectBy()
  276. }
  277. // 处理排序事件
  278. const handleSortChange = (column) => {
  279. console.log('排序字段:', column.prop)
  280. console.log('排序方式:', column.order)
  281. if (column.prop === 'beanNum') {
  282. sortField.value = 'beanNum'
  283. } else if (column.prop === 'consumeTime') {
  284. sortField.value = 'consumeTime'
  285. } else if (column.prop === 'buyBean') {
  286. sortField.value = 'buyBean'
  287. } else if (column.prop === 'freeBean') {
  288. sortField.value = 'freeBean'
  289. }
  290. sortOrder.value = column.order === 'ascending' ? 'DESC' : 'ASC'
  291. ConsumeSelectBy()
  292. }
  293. const handlePageSizeChange = function (val) {
  294. getObj.value.pageSize = val
  295. ConsumeSelectBy()
  296. }
  297. const handleCurrentChange = function (val) {
  298. getObj.value.pageNum = val
  299. ConsumeSelectBy()
  300. }
  301. /*
  302. ====================计算属性=================================
  303. */
  304. // 计算总金币数
  305. // const totalBean = computed(() => permanentBean.value + freeBean.value)
  306. /*
  307. ====================监听=================================
  308. */
  309. /*
  310. ====================挂载=================================
  311. */
  312. const format3 = (num) => {
  313. // 每三位添加逗号
  314. return num.toLocaleString('en-US')
  315. }
  316. onMounted(async function () {
  317. await getAdminData()
  318. await ConsumeSelectBy()
  319. await getDept()
  320. })
  321. const exportExcel = async function () {
  322. const params = { //需要修改
  323. ...getObj.value,
  324. "beanConsumeArticle": {
  325. ...beanConsumeArticle.value,
  326. sortField: sortField.value,
  327. sortOrder: sortOrder.value,
  328. },
  329. }
  330. const res = await API({ url: '/export/exportArticle', data: params })
  331. if (res.code === 200) {
  332. ElMessage.success('导出成功')
  333. }
  334. }
  335. const exportListVisible = ref(false)
  336. // 打开导出列表弹窗
  337. const openExportList = () => {
  338. getExportList()
  339. exportListVisible.value = true
  340. }
  341. // 导出列表数据
  342. const exportList = ref([])
  343. // 导出列表加载状态
  344. const exportListLoading = ref(false)
  345. // 获取导出列表
  346. const getExportList = async () => {
  347. exportListLoading.value = true
  348. try {
  349. const result = await API({ url: '/export/export' })
  350. if (result.code === 200) {
  351. const filteredData = result.data.filter(item => {
  352. return item.type === 8; //4表示金币消耗列表 // todo 修改对应type 8表示文章/视频
  353. });
  354. exportList.value = filteredData
  355. } else {
  356. ElMessage.error(result.msg || '获取导出列表失败')
  357. }
  358. } catch (error) {
  359. console.error('获取导出列表出错:', error)
  360. ElMessage.error('获取导出列表失败,请稍后重试')
  361. } finally {
  362. exportListLoading.value = false
  363. }
  364. }
  365. // 下载导出文件
  366. const downloadExportFile = (item) => {
  367. if (item.state === 2) {
  368. const link = document.createElement('a')
  369. link.href = item.url
  370. link.download = item.fileName
  371. link.click()
  372. } else {
  373. ElMessage.warning('文件还在导出中,请稍后再试')
  374. }
  375. }
  376. //根据状态返回对应的标签类型
  377. const getTagType = (state) => {
  378. switch (state) {
  379. case 0:
  380. return 'info';
  381. case 1:
  382. return 'primary';
  383. case 2:
  384. return 'success';
  385. case 3:
  386. return 'danger';
  387. default:
  388. return 'info';
  389. }
  390. }
  391. //根据状态返回对应的标签文案
  392. const getTagText = (state) => {
  393. switch (state) {
  394. case 0:
  395. return '待执行';
  396. case 1:
  397. return '执行中';
  398. case 2:
  399. return '执行完成';
  400. case 3:
  401. return '执行出错';
  402. default:
  403. return '未知状态';
  404. }
  405. }
  406. </script>
  407. <template>
  408. <el-card class="card1" style="margin-bottom: 0.5vh">
  409. <el-col style="margin-bottom: 1vh; ">
  410. <div class="select">
  411. <div class="selectRow">
  412. <el-text class="text" size="large">精网号</el-text>
  413. <el-input class="selectContent" v-model="beanConsumeArticle.jwcode" placeholder="请输入精网号" clearable />
  414. </div>
  415. <div class="selectRow">
  416. <el-text class="text" size="large">所属地区</el-text>
  417. <el-select class="selectContent" v-model="beanConsumeArticle.dept" placeholder="请选择地区" clearable>
  418. <el-option v-for="(item, index) in dept" :key="index" :label="item" :value="item" />
  419. </el-select>
  420. </div>
  421. <div class="selectRow">
  422. <el-text class="text" size="large">商品名称</el-text>
  423. <el-select class="selectContent" style="width: 20px" v-model="beanConsumeArticle.payMode" placeholder="请选择类型"
  424. clearable @change="handlePayModeChange">
  425. <el-option label="打赏" value="0" />
  426. <el-option label="付费购买" value="1" />
  427. <el-option label="其他" value="2" />
  428. </el-select>
  429. </div>
  430. <div class="selectRow">
  431. <el-text class="text">频道名称</el-text>
  432. <el-select class="selectContent" placeholder="请选择频道" clearable filterable>
  433. <el-option v-for="(item, index) in channels" :key="index" :label="item" :value="item" />
  434. </el-select>
  435. </div>
  436. </div>
  437. </el-col>
  438. <el-col>
  439. <div class="select">
  440. <div class="selectRow" style="width: 33vw;">
  441. <el-text class="text" size="large">下单时间</el-text>
  442. <el-date-picker class="selectContent" v-model="getTime" type="datetimerange" range-separator=""
  443. start-placeholder="起始时间" end-placeholder="结束时间" style="width:25vw" @change="handleDatePickerChange"
  444. value-format="YYYY-MM-DD HH:mm:ss" :default-time="defaultTime" />
  445. <div v-if="false">
  446. <el-button @click="getToday()" :type="activeTimeRange === 'today' ? 'primary' : ''"></el-button>
  447. <el-button @click="getYesterday()" :type="activeTimeRange === 'yesterday' ? 'primary' : ''"></el-button>
  448. <el-button @click="get7Days()" :type="activeTimeRange === '7days' ? 'primary' : ''">近7天</el-button>
  449. </div>
  450. </div>
  451. <div class="selectRow">
  452. <el-text class="text" size="large">直播间名称</el-text>
  453. <el-input class="selectContent" placeholder="请输入直播间" clearable />
  454. </div>
  455. </div>
  456. </el-col>
  457. <el-col>
  458. <div class="selectButton">
  459. <el-button type="primary" @click="search()">查询</el-button>
  460. <el-button type="primary" @click="exportExcel()">导出Excel</el-button>
  461. <el-button type="primary" @click="openExportList">查看导出列表</el-button>
  462. <el-button type="success" @click="reset()">重置</el-button>
  463. </div>
  464. </el-col>
  465. </el-card>
  466. <el-card class="card2">
  467. <div class="goldStatistics">
  468. 金豆总数{{ format3(Math.abs(permanentBean + freeBean)) }}&nbsp;&nbsp;&nbsp;&nbsp;
  469. 付费金豆数{{ format3(Math.abs(permanentBean)) }}&nbsp;&nbsp;&nbsp;&nbsp;
  470. 免费金豆数{{ format3(Math.abs(freeBean)) }}
  471. </div>
  472. <div style="overflow-y: auto">
  473. <el-table :data="tableData" style="width: 82vw" height="65vh" @sort-change="handleSortChange"
  474. :row-style="{ height: '50px' }">
  475. <el-table-column type="index" label="序号" width="110px" fixed="left">
  476. <template #default="scope">
  477. <span>{{
  478. scope.$index + 1 + (getObj.pageNum - 1) * getObj.pageSize
  479. }}</span>
  480. </template>
  481. </el-table-column>
  482. <!-- 固定姓名列 -->
  483. <el-table-column prop="name" label="姓名" width="140px" fixed="left" show-overflow-tooltip />
  484. <!-- 固定精网号列 -->
  485. <el-table-column prop="jwcode" label="精网号" width="140px" fixed="left" />
  486. <el-table-column prop="dept" label="地区" width="140px" />
  487. <el-table-column prop="type" label="商品名称" width="160px"/>
  488. <el-table-column prop="beanNum" label="金币数量" sortable="custom" width="140px" />
  489. <el-table-column prop="buyBean" label="频道名称" width="160px" show-overflow-tooltip />
  490. <el-table-column prop="freeBean" label="直播间名称" width="160px" show-overflow-tooltip />
  491. <el-table-column prop="consumeTime" label="下单时间" sortable="custom" width="180px">
  492. <template #default="scope">
  493. {{ formatTime(scope.row.consumeTime) }}
  494. </template>
  495. </el-table-column>
  496. </el-table>
  497. </div>
  498. <!-- 分页 -->
  499. <div class="pagination">
  500. <el-pagination background :page-size="getObj.pageSize" :page-sizes="[5, 10, 20, 50, 100]"
  501. layout="total, sizes, prev, pager, next, jumper" :total="total" @size-change="handlePageSizeChange"
  502. @current-change="handleCurrentChange"></el-pagination>
  503. </div>
  504. </el-card>
  505. <!-- 导出弹窗 -->
  506. <el-dialog v-model="exportListVisible" title="导出列表" width="80%">
  507. <el-table :data="exportList" style="width: 100% ;height: 60vh;" :loading="exportListLoading">
  508. <el-table-column prop="fileName" label="文件名" />
  509. <el-table-column prop="state" label="状态">
  510. <template #default="scope">
  511. <el-tag :type="getTagType(scope.row.state)" :effect="scope.row.state === 3 ? 'light' : 'plain'">
  512. {{ getTagText(scope.row.state) }}
  513. </el-tag>
  514. </template>
  515. </el-table-column>
  516. <el-table-column prop="createTime" label="创建时间">
  517. <template #default="scope">
  518. {{ moment(scope.row.createTime).format('YYYY-MM-DD HH:mm:ss') }}
  519. </template>
  520. </el-table-column>
  521. <el-table-column label="操作">
  522. <template #default="scope">
  523. <el-button type="primary" size="small" @click="downloadExportFile(scope.row)"
  524. :disabled="scope.row.state !== 2">
  525. 下载
  526. </el-button>
  527. </template>
  528. </el-table-column>
  529. </el-table>
  530. <template #footer>
  531. <div class="dialog-footer">
  532. <el-button text @click="exportListVisible = false">关闭</el-button>
  533. </div>
  534. </template>
  535. </el-dialog>
  536. </template>
  537. <style scoped lang="scss">
  538. // 搜索的卡片样式
  539. .card1 {
  540. background: #F3FAFE;
  541. }
  542. // 表单的卡片样式
  543. .card2 {
  544. background: #E7F4FD;
  545. height: 78vh;
  546. }
  547. // 新币总数等等
  548. .goldStatistics {
  549. margin-left: 1vw;
  550. margin-bottom: 1vh;
  551. color: #000000;
  552. font-family: "PingFang SC";
  553. font-size: 16px;
  554. font-style: normal;
  555. font-weight: 700;
  556. line-height: 20px;
  557. }
  558. // 表头背景等
  559. :deep(.el-table__header-wrapper),
  560. :deep(.el-table__body-wrapper),
  561. :deep(.el-table__cell),
  562. /* 表格 */
  563. :deep(.el-table__body td) {
  564. background-color: #F3FAFE !important;
  565. }
  566. /* 表头 */
  567. :deep(.el-table__header th) {
  568. background-color: #F3FAFE !important;
  569. }
  570. /* 鼠标悬停 */
  571. :deep(.el-table__row:hover > .el-table__cell) {
  572. background-color: #E5EBFE !important;
  573. }
  574. .pagination {
  575. display: flex;
  576. margin-top: 20px;
  577. }
  578. /** 搜索的样式 */
  579. .selectButton {
  580. margin-left: 1vw;
  581. margin-top: 1vh;
  582. }
  583. .select {
  584. display: flex;
  585. .selectRow {
  586. width: 16vw;
  587. display: flex;
  588. align-items: center;
  589. justify-content: center;
  590. padding: 0 0.5vw;
  591. .text {
  592. width: 5vw;
  593. font-size: 15px;
  594. }
  595. .textB {
  596. width: 7vw;
  597. font-size: 15px;
  598. }
  599. .selectContent {
  600. flex: 1;
  601. }
  602. }
  603. }
  604. </style>