index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. <template>
  2. <div :class="mobile ? 'mobileMain' : ''" :style="{
  3. marginTop: mainMarginTop,
  4. marginBottom: mobile ? '0px' : '30px !important'
  5. }">
  6. <div 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. baseUrl: "",
  85. mobile: false,
  86. isWeixinApp: true,
  87. icon,
  88. iconSuccess,
  89. iconFail,
  90. centerDialogVisible: false,
  91. url: "",
  92. certifyId: "",
  93. qrcodeBase64: "",
  94. timer: null,
  95. // normal 待实名 success 认证成功 fail 认证失败
  96. state: "normal",
  97. init: false,
  98. modalFormData: {
  99. cert_name: "",
  100. cert_type: 1,
  101. cert_no: ""
  102. },
  103. z_file: "",
  104. f_file: "",
  105. rules: {
  106. cert_name: [{
  107. required: true,
  108. message: "请输入真实姓名",
  109. trigger: "blur"
  110. }],
  111. cert_type: [{
  112. required: true,
  113. message: "请选择证件类型",
  114. trigger: "change"
  115. }],
  116. cert_no: [{
  117. required: true,
  118. message: "请输入证件号",
  119. trigger: "blur"
  120. }]
  121. },
  122. cert_typeOptions: [{
  123. label: "身份证",
  124. value: 1
  125. },
  126. {
  127. label: "港澳通行证",
  128. value: 2
  129. },
  130. {
  131. label: "台湾通行证",
  132. value: 3
  133. },
  134. {
  135. label: "港澳居住证",
  136. value: 4
  137. },
  138. {
  139. label: "台湾身份证",
  140. value: 5
  141. }
  142. ]
  143. };
  144. },
  145. head() {
  146. const {
  147. title = "实名认证",
  148. keyword = "",
  149. description = "",
  150. h1 = "",
  151. canonical = "",
  152. metaLocation
  153. } = this.head || {};
  154. let obj = {
  155. title: title,
  156. meta: [{
  157. name: "keywords",
  158. content: keyword
  159. },
  160. {
  161. name: "description",
  162. content: description
  163. },
  164. {
  165. name: "h1",
  166. content: h1
  167. }
  168. ],
  169. link: [{
  170. rel: "canonical",
  171. href: canonical
  172. }]
  173. };
  174. if (metaLocation) {
  175. obj.meta.push({
  176. name: "location",
  177. content: metaLocation
  178. });
  179. }
  180. return obj;
  181. },
  182. computed: {
  183. ...mapState(["deviceType"]),
  184. showWxHeader() {
  185. return (
  186. !this.deviceType.app &&
  187. !this.isWeixinApp &&
  188. (this.deviceType.android || this.deviceType.ios)
  189. );
  190. },
  191. mainMarginTop() {
  192. if (this.mobile && this.showWxHeader) {
  193. return "64px !important";
  194. } else if (this.mobile) {
  195. return "0px !important";
  196. } else {
  197. return "20px !important";
  198. }
  199. },
  200. userInfo() {
  201. return this.$store.state.userinfo;
  202. }
  203. },
  204. mounted() {
  205. this.checkLogin(true);
  206. this.home_page_type = this.userInfo.home_page_type;
  207. this.baseUrl = this.$store.state.domainConfig.siteUrl;
  208. this.isWeixinApp = navigator.userAgent.indexOf("miniProgram") > -1;
  209. this.checkNameIsCerted();
  210. document.body.style.background = "#fff";
  211. },
  212. methods: {
  213. handleDeleteFile(type) {
  214. if (type == 'z_file') {
  215. this.z_file = ""
  216. }
  217. if (type == 'f_file') {
  218. this.f_file = ""
  219. }
  220. },
  221. handleFileChange(file, type) {
  222. if (this.limitFileSize && this.limitFileSize > 0) {
  223. if (file.size / (1024 * 1024) > this.limitFileSize) {
  224. this.$message.error(`图片大小不得超过${this.limitFileSize}M,请重新选择`);
  225. return false;
  226. }
  227. } else if (file.size / 1024 > 2048) {
  228. this.$message.error("图片大小不得超过2M,请重新选择");
  229. return false;
  230. }
  231. const formData = new FormData();
  232. formData.append("file", file);
  233. formData.append("original_filename", file.name);
  234. this.uploading = true;
  235. this.$axios
  236. .$post(`/upload_image`, formData, {
  237. headers: {
  238. "Content-Type": "multipart/form-data"
  239. }
  240. })
  241. .then(res => {
  242. this.$emit("change", res.filename);
  243. if (type == 'z_file') {
  244. this.z_file = res.filename
  245. }
  246. if (type == 'f_file') {
  247. this.f_file = res.filename
  248. }
  249. })
  250. .finally(() => {
  251. this.uploading = false;
  252. });
  253. return false
  254. },
  255. submitForm() {
  256. this.$refs["modalForm"].validate(valid => {
  257. if (!valid) return;
  258. if (!this.z_file) {
  259. this.$message.error("请上传证件正面")
  260. return
  261. }
  262. if (!this.f_file) {
  263. this.$message.error("请上传证件反面")
  264. return
  265. }
  266. this.submit();
  267. // TODO 提交表单
  268. });
  269. },
  270. resetForm() {
  271. this.$refs["modalForm"].resetFields();
  272. },
  273. async submit() {
  274. const {
  275. cert_name,
  276. cert_no,
  277. cert_type
  278. } = this.modalFormData;
  279. // 测试用
  280. // let res = {
  281. // status:1,
  282. // data: {
  283. // url: "http://www.baidu.com",
  284. // certifyId: "123123"
  285. // }
  286. // }
  287. let res = await this.$axios.$post("/uapi/zfb/certify", {
  288. cert_name,
  289. cert_no,
  290. cert_type,
  291. z_file:this.z_file,
  292. f_file:this.f_file,
  293. from_type: 3
  294. });
  295. if (Number(res.status) !== 1) {
  296. this.$message.error(res.info);
  297. return;
  298. }
  299. const {
  300. url,
  301. certifyId,
  302. cert_status
  303. } = res.data;
  304. if(cert_status==3)
  305. {
  306. this.toSuccess();
  307. return ;
  308. }
  309. this.url = url;
  310. this.certifyId = certifyId;
  311. this.centerDialogVisible = true;
  312. this.createQrCode();
  313. this.startTimer();
  314. },
  315. createQrCode() {
  316. this.$nextTick(() => {
  317. const text = this.url;
  318. let that = this;
  319. QRCode.toDataURL(
  320. text, {
  321. errorCorrectionLevel: "H",
  322. margin: 1,
  323. width: 300
  324. },
  325. function (err, url) {
  326. that.qrcodeBase64 = url;
  327. }
  328. );
  329. });
  330. },
  331. startTimer() {
  332. // 启动定时器查询
  333. if (this.timer) {
  334. clearInterval(this.timer);
  335. this.timer = null;
  336. }
  337. this.timer = setInterval(async () => {
  338. let res = await this.$axios.$post("/uapi/zfb/return", {});
  339. if (Number(res.status) !== 1) {
  340. this.$message.error(res.info);
  341. return;
  342. }
  343. let {
  344. type
  345. } = res.data.type;
  346. if (type == 1 || type == 4) {
  347. // 关闭弹层
  348. this.centerDialogVisible = false;
  349. clearInterval(this.timer);
  350. this.timer = null;
  351. if (type == 1) {
  352. // 显示成功态
  353. this.toSuccess();
  354. } else if (type == 4) {
  355. // 显示失败态
  356. this.toFail();
  357. }
  358. }
  359. }, 5000);
  360. },
  361. checkNameIsCerted() {
  362. if (this.userInfo && this.userInfo.realname_verify_status == 2) {
  363. this.toSuccess()
  364. }
  365. },
  366. toSuccess() {
  367. location.href = "/frontend/name_cert_success";
  368. },
  369. toFail() {
  370. location.href = "/frontend/name_cert_fail";
  371. }
  372. }
  373. };
  374. </script>
  375. <style lang="scss">
  376. @import "@/assets/css/name_cert/name_cert.scss";
  377. </style>