【前端vue开发】vue开发输入姓名,电话,公司表单提交组件

复制代码
<template>
  <div id="parti-info">
    <div>
      <span>您的姓名:</span>
      <input v-model="username" type="text" placeholder="请输入您的姓名" >
    </div>
    <div>
      <span >手机号码:</span>
      <input v-model="phone" type="number" maxlength="11" placeholder="请输入您的手机号码">
    </div>
    <div>
      <span>所在保险公司:</span>
      <select v-model="selectedCompany" v-show="this.selectedCompany !== ''" >
        <option value="-1">请选择</option>
        <option value="">自定义输入</option>
        <option v-for="option in companyOptions" v-bind:value="option.id">
          {{ option.value }}
        </option>
      </select>
      <input v-model="selectedCustomCompany" v-show="this.selectedCompany === ''" type="text" maxlength="12" placeholder="请输入公司名称">
    </div>
  </div>
</template>
<script>
import Vue from 'vue'
import vcookie from 'vue-cookie'
import axios from 'axios'
import { companies } from '../data/companies'
Vue.use(vcookie)
export default {
  name: 'PartiInfo',
  data: function () {
    return {
      companyOptions: companies
    }
  },
  computed: {
    username: {
      get: function () {
        return this.$store.state.username
      },
      set: function (newValue) {
        this.$store.commit('updateUsername', newValue)
      }
    },
    phone: {
      get: function () {
        return this.$store.state.phone
      },
      set: function (newValue) {
        this.$store.commit('updatePhone', newValue)
      }
    },
    selectedCompany: {
      get: function () {
        return this.$store.state.company
      },
      set: function (newValue) {
        this.$store.commit('updateCompanyName', '')
        for (var i = 0; i < this.companyOptions.length; i++) {
          if (this.companyOptions[i].id === newValue) {
            this.$store.commit('updateCompanyName', this.companyOptions[i].value)
          }
        }
        this.$store.commit('updateCompany', newValue)
      }
    },
    selectedCustomCompany: {
      get: function () {
        return this.$store.state.companyName
      },
      set: function (newValue) {
        this.$store.commit('updateCompanyName', newValue)
      }
    }
  },
  mounted: function () {
    var vm = this
    var uuid = this.$cookie.get('api_uuid')
    var token = this.$cookie.get('api_token')
    axios.defaults.headers.common['api_token'] = token
    // 'eff7756789804c179e9efb0cbb48ecca'
    axios.get(vm.apiUrl + '/api/v1/activity/user/uuid/' + uuid)
    .then(function (response) {
      // 初始化自定义保险公司
      var notExist = true
      for (var i = 0; i < vm.companyOptions.length; i++) {
        if (vm.companyOptions[i].id === response.data.response.companyCode || vm.companyOptions[i].value === response.data.response.companyName) {
          notExist = false
        }
      }
      if (notExist) {
        vm.companyOptions.push({id: response.data.response.companyCode, value: response.data.response.companyName})
      }
      // 初始化数据
      vm.$store.commit('updateUsername', response.data.response.realName)
      vm.$store.commit('updatePhone', response.data.response.mobile)
      if (response.data.response.companyCode && response.data.response.companyCode !== '') {
        vm.$store.commit('updateCompany', response.data.response.companyCode)
      }
      if (response.data.response.companyName && response.data.response.companyName !== '') {
        vm.$store.commit('updateCompanyName', response.data.response.companyName)
      }
    }).catch(function (error) {
      console.log('Error! Could not reach the API. ' + error)
    })
  }
}
</script>
复制代码

 

posted @   JeckHui  阅读(1322)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
点击右上角即可分享
微信分享提示