index.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <template>
  2. <Dialog
  3. :flag="passengerDialogFlag"
  4. width="440px"
  5. >
  6. <div
  7. id="dialogPassenger"
  8. ref="dialog"
  9. tabindex="0"
  10. v-loading="loading"
  11. element-loading-text="拼命加载中"
  12. element-loading-spinner="el-icon-loading"
  13. element-loading-background="rgba(0, 0, 0, 0.8)"
  14. @keyup.self.esc="dialogHide"
  15. >
  16. <div class="title">
  17. <span>查看旅客信息</span>
  18. <i
  19. class="el-icon-close"
  20. @click="dialogHide"
  21. />
  22. </div>
  23. <div class="content">
  24. <template v-if="!userChecked">
  25. <el-form
  26. ref="checkForm"
  27. :model="checkForm"
  28. :rules="checkRules"
  29. class="check-form"
  30. label-position="left"
  31. label-width="70px"
  32. >
  33. <el-form-item
  34. label="密码"
  35. prop="password"
  36. >
  37. <el-input
  38. ref="password"
  39. v-model="checkForm.password"
  40. show-password
  41. placeholder="密码"
  42. name="password"
  43. tabindex="1"
  44. class="password"
  45. />
  46. </el-form-item>
  47. <div class="flex-wrap">
  48. <el-form-item
  49. label="验证码"
  50. prop="verificationCode"
  51. class="flex1"
  52. >
  53. <el-input
  54. ref="verificationCode"
  55. v-model="checkForm.verificationCode"
  56. placeholder="请输入验证码"
  57. name="verificationCode"
  58. tabindex="2"
  59. @keyup.enter.native="submitHandler"
  60. />
  61. </el-form-item>
  62. <Identify
  63. :identifyCode="checkCode"
  64. style="margin-left: 24px"
  65. @changeCode="changeCode"
  66. />
  67. </div>
  68. </el-form>
  69. </template>
  70. <template v-else>
  71. <div class="passenger-info-box">
  72. <img
  73. v-show="!loading"
  74. :src="passengerImg"
  75. alt="旅客信息"
  76. title="旅客信息"
  77. class="passenger-info-img"
  78. />
  79. </div>
  80. </template>
  81. </div>
  82. <div
  83. v-if="!userChecked"
  84. class="footer"
  85. >
  86. <el-button
  87. type="primary"
  88. size="small"
  89. @click="submitHandler"
  90. >提交</el-button>
  91. <el-button
  92. size="small"
  93. @click="dialogHide"
  94. >取消</el-button>
  95. </div>
  96. </div>
  97. </Dialog>
  98. </template>
  99. <script>
  100. import Dialog from '@/layout/components/Dialog'
  101. import Identify from '@/views/login/identify'
  102. import { mapGetters } from 'vuex'
  103. import { GetCheckCode, CheckUser } from '@/api/temp'
  104. import { GetPassengerInfo } from '@/api/flight'
  105. // import { getToken } from '@/utils/auth'
  106. import MD5 from 'blueimp-md5'
  107. import '@/config/staticConfig.js'
  108. import '@/config/config.js'
  109. const noDataImage = require('@/assets/logo/nodata.png')
  110. export default {
  111. name: 'PassengerDialog',
  112. components: { Dialog, Identify },
  113. computed: {
  114. ...mapGetters([
  115. 'passengerDialogFlag',
  116. 'passengerQueryParams',
  117. 'userChecked',
  118. ]),
  119. },
  120. data() {
  121. return {
  122. checkForm: {
  123. password: '',
  124. verificationCode: '',
  125. },
  126. checkCode: null,
  127. checkRules: {
  128. password: [{ required: true, trigger: 'blur', message: '请输入密码' }],
  129. verificationCode: [
  130. { required: true, trigger: 'blur', message: '请输入验证码' },
  131. ],
  132. },
  133. passengerImg: '',
  134. loading: false,
  135. }
  136. },
  137. watch: {
  138. passengerDialogFlag(val) {
  139. this.$nextTick(() => {
  140. this.$refs['dialog']?.focus()
  141. })
  142. this.passengerImg = noDataImage
  143. if (val) {
  144. if (this.userChecked) {
  145. this.getPassengerInfo()
  146. } else {
  147. this.getCheckCode()
  148. }
  149. }
  150. },
  151. },
  152. methods: {
  153. dialogHide() {
  154. this.$refs['checkForm']?.resetFields()
  155. this.$store.dispatch('app/togglePassengerDialogFlag', false)
  156. },
  157. //获取动态验证码
  158. async getCheckCode() {
  159. try {
  160. const { code, data, message } = await GetCheckCode({
  161. appToken: PLATFROM_CONFIG.tempAppToken,
  162. })
  163. if (Number(code) === 0) {
  164. this.checkCode = data
  165. } else {
  166. this.$message.error(message || '失败')
  167. }
  168. } catch (error) {
  169. this.$message.error('失败')
  170. }
  171. },
  172. //验证码重新获取
  173. changeCode() {
  174. this.getCheckCode()
  175. },
  176. submitHandler() {
  177. this.$refs['checkForm'].validate(async valid => {
  178. if (valid) {
  179. try {
  180. await this.checkUser()
  181. this.$refs['checkForm']?.resetFields()
  182. this.$store.dispatch('user/setUserChecked', true)
  183. await this.getPassengerInfo()
  184. } catch (error) {
  185. this.$message.error(error?.message || '失败')
  186. }
  187. }
  188. })
  189. },
  190. async checkUser() {
  191. this.loading = true
  192. try {
  193. const { code, data, message } = await CheckUser({
  194. userId: PLATFROM_CONFIG.tempUserId,
  195. password: MD5(this.checkForm.password.replace(/s+/g, '')),
  196. verificationCode: this.checkForm.verificationCode,
  197. })
  198. if (Number(code) !== 0) {
  199. throw new Error(message || '失败')
  200. }
  201. } catch (error) {
  202. this.loading = false
  203. this.getCheckCode()
  204. return Promise.reject(error.message)
  205. }
  206. this.loading = false
  207. },
  208. async getPassengerInfo() {
  209. this.loading = true
  210. try {
  211. const { passengerName, flightNO, flightDate } =
  212. this.passengerQueryParams
  213. const { code, data, message } = await GetPassengerInfo({
  214. id: '1803430',
  215. dataContent: [passengerName, flightNO, flightDate],
  216. })
  217. if (Number(code) === 0) {
  218. if (data?.verifyCodeImage) {
  219. this.passengerImg = `data:image/png;base64,${data.verifyCodeImage}`
  220. }
  221. } else {
  222. throw new Error(message || '失败')
  223. }
  224. } catch (error) {
  225. this.loading = false
  226. return Promise.reject(error.message)
  227. }
  228. this.loading = false
  229. },
  230. },
  231. }
  232. </script>
  233. <style lang="scss">
  234. #dialogPassenger {
  235. .title {
  236. display: flex;
  237. justify-content: space-between;
  238. margin-bottom: 0;
  239. .el-icon-close {
  240. margin-right: 16px;
  241. cursor: pointer;
  242. }
  243. }
  244. .content {
  245. margin: 0;
  246. .el-form {
  247. padding: 30px 20px 6px;
  248. }
  249. .passenger-info-box {
  250. width: 100%;
  251. height: 180px;
  252. padding: 20px;
  253. text-align: center;
  254. .passenger-info-img {
  255. max-width: 100%;
  256. max-height: 100%;
  257. object-fit: contain;
  258. vertical-align: middle;
  259. }
  260. }
  261. }
  262. .footer {
  263. padding: 0 22px;
  264. height: 56px;
  265. display: flex;
  266. justify-content: flex-end;
  267. align-items: center;
  268. background: #f0f5ff;
  269. .el-button {
  270. width: 80px;
  271. border-radius: 4px;
  272. font-family: 'Microsoft YaHei';
  273. &:not(:last-child) {
  274. margin-right: 14px;
  275. }
  276. }
  277. }
  278. }
  279. </style>