editUserInfo.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. <template>
  2. <view :class="['qn-page-' + theme]">
  3. <view class="user-pic-view">
  4. <QiniuUpload @uploadSuccess="uploadSuccess" :images="user_info.avatar" @handleRemove="imgRemove" :flag="true">
  5. <!-- <div slot="cont">
  6. <view class="user-img-view"><img class="user-pic" :src="user_info.avatar" alt="" /></view>
  7. <p>修改头像</p>
  8. </div> -->
  9. </QiniuUpload>
  10. </view>
  11. <view class="info-edit-ul" v-if="customer_field.includes('真实姓名')">
  12. <view class="info-edit-li">
  13. <p class="edit-label">
  14. 真实姓名
  15. <text class="start-icon">*</text>
  16. </p>
  17. <input type="text" placeholder="请输入真实姓名" v-model="user_info.name" placeholder-class="placeholderClass" />
  18. </view>
  19. <view class="info-edit-li" v-if="customer_field.includes('电话')">
  20. <p class="edit-label">
  21. 电话
  22. <text class="start-icon">*</text>
  23. </p>
  24. <input type="number" placeholder="请输入您的手机号" v-model="user_info.mobile" placeholder-class="placeholderClass" />
  25. </view>
  26. <RegionSel @pickerRegionChange="pickerRegionChange" v-if="customer_field.includes('地址')">
  27. <view class="info-edit-li">
  28. <p class="edit-label">
  29. 区域
  30. <text class="start-icon">*</text>
  31. </p>
  32. <view style="padding: 10rpx 0;">
  33. <span v-if="region_name" style="font-size: 28rpx;">{{ region_name }}</span>
  34. <span v-else style="color: #999;font-size: 28rpx;">请选择</span>
  35. </view>
  36. </view>
  37. </RegionSel>
  38. <view class="info-edit-li" v-if="customer_field.includes('地址')">
  39. <p class="edit-label">
  40. 详细地址
  41. <text class="start-icon">*</text>
  42. </p>
  43. <input type="text" placeholder="请输入详细地址" v-model="user_info.address" placeholder-class="placeholderClass" @blur="addressBlur" />
  44. </view>
  45. <view class="info-edit-li" v-if="customer_field.includes('客户类型')">
  46. <p class="edit-label">
  47. 客户类型
  48. <text class="start-icon">*</text>
  49. </p>
  50. <picker style="width: 680rpx;padding: 20upx 0;" class="clearfix" @change="typeChange" :value="tyIndex" :range="type_list" range-key="title">
  51. <block v-if="type_list[tyIndex]">
  52. <text class="uni-input" style="color:#000000">{{ type_list[tyIndex].title }}</text>
  53. </block>
  54. <block v-else><text class="uni-input">请选择客户类型</text></block>
  55. </picker>
  56. </view>
  57. <view class="info-edit-li" v-if="customer_field.includes('营业执照')">
  58. <p class="edit-label">
  59. 营业执照
  60. <text class="start-icon" v-if="isEvidence === 5">*</text>
  61. </p>
  62. <QiniuUpload @uploadSuccess="uploadLicense" :images="user_info.extend.license" :flag="true">
  63. <!-- <div slot="cont">
  64. <view class="user-img-license">
  65. <img v-if="user_info.extend.license" class="license-pic" :src="user_info.extend.license" alt="" />
  66. <text v-else>+</text>
  67. </view>
  68. </div> -->
  69. </QiniuUpload>
  70. </view>
  71. <!-- <view class="info-edit-li">
  72. <p class="edit-label">生日</p>
  73. <picker mode="date" :value="date" @change="bindDateChange">
  74. <view v-if="user_info.birthday" style="color:#000000" class="uni-input">{{ birthday }}</view>
  75. <view v-else class="uni-input">请选择</view>
  76. </picker>
  77. </view> -->
  78. <view class="info-edit-li" v-if="customer_field.includes('备注')">
  79. <p class="edit-label">备注</p>
  80. <input type="text" placeholder="备注" v-model="user_info.remark" placeholder-class="placeholderClass" />
  81. </view>
  82. </view>
  83. <view class="btn-view"><view class="sub-btn primary-btn" @click="updateInfo">保存</view></view>
  84. </view>
  85. </template>
  86. <script>
  87. import QiniuUpload from '../components/qiniu/QiniuUpload.vue';
  88. import webUrl from '@/config.js';
  89. import RegionSel from '../components/region/RegionSel.vue';
  90. import { getEnToken } from '@/access/common.js';
  91. export default {
  92. components: {
  93. QiniuUpload,
  94. RegionSel
  95. },
  96. data() {
  97. return {
  98. date: '1990-01-01',
  99. region_name: '',
  100. user_info: {
  101. name: '',
  102. avatar: '',
  103. remark: '',
  104. provinceCode: '',
  105. cityCode: '',
  106. districtCode: '',
  107. longitude: '',
  108. latitude: '',
  109. birthday: '',
  110. type: '',
  111. extend: {
  112. license: []
  113. },
  114. contact: {
  115. name: '',
  116. provinceCode: '',
  117. cityCode: '',
  118. districtCode: '',
  119. address: '',
  120. mobile: ''
  121. }
  122. },
  123. type_list: [],
  124. tyIndex: '',
  125. user_id: 0,
  126. uploadtoken: '',
  127. img_url: '',
  128. mobileO: '',
  129. base_set_info: {},
  130. isEvidence: 4,
  131. birthday: '',
  132. customer_field: []
  133. };
  134. },
  135. async onLoad(options) {
  136. this.user_info.avatar = [this.$common.getAvator()];
  137. this.user_info.mobile = this.$common.getphoneNumber() || '';
  138. // 获取用户注册的手机号,避免用户二次输入
  139. this.mobileO = this.$common.getphoneNumber() || '';
  140. this.base_set_info = this.$store.state.baseSet;
  141. await this.getUserInfo();
  142. await this.getBasicField();
  143. },
  144. methods: {
  145. getBasicField() {
  146. this.$u.api
  147. .getBasicField({
  148. field: ['customerData']
  149. })
  150. .then(res => {
  151. this.customer_field = res.data.customerData;
  152. if (this.customer_field.includes('客户类型')) {
  153. this.getCustomerSourceList();
  154. }
  155. });
  156. },
  157. // 选择生日
  158. bindDateChange(e) {
  159. this.birthday = e.target.value;
  160. this.user_info.birthday = this.$_utils.dateToStamp(e.target.value);
  161. },
  162. typeChange(e) {
  163. this.tyIndex = e.detail.value;
  164. this.user_info.type = this.type_list[this.tyIndex].id;
  165. this.isEvidence = this.type_list[this.tyIndex].isEvidence;
  166. },
  167. // 获取客户类型
  168. getCustomerSourceList() {
  169. this.$u.api.getCustomerSourceList().then(({ data }) => {
  170. this.type_list = data.map(item => {
  171. return {
  172. ...item,
  173. id: item.id,
  174. title: item.name
  175. };
  176. });
  177. if (this.user_info.type) {
  178. this.tyIndex = this.type_list.findIndex(item => item.id === this.user_info.type);
  179. } else {
  180. const indexT = this.type_list.findIndex(item => item.defaultStatus === 5);
  181. if (indexT > -1) {
  182. this.tyIndex = indexT;
  183. this.user_info.type = this.type_list[indexT].id;
  184. this.isEvidence = this.type_list[indexT].isEvidence;
  185. }
  186. }
  187. });
  188. },
  189. pickerRegionChange(row) {
  190. this.user_info.provinceCode = row[0].value;
  191. this.user_info.cityCode = row[1].value;
  192. this.user_info.districtCode = row[2].value;
  193. this.user_info.contact.provinceCode = row[0].value;
  194. this.user_info.contact.cityCode = row[1].value;
  195. this.user_info.contact.districtCode = row[2].value;
  196. this.region_name = row[0].label + '-' + row[1].label + '-' + row[2].label;
  197. },
  198. addressBlur() {
  199. if (!this.region_name) {
  200. this.$api.msg('请选择所属区域');
  201. return;
  202. }
  203. },
  204. uploadSuccess(res) {
  205. const uploadPicUrl = `${webUrl.QINIU_URL}/${res.key}`;
  206. this.user_info.avatar = [uploadPicUrl];
  207. },
  208. uploadLicense(res) {
  209. const uploadPicUrl = `${webUrl.QINIU_URL}/${res.key}`;
  210. this.user_info.extend.license = [uploadPicUrl];
  211. },
  212. // 获取用户个人信息
  213. getUserInfo(Refresh) {
  214. this.$u.api.getCustomerInfo().then(({ data }) => {
  215. this.user_info = {
  216. ...this.user_info,
  217. ...data,
  218. mobile: this.mobileO || data.mobile,
  219. avatar: [data.avatar],
  220. extend: data.extend || {
  221. license: []
  222. },
  223. address: data.contact[0] ? data.contact[0].address : '',
  224. contact: data.contact[0] || {
  225. provinceCode: '',
  226. cityCode: '',
  227. districtCode: '',
  228. address: '',
  229. name: '',
  230. mobile: this.mobileO || data.mobile
  231. }
  232. };
  233. console.log(this.user_info);
  234. if (data.contact[0]) {
  235. this.user_info.provinceCode = data.contact[0].provinceCode;
  236. this.user_info.cityCode = data.contact[0].cityCode;
  237. this.user_info.districtCode = data.contact[0].districtCode;
  238. }
  239. this.avatar = this.user_info.avatar;
  240. this.birthday = this.user_info.birthday ? this.$_utils.formatDate(this.user_info.birthday, 'yyyy-MM-dd') : '';
  241. if (data.contact.length) {
  242. this.region_name = data.contact[0].area.provinceName + '-' + data.contact[0].area.cityName + '-' + data.contact[0].area.districtName;
  243. }
  244. this.$store.commit('commit_userStatus', data);
  245. if (Refresh) {
  246. if (this.base_set_info.personnelReview === 4) {
  247. this.goPage('/pages/index/index', 'switchTab');
  248. } else {
  249. if (data.status === 1) {
  250. uni.showModal({
  251. title: '账号正在审核中,您可以',
  252. content: '联系电话:' + (data.enterpriseMobile || ''),
  253. confirmText: '联系客服',
  254. cancelText: '去逛逛',
  255. success: res => {
  256. if (res.confirm) {
  257. uni.makePhoneCall({
  258. phoneNumber: data.enterpriseMobile,
  259. complete: () => {
  260. this.goPage('/pages/index/index', 'switchTab');
  261. }
  262. });
  263. } else {
  264. this.goPage('/pages/index/index', 'switchTab');
  265. }
  266. }
  267. });
  268. } else if (data.status === 2) {
  269. this.goPage('/pages/index/index', 'switchTab');
  270. } else if (data.status === 3) {
  271. // 说明资料不完善,跳转到完善资料的页面
  272. uni.showModal({
  273. title: '审核未通过审核,请重新修改资料',
  274. content: data.auditFailReason || '',
  275. cancelText: '取消',
  276. confirmText: '修改资料',
  277. success: res => {}
  278. });
  279. } else if (data.status === 0) {
  280. uni.showModal({
  281. title: '请完善信息后再进行操作',
  282. content: '商家需要对客户资料进行审核,请您完善信息后再次进行操作',
  283. confirmText: '完善信息',
  284. cancelText: '取消',
  285. success: res => {}
  286. });
  287. }
  288. }
  289. }
  290. });
  291. },
  292. //修改个人信息
  293. updateInfo() {
  294. if (!this.user_info.name) {
  295. this.$api.msg('请填写个人名称');
  296. return;
  297. } else if (this.customer_field.includes('电话') && !this.user_info.mobile) {
  298. this.$api.msg('请填写电话');
  299. return;
  300. } else if (this.customer_field.includes('地址') && !this.user_info.districtCode) {
  301. this.$api.msg('请选择所属区域');
  302. return;
  303. } else if (this.customer_field.includes('地址') && !this.user_info.address) {
  304. this.$api.msg('请补充完详细地址');
  305. return;
  306. } else if (this.customer_field.includes('客户类型') && !this.user_info.type) {
  307. this.$api.msg('请选择客户类型');
  308. return;
  309. } else if (this.customer_field.includes('营业执照') && parseInt(this.isEvidence) === 5 && !this.user_info.extend.license) {
  310. this.$api.msg('由于您选择的客户类型是零售商或者是批发商,所以必须上传营业执照');
  311. return;
  312. }
  313. const params = {
  314. ...this.user_info,
  315. avatar: this.user_info.avatar[0],
  316. contact: {
  317. ...this.user_info.contact,
  318. name: this.user_info.name,
  319. mobile: this.user_info.mobile,
  320. address: this.user_info.address
  321. }
  322. };
  323. // return
  324. this.$u.api.editCustomerInfo(params).then(res => {
  325. this.getUserInfo('Refresh');
  326. if (this.customer_field.includes('地址')) {
  327. this.addAddress();
  328. }
  329. });
  330. },
  331. // 客户地址添加
  332. addAddress() {
  333. this.$u.api
  334. .addShippingAddress({
  335. name: this.user_info.name,
  336. mobile: this.user_info.mobile,
  337. defaultStatus: 5,
  338. provinceCode: this.user_info.provinceCode,
  339. cityCode: this.user_info.cityCode,
  340. districtCode: this.user_info.districtCode,
  341. address: this.user_info.address
  342. })
  343. .then(res => {});
  344. },
  345. imgRemove(arr) {
  346. this.user_info.avatar = arr;
  347. }
  348. }
  349. };
  350. </script>
  351. <style lang="scss">
  352. uni-page-body,
  353. page {
  354. background: #fff;
  355. }
  356. .uni-input {
  357. font-size: 28rpx;
  358. color: #999999;
  359. padding: 10upx 0;
  360. }
  361. .uni-input-input {
  362. width: 80%;
  363. padding: 10upx 0;
  364. }
  365. .user-pic-view {
  366. text-align: center;
  367. }
  368. .user-img-view {
  369. width: 120upx;
  370. height: 120upx;
  371. border-radius: 100%;
  372. margin: 32upx auto;
  373. background: #eee;
  374. }
  375. .user-img-license {
  376. width: 120upx;
  377. height: 120upx;
  378. border-radius: 8upx;
  379. border: 2upx #999999 dashed;
  380. margin: 32upx auto;
  381. background: #eee;
  382. text-align: center;
  383. line-height: 100upx;
  384. color: #666;
  385. font-size: 100rpx;
  386. font-weight: 300;
  387. }
  388. .license-pic {
  389. width: 120upx;
  390. height: 120upx;
  391. }
  392. .user-pic {
  393. width: 120upx;
  394. height: 120upx;
  395. border-radius: 100%;
  396. }
  397. .info-edit-ul {
  398. padding: 25upx 25upx 200upx 25upx;
  399. }
  400. .edit-label {
  401. color: #6a6a6a;
  402. font-size: 24upx;
  403. }
  404. .info-edit-li .edit-val {
  405. padding: 12upx 0 24upx;
  406. font-size: 28upx;
  407. }
  408. .info-edit-li {
  409. position: relative;
  410. border-bottom: 1upx solid #ddd;
  411. padding-top: 24upx;
  412. }
  413. .info-edit-li > input {
  414. margin: 10upx 0;
  415. font-size: 28upx;
  416. width: 80%;
  417. }
  418. .more-icon {
  419. width: 36upx;
  420. height: 36upx;
  421. position: absolute;
  422. top: 50upx;
  423. right: 10upx;
  424. }
  425. .sub-btn {
  426. font-size: 30upx;
  427. text-align: center;
  428. color: #ffffff;
  429. width: 645upx;
  430. height: 72upx;
  431. background: $base-btn-bg;
  432. border-radius: 10rpx;
  433. line-height: 72upx;
  434. margin: 0 auto;
  435. }
  436. .btn-view {
  437. padding: 30upx 0;
  438. position: fixed;
  439. background: #ffffff;
  440. width: 100%;
  441. bottom: 0;
  442. left: 0;
  443. z-index: 9;
  444. box-shadow: 15upx 12upx 42upx 0upx rgba(113, 113, 113, 0.2);
  445. }
  446. .start-icon {
  447. font-size: 24upx;
  448. color: #f53c28;
  449. }
  450. </style>