Blame view

apps/pages/passport/auth.vue 8.64 KB
yyq authored
1
<template>
yyq authored
2
    <LayoutApp class="yohoufo-real-auth-page" title="实名认证">
yyq authored
3
      <div class="auth-content">
yyq authored
4
        <p class="auth-sub-title">UFO平台将严格保密您的认证信息,请按照种类分别填写以下信息,保证上传的图片文字清晰可见。</p>
yyq authored
5 6 7
        <div class="auth-form">
          <p class="form-title">姓名</p>
          <div class="form-input-block">
yyq authored
8
            <CubeInput class="auth-input" v-model="name" :disabled="!!certName" placeholder="请填写姓名"></CubeInput>
yyq authored
9 10 11
          </div>
          <p class="form-title">身份证号</p>
          <div class="form-input-block">
yyq authored
12
            <CubeInput class="auth-input" v-model="idCode" :disabled="!!certIdCode" placeholder="请填写身份证号"></CubeInput>
yyq authored
13
          </div>
yyq authored
14
          <p class="form-title">上传身份证正面照片 <a :href="exampleLink" class="upload-intro"><span class="iconfont iconquestion"></span>示例照片</a></p>
yyq authored
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
          <div class="form-input-block">
            <div class="upload-btn" @click="uploadFrontCard">
              <div v-if="idCardFrontUrl" class="delete-img" @click.stop="clearInfo(['idCardFront', 'idCardFrontUrl'])">ㄨ</div>
              <div v-if="idCardFrontUrl" class="up-img-block">
                <img :src="idCardFrontUrl">
              </div>
            </div>
            <div class="example-view">
              <img src="//img12.static.yhbimg.com/goodsimg/2019/09/25/16/022553bde9fc6bafa0df244de694c551f2.png?imageView/1/w/160/h/100" alt="身份证正面(示例)">
              <p>(示例)</p>
            </div>
          </div>
          <p class="form-title">上传身份证反面照片</p>
          <div class="form-input-block">
            <div class="upload-btn" @click="uploadBackCard">
              <div v-if="idCardBackUrl" class="delete-img" @click.stop="clearInfo(['idCardBack', 'idCardBackUrl'])">ㄨ</div>
              <div v-if="idCardBackUrl" class="up-img-block">
                <img :src="idCardBackUrl">
              </div>
            </div>
            <div class="example-view">
              <img src="//img11.static.yhbimg.com/goodsimg/2019/09/25/16/011df7d2637953bd6ce2c59500011d7fd7.png?imageView/1/w/160/h/100" alt="身份证反面(示例)">
              <p>(示例)</p>
            </div>
          </div>
          <div class="hide-upload-wrap">
            <CubeUpload
              ref="upload"
              action="/xianyu/upload/idcard"
              :simultaneous-uploads="1"
              @files-added="addedHandler"
              @file-success="successHandler"
              @file-error="errorHandler"/>
          </div>
        </div>
      </div>
      <div class="auth-footer">
        <CubeButton class="submit-btn" :disabled="canSubmit" @click="submitCert">确认提交</CubeButton>
      </div>
    </LayoutApp>
</template>

<script>
import { get } from 'lodash';
import { Input, Button, Upload } from 'cube-ui';
import { mapActions, mapState } from 'vuex';

export default {
  name: 'auth',
  data() {
    return {
      name: '',
      idCode: '',
      idCardFront: '',
      idCardBack: '',
      idCardFrontUrl: '',
      idCardBackUrl: '',
      exampleLink: '//activity.yoho.cn/feature/4899.html?share_id=7593&title=UFO-身份证示例'
    }
  },
  computed: {
    ...mapState(['yoho']),
    certName() {
      let name = get(this.yoho, 'user.sellerInfo.certName');

      name && (this.name = name);
      return name;
    },
    certIdCode() {
      let code = get(this.yoho, 'user.sellerInfo.certNo');

      code && (this.idCode = code);
      return code;
    },
    canSubmit() {
      return !(this.name && this.idCode && this.idCardFront && this.idCardBack);
    }
  },
  methods: {
    ...mapActions(['userRealCertification']),
    clearInfo(arr) {
      if (arr && arr.length) {
        arr.forEach(val => {
          this[val] && (this[val] = '');
        });
      }
    },
    chooseUploadFile() {
      this.$refs.upload && this.$refs.upload.$el.querySelector('.cube-upload-input').click();
    },
    uploadFrontCard() {
      if (!this.uploading && !this.idCardFront) {
        this.uploadCallback = (path, img) => {
          this.idCardFront = path;
          this.idCardFrontUrl = img;
        };
        this.chooseUploadFile();
      }
    },
    uploadBackCard() {
      if (!this.uploading && !this.idCardBack) {
        this.uploadCallback = (path, img) => {
          this.idCardBack = path;
          this.idCardBackUrl = img;
        };
        this.chooseUploadFile();
      }
    },
    addedHandler() {
      this.uploading = true;
    },
    successHandler(file) {
yyq authored
127 128 129 130 131 132 133 134
      if (get(file, 'response.code') === 200) {
        this.uploadCallback && this.uploadCallback(get(file, 'response.data.imagesList[0]'), file.url);
      } else {
        this.$createToast && this.$createToast({
          txt: res.message || '上传失败',
          type: 'txt',
          time: 1000
        }).show();
yyq authored
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
      }

      this.uploading = false;
      setTimeout(() => {
        this.$refs.upload.removeFile(file);
      }, 1000);
    },
    errorHandler() {
      this.uploading = false;
    },
    submitCert() {
      this.userRealCertification({
        certName: this.name,
        certNo: this.idCode,
        frontImageUrl: this.idCardFront,
        backImageUrl: this.idCardBack
      }).then(res => {
        if (res.code === 200) {
          if (this.$route.query.refer) {
            this.$router.push({
              name: this.$route.query.refer
            });
          } else {
            this.$router.go(-1);
          }
        } else {
          this.$createToast && this.$createToast({
            txt: res.message || '认证失败',
            type: 'txt',
            time: 1000
          }).show();
        }
      });
    }
  },
  components: {
    CubeInput: Input,
    CubeButton: Button,
    CubeUpload: Upload
  }
};
</script>

