2026-06-15 22:28:39 +08:00
|
|
|
<template>
|
|
|
|
|
<el-dialog :title="title" :visible.sync="dialogFormVisible" width="500px" @close="close">
|
|
|
|
|
<el-form ref="form" label-width="80px" :model="form" :rules="rules">
|
|
|
|
|
<el-form-item label="支持项">
|
|
|
|
|
<span style="font-weight: bold; color: #409eff">{{ targetName }}</span>
|
|
|
|
|
</el-form-item>
|
2026-07-04 20:29:49 +08:00
|
|
|
<el-form-item label="支持方式" prop="voteMode">
|
|
|
|
|
<el-radio-group v-model="form.voteMode">
|
|
|
|
|
<el-radio label="user">投票用户</el-radio>
|
|
|
|
|
<el-radio label="count">支持个数</el-radio>
|
|
|
|
|
</el-radio-group>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
|
|
|
<el-form-item v-if="form.voteMode === 'user'" label="投票用户" prop="userId">
|
2026-06-15 22:28:39 +08:00
|
|
|
<el-select v-model="form.userId" v-loadmore="loadMoreRobots" filterable placeholder="请选择投票的机器人" style="width: 100%">
|
|
|
|
|
<el-option v-for="item in robotList" :key="item.id" :label="item.nickname || item.id" :value="item.id">
|
|
|
|
|
<div style="display: flex; align-items: center">
|
|
|
|
|
<el-image
|
|
|
|
|
v-if="item.avatar"
|
|
|
|
|
:src="getThumbUrl(item.avatar)"
|
|
|
|
|
style="width: 24px; height: 24px; border-radius: 50%; margin-right: 10px"
|
|
|
|
|
/>
|
|
|
|
|
<span>{{ item.nickname || '未知用户' }}</span>
|
|
|
|
|
</div>
|
|
|
|
|
</el-option>
|
|
|
|
|
</el-select>
|
|
|
|
|
</el-form-item>
|
2026-07-04 20:29:49 +08:00
|
|
|
|
|
|
|
|
<el-form-item v-if="form.voteMode === 'count'" label="支持个数" prop="count">
|
|
|
|
|
<el-input-number v-model="form.count" controls-position="right" :max="100000" :min="1" :step="1" style="width: 100%" />
|
|
|
|
|
</el-form-item>
|
2026-06-15 22:28:39 +08:00
|
|
|
</el-form>
|
|
|
|
|
|
|
|
|
|
<div slot="footer" class="dialog-footer">
|
|
|
|
|
<el-button @click="close">取 消</el-button>
|
|
|
|
|
<el-button :loading="saving" type="primary" @click="save">确 定</el-button>
|
|
|
|
|
</div>
|
|
|
|
|
</el-dialog>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
import { getListBase as getRobotList } from '@/api/system/robot'
|
|
|
|
|
import { vote } from '@/api/rating/pk'
|
|
|
|
|
import { getThumbUrl } from '@/utils/blessing'
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
name: 'PkVoteEdit',
|
|
|
|
|
directives: {
|
|
|
|
|
loadmore: {
|
|
|
|
|
bind(el, binding) {
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
const SELECTWRAP_DOM = el.querySelector('.el-select-dropdown .el-select-dropdown__wrap')
|
|
|
|
|
if (SELECTWRAP_DOM) {
|
|
|
|
|
SELECTWRAP_DOM.addEventListener('scroll', function () {
|
|
|
|
|
const condition = this.scrollHeight - this.scrollTop <= this.clientHeight + 2
|
|
|
|
|
if (condition) {
|
|
|
|
|
binding.value()
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}, 0)
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
title: '参与投票',
|
|
|
|
|
dialogFormVisible: false,
|
|
|
|
|
saving: false,
|
|
|
|
|
targetName: '',
|
|
|
|
|
form: {
|
|
|
|
|
pkId: '',
|
|
|
|
|
itemId: '',
|
2026-07-04 20:29:49 +08:00
|
|
|
voteMode: 'user',
|
2026-06-15 22:28:39 +08:00
|
|
|
userId: '',
|
2026-07-04 20:29:49 +08:00
|
|
|
count: 1,
|
2026-06-15 22:28:39 +08:00
|
|
|
},
|
|
|
|
|
rules: {
|
2026-07-04 20:29:49 +08:00
|
|
|
voteMode: [{ required: true, trigger: 'change', message: '请选择支持方式' }],
|
2026-06-15 22:28:39 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 机器人下拉列表状态
|
|
|
|
|
robotList: [],
|
|
|
|
|
robotQuery: {
|
|
|
|
|
appId: '6a0d7dbe4c5de50f2ba66475',
|
|
|
|
|
pageNo: 1,
|
|
|
|
|
pageSize: 20,
|
|
|
|
|
},
|
|
|
|
|
robotTotal: 0,
|
|
|
|
|
fetchingRobots: false,
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
getThumbUrl,
|
|
|
|
|
showEdit(pkId, itemId, itemName) {
|
|
|
|
|
this.dialogFormVisible = true
|
|
|
|
|
this.targetName = itemName
|
|
|
|
|
this.form = this.$options.data().form
|
|
|
|
|
this.form.pkId = pkId
|
|
|
|
|
this.form.itemId = itemId
|
|
|
|
|
|
|
|
|
|
// 重置列表并加载第一页
|
|
|
|
|
this.robotList = []
|
|
|
|
|
this.robotQuery.pageNo = 1
|
|
|
|
|
this.robotTotal = 0
|
|
|
|
|
this.fetchRobotList()
|
|
|
|
|
},
|
|
|
|
|
close() {
|
|
|
|
|
this.$refs['form'].resetFields()
|
|
|
|
|
this.dialogFormVisible = false
|
|
|
|
|
},
|
|
|
|
|
async fetchRobotList() {
|
|
|
|
|
if (this.fetchingRobots) return
|
|
|
|
|
this.fetchingRobots = true
|
|
|
|
|
try {
|
|
|
|
|
const { data } = await getRobotList(this.robotQuery)
|
|
|
|
|
this.robotList = this.robotList.concat(data.list || [])
|
|
|
|
|
this.robotTotal = data.totalCount || 0
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(error)
|
|
|
|
|
} finally {
|
|
|
|
|
this.fetchingRobots = false
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
loadMoreRobots() {
|
|
|
|
|
if (this.robotList.length >= this.robotTotal || this.fetchingRobots) return
|
|
|
|
|
this.robotQuery.pageNo += 1
|
|
|
|
|
this.fetchRobotList()
|
|
|
|
|
},
|
|
|
|
|
save() {
|
|
|
|
|
this.$refs['form'].validate(async (valid) => {
|
|
|
|
|
if (valid) {
|
2026-07-04 20:29:49 +08:00
|
|
|
if (this.form.voteMode === 'user' && !this.form.userId) {
|
|
|
|
|
this.$baseMessage('请选择投票的机器人', 'error')
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
if (this.form.voteMode === 'count' && (!this.form.count || this.form.count < 1)) {
|
|
|
|
|
this.$baseMessage('请输入正确的支持个数', 'error')
|
|
|
|
|
return false
|
|
|
|
|
}
|
2026-06-15 22:28:39 +08:00
|
|
|
this.saving = true
|
|
|
|
|
try {
|
2026-07-04 20:29:49 +08:00
|
|
|
const params = {
|
|
|
|
|
pkId: this.form.pkId,
|
|
|
|
|
itemId: this.form.itemId,
|
|
|
|
|
}
|
|
|
|
|
if (this.form.voteMode === 'user') {
|
|
|
|
|
params.userId = this.form.userId
|
|
|
|
|
} else {
|
|
|
|
|
params.count = this.form.count
|
|
|
|
|
}
|
|
|
|
|
const { msg } = await vote(params)
|
2026-06-15 22:28:39 +08:00
|
|
|
this.$baseMessage(msg || '投票成功', 'success')
|
|
|
|
|
this.close()
|
|
|
|
|
this.$emit('fetch-data')
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(error)
|
|
|
|
|
} finally {
|
|
|
|
|
this.saving = false
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
</script>
|