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.

674 lines
19 KiB

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