addKh.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <template>
  2. <uni-popup ref="popupRef" type="bottom" background-color="#fff" :is-mask-click="false" :mask-click="false">
  3. <view class="admin-kehu-info">
  4. <view class="icon-title-navBar-box">
  5. <view @click="goback2" class="nav-bar-icon"></view>
  6. <text class="nav-bar-title">新增家政客户</text>
  7. </view>
  8. <view>
  9. <view class="form-label-input">
  10. <view class="phone-form-label"><text class="form-label-require">*</text>姓名</view>
  11. <uni-easyinput v-model="formData.realName"
  12. placeholder="请输入姓名" />
  13. </view>
  14. <view class="form-label-input">
  15. <view class="phone-form-label"><text class="form-label-require">*</text>手机号</view>
  16. <uni-easyinput type="number" v-model="formData.userName"
  17. placeholder="请输入手机号" maxlength="11" />
  18. </view>
  19. <view class="form-label-input">
  20. <view class="phone-form-label">
  21. <text class="form-label-require"></text>
  22. <text v-if="formData.idtype ==1">身份证号</text>
  23. <text v-if="formData.idtype ==2">护照号</text>
  24. <icon @click="idCardChange" class="change-icon">切换</icon>
  25. </view>
  26. <uni-easyinput :disabled="!statusFlag && status=='edit'" @blur="idCardBlur" v-model="formData.idcard"
  27. placeholder="请输入身份证号或护照号" maxlength="18" />
  28. </view>
  29. <view class="form-label-input flex-start-row">
  30. <view class="phone-form-label"><text class="form-label-require"></text>具体地址</view>
  31. <textarea v-model="jingli" maxlength="-1" placeholder="请填写具体地址" class="form-textarea-box" />
  32. </view>
  33. </view>
  34. <button type="default" class="phone-green-btn info-btn" @click="saveBtn">保存</button>
  35. </view>
  36. </uni-popup>
  37. </template>
  38. <script setup>
  39. import {ref,reactive,nextTick} from "vue";
  40. import {onLoad} from "@dcloudio/uni-app";
  41. import * as khApi from "@/api/kehu.js"
  42. const emits = defineEmits('success')
  43. const formData = reactive({
  44. realName: '',
  45. userName: '',
  46. idcard: '',
  47. idtype: '1',
  48. })
  49. function goback2() {
  50. popupRef.value.close();
  51. formData.realName = '';
  52. formData.userName = '';
  53. formData.idcard = '';
  54. formData.idtype = '1';
  55. }
  56. const popupRef = ref(null)
  57. const data = reactive({
  58. })
  59. function handleShow() {
  60. popupRef.value.open();
  61. }
  62. function idCardChange(data) {
  63. formData.idtype = formData.idtype == 1 ? 2 : 1;
  64. }
  65. // 保存
  66. function saveBtn(){
  67. htAdd();
  68. }
  69. // 新增
  70. function htAdd(){
  71. let arr = [];
  72. if (!formData.realName) {
  73. arr.push('姓名');
  74. }
  75. if (!formData.userName) {
  76. arr.push('电话');
  77. }
  78. if (!formData.realName || !formData.userName) {
  79. uni.showToast({
  80. icon: 'none',
  81. title: `请完善${arr.join('、')}信息!`
  82. })
  83. return;
  84. }
  85. uni.showLoading({
  86. title: '新增中...',
  87. mask: true
  88. });
  89. const opt = {
  90. realName: formData.realName,
  91. userName: formData.userName,
  92. idtype: formData.idtype,
  93. idcard: formData.idcard,
  94. }
  95. khApi.getKehuAdd(opt).then(res => {
  96. if (res.data) {
  97. uni.showToast({
  98. title: '新增成功'
  99. })
  100. goback2();
  101. emits('success')
  102. nextTick(() => {
  103. formData.realName = '';
  104. formData.userName = '';
  105. formData.idcard = '';
  106. formData.idtype = '1';
  107. })
  108. }
  109. }).finally(()=>{
  110. uni.hideLoading()
  111. })
  112. }
  113. defineExpose({
  114. handleShow
  115. })
  116. </script>
  117. <style>
  118. </style>