yujialong 1 week ago
parent 321d0841e2
commit 2f2e5c5622
  1. 715
      src/pages/topic/detail/auto.vue
  2. 99
      src/pages/topic/detail/index.vue
  3. 133
      src/pages/topic/detail/topicType.vue

@ -1,715 +0,0 @@
<template>
<div>
<el-drawer title="自动选题" :visible.sync="quesVisible" size="1200px" :close-on-click-modal="false"
custom-class="ques-dia" @closed="closeDia">
<div class="overflow">
<h6 class="page-name">难度设置</h6>
<div class="tool">
<ul class="filter">
<li style="margin-right: 10px">
<label>试卷难度</label>
<el-select v-model="difficult" placeholder="请选择试卷难度" @change="difficultChange">
<el-option v-for="(item, i) in difficults" :key="i" :label="item.name" :value="item.id"></el-option>
</el-select>
</li>
<el-tooltip placement="top">
<div class="diff-text" slot="content">
<p>基础题难度系数0.2</p>
<p>普通题难度系数0.4</p>
<p>较难题难度系数0.6</p>
<p>困难题难度系数0.8</p>
<p>1<span class="em">题型难度系数</span>=对应题型所有试题的难度系数之和/总试题数</p>
<p>2<span class="em">试卷总难度系数</span>=所有试题的难度系数之和/总试题数</p>
<p>3<span class="em">难度系数评价</span></p>
<div class="coe">
<p>简单系数 &lt;=0.3</p>
<p>普通0.3&lt;系数&lt;=0.4</p>
<p>较难0.4&lt;系数&lt;0.5</p>
<p>困难:系数&gt;=0.5</p>
</div>
</div>
<i class="el-icon-question" style="font-size: 16px;color: #8f8f8f;cursor: pointer;"></i>
</el-tooltip>
</ul>
</div>
<el-table :data="list" stripe header-align="center" row-key="libraryId">
<el-table-column type="index" width="60" label="序号" align="center"></el-table-column>
<el-table-column label="大题" align="center" min-width="100">
<template slot-scope="scope">{{ arabicToChinese(scope.$index + 1) }}大题</template>
</el-table-column>
<el-table-column prop="name" label="题型" align="center" min-width="90">
<template slot-scope="scope">
<p v-if="scope.row.questionType">{{ questionTypes.find(e => e.id === scope.row.questionType).name }}</p>
</template>
</el-table-column>
<el-table-column prop="questionNum" label="目标题数" align="center" min-width="80"></el-table-column>
<el-table-column label="基础(道题)" align="center" width="90">
<template slot-scope="scope">
<el-input v-model.number="scope.row.basicDifficulty" type="number" />
</template>
</el-table-column>
<el-table-column label="普通(道题)" align="center" width="90">
<template slot-scope="scope">
<el-input v-model.number="scope.row.normalDifficulty" type="number" />
</template>
</el-table-column>
<el-table-column label="较难(道题)" align="center" width="90">
<template slot-scope="scope">
<el-input v-model.number="scope.row.hardDifficulty" type="number" />
</template>
</el-table-column>
<el-table-column label="难(道题)" align="center" width="90">
<template slot-scope="scope">
<el-input v-model.number="scope.row.veryHardDifficulty" type="number" />
</template>
</el-table-column>
<el-table-column label="难度随机(道题)" align="center" width="100">
<template slot-scope="scope">
<el-input v-model.number="scope.row.randomDifficulty" type="number" />
</template>
</el-table-column>
</el-table>
<h6 class="page-name m-t-20">知识点设置</h6>
<div class="wrap">
<!-- 题库 -->
<div class="item">
<p class="total m-b-10">题库</p>
<ul class="filter">
<li class="m-b-10">
<label>题库分类</label>
<el-cascader style="width: 240px;" placeholder="请选择题库分类" v-model="quesBankTypeVal"
:options="quesBankTypes" :props="{ value: 'id', label: 'name', checkStrictly: true }" clearable
@change="initQuesBank"></el-cascader>
</li>
<li>
<el-input placeholder="请输入题库名称" prefix-icon="el-icon-search" v-model="quesBankKeyword" clearable />
</li>
</ul>
<template v-if="quesBanks.length">
<div class="line">
<span class="serial first">序号</span>
<span>题库名称</span>
</div>
<div class="able-check lines">
<div v-for="(item, i) in quesBanks" :key="i" :class="['line', { active: curQuesBank.id === item.id }]"
@click="questionBankClick(item)">
<span class="serial first">{{ i + 1 }}</span>
<p class="stem" :title="item.questionBankName">{{ item.questionBankName }}</p>
</div>
</div>
</template>
<div v-else class="empty">
<img class="icon" src="@/assets/images/empty.svg" alt="">
<p>暂无数据</p>
</div>
</div>
<!-- 知识点 -->
<div class="item">
<p class="total m-b-10">知识点</p>
<ul class="filter">
<li class="m-b-10">
<label>知识点框架</label>
<el-cascader style="width: 240px;" placeholder="请选择知识点分类" v-model="knowledgeTypeVal"
:options="knowledgeTypes" :props="{ value: 'id', label: 'name', checkStrictly: true }" clearable
@change="getKnowledge"></el-cascader>
</li>
<li>
<el-input placeholder="请输入知识点名称" prefix-icon="el-icon-search" v-model="knowledgeKeyword" clearable />
</li>
</ul>
<template v-if="knowledges.length">
<div class="line">
<el-checkbox v-model="knowledgeCheck" @change="knowledgeAllCheckChange"></el-checkbox>
<span class="serial">序号</span>
<span>知识点名称</span>
</div>
<div class="lines">
<div v-for="(item, i) in knowledges" :key="i" class="line">
<el-checkbox v-model="item.check" :disabled="item.disabled"
@change="val => knowledgeChange(val, item)"></el-checkbox>
<span class="serial">{{ i + 1 }}</span>
<p class="stem" :title="item.name">{{ item.name }}</p>
</div>
</div>
</template>
<div v-else class="empty">
<img class="icon" src="@/assets/images/empty.svg" alt="">
<p>暂无数据</p>
</div>
</div>
<!-- 已选知识点 -->
<div class="item">
<div class="flex j-between a-center m-b-20">
<p class="total m-b-10">已选知识点{{ allKnowledges.length }}</p>
<p class="clear" @click="clearChecked">
<i class="el-icon-delete m-r-5"></i>
清空
</p>
</div>
<template v-for="(item, i) in checked">
<div :key="i" class="j-between m-b-10">
<div class="flex a-center">
题库{{ item.quesBank.questionBankName }}
<i class="el-icon-delete action-icon m-l-10" @click="delQuesBank(i)"></i>
</div>
<div class="knowledges">
<el-tag v-for="(tag, j) in item.knowledges" :key="tag.name" class="m-r-8 m-b-8" closable
@close="delKnowledge(i, j, item, tag)">{{ tag.name }}</el-tag>
</div>
</div>
</template>
</div>
</div>
<h6 class="page-name m-t-20">年份设置</h6>
<div class="years flex">
<el-checkbox style="margin-right: 20px" v-model="yearAll" @change="yearAllChange">全选</el-checkbox>
<el-checkbox-group v-model="yearCheck" @change="yearChange">
<el-checkbox v-for="(item, i) in years" :key="i" :label="item"></el-checkbox>
</el-checkbox-group>
</div>
</div>
<div class="btns">
<el-button @click="quesVisible = false">取消</el-button>
<el-button type="primary" :loading="submiting" @click="submit">自动选题</el-button>
</div>
</el-drawer>
</div>
</template>
<script>
import Setting from '@/setting'
import Util from '@/libs/util'
import QuesConst from '@/const/ques'
import TestPaperConst from '@/const/testPaper'
import _ from 'lodash'
import Decimal from 'decimal.js'
export default {
props: ['visible'],
data () {
return {
arabicToChinese: Util.arabicToChinese,
difficults: TestPaperConst.difficults,
questionTypes: QuesConst.questionTypes,
quesVisible: false,
difficult: '',
searchTimer: null,
curQuesBank: {},
quesBankTypeVal: [],
quesBankTypes: [],
quesBankKeyword: '',
quesBanks: [],
pageQuesBank: 1,
pageSizeQuesBank: 10,
totalQuesBank: 0,
knowledgeKeyword: '',
knowledgeTypeVal: [],
knowledgeTypes: [],
knowledgeCheck: false,
knowledges: [],
pageKn: 1,
pageSizeKn: 10,
totalKn: 0,
checkedKeyword: '',
checked: [],
list: [],
years: ['暂无年份', '2024', '2023', '2022', '2021', '2020', '2019', '2018', '2017', '2016', '更早'],
yearAll: true,
yearCheck: [],
submiting: false,
loaded: 0,
};
},
computed: {
allKnowledges () {
const result = []
this.checked.map(e => {
result.push(...e.knowledges)
})
return result
},
},
watch: {
'quesBankKeyword': function (val) {
clearTimeout(this.searchTimer)
this.searchTimer = setTimeout(this.initQuesBank, 500)
},
'knowledgeKeyword': function (val) {
clearTimeout(this.searchTimer)
this.searchTimer = setTimeout(this.getKnowledge, 500)
},
visible () {
this.quesVisible = this.visible
this.visible && this.init()
}
},
mounted () {
},
methods: {
//
init () {
this.handleQuesList()
if (!this.loaded) {
this.loaded = 1
this.yearCheck = this.years
this.getQuesBankType()
this.initQuesBank()
this.difficult = this.$parent.form.difficult
this.difficult && this.difficultChange(this.difficult)
}
},
//
async getQuesBankType () {
try {
const { data } = await this.$post(this.api.getAllQuestionBankCategories, {
createSource: 1,
status: 1,
})
this.handleList(data)
this.quesBankTypes = data
} catch (e) { }
},
//
async getQuesBank () {
try {
const type = this.quesBankTypeVal
const res = await this.$post(this.api.questionBankList, {
status: 1,
pageNum: 1,
pageSize: 1000,
questionCategoryId: type.length ? type[type.length - 1] : '',
name: this.quesBankKeyword
})
this.quesBanks = res.message.records
this.totalQuesBank = res.message.total
} catch (e) { }
},
initQuesBank () {
this.curQuesBank = {}
this.pageQuesBank = 1
this.getQuesBank()
},
//
currentChangeQuesBank (val) {
this.pageQuesBank = val
this.getQuesBank()
},
//
questionBankClick (item) {
this.curQuesBank = item
this.knowledgeCheck = false
this.getKnowledgeType()
this.getKnowledge()
},
//
handleList (list) {
list.map(e => {
if (e.children && e.children.length) {
this.handleList(e.children)
} else {
delete e.children
}
})
},
//
async getKnowledgeType () {
try {
const { data } = await this.$post(this.api.classificationTreeStructure, {
createSource: 1,
questionBankId: this.curQuesBank.id,
})
this.handleList(data)
this.knowledgeTypes = data
} catch (e) { }
},
//
async getKnowledge () {
try {
const { id } = this.curQuesBank
if (id) {
const type = this.knowledgeTypeVal
const res = await this.$post(this.api.knowledgeHierarchyList, {
pageNum: 1,
pageSize: 1000,
questionBankId: id,
knowledgePointCategoryId: type.length ? type[type.length - 1] : '',
name: this.knowledgeKeyword,
})
const list = res.message.records
const { allKnowledges } = this
list.map(e => {
e.check = !!allKnowledges.find(n => n.id === e.id)
})
this.knowledges = list
}
} catch (e) { }
},
//
currentChangeKn (val) {
this.pageKn = val
this.getKnowledge()
},
//
knowledgeAllCheckChange (val) {
this.knowledges.map(e => {
e.check = val
this.knowledgeChange(val, e)
})
},
//
knowledgeChange (checked, data) {
const checkQues = this.curQuesBank
const index = this.checked.findIndex(e => e.quesBank.id === checkQues.id)
//
if (index !== -1) {
const ques = this.checked[index]
const i = ques.knowledges.findIndex(e => e.id === data.id)
if (checked && i === -1) {
ques.knowledges.push(data)
} else if (!checked && i >= 0) {
ques.knowledges.splice(i, 1)
}
ques.knowledges.length || this.checked.splice(index, 1)
} else {
this.checked.push({
quesBank: checkQues,
knowledges: [data]
})
}
},
//
handleQuesList () {
this.list = _.cloneDeep(this.$parent.form.paperOutline)
},
//
async clearChecked () {
try {
await this.$confirm(`确认要清空吗?`, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
closeOnClickModal: false,
})
this.knowledges.map(e => e.check = false)
this.checked = []
this.knowledgeCheck = false
} catch (e) { }
},
//
async delQuesBank (i) {
try {
await this.$confirm(`确认要移除吗?`, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
closeOnClickModal: false,
})
const k = this.knowledges
this.checked[i].knowledges.map(e => {
const cur = k.findIndex(n => n.id === e.id)
if (cur !== -1) k[cur].check = false
})
this.checked.splice(i, 1)
this.knowledgeCheck = false
} catch (e) { }
},
//
delKnowledge (i, j, item, k) {
const cur = this.knowledges.findIndex(e => e.id === k.id)
if (cur !== -1) this.knowledges[cur].check = false
item.knowledges.splice(j, 1)
item.knowledges.length || this.checked.splice(i, 1) //
this.knowledgeCheck = false
},
//
difficultChange (val) {
const difficultyWeights = [0.2, 0.4, 0.6, 0.8]
const names = ['basicDifficulty', 'normalDifficulty', 'hardDifficulty', 'veryHardDifficulty']
//
this.list.forEach(e => {
const total = e.questionNum
let already = 0 //
if (val === 1) {
this.$set(e, 'basicDifficulty', Math.floor(total * 0.7))
this.$set(e, 'normalDifficulty', Math.floor(total * 0.3))
this.$set(e, 'hardDifficulty', 0)
this.$set(e, 'veryHardDifficulty', 0)
} else if (val === 2) {
this.$set(e, 'basicDifficulty', Math.floor(total * 0.45))
this.$set(e, 'normalDifficulty', Math.floor(total * 0.55))
this.$set(e, 'hardDifficulty', 0)
this.$set(e, 'veryHardDifficulty', 0)
} else if (val === 3) {
this.$set(e, 'basicDifficulty', Math.floor(total * 0.3))
this.$set(e, 'normalDifficulty', Math.floor(total * 0.3))
this.$set(e, 'hardDifficulty', Math.floor(total * 0.4))
this.$set(e, 'veryHardDifficulty', 0)
} else if (val === 4) {
this.$set(e, 'basicDifficulty', Math.floor(total * 0.1))
this.$set(e, 'normalDifficulty', Math.floor(total * 0.1))
this.$set(e, 'hardDifficulty', Math.floor(total * 0.3))
this.$set(e, 'veryHardDifficulty', Math.floor(total * 0.5))
}
already = Decimal(already).add(e.basicDifficulty).add(e.normalDifficulty).add(e.hardDifficulty).add(e.veryHardDifficulty).toNumber()
//
while (total > already) {
e[names[val - 1]]++
already++
}
this.$set(e, 'randomDifficulty', 0)
})
},
//
yearAllChange (val) {
this.yearCheck = val ? this.years : []
},
//
yearChange (val) {
this.yearAll = val.length === 11
},
//
async submit () {
if (this.submiting) return false
const { list } = this
let invalid = 0
let totalCount = 0
for (const i in list) {
const e = list[i]
const name = `${Util.arabicToChinese(+i + 1)}大题`
if (!e.questionType) {
Util.warningMsg(`${name}请先选择题型`)
invalid = 1
break
}
if (!e.questionNum || isNaN(e.questionNum) || e.questionNum <= 0) {
Util.warningMsg(`${name}的目标题数请输入正整数`)
invalid = 1
break
}
let total = Decimal(e.basicDifficulty || 0).add(e.normalDifficulty || 0).add(e.hardDifficulty || 0).add(e.veryHardDifficulty || 0).toNumber() // 4
if (total) { // 41
this.$set(e, 'randomDifficulty', 0)
} else {
total = +e.randomDifficulty || 0
}
if (total > e.questionNum) {
Util.warningMsg(`${name}的小题总数大于目标题数,请重新输入`)
invalid = 1
break
}
e.count = total
totalCount = Decimal(totalCount).add(total).toNumber()
}
if (invalid) return false
if (!totalCount) return Util.warningMsg(`请填写难度题数`)
this.submiting = true
const k = this.allKnowledges.map(e => e.id)
const years = []
this.yearCheck.map(e => {
if (e === '暂无年份') {
years.push('')
} else if (e === '更早') {
// 1990~2005
for (let i = 1990; i < 2006; i++) {
years.push(i)
}
} else {
years.push(+e)
}
})
list.map(e => {
e.givenYears = years
e.knowledgePointsIds = k
})
try {
const res = await this.$post(this.api.selectQuestionsByTypeAndDifficulty, list)
let invalid = 0
let hasQues = 0
list.map((e, i) => {
if (+e.count !== res.list[i].questions.length) invalid = 1
if (e.examQuestions.length) hasQues = 1
e.score = 0
})
// 3
const tips = invalid && hasQues ?
'此操作会清空当前试卷已添加的试题,并且满足自动选题设置的试题数量不足,确定要继续自动选题吗?' :
invalid && !hasQues ?
'满足自动选题设置的试题数量不足,确认要继续自动选题吗?' :
!invalid && hasQues ? '此操作会清空当前试卷已添加的试题,是否确定要继续自动选题吗?' :
''
if (tips) {
await this.$confirm(tips, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
closeOnClickModal: false,
})
}
list.map((e, i) => {
res.list[i].questions.map((e, i) => {
e.questionId = e.id
e.serialNumber = i + 1
e.originSort = i + 1
this.$parent.handleQuesInfo(e)
})
this.$parent.form.paperOutline[i].examQuestions = res.list[i].questions
})
this.quesVisible = false
this.$parent.calcDifficult()
this.submiting = false
} catch (e) {
this.submiting = false
}
},
//
closeDia () {
this.$emit('update:visible', false)
}
}
};
</script>
<style lang="scss" scoped>
/deep/.ques-dia {
.el-drawer__header {
margin-bottom: 20px;
}
.overflow {
height: calc(100vh - 147px);
padding: 0 20px;
overflow: auto;
}
.wrap {
display: flex;
margin-top: 20px;
border: 1px solid #eee;
.filter {
margin-bottom: 15px;
li {
display: flex;
align-items: center;
}
label {
margin-right: 10px;
font-size: 14px;
color: #333;
white-space: nowrap;
}
}
.item {
width: 30%;
padding: 15px;
border-right: 1px solid #eee;
&:last-child {
width: 40%;
border-right: 0;
}
}
.total {
font-size: 16px;
color: #333;
}
.clear {
display: inline-flex;
align-items: center;
font-size: 14px;
color: #8b8b8b;
cursor: pointer;
}
.knowledges {
padding-left: 44px;
margin-top: 10px;
}
.lines {
height: calc(100vh - 392px);
overflow: auto;
}
.line {
display: flex;
padding: 5px 0;
color: #333;
}
.able-check {
.line {
cursor: pointer;
&:hover {
background-color: #f5f5f5;
}
&.active {
background-color: #e5e5e5;
}
}
}
.serial {
width: 32px;
margin: 0 12px;
text-align: center;
white-space: nowrap;
&.first {
margin-left: 0;
}
}
.stem {
max-width: calc(100% - 71px);
@include ellipsis;
}
.checked-stem {
max-width: 165px;
@include ellipsis;
}
.check-left {
display: inline-flex;
align-items: center;
}
.action-icon {
font-size: 14px;
}
}
}
</style>

