沈丘营商办后台前端项目
wjt
2024-06-19 21245bd2f9775bc0149174256f58001a67fddba6
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
<template>
  <div class="app-container">
    <div class="form-content">
      <el-form inline :model="form.questionList" ref="formRef" label-width="75px" :rules="rules">
        <div
          class="border"
          v-for="(item, index) in form.questionList"
          :key="index"
        >
          <!-- <div class="title-project">
            评价项{{ index + 1 }}
          </div> -->
          <div class="close-icon" @click="removeList(index)">
            <el-tooltip content="移除评价项">
              <el-icon><Close color="red"/></el-icon>
            </el-tooltip>
          </div>
          <el-row>
            <el-col :span="12">
              <el-form-item :label="`评价项${index + 1}`" :prop="`${index}`" style="width: 100%"  :rules="[
                {
                  validator: validateSubField,
                  trigger: 'blur'
                }
              ]">
                <el-input
                  placeholder="请输入"
                  v-model="item.questionName"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="得分" :prop="item.questionScore">
                <el-input-number
                  placeholder="请输入"
                  v-model="item.questionScore"
                  :min="1"
                  :max="10"
                  controls-position="right"
                ></el-input-number>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="评价类型" :prop="item.questionType">
                <el-radio-group
                  placeholder="请输入"
                  v-model="item.questionType"
                >
                  <el-radio :value="2">打分</el-radio>
                  <el-radio :value="1">选择</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row v-if="item.questionType === 2">
            <el-form-item>
              <el-rate  disabled :max="item.questionScore"  v-model="item.questionScore"></el-rate>
            </el-form-item>
          </el-row>
          <el-row v-if="item.questionType === 1">
            <el-col :span="24">
              <el-form-item label="选项" style="width: 100%;"  :prop="`${index}`" :rules="[
                {
                  validator: answerListField,
                }
              ]">
                  <div
                    v-for="(ele, childIndex) in item.answerList"
                    :key="index"
                    style="width: 100%;"
                    class="set-flex"
                  >
                    <div style="font-size: 14px;margin-right: 10px">{{ childIndex + 1 }}</div>
                    <el-input
                      v-model="ele.answerName"
                      placeholder="请输入"
                       style="width: 65%; margin-right: 10px"
                    ></el-input>
                    <el-checkbox v-model="ele.isScore" @change="changeValue($event, index, childIndex)"  :true-value="1" :false-value="0" :label="'是否计分'"/>
                    <el-button type="danger" size="small" @click="removeArrlist(index, childIndex)" style="margin-left: 10px;">移除</el-button>
                  </div>
                  
                <!-- </el-radio-group> -->
 
                <div class="mt10">
                  <el-button type="primary" plain @click="addOptions(index, item.questionName)">添加选项</el-button>
                </div>
              </el-form-item>
            </el-col>
          </el-row>
        </div>          
      </el-form>
      <div class="center mt20 fixed">
        <el-button type="primary" @click="addContent">添加评价项</el-button>
        <el-button @click="save()" type="primary" >保存内容</el-button>
      </div>
    </div>
  </div>
</template>
 
<script lang="ts" setup>
import { listEvaluate, saveEvaluate } from '@/api/system/company/company'
import { ElMessage, ElMessageBox} from 'element-plus'
const tableData = ref([])
const addNewRef = ref()
const formRef = ref()
const form: any = ref({
  questionList: []
})
const rules = ref({
  questionName: [
    {
        required: true,
        message: '请输入问题',
        trigger: 'blur'
    }
  ]
})
const instance = getCurrentInstance()
 
function getListEvaluate() {
  listEvaluate().then((val) => {
    form.value.questionList = val.data.questionList
  })
}
function addContent() {
  form.value.questionList.push({
    questionStatus: 0,
    questionType: 2,
    questionScore: 5,
    questionName: '',
    answerList: []
  })
}
function addOptions(index: number, name: any){
  if(!form.value.questionList[index].answerList) {
    form.value.questionList[index].answerList = []
  }
  form.value.questionList[index].answerList.push({
    questionName: name
  })
}
function save(item?: string) {
  formRef.value.validate((valid) => {
    console.log(valid)
    if(valid) {
      saveEvaluate({questionList: form.value.questionList}).then(val => {
        ElMessage.success(item||'保存成功')
      })
    }
  })
 
}
function validateSubField(rule: any, value: any, callback: any) {
  // console.log(rule, value)
//   console.log(proxy['form'])
  if(!form.value.questionList[rule.field].questionName) {
    callback(new Error('请入评价项'))
  } else {
    callback()
  }
}
function answerListField(rule: { field: string | number }, value: any, callback: any) {
  if(form.value.questionList[rule.field].answerList.length < 2) {
    callback(new Error('请至少添加两项'))
  } else {
    callback()
  }
}
function changeValue(event, index, childIndex) {
  // form.value.questionList[index].isScore = event.target.
  form.value.questionList[index].answerList.forEach((item: { isScore: number }) => {
    item.isScore = 0
  })
  form.value.questionList[index].answerList[childIndex].isScore = 1
}
function removeList(index) {
  ElMessageBox.confirm('确认移除该评价项?', '提示', {
      confirmButtonText: '确认',
      cancelButtonText: '取消',
      type: 'danger',
    }).then(val => {
      form.value.questionList.splice(index, 1)
      save('删除成功')
    })
 
}
function removeArrlist(index: string | number, childIndex: any) {
  form.value.questionList[index].answerList.splice(childIndex, 1)
}
getListEvaluate()
</script>
 
<style scoped lang="scss">
.form-content {
  width: 80%;
  padding-bottom: 150px;
  margin: 0 auto;
  // border: 1px solid #e2e2e2;
}
 
.border {
  // border: 1px solid #e2e2e2;
  margin-bottom: 10px;
  padding: 20px 30px 0;
  position: relative;
  :deep() {
    .el-form-item__label{
      font-weight: 500
    }
  }
}
.close-icon {
  position: absolute;
  right: 10px;
  top: 10px;
  cursor: pointer;
}
 
.add-button {
  text-align: center;
  border: 1px dotted #979797;
  line-height: 40px;
  cursor: pointer;
  border-radius: 5px;
}
.set-flex{
  display: flex;
  justify-content: flex-start;
  margin-top: 10px
}
.center{
  text-align: center;
}
.fixed{
  background-color: white;
  position: sticky;
  bottom: 0;
}
.title-project{
  font-weight: 700;
  color: #606266;
  margin-bottom: 10px
}
</style>