register.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. <template>
  2. <view class="page">
  3. <!-- #ifdef H5-->
  4. <uni-nav-bar v-if="!$isWxBrowser()" :fixed="true" background-color="#FFE05C" :border="false" :statusBar="false"
  5. title="注册"/>
  6. <!-- #endif -->
  7. <view :style="{'marginTop':'10rpx'}">
  8. <u--form labelPosition="left" :model="form" :rules="rules" ref="uForm">
  9. <u-form-item :labelWidth="80" label="头像:" borderBottom prop="img" ref="item1">
  10. <view class="photoView" @click="updateAvatar">
  11. <image class="photoImage" :src="form.imgUrl || '/static/ud4.png'"></image>
  12. </view>
  13. </u-form-item>
  14. <u-form-item :labelWidth="80" label="姓名:" borderBottom prop="name" ref="item1">
  15. <u--input v-model="form.name" placeholder="请输入姓名" border="none"></u--input>
  16. </u-form-item>
  17. <u-form-item :labelWidth="80" label="身份证号:" borderBottom prop="idCard" ref="item1">
  18. <u--input v-model="form.idCard" placeholder="请输入身份证号" border="none"></u--input>
  19. </u-form-item>
  20. <u-form-item :labelWidth="80" label="密码:" borderBottom prop="newPassword" ref="item1">
  21. <u--input v-model="form.newPassword" placeholder="请输入密码" type="password" border="none"></u--input>
  22. </u-form-item>
  23. <u-form-item :labelWidth="80" label="确认密码:" borderBottom prop="againPassword" ref="item1">
  24. <u--input v-model="form.againPassword" placeholder="再次确认密码" type="password"
  25. border="none"></u--input>
  26. </u-form-item>
  27. <u-form-item :labelWidth="80" label="手机号:" borderBottom prop="phone" ref="item1">
  28. <u--input v-model="form.phone" placeholder="请输入手机号" border="none"></u--input>
  29. </u-form-item>
  30. <u-form-item :labelWidth="80" label="验证码:" borderBottom prop="code" ref="item1">
  31. <view class="inputCode">
  32. <u--input v-model="form.code" placeholder="请输入验证码" border="none"></u--input>
  33. </view>
  34. <u-button slot="right" @tap="getCode" :text="tips" type="success" size="small"
  35. :disabled="disabled1"></u-button>
  36. </u-form-item>
  37. </u--form>
  38. <view :style="{'marginTop':'100rpx'}">
  39. <!-- <button class="customStyle" @click="expandRegister">提交</button>-->
  40. <button class="customStyle" @click="debounce(expandRegister,500)">提交</button>
  41. </view>
  42. <view class="flex-row justify-center register">
  43. <text>已有账号!</text>
  44. <text @click="gologin" :style="{color:'#FFE05C'}">切换登录</text>
  45. </view>
  46. </view>
  47. <u-code ref="uCode" @change="codeChange" seconds="60" @start="disabled1 = true"
  48. @end="disabled1 = false"></u-code>
  49. <u-action-sheet
  50. :show="showSex"
  51. :actions="actions"
  52. title="请选择性别"
  53. @close="showSex = false"
  54. @select="sexSelect">
  55. </u-action-sheet>
  56. <u-datetime-picker
  57. :show="showBirthday"
  58. :value="birthday"
  59. mode="date"
  60. closeOnClickOverlay
  61. @confirm="birthdayConfirm"
  62. @cancel="birthdayClose"
  63. @close="birthdayClose"
  64. ></u-datetime-picker>
  65. </view>
  66. </template>
  67. <script>
  68. export default {
  69. data() {
  70. return {
  71. timer: null, //定时任务
  72. recordId: '',//拓客经理二维码被扫记录id
  73. qrCodeInvalid: false,//二维码是否无效标识
  74. requestStatus: false,
  75. disabled1: false,
  76. showBirthday: false,
  77. showSex: false,
  78. birthday: Number(new Date()),
  79. actions: [{
  80. name: '男',
  81. value: '1'
  82. },
  83. {
  84. name: '女',
  85. value: '0'
  86. }, {
  87. name: '保密',
  88. value: '2'
  89. }
  90. ],
  91. tips: '',
  92. form: {
  93. roleId: '',
  94. parentId: '',
  95. img: '',
  96. imgUrl: '',
  97. name: '',
  98. idCard: '',
  99. newPassword: '',
  100. againPassword: '',
  101. phone: '',
  102. code: '',
  103. },
  104. rules: {
  105. 'img': {
  106. type: 'string',
  107. required: true,
  108. message: '请上传头像',
  109. trigger: ['blur', 'change']
  110. },
  111. 'name': [
  112. {
  113. type: 'string',
  114. required: true,
  115. min: 2,
  116. pattern: '^([\u4e00-\u9fa5]{2,20})$',
  117. message: '请输入正确的姓名',
  118. trigger: ['blur', 'change']
  119. }
  120. ],
  121. 'idCard': [
  122. {
  123. type: 'string',
  124. required: true,
  125. min: 18,
  126. max: 18,
  127. pattern: this.$idCardPattern,
  128. message: '请输入身份证号',
  129. trigger: ['blur', 'change']
  130. }
  131. ],
  132. 'phone': {
  133. type: 'string',
  134. required: true,
  135. min: 11,
  136. max: 11,
  137. pattern: this.$phonePattern,
  138. message: '请输入正确的电话号码',
  139. trigger: ['blur', 'change']
  140. },
  141. 'code': {
  142. type: 'string',
  143. required: true,
  144. min: 4,
  145. max: 6,
  146. message: '请输入验证码',
  147. trigger: ['blur', 'change']
  148. },
  149. 'newPassword': {
  150. type: 'string',
  151. min: 6,
  152. max: 16,
  153. required: true,
  154. message: '请输入6-18位密码',
  155. trigger: ['blur', 'change']
  156. },
  157. 'againPassword': {
  158. type: 'string',
  159. min: 6,
  160. max: 16,
  161. required: true,
  162. message: '请输入6-18位密码',
  163. trigger: ['blur', 'change']
  164. }
  165. },
  166. }
  167. },
  168. onLoad(e) {
  169. if (e.roleId) {
  170. console.log('++++++++++++扫码进注册页面+++++++++++++++++++')
  171. uni.setStorageSync('isRegister', true)
  172. this.form.roleId = e.roleId
  173. console.log('获取到的id', e.roleId)
  174. }
  175. if (e.type) {
  176. this.form.type = e.type
  177. console.log('获取到的type', e.type)
  178. }
  179. if (e.parentId) {
  180. this.form.parentId = e.parentId
  181. console.log('获取到的name', e.parentId)
  182. this.addRecordForManager()
  183. }
  184. if (e.timestamp) {
  185. console.log('获取到的时间戳', e.timestamp, new Date().getTime() > e.timestamp)
  186. if (new Date().getTime() > e.timestamp) {
  187. this.qrCodeInvalid = true
  188. uni.showModal({
  189. title: '温馨提示',
  190. content: ' 当前二维码已过期,请重新扫码',
  191. showCancel: false,
  192. success: function (res) {
  193. if (res.confirm) {
  194. console.log('用户点击确定');
  195. } else if (res.cancel) {
  196. console.log('用户点击取消');
  197. }
  198. }
  199. });
  200. }
  201. }
  202. },
  203. methods: {
  204. addRecordForManager() {
  205. console.log("+++++++++++++创建被扫码记录++++++++++++++")
  206. console.log("+++++++++++++拓客经理id++++++++++++++", this.form.parentId)
  207. console.log("+++++++++++++角色id++++++++++++++", this.form.roleId)
  208. this.$api.service.addRecordForManager({
  209. expandUserId: this.form.parentId,
  210. roleId: this.form.roleId,
  211. type: this.form.type
  212. }).then(res => {
  213. console.log("获取到的记录id", res.data.data)
  214. this.recordId = res.data.data
  215. })
  216. },
  217. updateScanRecordById() {
  218. this.$api.service.updateScanRecordById({
  219. recordId: this.recordId
  220. }).then(res => {
  221. console.log("+++++++++++++创建被扫码记录为成功++++++++++++++", res)
  222. })
  223. },
  224. idCardAndName() {
  225. return this.$api.service.idCardAndName({
  226. name: this.form.name,
  227. idCard: this.form.idCard,
  228. }).then(res => {
  229. return res
  230. })
  231. },
  232. gologin() {
  233. uni.redirectTo({
  234. url: '/pages/login/login'
  235. })
  236. },
  237. updateAvatar() {
  238. let that = this
  239. uni.chooseImage({
  240. count: 1, //默认9
  241. sizeType: ['compressed'], //可以指定是原图还是压缩图,默认二者都有
  242. sourceType: ['album'], //从相册选择
  243. success: function (res) {
  244. let tempUrl = res.tempFiles[0].path
  245. uni.uploadFile({
  246. url: that.$baseUrl + '/resource/oss/upload', //仅为示例,非真实的接口地址
  247. filePath: tempUrl,
  248. name: 'file',
  249. header: {
  250. // "Content-Type": "multipart/form-data",
  251. // 'X-Access-Token': uni.getStorageSync('token'),
  252. 'Authorization': 'Bearer ' + uni.getStorageSync('accessToken'),
  253. },
  254. success: (uploadFileRes) => {
  255. let res = JSON.parse(uploadFileRes.data)
  256. console.log('+++++++++++++++++chooseavatar+++++++++++++++++++++++', uploadFileRes.data)
  257. that.form.imgUrl = res.data.url.replace(/^http:/, "https:")
  258. that.form.img = res.data.ossId
  259. },
  260. fail: (err) => {
  261. console.log(err)
  262. uni.showToast({
  263. icon: 'error',
  264. duration: 2000,
  265. title: err.errMsg
  266. });
  267. }
  268. });
  269. },
  270. fail: function(err) {
  271. console.log(err)
  272. uni.showToast({
  273. icon: 'error',
  274. duration: 2000,
  275. title: err.errMsg
  276. });
  277. }
  278. })
  279. },
  280. birthdayClose() {
  281. this.showBirthday = false
  282. // this.$refs.form1.validateField('userInfo.birthday')
  283. },
  284. birthdayConfirm(e) {
  285. console.log(e)
  286. this.showBirthday = false
  287. this.form.birthday = uni.$u.timeFormat(e.value, 'yyyy-mm-dd')
  288. // this.$refs.form1.validateField('userInfo.birthday')
  289. },
  290. sexSelect(e) {
  291. console.log(e)
  292. },
  293. expandRegister() {
  294. if (this.qrCodeInvalid) {
  295. uni.showModal({
  296. title: '温馨提示',
  297. content: ' 当前二维码已过期,请重新扫码',
  298. showCancel: false,
  299. success: function (res) {
  300. if (res.confirm) {
  301. console.log('用户点击确定');
  302. } else if (res.cancel) {
  303. console.log('用户点击取消');
  304. }
  305. }
  306. });
  307. return;
  308. }
  309. if (this.requestStatus) {
  310. return
  311. }
  312. this.requestStatus = true
  313. this.rules.idCard = [
  314. {
  315. type: 'string',
  316. required: true,
  317. min: 18,
  318. max: 18,
  319. pattern: this.$idCardPattern,
  320. message: '请输入身份证号',
  321. trigger: ['blur', 'change']
  322. }
  323. ]
  324. this.$refs.uForm.validate().then(res => {
  325. console.log('验证不通过!!!!')
  326. this.idCardAndName().then(res => {
  327. if (res.data.data != null && res.data.data.respCode !== '0000') {
  328. this.rules.idCard.push({
  329. validator: (a, b, callback) => {
  330. callback(new Error(res.data.data.respMessage));
  331. },
  332. // 触发器可以同时用blur和change
  333. trigger: []
  334. })
  335. this.$refs.uForm.validateField('idCard')
  336. } else {
  337. // 如果校验通过执行注册
  338. uni.showLoading({
  339. title: '正在注册...'
  340. });
  341. this.$api.login.expandRegister(this.form).then(res => {
  342. uni.hideLoading();
  343. uni.showToast({
  344. icon: 'success',
  345. duration: 2000,
  346. title: '注册成功,即将跳转登录页'
  347. });
  348. uni.removeStorageSync('isRegister');
  349. setTimeout(() => {
  350. this.requestStatus = false
  351. this.gologin()
  352. }, 2000)
  353. this.updateScanRecordById()
  354. }).catch(err => {
  355. uni.hideLoading();
  356. this.requestStatus = false
  357. })
  358. }
  359. }).finally((res)=>{
  360. console.log('改为false')
  361. this.requestStatus = false
  362. })
  363. }).catch(err => {
  364. this.requestStatus = false
  365. })
  366. },
  367. logout() {
  368. this.$api.login.logout().then(res => {
  369. uni.clearStorageSync();
  370. uni.navigateTo({
  371. url: '/pages/login/login'
  372. })
  373. })
  374. },
  375. back() {
  376. uni.navigateBack({
  377. delta: 1
  378. });
  379. },
  380. codeChange(text) {
  381. this.tips = text;
  382. },
  383. getCode() {
  384. let regExp = new RegExp(this.$phonePattern);
  385. let b = regExp.test(this.form.phone)
  386. if (!b) {
  387. uni.$u.toast('请输入正确的手机号')
  388. return
  389. }
  390. if (this.$refs.uCode.canGetCode) {
  391. // 模拟向后端请求验证码
  392. uni.showLoading({
  393. title: '正在获取验证码'
  394. })
  395. this.$api.service.getSmsCode({phonenumber: this.form.phone}).then(res => {
  396. uni.hideLoading();
  397. // 这里此提示会被this.start()方法中的提示覆盖
  398. uni.$u.toast('验证码已发送');
  399. // 通知验证码组件内部开始倒计时
  400. this.$refs.uCode.start();
  401. })
  402. } else {
  403. uni.$u.toast('倒计时结束后再发送');
  404. }
  405. },
  406. debounce(fn, delay) {
  407. console.log(delay)
  408. clearTimeout(this.timer);
  409. this.timer = setTimeout(() => {
  410. fn.apply();
  411. }, delay);
  412. }
  413. }
  414. }
  415. </script>
  416. <style lang="scss" scoped>
  417. @import './index.rpx.css';
  418. </style>