addKh.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. <commonDialogVue ref="comRef" :content="content" @confirm-btn="htAdd2"></commonDialogVue>
  38. </template>
  39. <script setup>
  40. import {ref,reactive,nextTick} from "vue";
  41. import {onLoad} from "@dcloudio/uni-app";
  42. import * as khApi from "@/api/kehu.js";
  43. import commonDialogVue from "@/components/dialog/commonDialog.vue";
  44. const emits = defineEmits('success')
  45. const comRef = ref(null);
  46. const content = ref('');
  47. const formData = reactive({
  48. realName: '',
  49. userName: '',
  50. idcard: '',
  51. idtype: '1',
  52. })
  53. function goback2() {
  54. popupRef.value.close();
  55. formData.realName = '';
  56. formData.userName = '';
  57. formData.idcard = '';
  58. formData.idtype = '1';
  59. content.value = null;
  60. }
  61. const popupRef = ref(null)
  62. const data = reactive({
  63. })
  64. function handleShow() {
  65. popupRef.value.open();
  66. }
  67. function idCardChange(data) {
  68. formData.idtype = formData.idtype == 1 ? 2 : 1;
  69. }
  70. // 保存
  71. function saveBtn(){
  72. htAdd();
  73. }
  74. // 新增
  75. function htAdd(){
  76. let arr = [];
  77. if (!formData.realName) {
  78. arr.push('姓名');
  79. }
  80. if (!formData.userName) {
  81. arr.push('电话');
  82. }
  83. if (!formData.realName || !formData.userName) {
  84. uni.showToast({
  85. icon: 'none',
  86. title: `请完善${arr.join('、')}信息!`
  87. })
  88. return;
  89. }
  90. uni.showLoading({
  91. title: '新增中...',
  92. mask: true
  93. });
  94. const opt = {
  95. realName: formData.realName,
  96. userName: formData.userName,
  97. idtype: formData.idtype,
  98. idcard: formData.idcard,
  99. checked: 0
  100. }
  101. khApi.getKehuAdd(opt).then(res => {
  102. if (res.data.result) {
  103. uni.showToast({
  104. title: '新增成功'
  105. })
  106. goback2();
  107. emits('success')
  108. nextTick(() => {
  109. formData.realName = '';
  110. formData.userName = '';
  111. formData.idcard = '';
  112. formData.idtype = '1';
  113. content.value = null;
  114. })
  115. } else {
  116. // 有重复数据
  117. content.value = res.data.message;
  118. comRef.value.handleShow();
  119. }
  120. }).finally(()=>{
  121. uni.hideLoading()
  122. })
  123. }
  124. function htAdd2(){
  125. let arr = [];
  126. if (!formData.realName) {
  127. arr.push('姓名');
  128. }
  129. if (!formData.userName) {
  130. arr.push('电话');
  131. }
  132. if (!formData.realName || !formData.userName) {
  133. uni.showToast({
  134. icon: 'none',
  135. title: `请完善${arr.join('、')}信息!`
  136. })
  137. return;
  138. }
  139. uni.showLoading({
  140. title: '新增中...',
  141. mask: true
  142. });
  143. const opt = {
  144. realName: formData.realName,
  145. userName: formData.userName,
  146. idtype: formData.idtype,
  147. idcard: formData.idcard,
  148. checked: 1
  149. }
  150. khApi.getKehuAdd(opt).then(res => {
  151. if (res.data.result) {
  152. uni.showToast({
  153. title: '新增成功'
  154. })
  155. goback2();
  156. emits('success')
  157. nextTick(() => {
  158. formData.realName = '';
  159. formData.userName = '';
  160. formData.idcard = '';
  161. formData.idtype = '1';
  162. content.value = null;
  163. })
  164. }
  165. }).finally(()=>{
  166. uni.hideLoading()
  167. })
  168. }
  169. defineExpose({
  170. handleShow
  171. })
  172. </script>
  173. <style>
  174. </style>