add.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. <template>
  2. <view class="add main-bg">
  3. <u-form :model="form" ref="uForm" :rules="rules">
  4. <u-form-item
  5. label="姓名"
  6. label-width="180"
  7. :label-position="labelPosition"
  8. prop="userName">
  9. <u-input
  10. v-model="form.userName"
  11. placeholder-style="color: #2E4F1C;"
  12. placeholder="请输入您的姓名" />
  13. </u-form-item>
  14. <u-form-item
  15. label="身份证号码"
  16. prop="userIdcard"
  17. label-width="180"
  18. :label-position="labelPosition">
  19. <view class="form-item">
  20. <u-input
  21. v-model="form.userIdcard"
  22. placeholder-style="color: #2E4F1C;"
  23. placeholder="请输入您的身份证号码" />
  24. </view>
  25. </u-form-item>
  26. <u-form-item
  27. label="手机号码"
  28. prop="tel"
  29. label-width="180"
  30. :label-position="labelPosition"
  31. >
  32. <u-input
  33. v-model="form.tel"
  34. placeholder-style="color: #2E4F1C;"
  35. placeholder="请输入您的手机号码" />
  36. </u-form-item>
  37. <u-form-item
  38. :label-position="labelPosition"
  39. label="身份"
  40. prop="relationName"
  41. label-width="150">
  42. <u-input
  43. type="select"
  44. :select-open="selectShow"
  45. v-model="form.relationName"
  46. placeholder="请选择"
  47. placeholder-style="color: #2E4F1C;"
  48. @click="selectShow = true">
  49. </u-input>
  50. </u-form-item>
  51. <view class="store-dis">
  52. <view class="store-address">
  53. <view class="select-address">
  54. <view style="color: #303133;" class="font-twenty">
  55. 家庭住址
  56. </view>
  57. <u-input
  58. v-model="form.address"
  59. placeholder-style="color: #2E4F1C;"
  60. placeholder="请选择地址"/>
  61. </view>
  62. </view>
  63. <view class="map-icon" @click="chooseLocation()">
  64. <image src="/static/map.png" class="icon-img"></image>
  65. </view>
  66. </view>
  67. </u-form>
  68. <view @click="submit" class="form-submit">确认添加</view>
  69. <u-select mode="single-column" :list="selectList" v-model="selectShow" @confirm="selectConfirm"></u-select>
  70. <u-toast ref="uToast" />
  71. </view>
  72. </template>
  73. <script>
  74. import server from "@/api/index";
  75. import amap from '@/lib/amap-wx.130.js'
  76. export default {
  77. data() {
  78. return {
  79. labelPosition: 'left',
  80. selectShow: false,
  81. id: null,
  82. userInfo: {},
  83. addressName: '',
  84. form: {
  85. userName: '',
  86. relationName: '',
  87. relationId:'',
  88. userIdcard: '',
  89. tel: '',
  90. address: ''
  91. },
  92. key:'1dc63f21c12985e199a715faf4c02f36',
  93. selectList: [],
  94. rules: {
  95. userName: [
  96. {
  97. required: true,
  98. message: '请输入您的姓名!',
  99. trigger: ['change','blur'],
  100. },
  101. {
  102. validator: (rule, value, callback) => {
  103. return this.$u.test.chinese(value);
  104. },
  105. message: '姓名必须是汉字!',
  106. trigger: ['change','blur'],
  107. }
  108. ],
  109. userIdcard: [
  110. {
  111. required: true,
  112. message: '请输入您的身份证号码!',
  113. trigger: ['change','blur']
  114. },
  115. {
  116. validator: (rule, value, callback) => {
  117. return this.$u.test.idCard(value);
  118. },
  119. message: '身份证号码格式不正确',
  120. trigger: ['change','blur'],
  121. }
  122. ],
  123. relationName: [
  124. {
  125. required: true,
  126. message: '请选择身份!',
  127. trigger: ['change','blur']
  128. }
  129. ],
  130. }
  131. }
  132. },
  133. onReady() {
  134. this.$refs.uForm.setRules(this.rules);
  135. },
  136. onLoad(e) {
  137. // this.userInfo = uni.getStorageSync('userInfo');
  138. // if(e.id){
  139. // this.id = e.id;
  140. // this.getUserRelationInfoFn();
  141. // }
  142. this.getRelationInfoListFn();
  143. this.amapPulgin = new amap.AMapWX({
  144. key: this.key
  145. })
  146. },
  147. methods:{
  148. chooseLocation(e) {
  149. uni.chooseLocation({
  150. success: (res) => {
  151. console.log("ppp99",res)
  152. this.form.address = res.address
  153. }
  154. })
  155. },
  156. getLocation() {
  157. let that = this;
  158. that.amapPulgin.getRegeo({
  159. success: res => {
  160. console.log('当前定位', res);
  161. that.addressName = `${res[0].regeocodeData.addressComponent.city}`
  162. // uni.hideLoading();
  163. },
  164. fail: err => {
  165. console.log(err)
  166. }
  167. })
  168. },
  169. getUserRelationInfoFn(){
  170. server.getUserRelationInfo(this.id).then(res =>{
  171. this.form = res
  172. })
  173. },
  174. getRelationInfoListFn(){
  175. server.getUploadInfo({dictType: 'basics_level'}).then(res =>{
  176. this.selectList = [];
  177. res.forEach(item =>{
  178. this.selectList.push({
  179. label: item.dictLabel,
  180. value: item.dictValue,
  181. // value: item.relationId,
  182. // label: item.relationInfo
  183. })
  184. })
  185. })
  186. },
  187. submit() {
  188. let _this = this
  189. this.$refs.uForm.validate(valid => {
  190. if (valid) {
  191. // if(_this.id){
  192. // server.updateUserRelation(_this.form).then(res =>{
  193. // _this.$refs.uToast.show({
  194. // title: '修改军属信息成功!',
  195. // type: 'default',
  196. // })
  197. // setTimeout(function() {
  198. // uni.navigateBack({
  199. // delta: 1
  200. // });
  201. // }, 2000);
  202. // })
  203. // }else{
  204. let params = _this.form
  205. params.remark = ''
  206. server.getAdd(params).then(res =>{
  207. _this.$refs.uToast.show({
  208. title: '添加军属成功!',
  209. type: 'default',
  210. })
  211. setTimeout(function() {
  212. uni.navigateBack({
  213. delta: 1
  214. });
  215. }, 2000);
  216. })
  217. // }
  218. } else {
  219. console.log('验证失败');
  220. }
  221. });
  222. },
  223. selectConfirm(e) {
  224. this.form.relationName = '';
  225. e.map((val, index) => {
  226. this.form.relationName = val.label;
  227. this.form.relationId = val.value;
  228. })
  229. },
  230. },
  231. }
  232. </script>
  233. <style lang="scss" scoped>
  234. /deep/ .u-icon__icon{
  235. position: relative;
  236. color: #2E4F1C!important;
  237. }
  238. /deep/ .u-form-item__message{
  239. padding-right: 0rpx!important;
  240. text-align: right;
  241. }
  242. /deep/ .u-input__input{
  243. color: #2E4F1C!important;
  244. font-size: 28rpx;
  245. font-family: PingFangSC-Regular, PingFang SC;
  246. font-weight: 400;
  247. text-align: right;
  248. }
  249. /deep/ .u-border, .u-border-bottom, .u-border-left, .u-border-right, .u-border-top, .u-border-top-bottom{
  250. }
  251. /deep/ .u-form-item{
  252. display: -webkit-box;
  253. display: -webkit-flex;
  254. display: flex;
  255. -webkit-box-orient: horizontal;
  256. -webkit-box-direction: normal;
  257. -webkit-flex-direction: row;
  258. flex-direction: row;
  259. box-sizing: border-box;
  260. line-height: 96rpx;
  261. -webkit-flex-direction: column;
  262. flex-direction: column;
  263. background: #FFFFFF;
  264. border-radius: 24rpx;
  265. height: 96rpx;
  266. margin-bottom: 40rpx;
  267. padding-left: 30rpx!important;
  268. padding-right: 30rpx!important;
  269. }
  270. .store-dis{
  271. display: flex;
  272. margin-bottom: 30rpx;
  273. .store-address{
  274. width: 580rpx;
  275. padding: 16rpx 30rpx;
  276. background: #fff;
  277. border-radius: 16rpx 0rpx 0rpx 16rpx;
  278. .select-address{
  279. display: flex;
  280. align-items: center;
  281. justify-content: space-between;
  282. }
  283. }
  284. .map-icon{
  285. width: 110rpx;
  286. background: #2E4F1C;
  287. text-align: center;
  288. border-radius: 0rpx 16rpx 16rpx 0rpx;
  289. padding-top: 31rpx;
  290. .icon-img{
  291. width: 42rpx;
  292. height: 42rpx;
  293. }
  294. }
  295. }
  296. .add{
  297. width: 100%;
  298. height: auto;
  299. min-height: 100vh;
  300. padding: 30rpx 30rpx 30rpx;
  301. .form-submit{
  302. margin: 120rpx auto;
  303. width: 570rpx;
  304. height: 96rpx;
  305. line-height: 96rpx;
  306. text-align: center;
  307. background: #2E4F1C;
  308. border-radius: 49rpx;
  309. font-size: 36rpx;
  310. font-family: PingFangSC-Medium, PingFang SC;
  311. font-weight: 500;
  312. color: #fff;
  313. }
  314. }
  315. </style>