Blame view

src/views/oa/addComplaintList.vue 4.91 KB
0a06b2d1   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
  <template>
    <div class="add-complaint-container">
      <el-card class="box-card">
        <div slot="header" class="clearfix">
          <span>{{ $t('addComplaint.title') }}</span>
        </div>
        <el-form ref="form" :model="addComplaintInfo" :rules="rules" label-width="120px">
          <el-row :gutter="20">
            <el-col :span="24">
              <el-form-item :label="$t('addComplaint.type')" prop="typeCd">
                <el-select v-model="addComplaintInfo.typeCd" :placeholder="$t('addComplaint.typePlaceholder')"
                  style="width:100%">
                  <el-option v-for="item in addComplaintInfo.complaintTypes" :key="item.typeCd" :label="item.typeName"
                    :value="item.typeCd" />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
  
          <el-row :gutter="20">
            <el-col :span="24">
              <el-form-item :label="$t('addComplaint.room')" prop="roomName">
                <el-input v-model="addComplaintInfo.roomName" :placeholder="$t('addComplaint.roomPlaceholder')" disabled />
                <el-button type="primary" @click="selectComplaintRoom" style="margin-left:10px">
                  {{ $t('addComplaint.register') }}
                </el-button>
              </el-form-item>
            </el-col>
          </el-row>
  
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item :label="$t('addComplaint.contact')" prop="complaintName">
                <el-input v-model="addComplaintInfo.complaintName" :placeholder="$t('addComplaint.contactPlaceholder')" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item :label="$t('addComplaint.phone')" prop="tel">
                <el-input v-model="addComplaintInfo.tel" :placeholder="$t('addComplaint.phonePlaceholder')" />
              </el-form-item>
            </el-col>
          </el-row>
  
          <el-row :gutter="20">
            <el-col :span="24">
              <el-form-item :label="$t('addComplaint.content')" prop="context">
                <el-input type="textarea" :rows="4" v-model="addComplaintInfo.context"
                  :placeholder="$t('addComplaint.contentPlaceholder')" />
              </el-form-item>
            </el-col>
          </el-row>
  
          <el-row :gutter="20">
            <el-col :span="24" style="text-align:right">
              <el-button type="warning" @click="goBack">{{ $t('common.back') }}</el-button>
              <el-button type="primary" @click="saveComplaint">{{ $t('addComplaint.register') }}</el-button>
            </el-col>
          </el-row>
        </el-form>
      </el-card>
    </div>
  </template>
  
  <script>
  import { listComplaintTypes, saveComplaint } from '@/api/oa/addComplaintApi'
  import { getCommunityId } from '@/api/community/communityApi'
  
  export default {
    name: 'AddComplaintList',
    data() {
      return {
        addComplaintInfo: {
          complaintTypes: [],
          typeCd: '',
          complaintName: '',
          tel: '',
          context: '',
          communityId: '',
          roomId: '',
          roomName: '',
          ownerId: '',
          ownerName: ''
        },
        rules: {
          typeCd: [{ required: true, message: this.$t('addComplaint.typeRequired'), trigger: 'blur' }],
          complaintName: [
            { required: true, message: this.$t('addComplaint.contactRequired'), trigger: 'blur' },
            { max: 200, message: this.$t('addComplaint.contactMaxLength'), trigger: 'blur' }
          ],
          tel: [
            { required: true, message: this.$t('addComplaint.phoneRequired'), trigger: 'blur' },
            { pattern: /^1[3-9]\d{9}$/, message: this.$t('addComplaint.phoneFormat'), trigger: 'blur' }
          ],
          context: [
            { required: true, message: this.$t('addComplaint.contentRequired'), trigger: 'blur' },
            { max: 4000, message: this.$t('addComplaint.contentMaxLength'), trigger: 'blur' }
          ]
        }
      }
    },
    created() {
      this.communityId = getCommunityId()
      this.listComplaintTypes()
    },
    methods: {
      async listComplaintTypes() {
        try {
          const params = {
            page: 1,
            row: 100,
            communityId: this.communityId
          }
          const { data } = await listComplaintTypes(params)
          this.addComplaintInfo.complaintTypes = data
        } catch (error) {
          this.$message.error(this.$t('addComplaint.fetchTypesError'))
        }
      },
      selectComplaintRoom() {
        this.$emit('selectRoom')
      },
      async saveComplaint() {
        await this.$refs.form.validate()
  
        try {
          this.addComplaintInfo.communityId = this.communityId
          await saveComplaint(this.addComplaintInfo)
          this.$message.success(this.$t('addComplaint.saveSuccess'))
          this.goBack()
        } catch (error) {
          this.$message.error(error.message || this.$t('addComplaint.saveError'))
        }
      },
      goBack() {
        this.$router.go(-1)
      }
    }
  }
  </script>
  
  <style scoped>
  .add-complaint-container {
    padding: 20px;
  }
  
  .box-card {
    margin-bottom: 20px;
  }
  </style>