index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. <template>
  2. <div :class="mobile ? 'mobileMain' : ''" :style="{
  3. marginTop: mainMarginTop,
  4. marginBottom: mobile ? '0px' : '30px !important'
  5. }">
  6. <div v-loading="loading" class="name-cert-container" v-if="!mobile">
  7. <!-- 待实名 -->
  8. <div class="name-cert-main">
  9. <div class="name-cert-title-area">
  10. <img class="name-cert-icon" :src="icon" />
  11. <h6 class="name-cert-title">实名认证</h6>
  12. <p class="name-cert-tips">请如实填写信息,客栈承诺保障用户的信息安</p>
  13. </div>
  14. <el-form ref="modalForm" :model="modalFormData" :rules="rules" size="medium" label-width="100px">
  15. <div class="name-cert-label">姓名</div>
  16. <el-form-item label-width="0" prop="cert_name">
  17. <el-input v-model="modalFormData.cert_name" placeholder="请输入真实姓名" clearable :style="{ width: '100%' }">
  18. </el-input>
  19. </el-form-item>
  20. <div class="name-cert-label">证件类型</div>
  21. <el-form-item label-width="0" prop="cert_type">
  22. <el-select v-model="modalFormData.cert_type" placeholder="请选择证件类型" clearable :style="{ width: '100%' }">
  23. <el-option v-for="(item, index) in cert_typeOptions" :key="index" :label="item.label" :value="item.value" :disabled="item.disabled"></el-option>
  24. </el-select>
  25. </el-form-item>
  26. <div class="name-cert-label">证件号</div>
  27. <el-form-item label-width="0" prop="cert_no">
  28. <el-input v-model="modalFormData.cert_no" placeholder="请输入证件号" clearable :style="{ width: '100%' }">
  29. </el-input>
  30. </el-form-item>
  31. <div class="upload-main">
  32. <el-upload class="upload-box" action="#" :show-file-list="false" :multiple="false" accept="image/png, image/jpeg" :before-upload="file => handleFileChange(file,'z_file')">
  33. <div class="upload-img" v-if="z_file" @click.stop="handleDeleteFile('z_file')">
  34. <i class="el-icon-delete avatar-uploader-icon"></i>
  35. <img :src="z_file" class="avatar" />
  36. </div>
  37. <div v-else class="upload-area z_file">
  38. <p>+点击上传正面</p>
  39. <div class="upload-"></div>
  40. </div>
  41. </el-upload>
  42. <el-upload class="upload-box" action="#" :show-file-list="false" :multiple="false" accept="image/png, image/jpeg" :before-upload="file => handleFileChange(file,'f_file')">
  43. <div class="upload-img" v-if="f_file" @click.stop="handleDeleteFile('f_file')">
  44. <i class="el-icon-delete avatar-uploader-icon"></i>
  45. <img :src="f_file" class="avatar" />
  46. </div>
  47. <div v-else class="upload-area f_file">
  48. <p>+点击上传反面</p>
  49. </div>
  50. </el-upload>
  51. </div>
  52. <div class="name-cert-submit">
  53. <el-button type="primary" class="cert-btn" size="medium" @click="submitForm">实名认证</el-button>
  54. </div>
  55. </el-form>
  56. </div>
  57. </div>
  58. <el-dialog title="温馨提示" :visible.sync="centerDialogVisible" width="350px" center>
  59. <p class="qrcode-tips">请打开支付宝扫码以下二维码</p>
  60. <div class="qrcode-img">
  61. <img :src="qrcodeBase64" />
  62. </div>
  63. </el-dialog>
  64. </div>
  65. </template>
  66. <script>
  67. import {
  68. mapState
  69. } from "vuex";
  70. import qs from "qs";
  71. import icon from "@/assets/img/account/certicon@3x.png";
  72. import iconSuccess from "@/assets/img/account/cert_success_icon@3x.png";
  73. import iconFail from "@/assets/img/account/cert_fail_icon@3x.png";
  74. import QRCode from "qrcode";
  75. import uploader from "@/components/uploader";
  76. export default {
  77. name: "SeoLearnList",
  78. components: {
  79. uploader
  80. },
  81. data() {
  82. return {
  83. diploma_photo: "",
  84. loading:false,
  85. baseUrl: "",
  86. mobile: false,
  87. isWeixinApp: true,
  88. icon,
  89. iconSuccess,
  90. iconFail,
  91. centerDialogVisible: false,
  92. url: "",
  93. certifyId: "",
  94. qrcodeBase64: "",
  95. timer: null,
  96. // normal 待实名 success 认证成功 fail 认证失败
  97. state: "normal",
  98. init: false,
  99. modalFormData: {
  100. cert_name: "",
  101. cert_type: 1,
  102. cert_no: ""
  103. },
  104. z_file: "",
  105. f_file: "",
  106. rules: {
  107. cert_name: [{
  108. required: true,
  109. message: "请输入真实姓名",
  110. trigger: "blur"
  111. }],
  112. cert_type: [{
  113. required: true,
  114. message: "请选择证件类型",
  115. trigger: "change"
  116. }],
  117. cert_no: [{
  118. required: true,
  119. message: "请输入证件号",
  120. trigger: "blur"
  121. }]
  122. },
  123. cert_typeOptions: [{
  124. label: "身份证",
  125. value: 1
  126. },
  127. {
  128. label: "港澳通行证",
  129. value: 2
  130. },
  131. {
  132. label: "台湾通行证",
  133. value: 3
  134. },
  135. {
  136. label: "港澳居住证",
  137. value: 4
  138. },
  139. {
  140. label: "台湾身份证",
  141. value: 5
  142. }
  143. ]
  144. };
  145. },
  146. head() {
  147. const {
  148. title = "实名认证",
  149. keyword = "",
  150. description = "",
  151. h1 = "",
  152. canonical = "",
  153. metaLocation
  154. } = this.head || {};
  155. let obj = {
  156. title: title,
  157. meta: [{
  158. name: "keywords",
  159. content: keyword
  160. },
  161. {
  162. name: "description",
  163. content: description
  164. },
  165. {
  166. name: "h1",
  167. content: h1
  168. }
  169. ],
  170. link: [{
  171. rel: "canonical",
  172. href: canonical
  173. }]
  174. };
  175. if (metaLocation) {
  176. obj.meta.push({
  177. name: "location",
  178. content: metaLocation
  179. });
  180. }
  181. return obj;
  182. },
  183. computed: {
  184. ...mapState(["deviceType"]),
  185. showWxHeader() {
  186. return (
  187. !this.deviceType.app &&
  188. !this.isWeixinApp &&
  189. (this.deviceType.android || this.deviceType.ios)
  190. );
  191. },
  192. mainMarginTop() {
  193. if (this.mobile && this.showWxHeader) {
  194. return "64px !important";
  195. } else if (this.mobile) {
  196. return "0px !important";
  197. } else {
  198. return "20px !important";
  199. }
  200. },
  201. userInfo() {
  202. return this.$store.state.userinfo;
  203. }
  204. },
  205. mounted() {
  206. this.checkLogin(true);
  207. this.home_page_type = this.userInfo.home_page_type;
  208. this.baseUrl = this.$store.state.domainConfig.siteUrl;
  209. this.isWeixinApp = navigator.userAgent.indexOf("miniProgram") > -1;
  210. this.checkNameIsCerted();
  211. document.body.style.background = "#fff";
  212. },
  213. methods: {
  214. handleDeleteFile(type) {
  215. if (type == 'z_file') {
  216. this.z_file = ""
  217. }
  218. if (type == 'f_file') {
  219. this.f_file = ""
  220. }
  221. },
  222. handleFileChange(file, type) {
  223. if (this.limitFileSize && this.limitFileSize > 0) {
  224. if (file.size / (1024 * 1024) > this.limitFileSize) {
  225. this.$message.error(`图片大小不得超过${this.limitFileSize}M,请重新选择`);
  226. return false;
  227. }
  228. } else if (file.size / 1024 > 2048) {
  229. this.$message.error("图片大小不得超过2M,请重新选择");
  230. return false;
  231. }
  232. const formData = new FormData();
  233. formData.append("file", file);
  234. formData.append("original_filename", file.name);
  235. this.uploading = true;
  236. this.$axios
  237. .$post(`/upload_image`, formData, {
  238. headers: {
  239. "Content-Type": "multipart/form-data"
  240. }
  241. })
  242. .then(res => {
  243. this.$emit("change", res.filename);
  244. if (type == 'z_file') {
  245. this.z_file = res.filename
  246. }
  247. if (type == 'f_file') {
  248. this.f_file = res.filename
  249. }
  250. })
  251. .finally(() => {
  252. this.uploading = false;
  253. });
  254. return false
  255. },
  256. submitForm() {
  257. this.$refs["modalForm"].validate(valid => {
  258. if (!valid) return;
  259. if (!this.z_file) {
  260. this.$message.error("请上传证件正面")
  261. return
  262. }
  263. if (!this.f_file) {
  264. this.$message.error("请上传证件反面")
  265. return
  266. }
  267. this.submit();
  268. // TODO 提交表单
  269. });
  270. },
  271. resetForm() {
  272. this.$refs["modalForm"].resetFields();
  273. },
  274. async submit() {
  275. this.loading=true;
  276. const {
  277. cert_name,
  278. cert_no,
  279. cert_type
  280. } = this.modalFormData;
  281. // 测试用
  282. // let res = {
  283. // status:1,
  284. // data: {
  285. // url: "http://www.baidu.com",
  286. // certifyId: "123123"
  287. // }
  288. // }
  289. let res = await this.$axios.$post("/uapi/user/realName/create", {
  290. cert_name,
  291. cert_no,
  292. cert_type,
  293. z_file:this.z_file,
  294. f_file:this.f_file,
  295. is_face_check:this.$route.query.is_face_check == 1 ? 1 : 0,
  296. from_type: 1
  297. });
  298. this.loading=false;
  299. if (Number(res.status) !== 1) {
  300. this.$message.error(res.info);
  301. return;
  302. }
  303. const {
  304. kezhan_url,
  305. certifyId,
  306. cert_status,
  307. zfb_url,
  308. certify_type
  309. } = res.data;
  310. if(cert_status==3)
  311. {
  312. this.toSuccess();
  313. return ;
  314. }
  315. if(certify_type==2)
  316. {
  317. this.url = kezhan_url;
  318. this.certifyId = certifyId;
  319. this.centerDialogVisible = true;
  320. this.createQrCode();
  321. this.startTimer();
  322. }
  323. },
  324. createQrCode() {
  325. this.$nextTick(() => {
  326. const text = this.url;
  327. let that = this;
  328. QRCode.toDataURL(
  329. text, {
  330. errorCorrectionLevel: "H",
  331. margin: 1,
  332. width: 300
  333. },
  334. function (err, url) {
  335. that.qrcodeBase64 = url;
  336. }
  337. );
  338. });
  339. },
  340. startTimer() {
  341. // 启动定时器查询
  342. if (this.timer) {
  343. clearInterval(this.timer);
  344. this.timer = null;
  345. }
  346. this.timer = setInterval(async () => {
  347. let res = await this.$axios.$post("/uapi/user/realName/check", {});
  348. if (Number(res.status) !== 1) {
  349. this.$message.error(res.info);
  350. return;
  351. }
  352. let {
  353. type
  354. } = res.data.type;
  355. if (type == 1 || type == 4) {
  356. // 关闭弹层
  357. this.centerDialogVisible = false;
  358. clearInterval(this.timer);
  359. this.timer = null;
  360. if (type == 1) {
  361. // 显示成功态
  362. this.toSuccess();
  363. } else if (type == 4) {
  364. // 显示失败态
  365. this.toFail();
  366. }
  367. }
  368. }, 5000);
  369. },
  370. checkNameIsCerted() {
  371. if (this.userInfo && this.userInfo.realname_verify_status == 2) {
  372. this.toSuccess()
  373. }
  374. },
  375. toSuccess() {
  376. location.href = "/frontend/name_cert_success";
  377. },
  378. toFail() {
  379. location.href = "/frontend/name_cert_fail";
  380. }
  381. }
  382. };
  383. </script>
  384. <style lang="scss">
  385. @import "@/assets/css/name_cert/name_cert.scss";
  386. </style>