Blame view

src/views/scm/editReserveServiceList.vue 8.91 KB
6ec243d6   wuxw   v1.9 点击提交后,成功提示没有...
1
  <template>
9d4e862a   wuxw   开发完成预约功能
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
    <div class="edit-reserve-service-container">
      <el-card class="box-card">
        <div slot="header" class="clearfix">
          <span>{{ $t('editReserveService.title') }}</span>
        </div>
  
        <el-form ref="form" :model="editReserveServiceInfo" label-width="120px" label-position="right">
          <el-row :gutter="20">
            <el-col :span="24">
              <el-form-item :label="$t('editReserveService.goodsName')" prop="goodsName">
                <el-input
                  v-model="editReserveServiceInfo.goodsName"
                  :placeholder="$t('editReserveService.goodsNamePlaceholder')"
                  clearable
                />
              </el-form-item>
            </el-col>
          </el-row>
  
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item :label="$t('editReserveService.params')" prop="paramsId">
                <el-select
                  v-model="editReserveServiceInfo.paramsId"
                  :placeholder="$t('editReserveService.paramsPlaceholder')"
                  style="width:100%"
                >
                  <el-option
                    v-for="(item,index) in editReserveServiceInfo.reserveParamss"
                    :key="index"
                    :label="item.name"
                    :value="item.paramsId"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item :label="$t('editReserveService.price')" prop="price">
                <el-input
                  v-model="editReserveServiceInfo.price"
                  :placeholder="$t('editReserveService.pricePlaceholder')"
                  clearable
                />
              </el-form-item>
            </el-col>
          </el-row>
  
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item :label="$t('editReserveService.sort')" prop="sort">
                <el-input
                  v-model="editReserveServiceInfo.sort"
                  :placeholder="$t('editReserveService.sortPlaceholder')"
                  clearable
                />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item :label="$t('editReserveService.state')" prop="state">
                <el-select
                  v-model="editReserveServiceInfo.state"
                  :placeholder="$t('editReserveService.statePlaceholder')"
                  style="width:100%"
                >
                  <el-option
                    :label="$t('editReserveService.stateOff')"
                    value="1001"
                  />
                  <el-option
                    :label="$t('editReserveService.stateOn')"
                    value="2002"
                  />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
  
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item :label="$t('editReserveService.startDate')" prop="startDate">
                <el-date-picker
                  v-model="editReserveServiceInfo.startDate"
b25b036d   wuxw   v1.9 优化日期
84
85
                  type="datetime" value-format="yyyy-MM-dd HH:mm:ss"                :placeholder="$t('editReserveService.startDatePlaceholder')"
                  style="width:100%" 
9d4e862a   wuxw   开发完成预约功能
86
87
88
89
90
91
92
                />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item :label="$t('editReserveService.endDate')" prop="endDate">
                <el-date-picker
                  v-model="editReserveServiceInfo.endDate"
b25b036d   wuxw   v1.9 优化日期
93
94
                  type="datetime" value-format="yyyy-MM-dd HH:mm:ss"                :placeholder="$t('editReserveService.endDatePlaceholder')"
                  style="width:100%" 
