cuiqian2004
8 天以前 2db331628bbf94deee446d6e172e98f4db474a33
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
<template>
    <view class="page-calendar-add">
        <view class="uni-panel-content items-center">
            <form class="calendar-form">
                <view class="uni-panel-body">
                    <view class="uni-panel-h">
                        <text class="uni-panel-calendar-name">名称:</text>
                        <view class="uni-panel-calendar-value">
                            <input class="input" :focus="formData.name" name="name" comfirm-type="done" type="text"
                                v-model="form.name" placeholder="请输入日历名称" />
                        </view>
                    </view>
                    <view class="uni-panel-h">
                        <text class="uni-panel-calendar-name">类型:</text>
                        <view class="uni-panel-calendar-value" @click="clickCalendarType">
                            <text class="uni-panel-text">{{typeArray[form.type]}}</text>
                            <view class="uni-picker-input">{{ '. . .'}}</view>
                        </view>
                    </view>
                    <view class="uni-panel-h">
                        <text class="uni-panel-calendar-name"></text>
                        <label class="uni-panel-calendar-value">
                            <switch :checked="form.isDefault" color="#007aff" style="transform:scale(0.8)"
                                @change="changeCalendarDefault" />缺省日历
                        </label>
                    </view>
                </view>
                <view class="button-clz">
                    <button class="uni-panel-button" @click="submitForm">提交</button>
                </view>
            </form>
 
        </view>
        <view class="uni-panel-safe-bottom" :style="{height:safeAreaBottom + 'px'}" />
    </view>
 
</template>
 
<script>
    import Session from "@/common/utils.js"
    import {
        create as calendarCreate,
    
    } from "@/api/gungho/calendar.js"
    
    import {
        showModal,
        showToast,
        showLoading,
        hideLoading
    } from "@/common/Page.js"
    export default {
        name: "pageCalendarAdd",
        data() {
            return {
                safeAreaBottom: getApp().globalData.safeAreaBottom,
                form: {
                    name: "",
                    type: 0,
                    isDefault: false,
                },
                formData: {
                    nameFocus: false,
                    typeFocus: false
                },
                typeArray: ['常规(上级可见)', '公开', '私密'],
            }
        },
        methods: {
            setData: function(obj) {
                let that = this;
                let keys = [];
                let val, data;
 
                Object.keys(obj).forEach(function(key) {
                    keys = key.split(".");
                    val = obj[key];
                    data = that.$data;
                    keys.forEach(function(key2, index) {
                        if (index + 1 == keys.length) {
                            that.$set(data, key2, val);
                        } else {
                            if (!data[key2]) {
                                that.$set(data, key2, {});
                            }
                        }
                        data = data[key2];
                    });
                });
            },
            clickCalendarType() {
                const _this = this
                uni.showActionSheet({
                    itemList: _this.typeArray,
                    success: function(res) {
                        let value = res.tapIndex;
                        if (value < 3 && value >= 0) {
                            _this.form.type = value
                        }
                    },
                    fail: function(res) {
                        console.log(res.errMsg);
                    }
                })
            },
            changeCalendarDefault(evt) {
                let checked = evt.detail.value;
                this.form.isDefault = checked
            },
            submitForm() {
                var _this = this
                let name = _this.form.name.trim()
                if (name.length < 1) {
                    _this.formData.nameFocus = true
                    showToast("日历名称不能为空!", "none")
                    uni.pageScrollTo({
                        scrollTop: 0
                    })
                    return
                }
                let year = new Date().getFullYear()
                showLoading("创建中,请稍后...")
                calendarCreate({
                    type: this.form.type,
                    isDefault: this.form.isDefault ? "1": "",
                    name
                }).then((res) => {
                    hideLoading()
                    showToast("新建日历成功", "success")
                    uni.$emit('calendarListChange')
                    uni.navigateBack()
                }).catch((rej) => {
                    hideLoading()
                    console.log("calendar-add calendarCreate failed", rej)
                    showModal(rej, "错误", false)
                })
            },
            showError(ex) {
                let tip = typeof ex == 'string' ? ex : typeof ex.err_msg == 'string' ? ex.err_msg : typeof ex.errMsg ==
                    'string' ? ex.errMsg : ""
                showModal(tip, "提示", false)
            },
        },
        onLoad(option) {
            // #ifdef MP-DINGTALK
        
            my.setNavigationBar({
                backgroundColor: "#007AFF",
                frontColor: "#ffffff"
            })
            // #endif
        }
    }
</script>
 
<style lang="scss" scoped>
    @import "../../common/css/button.scss";
 
    .page-calendar-add {
        display: flex;
        width: 750rpx;
        height: 100vh;
        flex-direction: column;
 
        .justify-center {
            justify-content: center;
        }
 
        .items-center {
            align-items: center
        }
 
 
 
        .uni-panel-content {
            display: flex;
            flex: 1;
            width: 750rpx;
        }
 
        .calendar-form {
            display: flex;
            width: 98%;
            flex: 1;
            padding: 4px 1% 8px;
            overflow: auto;
            flex-direction: column;
        }
 
        .uni-panel-h {
            display: flex;
            flex-direction: row !important;
            align-items: center !important;
            padding: 12px 10px 12px 12px;
            font-size: 14px;
        }
 
        .uni-panel-body {
            display: flex;
            flex-direction: column;
            margin: 8px 12px;
            padding: 4px 4px;
            border-radius: 8px;
        }
 
        .uni-panel-calendar-name {
            display: flex;
            margin: 0px 4px;
            width: 60px;
        }
 
        .uni-panel-calendar-value {
            flex: 1;
            display: flex;
            margin: 0px 4px;
        }
 
        .uni-panel-text {
            flex: 1;
            color: #000000;
            font-weight: normal;
            padding: 0 5px;
            line-height: 28px;
        }
 
        .uni-picker-input {
            height: 50rpx;
            padding: 0px 4px;
            line-height: 50rpx;
            font-size: 30rpx;
            background: #FFF;
            text-align: right;
            color: #007aff;
            flex: 1;
        }
 
        .button-clz {
            display: flex;
            justify-content: center;
            width: 100%;
            font-size: 17px !important;
            margin-top: 8px;
            margin-bottom: 8px;
            border-radius: 0px;
        }
 
        .uni-panel-button {
            flex: 1;
            border-radius: 12px;
            margin: 5px 12px 16px;
            background-color: #00aaff;
            color: #fff;
        }
 
        .uni-panel-bottom {
            display: flex;
            justify-content: flex-end;
            align-items: flex-end;
            min-height: 20px;
            padding: 8px 12px;
            font-size: 14px;
        }
    }
</style>