@ -150,6 +150,7 @@
</div> </div>
<Ques :visible.sync="quesVisible" /> <Ques :visible.sync="quesVisible" />
<TopicType :visible.sync="typeVisible" />
</div> </div>
</template> </template>
<script> <script>
@ -157,6 +158,7 @@ import Draggable from 'vuedraggable'
import UeditorPlus from '@/components/ueditorPlus' import UeditorPlus from '@/components/ueditorPlus'
import Breadcrumb from '@/components/breadcrumb' import Breadcrumb from '@/components/breadcrumb'
import Ques from './ques.vue' import Ques from './ques.vue'
import TopicType from './topicType.vue'
import Setting from '@/setting' import Setting from '@/setting'
import Util from '@/libs/util' import Util from '@/libs/util'
import dayjs from 'dayjs' import dayjs from 'dayjs'
@ -166,7 +168,7 @@ import Decimal from 'decimal.js'
import _ from 'lodash' import _ from 'lodash'
export default { export default {
components: { UeditorPlus, Breadcrumb, Draggable, Ques }, components: { UeditorPlus, Breadcrumb, Draggable, Ques, TopicType },
data () { data () {
return { return {
crumbs: [], crumbs: [],
@ -189,6 +191,7 @@ export default {
pull: false, pull: false,
}, },
classifications: [], classifications: [],
typeVisible: false,
multipleSelection: [], multipleSelection: [],
form: { form: {
classificationId: +this.$route.query.classificationId || '', classificationId: +this.$route.query.classificationId || '',
@ -258,32 +261,6 @@ export default {
submiting: false, submiting: false,
}; };
}, },
computed: {
//
overview () {
const paper = this.form.paperOutline
let questionCount = 0
let alreadyQuesCount = 0
let totalScore = 0
let alreadyScore = 0
paper.forEach(e => {
if (!isNaN(e.questionNum)) questionCount += +e.questionNum //
if (e.examQuestions) {
alreadyQuesCount += e.examQuestions.length //
if (!isNaN(e.targetScore)) totalScore = Decimal(totalScore).add(+e.targetScore || 0).toNumber() //
e.examQuestions.forEach(n => {
if (!isNaN(n.score)) alreadyScore = Decimal(alreadyScore).add(+n.score || 0).toNumber() //
})
}
})
return {
questionCount,
alreadyQuesCount,
totalScore,
alreadyScore,
}
},
},
mounted () { mounted () {
const { referrer2 } = this.$store.state.user const { referrer2 } = this.$store.state.user
this.crumbs = [ this.crumbs = [
@ -357,73 +334,7 @@ export default {
}, },
// //
setClass () { setClass () {
this.classVisible = true this.typeVisible = true
},
//
addClass () {
this.classifications.push({
edit: true,
id: '',
classificationName: ''
})
},
//
editClass (row) {
this.$set(row, 'edit', 1)
},
//
delClass (row, i) {
if (row.id) {
this.$confirm('确定要删除吗?', '提示', {
type: 'warning'
}).then(() => {
this.$post(this.api.delClassif, Util.rsa(row.id)).then(res => {
Util.successMsg('删除成功')
this.getClassification()
}).catch(res => { })
}).catch(() => { })
} else {
this.classifications.splice(i, 1)
}
},
//
submitClass (row, showMsg = 1) {
if (!row.classificationName) return Util.errorMsg('请输入分类名称')
this.$post(this.api.checkClassif, Util.rsa({
classificationName: encodeURI(row.classificationName),
siteId: this.site.id,
classificationId: row.id
})).then(res => {
this.$post(this.api[row.id ? 'updateClassif' : 'saveClassif'], Util.rsa({
classificationName: encodeURI(row.classificationName),
templateId: this.columnInfo.templateId,
id: row.id,
siteId: this.site.id,
editorId: this.userId,
founderId: this.userId
})).then(res => {
showMsg && Util.successMsg((row.id ? '修改' : '新增') + '成功')
this.getClassification()
}).catch(res => { })
}).catch(res => { })
},
//
closeClass () {
const list = this.classifications
if (list.find(e => e.edit && e.classificationName)) {
this.$confirm('所填写内容暂未保存,是否保存?', '提示', {
type: 'warning'
}).then(() => {
list.map(e => {
e.edit && e.classificationName && this.submitClass(e, 0)
})
this.classVisible = false
}).catch(() => {
this.classVisible = false
})
} else {
this.classVisible = false
}
}, },

@ -0,0 +1,133 @@
<template>
<div>
<el-dialog title="课题类型设置" :visible.sync="classVisible" width="500px" :close-on-click-modal="false"
class="manage-dia" :before-close="closeClass">
<div class="m-b-10 text-right">
<i class="el-icon-circle-plus-outline action-icon" @click="addClass"></i>
</div>
<el-table :data="classifications" ref="table" header-align="center" row-key="id">
<el-table-column type="index" width="60" label="序号" align="center"></el-table-column>
<el-table-column prop="classificationName" label="课题类型名称" align="center" min-width="130">
<template slot-scope="scope">
<el-input v-if="scope.row.edit" placeholder="请输入课题类型名称" v-model="scope.row.classificationName" clearable
maxlength="30"></el-input>
<span v-else>{{ scope.row.classificationName }}</span>
</template>
</el-table-column>
<el-table-column prop="updateTime1" label="是否引用" align="center" min-width="60"></el-table-column>
<el-table-column label="操作" align="center" min-width="60">
<template slot-scope="scope">
<i v-if="scope.row.edit" class="el-icon-check edit" @click="submitClass(scope.row)"></i>
<i v-else class="el-icon-edit action-icon" @click="editClass(scope.row)"></i>
<i class="el-icon-delete action-icon" @click="delClass(scope.row, scope.$index)"></i>
</template>
</el-table-column>
</el-table>
<span slot="footer">
<el-button @click="closeClass">返回</el-button>
</span>
</el-dialog>
</div>
</template>
<script>
import Setting from '@/setting'
import Util from '@/libs/util'
import _ from 'lodash'
import Decimal from 'decimal.js'
export default {
props: ['visible', 'list'],
data () {
return {
classVisible: false,
classifications: [],
submiting: false,
};
},
watch: {
visible () {
this.classVisible = this.visible
this.visible && this.init()
}
},
mounted () {
},
methods: {
init () {
this.classifications = _.cloneDeep(this.list)
},
//
addClass () {
this.classifications.push({
edit: true,
id: '',
classificationName: ''
})
},
//
editClass (row) {
this.$set(row, 'edit', 1)
},
//
delClass (row, i) {
if (row.id) {
this.$confirm('确定要删除吗?', '提示', {
type: 'warning'
}).then(() => {
this.$post(this.api.delClassif, Util.rsa(row.id)).then(res => {
Util.successMsg('删除成功')
this.getClassification()
}).catch(res => { })
}).catch(() => { })
} else {
this.classifications.splice(i, 1)
}
},
//
submitClass (row, showMsg = 1) {
if (!row.classificationName) return Util.errorMsg('请输入分类名称')
this.$post(this.api.checkClassif, Util.rsa({
classificationName: encodeURI(row.classificationName),
siteId: this.site.id,
classificationId: row.id
})).then(res => {
this.$post(this.api[row.id ? 'updateClassif' : 'saveClassif'], Util.rsa({
classificationName: encodeURI(row.classificationName),
templateId: this.columnInfo.templateId,
id: row.id,
siteId: this.site.id,
editorId: this.userId,
founderId: this.userId
})).then(res => {
showMsg && Util.successMsg((row.id ? '修改' : '新增') + '成功')
this.getClassification()
}).catch(res => { })
}).catch(res => { })
},
//
closeClass () {
const list = this.classifications
if (list.find(e => e.edit && e.classificationName)) {
this.$confirm('所填写内容暂未保存,是否保存?', '提示', {
type: 'warning'
}).then(() => {
list.map(e => {
e.edit && e.classificationName && this.submitClass(e, 0)
})
this.classVisible = false
}).catch(() => {
this.classVisible = false
})
} else {
this.classVisible = false
}
},
//
closeDia () {
this.$emit('update:visible', false)
}
}
};
</script>
<style lang="scss" scoped></style>
Loading…
Cancel
Save