9d4e862a   wuxw   开发完成预约功能
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
                />
              </el-form-item>
            </el-col>
          </el-row>
  
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item :label="$t('editReserveService.imgUrl')" prop="imgUrl">
                <upload-image-url
                  ref="uploadImage"
                  :limit="1"
                  :default-images="[editReserveServiceInfo.imgUrl]"
                  @notifyUploadCoverImage="handleImageChange"
                />
              </el-form-item>
            </el-col>
          </el-row>
  
          <el-row :gutter="20">
            <el-col :span="24">
              <el-form-item :label="$t('editReserveService.goodsDesc')" prop="goodsDesc">
                <el-input
                  v-model="editReserveServiceInfo.goodsDesc"
                  type="textarea"
                  :placeholder="$t('editReserveService.goodsDescPlaceholder')"
                  :rows="3"
                />
              </el-form-item>
            </el-col>
          </el-row>
  
          <el-row :gutter="20">
            <el-col :span="24">
              <el-form-item :label="$t('editReserveService.content')">
                <div class="editor-wrapper">
                  <rich-text-editor ref="richTextEditor" v-model="editReserveServiceInfo.content" />
                </div>
              </el-form-item>
            </el-col>
          </el-row>
  
          <el-row :gutter="20">
            <el-col :span="24" class="text-right">
              <el-button type="warning" @click="handleCancel">
                {{ $t('common.cancel') }}
              </el-button>
              <el-button type="primary" @click="handleSave">
                {{ $t('common.save') }}
              </el-button>
            </el-col>
          </el-row>
        </el-form>
      </el-card>
    </div>
  </template>
  
  <script>
  import UploadImageUrl from '@/components/upload/UploadImageUrl'
  import RichTextEditor from "@/components/editor/RichTextEditor";
  import { updateReserveGoods, listReserveParams, listReserveGoods } from '@/api/scm/editReserveServiceApi'
  import { getCommunityId } from '@/api/community/communityApi'
  
  export default {
    name: 'EditReserveServiceList',
    components: {
      UploadImageUrl,
      RichTextEditor
    },
    data() {
      return {
        editReserveServiceInfo: {
          goodsId: '',
          goodsName: '',
          goodsDesc: '',
          type: '1001',
          paramsId: '',
          price: '',
          sort: '',
          state: '',
          startDate: '',
          endDate: '',
          imgUrl: '',
          catalogId: '',
          content: '',
          reserveParamss: []
        },
        communityId: ''
      }
    },
    created() {
      this.communityId = getCommunityId()
      this.editReserveServiceInfo.goodsId = this.$route.query.goodsId
      this.listReserveParamss()
      this.listReserveServices()
    },
    methods: {
      handleImageChange(images) {
        this.editReserveServiceInfo.imgUrl = images.length > 0 ? images[0] : ''
      },
      async listReserveParamss() {
        try {
          const params = {
            page: 1,
            row: 100,
            communityId: this.communityId
          }
          const { data } = await listReserveParams(params)
          this.editReserveServiceInfo.reserveParamss = data
        } catch (error) {
          console.error('获取参数列表失败:', error)
          this.$message.error(this.$t('editReserveService.loadParamsFailed'))
        }
      },
      async listReserveServices() {
        try {
          const params = {
            page: 1,
            row: 1,
            goodsId: this.editReserveServiceInfo.goodsId,
            communityId: this.communityId
          }
          const { data } = await listReserveGoods(params)
          if (data && data.length > 0) {
            Object.assign(this.editReserveServiceInfo, data[0])
            this.$refs.richTextEditor.setContent(this.editReserveServiceInfo.content)
            this.$refs.uploadImage.setImages([this.editReserveServiceInfo.imgUrl])
  
          }
        } catch (error) {
          console.error('获取服务详情失败:', error)
          this.$message.error(this.$t('editReserveService.loadServiceFailed'))
        }
      },
      validateForm() {
        const requiredFields = [
          'goodsName',
          'paramsId',
          'price',
          'sort',
          'startDate',
          'endDate',
          'imgUrl',
          'state',
          'goodsDesc',
          'content'
        ]
  
        for (const field of requiredFields) {
          if (!this.editReserveServiceInfo[field]) {
            this.$message.error(this.$t(`editReserveService.${field}Required`))
            return false
          }
        }
        return true
      },
      async handleSave() {
        try {
          if (!this.validateForm()) return
  
          this.editReserveServiceInfo.communityId = this.communityId
          const { code, msg } = await updateReserveGoods(this.editReserveServiceInfo)
          
          if (code === 0) {
6ec243d6   wuxw   v1.9 点击提交后,成功提示没有...
258
            this.$message.success(this.$t('common.operationSuccess'))
9d4e862a   wuxw   开发完成预约功能
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
            this.$router.go(-1)
          } else {
            this.$message.error(msg)
          }
        } catch (error) {
          console.error('保存失败:', error)
          this.$message.error(this.$t('common.saveError'))
        }
      },
      handleCancel() {
        this.$router.go(-1)
      }
    }
  }
  </script>
  
  <style lang="scss" scoped>
  .edit-reserve-service-container {
    padding: 20px;
  
    .box-card {
      margin-bottom: 20px;
    }
  
    .text-right {
      text-align: right;
    }
  
    .editor-wrapper {
      border: 1px solid #dcdfe6;
      border-radius: 4px;
    }
  }
  </style>