Blame view

src/components/scm/editReserveParams.vue 6.15 KB
9d4e862a   wuxw   开发完成预约功能
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
  <template>
    <el-dialog
      :title="$t('reserveParamsManage.editTitle')"
      :visible.sync="visible"
      width="70%"
      @close="handleClose"
    >
      <el-form
        ref="form"
        :model="formData"
        :rules="rules"
        label-width="120px"
        label-position="right"
      >
        <el-form-item
          :label="$t('reserveParamsManage.name')"
          prop="name"
        >
          <el-input
            v-model="formData.name"
            :placeholder="$t('reserveParamsManage.namePlaceholder')"
          />
        </el-form-item>
  
        <el-form-item
          :label="$t('reserveParamsManage.paramWay')"
          prop="paramWay"
        >
          <el-select
            v-model="formData.paramWay"
            :placeholder="$t('reserveParamsManage.paramWayPlaceholder')"
            style="width: 100%"
            @change="handleParamWayChange"
          >
            <el-option
              :label="$t('reserveParamsManage.day')"
              value="1"
            />
            <el-option
              :label="$t('reserveParamsManage.week')"
              value="2"
            />
          </el-select>
        </el-form-item>
  
        <el-form-item
          v-if="formData.paramWay === '1'"
          :label="$t('reserveParamsManage.days')"
          prop="days"
        >
          <el-checkbox-group v-model="formData.days">
            <el-checkbox
              v-for="day in 31"
              :key="day"
              :label="day"
            >
              {{ day }}{{ $t('reserveParamsManage.dayUnit') }}
            </el-checkbox>
          </el-checkbox-group>
        </el-form-item>
  
        <el-form-item
          v-if="formData.paramWay === '2'"
          :label="$t('reserveParamsManage.weekdays')"
          prop="workdays"
        >
          <el-checkbox-group v-model="formData.workdays">
            <el-checkbox
              v-for="(weekday, index) in weekdays"
              :key="index"
              :label="index + 1"
            >
              {{ weekday }}
            </el-checkbox>
          </el-checkbox-group>
        </el-form-item>
  
        <el-form-item
          :label="$t('reserveParamsManage.startTime')"
          prop="startTime"
        >
          <el-time-picker
            v-model="formData.startTime"
            :placeholder="$t('reserveParamsManage.startTimePlaceholder')"
            value-format="HH:mm:ss"
            style="width: 100%"
          />
        </el-form-item>
  
        <el-form-item
          :label="$t('reserveParamsManage.maxQuantity')"
          prop="maxQuantity"
        >
          <el-input-number
            v-model="formData.maxQuantity"
            :min="1"
            :placeholder="$t('reserveParamsManage.maxQuantityPlaceholder')"
            style="width: 100%"
          />
        </el-form-item>
  
        <el-form-item
          :label="$t('reserveParamsManage.hoursMaxQuantity')"
          prop="hoursMaxQuantity"
        >
          <el-input-number
            v-model="formData.hoursMaxQuantity"
            :min="1"
            :placeholder="$t('reserveParamsManage.hoursMaxQuantityPlaceholder')"
            style="width: 100%"
          />
        </el-form-item>
      </el-form>
  
      <div slot="footer" class="dialog-footer">
        <el-button @click="visible = false">
          {{ $t('common.cancel') }}
        </el-button>
        <el-button type="primary" @click="handleSubmit">
          {{ $t('common.confirm') }}
        </el-button>
      </div>
    </el-dialog>
  </template>
  
  <script>
  import { updateReserveParams } from '@/api/scm/reserveParamsManageApi'
  import { getCommunityId } from '@/api/community/communityApi'
  
  export default {
    name: 'EditReserveParams',
    data() {
      return {
        visible: false,
        formData: {
          paramsId: '',
          name: '',
          paramWay: '',
          days: [],
          workdays: [],
          startTime: '',
          maxQuantity: '',
          hoursMaxQuantity: '',
          communityId: ''
        },
        weekdays: [
          this.$t('common.monday'),
          this.$t('common.tuesday'),
          this.$t('common.wednesday'),
          this.$t('common.thursday'),
          this.$t('common.friday'),
          this.$t('common.saturday'),
          this.$t('common.sunday')
        ],
        rules: {
          name: [
            { required: true, message: this.$t('reserveParamsManage.nameRequired'), trigger: 'blur' }
          ],
          paramWay: [
            { required: true, message: this.$t('reserveParamsManage.paramWayRequired'), trigger: 'change' }
          ],
          startTime: [
            { required: true, message: this.$t('reserveParamsManage.startTimeRequired'), trigger: 'change' }
          ],
          maxQuantity: [
            { required: true, message: this.$t('reserveParamsManage.maxQuantityRequired'), trigger: 'blur' }
          ],
          hoursMaxQuantity: [
            { required: true, message: this.$t('reserveParamsManage.hoursMaxQuantityRequired'), trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      open(row) {
        this.visible = true
        this.formData = {
          ...row,
          days: row.paramWay === '1' ? row.paramWayText.split(',').map(Number) : [],
          workdays: row.paramWay === '2' ? row.paramWayText.split(',').map(Number) : [],
          communityId: getCommunityId()
        }
      },
      handleParamWayChange(val) {
        if (val === '1') {
          this.formData.days = this.formData.days.length 
            ? this.formData.days 
            : Array.from({ length: 31 }, (_, i) => i + 1)
          this.formData.workdays = []
        } else {
          this.formData.workdays = this.formData.workdays.length 
            ? this.formData.workdays 
            : Array.from({ length: 7 }, (_, i) => i + 1)
          this.formData.days = []
        }
      },
      handleSubmit() {
        this.$refs.form.validate(async valid => {
          if (valid) {
            try {
              const params = {
                ...this.formData,
                paramWayText: this.formData.paramWay === '1' 
                  ? this.formData.days.join(',') 
                  : this.formData.workdays.join(',')
              }
              await updateReserveParams(params)
              this.$message.success(this.$t('common.editSuccess'))
              this.visible = false
              this.$emit('success')
            } catch (error) {
              this.$message.error(error.message || this.$t('common.editFailed'))
            }
          }
        })
      },
      handleClose() {
        this.$refs.form.resetFields()
      }
    }
  }
  </script>