CpmdQuestionnaire.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. <script lang="ts" setup>
  2. import { queryQuestionApi, sqveQuesQuestionApi, userPlanDetailApi } from '@/api/home';
  3. import { userInfoStore } from '@/stores';
  4. import Plan from '@/views/Plan.vue';
  5. import { Model } from 'echarts';
  6. import { ElMessage } from 'element-plus';
  7. import { format } from 'date-fns/format';
  8. import { ref, defineExpose, reactive, defineEmits } from 'vue'
  9. import { useRouter } from 'vue-router'
  10. const router = useRouter()
  11. const userInfo = userInfoStore()
  12. const dialogVisible = ref<boolean>(false)
  13. //设置防止重复点击的事件
  14. const isLock = ref<boolean>(false)
  15. const ruleForm = reactive<any>({
  16. //是否是少数民族
  17. isMinority: false,
  18. //出生年月
  19. birthday: '',
  20. //是否是独生子女
  21. isOnlyChild: false,
  22. //父母婚姻状况
  23. matrimony: 1,
  24. //异常体质
  25. abnormal: '',
  26. //吸烟程度
  27. smoking: '',
  28. //饮酒程度
  29. drink: '',
  30. //您在成长过程中是否有过被寄养在别人家的经历
  31. isFoster: false,
  32. //您在成长过程中是否有过超过六个月的留守经历
  33. isLeftBehind: false,
  34. //有无经济压力
  35. economy: false,
  36. //有无学业压力
  37. schoolWork: false,
  38. //有无就业压力
  39. job: false,
  40. //是否迷茫
  41. confused: false
  42. })
  43. //子组件调用父组件的方法
  44. const emit = defineEmits(['continueFun'])
  45. const visible = ref<boolean>(false)
  46. const questionList = ref<any>()
  47. //调用接口 查询问卷调查项的接口
  48. const queryQuestion = async (planId: string) => {
  49. //
  50. questionList.value = [];
  51. console.log(userInfo.userInfo.roleType)
  52. let paramsNum = ''
  53. if (userInfo.userInfo.roleType == '2') {
  54. paramsNum = '1'
  55. }
  56. if (userInfo.userInfo.roleType == '1') {
  57. paramsNum = '0'
  58. }
  59. //查询当前用户登录类型
  60. let list: any = await queryQuestionApi(paramsNum)
  61. for (let i = 0; i < list.data.length; i++) {
  62. let obj = {
  63. quesId: list.data[i].id,
  64. optionValue: "",//问题已选的答案
  65. idMandatory: list.data[i].idMandatory,
  66. mulValue: list.data[i].optionValue.split(';'),//全部备选答案
  67. orgNo: userInfo.userInfo.orgNo,//组织编号
  68. planId: planId,//计划ID
  69. quesName: list.data[i].name,//计划问题
  70. quesType: list.data[i].quesType,//问题类型
  71. sortValue: list.data[i].sortValue,//排序值
  72. topicType: list.data[i].topicType,//本题类型
  73. userName: userInfo.userInfo.userName,//用户姓名
  74. userNo: userInfo.userInfo.userNo,//用户编号
  75. }
  76. questionList.value.push(obj)
  77. }
  78. //从此得到返回列表
  79. }
  80. //提交答案时校验
  81. const submitQuestion = () => {
  82. //如果已经上锁---则直接退出
  83. if (isLock.value) {
  84. return
  85. }
  86. isLock.value = true;
  87. for (let i = 0; i < questionList.value.length; i++) {
  88. if (questionList.value[i].topicType == '3' && questionList.value[i].optionValue != '') {
  89. //格式化时间格式
  90. questionList.value[i].optionValue = format(questionList.value[i].optionValue, "yyyy-MM-dd");
  91. }
  92. if (questionList.value[i].idMandatory == '1') {
  93. if (questionList.value[i].optionValue == '') {
  94. ElMessage({
  95. message: `请完成必选项:${questionList.value[i].quesName}`,
  96. type: 'error'
  97. })
  98. isLock.value = false;
  99. return
  100. }
  101. }
  102. }
  103. //调用保存的接口
  104. //保存接口
  105. saveQuesQuestion()
  106. }
  107. const comT = () => {
  108. if (transmitType.value == '0') {
  109. //跳转到测试计划页面
  110. router.push({ name: 'plan' })
  111. } else if (transmitType.value == '1') {
  112. //调用父组件接口
  113. emit('continueFun')
  114. } else {
  115. //跳转到测试计划页面
  116. router.push({ name: 'plan' })
  117. }
  118. }
  119. //保存问卷接口
  120. //设置一个防止重复调用的接口
  121. const saveQuesQuestion = async () => {
  122. let res: any = await sqveQuesQuestionApi(questionList.value)
  123. if (res.code == 200) {
  124. //跳转到测试计划
  125. ElMessage({
  126. type: 'success',
  127. message: '提交完成'
  128. })
  129. dialogVisible.value = false
  130. visible.value = true
  131. }
  132. //当前的标志是---为0时 需要
  133. // if (transmitType.value == '0') {
  134. // //都需要弹出--弹出框
  135. // }
  136. //提交完成后、弹出框提示是进入测试计划页面----还是直接开始测试页面
  137. //弹出框进行提示
  138. //是否跳转到测试计划页面
  139. //是否弹出测试计划页面
  140. //是否弹出开始测试弹出框
  141. isLock.value = false;
  142. }
  143. const disbledData = (time: any) => {
  144. return time.getTime() >= Date.now()
  145. }
  146. const transmitType = ref('')
  147. const open = (planId: string, type: string) => {
  148. dialogVisible.value = true
  149. transmitType.value = type
  150. //拿到登录用户的信息
  151. queryQuestion(planId)
  152. }
  153. //
  154. defineExpose({ open })
  155. </script>
  156. <template>
  157. <el-dialog v-model="dialogVisible" title="" width="600px" top="15vh">
  158. <template #header>
  159. <p style="text-align: center;font-weight: 700;">问卷填写</p>
  160. </template>
  161. <span style="height: 60vh;display: flex;overflow-y: auto;padding:0px 20px">
  162. <div v-if="questionList.length > 0">
  163. <div v-for="item, index in questionList" :key="item.id" class="question_out">
  164. <div class="title_out">{{ index + 1 }}:
  165. <span class="xing">{{ item.idMandatory == '1' ? '*' : '' }}</span><span>{{
  166. item.quesName }}</span>
  167. </div>
  168. <el-radio-group v-model="item.optionValue" v-if="item.topicType == '1'" class="question_radio">
  169. <el-radio :label="ch" v-for="ch in item.mulValue" :key="ch"></el-radio>
  170. <!-- <el-radio label="线下场地免费"></el-radio> -->
  171. </el-radio-group>
  172. <el-date-picker v-model="item.optionValue" type="date" placeholder="选择出生年月" class="question_radio"
  173. v-if="item.topicType == '3'" :disabled-date="disbledData" />
  174. </div>
  175. </div>
  176. </span>
  177. <template #footer>
  178. <div class="footer_cus">
  179. <div class="start_button_out_close">
  180. <div class="start_button_self_close" @click="dialogVisible = false">
  181. <span>关闭</span>
  182. </div>
  183. </div>
  184. <!-- <el-button type="primary" @click="submitQuestion">
  185. 提交
  186. </el-button> -->
  187. <div class="start_button_out">
  188. <div class="start_button_self" @click="submitQuestion">
  189. <span>提交</span>
  190. </div>
  191. </div>
  192. <!-- <div>
  193. 提交
  194. </div> -->
  195. </div>
  196. </template>
  197. </el-dialog>
  198. <!-- //另一个框 弹出确认是否跳转 -->
  199. <el-dialog v-model="visible" :show-close="true" width="500" style="border-radius: 20px;">
  200. <template #header>
  201. <div class="my-header" style="text-align: center;">
  202. <div class="exit_login_title">提示</div>
  203. <div class="exit_login_info" v-if="transmitType == '0'">是否跳转到测试计划页面?</div>
  204. <div class="exit_login_info" v-if="transmitType == '1'">是否直接开始测试计划?</div>
  205. <div class="start_button_out" style="margin-top:20px;display: flex;justify-content: space-around;">
  206. <div class="start_button_self_close" @click="visible = false">
  207. 取消
  208. </div>
  209. <div class="start_button_self" @click="comT">
  210. 确定
  211. </div>
  212. </div>
  213. </div>
  214. </template>
  215. </el-dialog>
  216. </template>
  217. <style lang="scss">
  218. .el-dialog {
  219. border-radius: 20px;
  220. }
  221. .footer_cus {
  222. display: flex;
  223. justify-content: space-around;
  224. }
  225. .exit_login_title {
  226. text-align: center;
  227. color: #222222;
  228. font-weight: 700;
  229. font-size: 20px;
  230. letter-spacing: 3px;
  231. }
  232. .exit_login_info {
  233. text-align: center;
  234. letter-spacing: 3px;
  235. font-size: 18px;
  236. margin-top: 20px;
  237. }
  238. .start_button_out {
  239. // margin-top: 40px;
  240. // margin-bottom: 40px;
  241. display: flex;
  242. flex-direction: row;
  243. justify-content: end;
  244. .start_button_self_close {
  245. cursor: pointer;
  246. // width: 100px;
  247. border-radius: 12px;
  248. border: 1px solid #dddddd;
  249. color: #000000;
  250. background-color: #ffffff;
  251. margin-right: 20px;
  252. padding: 8px 20px;
  253. cursor: pointer;
  254. display: flex;
  255. align-items: center;
  256. }
  257. .start_button_self {
  258. cursor: pointer;
  259. // width: 100px;
  260. border-radius: 12px;
  261. border: 3px solid #48D68E;
  262. color: #ffffff;
  263. background-color: #000000;
  264. margin-right: 20px;
  265. padding: 8px 20px;
  266. cursor: pointer;
  267. display: flex;
  268. align-items: center;
  269. }
  270. }
  271. .start_button_out_close {
  272. // margin-top: 40px;
  273. // margin-bottom: 40px;
  274. display: flex;
  275. flex-direction: row;
  276. justify-content: end;
  277. .start_button_self_close {
  278. cursor: pointer;
  279. // width: 100px;
  280. border-radius: 12px;
  281. border: 1px solid #dddddd;
  282. color: #000000;
  283. background-color: #ffffff;
  284. margin-right: 20px;
  285. padding: 8px 20px;
  286. cursor: pointer;
  287. display: flex;
  288. align-items: center;
  289. }
  290. }
  291. .question_out {
  292. display: flex;
  293. flex-direction: column;
  294. .title_out {
  295. display: flex;
  296. .xing {
  297. width: 10px;
  298. text-align: right;
  299. color: red;
  300. }
  301. }
  302. .question_radio {
  303. margin-top: 5px;
  304. margin-bottom: 10px;
  305. margin-left: 10px;
  306. }
  307. }
  308. </style>