kehuInfo.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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" 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. <commonDialogVue ref="comRefEditor" :content="contentEditor" @confirm-btn="htAdd2"></commonDialogVue>
  34. </view>
  35. </template>
  36. <script setup>
  37. import {
  38. ref,
  39. reactive
  40. } from "vue";
  41. import {
  42. onLoad
  43. } from "@dcloudio/uni-app";
  44. import * as khApi from "@/api/kehu.js"
  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 contentEditor = ref('');
  57. const comRefAdd = ref(null);
  58. const comRefEditor = ref(null)
  59. // 返回
  60. function goUpPage() {
  61. uni.redirectTo({
  62. url: '/pages/admin/kehu/kehuList'
  63. })
  64. }
  65. function idCardChange(data) {
  66. formData.idtype = formData.idtype == 1 ? 2 : 1;
  67. }
  68. // 保存
  69. function saveBtn() {
  70. if (formData.pageFlag === 'editor') {
  71. htEditor();
  72. } else {
  73. htAdd();
  74. }
  75. }
  76. // 新增
  77. function htAdd() {
  78. let arr = [];
  79. if (!formData.realName) {
  80. arr.push('姓名');
  81. }
  82. if (!formData.userName) {
  83. arr.push('电话');
  84. }
  85. if (!formData.realName || !formData.userName) {
  86. uni.showToast({
  87. icon: 'none',
  88. title: `请完善${arr.join('、')}信息!`
  89. })
  90. return;
  91. }
  92. uni.showLoading({
  93. title: '新增中...',
  94. mask: true
  95. });
  96. const opt = {
  97. realName: formData.realName,
  98. userName: formData.userName,
  99. idtype: formData.idtype,
  100. idcard: formData.idcard,
  101. jutidizhi: formData.jutidizhi,
  102. checked: 0
  103. }
  104. khApi.getKehuAdd(opt).then(res => {
  105. if (res.data.result) {
  106. uni.showToast({
  107. title: '新增成功'
  108. })
  109. goUpPage();
  110. } else {
  111. contentAdd.value = res.data.message;
  112. comRefAdd.value.handleShow();
  113. }
  114. }).finally(() => {
  115. uni.hideLoading()
  116. })
  117. }
  118. function htAdd2() {
  119. let arr = [];
  120. if (!formData.realName) {
  121. arr.push('姓名');
  122. }
  123. if (!formData.userName) {
  124. arr.push('电话');
  125. }
  126. if (!formData.realName || !formData.userName) {
  127. uni.showToast({
  128. icon: 'none',
  129. title: `请完善${arr.join('、')}信息!`
  130. })
  131. return;
  132. }
  133. uni.showLoading({
  134. title: '新增中...',
  135. mask: true
  136. });
  137. const opt = {
  138. realName: formData.realName,
  139. userName: formData.userName,
  140. idtype: formData.idtype,
  141. idcard: formData.idcard,
  142. jutidizhi: formData.jutidizhi,
  143. checked:1
  144. }
  145. khApi.getKehuAdd(opt).then(res => {
  146. if (res.data) {
  147. uni.showToast({
  148. title: '新增成功'
  149. })
  150. goUpPage();
  151. }
  152. }).finally(() => {
  153. uni.hideLoading()
  154. })
  155. }
  156. // 编辑
  157. function handleEditor() {
  158. khApi.getKehuInfo({
  159. userId: formData.userId,
  160. id: formData.id,
  161. }).then(res => {
  162. formData.realName = res.data.realName,
  163. formData.userName = res.data.userName,
  164. formData.idcard = res.data.idcard;
  165. formData.idtype = res.data.idtype;
  166. formData.addres = res.data.addres;
  167. formData.jutidizhi = res.data.jutidizhi;
  168. formData.idtype = res.data.idtype;
  169. })
  170. }
  171. function htEditor() {
  172. let arr = [];
  173. if (!formData.realName) {
  174. arr.push('姓名');
  175. }
  176. if (!formData.userName) {
  177. arr.push('电话');
  178. }
  179. if (!formData.realName || !formData.userName) {
  180. uni.showToast({
  181. icon: 'none',
  182. title: `请完善${arr.join('、')}信息!`
  183. })
  184. return;
  185. }
  186. uni.showLoading({
  187. title: '更新中...',
  188. mask: true
  189. });
  190. const opt = {
  191. userId: formData.userId,
  192. realName: formData.realName,
  193. userName: formData.userName,
  194. idtype: formData.idtype,
  195. idcard: formData.idcard,
  196. jutidizhi: formData.jutidizhi,
  197. checked: 0
  198. }
  199. khApi.getKehuUpdate(opt).then(res => {
  200. if (res.data.result) {
  201. uni.showToast({
  202. title: '编辑成功'
  203. })
  204. goUpPage();
  205. } else {
  206. contentEditor.value = res.data.message;
  207. comRefEditor.value.handleShow();
  208. }
  209. }).finally(() => {
  210. uni.hideLoading()
  211. })
  212. }
  213. function htEditor2() {
  214. let arr = [];
  215. if (!formData.realName) {
  216. arr.push('姓名');
  217. }
  218. if (!formData.userName) {
  219. arr.push('电话');
  220. }
  221. if (!formData.realName || !formData.userName) {
  222. uni.showToast({
  223. icon: 'none',
  224. title: `请完善${arr.join('、')}信息!`
  225. })
  226. return;
  227. }
  228. uni.showLoading({
  229. title: '更新中...',
  230. mask: true
  231. });
  232. const opt = {
  233. userId: formData.userId,
  234. realName: formData.realName,
  235. userName: formData.userName,
  236. idtype: formData.idtype,
  237. idcard: formData.idcard,
  238. jutidizhi: formData.jutidizhi,
  239. checked: 1
  240. }
  241. khApi.getKehuUpdate(opt).then(res => {
  242. if (res.data) {
  243. uni.showToast({
  244. title: '编辑成功'
  245. })
  246. goUpPage();
  247. }
  248. }).finally(() => {
  249. uni.hideLoading()
  250. })
  251. }
  252. onLoad((options) => {
  253. if (options.id && options.userId) {
  254. formData.pageFlag = 'editor';
  255. formData.id = options.id;
  256. formData.userId = options.userId;
  257. handleEditor();
  258. }
  259. })
  260. </script>
  261. <style>
  262. </style>