kehuInfo.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <template>
  2. <view class="admin-kehu-info">
  3. <view class="icon-title-navBar-box">
  4. <view @click="goUpPage" class="nav-bar-icon"></view>
  5. <text class="nav-bar-title">家政客户</text>
  6. </view>
  7. <view>
  8. <view class="form-label-input">
  9. <view class="phone-form-label"><text class="form-label-require">*</text>姓名</view>
  10. <uni-easyinput v-model="formData.realName"
  11. placeholder="请输入姓名" />
  12. </view>
  13. <view class="form-label-input">
  14. <view class="phone-form-label"><text class="form-label-require">*</text>手机号</view>
  15. <uni-easyinput type="number" v-model="formData.userName"
  16. placeholder="请输入手机号" maxlength="11" />
  17. </view>
  18. <view class="form-label-input">
  19. <view class="phone-form-label">
  20. <text class="form-label-require"></text>
  21. <text v-if="formData.idtype ==1">身份证号</text>
  22. <text v-if="formData.idtype ==2">护照号</text>
  23. <icon @click="idCardChange" class="change-icon">切换</icon>
  24. </view>
  25. <uni-easyinput :disabled="!statusFlag && status=='edit'" @blur="idCardBlur" v-model="formData.idcard"
  26. placeholder="请输入身份证号或护照号" maxlength="18" />
  27. </view>
  28. <view class="form-label-input flex-start-row">
  29. <view class="phone-form-label"><text class="form-label-require"></text>具体地址</view>
  30. <textarea v-model="formData.jutidizhi" maxlength="-1" placeholder="请填写具体地址" class="form-textarea-box" />
  31. </view>
  32. </view>
  33. <button type="default" class="phone-green-btn info-btn" @click="saveBtn">保存</button>
  34. </view>
  35. </template>
  36. <script setup>
  37. import {ref,reactive} from "vue";
  38. import {onLoad} from "@dcloudio/uni-app";
  39. import * as khApi from "@/api/kehu.js"
  40. const formData = reactive({
  41. realName: '',
  42. userName: '',
  43. idcard: '',
  44. idtype: '1',
  45. jutidizhi: '',
  46. pageFlag:'add',
  47. id:null,
  48. userId:null,
  49. })
  50. // 返回
  51. function goUpPage() {
  52. uni.redirectTo({
  53. url: '/pages/admin/kehu/kehuList'
  54. })
  55. }
  56. function idCardChange(data) {
  57. formData.idtype = formData.idtype == 1 ? 2 : 1;
  58. }
  59. // 保存
  60. function saveBtn(){
  61. if(formData.pageFlag==='editor'){
  62. htEditor();
  63. }else{
  64. htAdd();
  65. }
  66. }
  67. // 新增
  68. function htAdd(){
  69. let arr = [];
  70. if (!formData.realName) {
  71. arr.push('姓名');
  72. }
  73. if (!formData.userName) {
  74. arr.push('电话');
  75. }
  76. if (!formData.realName || !formData.userName) {
  77. uni.showToast({
  78. icon: 'none',
  79. title: `请完善${arr.join('、')}信息!`
  80. })
  81. return;
  82. }
  83. uni.showLoading({
  84. title: '新增中...',
  85. mask: true
  86. });
  87. const opt = {
  88. realName: formData.realName,
  89. userName: formData.userName,
  90. idtype: formData.idtype,
  91. idcard: formData.idcard,
  92. jutidizhi: formData.jutidizhi,
  93. }
  94. khApi.getKehuAdd(opt).then(res => {
  95. if (res.data) {
  96. uni.showToast({
  97. title: '新增成功'
  98. })
  99. goUpPage();
  100. }
  101. }).finally(()=>{
  102. uni.hideLoading()
  103. })
  104. }
  105. // 编辑
  106. function handleEditor() {
  107. khApi.getKehuInfo({
  108. userId: formData.userId,
  109. id:formData.id,
  110. }).then(res => {
  111. formData.realName = res.data.realName,
  112. formData.userName = res.data.userName,
  113. formData.idcard = res.data.idcard;
  114. formData.idtype = res.data.idtype;
  115. formData.addres = res.data.addres;
  116. formData.jutidizhi = res.data.jutidizhi;
  117. formData.idtype = res.data.idtype;
  118. })
  119. }
  120. function htEditor(){
  121. let arr = [];
  122. if (!formData.realName) {
  123. arr.push('姓名');
  124. }
  125. if (!formData.userName) {
  126. arr.push('电话');
  127. }
  128. if (!formData.realName || !formData.userName) {
  129. uni.showToast({
  130. icon: 'none',
  131. title: `请完善${arr.join('、')}信息!`
  132. })
  133. return;
  134. }
  135. uni.showLoading({
  136. title: '更新中...',
  137. mask: true
  138. });
  139. const opt = {
  140. userId: formData.userId,
  141. realName: formData.realName,
  142. userName: formData.userName,
  143. idtype: formData.idtype,
  144. idcard: formData.idcard,
  145. jutidizhi: formData.jutidizhi,
  146. }
  147. khApi.getKehuUpdate(opt).then(res => {
  148. if (res.data) {
  149. uni.showToast({
  150. title: '编辑成功'
  151. })
  152. goUpPage();
  153. }
  154. }).finally(()=>{
  155. uni.hideLoading()
  156. })
  157. }
  158. onLoad((options) => {
  159. if(options.id && options.userId){
  160. formData.pageFlag = 'editor';
  161. formData.id = options.id;
  162. formData.userId = options.userId;
  163. handleEditor();
  164. }
  165. })
  166. </script>
  167. <style>
  168. </style>