提交 93c1af38 authored 作者: 王诒正's avatar 王诒正

添加用户群、用户群特征、用户群特征列表、删除用户群特征、删除用户群

上级 38d5df16
......@@ -21,6 +21,6 @@ export function groupUpdate(id, data) {
}
// 删除用户群
export function groupDelete(id, params) {
return httpRequest.put(`/api/opera/v1/oprations/${id}/cgroup`, { params })
export function groupDelete(id, params = {}) {
return httpRequest.delete(`/api/opera/v1/oprations/${id}/cgroup`, { params })
}
import httpRequest from '@/utils/axios'
// 批量创建用户群特征
export function characteristicsCreateBatch(data) {
var headers = {
'Content-Type': 'application/json'
}
return httpRequest.post('/api/opera/v1/oprations/characteristics', data, { headers })
}
// 删除用户群特征
export function characteristicsDelete(id, params = {}) {
var headers = {
'Content-Type': 'application/json'
}
return httpRequest.delete(`/api/opera/v1/oprations/${id}/characteristic`, { params }, { headers })
}
// 群特征列表
export function characteristicsList(params) {
var headers = {
'Content-Type': 'application/json'
}
return httpRequest.get('/api/opera/v1/oprations/characteristics', { params }, { headers })
}
......@@ -21,10 +21,10 @@
<div>
<el-form size="mini" :model="groupForm" :rules="groupRules"
ref="groupForm" label-width="130px" class="groupForm">
<el-form-item label="用户群名称" prop="name">
<el-form-item label="用户群名称" prop="name" :disabled="groupNameDisabled">
<el-input v-model="groupForm.name"></el-input>
</el-form-item>
<el-form-item label="用户群图片" prop="poster_url">
<el-form-item label="用户群图片" prop="poster_url" :disabled="groupPosterUrlDisabled">
<el-upload
action="/api/opera/v1/file/upload"
list-type="picture-card"
......@@ -59,6 +59,35 @@
<div>
<el-button size="mini" type="success" @click="dialogFormVisible = true">添加</el-button>
</div>
<div>
<el-table :data="tableData" style="width: 100%">
<el-table-column label="创建时间">
<template slot-scope="scope">
<i class="el-icon-time"></i>
<span style="margin-left: 10px">{{ scope.row.created_at }}</span>
</template>
</el-table-column>
<el-table-column label="特征名称">
<template slot-scope="scope">
<span>{{ scope.row.name }}</span>
</template>
</el-table-column>
<el-table-column label="特征选项">
<template slot-scope="scope">
<div v-for="(item, index) in JSON.parse(scope.row.context)" :key="index">
<el-tag :type="item.answer ? 'wanning' : 'info'">
<p>{{ item.options}}{{ item.options_info }}</p><br/>
</el-tag>
</div>
</template>
</el-table-column>
<el-table-column label="操作">
<template slot-scope="scope">
<el-button type="danger" icon="el-icon-delete" circle @click="deletecharaCteristics(scope.row.id)"></el-button>
</template>
</el-table-column>
</el-table>
</div>
</el-card>
</div>
<div>
......@@ -90,6 +119,7 @@
<script>
import * as templateApi from '@/api/characteristics-template'
import * as groupApi from '@/api/cgroups'
import * as characteristicsApi from '@/api/characteristic'
export default {
name: 'add',
mounted() {
......@@ -108,6 +138,8 @@ export default {
},
data () {
return {
groupNameDisabled: false,
groupPosterUrlDisabled: false,
visible: false,
dialogFormVisible: false,
characteristicTemplateList: [],
......@@ -137,7 +169,8 @@ export default {
options: [
{ required: true, message: '请勾选特征选项', trigger: 'blur' }
]
}
},
tableData: []
}
},
methods: {
......@@ -172,13 +205,15 @@ export default {
this.group = res.data
this.$message.success('创建用户群成功')
this.groupHidden = true
this.groupNameDisabled = true
this.groupPosterUrlDisabled = true
return true
} else {
this.$message.error(res.message)
return false
}
}).catch(error => {
console.log(error)
console.log('创建用户群失败')
this.$message.error(error)
return false
})
......@@ -198,7 +233,6 @@ export default {
var contextInfo = this.form.context
var addDataContext = []
for (var index in contextInfo) {
console.log(1232, contextInfo[index].options)
var addOptions = contextInfo[index].options
var addOptionsinfo = contextInfo[index].options_info
var answer = 0
......@@ -212,11 +246,25 @@ export default {
}
}
addData.context = addDataContext
var sendData = [addData]
console.log(addData)
templateApi.characteristicsTemplateCreate({ data: sendData }).then(res => {
var sendData = {
data: [addData]
}
characteristicsApi.characteristicsCreateBatch(sendData).then(res => {
if (res.code === 0) {
this.$message.success('创建成功')
this.dialogFormVisible = false
characteristicsApi.characteristicsList({ cgroup_id: this.group.id }).then(res => {
if (res.code === 0) {
this.tableData = res.data
return true
} else {
this.$message.error(res.message)
return false
}
}).catch(error => {
console.log(error)
return false
})
return true
} else {
this.$message.error(res.message)
......@@ -240,6 +288,36 @@ export default {
} else {
this.form.context = []
}
},
// 删除特征
deletecharaCteristics(id) {
this.$confirm('确认删除?', '提示')
.then(_ => {
characteristicsApi.characteristicsDelete(id).then(res => {
if (res.code === 0) {
this.$message.success('删除成功')
characteristicsApi.characteristicsList({ cgroup_id: this.group.id }).then(res => {
if (res.code === 0) {
this.tableData = res.data
return true
} else {
this.$message.error(res.message)
return false
}
}).catch(error => {
console.log(error)
return false
})
}
}).catch(error => {
console.log(error)
return false
})
return true
})
.catch(_ => {
return false
})
}
}
}
......
......@@ -54,24 +54,7 @@
<template slot-scope="scope">
<div v-if="scope.row.characteristics.length === 0"><span>无用户群相关特征...</span></div>
<div v-else>
<el-button type="text" @click="dialogVisible = true">点击查看用户群特征</el-button>
<div class="dialog-box" v-if="dialogVisible">
<el-dialog :title="scope.row.name" :visible.sync="dialogVisible" :modal="false">
<div class="scroll-content">
<i v-for="(characteristic, index) in scope.row.characteristics" :key="index">
<div v-if="characteristic.context" class="scroll-container">
{{ characteristic.name + ':'}}
<span v-for="(contextInfo, index) in JSON.parse(characteristic.context)" :key="index"><br/>{{contextInfo.options + '、' + contextInfo.options_info +'. '}}</span>
<br/>
</div>
</i>
</div>
<div slot="footer" class="dialog-footer">
<el-button @click="dialogVisible = false">取 消</el-button>
<el-button type="primary" @click="dialogVisible = false">确 定</el-button>
</div>
</el-dialog>
</div>
<el-button type="text" @click="showInfo(scope.row)">点击查看用户群特征</el-button>
</div>
</template>
</el-table-column>
......@@ -87,13 +70,30 @@
fixed="right"
label="操作">
<template slot-scope="scope">
<el-button size="mini" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
<el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
<el-button type="primary" icon="el-icon-edit" size="mini" @click="handleEdit(scope.$index, scope.row)"></el-button>
<el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDelete(scope.$index, scope.row)"></el-button>
</template>
</el-table-column>
</el-table>
</el-card>
</div>
<div class="dialog-box" v-if="dialogVisible">
<el-dialog :title="characteristicsInfo.name" :visible.sync="dialogVisible" :modal="false">
<div class="scroll-content">
<i v-for="(characteristic, index) in characteristicsInfo.characteristics" :key="index">
<div v-if="characteristic.context" class="scroll-container">
{{ characteristic.name + ':'}}
<span v-for="(contextInfo, index) in JSON.parse(characteristic.context)" :key="index"><br/>{{contextInfo.options + '、' + contextInfo.options_info +'. '}}</span>
<br/>
</div>
</i>
</div>
<div slot="footer" class="dialog-footer">
<el-button @click="dialogVisible = false">取 消</el-button>
<el-button type="primary" @click="dialogVisible = false">确 定</el-button>
</div>
</el-dialog>
</div>
</div>
</template>
......@@ -121,7 +121,8 @@ export default {
data () {
return {
dialogVisible: false,
tableData: []
tableData: [],
characteristicsInfo: {}
}
},
methods: {
......@@ -130,7 +131,40 @@ export default {
},
// 删除
handleDelete(index, group) {
this.$confirm('确认删除?', '提示').then(_ => {
api.groupDelete(group.id).then(res => {
if (res.code === 0) {
this.$message.success('删除成功')
api.groupList({ case_id: this.$route.params.id }).then(res => {
if (res.code === 0) {
console.log(res.data)
this.tableData = res.data
return true
} else {
this.$message.error(res.message)
return false
}
}).catch(error => {
console.log(error)
return false
})
return true
} else {
this.$message.error(res.message)
return false
}
}).catch(error => {
console.log(error)
this.$message.error('删除失败')
return false
})
}).catch(_ => {
return false
})
},
showInfo(row) {
this.dialogVisible = true
this.characteristicsInfo = row
}
}
}
......
......@@ -29,7 +29,7 @@ httpRequest.interceptors.request.use(
httpRequest.interceptors.response.use(
function(response) {
const { data } = response
if (data.code) {
if (data.code !== 0 && data.code !== 1 && data.code !== -1) {
Message.error(data.msg)
return Promise.reject(data)
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论