feat: rating
This commit is contained in:
210
src/views/rating/pk/list/components/PkGenerate.vue
Normal file
210
src/views/rating/pk/list/components/PkGenerate.vue
Normal file
@@ -0,0 +1,210 @@
|
||||
<template>
|
||||
<el-dialog :title="title" :visible.sync="dialogFormVisible" width="600px" @close="close">
|
||||
<el-form ref="form" label-width="100px" :model="form" :rules="rules">
|
||||
<el-form-item label="评价主题" prop="topicId">
|
||||
<el-select
|
||||
v-model="form.topicId"
|
||||
v-loadmore="loadMoreTopics"
|
||||
filterable
|
||||
placeholder="请选择评价主题"
|
||||
style="width: 100%"
|
||||
@change="handleTopicChange"
|
||||
>
|
||||
<el-option v-for="item in topicList" :key="item.id" :label="item.title" :value="item.id" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="评价项" prop="itemIds">
|
||||
<el-select
|
||||
v-model="form.itemIds"
|
||||
v-loadmore="loadMoreItems"
|
||||
:disabled="!form.topicId"
|
||||
filterable
|
||||
multiple
|
||||
:multiple-limit="2"
|
||||
placeholder="请选择两个评价项进行PK"
|
||||
style="width: 100%"
|
||||
>
|
||||
<el-option v-for="item in itemList" :key="item.id" :label="item.name" :value="item.id">
|
||||
<div style="display: flex; align-items: center">
|
||||
<el-image
|
||||
v-if="item.avatarUrl"
|
||||
:src="getThumbUrl(item.avatarUrl)"
|
||||
style="width: 24px; height: 24px; border-radius: 50%; margin-right: 10px"
|
||||
/>
|
||||
<span>{{ item.name }}</span>
|
||||
</div>
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</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 { getList as getTopicList } from '@/api/rating/topic'
|
||||
import { getList as getItemList } from '@/api/rating/topicItem'
|
||||
import { generate } from '@/api/rating/pk'
|
||||
import { getThumbUrl } from '@/utils/blessing'
|
||||
|
||||
export default {
|
||||
name: 'PkGenerate',
|
||||
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() {
|
||||
const validateItemIds = (rule, value, callback) => {
|
||||
if (!value || value.length !== 2) {
|
||||
callback(new Error('请必须选择两个评价项进行PK'))
|
||||
} else {
|
||||
callback()
|
||||
}
|
||||
}
|
||||
return {
|
||||
title: '生成PK赛',
|
||||
dialogFormVisible: false,
|
||||
saving: false,
|
||||
form: {
|
||||
topicId: '',
|
||||
itemIds: [],
|
||||
},
|
||||
rules: {
|
||||
topicId: [{ required: true, trigger: 'change', message: '请选择评价主题' }],
|
||||
itemIds: [{ required: true, trigger: 'change', validator: validateItemIds }],
|
||||
},
|
||||
topicList: [],
|
||||
topicQuery: {
|
||||
pageNo: 1,
|
||||
pageSize: 20,
|
||||
},
|
||||
topicTotal: 0,
|
||||
fetchingTopics: false,
|
||||
|
||||
itemList: [],
|
||||
itemQuery: {
|
||||
pageNo: 1,
|
||||
pageSize: 20,
|
||||
topicId: '',
|
||||
},
|
||||
itemTotal: 0,
|
||||
fetchingItems: false,
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
getThumbUrl,
|
||||
showEdit() {
|
||||
this.title = '生成PK赛'
|
||||
this.form = this.$options.data().form
|
||||
this.dialogFormVisible = true
|
||||
|
||||
this.topicQuery.pageNo = 1
|
||||
this.topicList = []
|
||||
this.topicTotal = 0
|
||||
this.fetchTopicList()
|
||||
},
|
||||
close() {
|
||||
this.$refs['form'].resetFields()
|
||||
this.form = this.$options.data().form
|
||||
this.itemList = []
|
||||
this.dialogFormVisible = false
|
||||
},
|
||||
// -- Topic 列表加载 --
|
||||
async fetchTopicList() {
|
||||
if (this.fetchingTopics) return
|
||||
this.fetchingTopics = true
|
||||
try {
|
||||
const { data } = await getTopicList(this.topicQuery)
|
||||
this.topicList = this.topicList.concat(data.list || [])
|
||||
this.topicTotal = data.totalCount || 0
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
} finally {
|
||||
this.fetchingTopics = false
|
||||
}
|
||||
},
|
||||
loadMoreTopics() {
|
||||
if (this.topicList.length >= this.topicTotal || this.fetchingTopics) return
|
||||
this.topicQuery.pageNo += 1
|
||||
this.fetchTopicList()
|
||||
},
|
||||
|
||||
// -- Item 列表加载 --
|
||||
async fetchItemList() {
|
||||
if (this.fetchingItems || !this.itemQuery.topicId) return
|
||||
this.fetchingItems = true
|
||||
try {
|
||||
const { data } = await getItemList(this.itemQuery)
|
||||
this.itemList = this.itemList.concat(data.list || [])
|
||||
this.itemTotal = data.totalCount || 0
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
} finally {
|
||||
this.fetchingItems = false
|
||||
}
|
||||
},
|
||||
loadMoreItems() {
|
||||
if (this.itemList.length >= this.itemTotal || this.fetchingItems) return
|
||||
this.itemQuery.pageNo += 1
|
||||
this.fetchItemList()
|
||||
},
|
||||
|
||||
handleTopicChange(val) {
|
||||
this.form.itemIds = []
|
||||
this.itemList = []
|
||||
this.itemQuery.pageNo = 1
|
||||
this.itemTotal = 0
|
||||
|
||||
if (val) {
|
||||
this.itemQuery.topicId = val
|
||||
this.fetchItemList()
|
||||
} else {
|
||||
this.itemQuery.topicId = ''
|
||||
}
|
||||
},
|
||||
|
||||
save() {
|
||||
this.$refs['form'].validate(async (valid) => {
|
||||
if (valid) {
|
||||
this.saving = true
|
||||
try {
|
||||
const payload = {
|
||||
topicId: this.form.topicId,
|
||||
leftItemId: this.form.itemIds[0],
|
||||
rightItemId: this.form.itemIds[1],
|
||||
}
|
||||
const { msg } = await generate(payload)
|
||||
this.$baseMessage(msg || '生成PK赛成功', 'success')
|
||||
this.close()
|
||||
this.$emit('fetch-data')
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
} finally {
|
||||
this.saving = false
|
||||
}
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
})
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
Reference in New Issue
Block a user