kehuInfo.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. const opt = {
  84. realName: formData.realName,
  85. userName: formData.userName,
  86. idtype: formData.idtype,
  87. idcard: formData.idcard,
  88. jutidizhi: formData.jutidizhi,
  89. }
  90. khApi.getKehuAdd(opt).then(res => {
  91. if (res.data) {
  92. uni.showToast({
  93. title: '新增成功'
  94. })
  95. goUpPage();
  96. }
  97. })
  98. }
  99. // 编辑
  100. function handleEditor() {
  101. khApi.getKehuInfo({
  102. userId: formData.userId,
  103. id:formData.id,
  104. }).then(res => {
  105. formData.realName = res.data.realName,
  106. formData.userName = res.data.userName,
  107. formData.idcard = res.data.idcard;
  108. formData.idtype = res.data.idtype;
  109. formData.addres = res.data.addres;
  110. formData.jutidizhi = res.data.jutidizhi;
  111. formData.idtype = res.data.idtype;
  112. })
  113. }
  114. function htEditor(){
  115. let arr = [];
  116. if (!formData.realName) {
  117. arr.push('姓名');
  118. }
  119. if (!formData.userName) {
  120. arr.push('电话');
  121. }
  122. if (!formData.realName || !formData.userName) {
  123. uni.showToast({
  124. icon: 'none',
  125. title: `请完善${arr.join('、')}信息!`
  126. })
  127. return;
  128. }
  129. const opt = {
  130. userId: formData.userId,
  131. realName: formData.realName,
  132. userName: formData.userName,
  133. idtype: formData.idtype,
  134. idcard: formData.idcard,
  135. jutidizhi: formData.jutidizhi,
  136. }
  137. console.log('opt',opt);
  138. khApi.getKehuUpdate(opt).then(res => {
  139. if (res.data) {
  140. uni.showToast({
  141. title: '编辑成功'
  142. })
  143. goUpPage();
  144. }
  145. })
  146. }
  147. onLoad((options) => {
  148. if(options.id && options.userId){
  149. formData.pageFlag = 'editor';
  150. formData.id = options.id;
  151. formData.userId = options.userId;
  152. handleEditor();
  153. }
  154. })
  155. </script>
  156. <style>
  157. </style>