register.vue 16 KB

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