Blame view

pages/apply/reportLog/form.vue 3.3 KB
290144e9   易尊强   第一次
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
  <template>
  	<view class="logForm-v ncc-wrap">
  		<u-form :model="dataForm" :rules="rules" ref="dataForm" :errorType="['toast']" label-position="left"
  			label-width="150" label-align="left">
  			<u-form-item label="日志标题" prop="title" required>
  				<u-input v-model="dataForm.title" placeholder="请输入日志标题" :disabled="disabled"></u-input>
  			</u-form-item>
  			<u-form-item label="今日内容" prop="todayContent" required>
  				<u-input v-model="dataForm.todayContent" type="textarea" placeholder="请输入今日内容" :disabled="disabled" />
  			</u-form-item>
  			<u-form-item label="明日内容" prop="tomorrowContent" required>
  				<u-input v-model="dataForm.tomorrowContent" type="textarea" placeholder="请输入明日内容"
  					:disabled="disabled" />
  			</u-form-item>
  			<u-form-item label="遇到问题" prop="question" required>
  				<u-input v-model="dataForm.question" type="textarea" placeholder="请输入遇到问题" :disabled="disabled" />
  			</u-form-item>
  			<u-form-item label="发送给谁" prop="userIds" required>
  				<ncc-org-select v-model="dataForm.userIds" multiple :disabled="disabled"></ncc-org-select>
  			</u-form-item>
  		</u-form>
  		<view class="com-saveBox" v-if="!disabled">
  			<u-button type="primary" @click="save">保存</u-button>
  		</view>
  	</view>
  </template>
  
  <script>
  	import {
  		getLogInfo,
  		createLog,
  		updateLog
  	} from '@/api/apply/reportLog.js'
  	export default {
  		data() {
  			return {
  				dataForm: {
  					title: '',
  					todayContent: '',
  					tomorrowContent: '',
  					question: '',
  					userIds: ''
  				},
  				rules: {
  					title: [{
  						required: true,
  						message: '日志标题不能为空',
  						trigger: 'blur'
  					}],
  					todayContent: [{
  						required: true,
  						message: '今日内容不能为空',
  						trigger: 'blur'
  					}],
  					tomorrowContent: [{
  						required: true,
  						message: '明日内容不能为空',
  						trigger: 'blur'
  					}],
  					question: [{
  						required: true,
  						message: '问题不能为空',
  						trigger: 'blur'
  					}],
  					userIds: [{
  						required: true,
  						message: '用户不能为空',
  						trigger: 'blur'
  					}],
  				},
  				type: '0',
  				disabled: false
  			}
  		},
  		onReady() {
  			this.$refs.dataForm.setRules(this.rules);
  		},
  		onLoad(option) {
  			this.type = option.type
  			if (!option.id) {
  				uni.setNavigationBarTitle({
  					title: '新增日志'
  				});
  				let userInfo = uni.getStorageSync('userInfo') || {}
  				if (!userInfo.userName) return
  				this.dataForm.title = userInfo.userName + '的日志'
  			} else {
  				if (this.type == '1') this.disabled = true
  				getLogInfo(option.id).then(res => {
  					this.dataForm = res.data;
  					uni.setNavigationBarTitle({
  						title: this.dataForm.title
  					});
  				})
  			}
  		},
  		methods: {
  			save() {
  				this.$refs.dataForm.validate((valid) => {
  					this.dataForm.toUserId = this.dataForm.userIds
  					if (valid) {
  						const method = this.dataForm.id ? updateLog : createLog
  						method(this.dataForm).then(res => {
  							uni.showToast({
  								title: res.msg,
  								complete: () => {
  									setTimeout(() => {
  										uni.$emit('refresh')
  										uni.navigateBack()
  									}, 1500)
  								}
  							})
  						})
  					}
  				})
  			}
  		}
  	}
  </script>
  <style lang="scss">
  	page {
  		background-color: #f0f2f6;
  	}
  
  	.logForm-v {
  		padding-bottom: 140rpx;
  	}
  </style>