info.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  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 :disabled="true" 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 :disabled="true" 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.HeadImageUrl !== 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.form.marry], //结婚状态
  302. politic: this.array_politic[this.form.politic], //政治面貌
  303. oneInchPhotos: this.form.oneInchPhotos //一寸照
  304. };
  305. this.$api.appuserInfo(data).then(res => {
  306. if (res.data.code === 200) {
  307. uni.showToast({
  308. title: '提交成功',
  309. icon: 'none'
  310. });
  311. self.$api.refreshUserInfo()
  312. }else{
  313. uni.showToast({
  314. title: res.data.msg,
  315. icon: 'none'
  316. });
  317. }
  318. });
  319. },
  320. uploadFile(options, int) {
  321. return new Promise((resolve, reject) => {
  322. var self = this;
  323. var data = {
  324. imageStatus: int
  325. };
  326. this.$api.aliyunpolicy(data).then(res => {
  327. console.log(res);
  328. var ossToken = res.data.data.resultContent;
  329. uni.uploadFile({
  330. url: ossToken.host,
  331. name: 'file',
  332. filePath: options,
  333. fileType: 'image',
  334. header: {
  335. AuthorizationToken: 'WX ' + uni.getStorageSync('token')
  336. },
  337. formData: {
  338. key: ossToken.dir,
  339. OSSAccessKeyId: ossToken.accessid,
  340. policy: ossToken.policy,
  341. Signature: ossToken.signature,
  342. callback: ossToken.callback,
  343. success_action_status: 200
  344. },
  345. success: result => {
  346. if (result.statusCode === 200) {
  347. self.form.oneInchPhotos = ossToken.dir;
  348. resolve();
  349. } else {
  350. uni.showToast({
  351. title: '一寸头像上传失败',
  352. icon: 'none'
  353. });
  354. return;
  355. }
  356. },
  357. fail: error => {
  358. uni.showToast({
  359. title: '上传接口报错',
  360. icon: 'none'
  361. });
  362. return;
  363. }
  364. });
  365. });
  366. });
  367. },
  368. bindPickerChangeSex(e) {
  369. this.form.sex = e.detail.value;
  370. },
  371. bindPickerChangePolitic(e) {
  372. this.form.politic = e.detail.value;
  373. },
  374. bindPickerChangeMarry(e) {
  375. console.log(e)
  376. this.form.marry = e.detail.value;
  377. },
  378. //城市
  379. handleGetRegion2(region) {
  380. this.form.province = region[0].name;
  381. this.form.city = region[1].name;
  382. this.form.district = region[2].name;
  383. },
  384. // 籍贯获取选择的地区
  385. handleGetRegion(region) {
  386. console.log(region)
  387. this.form.houseProvince = region[0].name;
  388. this.form.houseCity = region[1].name;
  389. this.form.houseDistrict = region[2].name;
  390. },
  391. bindDateChange(e) {
  392. console.log(e.detail.value);
  393. this.form.userBirth = e.detail.value;
  394. // var year = this.form.userBirth.substr(0, 4);
  395. // var month = this.userBirth.substr(5, 2);
  396. // var day = this.userBirth.substr(8, 2);
  397. },
  398. actionSheetCallback(index) {
  399. uni.hideKeyboard();
  400. this.form.sex_text = this.actionSheetList[index].text;
  401. }
  402. },
  403. computed: {...mapGetters(['userInfo'])},
  404. watch:{
  405. userInfo(val, oldVal){
  406. this.form = val
  407. console.log(this.form,66)
  408. }
  409. }
  410. };
  411. </script>
  412. <style scope>
  413. .submit_btn{
  414. background-color: #32467B !important;
  415. border-color: #32467B !important;
  416. color: #FFFFFF;
  417. font-size: 30rpx;
  418. padding: 5rpx;
  419. }
  420. .u-form-item__message.data-v-5e7216f1 {
  421. padding: 0px !important;
  422. }
  423. .picker {
  424. text-align: right;
  425. }
  426. input {
  427. text-align: right;
  428. }
  429. .form {
  430. background: #ffffff;
  431. box-shadow: 0rpx 0rpx 16rpx 4rpx rgba(145, 156, 178, 0.1);
  432. border-radius: 32rpx;
  433. margin: 20rpx 0;
  434. padding: 15rpx;
  435. }
  436. .btn {
  437. width: 96rpx;
  438. height: 48rpx;
  439. background: #32467b;
  440. border-radius: 16rpx;
  441. font-size: 24rpx;
  442. color: #ffffff;
  443. line-height: 48rpx;
  444. text-align: center;
  445. }
  446. page {
  447. background: #fdfdfd;
  448. }
  449. .tip {
  450. width: 70%;
  451. font-size: 20rpx;
  452. font-family: PingFang SC;
  453. font-weight: 400;
  454. color: #32467b;
  455. }
  456. </style>