register.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  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: false,
  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. this.$api.service.idCardAndName({
  226. name: this.form.name,
  227. idCard: this.form.idCard,
  228. }).then(res => {
  229. if (res.data.data != null && res.data.data.respCode !== '0000') {
  230. this.rules.idCard.push({
  231. validator: (a, b, callback) => {
  232. callback(new Error(res.data.data.respMessage));
  233. },
  234. // 触发器可以同时用blur和change
  235. trigger: []
  236. })
  237. this.$refs.uForm.validateField('idCard')
  238. }else {
  239. this.register()
  240. }
  241. })
  242. },
  243. gologin() {
  244. uni.redirectTo({
  245. url: '/pages/login/login'
  246. })
  247. },
  248. updateAvatar() {
  249. let that = this
  250. uni.chooseImage({
  251. count: 1, //默认9
  252. sizeType: ['compressed'], //可以指定是原图还是压缩图,默认二者都有
  253. sourceType: ['album'], //从相册选择
  254. success: function (res) {
  255. let tempUrl = res.tempFiles[0].path
  256. uni.uploadFile({
  257. url: that.$baseUrl + '/resource/oss/upload', //仅为示例,非真实的接口地址
  258. filePath: tempUrl,
  259. name: 'file',
  260. header: {
  261. // "Content-Type": "multipart/form-data",
  262. // 'X-Access-Token': uni.getStorageSync('token'),
  263. 'Authorization': 'Bearer ' + uni.getStorageSync('accessToken'),
  264. },
  265. success: (uploadFileRes) => {
  266. let res = JSON.parse(uploadFileRes.data)
  267. console.log('+++++++++++++++++chooseavatar+++++++++++++++++++++++', uploadFileRes.data)
  268. that.form.imgUrl = res.data.url.replace(/^http:/, "https:")
  269. that.form.img = res.data.ossId
  270. },
  271. fail: (err) => {
  272. console.log(err)
  273. uni.showToast({
  274. icon: 'error',
  275. duration: 2000,
  276. title: err.errMsg
  277. });
  278. }
  279. });
  280. },
  281. fail: function (err) {
  282. console.log(err)
  283. uni.showToast({
  284. icon: 'error',
  285. duration: 2000,
  286. title: err.errMsg
  287. });
  288. }
  289. })
  290. },
  291. birthdayClose() {
  292. this.showBirthday = false
  293. // this.$refs.form1.validateField('userInfo.birthday')
  294. },
  295. birthdayConfirm(e) {
  296. console.log(e)
  297. this.showBirthday = false
  298. this.form.birthday = uni.$u.timeFormat(e.value, 'yyyy-mm-dd')
  299. // this.$refs.form1.validateField('userInfo.birthday')
  300. },
  301. sexSelect(e) {
  302. console.log(e)
  303. },
  304. expandRegister() {
  305. if (this.qrCodeInvalid) {
  306. uni.showModal({
  307. title: '温馨提示',
  308. content: ' 当前二维码已过期,请重新扫码',
  309. showCancel: false,
  310. success: function (res) {
  311. if (res.confirm) {
  312. console.log('用户点击确定');
  313. } else if (res.cancel) {
  314. console.log('用户点击取消');
  315. }
  316. }
  317. });
  318. return;
  319. }
  320. // this.rules.idCard = [
  321. // {
  322. // type: 'string',
  323. // required: false,
  324. // min: 18,
  325. // max: 18,
  326. // pattern: this.$idCardPattern,
  327. // message: '请输入身份证号',
  328. // trigger: ['blur', 'change']
  329. // }
  330. // ]
  331. this.$refs.uForm.validate().then(validate => {
  332. this.register()
  333. })
  334. },
  335. register () {
  336. if (this.requestStatus) {
  337. return
  338. }
  339. this.requestStatus = true
  340. // 如果校验通过执行注册
  341. uni.showLoading({
  342. title: '正在注册...'
  343. });
  344. this.$api.login.expandRegister(this.form).then(res => {
  345. uni.hideLoading();
  346. uni.showToast({
  347. icon: 'success',
  348. duration: 2000,
  349. title: '注册成功,即将跳转登录页'
  350. });
  351. uni.removeStorageSync('isRegister');
  352. setTimeout(() => {
  353. this.requestStatus = false
  354. this.gologin()
  355. }, 2000)
  356. this.updateScanRecordById()
  357. }).catch(err => {
  358. uni.hideLoading();
  359. this.requestStatus = false
  360. })
  361. },
  362. logout() {
  363. this.$api.login.logout().then(res => {
  364. uni.clearStorageSync();
  365. uni.navigateTo({
  366. url: '/pages/login/login'
  367. })
  368. })
  369. },
  370. back() {
  371. uni.navigateBack({
  372. delta: 1
  373. });
  374. },
  375. codeChange(text) {
  376. this.tips = text;
  377. },
  378. getCode() {
  379. let regExp = new RegExp(this.$phonePattern);
  380. let b = regExp.test(this.form.phone)
  381. if (!b) {
  382. uni.$u.toast('请输入正确的手机号')
  383. return
  384. }
  385. if (this.$refs.uCode.canGetCode) {
  386. // 模拟向后端请求验证码
  387. uni.showLoading({
  388. title: '正在获取验证码'
  389. })
  390. this.$api.service.getSmsCode({phonenumber: this.form.phone}).then(res => {
  391. uni.hideLoading();
  392. // 这里此提示会被this.start()方法中的提示覆盖
  393. uni.$u.toast('验证码已发送');
  394. // 通知验证码组件内部开始倒计时
  395. this.$refs.uCode.start();
  396. })
  397. } else {
  398. uni.$u.toast('倒计时结束后再发送');
  399. }
  400. },
  401. debounce(fn, delay) {
  402. console.log(delay)
  403. clearTimeout(this.timer);
  404. this.timer = setTimeout(() => {
  405. fn.apply();
  406. }, delay);
  407. }
  408. }
  409. }
  410. </script>
  411. <style lang="scss" scoped>
  412. @import './index.rpx.css';
  413. </style>