info.vue 13 KB

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