questionnaire.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. <!--
  2. * @Page: 问卷调查
  3. * @Author: Fengyu
  4. * @Date: 2025-12-12 10:12:59
  5. * @LastEditors: Fengyu
  6. * @LastEditTime: 2025-12-17 11:12:47
  7. -->
  8. <template>
  9. <view class="questionnaire-container">
  10. <!-- 顶部导航栏 -->
  11. <!-- <view class="nav-bar">
  12. <view class="nav-left">
  13. <uni-icons type="left" size="32" color="#333" @click="goBack"></uni-icons>
  14. </view>
  15. <view class="nav-title">调查问卷</view>
  16. <view class="nav-right">
  17. <uni-icons type="ellipsis" size="32" color="#333"></uni-icons>
  18. <uni-icons type="eye" size="32" color="#333" class="ml10"></uni-icons>
  19. </view>
  20. </view> -->
  21. <!-- 问卷引导区域 -->
  22. <view class="guide-section">
  23. <view class="guide-content">
  24. <view class="guide-text">
  25. <view class="guide-title">问卷引导</view>
  26. <view class="guide-desc">欢迎您对我们服务区提出建议反馈,我们会对您的问题进行全程跟踪</view>
  27. </view>
  28. <view class="guide-image"></view>
  29. </view>
  30. </view>
  31. <!-- 网格选择区域 -->
  32. <view class="grid-section">
  33. <view class="grid-container">
  34. <view class="grid-item">
  35. <view class="grid-content flex j-sb a-center">
  36. <view class="grid-title">1.您所在的服务区</view>
  37. <view class="grid-desc">
  38. <u-select v-model="parkSelectShow" :list="parkList" @confirm="confirm"></u-select>
  39. <span @click="parkSelectShow = true">{{ parkName || '请选择' }}&nbsp;﹥</span>
  40. </view>
  41. </view>
  42. </view>
  43. <view v-for="(item, index) in dataFilledIn" :key="item.id" class="grid-item">
  44. <view class="grid-content">
  45. <view class="grid-title">{{ index + 2 }}. {{ item.name }}</view>
  46. <view class="grid-desc">
  47. <u-radio-group v-model="item.value">
  48. <u-radio
  49. v-for="(t, i) in options" :key="i"
  50. :name="t.value"
  51. :disabled="t.disabled"
  52. >
  53. {{t.name}}
  54. </u-radio>
  55. </u-radio-group>
  56. </view>
  57. </view>
  58. </view>
  59. <!-- 最好的高速 -->
  60. <view class="grid-item">
  61. <view class="grid-content">
  62. <view class="grid-title">{{ dataFilledIn.length + 2 }}. 您认为途经最好的高速是?</view>
  63. <view class="grid-desc">
  64. <u-input v-model="bestWay" type="textarea" :border="false" :height="100" :auto-height="true" placeholder="请输入您认为途经最好的高速" />
  65. </view>
  66. </view>
  67. </view>
  68. <!-- 最好的服务区 -->
  69. <view class="grid-item">
  70. <view class="grid-content">
  71. <view class="grid-title">{{ dataFilledIn.length + 3 }}. 您认为途经最好的服务区是?</view>
  72. <view class="grid-desc">
  73. <u-input v-model="bestService" type="textarea" :border="false" :height="100" :auto-height="true" placeholder="请输入您认为途经最好的服务区" />
  74. </view>
  75. </view>
  76. </view>
  77. <view class="grid-item">
  78. <view class="grid-content">
  79. <view class="grid-title">您的手机号:</view>
  80. <view class="grid-desc">
  81. <u-input v-model="phone" type="number" :border="false" :height="100" :maxlength="11" :auto-height="true" placeholder="请输入您的手机号" />
  82. </view>
  83. </view>
  84. </view>
  85. <view class="submit-btn" @click="submitForm">
  86. 提 交
  87. </view>
  88. </view>
  89. </view>
  90. </view>
  91. </template>
  92. <script setup>
  93. import { ref, onMounted } from 'vue'
  94. import { getQuestionnaireDetailApi, submitQuestionnaireApi, getParkList } from '@/api/investigation'
  95. const dataList = ref([
  96. {
  97. id: 1,
  98. name: '公共卫生间',
  99. value: ''
  100. },
  101. {
  102. id: 2,
  103. name: '公共区域',
  104. value: ''
  105. },
  106. {
  107. id: 3,
  108. name: '餐饮',
  109. value: ''
  110. },
  111. {
  112. id: 4,
  113. name: '便利店',
  114. value: ''
  115. },
  116. {
  117. id: 5,
  118. name: '加油(加气、充电)站',
  119. value: ''
  120. },
  121. {
  122. id: 6,
  123. name: '车辆维修站',
  124. value: ''
  125. },
  126. {
  127. id: 7,
  128. name: '对本服务区总体评价',
  129. value: ''
  130. }
  131. ])
  132. const options = ref([
  133. {
  134. name: '满意',
  135. value: 1
  136. },
  137. {
  138. name: '比较满意',
  139. value: 2
  140. },
  141. {
  142. name: '一般',
  143. value: 3
  144. },
  145. {
  146. name: '不满意',
  147. value: 4
  148. }
  149. ])
  150. // 服务区选择框是否显示
  151. const parkSelectShow = ref(false)
  152. // 服务区列表
  153. const parkList = ref([])
  154. const parkId = ref('')
  155. const parkName = ref('')
  156. const phone = ref('')
  157. // 获取服务区列表
  158. const getParkListApi = () => {
  159. getParkList().then(res => {
  160. if (res.code === 200) {
  161. parkList.value = res.data.map(item => ({
  162. label: item.name,
  163. value: item.id
  164. }))
  165. } else {
  166. uni.showToast({
  167. title: res.message || '获取服务区列表失败',
  168. icon: 'none'
  169. });
  170. }
  171. }).catch(err => {
  172. console.error('获取服务区列表失败:', err);
  173. uni.showToast({
  174. title: err.data.msg ||'网络错误,请重试',
  175. icon: 'none'
  176. });
  177. });
  178. }
  179. // 选择服务区
  180. const confirm = (e) => {
  181. console.log(e[0].value, e[0].label)
  182. parkId.value = e[0].value
  183. parkName.value = e[0].label
  184. }
  185. // 最好的高速
  186. const bestWay = ref('')
  187. // 最好的服务区
  188. const bestService = ref('')
  189. // 动态的判断是否需要显示‘车辆维修站’
  190. const dataFilledIn = ref([])
  191. // 问卷信息
  192. const questionnaireInfo = ref({
  193. // id: '',
  194. name: '',
  195. endAt: '',
  196. fileId: 0,
  197. type: 0
  198. })
  199. // 根据页面参数获取问卷详情
  200. onMounted(() => {
  201. getParkListApi()
  202. // 使用URLSearchParams正确解析URL参数
  203. const urlParams = new URLSearchParams(window.location.search);
  204. const questionnaireId = urlParams.get('id');
  205. if (!questionnaireId) {
  206. uni.showToast({
  207. title: '问卷ID参数缺失',
  208. icon: 'none'
  209. });
  210. return;
  211. }
  212. getQuestionnaireDetailApi(questionnaireId).then(res => {
  213. if (res.code === 200) {
  214. questionnaireInfo.value = res.data
  215. // 如果questionnaireInfo.value.type == 2,不显示‘车辆维修站’
  216. if (questionnaireInfo.value.type == 2) {
  217. dataFilledIn.value = dataList.value.filter(item => item.id != 6)
  218. } else {
  219. dataFilledIn.value = dataList.value
  220. }
  221. } else {
  222. uni.showToast({
  223. title: res.message || '获取问卷详情失败',
  224. icon: 'none'
  225. });
  226. }
  227. }).catch(err => {
  228. console.error('获取问卷详情失败:', err);
  229. uni.showToast({
  230. title: '网络错误,请重试',
  231. icon: 'none'
  232. });
  233. });
  234. });
  235. // 提交表单
  236. const submitForm = () => {
  237. // 检查是否所有项都有选择
  238. const isComplete = dataFilledIn.value.every(item => item.value !== '');
  239. if (!isComplete) {
  240. uni.showToast({
  241. title: '请完成所有项',
  242. icon: 'none'
  243. });
  244. return;
  245. }
  246. if (!parkId.value) {
  247. uni.showToast({
  248. title: '请选择服务区',
  249. icon: 'none'
  250. });
  251. return;
  252. }
  253. if (!phone.value) {
  254. uni.showToast({
  255. title: '请输入手机号',
  256. icon: 'none'
  257. });
  258. return;
  259. }
  260. if (!bestWay.value) {
  261. uni.showToast({
  262. title: '请输入最好的高速',
  263. icon: 'none'
  264. });
  265. return;
  266. }
  267. if (!bestService.value) {
  268. uni.showToast({
  269. title: '请输入最好的服务区',
  270. icon: 'none'
  271. });
  272. return;
  273. }
  274. // 解析URL参数
  275. const urlParams = new URLSearchParams(window.location.search);
  276. const questionnaireId = questionnaireInfo.value.id || 0;
  277. // const questionnaireId = '2000476937984221185' || 0;
  278. // const parkid = parseInt(urlParams.get('parkid')) || 0; // 与API参数名保持一致
  279. const mobile = urlParams.get('m') || '';
  280. // 验证必需参数
  281. if (!questionnaireId || !mobile) {
  282. uni.showToast({
  283. title: '参数错误,请重新进入页面',
  284. icon: 'none'
  285. });
  286. return;
  287. }
  288. // 验证手机号格式
  289. // const mobileRegex = /^1[3-9]\d{9}$/;
  290. // if (!mobileRegex.test(mobile)) {
  291. // uni.showToast({
  292. // title: '手机号格式不正确',
  293. // icon: 'none'
  294. // });
  295. // return;
  296. // }
  297. // 转换评分数据为targetA-G格式,确保为整数类型
  298. const scoreData = {
  299. targetA: parseInt(dataFilledIn.value.find(item => item.id === 1)?.value) || 0, // 公共卫生间
  300. targetB: parseInt(dataFilledIn.value.find(item => item.id === 2)?.value) || 0, // 公共区域
  301. targetC: parseInt(dataFilledIn.value.find(item => item.id === 3)?.value) || 0, // 餐饮
  302. targetD: parseInt(dataFilledIn.value.find(item => item.id === 4)?.value) || 0, // 便利店
  303. targetE: parseInt(dataFilledIn.value.find(item => item.id === 5)?.value) || 0, // 加油(加气、充电)站
  304. targetF: parseInt(dataFilledIn.value.find(item => item.id === 6)?.value) || 0, // 车辆维修站
  305. targetG: parseInt(dataFilledIn.value.find(item => item.id === 7)?.value) || 0, // 总体评价
  306. bestWay: bestWay.value, // 最好的高速
  307. bestService: bestService.value, // 最好的服务区
  308. parkId: parkId.value,
  309. // id: questionnaireId
  310. };
  311. // 构建完整参数对象,确保与API要求一致
  312. let params = {
  313. questionnaireId,
  314. // parkid, // 使用API要求的参数名
  315. mobile: phone.value,
  316. ...scoreData
  317. };
  318. console.log('提交参数:', params);
  319. // 调用API提交表单
  320. submitQuestionnaireApi(params).then(res => {
  321. if (res.code === 200) {
  322. uni.showToast({
  323. title: '感谢您的反馈!',
  324. icon: 'success'
  325. });
  326. setTimeout(() => {
  327. uni.switchTab({
  328. url: '/pages/index'
  329. })
  330. }, 2000);
  331. } else {
  332. uni.showToast({
  333. title: res.message || '提交失败,请重试',
  334. icon: 'none'
  335. });
  336. }
  337. }).catch(err => {
  338. console.error('提交失败:', err);
  339. uni.showToast({
  340. title: err.data.msg || '操作失败',
  341. icon: 'none'
  342. });
  343. });
  344. }
  345. </script>
  346. <style lang="scss" scoped>
  347. .questionnaire-container {
  348. width: 100%;
  349. min-height: 100vh;
  350. background-color: #f5f7fa;
  351. }
  352. /* 导航栏 */
  353. .nav-bar {
  354. display: flex;
  355. align-items: center;
  356. justify-content: space-between;
  357. padding: 20rpx 30rpx;
  358. background-color: #fff;
  359. }
  360. .nav-left,
  361. .nav-right {
  362. display: flex;
  363. align-items: center;
  364. }
  365. .nav-title {
  366. font-size: 32rpx;
  367. font-weight: 600;
  368. color: #333;
  369. }
  370. /* 问卷引导区域 */
  371. .guide-section {
  372. width: 100%;
  373. height: 100vh;
  374. /* 从上到下渐变样式 */
  375. background: linear-gradient(to bottom, #9ED9FC, #F0F8FB 40%);
  376. padding: 40rpx 30rpx;
  377. position: absolute;
  378. top: 0;
  379. left: 0;
  380. z-index: 2;
  381. margin-bottom: 40rpx;
  382. }
  383. .guide-content {
  384. display: flex;
  385. align-items: center;
  386. justify-content: space-between;
  387. }
  388. .guide-text {
  389. flex: 1;
  390. /* color: #fff; */
  391. }
  392. .guide-title {
  393. font-size: 32rpx;
  394. font-weight: 600;
  395. margin-bottom: 20rpx;
  396. }
  397. .guide-desc {
  398. font-size: 24rpx;
  399. line-height: 36rpx;
  400. }
  401. .guide-image {
  402. width: 300rpx;
  403. height: 300rpx;
  404. background: url('@/static/images/wenjuan.png') no-repeat center center;
  405. background-size: 100%;
  406. }
  407. .guide-image image {
  408. width: 100%;
  409. height: 100%;
  410. }
  411. /* 网格选择区域 */
  412. .grid-section {
  413. width: 90%;
  414. /* height: 80vh; */
  415. margin: 0 auto;
  416. background-color: #fff;
  417. position: relative;
  418. top: 24vh;
  419. z-index: 3;
  420. border-radius: 20rpx;
  421. }
  422. .grid-container {
  423. /* display: grid;
  424. grid-template-columns: repeat(5, 1fr);
  425. gap: 30rpx; */
  426. display: flex;
  427. flex-direction: column;
  428. margin-bottom: 40rpx;
  429. .grid-content {
  430. .grid-title {
  431. font-size: 28rpx;
  432. font-weight: 600;
  433. margin-bottom: 20rpx;
  434. }
  435. }
  436. // 提交按钮
  437. .submit-btn {
  438. width: 100%;
  439. height: 80rpx;
  440. line-height: 80rpx;
  441. text-align: center;
  442. font-size: 32rpx;
  443. font-weight: 600;
  444. color: #fff;
  445. background: linear-gradient(to bottom, #7EBBF5, #4B9EF6);
  446. border-radius: 10rpx;
  447. margin-top: 40rpx;
  448. // position: absolute;
  449. // bottom: 0;
  450. // left: 0;
  451. // z-index: 3;
  452. }
  453. }
  454. .grid-item {
  455. width: 100%;
  456. background-color: #fff;
  457. padding: 10px;
  458. /* border: 2rpx solid #e4e7ed; */
  459. border-radius: 10rpx;
  460. box-sizing: border-box;
  461. position: relative;
  462. transition: all 0.3s ease;
  463. }
  464. .grid-item-selected {
  465. background-color: #479bfa;
  466. border-color: #479bfa;
  467. }
  468. /* 换一换按钮 */
  469. .refresh-btn {
  470. display: flex;
  471. justify-content: center;
  472. }
  473. </style>