info.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. <template>
  2. <view style="padding: 30rpx;">
  3. <view style="display: flex;align-items: center;justify-content: space-between;">
  4. <view class="tip">
  5. 请填写真实信息,以便我们后续为您提供完善的
  6. <br />
  7. 个人职业成长定制服务!
  8. </view>
  9. <view style="display: flex;align-items: center;">
  10. <view class="btn" style="margin-right: 5rpx;" :style="form.certified === 1 ? isStatus : ''" @click="form.certified === 0 ? certification() : iscertification()">
  11. {{ form.certified === 0 ? '认证' : '已认证' }}
  12. </view>
  13. <!-- <view class="btn">编辑</view> -->
  14. </view>
  15. </view>
  16. <view class="form">
  17. <u-form :model="form" ref="uForm">
  18. <u-form-item label="姓名" prop="realname"><u-input placeholder="请输入真实姓名" v-model="form.realname" /></u-form-item>
  19. <u-form-item label="手机号码" prop="telphone" :label-width="auto"><u-input :disabled="true" v-model="form.telphone" /></u-form-item>
  20. <u-form-item label="身份证号" prop="idCard" :label-width="auto"><u-input placeholder="请输入身份证号" v-model="form.idCard" /></u-form-item>
  21. <u-form-item label="性别" prop="sex">
  22. <picker @change="bindPickerChangeSex" :value="form.sex" :range="array_sex">
  23. <view class="picker">{{ array_sex[form.sex] }}</view>
  24. </picker>
  25. </u-form-item>
  26. <u-form-item label="邮箱" prop="email" :label-width="auto"><u-input v-model="form.email" /></u-form-item>
  27. <u-form-item label="出生日期" prop="userBirth" :label-width="auto">
  28. <picker mode="date" :value="form.userBirth" @change="bindDateChange">
  29. <view class="picker">{{ form.userBirth?form.userBirth:'未知' }}</view>
  30. </picker>
  31. </u-form-item>
  32. <!-- <u-form-item label="身份"></u-form-item> -->
  33. <u-form-item label="户籍">
  34. <pick-regions :defaultRegion="defaultRegionCode" @getRegion="handleGetRegion">
  35. <view class="picker">{{ form.houseProvince }} {{ form.houseCity }} {{ form.houseDistrict }}</view>
  36. </pick-regions>
  37. </u-form-item>
  38. <u-form-item label="婚姻状况" prop="marry" :label-width="auto">
  39. <picker @change="bindPickerChangeMarry" :value="index_marry" :range="array_marry">
  40. <view class="picker">{{ array_marry[index_marry] }}</view>
  41. </picker>
  42. </u-form-item>
  43. <u-form-item label="所在城市" :label-width="auto">
  44. <pick-regions :defaultRegion="defaultRegionCode" @getRegion="handleGetRegion2">
  45. <view class="picker">{{ form.province }} {{ form.city }} {{ form.district }}</view>
  46. </pick-regions>
  47. </u-form-item>
  48. <u-form-item label="政治面貌" :label-width="auto" prop="politic">
  49. <picker @change="bindPickerChangePolitic" :value="index_politic" :range="array_politic">
  50. <view class="picker">{{ array_politic[index_politic] }}</view>
  51. </picker>
  52. </u-form-item>
  53. <u-form-item label="一寸头像" prop="fileList" :label-width="auto" label-position="top">
  54. <u-upload
  55. :auto-upload="false"
  56. :show-progress="false"
  57. custom-btn="true"
  58. :action="action"
  59. :file-list="fileList"
  60. width="120"
  61. height="169"
  62. size-type="['compressed']"
  63. max-count="1"
  64. @on-list-change="changePhotoListHeader"
  65. @on-remove="onRemovePic"
  66. >
  67. <template v-slot:addBtn>
  68. <image :src="form.oneInchPhotos!=null ? $method.splitImgHost( form.oneInchPhotos) : '/static/info_1.png'" style="width: 120rpx; height: 169rpx;"></image>
  69. </template>
  70. </u-upload>
  71. </u-form-item>
  72. <!-- <u-form-item label="身份证人像面" :label-width="auto" label-position="top">
  73. <u-upload
  74. :auto-upload="false"
  75. custom-btn="true"
  76. :action="action"
  77. :file-list="fileList1"
  78. width="120"
  79. height="82"
  80. size-type="['compressed']"
  81. max-count="1"
  82. @on-list-change="changePhotoListZ"
  83. >
  84. <template v-slot:addBtn>
  85. <image src="/static/info_2.png" style="width: 120rpx; height: 82rpx;"></image>
  86. </template>
  87. </u-upload>
  88. </u-form-item>
  89. <u-form-item label="身份证国徽面" :label-width="auto" label-position="top">
  90. <u-upload
  91. :auto-upload="false"
  92. custom-btn="true"
  93. :action="action"
  94. :file-list="fileList2"
  95. width="120"
  96. height="82"
  97. size-type="['compressed']"
  98. max-count="1"
  99. @on-list-change="changePhotoListF"
  100. >
  101. <template v-slot:addBtn>
  102. <image src="/static/info_3.png" style="width: 120rpx; height: 82rpx;"></image>
  103. </template>
  104. </u-upload>
  105. </u-form-item> -->
  106. </u-form>
  107. </view>
  108. <button @click="resultForm" class="submit_btn">提交</button>
  109. </view>
  110. </template>
  111. <script>
  112. import {mapGetters} from 'vuex';
  113. export default {
  114. data() {
  115. return {
  116. isStatus: 'background-color:#a8a8a8;',
  117. BizToken: '',
  118. action: '33',
  119. fileList: [],
  120. defaultRegionCode: '440112',
  121. form: {
  122. sex: 0,
  123. userBirth: '1990-01-01',
  124. houseProvince: '', //户籍省
  125. houseCity: '', //户籍市
  126. houseDistrict: '', //户籍区
  127. province: '', //城市省
  128. city: '', //市
  129. district: '', //区
  130. oneInchPhotos: ''
  131. },
  132. array_sex: ['男', '女'],
  133. index_marry: 0,
  134. array_marry: [],
  135. index_politic: 0,
  136. array_politic: [],
  137. rules: {
  138. realname: [
  139. {
  140. required: true,
  141. message: '请先输入真实姓名',
  142. trigger: 'blur'
  143. }
  144. ],
  145. telphone: [
  146. {
  147. required: true,
  148. message: '请输入手机号码',
  149. // 可以单个或者同时写两个触发验证方式
  150. trigger: 'blur'
  151. }
  152. ],
  153. idCard: [
  154. {
  155. required: true,
  156. message: '请先输入身份证号',
  157. // 可以单个或者同时写两个触发验证方式
  158. trigger: 'blur'
  159. }
  160. ],
  161. width: 0,
  162. height: 0,
  163. }
  164. };
  165. },
  166. onReady() {
  167. this.$refs.uForm.setRules(this.rules);
  168. this.form = this.userInfo
  169. if(this.form.houseProvince === ''||this.form.houseProvince == null){
  170. this.form.houseProvince = '广东省'
  171. }
  172. if(this.form.houseCity === ''||this.form.houseCity == null){
  173. this.form.houseCity = '广州市'
  174. }
  175. if(this.form.houseDistrict === ''||this.form.houseDistrict == null){
  176. this.form.houseDistrict = '天河区'
  177. }
  178. if(this.form.province === ''||this.form.province == null){
  179. this.form.province = '广东省'
  180. }
  181. if(this.form.city === ''||this.form.city == null){
  182. this.form.city = '广州市'
  183. }
  184. if(this.form.district === ''||this.form.district == null){
  185. this.form.district = '天河区'
  186. }
  187. if(this.form.marry !== null && this.form.marry != 'undefined' && this.form.marry !== ''){
  188. this.index_marry = this.array_marry.indexOf(this.form.marry)
  189. }
  190. if(this.form.politic !== null && this.form.politic != 'undefined' && this.form.politic !== ''){
  191. this.index_politic = this.array_politic.indexOf(this.form.politic)
  192. }
  193. },
  194. onLoad(option) {
  195. this.getUserInfos()
  196. const Verify = require('@/wxcomponents/verify_mpsdk/main.js');
  197. Verify.init();
  198. this.array_marry = this.$store.state.dictObj['marry_status']
  199. this.array_politic = this.$store.state.dictObj['politic_status']
  200. },
  201. methods: {
  202. onRemovePic(){
  203. this.form.oneInchPhotos = null
  204. },
  205. getUserInfos(){
  206. var self = this
  207. this.$api.getInfo().then(res => {
  208. this.form = res.data.data
  209. if (this.form.oneInchPhotos !== null) {
  210. self.fileList = [{ url: self.$method.splitImgHost(self.form.oneInchPhotos) }];
  211. }
  212. })
  213. },
  214. changePhotoListHeader(lists, name) {
  215. this.fileList = lists;
  216. },
  217. resultForm() {
  218. this.$refs.uForm.validate(valid => {
  219. if (valid) {
  220. this.submitForm();
  221. } else {
  222. console.log('验证失败');
  223. }
  224. });
  225. },
  226. iscertification() {},
  227. async certification() {
  228. var self = this;
  229. const faceBiz = await self.$api.faceBizToken();
  230. self.BizToken = faceBiz.data.data.bizToken;
  231. wx.startVerify({
  232. data: {
  233. token: self.BizToken
  234. },
  235. success: result => {
  236. setTimeout(() => {
  237. self.$api.facecertification(self.BizToken).then(faceRec => {
  238. //刷新用户信息
  239. self.getUserInfos()
  240. });
  241. }, 500);
  242. },
  243. fail: err => {
  244. setTimeout(() => {
  245. uni.showModal({
  246. title: '提示',
  247. content: err,
  248. showCancel: false
  249. });
  250. }, 500);
  251. }
  252. });
  253. },
  254. imageInfos() {
  255. var self = this
  256. return new Promise((resolve, reject) => {
  257. uni.getImageInfo({
  258. src: self.fileList[0].url,
  259. success: async res => {
  260. let canvasWidth = res.width; //图片原始长宽
  261. let canvasHeight = res.height;
  262. if (canvasWidth > 1000 || canvasHeight > 1000) {
  263. uni.compressImage({
  264. src: self.fileList[0].url,
  265. quality: 75,
  266. width: '50%',
  267. height: '50%',
  268. success: async rest => {
  269. const waitUpload = await self.uploadFile(rest.tempFilePath, 0);
  270. resolve()
  271. }
  272. });
  273. } else {
  274. console.log('无需压缩');
  275. const waitUpload = await self.uploadFile(self.fileList[0].url, 0);
  276. resolve()
  277. }
  278. }
  279. });
  280. });
  281. },
  282. async submitForm() {
  283. var self = this;
  284. if (self.fileList.length > 0&&self.fileList[0].url!=self.$method.splitImgHost(self.form.oneInchPhotos)) {
  285. const waitYS = await self.imageInfos();
  286. }
  287. var data = {
  288. userId: this.form.userId,
  289. email: this.form.email,
  290. houseProvince: this.form.houseProvince, //户籍省份
  291. idCard: this.form.idCard,
  292. houseCity: this.form.houseCity,
  293. houseDistrict: this.form.houseDistrict,
  294. province: this.form.province, //城市省份
  295. city: this.form.city, //城市
  296. district: this.form.district, //区
  297. realname: this.form.realname, //姓名
  298. sex: this.form.sex, //性别
  299. telphone: this.form.telphone, //手机号
  300. userBirth: this.form.userBirth, //出生日期
  301. marry: this.array_marry[this.index_marry], //结婚状态
  302. politic: this.array_politic[this.index_politic], //政治面貌
  303. oneInchPhotos: this.form.oneInchPhotos //一寸照
  304. };
  305. this.$api.appuserInfo(data).then(res => {
  306. if (res.data.code === 200) {
  307. setTimeout(()=>{
  308. uni.showToast({
  309. title: '提交成功',
  310. icon: 'none'
  311. });
  312. uni.navigateBack();
  313. },500);
  314. self.$api.refreshUserInfo()
  315. }else{
  316. uni.showToast({
  317. title: res.data.msg,
  318. icon: 'none'
  319. });
  320. }
  321. });
  322. },
  323. uploadFile(options, int) {
  324. return new Promise((resolve, reject) => {
  325. var self = this;
  326. var data = {
  327. imageStatus: int
  328. };
  329. this.$api.aliyunpolicy(data).then(res => {
  330. console.log(res);
  331. var ossToken = res.data.data.resultContent;
  332. uni.uploadFile({
  333. url: ossToken.host,
  334. name: 'file',
  335. filePath: options,
  336. fileType: 'image',
  337. header: {
  338. AuthorizationToken: 'WX ' + uni.getStorageSync('token')
  339. },
  340. formData: {
  341. key: ossToken.dir,
  342. OSSAccessKeyId: ossToken.accessid,
  343. policy: ossToken.policy,
  344. Signature: ossToken.signature,
  345. callback: ossToken.callback,
  346. success_action_status: 200
  347. },
  348. success: result => {
  349. if (result.statusCode === 200) {
  350. self.form.oneInchPhotos = ossToken.dir;
  351. resolve();
  352. } else {
  353. uni.showToast({
  354. title: '一寸头像上传失败',
  355. icon: 'none'
  356. });
  357. return;
  358. }
  359. },
  360. fail: error => {
  361. uni.showToast({
  362. title: '上传接口报错',
  363. icon: 'none'
  364. });
  365. return;
  366. }
  367. });
  368. });
  369. });
  370. },
  371. bindPickerChangeSex(e) {
  372. this.form.sex = e.detail.value;
  373. },
  374. bindPickerChangePolitic(e) {
  375. this.index_politic = e.detail.value;
  376. },
  377. bindPickerChangeMarry(e) {
  378. console.log(e)
  379. this.index_marry = e.detail.value;
  380. },
  381. //城市
  382. handleGetRegion2(region) {
  383. this.form.province = region[0].name;
  384. this.form.city = region[1].name;
  385. this.form.district = region[2].name;
  386. },
  387. // 籍贯获取选择的地区
  388. handleGetRegion(region) {
  389. console.log(region)
  390. this.form.houseProvince = region[0].name;
  391. this.form.houseCity = region[1].name;
  392. this.form.houseDistrict = region[2].name;
  393. },
  394. bindDateChange(e) {
  395. console.log(e.detail.value);
  396. this.form.userBirth = e.detail.value;
  397. // var year = this.form.userBirth.substr(0, 4);
  398. // var month = this.userBirth.substr(5, 2);
  399. // var day = this.userBirth.substr(8, 2);
  400. },
  401. actionSheetCallback(index) {
  402. uni.hideKeyboard();
  403. this.form.sex_text = this.actionSheetList[index].text;
  404. }
  405. },
  406. computed: {...mapGetters(['userInfo'])},
  407. watch:{
  408. userInfo(val, oldVal){
  409. this.form = val
  410. console.log(this.form,66)
  411. }
  412. }
  413. };
  414. </script>
  415. <style scope>
  416. .submit_btn{
  417. background-color: #32467B !important;
  418. border-color: #32467B !important;
  419. color: #FFFFFF;
  420. font-size: 30rpx;
  421. padding: 5rpx;
  422. }
  423. .u-form-item__message.data-v-5e7216f1 {
  424. padding: 0px !important;
  425. }
  426. .picker {
  427. text-align: right;
  428. }
  429. input {
  430. text-align: right;
  431. }
  432. .form {
  433. background: #ffffff;
  434. box-shadow: 0rpx 0rpx 16rpx 4rpx rgba(145, 156, 178, 0.1);
  435. border-radius: 32rpx;
  436. margin: 20rpx 0;
  437. padding: 15rpx;
  438. }
  439. .btn {
  440. width: 96rpx;
  441. height: 48rpx;
  442. background: #32467b;
  443. border-radius: 16rpx;
  444. font-size: 24rpx;
  445. color: #ffffff;
  446. line-height: 48rpx;
  447. text-align: center;
  448. }
  449. page {
  450. background: #fdfdfd;
  451. }
  452. .tip {
  453. width: 70%;
  454. font-size: 20rpx;
  455. font-family: PingFang SC;
  456. font-weight: 400;
  457. color: #32467b;
  458. }
  459. </style>