天波h5前端应用
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

346 lines
7.0KB

  1. <template>
  2. <div class="page" v-if="topic.length">
  3. <div class="top">
  4. <div class="schedule">
  5. <div class="progress">
  6. <van-progress
  7. :percentage="
  8. (select.length == 0 ? 0 : select.length / topic.length) * 100
  9. "
  10. stroke-width="10px"
  11. color="#638ee4"
  12. :show-pivot="false"
  13. v-if="topic.length"
  14. ></van-progress>
  15. </div>
  16. <div class="text">
  17. <span class="val">{{ select.length }}</span
  18. >/<span class="total">{{ topic.length }}</span>
  19. </div>
  20. </div>
  21. <div class="title">{{ title }}</div>
  22. </div>
  23. <div class="list_box">
  24. <div class="item" v-for="(item, index) in topic" :key="index">
  25. <div class="label">
  26. <span>{{ item.Title }}</span>
  27. <span>({{ item.Type }})</span>
  28. </div>
  29. <van-radio-group
  30. class="radio"
  31. v-model="item.select"
  32. v-if="item.Type == '单选题'"
  33. >
  34. <van-cell-group>
  35. <van-cell
  36. clickable
  37. v-for="(ite, idx) in item.Option"
  38. :key="idx"
  39. :title="ite.label"
  40. @click="onRadio(index, ite.value)"
  41. >
  42. <template #right-icon>
  43. <van-radio :name="ite.value" />
  44. </template>
  45. </van-cell>
  46. </van-cell-group>
  47. </van-radio-group>
  48. <van-checkbox-group class="checkbox" v-model="item.select" v-else>
  49. <van-cell-group>
  50. <van-cell
  51. v-for="(ite, idx) in item.Option"
  52. clickable
  53. :key="idx"
  54. :title="ite.label"
  55. @click="onCheckbox(`checkboxes${item.QId}`, idx)"
  56. >
  57. <template #right-icon>
  58. <van-checkbox
  59. :name="ite.value"
  60. :ref="`checkboxes${item.QId}`"
  61. />
  62. </template>
  63. </van-cell>
  64. </van-cell-group>
  65. </van-checkbox-group>
  66. </div>
  67. </div>
  68. <div class="button">
  69. <van-button
  70. round
  71. type="info"
  72. :disabled="topic.length != select.length"
  73. style="width: 100%; height: 100%"
  74. @click="submit"
  75. >提交问卷</van-button
  76. >
  77. </div>
  78. </div>
  79. </template>
  80. <script>
  81. import axios from 'axios'
  82. export default {
  83. name: 'PsychologicalModeling',
  84. data() {
  85. return {
  86. uid: '',
  87. keyCode: '',
  88. title: '',
  89. topic: [], //题目列表
  90. select: [],
  91. }
  92. },
  93. mounted() {
  94. //页面标题
  95. window.document.title = '情绪初始化评估'
  96. //页面传参
  97. let params = { ...this.$route.query }
  98. if (params.uid) {
  99. this.uid = params.uid
  100. //初始化
  101. this.init()
  102. } else {
  103. this.$toast('参数错误')
  104. }
  105. },
  106. watch: {
  107. selects(val) {
  108. let temp = JSON.parse(val)
  109. let tempt = temp.filter((item) => {
  110. if (item.select) {
  111. return true
  112. }
  113. })
  114. this.select = tempt
  115. },
  116. },
  117. computed: {
  118. selects() {
  119. return JSON.stringify(this.topic)
  120. },
  121. },
  122. methods: {
  123. async init() {
  124. let re = await this.api('/api/Question/Get', {
  125. method: 'GET',
  126. sslVerify: false,
  127. withCredentials: false,
  128. params: {
  129. // uid: this.uid,
  130. },
  131. }, this.$store.getters.ssjlToken)
  132. if (re.success) {
  133. if (re.response && re.response.length) {
  134. let temp = re.response[0]
  135. let code = temp.Code
  136. this.title = temp.Memo
  137. this.keyCode = temp.Code
  138. let re1 = await this.api('/api/Question/GetQuestion', {
  139. method: 'GET',
  140. sslVerify: false,
  141. withCredentials: false,
  142. params: {
  143. code: code,
  144. },
  145. }, this.$store.getters.ssjlToken)
  146. if (re1.success) {
  147. if (re1.response && re1.response.length) {
  148. let topic = []
  149. re1.response.forEach((item) => {
  150. let tempt = { ...item }
  151. let a1 = tempt.Option.split('#&')
  152. let option = []
  153. for (let index = 0; index < a1.length; index++) {
  154. option.push({
  155. label: a1[index],
  156. value: index + 1,
  157. })
  158. }
  159. tempt.Option = option
  160. tempt.value = ''
  161. topic.push(tempt)
  162. })
  163. this.topic = topic
  164. } else {
  165. this.$toast('问卷暂无题目')
  166. }
  167. } else {
  168. this.$toast(re1.msg)
  169. }
  170. } else {
  171. this.$toast('问卷不存在')
  172. }
  173. } else {
  174. this.$toast(re.msg)
  175. }
  176. },
  177. async submit() {
  178. let temp = {
  179. uid: this.uid, //客户端系统用户id
  180. keyCode: this.keyCode, //问卷编号
  181. answer: [],
  182. }
  183. this.topic.forEach((item) => {
  184. temp.answer.push({
  185. qid: item.QId, //问卷题目编号
  186. value:
  187. typeof item.select == 'object'
  188. ? item.select.join(',')
  189. : item.select, //用户所选答案的 id
  190. })
  191. })
  192. let re = await this.api('/api/Question/Rsults', {
  193. method: 'POST',
  194. sslVerify: false,
  195. withCredentials: false,
  196. data: temp,
  197. }, this.$store.getters.ssjlToken)
  198. if (re.success) {
  199. this.$toast('问卷提交成功', 3000)
  200. setTimeout(() => {
  201. window.history.back(-1)
  202. }, 3000)
  203. } else {
  204. this.$toast(re.msg)
  205. }
  206. },
  207. onRadio(index, value) {
  208. let temp = { ...this.topic[index] }
  209. temp.select = value
  210. this.$set(this.topic, index, temp)
  211. },
  212. onCheckbox(key, index) {
  213. try {
  214. this.$refs[`${key}`][index].toggle()
  215. } catch (error) {
  216. console.log(error)
  217. }
  218. },
  219. api(url, config, token) {
  220. setTimeout(() => {
  221. this.$toast.loading({
  222. message: '',
  223. forbidClick: true,
  224. duration: 1500,
  225. })
  226. }, 100)
  227. let baseUrl = process.env.NODE_ENV === 'production' ? 'https://dbmq.rzliot.com/auth_heart' : 'https://dbmq.rzliot.com/heart';
  228. return new Promise((res) => {
  229. axios({
  230. url: `${baseUrl}${url}`,
  231. ...config,
  232. // 增加请求头部 token
  233. headers: {
  234. 'AccessToken': token
  235. }
  236. })
  237. .then((re) => {
  238. if (re) {
  239. if (re.data) {
  240. console.log(re.data)
  241. res(re.data)
  242. this.$toast.clear()
  243. return
  244. }
  245. this.$toast(`信息获取失败-${re.status}`)
  246. res(true)
  247. this.$toast.clear()
  248. return
  249. }
  250. this.$toast(`信息获取失败-${url}`)
  251. res(true)
  252. this.$toast.clear()
  253. })
  254. .catch((e) => {
  255. this.$toast(`信息获取失败-${url}`)
  256. res(true)
  257. this.$toast.clear()
  258. console.log(e)
  259. })
  260. })
  261. },
  262. },
  263. }
  264. </script>
  265. <style lang="scss" scoped>
  266. .page {
  267. width: 100%;
  268. min-height: 100%;
  269. box-sizing: border-box;
  270. font-size: 3.6vw;
  271. text-align: left;
  272. background: #f4f4f4;
  273. padding-bottom: 8vw;
  274. padding-top: 24vw;
  275. .top {
  276. box-sizing: border-box;
  277. position: fixed;
  278. top: 0;
  279. display: flex;
  280. flex-direction: column;
  281. justify-content: space-between;
  282. padding: 3vw;
  283. width: 100vw;
  284. height: 24vw;
  285. background: white;
  286. z-index: 99;
  287. .schedule {
  288. display: flex;
  289. align-items: center;
  290. .progress {
  291. width: 85%;
  292. }
  293. .text {
  294. width: 15%;
  295. font-size: 4.5vw;
  296. text-align: center;
  297. .val {
  298. font-size: 5vw;
  299. font-weight: bold;
  300. }
  301. }
  302. }
  303. .title {
  304. color: #638ee4;
  305. }
  306. }
  307. .list_box {
  308. width: 100%;
  309. margin-top: 3vw;
  310. .item {
  311. margin-top: 3vw;
  312. padding: 3vw;
  313. background: white;
  314. .label {
  315. font-size: 4vw;
  316. }
  317. }
  318. }
  319. .button {
  320. width: 75vw;
  321. height: 14vw;
  322. margin: 0 auto;
  323. margin-top: 8vw;
  324. .van-button--info {
  325. background-color: #638ee4;
  326. border: 1px solid #638ee4;
  327. }
  328. }
  329. }
  330. </style>