123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- <!--test.vue-->
- <template>
- <div>
- <van-form
- class="source-form"
- @submit="onSubmit"
- :style="{
- 'background-color': sourceFormConfig.background
- }"
- >
- <van-field
- v-if="sourceFormConfig.company"
- v-model.trim="form.company"
- required
- name="公司名称"
- label="公司名称"
- placeholder="请输入准确的公司名称"
- />
- <van-field
- v-if="sourceFormConfig.name"
- v-model.trim="form.name"
- required
- name="姓名"
- label="姓名"
- placeholder="请输入姓名"
- />
- <van-field
- v-if="sourceFormConfig.phone"
- v-model.trim="form.phone"
- required
- name="手机号"
- label="手机号"
- placeholder="请输入准确的手机号"
- />
- <van-field name="radio" required label="你希望获得哪个行业的报告" v-if="sourceFormConfig.source_desc">
- <template #input>
- <div class="custom-radio-type">
- <van-radio-group
- v-model="form.source_desc"
- >
- <van-radio
- v-for="item in sourceFormConfig.sourceOptions"
- :name="item"
- :key="item"
- >
- <div class="other-input-box" v-if="form.source_desc === '其他' && item === '其他'">
- <span>{{item}}</span>
- <van-field
- v-model.trim="form.source_desc_temp"
- placeholder="请输入行业"
- />
- </div>
- <span v-else>{{item}}</span>
- </van-radio>
- </van-radio-group>
- </div>
- </template>
- </van-field>
- <div style="margin: 16px;">
- <van-button round block :type="btnType" :size="size" native-type="submit">{{text}}</van-button>
- </div>
- </van-form>
- </div>
- </template>
- <script>
- import { Form, Field, Button, Radio, RadioGroup } from 'vant';
- import $axios from "@/service/httpServer";
- export default {
- name: 'DsSourceForm',
- components: {
- [Form.name]: Form,
- [Field.name]: Field,
- [Radio.name]: Radio,
- [RadioGroup.name]: RadioGroup,
- [Button.name]: Button
- },
- data() {
- return {
- form: {
- name: '',
- phone: '',
- company: '',
- source_desc: '',
- source_desc_temp: ''
- }
- }
- },
- props: {
- api: {
- type: String,
- default: '/salesLeads/collectInfo'
- },
- btnType:{
- type:String,
- default:'info'
- },
- text: {
- type: String,
- default: '提 交'
- },
- size:{
- type:String,
- default:'large'
- },
- sourceFormConfig: {
- type:Object,
- default: ()=>({
- background: 'transparent',
- source: 'default-source-h5',
- name: true,
- phone: true,
- company: true,
- source_desc: true,
- sourceOptions: [
- '建筑工程',
- '信息技术',
- '弱电安防',
- '医疗卫生',
- '服务采购',
- '其他'
- ]
- })
- }
- },
- methods: {
- onSubmit (values) {
- console.log(values)
- this.$toast.loading({
- duration: 0,
- forbidClick: true
- });
- const params = Object.assign({
- source: this.form.source_desc === '其他' ? this.form.source_desc_temp : this.form.source_desc,
- origin: location.href
- }, this.form)
- console.log('source-params', params)
- $axios.post(this.api, JSON.stringify(params), {
- headers: {
- 'Content-Type': 'application/json;charset=utf-8'
- }
- }).then(res => {
- console.log('res', res)
- this.$toast.clear()
- this.$toast('提交成功,我们会尽快联系您~')
- }).catch(() => {
- this.$toast.clear()
- this.$toast('太火爆了,请稍后重试')
- })
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .other-input-box {
- display: flex;
- flex-direction: row;
- align-items: center;
- span {
- flex-shrink: 0;
- }
- }
- .custom-radio-type {
- display: flex;
- flex-direction: column;
- }
- .source-form {
- width: 100%;
- height: 100%;
- ::v-deep {
- .van-cell {
- flex-direction: column;
- background-color: inherit;
- }
- .van-field__label {
- width: 100%;
- }
- .van-radio {
- height: 44px;
- }
- }
- }
- </style>
|