<style lang="scss" scoped>
  .auth-content {
yyq authored
180
    height: calc(100% - 144px);
yyq authored
181 182 183 184 185 186 187
    padding: 0 40px;
    overflow-y: scroll;

    .auth-sub-title {
      font-size: 24px;
      color: #999;
      line-height: 1.5;
yyq authored
188 189
      margin: 40px 0 10px;
      text-align: center;
yyq authored
190 191 192 193 194 195 196 197 198 199
    }

    .auth-form {
      margin-top: 40px;
    }

    .form-title {
      font-size: 36px;
      padding-top: 40px;
      line-height: 1.6;
yyq authored
200
      font-weight: 500;
yyq authored
201 202 203 204
    }

    .form-input-block {
      padding-bottom: 16px;
yyq authored
205
      border-bottom: 1px solid #eee;
yyq authored
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
      position: relative;
    }

    .auth-input {
      &:after {
        border: 0;
      }

      /deep/ .cube-input-field {
        font-size: 14px;
        height: 40px;
        border: none;
        padding: 0;
      }
    }

    .upload-intro {
yyq authored
223
      font-size: 24px;
yyq authored
224 225 226
      line-height: 58px;
      color: #999;
      float: right;
yyq authored
227 228 229 230 231 232 233 234 235
      display: flex;
      align-items: center;
      font-weight: 300;

      .iconfont {
        font-size: 30px;
        color: #d8d8d8;
        margin-right: 10px;
      }
yyq authored
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327
    }

    .upload-btn {
      width: 220px;
      height: 140px;
      background-color: #eee;
      margin: 30px 0 14px;
      position: relative;

      &:before {
        content: "";
        width: 40px;
        height: 4px;
        background-color: #999;
        position: absolute;
        left: 50%;
        top: 50%;
        margin-top: -2px;
        margin-left: -20px;
      }

      &:after {
        content: "";
        width: 4px;
        height: 40px;
        background-color: #999;
        position: absolute;
        left: 50%;
        top: 50%;
        margin-top: -20px;
        margin-left: -2px;
      }
    }

    .delete-img {
      width: 40px;
      height: 40px;
      line-height: 40px;
      border-radius: 20px;
      background-color: #676767;
      color: #fff;
      text-align: center;
      position: absolute;
      top: -20px;
      right: -20px;
      z-index: 2;
    }

    .up-img-block {
      position: absolute;
      top: 0;
      bottom: 0;
      left: 0;
      right: 0;
      z-index: 1;
      background-color: #fff;
      display: flex;
      justify-content: center;
      align-items: center;

      > img {
        display: block;
        max-width: 100%;
        max-height: 100%;
      }
    }

    .example-view {
      width: 160px;
      font-size: 20px;
      color: #999;
      text-align: center;
      position: absolute;
      right: 0;
      top: 16px;

      > img {
        width: 100%;
      }

      > p {
        font-weight: 300;
      }
    }

    .hide-upload-wrap {
      height: 0;
      overflow: hidden;
    }
  }

  .auth-footer {
yyq authored
328
    padding: 28px 40px;
yyq authored
329 330

    .submit-btn {
yyq authored
331 332 333
      height: 88px;
      line-height: 88px;
      padding: 0;
yyq authored
334
      background: #022c46;
yyq authored
335 336 337 338 339
      border-radius: 44px;

      &:after {
        border: 0;
      }
yyq authored
340 341 342 343 344 345 346

      &.cube-btn_disabled {
        background: #ccc;
      }
    }
  }
</style>