index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  1. <template>
  2. <div class="wrapper">
  3. <img class="goods-cover" src="./image/banner@2x.png" alt="">
  4. <ul class="form-wrap">
  5. <li class="form-item">
  6. <label>
  7. <span class="label-name" v-for="(str, index) in '姓名:姓名'" :key="index">{{ str }}</span>
  8. </label>
  9. <div class="value-wrap">
  10. <div class="value-name">
  11. <input type="text" placeholder="请输入姓名" v-myBlur v-model.trim="postData.orderUserName">
  12. </div>
  13. <div class="value-gender">
  14. <p v-for="str in ['男', '女']" :key="str" @click="postData.orderUserSex = str">
  15. <img src="./image/btn_xingbie_sel@2x.png" alt="" v-show="postData.orderUserSex === str">
  16. <img src="./image/btn_xingbie_nor@2x.png" alt="" v-show="postData.orderUserSex !== str">
  17. <span>{{ str }}</span>
  18. </p>
  19. </div>
  20. </div>
  21. </li>
  22. <li class="form-item">
  23. <label>
  24. <span v-for="(str, index) in '手机号码:'" :key="index">{{ str }}</span>
  25. </label>
  26. <div class="value-wrap">
  27. <input
  28. type="tel"
  29. placeholder="请输入手机号码"
  30. v-myBlur
  31. v-model.trim="postData.orderUserPhone"
  32. @input="postData.orderUserPhone = postData.orderUserPhone.replace(/[^\d]/, '').replace(/^0/, '').replace(/(\d{11})(.*)/, '$1')">
  33. </div>
  34. </li>
  35. <li class="form-item">
  36. <label>
  37. <span class="label-code" v-for="(str, index) in '验证码:码'" :key="index">{{ str }}</span>
  38. </label>
  39. <div class="value-wrap">
  40. <input
  41. type="tel"
  42. placeholder="请输入验证码"
  43. v-myBlur v-model.trim="postData.code"
  44. @input="postData.code = postData.code.replace(/[^\d]/, '').replace(/(\d{4})(.*)/, '$1')">
  45. </div>
  46. <button class="get-code" @click="funGetCode">{{ [0, 60].includes(numCount) ? '获取' : numCount + '秒' }}</button>
  47. </li>
  48. <li class="form-item">
  49. <label>
  50. <span v-for="(str, index) in '所在城市:'" :key="index">{{ str }}</span>
  51. </label>
  52. <div class="value-wrap" @click="showPicker = true">
  53. <p class="value-city" v-show="postData.orderProvince">{{
  54. postData.orderProvince + postData.orderCity +
  55. postData.orderDistrict
  56. }}</p>
  57. <p class="value-city init" v-show="!postData.orderProvince">请选择所在城市</p>
  58. <img src="./image/btn_next@2x.png" alt="">
  59. </div>
  60. </li>
  61. <li class="form-item">
  62. <label>
  63. <span v-for="(str, index) in '小区名称:'" :key="index">{{ str }}</span>
  64. </label>
  65. <div class="value-wrap">
  66. <textarea
  67. name=""
  68. rows="1"
  69. placeholder="请输入小区名称"
  70. v-model.trim="postData.orderAddress"
  71. v-myBlur
  72. ref="myTextarea"></textarea>
  73. </div>
  74. </li>
  75. <li class="form-item">
  76. <label>
  77. <span v-for="(str, index) in '需求金额(万元):'" :key="index">{{ str }}</span>
  78. </label>
  79. <div class="value-wrap amount-wrap">
  80. <input
  81. :class="{'opacity-0': postData.orderPrice * 1 > 0}"
  82. type="tel" placeholder="请输入需求金额"
  83. v-myBlur
  84. v-model.trim="amount"
  85. @input="amount = amount.replace(/[^\d]/, '').replace(/^0/, '')">
  86. <p v-show="postData.orderPrice * 1 > 0">{{ postData.orderPrice * 1 | toThousands }}</p>
  87. </div>
  88. </li>
  89. <li class="form-item">
  90. <label>
  91. <span v-for="(str, index) in '是否有房'" :key="index">{{ str }}</span>
  92. </label>
  93. <div class="value-wrap">
  94. <div class="value-name"></div>
  95. <div class="value-gender">
  96. <p v-for="str in ['有', '无']" :key="str" @click="postData.orderUserSex = str">
  97. <img src="./image/btn_xingbie_sel@2x.png" alt="" v-show="postData.orderUserSex === str">
  98. <img src="./image/btn_xingbie_nor@2x.png" alt="" v-show="postData.orderUserSex !== str">
  99. <span>{{ str }}</span>
  100. </p>
  101. </div>
  102. </div>
  103. </li>
  104. <li>
  105. <button class="submit" @click="funSubmit">提交</button>
  106. </li>
  107. <li>
  108. <p class="explain">
  109. <span>申请代表您同意</span>
  110. <router-link :to="{path: '/loan/privacy'}">《用户隐私协议》</router-link>
  111. <span>和</span>
  112. <router-link :to="{path: '/loan/agreement'}">《服务协议》</router-link>
  113. </p>
  114. </li>
  115. </ul>
  116. <div class="about"></div>
  117. <van-popup v-model="showPicker" round position="bottom">
  118. <van-picker
  119. show-toolbar
  120. title="所在城市"
  121. :columns="columns"
  122. @cancel="showPicker = false"
  123. @confirm="onConfirm"/>
  124. </van-popup>
  125. </div>
  126. </template>
  127. <script>
  128. import { Popup, Picker, Toast } from 'vant'
  129. import { createOrder } from './api'
  130. import { getChinaArea, sendSMS } from '../../../api/common'
  131. export default {
  132. name: 'onlineAct',
  133. components: {
  134. 'van-popup': Popup,
  135. 'van-picker': Picker
  136. },
  137. props: {
  138. partnerId: {
  139. type: String,
  140. default: ''
  141. },
  142. RId: {
  143. type: [String, Number],
  144. default: ''
  145. }
  146. },
  147. data () {
  148. return {
  149. postData: {
  150. orderUserName: '', // 用户名称
  151. orderUserSex: '男',
  152. orderUserPhone: '', // 手机号码
  153. code: '', // 验证码
  154. capture: '',
  155. orderPrice: '', // 申请金额
  156. orderProvince: '', // 省份
  157. orderCity: '', // 城市
  158. orderDistrict: '', // 区域
  159. orderAddress: '' // 详细地址
  160. },
  161. numCount: 60,
  162. arrErrorList: [],
  163. showPicker: false,
  164. columns: [],
  165. timer: null
  166. }
  167. },
  168. computed: {
  169. amount: {
  170. get () {
  171. return this.postData.orderPrice * 1 ? this.postData.orderPrice : ''
  172. },
  173. set (value) {
  174. this.postData.orderPrice = value
  175. }
  176. }
  177. },
  178. async mounted () {
  179. this.funGetChinaArea()
  180. await this.$nextTick()
  181. const textarea = this.$refs.myTextarea
  182. if (textarea) {
  183. this.handleTextarea(textarea)
  184. textarea.addEventListener('input', this.handleTextarea(textarea, 1), false)
  185. this.$once('hook:beforeDestroy', () => {
  186. textarea.addEventListener('input', this.handleTextarea(textarea, 1), false)
  187. })
  188. }
  189. this.$refreshTitle('在线申请')
  190. },
  191. methods: {
  192. funGetChinaArea () {
  193. getChinaArea().then(res => {
  194. if (res.status) {
  195. this.columns = res.data.filter(province => province.text === '浙江')
  196. } else {
  197. Toast(res.msg)
  198. }
  199. }).catch(err => {
  200. Toast(err)
  201. })
  202. },
  203. handleTextarea (el, auto) {
  204. return () => {
  205. if (auto) {
  206. el.style.height = 'auto'
  207. }
  208. el.style.height = el.scrollHeight + 'px'
  209. }
  210. },
  211. onConfirm (value) {
  212. this.showPicker = false
  213. this.$set(this.postData, 'orderProvince', value[0])
  214. this.$set(this.postData, 'orderCity', value[1])
  215. this.$set(this.postData, 'orderDistrict', value[2])
  216. },
  217. funCutDown () {
  218. clearInterval(this.timer)
  219. this.timer = setInterval(() => {
  220. if (this.numCount === 0) {
  221. clearInterval(this.timer)
  222. this.numCount = 0
  223. return
  224. }
  225. this.numCount--
  226. }, 1000)
  227. },
  228. // 获取验证码
  229. funGetCode () {
  230. const numCount = this.numCount
  231. const { orderUserPhone, capture } = this.postData
  232. if (numCount < 60 && numCount > 0) {
  233. return
  234. }
  235. this.numCount = 60
  236. if (!(/^1[2|3|4|5|6|7|8|9]\d{9}$/.test(orderUserPhone))) {
  237. Toast('请输入手机号码')
  238. return
  239. }
  240. this.funCutDown()
  241. sendSMS(orderUserPhone, 0, capture).then(res => {
  242. if (res.status) {
  243. Toast('发送成功')
  244. } else {
  245. Toast(res.msg)
  246. clearInterval(this.timer)
  247. this.numCount = 60
  248. }
  249. }).catch(err => {
  250. Toast(err.msg)
  251. clearInterval(this.timer)
  252. this.numCount = 60
  253. })
  254. },
  255. verifyData () {
  256. const {
  257. orderUserName,
  258. orderUserSex,
  259. orderUserPhone,
  260. code,
  261. orderProvince,
  262. orderCity,
  263. orderDistrict,
  264. orderAddress,
  265. orderPrice
  266. } = this.postData
  267. this.arrErrorList = []
  268. if (!orderUserName) {
  269. this.arrErrorList.push('请输入姓名')
  270. }
  271. if (!orderUserSex) {
  272. this.arrErrorList.push('请选择性别')
  273. }
  274. if (!/^1[2|3|4|5|6|7|8|9]\d{9}$/.test(orderUserPhone)) {
  275. this.arrErrorList.push('请输入手机号码')
  276. }
  277. if (!(/^\d{4}$/.test(code))) {
  278. this.arrErrorList.push('请输入验证码')
  279. }
  280. if (!orderProvince || !orderCity || !orderDistrict) {
  281. this.arrErrorList.push('请选择所在城市')
  282. }
  283. if (!orderAddress) {
  284. this.arrErrorList.push('请输入小区名称')
  285. }
  286. if (orderPrice * 1 <= 0) {
  287. this.arrErrorList.push('请输入需求金额')
  288. }
  289. return this.arrErrorList.length <= 0
  290. },
  291. funSubmit () {
  292. const postData = {
  293. partnerId: this.partnerId,
  294. userNewId: this.RId,
  295. ...this.postData
  296. }
  297. delete postData.capture
  298. if (!this.verifyData()) {
  299. Toast({
  300. message: this.arrErrorList[0],
  301. forbidClick: true
  302. })
  303. return
  304. }
  305. const myToast = Toast.loading({
  306. message: '提交中...',
  307. duration: 1000 * 100,
  308. forbidClick: true
  309. })
  310. createOrder(postData).then(res => {
  311. myToast.clear()
  312. if (res.status) {
  313. Toast({
  314. type: 'success',
  315. message: '提交成功',
  316. forbidClick: true,
  317. onClose: () => {
  318. }
  319. })
  320. return
  321. }
  322. Toast(res.msg)
  323. }).catch(err => {
  324. myToast.clear()
  325. Toast(err)
  326. })
  327. }
  328. }
  329. }
  330. </script>
  331. <style lang="scss" scoped>
  332. .wrapper {
  333. position: relative;
  334. left: 0;
  335. top: 0;
  336. display: flex;
  337. flex-direction: column;
  338. align-items: center;
  339. width: 100%;
  340. min-height: 100vh;
  341. background: #3D82D9;
  342. }
  343. .goods-cover {
  344. display: block;
  345. width: 100%;
  346. min-height: 170px;
  347. margin-bottom: 10px;
  348. }
  349. .form-wrap {
  350. width: 356px;
  351. padding-top: 8px;
  352. padding-bottom: 26px;
  353. border-radius: 9px;
  354. background: #FFFFFF;
  355. .form-item {
  356. position: relative;
  357. left: 0;
  358. top: 0;
  359. display: flex;
  360. align-items: flex-start;
  361. width: 327px;
  362. padding: 13px 14px;
  363. margin: 8px auto 0;
  364. border: 1px solid #E8E8E8;
  365. border-radius: 4px;
  366. }
  367. label {
  368. display: flex;
  369. span {
  370. line-height: 22px;
  371. font-size: 16px;
  372. font-weight: 500;
  373. color: #333;
  374. &.label-name:nth-of-type(4),
  375. &.label-name:nth-of-type(5),
  376. &.label-code:nth-of-type(5), {
  377. visibility: hidden;
  378. }
  379. }
  380. }
  381. .value-wrap {
  382. flex: 1;
  383. display: flex;
  384. margin-left: 9px;
  385. }
  386. .amount-wrap {
  387. position: relative;
  388. left: 0;
  389. top: 0;
  390. input {
  391. position: absolute;
  392. left: 0;
  393. top: 0;
  394. z-index: 1;
  395. &.opacity-0 {
  396. opacity: 0;
  397. }
  398. }
  399. p {
  400. width: 100%;
  401. padding-top: 2px;
  402. line-height: 20px;
  403. font-size: 15px;
  404. color: #333;
  405. }
  406. }
  407. input,
  408. textarea {
  409. width: 100%;
  410. min-height: 20px;
  411. padding-top: 2px;
  412. line-height: 20px;
  413. font-size: 15px;
  414. color: #333;
  415. word-break: break-all;
  416. resize: none;
  417. outline: 0 none;
  418. overflow: hidden;
  419. background: transparent;
  420. -webkit-text-fill-color: #333;
  421. opacity: 1;
  422. &::-webkit-input-placeholder {
  423. color: #999;
  424. -webkit-text-fill-color: #999;
  425. opacity: 1;
  426. }
  427. }
  428. .value-name {
  429. display: flex;
  430. width: 100%;
  431. }
  432. .value-gender {
  433. display: flex;
  434. p {
  435. display: flex;
  436. &:nth-of-type(2) {
  437. margin-left: 15px;
  438. }
  439. }
  440. span {
  441. margin-left: 4px;
  442. line-height: 22px;
  443. font-size: 16px;
  444. color: #333;
  445. }
  446. }
  447. .value-city {
  448. flex: 1;
  449. line-height: 22px;
  450. font-size: 15px;
  451. color: #333;
  452. &.init {
  453. color: #999;
  454. }
  455. }
  456. img {
  457. width: 22px;
  458. height: 22px;
  459. }
  460. .capture-img {
  461. @include vertical-center;
  462. right: 14px;
  463. z-index: 1;
  464. display: block;
  465. width: 125px;
  466. height: 31px;
  467. border-radius: 4px;
  468. overflow: hidden;
  469. }
  470. .get-code {
  471. @include vertical-center;
  472. right: 0;
  473. z-index: 1;
  474. display: block;
  475. min-width: 87px;
  476. padding: 6px;
  477. line-height: 22px;
  478. font-size: 16px;
  479. font-weight: 500;
  480. color: #3D82D9;
  481. }
  482. }
  483. .submit {
  484. display: block;
  485. width: 327px;
  486. height: 45px;
  487. margin: 18px auto 0;
  488. border-radius: 4px;
  489. line-height: 45px;
  490. font-size: 14px;
  491. font-weight: 500;
  492. color: #fff;
  493. background: #3D82D9;
  494. }
  495. .explain {
  496. display: flex;
  497. width: 327px;
  498. padding-left: 10px;
  499. margin: 12px auto 0;
  500. span,
  501. a {
  502. line-height: 17px;
  503. font-size: 12px;
  504. color: #666;
  505. }
  506. }
  507. .about {
  508. width: 100%;
  509. height: 647px;
  510. margin-top: 28px;
  511. background: url("./image/explain@2x.png") center top/100% 100% no-repeat;
  512. }
  513. </style>