profile.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  1. <template>
  2. <view class="page">
  3. <u-alert-tips
  4. v-if="vk.pubfn.isNotNull(vk.vuex.get('$user.agentInfo.verify_status'))"
  5. :type="vk.vuex.get('$user.agentInfo.verify_status') == 0 ? 'warning' : vk.vuex.get('$user.agentInfo.verify_status') == 1 ? 'success' : 'error'"
  6. title="当前状态:"
  7. :description="
  8. vk.vuex.get('$user.agentInfo.verify_status') == 0
  9. ? '当前资料审核中,修改提交后将重新进入审核流程'
  10. : vk.vuex.get('$user.agentInfo.verify_status') == 1
  11. ? '当前资料已审核通过,修改提交将重新进入审核流程'
  12. : '申请被拒绝,清理联系客服咨询'
  13. "
  14. ></u-alert-tips>
  15. <view class="form">
  16. <u-form :model="form" ref="uForm">
  17. <u-form-item label-width="150" label="姓名" prop="relname"><u-input placeholder="请输入您的真实姓名" v-model="form.relname" type="text"></u-input></u-form-item>
  18. <u-form-item label-width="150" label="性别" prop="gender">
  19. <u-radio-group v-model="form.gender" active-color="#2979ff">
  20. <u-radio name="male">男</u-radio>
  21. <u-radio name="female">女</u-radio>
  22. </u-radio-group>
  23. </u-form-item>
  24. <u-form-item label-width="150" label="手机号" prop="mobile"><u-input placeholder="请输入您的手机号" v-model="form.mobile" type="text"></u-input></u-form-item>
  25. <u-form-item label-width="150" label="身份证号" prop="id_card_no">
  26. <u-input placeholder="请输入您的身份证号" v-model="form.id_card_no" type="text" @input="inputIdcard()"></u-input>
  27. </u-form-item>
  28. <u-form-item label-width="150" label="选择身份" prop="type">
  29. <u-input type="select" :select-open="agentTypeSelectShow" v-model="form.agent_type_name" placeholder="请选择身份" @click="agentTypeSelectShow = true"></u-input>
  30. </u-form-item>
  31. <u-form-item label-width="150" label="选择机构" prop="agency_id" v-if="form.type == 2">
  32. <u-input
  33. type="select"
  34. :select-open="agencySelectShow"
  35. v-model="form.agency_name"
  36. placeholder="请选择所属机构"
  37. @click="agencyList.length > 0 ? (agencySelectShow = true) : vk.toast('暂无可选经纪机构')"
  38. ></u-input>
  39. </u-form-item>
  40. <u-form-item label-width="150" label="项目名称" prop="property_name" v-if="form.type == 3">
  41. <u-input type="text" v-model="form.property_name" placeholder="请输入拥有产权项目名称"></u-input>
  42. </u-form-item>
  43. <u-form-item label-width="150" label="项目房号" prop="house_no" v-if="form.type == 3">
  44. <u-input type="text" v-model="form.house_no" placeholder="请输入拥有产权项目名称"></u-input>
  45. </u-form-item>
  46. <u-form-item label-position="top" label-width="150" label="身份证头像页" prop="id_card_front_image">
  47. <view class="id_card" @click="uploadFrontImage">
  48. <u-icon v-if="form.id_card_front_image == null" name="plus" size="32" color="#606266"></u-icon>
  49. <text v-if="form.id_card_front_image == null">{{ idCradFrontImageDisabled ? '请先输入身份证号' : '点击上传图片' }}</text>
  50. <image v-if="form.id_card_front_image != null" :src="form.id_card_front_image" mode="aspectFill"></image>
  51. </view>
  52. </u-form-item>
  53. <u-form-item label-position="top" label-width="150" label="身份证国徽页" prop="id_card_back_image">
  54. <view class="id_card" @click="uploadBackImage">
  55. <u-icon v-if="form.id_card_back_image == null" name="plus" size="32" color="#606266"></u-icon>
  56. <text v-if="form.id_card_back_image == null">{{ idCradBackImageDisabled ? '请先上传身份证头像页照片' : '点击上传图片' }}</text>
  57. <image v-if="form.id_card_back_image != null" :src="form.id_card_back_image" mode="aspectFill"></image>
  58. </view>
  59. </u-form-item>
  60. </u-form>
  61. <u-gap height="60"></u-gap>
  62. <u-button type="primary" :disabled="submitButtonDisabled" @click="submitModalShow = true">提交</u-button>
  63. <u-gap></u-gap>
  64. <view class="footer">
  65. 提交即代表同意
  66. <text class="agreement" @click="vk.navigateTo('/pages/agreement/agreement?type=user_agreement')">《用户协议》</text>
  67. <text class="agreement" @click="vk.navigateTo('/pages/agreement/agreement?type=privacy_agreement')">《隐私协议》</text>
  68. </view>
  69. </view>
  70. <!-- 列表选择 -->
  71. <u-select mode="single-column" :list="agentTypeList" v-model="agentTypeSelectShow" @confirm="agentTypeConfirm"></u-select>
  72. <u-select mode="single-column" :list="agencyList" v-model="agencySelectShow" @confirm="agencySelectConfirm"></u-select>
  73. <!-- modal -->
  74. <u-modal v-model="submitModalShow" content="请务必仔细确认各项信息是否正确" :show-cancel-button="true" @confirm="submit()"></u-modal>
  75. <u-modal v-model="modalShow" :content="modalContent" :show-cancel-button="true" @cancel="modalCancel()" @confirm="modalConfirm()"></u-modal>
  76. <!-- mask -->
  77. <u-mask :show="maskShow" @click="maskShow = false">
  78. <view class="warp">
  79. <u-image src="https://zdcdn.2bwin.cn/uploads/20220513/90abe6fe85d6c17f6bdc069955fbb878.png" mode="widthFix" width="400rpx" border-radius="20rpx"></u-image>
  80. <u-gap></u-gap>
  81. <u-button size="medium" type="primary" @click="maskShow = false">确定</u-button>
  82. </view>
  83. </u-mask>
  84. <!-- utoast -->
  85. <u-toast ref="uToast" />
  86. </view>
  87. </template>
  88. <script>
  89. var that;
  90. export default {
  91. data() {
  92. return {
  93. maskShow: true,
  94. form: {
  95. relname: null,
  96. gender: 'male',
  97. mobile: '',
  98. id_card_no: '',
  99. id_card_front_image: null,
  100. id_card_back_image: null,
  101. type: '', // 身份
  102. agent_type_name: '请选择', // 名称
  103. agency_id: null,
  104. agency_name: '请选择',
  105. property_name: null,
  106. house_no: null
  107. },
  108. idCradFrontImageDisabled: true,
  109. idCradBackImageDisabled: true,
  110. submitButtonDisabled: true,
  111. rules: {
  112. relname: [
  113. {
  114. required: true,
  115. message: '姓名不得为空',
  116. trigger: ['change', 'blur']
  117. },
  118. {
  119. // 自定义验证函数,见上说明
  120. validator: (rule, value, callback) => {
  121. return this.$u.test.chinese(value);
  122. },
  123. message: '姓名格式不正确',
  124. trigger: ['change', 'blur']
  125. }
  126. ],
  127. mobile: [
  128. {
  129. required: true,
  130. message: '手机号不得为空',
  131. trigger: ['change', 'blur']
  132. },
  133. {
  134. // 自定义验证函数,见上说明
  135. validator: (rule, value, callback) => {
  136. return vk.pubfn.test(value,'mobile');
  137. },
  138. message: '手机号格式不正确',
  139. trigger: ['change', 'blur']
  140. }
  141. ],
  142. id_card_no: [
  143. {
  144. required: true,
  145. message: '身份证号不得为空',
  146. trigger: ['change', 'blur']
  147. },
  148. {
  149. // 自定义验证函数,见上说明
  150. validator: (rule, value, callback) => {
  151. return this.$u.test.idCard(value);
  152. },
  153. message: '身份证号格式不正确',
  154. trigger: ['change', 'blur']
  155. }
  156. ],
  157. id_card_back_image: [
  158. {
  159. required: true,
  160. message: '身份证头像页照片不得为空',
  161. trigger: ['change', 'blur']
  162. }
  163. ],
  164. back_image: [
  165. {
  166. required: true,
  167. message: '身份证国徽页照片不得为空',
  168. trigger: ['change', 'blur']
  169. }
  170. ],
  171. agency_id: [
  172. {
  173. required: true,
  174. message: '所属机构不得为空',
  175. trigger: ['change', 'blur']
  176. }
  177. ],
  178. property_name: [
  179. {
  180. required: true,
  181. message: '所属项目不得为空',
  182. trigger: ['change', 'blur']
  183. }
  184. ],
  185. house_no: [
  186. {
  187. required: true,
  188. message: '房号不得为空',
  189. trigger: ['change', 'blur']
  190. }
  191. ]
  192. },
  193. // 给百度识别用的
  194. idcard_name: '',
  195. idcard_code: '',
  196. // 经纪人身份等
  197. agentTypeSelectShow: false,
  198. agentTypeList: [
  199. {
  200. label: '自由经纪人',
  201. value: 1
  202. },
  203. {
  204. label: '渠道经纪人',
  205. value: 2
  206. },
  207. {
  208. label: '老业主',
  209. value: 3
  210. }
  211. ],
  212. agencySelectShow: false, // 中介机构
  213. agencyList: [], // 中介机构
  214. propertyInputShow: false, // 老业主
  215. disabled: true,
  216. submitModalShow: false,
  217. modalType: 1,
  218. modalShow: false,
  219. modalContent: '',
  220. guideShow: false,
  221. updateMethod: 'update'
  222. };
  223. },
  224. onLoad(params) {
  225. that = this;
  226. if (!vk.checkToken()) {
  227. vk.toast('请先登录', 'none', 1500, true, function() {
  228. vk.navigateToLogin();
  229. });
  230. } else {
  231. vk.callFunction({
  232. url: 'client/agent/kh/getAgentInfo',
  233. title: '请求中...',
  234. needAlert: false
  235. })
  236. .then(res => {
  237. if (vk.pubfn.isNull(res.info)) {
  238. that.updateMethod = 'create';
  239. vk.toast('请补全您的资料', 'none');
  240. } else {
  241. // 更新审核状态
  242. vk.vuex.set('$user.agentInfo', res.info);
  243. console.log(vk.vuex.get('$user.agentInfo'));
  244. that.form.relname = res.info.relname;
  245. that.form.mobile = res.info.mobile;
  246. that.form.id_card_no = res.info.id_card_info.no;
  247. // 已设置类型
  248. if (vk.pubfn.isNotNull(res.info.type)) {
  249. that.form.type = res.info.type;
  250. let typeItem = vk.pubfn.getListItem(that.agentTypeList, 'value', res.info.type);
  251. that.form.agent_type_name = typeItem.label;
  252. if (res.info.type == 2 && vk.pubfn.isNotNull(res.info.agencyInfo)) {
  253. that.form.agency_id = res.info.agency_id;
  254. that.form.agency_name = res.info.agencyInfo.name;
  255. }
  256. if (res.info.type == 3) {
  257. that.form.property_name = res.info.property_info.name;
  258. that.form.house_no = res.info.property_info.house_no;
  259. }
  260. }
  261. that.form.id_card_front_image = res.info.id_card_info.front_image;
  262. that.form.id_card_back_image = res.info.id_card_info.back_image;
  263. if (vk.pubfn.isNotNull(res.info.id_card_info.no)) {
  264. that.idcard_name = res.info.relname;
  265. that.idcard_code = res.info.id_card_info.no;
  266. that.idCradFrontImageDisabled = false;
  267. }
  268. if (vk.pubfn.isNotNull(res.info.id_card_info.front_image)) {
  269. that.idCradBackImageDisabled = false;
  270. }
  271. if (vk.pubfn.isNotNull(res.info.id_card_info.back_image)) {
  272. that.submitButtonDisabled = false;
  273. }
  274. }
  275. })
  276. .catch(res => {
  277. console.log(res);
  278. });
  279. }
  280. },
  281. // 必须要在onReady生命周期,因为onLoad生命周期组件可能尚未创建完毕
  282. onReady() {
  283. this.$refs.uForm.setRules(this.rules);
  284. },
  285. methods: {
  286. // 选择所属项目回调
  287. agentTypeConfirm(e) {
  288. e.map((val, index) => {
  289. that.form.type = val.value;
  290. that.form.agent_type_name = val.label;
  291. // 如果是渠道经纪人,需要选择渠道公司名称
  292. if (val.value == 2) {
  293. vk.callFunction({
  294. url: 'client/agent/kh/getAgencyList',
  295. needAlert: false
  296. }).then(res => {
  297. if (res.list.length == 0) {
  298. that.form.agency_name = '可联系客服添加';
  299. vk.toast('暂无可选经纪机构', 'none');
  300. return;
  301. }
  302. that.agencyList = res.list;
  303. });
  304. }
  305. });
  306. },
  307. // 选择经纪机构后回调
  308. agencySelectConfirm(e) {
  309. e.map((val, index) => {
  310. this.form.agency_id = val.value;
  311. this.form.agency_name = val.label;
  312. });
  313. },
  314. // 选择、验证、上传正面照片
  315. uploadFrontImage() {
  316. if (vk.pubfn.isNullOne(that.form.relname, that.form.id_card_no) || !vk.pubfn.test(that.form.relname, 'chinese') || !vk.pubfn.test(that.form.id_card_no, 'card')) {
  317. vk.toast('请检查姓名、身份证号', 'none');
  318. return;
  319. }
  320. uni.chooseImage({
  321. count: 1,
  322. sizeType: ['compressed'],
  323. success: function(res) {
  324. let file = res.tempFiles[0];
  325. // 这里需要自己配置百度的secret
  326. vk.openapi.baidu.open.ocr.idcard({
  327. title: '识别中...',
  328. data: {
  329. file
  330. },
  331. success: function(ocrRes) {
  332. console.log(ocrRes);
  333. if (that.form.relname !== ocrRes['words_result']['姓名']['words']) {
  334. vk.toast('身份证姓名不符');
  335. return;
  336. }
  337. if (that.form.id_card_no !== ocrRes['words_result']['公民身份号码']['words']) {
  338. vk.toast('身份证号不符');
  339. return;
  340. }
  341. vk.toast('身份信息验证通过', 'success');
  342. that.idcard_code = ocrRes['words_result']['公民身份号码']['words'];
  343. that.idcard_name = ocrRes['words_result']['姓名']['words'];
  344. // 上传至 unicloud云储存
  345. vk.callFunctionUtil.uploadFile({
  346. title: '上传中...',
  347. filePath: res.tempFilePaths[0],
  348. suffix: 'png', // 不传suffix会自动获取,但H5环境下获取不到后缀,但可以通过file.name 获取
  349. provider: 'unicloud',
  350. success(uploadRes) {
  351. console.log(uploadRes);
  352. // 上传成功
  353. that.form.id_card_front_image = uploadRes.url;
  354. that.idCradBackImageDisabled = false;
  355. }
  356. });
  357. },
  358. fail: err => {
  359. console.log(err);
  360. }
  361. });
  362. }
  363. });
  364. },
  365. // 选择、上传身份证背面
  366. uploadBackImage() {
  367. uni.chooseImage({
  368. count: 1,
  369. sizeType: ['compressed'],
  370. success: function(res) {
  371. // 上传至 unicloud云储存
  372. vk.callFunctionUtil.uploadFile({
  373. title: '上传中...',
  374. filePath: res.tempFilePaths[0],
  375. suffix: 'png', // 不传suffix会自动获取,但H5环境下获取不到后缀,但可以通过file.name 获取
  376. provider: 'unicloud',
  377. success(res) {
  378. // 上传成功
  379. that.form.id_card_back_image = res.url;
  380. }
  381. });
  382. }
  383. });
  384. },
  385. submit() {
  386. that.$refs.uForm.validate(valid => {
  387. if (valid) {
  388. if (that.form.relname !== that.idcard_name) {
  389. vk.toast('身份证姓名不符');
  390. console.log(that.idcard_name);
  391. return;
  392. }
  393. if (that.form.id_card_no !== that.idcard_code) {
  394. vk.toast('身份证号不符');
  395. console.log(that.idcard_code);
  396. return;
  397. }
  398. let id_card_info = {
  399. no: that.form.id_card_no,
  400. front_image: that.form.id_card_front_image,
  401. back_image: that.form.id_card_back_image
  402. };
  403. let property_info = {
  404. name: that.form.property_name,
  405. house_no: that.form.house_no
  406. };
  407. vk.callFunction({
  408. url: 'client/agent/kh/updateAgentInfo',
  409. title: '请求中...',
  410. needAlert: false,
  411. data: {
  412. method: that.updateMethod,
  413. type: that.form.type,
  414. relname: that.form.relname,
  415. gender: that.form.gender,
  416. mobile: that.form.mobile,
  417. id_card_info: id_card_info,
  418. property_info: property_info,
  419. agency_id: that.form.agency_id
  420. }
  421. })
  422. .then(res => {
  423. console.log(res);
  424. vk.vuex.set('$user.agentInfo.relname', that.form.relname);
  425. vk.vuex.set('$user.userInfo.mobile', that.form.mobile);
  426. vk.vuex.set('$user.agentInfo.id_card_info', id_card_info);
  427. vk.vuex.set('$user.agentInfo.verify_status', 0); // 审核中
  428. vk.toast('更新成功,等待审核', 'none', 1500, true, function() {
  429. vk.navigateToHome();
  430. });
  431. })
  432. .catch(res => {
  433. console.log(res);
  434. });
  435. } else {
  436. console.log('验证失败');
  437. }
  438. });
  439. },
  440. // 监听身份证号
  441. inputIdcard() {
  442. that.idCradFrontImageDisabled = true;
  443. // 判断身份证格式
  444. if (vk.pubfn.test(that.form.id_card_no, 'card') && vk.pubfn.isNotNull(that.form.relname)) {
  445. that.idCradFrontImageDisabled = false;
  446. }
  447. },
  448. // 以下是工具函数
  449. // 格式化日期的月份或天数的显示(小于10,在前面增加0)
  450. getFormatDate(value) {
  451. if (value == undefined || value == '') {
  452. return '';
  453. }
  454. var str = value;
  455. if (parseInt(value) < 10) {
  456. str = '0' + value;
  457. }
  458. return str;
  459. }
  460. }
  461. };
  462. </script>
  463. <style lang="scss">
  464. .page {
  465. background-color: #ffffff;
  466. }
  467. .form {
  468. border-radius: 10rpx;
  469. padding: 0 40rpx;
  470. }
  471. .popup-body {
  472. .tips-title {
  473. font-size: $u-p;
  474. margin-bottom: 20rpx;
  475. }
  476. .tips-content {
  477. font-size: $u-p2;
  478. color: $u-tips-color;
  479. margin-bottom: 60rpx;
  480. }
  481. }
  482. .id_card {
  483. color: #606266;
  484. width: 100%;
  485. height: 350rpx;
  486. display: flex;
  487. flex-direction: column;
  488. align-items: center;
  489. justify-content: center;
  490. background-color: #f4f5f6;
  491. font-size: $u-p2;
  492. border-radius: 10rpx;
  493. image {
  494. border-radius: 10rpx;
  495. }
  496. }
  497. .footer {
  498. position: relative;
  499. text-align: center;
  500. font-size: $u-p2;
  501. left: 0;
  502. bottom: 20rpx;
  503. .agreement {
  504. color: $u-theme-color;
  505. }
  506. }
  507. .slot-content {
  508. font-size: 28rpx;
  509. color: $u-content-color;
  510. padding: 20rpx;
  511. }
  512. .warp {
  513. display: flex;
  514. flex-direction: column;
  515. align-items: center;
  516. justify-content: center;
  517. height: 100%;
  518. }
  519. .rect {
  520. width: 400rpx;
  521. height: 400rpx;
  522. background-color: #fff;
  523. }
  524. </style>