MyRedPackage.vue 15.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
<template>
	<div>
		<el-container>
			<el-main>
				<el-form :inline="true" :model="formInline" class="demo-form-inline">
					<el-form-item>
						<el-input size="small" clearable v-model="formInline.nickName" placeholder="请输入用户昵称" @keydown.enter.native="redPackagePage"></el-input>
					</el-form-item>

					<el-form-item>
11 12 13 14 15
						<el-input size="small" clearable v-model="formInline.myAmountStart" placeholder="请输入最小金额" @keydown.enter.native="redPackagePage"></el-input>
					</el-form-item>

					<el-form-item>
						<el-input size="small" clearable v-model="formInline.myAmountEnd" placeholder="请输入最大金额" @keydown.enter.native="redPackagePage"></el-input>
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
					</el-form-item>

					<el-form-item>
						<el-select size="small" v-model="formInline.itemType" placeholder="请选择红包类型" @change="redPackagePage">
							<el-option v-for="type in itemType" :key="type" :label="type" :value="type"></el-option>
						</el-select>
					</el-form-item>

					<el-form-item>
						<el-select size="small" v-model="formInline.msg" placeholder="请选择当前状态" @change="redPackagePage">
							<el-option v-for="type in msg" :key="type" :label="type" :value="type"></el-option>
						</el-select>
					</el-form-item>

					<el-form-item>
						<el-button size="small" type="primary" @click="redPackagePage">查询</el-button>
					</el-form-item>

					<el-form-item>
						<el-button size="small" type="primary" @click="prepareGetToday">今日所得</el-button>
36
						<el-dialog v-loading="loading" title="今日所得查询" :visible.sync="getTodayDialogVisible" style="width: 100%">
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
							<el-form :model="form" class="custom-form">
								<el-row :gutter="20">
									<el-col :span="12">
										<el-input v-model="form.todayGet" placeholder="今日所得" autocomplete="off"></el-input>
										<el-input v-model="form.allGet" placeholder="累计所得" autocomplete="off"></el-input>
									</el-col>
								</el-row>
							</el-form>
							<div slot="footer" class="dialog-footer">
								<el-button @click="getTodayDialogVisible = false">取 消</el-button>
								<el-button type="primary" @click="getToday">查 询</el-button>
							</div>
						</el-dialog>
					</el-form-item>

					<el-form-item>
						<el-button size="small" type="primary" @click="prepareViewCountAll">浏览量</el-button>
						<el-dialog title="提示" :visible.sync="viewCountAllDialogVisible" width="30%" :before-close="handleClose">
							<span>确认处理浏览量吗?</span>
							<span slot="footer" class="dialog-footer">
								<el-button @click="viewCountAllDialogVisible = false">取 消</el-button>
								<el-button type="primary" @click.prevent="viewCountAll()">确 定</el-button>
							</span>
						</el-dialog>
					</el-form-item>
62 63 64 65

					<el-form-item>
						<el-button size="small" type="primary" @click="newRedPackage">最新红包</el-button>
					</el-form-item>
66 67 68 69 70 71 72 73 74 75 76

					<el-form-item>
						<el-button size="small" type="primary" @click="prepareDetailsInfo">同步详情</el-button>
						<el-dialog title="提示" :visible.sync="detailsInfoDialogVisible" width="30%" :before-close="handleClose">
							<span>确认同步红包详情吗?</span>
							<span slot="footer" class="dialog-footer">
								<el-button @click="detailsInfoDialogVisible = false">取 消</el-button>
								<el-button type="primary" @click.prevent="detailsInfo()">确 定</el-button>
							</span>
						</el-dialog>
					</el-form-item>
77 78 79 80 81 82 83 84 85 86 87 88
				</el-form>
				<el-table ref="multipleTable" v-loading="loading" :data="csdnRedPackageList" tooltip-effect="dark" style="width: 100%">
					<el-table-column prop="id" label="序号" width="100" sortable></el-table-column>
					<el-table-column prop="nickName" label="用户昵称" show-overflow-tooltip>
						<template slot-scope="scope">
							<a :href="scope.row.shareUrl" target="_blank">{{ scope.row.nickName }}</a>
						</template>
					</el-table-column>

					<el-table-column prop="viewCount" label="浏览量" show-overflow-tooltip></el-table-column>
					<el-table-column prop="itemType" label="类型" show-overflow-tooltip></el-table-column>

89 90
					<el-table-column prop="orderNo" label="订单号" show-overflow-tooltip></el-table-column>

91
					<el-table-column prop="myAmount" label="我的金额" sortable show-overflow-tooltip>
92 93 94 95 96
						<template slot-scope="scope">
							<el-tag :type="getTagType(scope.row.myAmount)">{{ scope.row.myAmount }}</el-tag>
						</template>
					</el-table-column>

97 98 99 100 101
					<el-table-column prop="msg" label="详情" show-overflow-tooltip>
						<template slot-scope="scope">
							<el-tag :type="getMsgType(scope.row.msg)">{{ scope.row.msg }}</el-tag>
						</template>
					</el-table-column>
