index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  1. <template>
  2. <div class="wrapper">
  3. <img class="goods-cover" src="./image/header@2x.png" alt="">
  4. <Flow></Flow>
  5. <ul class="form-wrap">
  6. <li>
  7. <label>
  8. <span class="label-name" v-for="(str, index) in '姓名:姓名'" :key="index">{{ str }}</span>
  9. </label>
  10. <div class="value-wrap">
  11. <div class="value-name">
  12. <input type="text" placeholder="请输入姓名" v-model.trim="postData.name">
  13. </div>
  14. <div class="value-gender">
  15. <p v-for="(str, index) in ['男', '女']" :key="index" @click="postData.gender = index">
  16. <img src="./image/btn_xingbie_sel@2x.png" alt="" v-show="postData.gender === index">
  17. <img src="./image/btn_xingbie_nor@2x.png" alt="" v-show="postData.gender !== index">
  18. <span>{{ str }}</span>
  19. </p>
  20. </div>
  21. </div>
  22. </li>
  23. <li>
  24. <label>
  25. <span v-for="(str, index) in '手机号码:'" :key="index">{{ str }}</span>
  26. </label>
  27. <div class="value-wrap">
  28. <input type="text" placeholder="请输入手机号码" v-model.trim="postData.phone" @input="funLimitLength">
  29. </div>
  30. </li>
  31. <li>
  32. <label>
  33. <span class="label-code" v-for="(str, index) in '验证码:码'" :key="index">{{ str }}</span>
  34. </label>
  35. <div class="value-wrap">
  36. <input type="number" placeholder="请输入验证码" v-model.trim="postData.code" @input="funLimitLength">
  37. </div>
  38. <button class="get-code" @click="funGetCode">{{[0, 60].includes(numCount) ? '获取验证码': numCount + '秒'}}</button>
  39. </li>
  40. <li>
  41. <label>
  42. <span v-for="(str, index) in '所在城市:'" :key="index">{{ str }}</span>
  43. </label>
  44. <div class="value-wrap" @click="showPicker = true">
  45. <p class="value-address" v-show="postData.province">{{ postData.province + postData.city}}</p>
  46. <p class="value-address init" v-show="!postData.province">请选择所在城市</p>
  47. <img src="./image/btn_next@2x.png" alt="">
  48. </div>
  49. </li>
  50. <li>
  51. <label>
  52. <span v-for="(str, index) in '房产地址:'" :key="index">{{ str }}</span>
  53. </label>
  54. <div class="value-wrap">
  55. <textarea name="" rows="1" placeholder="请输入房产地址" v-model.trim="postData.address" ref="myTextarea"></textarea>
  56. </div>
  57. </li>
  58. <li>
  59. <label>
  60. <span v-for="(str, index) in '需求金额:'" :key="index">{{ str }}</span>
  61. </label>
  62. <div class="value-wrap amount-wrap">
  63. <input :class="{'opacity-0': postData.amount * 1 > 0}" type="number" placeholder="请输入需求金额"
  64. v-model.trim="amount">
  65. <p v-show="postData.amount * 1 > 0">{{ postData.amount * 1 | toThousands }}.00</p>
  66. </div>
  67. </li>
  68. </ul>
  69. <button class="submit" @click="funSubmit">提交</button>
  70. <p class="explain">
  71. <span>申请代表您同意</span>
  72. <router-link :to="{path: '/privacy'}">《用户隐私协议》</router-link>
  73. <span>和</span>
  74. <router-link :to="{path: '/agreement'}">《服务协议》</router-link>
  75. </p>
  76. <van-popup v-model="showPicker" round position="bottom">
  77. <van-picker
  78. show-toolbar
  79. title="所在城市"
  80. :columns="columns"
  81. @cancel="showPicker = false"
  82. @confirm="onConfirm"/>
  83. </van-popup>
  84. </div>
  85. </template>
  86. <script>
  87. import Flow from './components/flow'
  88. import { Popup, Picker, Toast } from 'vant'
  89. export default {
  90. name: 'apply',
  91. components: {
  92. Flow,
  93. 'van-popup': Popup,
  94. 'van-picker': Picker
  95. },
  96. data () {
  97. return {
  98. postData: {
  99. name: '',
  100. gender: -1,
  101. phone: '',
  102. code: '',
  103. province: '',
  104. city: '',
  105. address: '',
  106. amount: ''
  107. },
  108. numCount: 60,
  109. arrErrorList: [],
  110. showPicker: false,
  111. columns: [
  112. {
  113. text: '浙江',
  114. children: [
  115. {
  116. text: '杭州'
  117. // children: [{ text: '西湖区' }, { text: '余杭区' }]
  118. },
  119. {
  120. text: '温州'
  121. // children: [{ text: '鹿城区' }, { text: '瓯海区' }]
  122. }
  123. ]
  124. },
  125. {
  126. text: '福建',
  127. children: [
  128. {
  129. text: '福州'
  130. // children: [{ text: '鼓楼区' }, { text: '台江区' }]
  131. },
  132. {
  133. text: '厦门'
  134. // children: [{ text: '思明区' }, { text: '海沧区' }]
  135. }
  136. ]
  137. }
  138. ]
  139. }
  140. },
  141. computed: {
  142. amount: {
  143. get () {
  144. return this.postData.amount ? this.postData.amount * 1 : ''
  145. },
  146. set (value) {
  147. this.postData.amount = value
  148. }
  149. }
  150. },
  151. async mounted () {
  152. await this.$nextTick()
  153. const textarea = this.$refs.myTextarea
  154. if (textarea) {
  155. this.handleTextarea(textarea)
  156. textarea.addEventListener('input', this.handleTextarea(textarea, 1), false)
  157. this.$once('hook:beforeDestroy', () => {
  158. textarea.addEventListener('input', this.handleTextarea(textarea, 1), false)
  159. })
  160. }
  161. this.$refreshTitle('中行贷')
  162. },
  163. methods: {
  164. handleTextarea (el, auto) {
  165. return () => {
  166. if (auto) {
  167. el.style.height = 'auto'
  168. }
  169. el.style.height = el.scrollHeight + 'px'
  170. }
  171. },
  172. onConfirm (value) {
  173. this.showPicker = false
  174. this.$set(this.postData, 'province', value[0])
  175. this.$set(this.postData, 'city', value[1])
  176. },
  177. funLimitLength () {
  178. const { phone, code } = this.postData
  179. this.postData.phone = phone.length > 11 ? phone.slice(0, 11) : phone
  180. this.postData.code = code.length > 4 ? code.slice(0, 4) : code
  181. },
  182. funCutDown () {
  183. let numCount = this.numCount
  184. const timer = setInterval(() => {
  185. if (numCount === 0) {
  186. clearInterval(timer)
  187. this.numCount = 0
  188. return
  189. }
  190. numCount--
  191. this.numCount = numCount
  192. }, 1000)
  193. },
  194. // 获取验证码
  195. funGetCode () {
  196. const numCount = this.numCount
  197. const { phone } = this.postData
  198. if (numCount < 60 && numCount > 0) {
  199. return
  200. }
  201. this.numCount = 60
  202. if (!(/^1[2|3|4|5|6|7|8|9]\d{9}$/.test(phone))) {
  203. Toast('请输入手机号码')
  204. return
  205. }
  206. this.funCutDown()
  207. // todo ajax
  208. },
  209. verifyData () {
  210. const { name, gender, phone, code, province, city, address, amount } = this.postData
  211. this.arrErrorList = []
  212. if (!name) {
  213. this.arrErrorList.push('请输入姓名')
  214. }
  215. if (gender < 0) {
  216. this.arrErrorList.push('请选择性别')
  217. }
  218. if (!/^1[2|3|4|5|6|7|8|9]\d{9}$/.test(phone)) {
  219. this.arrErrorList.push('请输入手机号码')
  220. }
  221. if (!(/^\d{4}$/.test(code))) {
  222. this.arrErrorList.push('请输入验证码')
  223. }
  224. if (!province) {
  225. this.arrErrorList.push('请选择所在城市')
  226. }
  227. if (!city) {
  228. this.arrErrorList.push('请选择所在城市')
  229. }
  230. if (!address) {
  231. this.arrErrorList.push('请输入房产地址')
  232. }
  233. if (amount * 1 <= 0) {
  234. this.arrErrorList.push('请输入需求金额')
  235. }
  236. return this.arrErrorList.length <= 0
  237. },
  238. funSubmit () {
  239. if (!this.verifyData()) {
  240. Toast({
  241. message: this.arrErrorList[0],
  242. forbidClick: true
  243. })
  244. }
  245. this.$router.replace({ path: '/detail' })
  246. }
  247. }
  248. }
  249. </script>
  250. <style lang="scss" scoped>
  251. .wrapper {
  252. position: relative;
  253. left: 0;
  254. top: 0;
  255. display: flex;
  256. flex-direction: column;
  257. align-items: center;
  258. width: 100%;
  259. min-height: 100vh;
  260. padding: 110px 0 200px;
  261. background: #fff;
  262. }
  263. .goods-cover {
  264. position: absolute;
  265. left: 0;
  266. top: 0;
  267. right: 0;
  268. display: block;
  269. width: 100%;
  270. min-height: 147px;
  271. }
  272. .form-wrap {
  273. li {
  274. position: relative;
  275. left: 0;
  276. top: 0;
  277. display: flex;
  278. align-items: flex-start;
  279. width: 327px;
  280. padding: 13px 14px;
  281. margin-top: 8px;
  282. border: 1px solid #E8E8E8;
  283. border-radius: 4px;
  284. &:nth-of-type(1) {
  285. margin-top: 37px;
  286. }
  287. }
  288. label {
  289. display: flex;
  290. span {
  291. line-height: 22px;
  292. font-size: 16px;
  293. font-weight: 500;
  294. color: #333;
  295. &.label-name:nth-of-type(4),
  296. &.label-name:nth-of-type(5),
  297. &.label-code:nth-of-type(5), {
  298. visibility: hidden;
  299. }
  300. }
  301. }
  302. .value-wrap {
  303. flex: 1;
  304. display: flex;
  305. margin-left: 9px;
  306. }
  307. .amount-wrap {
  308. position: relative;
  309. left: 0;
  310. top: 0;
  311. input {
  312. position: absolute;
  313. left: 0;
  314. top: 0;
  315. z-index: 1;
  316. &.opacity-0 {
  317. opacity: 0;
  318. }
  319. }
  320. p {
  321. width: 100%;
  322. padding-top: 2px;
  323. line-height: 20px;
  324. font-size: 15px;
  325. color: #333;
  326. }
  327. }
  328. input,
  329. textarea {
  330. width: 100%;
  331. min-height: 20px;
  332. padding-top: 2px;
  333. line-height: 20px;
  334. font-size: 15px;
  335. color: #333;
  336. word-break: break-all;
  337. resize: none;
  338. outline: 0 none;
  339. overflow: hidden;
  340. background: transparent;
  341. -webkit-text-fill-color: #333;
  342. opacity: 1;
  343. &::-webkit-input-placeholder {
  344. color: #999;
  345. -webkit-text-fill-color: #999;
  346. opacity: 1;
  347. }
  348. }
  349. .value-name {
  350. display: flex;
  351. width: 100%;
  352. }
  353. .value-gender {
  354. display: flex;
  355. p {
  356. display: flex;
  357. &:nth-of-type(2) {
  358. margin-left: 15px;
  359. }
  360. }
  361. span {
  362. margin-left: 4px;
  363. line-height: 22px;
  364. font-size: 16px;
  365. color: #333;
  366. }
  367. }
  368. .value-address {
  369. flex: 1;
  370. line-height: 22px;
  371. font-size: 15px;
  372. color: #333;
  373. &.init {
  374. color: #999;
  375. }
  376. }
  377. img {
  378. width: 22px;
  379. height: 22px;
  380. }
  381. .get-code {
  382. @include vertical-center;
  383. right: 14px;
  384. z-index: 1;
  385. display: block;
  386. min-width: 87px;
  387. padding: 6px;
  388. border-radius: 4px;
  389. line-height: 20px;
  390. font-size: 15px;
  391. color: #333;
  392. background: linear-gradient(90deg, #E5C7A5 0%, #CFAA7F 100%);
  393. }
  394. }
  395. .submit {
  396. width: 327px;
  397. height: 45px;
  398. margin-top: 36px;
  399. border-radius: 4px;
  400. line-height: 20px;
  401. font-size: 14px;
  402. font-weight: 500;
  403. color: #fff;
  404. background: linear-gradient(90deg, #E5C7A5 0%, #CFAA7F 100%);
  405. box-shadow: 0 14px 9px -10px rgba(219, 208, 194, 1);
  406. }
  407. .explain {
  408. display: flex;
  409. margin-top: 12px;
  410. span,
  411. a {
  412. line-height: 17px;
  413. font-size: 12px;
  414. color: #666;
  415. }
  416. }
  417. </style>