my.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. <template>
  2. <ax-body>
  3. <template #title></template>
  4. <view class="page-background">
  5. <image src="@/static/img/my-bg.svg" mode="widthFix"></image>
  6. </view>
  7. <!-- 主内容 -->
  8. <view class="main">
  9. <!-- 用户信息 -->
  10. <view class="app-flex c-between user-card">
  11. <view class="app-flex middle">
  12. <image src="@/static/img/user-avatar.svg" class="user-avatar"></image>
  13. <view>
  14. <view class="user-name">
  15. <view class="user-name-text">{{ userinfo.nickName ? userinfo.nickName : '匿名' }}</view>
  16. <view class="enterprise-name-card" v-if="userinfo.firmInfoName">{{ userinfo.firmInfoName }}
  17. </view>
  18. </view>
  19. <view class="user-phone" v-if="userinfo.phone">{{ userinfo.phone ? userinfo.phone : '未获取手机' }}
  20. </view>
  21. <button v-if="!userinfo.phone" @getphonenumber="onGetPhoneNumber" open-type="getPhoneNumber"
  22. class="get-phone-number">授权并登录</button>
  23. </view>
  24. </view>
  25. <view class="seting-icon-box" @click="$app.url.goto('/pages/coupons/coupons')">
  26. <image class="img-icon" src="@/static/img/Coupons.png"></image>
  27. <view class="tips-text">优惠券</view>
  28. </view>
  29. </view>
  30. <!-- 统计卡 -->
  31. <view class="statistics-card">
  32. <view class="statistics-title">我的钱包</view>
  33. <view class="statistics-dataInfo">
  34. <view class="dataInfo-left">
  35. <view class="left-text">我的积分</view>
  36. <view class="left-number">{{ userinfo.integralNum }}</view>
  37. </view>
  38. <view class="dataInfo-line"></view>
  39. <view class="dataInfo-left">
  40. <view class="left-text">可抵扣余量</view>
  41. <view class="left-number">{{ userinfo.balance }}</view>
  42. <view class="left-refund-btn" @click="refund">
  43. 退还
  44. </view>
  45. </view>
  46. </view>
  47. <view @click="$app.url.goto('/pages/coupon-buy/coupon-buy')" class="buy">购买充电券</view>
  48. </view>
  49. <!-- 个人中心banner -->
  50. <swiper class="banner" v-if="banners.length > 0" autoplay="true">
  51. <swiper-item v-for="(item, index) in banners" :key="index" @click="$app.url.goto(item.jumpPage)">
  52. <view class="swiper-item">
  53. <image @load="bannerLoadCompleted()" :src="showImg(item.pic)" class="swiper-item-image"
  54. mode="widthFix">
  55. </image>
  56. </view>
  57. </swiper-item>
  58. </swiper>
  59. <!-- 常用工具 -->
  60. <view class="card">
  61. <view class="card-title">常用工具</view>
  62. <view class="act-wrap">
  63. <view class="act-item" @click="$app.url.goto('/pages/recharge-log/recharge-log')">
  64. <image src="@/static/img/my-icon01.svg" class="icon"></image>
  65. <view class="name">购券记录</view>
  66. </view>
  67. <view class="act-item" @click="$app.url.goto('/pages/order/order')">
  68. <image src="@/static/img/my-icon02.svg" class="icon"></image>
  69. <view class="name">我的订单</view>
  70. </view>
  71. <view class="act-item" @click="$app.url.goto('/pages/feedback/feedback')">
  72. <image src="@/static/img/my-icon03.svg" class="icon"></image>
  73. <view class="name">意见反馈</view>
  74. </view>
  75. <view class="act-item" @click="customerService()">
  76. <image src="@/static/img/my-icon04.svg" class="icon"></image>
  77. <view class="name">在线客服</view>
  78. </view>
  79. </view>
  80. </view>
  81. <!-- 更多功能 -->
  82. <view class="card">
  83. <view class="card-title">更多功能</view>
  84. <view class="act-wrap">
  85. <!-- <view class="act-item about">
  86. <image src="@/static/img/logo-small.png" class="icon"></image>
  87. <view class="name">关于我们</view>
  88. </view> -->
  89. <view class="act-item" @click="openPrivacyContract">
  90. <image src="@/static/img/my-icon05.svg" class="icon"></image>
  91. <view class="name">隐私条例</view>
  92. </view>
  93. <!-- firmUserType===1管理员,2普通用户 -->
  94. <view class="act-item" @click="openFilter()" v-if="userinfo.firmUserType === 1">
  95. <image src="@/static/img/my-icon06.svg" class="icon"></image>
  96. <view class="name">邀请员工</view>
  97. </view>
  98. </view>
  99. </view>
  100. </view>
  101. <ax-popup ref="filter" position="" maskType="black" maskEnable maskClose>
  102. <!-- <view class="playbil-box" @click="editPlaybil">
  103. <image class="playbil-bg" :src="playbil_img" mode="widthFix"></image>
  104. <image class="playbil-qrcode" :src="qrCode" mode=""></image>
  105. <view class="enterprise-name">
  106. {{ userinfo.firmInfoName }}
  107. </view>
  108. <view class="enterprise-user">{{ userinfo.nickName ? userinfo.nickName : '匿名用户' }}</view>
  109. </view> -->
  110. <l-painter ref="painter" isCanvasToTempFilePath @success="path = $event">
  111. <l-painter-view css="position:relative;">
  112. <l-painter-image
  113. src="https://hyxhsh.oss-cn-chengdu.aliyuncs.com/63b7c68b71a69169d1b33f92/store/bdb/user/avatar/XVsEVGuCCbNv4aee36cc2f76e7050f62ebad3080ad88.jpg/1.jpg"
  114. css="width:600rpx; height: 1000rpx" />
  115. <l-painter-image :src="qrCode"
  116. css="width:260rpx; height: 260rpx;position: absolute;top:27%;left:29%" />
  117. <l-painter-text
  118. css="position: absolute;top:594rpx;left:50%;transform:translateX(-50%);color:#216ff7;font-size:22rpx;width:60%;text-align:center;"
  119. align="center" :text="userinfo.firmInfoName ? userinfo.firmInfoName : '默认企业'">
  120. </l-painter-text>
  121. <l-painter-text css="position: absolute;top:86%;left:42%;color:#ffffff;font-size:24rpx"
  122. :text="userinfo.nickName ? userinfo.nickName : '匿名用户'">
  123. </l-painter-text>
  124. </l-painter-view>
  125. </l-painter>
  126. <view class="enterprise-tips" @click="savePainter">保存海报</view>
  127. </ax-popup>
  128. <!-- 导航栏 -->
  129. <app-navigation active="my"></app-navigation>
  130. </ax-body>
  131. </template>
  132. <script>
  133. import $config from '@/static/js/config.js';
  134. export default {
  135. data() {
  136. return {
  137. userinfo: {},
  138. playbil_img: 'https://hyxhsh.oss-cn-chengdu.aliyuncs.com/63b7c68b71a69169d1b33f92/store/bdb/user/avatar/XVsEVGuCCbNv4aee36cc2f76e7050f62ebad3080ad88.jpg/1.jpg',
  139. qrCode: null,
  140. banners: [],
  141. }
  142. },
  143. onShow() {
  144. this.getMyAccount()
  145. },
  146. mounted() {
  147. this.getBanners()
  148. },
  149. methods: {
  150. openFilter() {
  151. this.get_qrCode()
  152. },
  153. // 版头加载完成
  154. bannerLoadCompleted() {
  155. this.setListHeight();
  156. },
  157. showImg(img) {
  158. return this.$config.url.request + img
  159. },
  160. getBanners() {
  161. this.$api.base("post", "/userApi/getBanners", {}, {}).then(res => {
  162. this.banners = res.banners
  163. })
  164. },
  165. get_qrCode() {
  166. uni.showLoading()
  167. uni.request({
  168. url: $config.url.request + 'userApi/get-invite-qr',
  169. method: 'GET',
  170. responseType: 'arraybuffer',
  171. header: {
  172. 'content-type': 'application/json',
  173. 'token': uni.getStorageSync($config.keyname.userToken)
  174. },
  175. data: {},
  176. success: (res) => {
  177. console.log(res);
  178. uni.hideLoading()
  179. const arrayBuffer = res.data;
  180. const base64 = wx.arrayBufferToBase64(arrayBuffer);
  181. this.qrCode = 'data:image/png;base64,' + base64;
  182. this.$refs.filter.open();
  183. },
  184. fail(err) {
  185. uni.showToast({
  186. icon: "error",
  187. title: '获取二维码失败' + err
  188. })
  189. }
  190. });
  191. },
  192. savePainter() {
  193. this.$refs.painter.canvasToTempFilePathSync({
  194. fileType: "png",
  195. // 如果返回的是base64是无法使用 saveImageToPhotosAlbum,需要设置 pathType为url
  196. pathType: 'url',
  197. quality: 1,
  198. success: (res) => {
  199. console.log(res.tempFilePath);
  200. uni.showShareImageMenu({
  201. path: res.tempFilePath,
  202. success: () => {
  203. console.log('分享成功');
  204. },
  205. fail: (err) => {
  206. console.error('分享失败', err);
  207. }
  208. });
  209. },
  210. });
  211. },
  212. refund() {
  213. this.$app.popup.confirm("退款按照购券记录进行逐笔退款,可能产生多笔退款到账记录,请注意查收。", "退款说明").then(confirm => {
  214. if (confirm) {
  215. this.$api.base("post", '/orderApi/refund', {}).then(res => {
  216. if (res.code == 0) {
  217. this.$app.popup.alert('退款成功!').then(() => {
  218. this.getMyAccount()
  219. });
  220. } else {
  221. this.$app.popup.alert(res.msg);
  222. }
  223. });
  224. }
  225. });;
  226. },
  227. openPrivacyContract() {
  228. uni.openPrivacyContract();
  229. },
  230. // 打开客服
  231. customerService() {
  232. const cs = this.$config.customerService;
  233. this.$app.act.customerService(cs.id, cs.url).catch(err => {
  234. console.log(err);
  235. this.$app.popup.alert('客服中心失联啦,请联系管理员!');
  236. });
  237. },
  238. getMyAccount() {
  239. // let channelUrl = 'http://192.168.110.241:9120/zs/channel/admin/'
  240. let channelUrl = 'https://channel-api.zonelife.cn/zs/channel/admin/'
  241. this.$api.base("get", "/applet/v1/user/getUserInfo", {}, {
  242. error: false
  243. }).then(res => {
  244. console.log(res);
  245. this.userinfo = res.data
  246. this.$app.storage.set('USER_INFO', res.data);
  247. // 识别用户是否通过分销码进入小程序
  248. if (uni.getStorageSync('ADMIN_USERID')) {
  249. uni.request({
  250. url: channelUrl + 'ums/umsAdminUser/distributionBindUser',
  251. method: 'POST',
  252. header: {
  253. 'content-type': 'application/json'
  254. },
  255. data: {
  256. userId: uni.getStorageSync('USER_INFO').id,
  257. adminUserId: parseInt(uni.getStorageSync('ADMIN_USERID')),
  258. },
  259. success: (res) => {
  260. setTimeout(() => {
  261. this.$app.storage.remove('ADMIN_USERID')
  262. }, 500)
  263. },
  264. fail(err) {
  265. console.log(err, '----错误信息');
  266. }
  267. });
  268. }
  269. })
  270. },
  271. get_firmId() {
  272. if (this.$app.storage.get('FRIM_ID')) {
  273. this.$api.base("post", "/userApi/add-firm-user?firmId=" + parseInt(this.$app.storage.get(
  274. 'FRIM_ID')), {}, {
  275. error: false
  276. }).then(res => {
  277. this.$app.popup.alert(res.msg);
  278. setTimeout(() => {
  279. this.$app.storage.remove('FRIM_ID')
  280. }, 500)
  281. }).catch(err => {
  282. setTimeout(() => {
  283. this.$app.storage.remove('FRIM_ID')
  284. }, 500)
  285. })
  286. }
  287. },
  288. onGetPhoneNumber(e) {
  289. uni.login({
  290. provider: 'weixin',
  291. success: (result) => {
  292. console.log(result, '微信登录');
  293. if (result.code) {
  294. if (e.detail.code) {
  295. this.$api.base("post", '/api/v1/auth/wx/miniapp/phone-code-login', {
  296. code: result.code,
  297. phoneCode: e.detail.code
  298. }).then(res => {
  299. console.log(res);
  300. uni.setStorageSync($config.keyname.accessToken, res?.data?.accessToken);
  301. uni.setStorageSync($config.keyname.refreshToken, res?.data?.refreshToken);
  302. this.$app.storage.set('USER_INFO', res.data);
  303. this.getMyAccount();
  304. this.get_firmId()
  305. });
  306. }
  307. }
  308. },
  309. fail: (error) => { }
  310. })
  311. },
  312. }
  313. }
  314. </script>
  315. <style scoped>
  316. @import url("my.css");
  317. .refund_btn {
  318. position: absolute;
  319. font-size: 14px;
  320. color: #fff;
  321. background-color: #3EB6F8;
  322. padding: 2px 8px;
  323. border-radius: 10px 0 0 10px;
  324. bottom: 5px;
  325. right: 0;
  326. z-index: 99;
  327. }
  328. </style>