Newer
Older
KaiFengPC / src / views / publicService / quesNaire.vue
@鲁yixuan 鲁yixuan on 23 Jul 13 KB update
<template>
  <!-- 排水防涝子系统 公众服务  问卷调查-->
  <div class="publicContainer">
    <!-- 搜索区域 -->
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch">
      <el-form-item label="问卷调查名称" prop="topicName">
        <el-input v-model="queryParams.topicName" placeholder="请输入" clearable @keyup.enter="handleQuery" />
      </el-form-item>
      <el-form-item label="调查状态" prop="adjustmentStatus">
        <el-select v-model="queryParams.adjustmentStatus" placeholder="请选择" clearable>
          <el-option v-for="item in statusList" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button type="success" icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <!-- 按钮区域 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="Plus" @click="handleAdd" v-if="tableData.length == ''">新增</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getDataList"></right-toolbar>
    </el-row>
    <!-- 表格 -->
    <el-table v-loading="tableLoading" :data="tableData" max-height="700">
      <el-table-column label="调查问卷调查名称" prop="topicName" />
      <el-table-column label="问卷状态" prop="ifStart">
        <template #default="scope">
          <span :class="scope.row.ifStart == 1 ? 'green' : 'red'">{{ scope.row.ifStart == 1 ? '启用' : '未启用' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" prop="createTime" />
      <el-table-column label="操作" width="260" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button
            type="primary"
            icon="Edit"
            @click="handleUpdate(scope.row)"
            v-if="scope.row.ifStart == 0 && scope.row.adjustmentStatus != 'ended'"
          >
            修改
          </el-button>
          <el-button
            type="danger"
            icon="Delete"
            @click="handleDelete(scope.row)"
            v-if="scope.row.ifStart == 0 && scope.row.adjustmentStatus != 'ended'"
          >
            删除
          </el-button>
          <el-button type="warning" icon="Edit" @click="handleCount(scope.row)" v-if="scope.row.ifStart == 1 || allData.ifStartQy == 0">
            满意度统计
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <pagination
      v-show="total > 0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getDataList"
    />

    <!-- 添加或修改弹窗 -->
    <el-dialog :title="dialogTitle" v-model="dialogShow" width="600px" append-to-body>
      <el-form ref="formRef" :model="formData" :rules="rulesForm" label-width="120px" class="publicForm">
        <el-form-item label="问卷调查名称" prop="topicName">
          <el-input v-model="formData.topicName" />
        </el-form-item>
        <!-- <el-form-item label="年份选择" prop="year">
          <el-date-picker type="year" v-model="formData.year" value-format="YYYY" placeholder="请选择日期"> </el-date-picker>
        </el-form-item> -->
        <el-form-item label="问卷状态" prop="ifStart">
          <el-radio-group v-model="formData.ifStart">
            <el-radio :label="1">启用</el-radio>
            <el-radio :label="0">未启用</el-radio>
          </el-radio-group>
        </el-form-item>
        <!-- <el-form-item label="问卷介绍" prop="introduce">
          <el-input type="textarea" v-model="formData.introduce" />
        </el-form-item> -->
        <el-divider />
        <el-button type="primary" plain icon="Plus" @click="addQues">新增标题内容</el-button>
        <el-table :data="formData.problemConfigList" style="margin-top: 10px" max-height="300">
          <el-table-column label="问题名称" prop="problemName" />
          <el-table-column label="问题类型" prop="problemType">
            <template #default="scope">
              <dict-tag :options="typeList" :value="scope.row.problemType" />
            </template>
          </el-table-column>
          <el-table-column label="操作" width="240" class-name="small-padding fixed-width">
            <template #default="scope">
              <el-button type="primary" icon="Edit" @click="changeQues(scope.row)"> 修改 </el-button>
              <el-button type="danger" icon="Delete" @click="deleteQues(scope.row)"> 删除 </el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="info" @click="cancelForm">取 消</el-button>
          <el-button type="primary" @click="submitForm">确 定</el-button>
        </div>
      </template>
    </el-dialog>
    <!-- 问题答案编辑 -->
    <el-dialog :title="dialogTitleAns" v-model="dialogShowAns" width="500px" append-to-body>
      <el-form ref="formRefAns" :model="formDataAns" :rules="rulesFormAns" label-width="80px" class="publicForm">
        <el-form-item label="问题名称" prop="problemName">
          <el-input v-model="formDataAns.problemName" />
        </el-form-item>
        <el-form-item label="满分" prop="fullScore">
          <el-input v-model="formDataAns.fullScore" placeholder="分值" />
        </el-form-item>
        <el-form-item label="问题类型" prop="problemType">
          <el-select v-model="formDataAns.problemType" placeholder="请选择">
            <el-option v-for="item in typeList" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
        </el-form-item>
        <el-divider />
        <el-button type="primary" plain icon="Plus" @click="addAnswer">新增问题答案</el-button>
        <!-- 批量新增 可新增区域 -->
        <el-table :data="formDataAns.problemOptionList" style="margin-top: 10px">
          <el-table-column label="问题选项" prop="optionName">
            <template #default="scope">
              <el-input v-model="scope.row.optionName" />
            </template>
          </el-table-column>
          <el-table-column label="分数" prop="score">
            <template #default="scope">
              <el-input v-model="scope.row.score" placeholder="分值" />
            </template>
          </el-table-column>
          <el-table-column label="操作" width="160" class-name="small-padding fixed-width">
            <template #default="scope">
              <el-button type="danger" icon="Edit" @click="deleteAnswer(scope.row)"> 删除 </el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="info" @click="sureAnswer">确定</el-button>
        </div>
      </template>
    </el-dialog>
    <!-- 满意度统计 -->
    <el-dialog title="满意度统计" v-model="dialogCount" width="1200px" append-to-body>
      <!-- <el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['floodSys:paikou:export']">导出</el-button> -->
      <!-- <el-divider /> -->
      <div class="satisfied">
        <div class="part" v-for="(item, index) in tableDataCount" :key="item.id">
          <p>
            <span>{{ index + 1 }},题目名称:{{ item.problemName }},</span>
            <span>
              题目类型:{{
                item.problemType == 'radio'
                  ? '单选'
                  : item.problemType == 'checkbox'
                  ? '多选'
                  : item.problemType == 'answers'
                  ? '简答题'
                  : '--'
              }}
            </span>
            <span>,本题有效填写人次:{{ item.fillTimes || 0 }}</span>
          </p>
          <el-table :data="item.problemOptionList">
            <el-table-column label="选项名称" prop="optionName" />
            <el-table-column label="问题选项填报次数" prop="optionTimes" />
            <el-table-column label="问题选项填报百分比" prop="percentage" />
          </el-table>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script setup name="问卷调查">
import { quesNairePage, quesNaireAdd, quesNaireDel, quesNaireDetail, quesNaireEdit, quesNaireCount } from '@/api/publicService/index';

const { proxy } = getCurrentInstance();

const tableData = ref([]);
const tableLoading = ref(true);
const total = ref(0);
const dialogShow = ref(false);
const dialogTitle = ref('');
const showSearch = ref(true);
const dialogCount = ref(false);
const tableDataCount = ref([]);
const dialogTitleAns = ref('');
const dialogShowAns = ref(false);

const allData = reactive({
  ifStartQy: '',
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    topicName: undefined,
    adjustmentStatus: undefined,
  },
  formData: {
    topicName: '',
    ifStart: 1,
    year: null,
    introduce: '',
    problemConfigList: [],
  },
  rulesForm: {
    topicName: [{ required: true, message: '请输入', trigger: 'blur' }],
    ifStart: [{ required: true, message: '请输入', trigger: 'change' }],
    year: [{ required: true, message: '请输入', trigger: 'change' }],
  },
  formDataAns: {
    problemType: '',
    problemName: '',
    fullScore: '100',
    questionnaireId: '',
    problemOptionList: [{ optionName: '', score: '', problemId: '' }],
  },
  rulesFormAns: {
    problemName: [{ required: true, message: '请输入', trigger: 'blur' }],
    fullScore: [{ required: true, message: '请输入', trigger: 'blur', type: 'number' }],
    problemType: [{ required: true, message: '请选择', trigger: 'change' }],
  },
});
const { queryParams, formData, rulesForm, formDataAns, rulesFormAns } = toRefs(allData);
const statusList = ref([
  { value: 1, label: '启用' },
  // { value: 'executing', label: '执行中' },
  { value: 0, label: '未启用' },
]);
const typeList = ref([
  { value: 'radio', label: '单选' },
  { value: 'checkbox', label: '多选' },
  { value: 'answers', label: '简答题' },
]);

/** 获取查询数据列表 */
function getDataList() {
  tableLoading.value = true;
  quesNairePage(queryParams.value).then(response => {
    tableData.value = response.data;
    response.data.forEach(element => {
      if (element.ifStart == 0) {
        allData.ifStartQy = element.ifStart;
        console.log(allData.ifStartQy, '   allData.ifStartQy');
      }
    });
    total.value = response.total;
    tableLoading.value = false;
  });
}
/** 取消按钮 */
function cancelForm() {
  dialogShow.value = false;
}
/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getDataList();
}
/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm('queryRef');
  handleQuery();
}
/** 新增按钮操作 */
function handleAdd() {
  proxy.resetForm('formRef'); //清空表单
  formData.value = {
    topicName: '',
    ifStart: 1,
    year: null,
    introduce: '',
    problemConfigList: [],
  };
  dialogShow.value = true;
  dialogTitle.value = '添加问卷调查';
}
/** 修改按钮操作 */
function handleUpdate(row) {
  const postId = row.id;
  quesNaireDetail(postId).then(response => {
    dialogShow.value = true;
    dialogTitle.value = '修改问卷调查';
    nextTick(() => {
      formData.value = response.data;
    });
  });
}
/** 提交按钮 */
function submitForm() {
  proxy.$refs['formRef'].validate(valid => {
    if (valid) {
      if (dialogTitle.value == '修改问卷调查') {
        quesNaireEdit(formData.value).then(response => {
          proxy.$modal.msgSuccess('修改成功');
          dialogShow.value = false;
          getDataList();
        });
      } else {
        quesNaireAdd(formData.value).then(response => {
          proxy.$modal.msgSuccess('新增成功');
          dialogShow.value = false;
          getDataList();
        });
      }
    }
  });
}
/** 删除按钮操作 */
function handleDelete(row) {
  const postIds = row.id;
  proxy.$modal
    .confirm('是否确认删除该数据项?')
    .then(function () {
      return quesNaireDel(postIds);
    })
    .then(() => {
      getDataList();
      proxy.$modal.msgSuccess('删除成功');
    })
    .catch(() => {});
}
// 满意度统计
function handleCount(row) {
  quesNaireCount(row.id).then(res => {
    tableDataCount.value = res.data.problemConfigList;
    dialogCount.value = true;
  });
}
/** 导出按钮操作 */
function handleExport() {
  proxy.download(
    'system/post/export',
    {
      ...queryParams.value,
    },
    `问卷调查满意度统计 ${new Date().getTime()}.xlsx`
  );
}
// 问题 新增
const addQues = () => {
  dialogTitleAns.value = '新增问题答案';
  dialogShowAns.value = true;
  formDataAns.value = {
    problemType: '',
    problemName: '',
    fullScore: '100',
    questionnaireId: '',
    problemOptionList: [{ optionName: '', score: '', problemId: '' }],
  };
};
// 问题 修改
function changeQues(row) {
  formDataAns.value = row;
  dialogTitleAns.value = '修改问题答案';
  dialogShowAns.value = true;
}
// 问题 删除
function deleteQues(row) {
  formData.value.problemConfigList.splice(row, 1);
}

// 新增问题答案
function addAnswer() {
  formDataAns.value.problemOptionList.push({ optionName: '', score: '', problemId: '' });
}
// 删除问题答案
const deleteAnswer = row => {
  formDataAns.value.problemOptionList.splice(row, 1);
};
// 问题答案编辑完成
function sureAnswer() {
  if (dialogTitleAns.value == '新增问题答案') {
    formData.value.problemConfigList.push(formDataAns.value);
  } else {
  }
  dialogShowAns.value = false;
}
onMounted(() => {
  getDataList();
});
</script>

<style lang="scss">
.satisfied {
  margin-bottom: 20px;
  max-height: 800px;
  overflow: auto;
  .part {
    p {
      display: flex;
      color: #c6c6c6;
    }
    .el-table {
      margin: 10px 0px;
    }
  }
}
</style>