| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440 |
- <template>
- <view class="page">
- <!-- #ifdef H5-->
- <uni-nav-bar v-if="!$isWxBrowser()" :fixed="true" background-color="#FFE05C" :border="false" :statusBar="false"
- title="注册"/>
- <!-- #endif -->
- <view :style="{'marginTop':'10rpx'}">
- <u--form labelPosition="left" :model="form" :rules="rules" ref="uForm">
- <u-form-item :labelWidth="80" label="头像:" borderBottom prop="img" ref="item1">
- <view class="photoView" @click="updateAvatar">
- <image class="photoImage" :src="form.imgUrl || '/static/ud4.png'"></image>
- </view>
- </u-form-item>
- <u-form-item :labelWidth="80" label="姓名:" borderBottom prop="name" ref="item1">
- <u--input v-model="form.name" placeholder="请输入姓名" border="none"></u--input>
- </u-form-item>
- <u-form-item :labelWidth="80" label="身份证号:" borderBottom prop="idCard" ref="item1">
- <u--input v-model="form.idCard" placeholder="请输入身份证号" border="none"></u--input>
- </u-form-item>
- <u-form-item :labelWidth="80" label="密码:" borderBottom prop="newPassword" ref="item1">
- <u--input v-model="form.newPassword" placeholder="请输入密码" type="password" border="none"></u--input>
- </u-form-item>
- <u-form-item :labelWidth="80" label="确认密码:" borderBottom prop="againPassword" ref="item1">
- <u--input v-model="form.againPassword" placeholder="再次确认密码" type="password"
- border="none"></u--input>
- </u-form-item>
- <u-form-item :labelWidth="80" label="手机号:" borderBottom prop="phone" ref="item1">
- <u--input v-model="form.phone" placeholder="请输入手机号" border="none"></u--input>
- </u-form-item>
- <u-form-item :labelWidth="80" label="验证码:" borderBottom prop="code" ref="item1">
- <view class="inputCode">
- <u--input v-model="form.code" placeholder="请输入验证码" border="none"></u--input>
- </view>
- <u-button slot="right" @tap="getCode" :text="tips" type="success" size="small"
- :disabled="disabled1"></u-button>
- </u-form-item>
- </u--form>
- <view :style="{'marginTop':'100rpx'}">
- <!-- <button class="customStyle" @click="expandRegister">提交</button>-->
- <button class="customStyle" @click="debounce(expandRegister,500)">提交</button>
- </view>
- <view class="flex-row justify-center register">
- <text>已有账号!</text>
- <text @click="gologin" :style="{color:'#FFE05C'}">切换登录</text>
- </view>
- </view>
- <u-code ref="uCode" @change="codeChange" seconds="60" @start="disabled1 = true"
- @end="disabled1 = false"></u-code>
- <u-action-sheet
- :show="showSex"
- :actions="actions"
- title="请选择性别"
- @close="showSex = false"
- @select="sexSelect">
- </u-action-sheet>
- <u-datetime-picker
- :show="showBirthday"
- :value="birthday"
- mode="date"
- closeOnClickOverlay
- @confirm="birthdayConfirm"
- @cancel="birthdayClose"
- @close="birthdayClose"
- ></u-datetime-picker>
- </view>
- </template>
- <script>
- export default {
- data() {
- return {
- timer: null, //定时任务
- recordId: '',//拓客经理二维码被扫记录id
- qrCodeInvalid: false,//二维码是否无效标识
- requestStatus: false,
- disabled1: false,
- showBirthday: false,
- showSex: false,
- birthday: Number(new Date()),
- actions: [{
- name: '男',
- value: '1'
- },
- {
- name: '女',
- value: '0'
- }, {
- name: '保密',
- value: '2'
- }
- ],
- tips: '',
- form: {
- roleId: '',
- parentId: '',
- img: '',
- imgUrl: '',
- name: '',
- idCard: '',
- newPassword: '',
- againPassword: '',
- phone: '',
- code: '',
- },
- rules: {
- // 'img': {
- // type: 'string',
- // required: true,
- // message: '请上传头像',
- // trigger: ['blur', 'change']
- // },
- // 'name': [
- // {
- // type: 'string',
- // required: true,
- // min: 2,
- // pattern: '^([\u4e00-\u9fa5]{2,20})$',
- // message: '请输入正确的姓名',
- // trigger: ['blur', 'change']
- // }
- // ],
- // 'idCard': [
- // {
- // type: 'string',
- // required: false,
- // min: 18,
- // max: 18,
- // pattern: this.$idCardPattern,
- // message: '请输入身份证号',
- // trigger: ['blur', 'change']
- // }
- // ],
- 'phone': {
- type: 'string',
- required: true,
- min: 11,
- max: 11,
- pattern: this.$phonePattern,
- message: '请输入正确的电话号码',
- trigger: ['blur', 'change']
- },
- 'code': {
- type: 'string',
- required: true,
- min: 4,
- max: 6,
- message: '请输入验证码',
- trigger: ['blur', 'change']
- },
- 'newPassword': {
- type: 'string',
- min: 6,
- max: 16,
- required: true,
- message: '请输入6-18位密码',
- trigger: ['blur', 'change']
- },
- 'againPassword': {
- type: 'string',
- min: 6,
- max: 16,
- required: true,
- message: '请输入6-18位密码',
- trigger: ['blur', 'change']
- }
- },
- }
- },
- onLoad(e) {
- if (e.roleId) {
- console.log('++++++++++++扫码进注册页面+++++++++++++++++++')
- uni.setStorageSync('isRegister', true)
- this.form.roleId = e.roleId
- console.log('获取到的id', e.roleId)
- }
- if (e.type) {
- this.form.type = e.type
- console.log('获取到的type', e.type)
- }
- if (e.parentId) {
- this.form.parentId = e.parentId
- console.log('获取到的name', e.parentId)
- this.addRecordForManager()
- }
- if (e.timestamp) {
- console.log('获取到的时间戳', e.timestamp, new Date().getTime() > e.timestamp)
- if (new Date().getTime() > e.timestamp) {
- this.qrCodeInvalid = true
- uni.showModal({
- title: '温馨提示',
- content: ' 当前二维码已过期,请重新扫码',
- showCancel: false,
- success: function (res) {
- if (res.confirm) {
- console.log('用户点击确定');
- } else if (res.cancel) {
- console.log('用户点击取消');
- }
- }
- });
- }
- }
- },
- methods: {
- addRecordForManager() {
- console.log("+++++++++++++创建被扫码记录++++++++++++++")
- console.log("+++++++++++++拓客经理id++++++++++++++", this.form.parentId)
- console.log("+++++++++++++角色id++++++++++++++", this.form.roleId)
- this.$api.service.addRecordForManager({
- expandUserId: this.form.parentId,
- roleId: this.form.roleId,
- type: this.form.type
- }).then(res => {
- console.log("获取到的记录id", res.data.data)
- this.recordId = res.data.data
- })
- },
- updateScanRecordById() {
- this.$api.service.updateScanRecordById({
- recordId: this.recordId
- }).then(res => {
- console.log("+++++++++++++创建被扫码记录为成功++++++++++++++", res)
- })
- },
- idCardAndName() {
- this.$api.service.idCardAndName({
- name: this.form.name,
- idCard: this.form.idCard,
- }).then(res => {
- if (res.data.data != null && res.data.data.respCode !== '0000') {
- this.rules.idCard.push({
- validator: (a, b, callback) => {
- callback(new Error(res.data.data.respMessage));
- },
- // 触发器可以同时用blur和change
- trigger: []
- })
- this.$refs.uForm.validateField('idCard')
- }else {
- this.register()
- }
- })
- },
- gologin() {
- uni.redirectTo({
- url: '/pages/login/login'
- })
- },
- updateAvatar() {
- let that = this
- uni.chooseImage({
- count: 1, //默认9
- sizeType: ['compressed'], //可以指定是原图还是压缩图,默认二者都有
- sourceType: ['album'], //从相册选择
- success: function (res) {
- let tempUrl = res.tempFiles[0].path
- uni.uploadFile({
- url: that.$baseUrl + '/resource/oss/upload', //仅为示例,非真实的接口地址
- filePath: tempUrl,
- name: 'file',
- header: {
- // "Content-Type": "multipart/form-data",
- // 'X-Access-Token': uni.getStorageSync('token'),
- 'Authorization': 'Bearer ' + uni.getStorageSync('accessToken'),
- },
- success: (uploadFileRes) => {
- let res = JSON.parse(uploadFileRes.data)
- console.log('+++++++++++++++++chooseavatar+++++++++++++++++++++++', uploadFileRes.data)
- that.form.imgUrl = res.data.url.replace(/^http:/, "https:")
- that.form.img = res.data.ossId
- },
- fail: (err) => {
- console.log(err)
- uni.showToast({
- icon: 'error',
- duration: 2000,
- title: err.errMsg
- });
- }
- });
- },
- fail: function (err) {
- console.log(err)
- uni.showToast({
- icon: 'error',
- duration: 2000,
- title: err.errMsg
- });
- }
- })
- },
- birthdayClose() {
- this.showBirthday = false
- // this.$refs.form1.validateField('userInfo.birthday')
- },
- birthdayConfirm(e) {
- console.log(e)
- this.showBirthday = false
- this.form.birthday = uni.$u.timeFormat(e.value, 'yyyy-mm-dd')
- // this.$refs.form1.validateField('userInfo.birthday')
- },
- sexSelect(e) {
- console.log(e)
- },
- expandRegister() {
- if (this.qrCodeInvalid) {
- uni.showModal({
- title: '温馨提示',
- content: ' 当前二维码已过期,请重新扫码',
- showCancel: false,
- success: function (res) {
- if (res.confirm) {
- console.log('用户点击确定');
- } else if (res.cancel) {
- console.log('用户点击取消');
- }
- }
- });
- return;
- }
- // this.rules.idCard = [
- // {
- // type: 'string',
- // required: false,
- // min: 18,
- // max: 18,
- // pattern: this.$idCardPattern,
- // message: '请输入身份证号',
- // trigger: ['blur', 'change']
- // }
- // ]
- this.$refs.uForm.validate().then(validate => {
- this.register()
- })
- },
- register () {
- if (this.requestStatus) {
- return
- }
- this.requestStatus = true
- // 如果校验通过执行注册
- uni.showLoading({
- title: '正在注册...'
- });
- this.$api.login.expandRegister(this.form).then(res => {
- uni.hideLoading();
- uni.showToast({
- icon: 'success',
- duration: 2000,
- title: '注册成功,即将跳转登录页'
- });
- uni.removeStorageSync('isRegister');
- setTimeout(() => {
- this.requestStatus = false
- this.gologin()
- }, 2000)
- this.updateScanRecordById()
- }).catch(err => {
- uni.hideLoading();
- this.requestStatus = false
- })
- },
- logout() {
- this.$api.login.logout().then(res => {
- uni.clearStorageSync();
- uni.navigateTo({
- url: '/pages/login/login'
- })
- })
- },
- back() {
- uni.navigateBack({
- delta: 1
- });
- },
- codeChange(text) {
- this.tips = text;
- },
- getCode() {
- let regExp = new RegExp(this.$phonePattern);
- let b = regExp.test(this.form.phone)
- if (!b) {
- uni.$u.toast('请输入正确的手机号')
- return
- }
- if (this.$refs.uCode.canGetCode) {
- // 模拟向后端请求验证码
- uni.showLoading({
- title: '正在获取验证码'
- })
- this.$api.service.getSmsCode({phonenumber: this.form.phone}).then(res => {
- uni.hideLoading();
- // 这里此提示会被this.start()方法中的提示覆盖
- uni.$u.toast('验证码已发送');
- // 通知验证码组件内部开始倒计时
- this.$refs.uCode.start();
- })
- } else {
- uni.$u.toast('倒计时结束后再发送');
- }
- },
- debounce(fn, delay) {
- console.log(delay)
- clearTimeout(this.timer);
- this.timer = setTimeout(() => {
- fn.apply();
- }, delay);
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- @import './index.rpx.css';
- </style>
|