mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/fe-manage.git
synced 2025-12-14 05:16:45 +08:00
feat:创建投票
This commit is contained in:
@@ -26,7 +26,7 @@
|
||||
</div>
|
||||
<div class="btnbox">
|
||||
<a-input
|
||||
v-model:value="voteName"
|
||||
v-model:value="ballotName"
|
||||
style="width: 424px; height: 32px"
|
||||
placeholder="请输入任务名称"
|
||||
maxlength="20"
|
||||
@@ -47,7 +47,7 @@
|
||||
<!-- 创建投票侧弹窗 -->
|
||||
</div>
|
||||
<div v-for="(item, index) in allFormsData" :key="index">
|
||||
<VoteQuestion :item="item" :ballotId="ballotId" @del="handleDel" />
|
||||
<VoteQuestion :item="item" :optionId="optionId" @del="handleDel" />
|
||||
</div>
|
||||
|
||||
<div class="footer">
|
||||
@@ -84,20 +84,22 @@
|
||||
</template>
|
||||
<script>
|
||||
import { reactive, toRefs } from "vue";
|
||||
// import { message } from "ant-design-vue";
|
||||
import { message } from "ant-design-vue";
|
||||
// import { createResearch } from "../../api/indexResearch";
|
||||
import VoteQuestion from "./VoteQuestion.vue";
|
||||
|
||||
import {
|
||||
// sortBy,
|
||||
traverseArr,
|
||||
// filterCommon,
|
||||
//filterCommon,
|
||||
// deepCloneFilterString,
|
||||
} from "../../utils/utils";
|
||||
|
||||
//import store from "@/store";
|
||||
import * as api from "@/api/indexVote";
|
||||
//import { useRouter } from "vue-router";
|
||||
import {} from "@/api/indexResearch";
|
||||
|
||||
//import { message } from "ant-design-vue";
|
||||
|
||||
export default {
|
||||
@@ -124,51 +126,71 @@ export default {
|
||||
ballotId: "",
|
||||
ballotName: "",
|
||||
allFormsData: [],
|
||||
|
||||
});
|
||||
// const router = useRouter();
|
||||
const afterVisibleChange = () => {
|
||||
handleTypes();
|
||||
getInfoDate();
|
||||
|
||||
/*
|
||||
if(){
|
||||
|
||||
}else{
|
||||
handleTypes();
|
||||
}
|
||||
*/
|
||||
};
|
||||
const closeDrawer = () => {
|
||||
ctx.emit("update:createVoteVisible", false);
|
||||
ctx.emit("update:ballotId", state.ballotId);
|
||||
handleAllCancel();
|
||||
};
|
||||
// 详情
|
||||
const getInfoDate = async () => {
|
||||
if (props.editChild) {
|
||||
//stemId 多余字段
|
||||
console.log("props.editChild=====",props.editChild);
|
||||
if (props.ballotId>0) {
|
||||
console.log("props.editChild2=====",props.editChild);
|
||||
let res = await api
|
||||
.queryStemByStemId({
|
||||
stemId: 0,
|
||||
ballotId: state.ballotId,
|
||||
})
|
||||
.queryStemByStemId({ballotId:props.ballotId})
|
||||
.then((res) => {
|
||||
if (res.data.code === 200) {
|
||||
return res.data.data;
|
||||
}
|
||||
});
|
||||
state.ballotName = res[0].ballotId;
|
||||
let renderArr = [...res];
|
||||
console.log("res====",res);
|
||||
state.ballotName = res.ballotId;
|
||||
// let renderArr = [...res];
|
||||
// sortBy(renderArr, "orderNumber"); //序号
|
||||
state.allFormsData = parseData(renderArr); //类型
|
||||
state.allFormsData = parseData(res); //类型
|
||||
|
||||
console.log( state.allFormsData);
|
||||
}
|
||||
};
|
||||
getInfoDate();
|
||||
|
||||
|
||||
// 转换成前端格式
|
||||
const parseData = (arr) => {
|
||||
const resultArr = [];
|
||||
arr.forEach((item) => {
|
||||
state.ballotId = arr.ballotId;
|
||||
state.ballotName =arr.ballotName;
|
||||
|
||||
console.log("arr.voteStemVoList=====",arr.voteStemVoList);
|
||||
arr.voteStemVoList.forEach((item) => {
|
||||
let obj = {};
|
||||
let restList = traverseArr(item.optionDetailList, {
|
||||
inputVal: "singleOptionName",
|
||||
imgVal: "singleOptionPictureAddress",
|
||||
optionId: "singleOptionId",
|
||||
inputVal: "optionName",
|
||||
imgVal: "optionPictureAddress",
|
||||
optionId: "optionId",
|
||||
voteStemId:"voteStemId",
|
||||
stem:"stem",
|
||||
}).map((itm, idx) => {
|
||||
itm.id = idx + 1;
|
||||
return itm;
|
||||
});
|
||||
|
||||
obj = {
|
||||
voteStemName: item.singleStemName,
|
||||
voteStemId:item.voteStemId,
|
||||
valueSingle: item.voteStemName,
|
||||
singleList: restList,
|
||||
};
|
||||
resultArr.push(obj);
|
||||
@@ -179,78 +201,41 @@ export default {
|
||||
});
|
||||
return resultArr;
|
||||
};
|
||||
/**
|
||||
|
||||
// 转换成后端格式
|
||||
const restData = (arr, typeKey) => {
|
||||
const restData = (arr) => {
|
||||
const resultArr = [];
|
||||
arr.forEach((item) => {
|
||||
let obj = {};
|
||||
if (item[typeKey] === 1) {
|
||||
console.log("item=======",item);
|
||||
// if (item[typeKey] === 1) {
|
||||
let restList = traverseArr(item.singleList, {
|
||||
singleOptionName: "inputVal",
|
||||
singleOptionPictureAddress: "imgVal",
|
||||
singleOptionId: "optionId",
|
||||
optionName: "inputVal",
|
||||
optionPictureAddress: "imgVal",
|
||||
optionId: "optionId",
|
||||
voteStemId:"voteStemId",
|
||||
stem:"stem",
|
||||
}).map((itm, idx) => {
|
||||
itm.optionOrderNum = idx + 1;
|
||||
return itm;
|
||||
});
|
||||
restList.forEach((item) => {
|
||||
item.singleOptionId = item.singleOptionId
|
||||
? item.singleOptionId
|
||||
item.optionId = item.optionId
|
||||
? item.optionId
|
||||
: "";
|
||||
});
|
||||
|
||||
obj = {
|
||||
questionType: item[typeKey],
|
||||
singleStemName: item.valueSingle,
|
||||
singleList: restList,
|
||||
orderNumber: item.orderNumber,
|
||||
};
|
||||
|
||||
voteStemName: item.valueSingle,
|
||||
optionDetailList: restList,
|
||||
voteStemId:item.voteStemId,
|
||||
|
||||
};
|
||||
resultArr.push(obj);
|
||||
}
|
||||
if (item[typeKey] === 2) {
|
||||
let restList = traverseArr(item.mutilList, {
|
||||
multipleOptionName: "inputVal",
|
||||
multipleOptionPictureAddress: "imgVal",
|
||||
multipleOptionId: "optionId",
|
||||
}).map((itm, idx) => {
|
||||
itm.optionOrderNum = idx + 1;
|
||||
return itm;
|
||||
});
|
||||
restList.forEach((item) => {
|
||||
item.multipleOptionId = item.multipleOptionId
|
||||
? item.multipleOptionId
|
||||
: "";
|
||||
});
|
||||
|
||||
obj = {
|
||||
questionType: item[typeKey],
|
||||
multipleStemName: item.valueMutil,
|
||||
mutilList: restList,
|
||||
orderNumber: item.orderNumber,
|
||||
};
|
||||
resultArr.push(obj);
|
||||
}
|
||||
if (item[typeKey] === 3) {
|
||||
obj = {
|
||||
questionType: item[typeKey],
|
||||
assessmentQaTitle: item.valueAsk,
|
||||
assessmentQaDescribe: item.valueAskDesc,
|
||||
assessmentQaId: item.optionId ? item.optionId : "",
|
||||
};
|
||||
resultArr.push(obj);
|
||||
}
|
||||
if (item[typeKey] === 4) {
|
||||
obj = {
|
||||
questionType: item[typeKey],
|
||||
assessmentScTitle: item.valuePin,
|
||||
assessmentMinScore: item.minScore,
|
||||
assessmentMaxScore: item.maxScore,
|
||||
weightScale: item.pinQuan,
|
||||
assessmentScId: item.optionId ? item.optionId : "",
|
||||
};
|
||||
resultArr.push(obj);
|
||||
}
|
||||
// }
|
||||
console.log("resultArr=======",resultArr);
|
||||
|
||||
});
|
||||
resultArr.map((itm, idx) => {
|
||||
itm.orderNumber = idx + 1;
|
||||
@@ -260,55 +245,37 @@ export default {
|
||||
};
|
||||
|
||||
// 解散传值
|
||||
const parseItem = (arr) => {
|
||||
const filterComObj = filterCommon(arr, "questionType");
|
||||
const parseItem = (arrr) => {
|
||||
// const filterComObj = filterCommon(arr, "questionType");
|
||||
let resultObj = {};
|
||||
for (let key in filterComObj) {
|
||||
if (key === "1") {
|
||||
let arrSingle = filterComObj[key];
|
||||
// for (let key in filterComObj) {
|
||||
// if (key === "1") {
|
||||
// let arrSingle = arrr
|
||||
//filterComObj[key];
|
||||
console.log("arrr======",arrr);
|
||||
/*
|
||||
let arr = [];
|
||||
arrSingle.forEach((item) => {
|
||||
console.log("item======",item);
|
||||
if (item.singleList.length) {
|
||||
item.singleList.forEach((itm) => {
|
||||
arr.push({
|
||||
...itm,
|
||||
singleStemName: item.singleStemName,
|
||||
orderNumber: item.orderNumber,
|
||||
questionType: item.questionType,
|
||||
optionName: item.optionName,
|
||||
optionOrderNum: item.optionOrderNum,
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
resultObj.assessmentSingleChoiceDtoList = arr;
|
||||
}
|
||||
if (key === "2") {
|
||||
let arrMulti = filterComObj[key];
|
||||
let arr = [];
|
||||
arrMulti.forEach((item) => {
|
||||
if (item.mutilList.length) {
|
||||
item.mutilList.forEach((itm) => {
|
||||
arr.push({
|
||||
...itm,
|
||||
multipleStemName: item.multipleStemName,
|
||||
orderNumber: item.orderNumber,
|
||||
questionType: item.questionType,
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
resultObj.assessmentMultipleChoiceDtoList = arr;
|
||||
}
|
||||
if (key === "3") {
|
||||
resultObj.assessmentEssayQuestionDtoList = filterComObj[key];
|
||||
}
|
||||
if (key === "4") {
|
||||
resultObj.assessmentScoringQuestionDtoList = filterComObj[key];
|
||||
}
|
||||
}
|
||||
});*/
|
||||
resultObj.voteStemDtoList = arrr;
|
||||
// }
|
||||
console.log("resultObj======",resultObj);
|
||||
// }
|
||||
return resultObj;
|
||||
};
|
||||
|
||||
*/
|
||||
|
||||
const handleTypes = () => {
|
||||
let obj = {
|
||||
id: state.allFormsData.length,
|
||||
@@ -339,14 +306,21 @@ export default {
|
||||
};
|
||||
|
||||
const handleSave = () => {
|
||||
/**
|
||||
|
||||
let resultPost = {};
|
||||
|
||||
let filterData = parseItem(restData(state.allFormsData, "type"));
|
||||
|
||||
if (!state.ballotName) {
|
||||
return message.warning("请输入投票名称");
|
||||
}
|
||||
// 校验s
|
||||
|
||||
// 校验
|
||||
if (!checkVal(filterData)) {
|
||||
return false;
|
||||
}
|
||||
// checkVal(filterData);
|
||||
console.log(12121212);
|
||||
console.log(filterData);
|
||||
|
||||
@@ -356,105 +330,71 @@ export default {
|
||||
ballotName: state.ballotName,
|
||||
...filterData,
|
||||
};
|
||||
/*
|
||||
resultPost = deepCloneFilterString(resultPost, [
|
||||
"assessmentMaxScore",
|
||||
"assessmentMinScore",
|
||||
]);
|
||||
]);*/
|
||||
console.log(1212334);
|
||||
console.log(resultPost);
|
||||
editResearchMessage(resultPost).then((res) => {
|
||||
api.updateStemMessage(resultPost).then((res) => {
|
||||
if (res.data.code === 200) {
|
||||
state.ballotId=res.data.data.ballotId
|
||||
console.log("res.data.data==============",res.data.data);
|
||||
console.log("res.state.ballotId==============",state.ballotId);
|
||||
message.success("编辑成功");
|
||||
router.push({
|
||||
path: "/researchmanage",
|
||||
});
|
||||
closeDrawer();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
resultPost = {
|
||||
ballotName: state.ballotNameNew,
|
||||
assessmentMark: state.valueMore,
|
||||
ballotName: state.ballotName,
|
||||
...filterData,
|
||||
};
|
||||
/*
|
||||
resultPost = deepCloneFilterString(resultPost, [
|
||||
"assessmentMaxScore",
|
||||
"assessmentMinScore",
|
||||
]);
|
||||
createOptionMessage(resultPost).then((res) => {
|
||||
]);*/
|
||||
|
||||
console.log("=========",resultPost);
|
||||
api.createStemMessage(resultPost).then((res) => {
|
||||
if (res.data.code === 200) {
|
||||
state.ballotId=res.data.data.ballotId
|
||||
console.log("res.data.data2==============",res.data.data);
|
||||
console.log("res.state.ballotId=2s=============",state.ballotId);
|
||||
message.success("创建成功");
|
||||
|
||||
closeDrawer();
|
||||
}
|
||||
});
|
||||
}
|
||||
*/
|
||||
|
||||
};
|
||||
const handleAllCancel = () => {
|
||||
state.allFormsData = [];
|
||||
};
|
||||
/**
|
||||
|
||||
const checkVal = (filterData) => {
|
||||
// 问答
|
||||
if (
|
||||
filterData.assessmentEssayQuestionDtoList &&
|
||||
filterData.assessmentEssayQuestionDtoList.length
|
||||
) {
|
||||
let arr = filterData.assessmentEssayQuestionDtoList;
|
||||
for (let item of arr) {
|
||||
if (!item.assessmentQaTitle) {
|
||||
message.error("问答题干为必填 请确认");
|
||||
console.log("filterData.====",filterData);
|
||||
console.log("filterData.voteStemVoList====",filterData.voteStemDtoList);
|
||||
|
||||
if(!filterData.voteStemDtoList){
|
||||
message.error("请添加题干");
|
||||
return false;
|
||||
}
|
||||
let arr = filterData.voteStemDtoList;
|
||||
arr.forEach((item) => {
|
||||
console.log("item===",item);
|
||||
console.log("!item.voteStemName===",!item.voteStemName);
|
||||
if (!item.voteStemName) {
|
||||
console.log("item.voteStemName===",item.voteStemName);
|
||||
message.error("题干为必填 请确认",item.voteStemName);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
// 多选
|
||||
if (
|
||||
filterData.assessmentMultipleChoiceDtoList &&
|
||||
filterData.assessmentMultipleChoiceDtoList.length
|
||||
) {
|
||||
let arr = filterData.assessmentMultipleChoiceDtoList;
|
||||
for (let item of arr) {
|
||||
if (!item.multipleStemName) {
|
||||
message.error("多选题干为必填 请确认");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
// 评分
|
||||
if (
|
||||
filterData.assessmentScoringQuestionDtoList &&
|
||||
filterData.assessmentScoringQuestionDtoList.length
|
||||
) {
|
||||
let CountNum = 0;
|
||||
let CountArr = filterData.assessmentScoringQuestionDtoList;
|
||||
for (let item of CountArr) {
|
||||
if (!item.assessmentScTitle) {
|
||||
message.error("评分题干为必填 请确认");
|
||||
return false;
|
||||
}
|
||||
CountNum += Number(item["weightScale"]);
|
||||
}
|
||||
if (CountNum !== 100) {
|
||||
message.error("当前权重设置是百分制 请重新配置");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// 单选
|
||||
if (
|
||||
filterData.assessmentSingleChoiceDtoList &&
|
||||
filterData.assessmentSingleChoiceDtoList.length
|
||||
) {
|
||||
let arr = filterData.assessmentSingleChoiceDtoList;
|
||||
for (let item of arr) {
|
||||
if (!item.singleStemName) {
|
||||
message.error("单选题干为必填 请确认");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
return true;
|
||||
};
|
||||
*/
|
||||
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
|
||||
Reference in New Issue
Block a user