my.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  1. <template>
  2. <view class="user" hover-class="navigator-hover" @click="popupShow = true">
  3. <view class="profile-photo">
  4. <up-image :show-loading="true" :src="user.profilePhoto" width="120rpx" height="120rpx" />
  5. </view>
  6. <view class="user-info">
  7. <view class="user-name">{{ user.name }}</view>
  8. <view class="user-phone">{{ user.phonenumber }}</view>
  9. </view>
  10. <view class="iconfont icon-shezhi" />
  11. </view>
  12. <view class="assets">
  13. 我的资产
  14. </view>
  15. <view class="assets-list">
  16. <view v-if="!assetsList.length" style="padding: 30rpx 0;">
  17. <up-empty mode="car" text=" " />
  18. </view>
  19. <view v-else>
  20. <view class="item" v-for="item in assetsList" :key="item.itemid" @click="perviewImgs(item.attinfos)">
  21. <view class="image-box">
  22. <up-image :show-loading="true" :src="item.cover" width="80px" height="80px" />
  23. <view class="tag" :style="{
  24. background: item.isUnderWarranty ? '#27D8B4' : '#E14154',
  25. }">
  26. {{ item.isUnderWarranty ? '在' : '过' }}保
  27. </view>
  28. </view>
  29. <view class="content">
  30. <view class="row">
  31. <text class="label">
  32. 产品名称
  33. </text>
  34. {{ item.itemname || ' --' }}
  35. </view>
  36. <view class="row">
  37. <text class="label">
  38. 产品型号
  39. </text>
  40. {{ item.model || ' --' }}
  41. </view>
  42. <view class="row">
  43. <text class="label">
  44. 序列号
  45. </text>
  46. {{ item.sku || ' --' }}
  47. </view>
  48. <view class="row">
  49. <text class="label">
  50. 保修卡号
  51. </text>
  52. {{ item.cardno || ' --' }}
  53. </view>
  54. <view class="row">
  55. <text class="label">
  56. 保修期限
  57. </text>
  58. {{ item.begdate ? item.begdate + '至' + item.enddate : ' --' }}
  59. </view>
  60. </view>
  61. </view>
  62. </view>
  63. </view>
  64. <up-popup :show="popupShow" mode="right" :customStyle="{
  65. width: '80vw',
  66. padding: '0 20rpx',
  67. background: '#F7F7FF'
  68. }" zIndex="99" @close="close" @open="open">
  69. <view class="change-user">
  70. <view class="title">
  71. 账号信息
  72. </view>
  73. <view class="row" v-show="headportraitLoading">
  74. <view class="label">
  75. 点击更换头像
  76. </view>
  77. <view class="value">
  78. <view class="profilePhoto">
  79. <up-image :show-loading="true" :src="user.profilePhoto" width="80rpx" height="80rpx" />
  80. <view class="loading">
  81. <up-loading-icon mode="semicircle" />
  82. </view>
  83. </view>
  84. <view class="iconfont icon-a-wodetiaozhuan" />
  85. </view>
  86. </view>
  87. <view v-show="!headportraitLoading">
  88. <My_upload ref="upload" custom maxCount="1" @uploadCallback="uploadCallback"
  89. @startUploading="startUploading">
  90. <view class="row" style="width: calc(80vw);" hover-class="navigator-hover">
  91. <view class="label">
  92. 点击更换头像
  93. </view>
  94. <view class="value">
  95. <view class="profilePhoto">
  96. <up-image :show-loading="true" :src="user.profilePhoto" width="80rpx" height="80rpx" />
  97. </view>
  98. <view class="iconfont icon-a-wodetiaozhuan" />
  99. </view>
  100. </view>
  101. </My_upload>
  102. </view>
  103. <view class="row" hover-class="navigator-hover" @click="modalShow = true">
  104. <view class="label">
  105. 用户昵称
  106. </view>
  107. <view class="value">
  108. {{ user.name }}
  109. <view class="iconfont icon-a-wodetiaozhuan" />
  110. </view>
  111. </view>
  112. <view class="row">
  113. <view class="label">
  114. 手机号码
  115. </view>
  116. <view class="value">
  117. {{ user.phonenumber }}
  118. </view>
  119. </view>
  120. <view class="but">
  121. <up-button type="primary" shape="circle" size="large" color="#3874F6" text="退出登录" @tap="logOut" />
  122. </view>
  123. </view>
  124. </up-popup>
  125. <up-modal :show="modalShow" title="修改昵称" showCancelButton @confirm="confirm" @cancel="modalShow = false"
  126. ref="uModal" :asyncClose="true">
  127. <up-input :placeholder="user.name" border="surround" v-model="userName"></up-input>
  128. </up-modal>
  129. </template>
  130. <script setup>
  131. import { ref, reactive, getCurrentInstance } from 'vue'
  132. const { $Http } = getCurrentInstance().proxy;
  133. import { onLoad, onShow } from '@dcloudio/uni-app';
  134. let user = reactive({
  135. name: '',
  136. phonenumber: '',
  137. profilePhoto: "",
  138. attinfos: []
  139. });
  140. onLoad(() => {
  141. const userInfo = uni.getStorageSync('WuserMsg')
  142. user.name = userInfo.name;
  143. user.phonenumber = userInfo.phonenumber;
  144. user.attinfos = userInfo.attinfos;
  145. user.profilePhoto = userInfo.profilePhoto || '/static/image/user.png';
  146. });
  147. function getUserInfo() {
  148. getUserMsg()
  149. getProperty()
  150. }
  151. let popupShow = ref(false),
  152. headportraitLoading = ref(false);
  153. function close() {
  154. popupShow.value = false
  155. }
  156. let uModal = ref(null),
  157. modalShow = ref(false),
  158. userName = ref('');
  159. function confirm() {
  160. console.log('修改昵称', userName.value);
  161. if (userName.value.trim() == '') {
  162. modalShow.value = false;
  163. return uni.showToast({
  164. title: '昵称不能为空',
  165. icon: 'none'
  166. })
  167. }
  168. $Http.basic({
  169. "classname": "common.usercenter.usercenter",
  170. "method": "updateUserMsg",
  171. "content": {
  172. "name": userName.value,
  173. "phonenumber": user.phonenumber,
  174. }
  175. }).then(res => {
  176. console.log(res)
  177. uni.showToast({
  178. title: res.code == 1 ? '修改成功' : res.msg,
  179. icon: 'none'
  180. })
  181. modalShow.value = false;
  182. if (res.code == 1) {
  183. userName.value = '';
  184. getUserMsg();
  185. }
  186. })
  187. }
  188. // 更换头像
  189. let upload = ref(null);
  190. function startUploading(e) {
  191. headportraitLoading.value = true;
  192. }
  193. function uploadCallback({ attachmentids, fileList }) {
  194. if (fileList.pop().usetype == 'headportrait') return;
  195. $Http.basic({
  196. "classname": "system.attachment.Attachment",
  197. "method": "createFileLink",
  198. content: {
  199. ownertable: "sys_users",
  200. ownerid: uni.getStorageSync('WuserMsg').userid,
  201. usetype: 'headportrait',
  202. attachmentids,
  203. siteid: uni.getStorageSync("WuserMsg").siteid
  204. }
  205. }).then(res => {
  206. console.log('跟进记录绑定附件', res)
  207. if (res.code != '1') return uni.showToast({
  208. title: res.msg,
  209. icon: "none"
  210. })
  211. upload.value.deleteFile(user.attinfos.filter(v => v.usetype == 'headportrait')).then(res1 => {
  212. if (res1) {
  213. getUserMsg();
  214. setTimeout(() => {
  215. uni.showToast({
  216. title: '头像更换成功',
  217. icon: 'none'
  218. });
  219. }, 100);
  220. }
  221. })
  222. })
  223. }
  224. function getUserMsg() {
  225. $Http.basic({
  226. "classname": "common.usercenter.usercenter",
  227. "method": "queryUserMsg",
  228. "content": { "nocache": true }
  229. }).then(res => {
  230. console.log("获取用户信息", res);
  231. if (res.code == 1) {
  232. user.name = res.data.name;
  233. user.phonenumber = res.data.phonenumber;
  234. user.attinfos = res.data.attinfos;
  235. headportraitLoading.value = false;
  236. const headportrait = res.data.attinfos.find(v => v.usetype == 'headportrait');
  237. user.profilePhoto = headportrait ? $Http.getSpecifiedImage(headportrait) : user.profilePhoto;
  238. const WuserMsg = uni.getStorageSync('WuserMsg')
  239. uni.setStorageSync('WuserMsg', Object.assign(WuserMsg, user))
  240. }
  241. })
  242. }
  243. let assetsList = ref([]);
  244. function perviewImgs(imgs) {
  245. wx.previewImage({
  246. urls: imgs.filter(v => isImage(v.postfix)).map(item => item.url),
  247. current: 0,
  248. })
  249. }
  250. function isImage(postfix) {
  251. const imageTypes = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp'];
  252. return imageTypes.includes(postfix.toLowerCase());
  253. }
  254. function getProperty(count = 0) {
  255. let sa_customersid = uni.getStorageSync('WuserRecord').sa_customersid || 0;
  256. console.log("sa_customersid", sa_customersid)
  257. if (sa_customersid) {
  258. $Http.basic({
  259. id: 2025082115363003,
  260. content: {
  261. sa_customersid,
  262. pageSize: 9999
  263. }
  264. }).then(res => {
  265. console.log('个人资产', res);
  266. if (res.code == 1) assetsList.value = res.data.map(v => {
  267. //判断是否过保 当前的时间是否在 v.begdate 与 v.enddate 的之间
  268. v.cover = v.attinfos.length ? $Http.getSpecifiedImage(v.attinfos[0]) : ''
  269. v.isUnderWarranty = new Date() >= new Date(v.begdate) && new Date() <= new Date(v.enddate);
  270. return v
  271. });
  272. })
  273. } else {
  274. if (count == 5) return;
  275. setTimeout(() => {
  276. getProperty(count + 1);
  277. }, 500);
  278. }
  279. }
  280. function logOut() {
  281. console.log('退出登录');
  282. uni.showModal({
  283. title: '提示',
  284. content: '是否确定退出登录?',
  285. success: function ({ confirm }) {
  286. if (confirm) {
  287. $Http.logout();
  288. uni.removeStorageSync('WuserMsg');
  289. uni.removeStorageSync('WuserRecord');
  290. uni.reLaunch({
  291. url: '/pages/login/login',
  292. success: () => {
  293. uni.showToast({
  294. title: '退出登录成功',
  295. icon: 'none'
  296. });
  297. }
  298. });
  299. }
  300. }
  301. });
  302. }
  303. //暴露方法
  304. defineExpose({
  305. getUserInfo
  306. });
  307. </script>
  308. <style lang="less" scoped>
  309. .user {
  310. display: flex;
  311. align-items: center;
  312. width: 100%;
  313. background-color: #fff;
  314. box-sizing: border-box;
  315. padding: 40rpx;
  316. .profile-photo {
  317. width: 120rpx;
  318. height: 120rpx;
  319. border-radius: 50%;
  320. overflow: hidden;
  321. }
  322. .user-info {
  323. flex: 1;
  324. margin-left: 40rpx;
  325. padding-top: 10rpx;
  326. .user-name {
  327. line-height: 42rpx;
  328. font-family: Microsoft YaHei, Microsoft YaHei;
  329. font-size: 32rpx;
  330. color: #333333;
  331. }
  332. .user-phone {
  333. line-height: 38rpx;
  334. font-family: Microsoft YaHei, Microsoft YaHei;
  335. font-size: 28rpx;
  336. color: #999999;
  337. margin-top: 20rpx;
  338. }
  339. }
  340. }
  341. .assets,
  342. .assets-list {
  343. width: 95%;
  344. margin: 20rpx auto 0;
  345. background: #fff;
  346. border-radius: 8rpx 8rpx 0 0;
  347. padding: 20rpx 30rpx;
  348. box-sizing: border-box;
  349. .item {
  350. display: flex;
  351. width: 100%;
  352. box-shadow: 0rpx 4rpx 16rpx 2rpx rgba(150, 157, 165, 0.16);
  353. border-radius: 10rpx;
  354. box-sizing: border-box;
  355. padding: 20rpx 30rpx;
  356. overflow: hidden;
  357. margin-bottom: 20rpx;
  358. .image-box {
  359. position: relative;
  360. .tag {
  361. position: absolute;
  362. left: 0;
  363. top: 0;
  364. padding: 4rpx 14rpx;
  365. padding-right: 20rpx;
  366. text-align: center;
  367. background: red;
  368. font-size: 22rpx;
  369. color: #fff;
  370. border-radius: 0 0 8rpx 0;
  371. }
  372. }
  373. .content {
  374. margin-left: 20rpx;
  375. .row {
  376. display: flex;
  377. line-height: 32rpx;
  378. font-family: Microsoft YaHei, Microsoft YaHei;
  379. font-size: 24rpx;
  380. margin-top: 8rpx;
  381. .label {
  382. color: #666;
  383. flex-shrink: 0;
  384. }
  385. .label::after {
  386. content: ':';
  387. }
  388. }
  389. }
  390. }
  391. }
  392. .assets-list {
  393. margin-top: 0;
  394. border-radius: 0 0 8rpx 8rpx;
  395. border-top: 1px solid #333;
  396. }
  397. .change-user {
  398. position: relative;
  399. padding-top: 55px;
  400. box-sizing: border-box;
  401. height: 100%;
  402. .title {
  403. font-size: 28rpx;
  404. color: #333;
  405. margin-bottom: 30rpx;
  406. padding-left: 20rpx;
  407. }
  408. .row {
  409. width: 100%;
  410. display: flex;
  411. align-items: center;
  412. justify-content: space-between;
  413. background: #fff;
  414. padding: 20rpx 30rpx;
  415. border-radius: 16rpx;
  416. box-sizing: border-box;
  417. margin-bottom: 20rpx;
  418. .label {
  419. font-size: 28rpx;
  420. color: #666;
  421. flex-shrink: 0;
  422. margin-right: 20rpx;
  423. }
  424. .value {
  425. display: flex;
  426. align-items: center;
  427. .profilePhoto {
  428. position: relative;
  429. width: 80rpx;
  430. height: 80rpx;
  431. border-radius: 50%;
  432. overflow: hidden;
  433. .loading {
  434. position: absolute;
  435. top: 0;
  436. left: 0;
  437. width: 100%;
  438. height: 100%;
  439. display: flex;
  440. align-items: center;
  441. justify-content: center;
  442. background: rgba(0, 0, 0, 0.09);
  443. z-index: 1;
  444. }
  445. }
  446. .iconfont {
  447. font-size: 28rpx;
  448. color: #999;
  449. margin-top: 5rpx;
  450. }
  451. }
  452. }
  453. .but {
  454. width: 100%;
  455. position: absolute;
  456. bottom: 130rpx;
  457. }
  458. }
  459. </style>