Blame view

src/components/system/editStoreAttr.vue 2.03 KB
03f63ab4   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
  <template>
    <el-dialog :title="$t('editStoreAttr.title')" :visible.sync="visible" width="60%" @close="handleClose">
      <el-form ref="form" :model="form" :rules="rules" label-width="120px" label-position="right">
        <el-form-item :label="form.name">
          <el-input v-model="form.value" :placeholder="$t('editStoreAttr.attributePlaceholder')" />
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="visible = false">
          {{ $t('common.cancel') }}
        </el-button>
        <el-button type="primary" @click="submitForm">
          {{ $t('common.save') }}
        </el-button>
      </span>
    </el-dialog>
  </template>
  
  <script>
  import { updateStoreAttr } from '@/api/system/storeInfoManageApi'
  
  export default {
    name: 'EditStoreAttr',
    data() {
      return {
        visible: false,
        form: {
          attrId: '',
          value: '',
          name: ''
        },
        rules: {
          value: [
            { required: true, message: this.$t('editStoreAttr.validate.valueRequired'), trigger: 'blur' },
            { max: 50, message: this.$t('editStoreAttr.validate.valueMaxLength'), trigger: 'blur' }
          ],
          attrId: [
            { required: true, message: this.$t('editStoreAttr.validate.attrIdRequired'), trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      open(storeAttr) {
        this.resetForm()
        this.form = {
          ...this.form,
          ...storeAttr
        }
        this.visible = true
      },
      resetForm() {
        this.form = {
          attrId: '',
          value: '',
          name: ''
        }
      },
      handleClose() {
        this.resetForm()
      },
      submitForm() {
        this.$refs.form.validate(async valid => {
          if (valid) {
            try {
              await updateStoreAttr(this.form)
              this.$message.success(this.$t('common.saveSuccess'))
              this.visible = false
              this.$emit('success')
            } catch (error) {
              this.$message.error(error.message || this.$t('common.saveFailed'))
            }
          }
        })
      }
    }
  }
  </script>