kehuInfo.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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" placeholder="请输入姓名" />
  11. </view>
  12. <view class="form-label-input">
  13. <view class="phone-form-label"><text class="form-label-require">*</text>手机号</view>
  14. <uni-easyinput type="number" :disabled="formData.userId" v-model="formData.userName" placeholder="请输入手机号" maxlength="11" />
  15. </view>
  16. <view class="form-label-input">
  17. <view class="phone-form-label">
  18. <text class="form-label-require"></text>
  19. <text v-if="formData.idtype ==1">身份证号</text>
  20. <text v-if="formData.idtype ==2">护照号</text>
  21. <icon @click="idCardChange" class="change-icon">切换</icon>
  22. </view>
  23. <uni-easyinput :disabled="!statusFlag && status=='edit'" @blur="idCardBlur" v-model="formData.idcard"
  24. placeholder="请输入身份证号或护照号" maxlength="18" />
  25. </view>
  26. <view class="form-label-input flex-start-row">
  27. <view class="phone-form-label"><text class="form-label-require"></text>具体地址</view>
  28. <textarea v-model="formData.jutidizhi" maxlength="-1" placeholder="请填写具体地址" class="form-textarea-box" />
  29. </view>
  30. </view>
  31. <button type="default" class="phone-green-btn info-btn" @click="saveBtn">保存</button>
  32. <commonDialogVue ref="comRefAdd" :content="contentAdd" @confirm-btn="htAdd2"></commonDialogVue>
  33. </view>
  34. </template>
  35. <script setup>
  36. import {
  37. ref,
  38. reactive
  39. } from "vue";
  40. import {
  41. onLoad
  42. } from "@dcloudio/uni-app";
  43. import * as khApi from "@/api/kehu.js"
  44. import commonDialogVue from "@/components/dialog/commonDialog.vue"
  45. const formData = reactive({
  46. realName: '',
  47. userName: '',
  48. idcard: '',
  49. idtype: '1',
  50. jutidizhi: '',
  51. pageFlag: 'add',
  52. id: null,
  53. userId: null,
  54. })
  55. const contentAdd = ref('');
  56. const comRefAdd = ref(null);
  57. // 返回
  58. function goUpPage() {
  59. uni.redirectTo({
  60. url: '/pages/admin/kehu/kehuList'
  61. })
  62. }
  63. function idCardChange(data) {
  64. formData.idtype = formData.idtype == 1 ? 2 : 1;
  65. }
  66. // 保存
  67. function saveBtn() {
  68. if (formData.pageFlag === 'editor') {
  69. htEditor();
  70. } else {
  71. htAdd();
  72. }
  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. jutidizhi: formData.jutidizhi,
  100. checked: 0
  101. }
  102. khApi.getKehuAdd(opt).then(res => {
  103. if (res.data.result) {
  104. uni.showToast({
  105. title: '新增成功'
  106. })
  107. goUpPage();
  108. } else {
  109. contentAdd.value = res.data.message;
  110. comRefAdd.value.handleShow();
  111. }
  112. }).finally(() => {
  113. uni.hideLoading()
  114. })
  115. }
  116. function htAdd2() {
  117. let arr = [];
  118. if (!formData.realName) {
  119. arr.push('姓名');
  120. }
  121. if (!formData.userName) {
  122. arr.push('电话');
  123. }
  124. if (!formData.realName || !formData.userName) {
  125. uni.showToast({
  126. icon: 'none',
  127. title: `请完善${arr.join('、')}信息!`
  128. })
  129. return;
  130. }
  131. uni.showLoading({
  132. title: '新增中...',
  133. mask: true
  134. });
  135. const opt = {
  136. realName: formData.realName,
  137. userName: formData.userName,
  138. idtype: formData.idtype,
  139. idcard: formData.idcard,
  140. jutidizhi: formData.jutidizhi,
  141. checked:1
  142. }
  143. khApi.getKehuAdd(opt).then(res => {
  144. if (res.data) {
  145. uni.showToast({
  146. title: '新增成功'
  147. })
  148. goUpPage();
  149. }
  150. }).finally(() => {
  151. uni.hideLoading()
  152. })
  153. }
  154. // 编辑
  155. function handleEditor() {
  156. khApi.getKehuInfo({
  157. userId: formData.userId,
  158. id: formData.id,
  159. }).then(res => {
  160. formData.realName = res.data.realName,
  161. formData.userName = res.data.userName,
  162. formData.idcard = res.data.idcard;
  163. formData.idtype = res.data.idtype;
  164. formData.addres = res.data.addres;
  165. formData.jutidizhi = res.data.jutidizhi;
  166. formData.idtype = res.data.idtype;
  167. })
  168. }
  169. function htEditor() {
  170. let arr = [];
  171. if (!formData.realName) {
  172. arr.push('姓名');
  173. }
  174. if (!formData.userName) {
  175. arr.push('电话');
  176. }
  177. if (!formData.realName || !formData.userName) {
  178. uni.showToast({
  179. icon: 'none',
  180. title: `请完善${arr.join('、')}信息!`
  181. })
  182. return;
  183. }
  184. uni.showLoading({
  185. title: '更新中...',
  186. mask: true
  187. });
  188. const opt = {
  189. userId: formData.userId,
  190. realName: formData.realName,
  191. userName: formData.userName,
  192. idtype: formData.idtype,
  193. idcard: formData.idcard,
  194. jutidizhi: formData.jutidizhi,
  195. }
  196. khApi.getKehuUpdate(opt).then(res => {
  197. if (res.data) {
  198. uni.showToast({
  199. title: '编辑成功'
  200. })
  201. goUpPage();
  202. }
  203. }).finally(() => {
  204. uni.hideLoading()
  205. })
  206. }
  207. onLoad((options) => {
  208. if (options.id && options.userId) {
  209. formData.pageFlag = 'editor';
  210. formData.id = options.id;
  211. formData.userId = options.userId;
  212. handleEditor();
  213. }
  214. })
  215. </script>
  216. <style>
  217. </style>