102

103 104
					<el-table-column label="创建时间">
						<template slot-scope="props">{{ props.row.createTime | dateFormat }}</template>
105
					</el-table-column>
106

107
					<el-table-column prop="操作" label="操作" width="250">
108
						<template slot-scope="props">
109
							<el-button type="success" @click="dealViewCount(props.row.id)" size="small">浏览量</el-button>
110
							<el-button type="success" @click="syncDetailInfo(props.row.id)" size="small">同步详情</el-button>
111
							<el-button size="small" type="primary" @click.prevent="preEdit(props.row.id, props.row.nickName, props.row.myAmount, props.row.msg)" width="200">编辑</el-button>
112 113 114
							<el-dialog title="编辑红包信息" :visible.sync="editVisible">
								<el-form :model="form">
									<el-form-item label="用户名称" class="form-item">
115
										<el-input v-model="form.nickName" autocomplete="off" style="width: 100%"></el-input>
116 117 118 119
									</el-form-item>
									<el-form-item label="我的金额" class="form-item">
										<el-input v-model="form.myAmount" autocomplete="off" style="width: 100%"></el-input>
									</el-form-item>
120 121 122
									<el-form-item label="详细信息" class="form-item">
										<el-input v-model="form.msg" autocomplete="off" style="width: 100%"></el-input>
									</el-form-item>
123 124 125 126 127 128
								</el-form>
								<div slot="footer" class="dialog-footer">
									<el-button @click="editVisible = false">取 消</el-button>
									<el-button type="primary" @click="editConfirm">确 定</el-button>
								</div>
							</el-dialog>
129 130 131 132 133 134 135 136 137 138 139 140 141
						</template>
					</el-table-column>
				</el-table>
				<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-sizes="[8, 50, 100, 200, 400]" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total"></el-pagination>
			</el-main>
			<el-backtop class="backtop"></el-backtop>
		</el-container>
	</div>
</template>

