index.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. <template>
  2. <view class="container-login" :style="appThemeStyle">
  3. <!-- 表单 -->
  4. <view class="submit-form">
  5. <!-- 页面头部 -->
  6. <view class="header">
  7. <view class="title">
  8. <text>企业账户注册</text>
  9. </view>
  10. <view class="sub-title">
  11. <text>未注册的手机号登录后将自动注册</text>
  12. </view>
  13. </view>
  14. <!-- 手机号 -->
  15. <view class="form-item">
  16. <input class="form-item--input" type="number" v-model="agentstel" maxlength="11" placeholder="请输入手机号码" />
  17. </view>
  18. <!-- 请填写商户名称 -->
  19. <view class="form-item">
  20. <input class="form-item--input" type="text" v-model="agentsname" placeholder="请填写企业名称" />
  21. </view>
  22. <!-- 代理商联系地址 -->
  23. <view class="form-item">
  24. <select-region class="form-dizhi" ref="sRegion" v-model="address" />
  25. </view>
  26. <!-- 代理商联系地址 -->
  27. <view class="form-item">
  28. <input class="form-item--input" type="text" v-model="agentsadress" placeholder="请填写详细地址" />
  29. </view>
  30. <!-- 图形验证码 -->
  31. <!-- <view class="form-item">
  32. <input class="form-item--input" type="text" v-model="captchaCode" maxlength="5" placeholder="请输入图形验证码" />
  33. <view class="form-item--parts">
  34. <view class="captcha" @click="getCaptcha()">
  35. <image class="image" :src="captcha.base64"></image>
  36. </view>
  37. </view>
  38. </view> -->
  39. <!-- 短信验证码 -->
  40. <view class="form-item">
  41. <input class="form-item--input" type="number" v-model="smsCode" maxlength="6" placeholder="请输入短信验证码" />
  42. <view class="form-item--parts">
  43. <view class="captcha-sms" @click="handelSmsCaptcha()">
  44. <text v-if="!smsState" class="activate">获取验证码</text>
  45. <text v-else class="un-activate">重新发送({{ times }})秒</text>
  46. </view>
  47. </view>
  48. </view>
  49. </view>
  50. <!-- 确认绑定 -->
  51. <view class="submit-button" @click="handleSubmit()">
  52. <text>登 录</text>
  53. </view>
  54. </view>
  55. </template>
  56. <script>
  57. import store from '@/store'
  58. import * as UserApi from '@/api/user'
  59. import * as CaptchaApi from '@/api/captcha'
  60. import * as Verify from '@/utils/verify'
  61. import * as AppApi from '@/api/app'
  62. import storage from '@/utils/storage'
  63. import SelectRegion from '@/components/select-region/select-region'
  64. // 倒计时时长(秒)
  65. const times = 60
  66. // 表单验证场景
  67. const GET_CAPTCHA = 10
  68. const FORM_SUBMIT = 20
  69. export default {
  70. data() {
  71. return {
  72. // 正在加载
  73. isLoading: false,
  74. // 图形验证码信息
  75. captcha: {},
  76. // 短信验证码发送状态
  77. smsState: false,
  78. // 倒计时
  79. times,
  80. // 手机号
  81. agentstel: '',
  82. agentsname: '',
  83. agentsadress: '',
  84. address: '',
  85. // 图形验证码
  86. captchaCode: '',
  87. // 短信验证码
  88. smsCode: '',
  89. wx_userid: storage.get('wx_userid'),
  90. wx_openid: storage.get('wx_openid')
  91. }
  92. },
  93. components: {
  94. SelectRegion
  95. },
  96. /**
  97. * 生命周期函数--监听页面加载
  98. */
  99. created() {
  100. // 获取图形验证码
  101. // this.getCaptcha()
  102. if (storage.get('wx_userinfo').customertype == '代理商') {
  103. // 如果已经是代理商则直接登录
  104. this.$navTo('pages/firm/home/index')
  105. }
  106. },
  107. methods: {
  108. // 获取图形验证码
  109. getCaptcha() {
  110. const app = this
  111. CaptchaApi.image().then((result) => (app.captcha = result.data))
  112. },
  113. // 点击发送短信验证码
  114. handelSmsCaptcha() {
  115. const app = this
  116. if (!app.isLoading && !app.smsState && app.formValidation(GET_CAPTCHA)) {
  117. app.sendSmsCaptcha()
  118. }
  119. },
  120. // 表单验证
  121. formValidation(scene = GET_CAPTCHA) {
  122. const app = this
  123. // 验证获取短信验证码
  124. if (scene === GET_CAPTCHA) {
  125. if (!app.validteMobile(app.agentstel)) {
  126. return false
  127. }
  128. }
  129. // 验证表单提交
  130. if (scene === FORM_SUBMIT) {
  131. if (!app.validteMobile(app.agentstel) || !app.validteSmsCode(app.smsCode)) {
  132. return false
  133. }
  134. }
  135. return true
  136. },
  137. // 验证手机号
  138. validteMobile(str) {
  139. if (Verify.isEmpty(str)) {
  140. this.$toast('请先输入手机号')
  141. return false
  142. }
  143. if (!Verify.isMobile(str)) {
  144. this.$toast('请输入正确格式的手机号')
  145. return false
  146. }
  147. return true
  148. },
  149. // 验证图形验证码
  150. validteCaptchaCode(str) {
  151. if (Verify.isEmpty(str)) {
  152. this.$toast('请先输入图形验证码')
  153. return false
  154. }
  155. return true
  156. },
  157. // 验证短信验证码
  158. validteSmsCode(str) {
  159. if (Verify.isEmpty(str)) {
  160. this.$toast('请先输入短信验证码')
  161. return false
  162. }
  163. return true
  164. },
  165. // 请求发送短信验证码接口
  166. sendSmsCaptcha() {
  167. const app = this
  168. app.isLoading = true
  169. AppApi.getSmsCode({mobile: app.agentstel})
  170. .then((result) => {
  171. // 显示发送成功
  172. app.$toast('发送成功')
  173. // 执行定时器
  174. app.timer()
  175. })
  176. .finally(() => {
  177. app.isLoading = false
  178. })
  179. },
  180. // 执行定时器
  181. timer() {
  182. const app = this
  183. app.smsState = true
  184. const inter = setInterval(() => {
  185. app.times = app.times - 1
  186. if (app.times <= 0) {
  187. app.smsState = false
  188. app.times = times
  189. clearInterval(inter)
  190. }
  191. }, 1000)
  192. },
  193. // 点击提交
  194. handleSubmit() {
  195. const app = this
  196. if (!app.isLoading && app.formValidation(FORM_SUBMIT)) {
  197. app.onSubmitEvent()
  198. }
  199. },
  200. // 确认提交事件
  201. onSubmitEvent() {
  202. const app = this
  203. if (Verify.isEmpty(app.address)) {
  204. this.$toast('请选择地区')
  205. return false
  206. }
  207. if (Verify.isEmpty(app.agentsname)) {
  208. this.$toast('请填写商户名称')
  209. return false
  210. }
  211. app.isLoading = true
  212. let platform = {
  213. agentscustomerid: storage.get('wx_userid'),
  214. agentsname: app.agentsname,
  215. agentsadress: app.agentsadress,
  216. agentstel: app.agentstel,
  217. agentsprovince: app.address[0].label,
  218. agentscity: app.address[1].label,
  219. agentsarea: app.address[2].label,
  220. smscode: app.smsCode
  221. }
  222. AppApi.companyLogin(platform)
  223. .then((res) => {
  224. // 显示操作成功
  225. app.$toast('登录成功,正在跳转')
  226. // 登录成功存储企业信息
  227. storage.set('wx_qyid', res.Data.id)
  228. storage.set('wx_qym', res.Data.qym)
  229. setTimeout(() => {
  230. this.$navTo('pages/firm/home/index')
  231. }, 1000)
  232. })
  233. .finally(() => (app.isLoading = false))
  234. },
  235. /**
  236. * 提交成功-跳转回原页面
  237. */
  238. onNavigateBack(delta) {
  239. uni.navigateBack({
  240. delta: Number(delta || 1)
  241. })
  242. }
  243. }
  244. }
  245. </script>
  246. <style lang="scss" scoped>
  247. .container-login {
  248. padding: 30rpx 60rpx;
  249. padding-top: 200rpx;
  250. min-height: 100vh;
  251. background-color: #fff;
  252. }
  253. // 页面头部
  254. .header {
  255. margin-bottom: 50rpx;
  256. .title {
  257. color: #0081ff;
  258. font-size: 50rpx;
  259. font-weight: 900;
  260. }
  261. .sub-title {
  262. margin-top: 20rpx;
  263. color: #0080ffa9;
  264. font-size: 25rpx;
  265. }
  266. }
  267. .shiming {
  268. margin-top: 90rpx;
  269. }
  270. // 输入框元素
  271. .form-item {
  272. display: flex;
  273. padding: 18rpx;
  274. border-bottom: 1rpx solid #f3f1f2;
  275. margin-bottom: 25rpx;
  276. height: 96rpx;
  277. font-size: 30rpx;
  278. color: #333;
  279. &--input {
  280. font-size: 30rpx;
  281. letter-spacing: 1rpx;
  282. flex: 1;
  283. height: 100%;
  284. color: #333;
  285. }
  286. &--parts {
  287. min-width: 100rpx;
  288. height: 100%;
  289. }
  290. // 图形验证码
  291. .captcha {
  292. height: 100%;
  293. .image {
  294. display: block;
  295. width: 192rpx;
  296. height: 100%;
  297. }
  298. }
  299. // 短信验证码
  300. .captcha-sms {
  301. font-size: 30rpx;
  302. line-height: 50rpx;
  303. padding-right: 20rpx;
  304. .activate {
  305. color: #0081ff;
  306. }
  307. .un-activate {
  308. color: #9e9e9e;
  309. }
  310. }
  311. }
  312. // 提交按钮
  313. .submit-button {
  314. width: 100%;
  315. height: 86rpx;
  316. margin-top: 70rpx;
  317. background: linear-gradient(to right, $main-bg, $main-bg2);
  318. color: $main-text;
  319. border-radius: 80rpx;
  320. box-shadow: 0px 10px 20px 0px rgba(0, 0, 0, 0.1);
  321. letter-spacing: 5rpx;
  322. display: flex;
  323. justify-content: center;
  324. align-items: center;
  325. background-image: linear-gradient(-20deg, #b721ff 0%, #21d4fd 100%);
  326. }
  327. .form-dizhi {
  328. color: gray;
  329. }
  330. </style>