people.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <template>
  2. <view class="pages">
  3. <view class="" :style="{height: navHeight+'px' }"></view>
  4. <!-- 自定义导航 -->
  5. <view class="navbar-box">
  6. <u-navbar title="信息填写" :safeAreaInsetTop="true" @leftClick="leftClick"></u-navbar>
  7. </view>
  8. <view class="page-wrap">
  9. <view class="form-wrap">
  10. <u--form labelPosition="left" :model="form" :rules="rules" ref="uForm" labelWidth="120rpx" >
  11. <u-form-item label="姓名" prop="name" borderBottom>
  12. <u--input v-model="form.name" placeholder="与证件名字一致" border="none"></u--input>
  13. </u-form-item>
  14. <u-form-item label="身份证" prop="idcard" borderBottom>
  15. <u--input v-model="form.idcard" placeholder="身份证号码" border="none"></u--input>
  16. </u-form-item>
  17. <u-form-item label="手机号" prop="mobile" borderBottom>
  18. <u--input v-model="form.mobile" placeholder="常用手机号" border="none"></u--input>
  19. </u-form-item>
  20. </u--form>
  21. <!-- <view class="set-default u-flex u-row-between">
  22. <view class="left">
  23. <view class="up">设置为默认信息</view>
  24. <view class="down">提醒:每次下单会默认使用该信息</view>
  25. </view>
  26. <view class="right">
  27. <u-switch v-model="form.default" activeValue='1' inactiveValue='0'></u-switch>
  28. </view>
  29. </view> -->
  30. </view>
  31. <view class="btn-wrap">
  32. <view class="full-btn" @click="submit">保存</view>
  33. <view class="full-btn red" v-if="type=='editVisitor'" @click="delVisitor">删除</view>
  34. <view class="full-btn white" @click="cancel">取消</view>
  35. </view>
  36. </view>
  37. </view>
  38. </template>
  39. <script>
  40. import { systemInfo } from "@/mixin.js";
  41. export default {
  42. mixins:[systemInfo],
  43. data() {
  44. return {
  45. type:'',
  46. fromPage:'',
  47. form: {
  48. id:null,
  49. name: '',
  50. idcard:'',
  51. mobile:'',
  52. // default:'0',
  53. },
  54. rules: {
  55. 'name': [
  56. {
  57. type: 'string',
  58. required: true,
  59. message: '请填写姓名',
  60. trigger: ['blur', 'change']
  61. }
  62. ],
  63. 'idcard': [
  64. {
  65. type: 'string',
  66. required: true,
  67. message: '请输入身份证',
  68. trigger: ['blur', 'change']
  69. },
  70. // {
  71. // validator: (rule, value, callback) => {
  72. // // 上面有说,返回true表示校验通过,返回false表示不通过
  73. // // this.$u.test.mobile()就是返回true或者false的
  74. // return this.$u.test.idCard(value);
  75. // },
  76. // message: '请输入正确身份证',
  77. // // 触发器可以同时用blur和change
  78. // trigger: ['change', 'blur'],
  79. // }
  80. ],
  81. mobile: [
  82. {
  83. type: 'string',
  84. required: true,
  85. message: '请输入手机号',
  86. trigger: ['blur', 'change']
  87. },
  88. {
  89. validator: (rule, value, callback) => {
  90. // 上面有说,返回true表示校验通过,返回false表示不通过
  91. // this.$u.test.mobile()就是返回true或者false的
  92. return this.$u.test.mobile(value);
  93. },
  94. message: '请输入正确手机号',
  95. // 触发器可以同时用blur和change
  96. trigger: ['change', 'blur'],
  97. }
  98. ],
  99. },
  100. }
  101. },
  102. onLoad(page) {
  103. this.getSystemInfo();
  104. this.type = page.type;
  105. this.fromPage = page.fromPage;
  106. this.form.id = page.id;
  107. this.form.name = page.name;
  108. this.form.idcard = page.idcard;
  109. this.form.mobile = page.mobile;
  110. },
  111. onReady() {
  112. this.$refs.uForm.setRules(this.rules)
  113. },
  114. methods: {
  115. leftClick() {
  116. let pages = getCurrentPages();
  117. if(pages.length==1){
  118. uni.$u.route('/pages/index/index')
  119. }else{
  120. uni.navigateBack()
  121. };
  122. },
  123. submit() {
  124. // if(!this.form.idcard.startsWith("52")){
  125. // uni.$u.toast('仅允许以52开头的身份证')
  126. // return
  127. // }
  128. this.$refs.uForm.validate().then(res => {
  129. // uni.$u.toast('表单校验成功')
  130. console.log('this.type',this.type);
  131. console.log('form',this.form);
  132. this.$u.api.insertOrUpdateMember(this.form).then(res=>{
  133. uni.navigateBack()
  134. // if(this.type=='addVisitor'){
  135. // // this.addVisitor()
  136. // }else if(this.type=='editVisitor'){
  137. // // this.editVisitor()
  138. // }
  139. }).catch(err=>{
  140. console.log('insertOrUpdateMember',err);
  141. })
  142. }).catch(errors => {
  143. console.log('errors',errors);
  144. uni.$u.toast('表单校验失败')
  145. })
  146. },
  147. addVisitor(){
  148. console.log('form',this.form);
  149. this.$u.api.insertOrUpdateMember(this.form).then(res=>{
  150. // console.log('getSettlement',res.data);
  151. this.pageContent = res.data;
  152. }).catch(err=>{
  153. console.log('insertOrUpdateMember',err);
  154. })
  155. },
  156. editVisitor(){
  157. console.log('form',this.form);
  158. },
  159. delVisitor(){
  160. console.log('form',this.form);
  161. uni.showModal({
  162. title: '提示',
  163. content: '确认删除吗!',
  164. success: res => {
  165. if (res.confirm) {
  166. this.$u.api.deleteMember({id:this.form.id}).then(res=>{
  167. uni.navigateBack()
  168. }).catch(err=>{
  169. console.log('deleteMember',err);
  170. })
  171. }
  172. }
  173. });
  174. },
  175. cancel(){
  176. this.leftClick();
  177. }
  178. }
  179. }
  180. </script>
  181. <style>
  182. page{
  183. background-color: #F4F5F7;
  184. }
  185. </style>
  186. <style lang="scss" scoped>
  187. .form-wrap{
  188. background: #FFFFFF;
  189. box-shadow: 0rpx 4rpx 8rpx 0rpx rgba(226,226,226,0.5);
  190. border-radius: 24rpx;
  191. margin-bottom: 70rpx;
  192. padding: 10rpx 40rpx 24rpx;
  193. }
  194. .set-default{
  195. padding-top: 26rpx;
  196. .up{
  197. font-size: 28rpx;
  198. font-weight: 500;
  199. color: #606060;
  200. line-height: 42rpx;
  201. margin-bottom: 20rpx;
  202. }
  203. .down{
  204. font-size: 24rpx;
  205. font-weight: 400;
  206. color: #7F7F7F;
  207. line-height: 36rpx;
  208. }
  209. }
  210. </style>