天波h5前端应用
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

index.vue 9.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  1. <template>
  2. <div
  3. class="page"
  4. v-if="topic.length"
  5. :style="`padding-top: ${showLeftArrow ? 'calc(24vw + 46px)' : '24vw'};`"
  6. >
  7. <van-nav-bar
  8. title="测评"
  9. :border="true"
  10. :left-arrow="true"
  11. @click-left="onNavBack"
  12. v-if="showLeftArrow"
  13. style="position: fixed; left: 0; top: 0; width: 100vw"
  14. >
  15. <template #left>
  16. <van-icon name="arrow-left" size="23" style="padding: 0" />返回
  17. </template>
  18. </van-nav-bar>
  19. <div class="top" :style="`top: ${showLeftArrow ? '46px' : '0'};`">
  20. <div class="schedule">
  21. <div class="progress">
  22. <van-progress
  23. :percentage="
  24. (select.length == 0 ? 0 : select.length / topic.length) * 100
  25. "
  26. stroke-width="10px"
  27. color="#638ee4"
  28. :show-pivot="false"
  29. v-if="topic.length"
  30. ></van-progress>
  31. </div>
  32. <div class="text">
  33. <span class="val">{{ select.length }}</span
  34. >/<span class="total">{{ topic.length }}</span>
  35. </div>
  36. </div>
  37. <div class="title">{{ title }}</div>
  38. </div>
  39. <div class="list_box">
  40. <div class="item" v-for="(item, index) in topic" :key="index">
  41. <div
  42. :class="[
  43. 'label',
  44. {
  45. error:
  46. (isError && fromSsjl && item.Id == '6') ||
  47. (isError && fromSsjl && item.Id == '8') ||
  48. (isError && fromSsjl && item.Id == '11'),
  49. },
  50. ]"
  51. >
  52. <span>{{ item.Title }}</span>
  53. <span>({{ item.Type }})</span>
  54. </div>
  55. <van-radio-group
  56. class="radio"
  57. v-model="item.select"
  58. v-if="item.Type == '单选题'"
  59. >
  60. <van-cell-group>
  61. <van-cell
  62. clickable
  63. v-for="(ite, idx) in item.Option"
  64. :key="idx"
  65. :title="ite.label"
  66. @click="onRadio(index, ite.value)"
  67. :title-class="[
  68. {
  69. cellTitle:
  70. (isError && fromSsjl && item.Id == '6') ||
  71. (isError && fromSsjl && item.Id == '8') ||
  72. (isError && fromSsjl && item.Id == '11'),
  73. },
  74. ]"
  75. >
  76. <template #right-icon>
  77. <van-radio :name="ite.value" />
  78. </template>
  79. </van-cell>
  80. </van-cell-group>
  81. </van-radio-group>
  82. <van-checkbox-group class="checkbox" v-model="item.select" v-else>
  83. <van-cell-group>
  84. <van-cell
  85. v-for="(ite, idx) in item.Option"
  86. clickable
  87. :key="idx"
  88. :title="ite.label"
  89. @click="onCheckbox(`checkboxes${item.Id}`, idx)"
  90. >
  91. <template #right-icon>
  92. <van-checkbox :name="ite.value" :ref="`checkboxes${item.Id}`" />
  93. </template>
  94. </van-cell>
  95. </van-cell-group>
  96. </van-checkbox-group>
  97. </div>
  98. </div>
  99. <div class="button">
  100. <van-button
  101. round
  102. type="info"
  103. :disabled="topic.length != select.length"
  104. style="width: 100%; height: 100%"
  105. @click="submit"
  106. >提交测评</van-button
  107. >
  108. </div>
  109. </div>
  110. </template>
  111. <script>
  112. import axios from 'axios'
  113. import APICore from '@/api/core'
  114. export default {
  115. name: 'PsychologicalScale',
  116. data() {
  117. return {
  118. uid: '',
  119. keyCode: '',
  120. title: '',
  121. topic: [], //题目列表
  122. select: [],
  123. isError: null, //是否是答题错误
  124. fromSsjl: this.$store.getters.fromSsjl,
  125. showLeftArrow: false,
  126. isModel: false,
  127. }
  128. },
  129. mounted() {
  130. //页面标题
  131. window.document.title = '测评'
  132. //页面传参
  133. let params = { ...this.$route.query }
  134. if (params.uid) {
  135. this.uid = params.uid
  136. // 缓存从随手精灵传过来的token
  137. this.$store.commit('ssjlToken', params.accessToken || '')
  138. if (params.appType) {
  139. this.$store.commit('appType', params.appType)
  140. }
  141. // 缓存从随手精灵传过来的标识
  142. this.$store.commit('fromSsjl', params.fromSsjl)
  143. // 是否显示 返回标签
  144. if (params.showLeftArrow) {
  145. this.showLeftArrow = true
  146. }
  147. this.fromUrl = params.fromUrl
  148. console.log('fromUrl', this.fromUrl)
  149. // 是否从建模页过来
  150. if (params.isModel) {
  151. this.isModel = true
  152. }
  153. //初始化
  154. this.init()
  155. } else {
  156. this.$toast('参数错误')
  157. }
  158. },
  159. watch: {
  160. selects(val) {
  161. let temp = JSON.parse(val)
  162. let tempt = temp.filter((item) => {
  163. if (item.select >= 0) {
  164. return true
  165. }
  166. })
  167. this.select = tempt
  168. },
  169. },
  170. computed: {
  171. selects() {
  172. return JSON.stringify(this.topic)
  173. },
  174. },
  175. methods: {
  176. async init() {
  177. if (!this.$route.query.accessToken) {
  178. // 如果当前url没有 accessToken, 获取token,并且存储到本地缓存里面
  179. let authToken = await this.getAuth()
  180. this.$store.commit('ssjlToken', authToken)
  181. }
  182. let re = await this.api(
  183. '/api/Question/GetScaleQuestion',
  184. {
  185. method: 'GET',
  186. sslVerify: false,
  187. withCredentials: false,
  188. params: {
  189. // uid: this.uid,
  190. code: 'EPDS',
  191. },
  192. },
  193. this.$store.getters.ssjlToken
  194. )
  195. if (re.success) {
  196. if (
  197. re.response &&
  198. re.response.ScaleQuestionDetails &&
  199. re.response.ScaleQuestionDetails.length
  200. ) {
  201. let code = re.response.Code
  202. this.title = re.response.Name
  203. this.keyCode = re.response.Code
  204. let temp = re.response.ScaleQuestionDetails
  205. let topic = []
  206. temp.forEach((item) => {
  207. let tempt = { ...item }
  208. if (!tempt.Type) {
  209. tempt.Type = '单选题'
  210. }
  211. let a1 = tempt.Option.split('&')
  212. let option = []
  213. for (let index = 0; index < a1.length; index++) {
  214. option.push({
  215. label: a1[index],
  216. value: index,
  217. })
  218. }
  219. tempt.Option = option
  220. tempt.value = ''
  221. topic.push(tempt)
  222. })
  223. this.topic = topic
  224. } else {
  225. this.$toast('问卷不存在')
  226. }
  227. } else {
  228. this.$toast(re.msg)
  229. }
  230. },
  231. async submit() {
  232. let temp = {
  233. uid: this.uid, //客户端系统用户id
  234. keyCode: this.keyCode, //问卷编号
  235. answer: [],
  236. }
  237. this.topic.forEach((item) => {
  238. temp.answer.push({
  239. qid: item.Id, //问卷题目编号
  240. value:
  241. typeof item.select == 'object'
  242. ? item.select.join(',')
  243. : item.select, //用户所选答案的 id
  244. })
  245. })
  246. let re = await this.api(
  247. '/api/Question/ScaleRsults',
  248. {
  249. method: 'POST',
  250. sslVerify: false,
  251. withCredentials: false,
  252. data: temp,
  253. },
  254. this.$store.getters.ssjlToken
  255. )
  256. if (re.success && re.response) {
  257. this.$toast('问卷提交成功', 3000)
  258. this.isError = false
  259. setTimeout(() => {
  260. if (this.isModel) {
  261. // 建模页跳转过来的要回建模页
  262. this.$router.replace({
  263. name: 'PsychologicalModeling',
  264. query: {
  265. uid: this.uid,
  266. },
  267. })
  268. } else {
  269. this.$router.replace({
  270. name: 'PsychologicalScaleDetail',
  271. query: {
  272. id: re.response.Id,
  273. uid: this.uid,
  274. accessToken: this.$store.getters.ssjlToken,
  275. showLeftArrow: this.showLeftArrow,
  276. },
  277. })
  278. }
  279. }, 3000)
  280. } else {
  281. //this.$toast(re.msg);
  282. this.$dialog.confirm({
  283. message: re.msg,
  284. showCancelButton: false,
  285. })
  286. this.isError = true
  287. }
  288. },
  289. onRadio(index, value) {
  290. let temp = { ...this.topic[index] }
  291. temp.select = value
  292. this.$set(this.topic, index, temp)
  293. },
  294. onCheckbox(key, index) {
  295. try {
  296. this.$refs[`${key}`][index].toggle()
  297. } catch (error) {
  298. console.log(error)
  299. }
  300. },
  301. onNavBack() {
  302. let fromSsjl = this.$store.getters.fromSsjl === 'true'
  303. if (fromSsjl) {
  304. let baseUrl = this.fromUrl
  305. window.location.href = `${baseUrl}/#/${
  306. this.$route.query.fromMenu || 'device'
  307. }`
  308. } else {
  309. window.history.go(-1)
  310. }
  311. },
  312. // 获取b端token
  313. getAuth() {
  314. let manufactorId = '5bf13062-a41e-4d00-ba14-1101aad12650'
  315. let that = this
  316. return new Promise((resolve, reject) => {
  317. APICore.getAuth({ manufactorId: manufactorId }).then((res) => {
  318. let data = res.data
  319. if (data.code === 0) {
  320. resolve(res.data.data)
  321. } else {
  322. that.$toast.fail(`${data.message}`)
  323. reject('')
  324. }
  325. })
  326. })
  327. },
  328. api(url, config, token) {
  329. setTimeout(() => {
  330. this.$toast.loading({
  331. message: '',
  332. forbidClick: true,
  333. duration: 1500,
  334. })
  335. }, 100)
  336. let baseUrl =
  337. process.env.NODE_ENV === 'production'
  338. ? 'https://dbmq.rzliot.com/auth_heart'
  339. : 'https://dbmq.rzliot.com/heart'
  340. return new Promise((res) => {
  341. axios({
  342. url: `${baseUrl}${url}`,
  343. ...config,
  344. // 增加请求头部 token
  345. headers: {
  346. AccessToken: token,
  347. },
  348. })
  349. .then((re) => {
  350. if (re) {
  351. if (re.data) {
  352. console.log(re.data)
  353. res(re.data)
  354. this.$toast.clear()
  355. return
  356. }
  357. this.$toast(`信息获取失败-${re.status}`)
  358. res(true)
  359. this.$toast.clear()
  360. return
  361. }
  362. this.$toast(`信息获取失败-${url}`)
  363. res(true)
  364. this.$toast.clear()
  365. })
  366. .catch((e) => {
  367. this.$toast(`信息获取失败-${url}`)
  368. res(true)
  369. this.$toast.clear()
  370. console.log(e)
  371. })
  372. })
  373. },
  374. },
  375. }
  376. </script>
  377. <style lang="scss" scoped>
  378. .page {
  379. width: 100%;
  380. min-height: 100%;
  381. box-sizing: border-box;
  382. font-size: 3.6vw;
  383. text-align: left;
  384. background: #f4f4f4;
  385. padding-bottom: 8vw;
  386. padding-top: 24vw;
  387. .top {
  388. box-sizing: border-box;
  389. position: fixed;
  390. top: 0;
  391. display: flex;
  392. flex-direction: column;
  393. justify-content: space-between;
  394. padding: 3vw;
  395. width: 100vw;
  396. height: 24vw;
  397. background: white;
  398. z-index: 99;
  399. .schedule {
  400. display: flex;
  401. align-items: center;
  402. .progress {
  403. width: 85%;
  404. }
  405. .text {
  406. width: 15%;
  407. font-size: 4.5vw;
  408. text-align: center;
  409. .val {
  410. font-size: 5vw;
  411. font-weight: bold;
  412. }
  413. }
  414. }
  415. .title {
  416. color: #638ee4;
  417. }
  418. }
  419. .list_box {
  420. width: 100%;
  421. margin-top: 3vw;
  422. .item {
  423. margin-top: 3vw;
  424. padding: 3vw;
  425. background: white;
  426. .label {
  427. font-size: 4vw;
  428. &.error {
  429. color: red;
  430. }
  431. }
  432. .van-cell {
  433. .van-cell__title {
  434. &.cellTitle {
  435. color: red;
  436. }
  437. }
  438. }
  439. }
  440. }
  441. .button {
  442. width: 75vw;
  443. height: 14vw;
  444. margin: 0 auto;
  445. margin-top: 8vw;
  446. .van-button--info {
  447. background-color: #638ee4;
  448. border: 1px solid #638ee4;
  449. }
  450. }
  451. }
  452. </style>