<script>
import axios from 'axios'
export default {
142
    name: 'MyRedPackage',
143

144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
    data() {
        return {
            form: {
                todayGet: '',
                allGet: '',
                myAmount: '',
                nickName: '',
                msg: '',
            },
            formInline: {
                nickName: '',
                itemType: '',
                myAmount: '',
                msg: '',
                myAmountStart: '',
                myAmountEnd: '',
            },
            itemType: ['全部', 'article', 'blink', 'topic'],
            msg: ['全部', 'received', 'completed', '其它'],
            deleteDialogVisible: false,
            editVisible: false,
            viewCountAllDialogVisible: false,
            getTodayDialogVisible: false,
167
            detailsInfoDialogVisible: false,
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
            // 用户列表数据
            csdnRedPackageList: [],
            loading: false,
            elementui_page_component_key: 0,
            currentPage: Number(localStorage.getItem('redPackagePage')) || 1,
            pageSize: 10,
            total: 0,
            currentRowId: null,
            currentUserName: null,
        }
    },
    watch: {
        formInline: {
            handler(newVal, oldVal) {
                this.currentPage = 1
                localStorage.setItem('redPackagePage', this.currentPage)
                this.redPackagePage()
            },
            deep: true,
        },
        // 监听currentPage的变化,将新值保存到localStorage中
        currentPage(newPage) {
            localStorage.setItem('redPackagePage', newPage.toString())
        },
    },
    created() {
        //获取问题类型的枚举
        this.redPackagePage()
    },
    mounted() {
        this.currentPage = 1
    },
    methods: {
        prepareViewCountAll() {
            this.viewCountAllDialogVisible = true
        },
204 205 206
        prepareDetailsInfo() {
            this.detailsInfoDialogVisible = true
        },
207 208 209 210 211 212 213 214 215
        prepareGetToday() {
            this.form.todayGet = ''
            this.form.allGet = ''
            this.getTodayDialogVisible = true
        },
        prepareDelete(id) {
            this.currentRowId = id
            this.deleteDialogVisible = true
        },
216

217 218 219 220 221 222 223
        preEdit(id, nickName, myAmount, msg) {
            this.form.nickName = nickName
            this.form.myAmount = myAmount
            this.form.msg = msg
            this.currentRowId = id
            this.editVisible = true
        },
224

225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253
        handleClose(done) {
            this.$confirm('确认关闭?')
                .then((_) => {
                    done()
                })
                .catch((_) => {})
        },
        handleConfirm(addType) {
            this.dialogFormVisible = false // 关闭对话框
            this.dialogMutiFormVisible = false
            this.addUser(addType) // 发送请求
        },
        async redPackagePage() {
            this.loading = true
            const { data: res } = await axios.post('http://43.139.90.182:8888/csdn/redPackage/page', {
                page: this.currentPage,
                pageSize: this.pageSize,
                nickName: this.formInline.nickName,
                myAmountStart: this.formInline.myAmountStart,
                myAmountEnd: this.formInline.myAmountEnd,
                itemType: this.formInline.itemType == '全部' ? null : this.formInline.itemType,
                msg: this.formInline.msg == '全部' ? null : this.formInline.msg,
            })
            if (res.code === 200) {
                this.total = res.result.totalElements
                this.csdnRedPackageList = res.result.content
            }
            this.loading = false
        },
254

255 256 257 258 259 260 261
        async dealViewCount(id) {
            this.loading = true
            const { data: res } = await axios.get('http://43.139.90.182:8888/csdn/redPackage/getViewCountById?id=' + id)
            if (res.code === 200) {
                this.redPackagePage()
            } else {
                console.error('Received non-200 status code', res)
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
            }
            this.loading = false
        },
        async syncDetailInfo(id) {
            this.loading = true
            const { data: res } = await axios.get('http://43.139.90.182:8888/csdn/redPackage/syncDetailInfo?id=' + id)
            if (res.code === 200) {
                this.redPackagePage()
            } else {
                console.error('Received non-200 status code', res)
            }
            this.loading = false
        },

        async detailsInfo() {
            this.loading = true
            this.detailsInfoDialogVisible = false
            const { data: res } = await axios.get('http://43.139.90.182:8888/csdn/redPackage/getRedPackageDetailInfo')
            if (res.code === 200) {
                this.redPackagePage()
            } else {
                console.error('Received non-200 status code', res)
284 285 286
            }
            this.loading = false
        },
287

288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
        async editConfirm() {
            try {
                this.loading = true
                const { data: res } = await axios.post('http://43.139.90.182:8888/csdn/redPackage/update', {
                    id: this.currentRowId,
                    nickName: this.form.nickName,
                    myAmount: this.form.myAmount,
                    msg: this.form.msg,
                })
                if (res.code === 200) {
                    this.form.nickName = ''
                    this.form.myAmount = ''
                    this.form.msg = ''
                    this.editVisible = false
                    currentRowId: null
                    this.redPackagePage()
                } else {
                    console.error('Received non-200 status code', res)
                }
            } catch (error) {
                console.error('An error occurred while adding the questionName:', error)
                // 异常处理逻辑
            } finally {
                this.loading = false
            }
        },
314

315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358
        async viewCountAll() {
            this.loading = true
            this.viewCountAllDialogVisible = false
            const { data: res1 } = await axios.get('http://43.139.90.182:8888/csdn/redPackage/getViewCountAll')
            if (res1.code === 200) {
                this.redPackagePage()
            } else {
                console.error('Received non-200 status code', res1)
            }
            this.loading = false
        },
        async getToday() {
            const { data: res } = await axios.get('http://43.139.90.182:8888/csdn/redPackage/getMyAmount')
            if (res.code === 200) {
                this.form.todayGet = res.result.todayGet
                this.form.allGet = res.result.allGet
            } else {
                console.error('Received non-200 status code', res)
            }
        },
        async onDelete(id) {
            this.loading = true
            const { data: res } = await axios.get('http://43.139.90.182:8888/csdn/user/delete', {
                params: {
                    id: id,
                },
            })
            this.deleteDialogVisible = false
            this.redPackagePage()
            this.loading = false
        },
        refreshPage() {
            //获取问题类型的枚举
            this.redPackagePage()
            location.reload()
        },
        handleCurrentChange(currentPage) {
            this.currentPage = currentPage
            this.redPackagePage()
        },
        handleSizeChange(currentSize) {
            this.pageSize = currentSize
            this.redPackagePage()
        },
359

360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382
        newRedPackage() {
            // 新页面打开
            window.open('https://bbs.csdn.net/?type=4&header=0&utm_source=wwwtab')
        },
        getTagType(myAmount) {
            if (myAmount >= 0.3) {
                return 'success'
            } else if (myAmount >= 0.2) {
                return 'primary'
            } else if (myAmount >= 0.1) {
                return 'warning'
            } else {
                return 'danger'
            }
        },
        getMsgType(msg) {
            if (msg == 'received' || msg == 'completed') {
                return 'success'
            } else {
                return 'danger'
            }
        },
    },
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433
}
</script>

<style lang="less" scoped>
.el-header {
	background-color: #b3c0d1;
	color: #333;
	line-height: 60px;
}

.el-aside {
	color: #333;
}

.pagination {
	margin-top: 16px;
	text-align: right;
}
.header-button-item {
	margin-right: 15px;
	font-size: 20px;
}

.red-title {
	line-height: 24px;
	font-size: 18px;
	color: red;
}

.backtop {
	position: fixed;
	bottom: 50px;
	right: 50px;
	height: 40px;
	width: 40px;
	line-height: 40px;
	text-align: center;
	border-radius: 20px;
	background-color: #007aff;
	color: #fff;
	cursor: pointer;
	z-index: 999;
}
.custom-textarea {
	width: 100%;
	text-align: left;
}
.backtop:hover {
	background-color: #0050a0;
}
</style>