zhangwei
19 小时以前 309b5a2eb4a99f20b2dcceca41c7ed1275bcc6ae
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
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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
<script lang="ts" name="procurementComplaint" setup>
import { ref, reactive, onMounted } from "vue";
import { ElMessage } from "element-plus";
import type { FormRules } from "element-plus";
import { formatDate } from "/@/utils/formatTime";
import { useProcurementComplaintApi } from "/@/api/fb_p_complaints/procurementComplaint";
import { log } from "console";
 
//父级传递来的函数,用于回调
const emit = defineEmits(["reloadTable"]);
const procurementComplaintApi = useProcurementComplaintApi();
const ruleFormRef = ref();
 
const state = reactive({
  title: "",
  loading: false,
  showDialog: false,
  ruleForm: {
    complaints: [{ itemDescription: "" }]
  } as any,
  stores: {},
  dropdownData: {} as any
});
 
const handlingStatus = [
  { value: 0, label: "其它" },
  { value: 1, label: "成立" },
  { value: 2, label: "驳回" },
  { value: 3, label: "部分成立" }
];
 
// 自行添加其他规则
const rules = ref<FormRules>({
  projectCode: [
    { required: true, message: "请选择项目编号!", trigger: "blur" }
  ],
  projectName: [
    { required: true, message: "请选择项目名称!", trigger: "blur" }
  ],
  decisionDate: [
    { required: true, message: "请选择决定日期!", trigger: "change" }
  ],
  purchaser: [{ required: true, message: "请选择采购人!", trigger: "blur" }],
  procurementAgency: [
    { required: true, message: "请选择采购代理机构!", trigger: "blur" }
  ]
});
 
// 页面加载时
onMounted(async () => {});
 
// 打开弹窗
const openDialog = async (row: any, title: string) => {
  state.title = title;
  row = row ?? { complaints: [{ itemDescription: "" }] };
  state.ruleForm = row.id
    ? await procurementComplaintApi.detail(row.id).then(res => res.data.result)
    : JSON.parse(JSON.stringify(row));
  state.showDialog = true;
  console.log(state.ruleForm.complaints, state.ruleForm.complaints.length);
};
 
// 关闭弹窗
const closeDialog = () => {
  emit("reloadTable");
  state.showDialog = false;
};
 
// 提交
const submit = async () => {
  ruleFormRef.value.validate(async (isValid: boolean, fields?: any) => {
    if (isValid) {
      let values = state.ruleForm;
      await procurementComplaintApi[state.ruleForm.id ? "update" : "add"](
        values
      );
      closeDialog();
    } else {
      ElMessage({
        message: `表单有${Object.keys(fields).length}处验证失败,请修改后再提交`,
        type: "error"
      });
    }
  });
};
 
const changeComplaints = (index: any, txt: String) => {
  if (txt == "add") {
    state.ruleForm.complaints.splice(index + 1, 0, { itemDescription: "" });
  } else {
    state.ruleForm.complaints.splice(index, 1);
  }
};
 
//将属性或者函数暴露给父组件
defineExpose({ openDialog });
</script>
<template>
  <div class="procurementComplaint-container">
    <el-dialog
      v-model="state.showDialog"
      :width="900"
      draggable
      :close-on-click-modal="false"
    >
      <template #header>
        <div style="color: #fff">
          <span>{{ state.title }}</span>
        </div>
      </template>
      <el-form
        ref="ruleFormRef"
        :model="state.ruleForm"
        label-width="auto"
        :rules="rules"
      >
        <el-row :gutter="35">
          <el-form-item v-show="false">
            <el-input v-model="state.ruleForm.id" />
          </el-form-item>
          <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
            <el-form-item label="决定日期" prop="decisionDate">
              <el-date-picker
                v-model="state.ruleForm.decisionDate"
                type="date"
                placeholder="请选择决定日期"
              />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
            <el-form-item label="项目名称" prop="projectName">
              <el-input
                v-model="state.ruleForm.projectName"
                placeholder="请输入项目名称"
                maxlength="200"
                show-word-limit
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
            <el-form-item label="项目编号" prop="projectCode">
              <el-input
                v-model="state.ruleForm.projectCode"
                placeholder="请输入项目编号"
                maxlength="50"
                show-word-limit
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
            <el-form-item label="采购人" prop="purchaser">
              <el-input
                v-model="state.ruleForm.purchaser"
                placeholder="请输入采购人"
                maxlength="100"
                show-word-limit
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
            <el-form-item label="采购代理机构" prop="procurementAgency">
              <el-input
                v-model="state.ruleForm.procurementAgency"
                placeholder="请输入采购代理机构"
                maxlength="100"
                show-word-limit
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
            <el-form-item
              label="采购监督部门"
              prop="procurementSupervisionDepartment"
            >
              <el-input
                v-model="state.ruleForm.procurementSupervisionDepartment"
                placeholder="请输入采购监督部门"
                maxlength="100"
                show-word-limit
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
            <el-form-item label="投诉人" prop="complainant">
              <el-input
                v-model="state.ruleForm.complainant"
                placeholder="请输入投诉人"
                maxlength="100"
                show-word-limit
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
            <el-form-item label="线上地址" prop="url">
              <el-input
                v-model="state.ruleForm.url"
                placeholder="请输入线上地址"
                maxlength="255"
                show-word-limit
                clearable
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <template
            v-for="(item, index) in state.ruleForm.complaints"
            :key="index"
          >
            <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
              <el-form-item
                :label="`投诉事项${index == 0 ? '' : index}`"
                prop="complaints"
              >
                <el-input
                  v-model="item.itemDescription"
                  type="textarea"
                  :placeholder="`请输入投诉事项${index == 0 ? '' : index}`"
                  maxlength="1000"
                  show-word-limit
                  clearable
                />
              </el-form-item>
            </el-col>
            <el-col :xs="12" :sm="12" :md="12" :lg="12" :xl="12" class="">
              <el-form-item
                :label="`处理描述${index == 0 ? '' : index}`"
                prop="complaints"
              >
                <el-input
                  v-model="item.handlingResult"
                  type="textarea"
                  :placeholder="`请输入处理描述${index == 0 ? '' : index}`"
                  maxlength="1000"
                  show-word-limit
                  clearable
                />
              </el-form-item>
            </el-col>
            <el-col :xs="6" :sm="6" :md="6" :lg="6" :xl="6" class="mb20">
              <el-form-item
                :label="`投诉状态${index == 0 ? '' : index}`"
                prop="complaints"
              >
                <el-select v-model="item.handlingStatus">
                  <el-option
                    v-for="item in handlingStatus"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :xs="1" :sm="1" :md="1" :lg="1" :xl="1" class="mb20">
              <el-button type="primary" @click="changeComplaints(index, 'add')"
                >+</el-button
              >
            </el-col>
            <el-col
              v-if="
                state.ruleForm.complaints &&
                state.ruleForm.complaints.length > 1
              "
              :xs="1"
              :sm="1"
              :md="1"
              :lg="1"
              :xl="1"
              class="mb20"
            >
              <el-button type="primary" @click="changeComplaints(index)"
                >-</el-button
              >
            </el-col>
            <el-divider
              v-if="
                state.ruleForm.complaints &&
                state.ruleForm.complaints.length > 1
              "
            />
          </template>
        </el-row>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="() => (state.showDialog = false)">取 消</el-button>
          <el-button v-reclick="1000" type="primary" @click="submit"
            >确 定</el-button
          >
        </span>
      </template>
    </el-dialog>
  </div>
</template>
<style lang="scss" scoped>
:deep(.el-select),
:deep(.el-input-number) {
  width: 100%;
}
</style>