postTalent.vue
3.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<template>
<view class="page">
<uni-section title="表单校验" type="line">
<view class="example">
<!-- 基础表单校验 -->
<uni-forms ref="valiForm" :rules="rules" :modelValue="valiFormData">
<uni-forms-item label="标题" required name="title">
<uni-easyinput v-model="valiFormData.title" placeholder="请输入标题" />
</uni-forms-item>
<uni-forms-item label="介绍标题" required name="subTitle">
<uni-easyinput v-model="valiFormData.subTitle" placeholder="请输入介绍标题" />
</uni-forms-item>
<uni-forms-item label="岗位名" required name="post">
<uni-easyinput v-model="valiFormData.post" placeholder="请输入岗位名" />
</uni-forms-item>
<uni-forms-item label="详细内容">
<uni-easyinput type="textarea" v-model="valiFormData.bodyContent" placeholder="请输入详细内容" />
</uni-forms-item>
</uni-forms>
<button type="primary" @click="submit('valiForm')">提交</button>
</view>
</uni-section>
</view>
</template>
<script>
export default {
data() {
return {
// 校验表单数据
valiFormData: {
title: '',
subTitle: '',
bodyContent: '',
post: '',
phone:''
},
creater: '',
rules: {
title: {
rules: [{
required: true,
errorMessage: '标题不能为空'
}]
},
post: {
rules: [{
required: true,
errorMessage: '标题不能为空'
}]
},
subTitle: {
rules: [{
required: true,
errorMessage: '介绍不能为空'
}]
}
},
}
},
onLoad() {
let userinfo = uni.getStorageSync('user')
this.creater = userinfo.userInfo.userId
},
methods: {
// 获取用户信息
getUser() {
if (uni.getStorageSync('user')) {
// this.userCode = uni.getStorageSync('user').data.user.userInfo
// this.userInfo = this.userCode.userAccount
// this.userInfo = '123456'
console.log('用户已登录!')
} else {
uni.showToast({
title: '请登录',
icon: 'none',
duration:1500
})
setTimeout(() => {
uni.reLaunch({
url: '/pages/login/index'
})
})
}
},
// 表单校验与提交
submit(ref) {
this.$refs[ref].validate().then(res => {
console.log('success', res);
uni.showToast({
title: `校验通过`
})
let query = {
title:this.valiFormData.title,
subTitle:this.valiFormData.subTitle,
bodyContent:this.valiFormData.bodyContent,
post:this.valiFormData.post,
creater:this.creater
}
console.log(query)
this.API.postTalent(query).then(res=>{
if(res.code === 200){
console.log(res)
uni.showToast({
icon:"success",
title:'发布成功'
}).then(()=>{
uni.navigateTo({
url:'/pages/talent/talent'
})
})
}
})
}).catch(err => {
console.log('err', err);
})
},
}
}
</script>
<style lang="scss" scoped>
.page {
width: 100%;
height: 100vh;
background-color: #f4f4f4;
}
.example {
padding: 15px;
background-color: #fff;
}
.segmented-control {
margin-bottom: 15px;
}
.button-group {
margin-top: 15px;
display: flex;
justify-content: space-around;
}
.form-item {
display: flex;
align-items: center;
}
.button {
display: flex;
align-items: center;
height: 35px;
margin-left: 10px;
}
</style>