| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236 |
- // pages/thirdPartyContent/thirdPartyContent.js
- const thirdPartyApi = require('../../api/thirdPartyContent');
- const categoryApi = require('../../api/category');
- Page({
- data: {
- contentList: [],
- categoryList: [],
- loading: false,
- current: 1,
- size: 10,
- total: 0,
- totalPages: 0,
- keyword: '',
- statistics: {
- pending: 0,
- approved: 0,
- rejected: 0,
- deletePending: 0
- }
- },
- onLoad() {
- this.loadCategoryList();
- this.loadData();
- this.loadStatistics();
- },
- onShow() {
- this.loadData();
- this.loadStatistics();
- },
- // 加载分类列表
- async loadCategoryList() {
- try {
- const res = await categoryApi.getCategoryList();
- if (res.code === 200) {
- this.setData({
- categoryList: res.data || []
- });
- }
- } catch (error) {
- console.error('加载分类列表失败:', error);
- }
- },
- // 加载数据
- async loadData() {
- this.setData({ loading: true });
- try {
- const res = await thirdPartyApi.getMyContentPage(
- this.data.current,
- this.data.size,
- this.data.keyword
- );
- if (res.code === 200) {
- const total = res.data.total || 0;
- const totalPages = Math.ceil(total / this.data.size);
- this.setData({
- contentList: res.data.records || [],
- total: total,
- totalPages: totalPages,
- loading: false
- });
- } else {
- wx.showToast({
- title: res.message || '加载失败',
- icon: 'none'
- });
- this.setData({ loading: false });
- }
- } catch (error) {
- console.error('加载数据失败:', error);
- wx.showToast({
- title: '加载失败',
- icon: 'none'
- });
- this.setData({ loading: false });
- }
- },
- // 加载统计信息
- async loadStatistics() {
- try {
- const res = await thirdPartyApi.getStatistics();
- if (res.code === 200) {
- this.setData({
- statistics: res.data || {}
- });
- }
- } catch (error) {
- console.error('加载统计信息失败:', error);
- }
- },
- // 搜索
- onSearchInput(e) {
- this.setData({
- keyword: e.detail.value
- });
- },
- // 执行搜索
- onSearch() {
- this.setData({ current: 1 });
- this.loadData();
- },
- // 上传书籍
- goToUpload() {
- wx.navigateTo({
- url: '/pages/thirdPartyContentEdit/thirdPartyContentEdit'
- });
- },
- // 编辑书籍
- editContent(e) {
- const contentId = e.currentTarget.dataset.id;
- wx.navigateTo({
- url: `/pages/thirdPartyContentEdit/thirdPartyContentEdit?id=${contentId}`
- });
- },
- // 下架书籍
- async offlineContent(e) {
- const contentId = e.currentTarget.dataset.id;
- wx.showModal({
- title: '提示',
- content: '确定要下架这本书吗?下架后用户将无法看到。',
- success: async (res) => {
- if (res.confirm) {
- try {
- const result = await thirdPartyApi.offlineContent(contentId);
- if (result.code === 200) {
- wx.showToast({
- title: '已下架',
- icon: 'success'
- });
- this.loadData();
- this.loadStatistics();
- } else {
- wx.showToast({
- title: result.message || '操作失败',
- icon: 'none'
- });
- }
- } catch (error) {
- wx.showToast({
- title: '操作失败',
- icon: 'none'
- });
- }
- }
- }
- });
- },
- // 上架书籍
- async onlineContent(e) {
- const contentId = e.currentTarget.dataset.id;
- try {
- const result = await thirdPartyApi.onlineContent(contentId);
- if (result.code === 200) {
- wx.showToast({
- title: '已上架',
- icon: 'success'
- });
- this.loadData();
- this.loadStatistics();
- } else {
- wx.showToast({
- title: result.message || '操作失败',
- icon: 'none'
- });
- }
- } catch (error) {
- wx.showToast({
- title: '操作失败',
- icon: 'none'
- });
- }
- },
- // 申请删除
- async requestDelete(e) {
- const contentId = e.currentTarget.dataset.id;
- wx.showModal({
- title: '提示',
- content: '确定要申请删除这本书吗?需要超级管理员审核后才能删除。',
- success: async (res) => {
- if (res.confirm) {
- try {
- const result = await thirdPartyApi.requestDeleteContent(contentId);
- if (result.code === 200) {
- wx.showToast({
- title: '删除申请已提交',
- icon: 'success'
- });
- this.loadData();
- this.loadStatistics();
- } else {
- wx.showToast({
- title: result.message || '操作失败',
- icon: 'none'
- });
- }
- } catch (error) {
- wx.showToast({
- title: '操作失败',
- icon: 'none'
- });
- }
- }
- }
- });
- },
- // 分页
- onPageChange(e) {
- const current = e.currentTarget.dataset.current || e.detail.current;
- this.setData({ current });
- this.loadData();
- },
- // 下拉刷新
- onPullDownRefresh() {
- this.setData({ current: 1 });
- this.loadData();
- this.loadStatistics();
- setTimeout(() => {
- wx.stopPullDownRefresh();
- }, 1000);
- }
- });
|