Commit b30bae41 authored by Davve's avatar Davve

完善用户

parent 04d2faa9
......@@ -3,6 +3,7 @@
# __author__ = "chenwei"
# Date: 2018/11/15
import json
from utils.base import APIView
from utils.time_utils import generate_id
......@@ -34,7 +35,7 @@ class UserUpdateOrCreate(APIView):
def post(self, request):
id = request.POST.get('id', '')
user_id = request.POST.get('user_id', '')
tag_ids = list(set(request.POST.get('tag_ids').split(',')))
tag_ids = list(map(lambda x: x.split(":")[0], json.loads(request.POST.get('tags', '[]'))))
if not user_id:
user_id = generate_id()
data = {
......@@ -42,9 +43,9 @@ class UserUpdateOrCreate(APIView):
'is_recommend': request.POST.get('is_recommend'),
'profile_pic': request.POST.get('avatar')[:-2],
'nick_name': request.POST.get('nick_name'),
'tag_ids': list(filter(lambda x: x, tag_ids)),
'tag_ids': tag_ids,
'is_puppet': request.POST.get('is_puppet'),
'city_id': request.POST.get('city'),
'city_id': request.POST.get('city', '').split(":")[0],
'phone': request.POST.get('phone'),
'email': request.POST.get('email'),
'gender': request.POST.get('gender'),
......
......@@ -81,11 +81,11 @@
</el-col>
<el-col :span="12">
<el-form-item label-width="75px" label="城市:">
<el-select v-model="postForm.city" :remote-method="getRemoteCityList" filterable remote
<el-select v-model="city" :remote-method="getRemoteCityList" filterable remote clearable
value-key="id"
placeholder="搜索城市" style="width: 230px">
<el-option v-for="(item,index) in regionListOptions" :key="item+index" :label="item.name"
:value="item.id"/>
<el-option v-for="(item,index) in regionListOptions" :key="item+index" :label="item"
:value="item"/>
</el-select>
</el-form-item>
</el-col>
......@@ -93,11 +93,11 @@
<el-row>
<el-col :span="24">
<el-form-item label-width="75px" label="标签:">
<el-select v-model="postForm.tag_ids" :remote-method="getRemoteTagList" filterable remote
<el-select v-model="tags" :remote-method="getRemoteTagList" filterable remote clearable
multiple value-key="id"
placeholder="搜索地区" style="width: 720px">
<el-option v-for="(item,index) in tagListOptions" :key="item+index" :label="item.name"
:value="item.id"/>
<el-option v-for="(item,index) in tagListOptions" :key="item+index" :label="item"
:value="item"/>
</el-select>
</el-form-item>
</el-col>
......@@ -132,60 +132,6 @@
</div>
</el-card>
</el-row>
<!--<el-row :gutter="20" style="margin-top:50px;">-->
<!--<el-card class="box-card">-->
<!--<div slot="header" class="clearfix">-->
<!--<span>小组相关</span>-->
<!--</div>-->
<!--<div style="margin-bottom:50px;">-->
<!--<div class="filter-container">-->
<!--<el-select v-model="temp_group_ids" :remote-method="getRemoteGroupList" filterable remote-->
<!--value-key="id"-->
<!--placeholder="小组" style="width: 220px">-->
<!--<el-option v-for="(item,index) in groupListOptions" :key="item+index" :label="item.id + ':' + item.name" :value="item.id"/>-->
<!--</el-select>-->
<!--<el-button v-waves class="filter-item" type="primary" icon="el-icon-edit" @click="appendGroup">添加-->
<!--</el-button>-->
<!--</div>-->
<!--<el-table :data="list" border fit highlight-current-row style="width: 100%"-->
<!--ref="multipleTable">-->
<!--<el-table-column align="center" label="小组ID">-->
<!--<template slot-scope="scope">-->
<!--<span>{{ scope.row.id }}</span>-->
<!--</template>-->
<!--</el-table-column>-->
<!--<el-table-column align="center" label="小组名称">-->
<!--<template slot-scope="scope">-->
<!--<span>{{ scope.row.group_name }}</span>-->
<!--</template>-->
<!--</el-table-column>-->
<!--<el-table-column align="center" label="小组简介">-->
<!--<template slot-scope="scope">-->
<!--<span>{{ scope.row.group_desc }}</span>-->
<!--</template>-->
<!--</el-table-column>-->
<!--<el-table-column align="center" label="组长">-->
<!--<template slot-scope="scope">-->
<!--<span>{{ scope.row.nick_name }}</span>-->
<!--</template>-->
<!--</el-table-column>-->
<!--<el-table-column align="center" label="帖子数">-->
<!--<template slot-scope="scope">-->
<!--<span>{{ scope.row.topic_nums }}</span>-->
<!--</template>-->
<!--</el-table-column>-->
<!--<el-table-column align="center" label="组内身份">-->
<!--<template slot-scope="scope">-->
<!--<span>{{ scope.row.group_identify }}</span>-->
<!--</template>-->
<!--</el-table-column>-->
<!--</el-table>-->
<!--<pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit"-->
<!--style="margin-left: 250px;" @pagination="getList"/>-->
<!--</div>-->
<!--</el-card>-->
<!--</el-row>-->
</div>
</el-form>
......@@ -201,21 +147,8 @@
import Pagination from '@/components/Pagination'
import {validateURL} from '@/utils/validate'
import {UserDetail, fetchGroupUser, userCreate} from '@/api/user'
import { GroupDetail } from '@/api/group'
import { tagSearch, groupSearch, citySearch} from '@/api/remoteSearch'
import { isInArray, removeByvale} from "@/utils";
function Assembledata(target, source) {
var region_data = []
for (var i=0;i<target.length;i++){
if (isInArray(source, target[i]['name'])){
region_data.push(target[i]['id'])
removeByvale(source, target[i]['name']);
}
}
region_data.push(...source)
return region_data.join(',')
}
const defaultForm = {
status: 'draft',
......@@ -227,7 +160,8 @@
password: '',
avatar: '',
nick_name: '',
tag_ids: [],
tags: [],
is_puppet: 1,
city: '',
}
......@@ -257,39 +191,23 @@
return {
postForm: Object.assign({}, defaultForm),
loading: false,
group_ids: [],
groupListOptions: [],
city: '',
tags: [],
rules: {
image_uri: [{validator: validateRequire, trigger: 'blur'}],
title: [{validator: validateRequire}],
content: [{validator: validateRequire}],
},
tempRoute: {},
listQuery: {
page: 1,
limit: 10,
filter: {
},
},
GenderTypeOptions: [
{'key': 0, 'display_name': '男'},
{'key': 1, 'display_name': '女'},
],
regionListOptions: [],
tagListOptions: [],
temp_group_ids: '',
uploadType: 99,
list: [],
total: 0,
listLoading: true,
multipleSelection: [],
del_list: [],
temp: {
tags:[],
city_temp_id:'',
city_temp_name: '',
group_ids: []
}
}
},
computed: {
......@@ -301,7 +219,6 @@
if (this.isEdit) {
const id = this.$route.params && this.$route.params.id
this.fetchData(id)
this.getList()
} else {
this.postForm = Object.assign({}, defaultForm)
}
......@@ -311,15 +228,11 @@
fetchData(id) {
UserDetail(id).then(response => {
let rep = response.data.data
let temp_tags = []
this.postForm = response.data.data
this.temp.city_temp_id = response.data.data.city.id
this.postForm.city = this.temp.city_temp_name = response.data.data.city.name
this.city = response.data.data.city.id + ':' + response.data.data.city.name
for (let i = 0;i < rep.tag_list.length; i++){
temp_tags.push(rep.tag_list[i].name)
this.temp.tags.push(rep.tag_list[i])
this.tags.push(rep.tag_list[i].id + ':' + rep.tag_list[i].name)
}
this.postForm.tag_ids = temp_tags
}).catch(err => {
console.log(err)
......@@ -330,18 +243,9 @@
this.$refs.postForm.validate(valid => {
if (valid) {
this.loading = true
this.postForm.group_ids = JSON.stringify(this.temp.group_ids)
if (this.temp.city_temp_name === this.postForm.city){
this.postForm.city = this.temp.city_temp_id
}
if (this.isEdit){
this.postForm.tag_ids = Assembledata(this.temp.tags, this.postForm.tag_ids)
}else{
this.postForm.tag_ids = this.postForm.tag_ids.join(',')
}
this.postForm.city = this.city;
this.postForm.tags = JSON.stringify(this.tags)
userCreate(this.postForm).then(response => {
this.$notify({
title: '成功',
......@@ -371,30 +275,6 @@
}
})
},
appendGroup() {
if (isInArray(this.group_ids, this.temp_group_ids)){
this.$message({
message: '数据添加重复',
type: 'error'
})
return false;
}
GroupDetail(this.temp_group_ids).then(response => {
if (!response.data.data) return
console.log(response.data.data)
console.log(this.list)
this.list.push(response.data.data)
this.total = this.list.length
})
this.temp.group_ids.push(this.temp_group_ids)
this.temp_group_ids = ''
},
getRemoteGroupList(query) {
groupSearch(query).then(response => {
if (!response.data.data.data) return
this.groupListOptions = response.data.data.data
})
},
getRemoteCityList(query) {
citySearch(query).then(response => {
if (!response.data.data.data) return
......@@ -407,19 +287,6 @@
this.tagListOptions = response.data.data.data
})
},
getList() {
this.listLoading = true
this.listQuery.id = this.$route.params && this.$route.params.id
fetchGroupUser(this.listQuery).then(response => {
let rep = response.data.data.data
this.list = response.data.data.data
this.total = response.data.data.total
for (let i=0;i<rep.length;i++){
this.temp.group_ids.push(rep[i].id)
}
this.listLoading = false
})
},
}
}
</script>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment