my.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  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 : '未获取手机' }}</view>
  20. <button v-if="!userinfo.phone" @getphonenumber="onGetPhoneNumber" open-type="getPhoneNumber"
  21. class="get-phone-number">授权并登录</button>
  22. </view>
  23. </view>
  24. <view class="seting-icon-box" @click="$app.url.goto('/pages/coupons/coupons')">
  25. <image class="img-icon" src="@/static/img/Coupons.png"></image>
  26. <view class="tips-text">优惠券</view>
  27. </view>
  28. </view>
  29. <!-- 统计卡 -->
  30. <view class="app-flex c-between">
  31. <view class="sta-card">
  32. <view class="value">{{ userinfo.integralNum }}</view>
  33. <view class="name">我的积分</view>
  34. <image src="@/static/img/my-sta-bg01.png" mode="heightFix" class="bg"></image>
  35. </view>
  36. <view class="sta-card">
  37. <view class="value">{{ userinfo.params.balance }}</view>
  38. <view class="name">可抵扣余量</view>
  39. <image src="@/static/img/my-sta-bg03.png" mode="heightFix" class="bg"></image>
  40. <view class="refund_btn" @click="refund">
  41. 退还
  42. </view>
  43. </view>
  44. </view>
  45. <view @click="$app.url.goto('/pages/coupon-buy/coupon-buy')" class="buy">购买充电券</view>
  46. <!-- 常用工具 -->
  47. <view class="card">
  48. <view class="card-title">常用工具</view>
  49. <view class="act-wrap">
  50. <view class="act-item" @click="$app.url.goto('/pages/recharge-log/recharge-log')">
  51. <image src="@/static/img/my-icon01.svg" class="icon"></image>
  52. <view class="name">购券记录</view>
  53. </view>
  54. <view class="act-item" @click="$app.url.goto('/pages/order/order')">
  55. <image src="@/static/img/my-icon02.svg" class="icon"></image>
  56. <view class="name">我的订单</view>
  57. </view>
  58. <view class="act-item" @click="$app.url.goto('/pages/feedback/feedback')">
  59. <image src="@/static/img/my-icon03.svg" class="icon"></image>
  60. <view class="name">意见反馈</view>
  61. </view>
  62. <view class="act-item" @click="customerService()">
  63. <image src="@/static/img/my-icon04.svg" class="icon"></image>
  64. <view class="name">在线客服</view>
  65. </view>
  66. </view>
  67. </view>
  68. <!-- 更多功能 -->
  69. <view class="card">
  70. <view class="card-title">更多功能</view>
  71. <view class="act-wrap">
  72. <!-- <view class="act-item about">
  73. <image src="@/static/img/logo-small.png" class="icon"></image>
  74. <view class="name">关于我们</view>
  75. </view> -->
  76. <view class="act-item" @click="openPrivacyContract">
  77. <image src="@/static/img/my-icon05.svg" class="icon"></image>
  78. <view class="name">隐私条例</view>
  79. </view>
  80. <!-- firmUserType===1管理员,2普通用户 -->
  81. <view class="act-item" @click="openFilter()" v-if="userinfo.firmUserType === 1">
  82. <image src="@/static/img/my-icon06.svg" class="icon"></image>
  83. <view class="name">邀请员工</view>
  84. </view>
  85. </view>
  86. </view>
  87. </view>
  88. <ax-popup ref="filter" position="" maskType="black" maskEnable maskClose>
  89. <view class="playbil-box" @click="editPlaybil">
  90. <image class="playbil-bg" :src="playbil_img" mode="widthFix"></image>
  91. <image class="playbil-qrcode" :src="qrCode" mode=""></image>
  92. <view class="enterprise-name">
  93. {{ userinfo.firmInfoName }}
  94. </view>
  95. <view class="enterprise-user">{{ userinfo.nickName ? userinfo.nickName : '匿名用户' }}</view>
  96. <view class="enterprise-tips">*点击图片进行分享或保存</view>
  97. </view>
  98. </ax-popup>
  99. <r-canvas ref="rCanvas"></r-canvas>
  100. <!-- 导航栏 -->
  101. <app-navigation active="my"></app-navigation>
  102. </ax-body>
  103. </template>
  104. <script>
  105. import rCanvas from "@/components/r-canvas/r-canvas.vue"
  106. import $config from '@/static/js/config.js';
  107. export default {
  108. data() {
  109. return {
  110. userinfo: {},
  111. playbil_img: 'https://hyxhsh.oss-cn-chengdu.aliyuncs.com/63b7c68b71a69169d1b33f92/store/bdb/user/avatar/XVsEVGuCCbNv4aee36cc2f76e7050f62ebad3080ad88.jpg/1.jpg',
  112. qrCode: null,
  113. }
  114. },
  115. onShow() {
  116. this.getMyAccount()
  117. },
  118. mounted() { },
  119. methods: {
  120. openFilter() {
  121. this.$refs.filter.open();
  122. this.get_qrCode()
  123. },
  124. get_qrCode() {
  125. uni.showLoading()
  126. uni.request({
  127. url: $config.url.request + 'userApi/get-invite-qr',
  128. method: 'GET',
  129. responseType: 'arraybuffer',
  130. header: {
  131. 'content-type': 'application/json',
  132. 'token': uni.getStorageSync($config.keyname.userToken)
  133. },
  134. data: {},
  135. success: (res) => {
  136. console.log(res);
  137. uni.hideLoading()
  138. const arrayBuffer = res.data;
  139. const base64 = wx.arrayBufferToBase64(arrayBuffer);
  140. this.qrCode = 'data:image/png;base64,' + base64;
  141. },
  142. fail(err) {
  143. uni.showToast({
  144. icon: "error",
  145. title: '获取二维码失败' + err
  146. })
  147. }
  148. });
  149. },
  150. // 单独下载二维码
  151. // downloadQRCode() {
  152. // const qrCodeUrl = this.qrCode; // base64 图片数据
  153. // // 将 base64 转换为本地文件
  154. // const fsm = uni.getFileSystemManager();
  155. // const fileName = Date.now() + '.png';
  156. // const filePath = uni.env.USER_DATA_PATH + '/' + fileName;
  157. // fsm.writeFile({
  158. // filePath: filePath,
  159. // data: qrCodeUrl.slice(22), // 去掉 "data:image/png;base64," 前缀
  160. // encoding: 'base64',
  161. // success: () => {
  162. // // 保存到相册
  163. // uni.saveImageToPhotosAlbum({
  164. // filePath: filePath,
  165. // success: () => {
  166. // uni.showToast({
  167. // title: '保存成功',
  168. // icon: 'success'
  169. // });
  170. // },
  171. // fail: (err) => {
  172. // console.error('保存失败', err);
  173. // uni.showToast({
  174. // title: '保存失败',
  175. // icon: 'none'
  176. // });
  177. // }
  178. // });
  179. // },
  180. // fail: (err) => {
  181. // console.error('写入文件失败', err);
  182. // uni.showToast({
  183. // title: '下载失败',
  184. // icon: 'none'
  185. // });
  186. // }
  187. // });
  188. // },
  189. // 操作图片
  190. editPlaybil() {
  191. // console.log(this.$refs.filter);
  192. this.get_downloadImg()
  193. },
  194. async get_downloadImg() {
  195. uni.showLoading()
  196. this.$nextTick(async () => {
  197. await this.$refs.rCanvas.init({
  198. canvas_id: "rCanvas"
  199. })
  200. await this.$refs.rCanvas.setCanvasWidth(300)
  201. await this.$refs.rCanvas.setCanvasHeight(515)
  202. // 背景卡片
  203. await this.$refs.rCanvas.drawImage({
  204. url: this.playbil_img,
  205. x: 0,
  206. y: 30,
  207. w: 300,
  208. h: 515
  209. }).catch(err_msg => {
  210. uni.showToast({
  211. title: err_msg,
  212. icon: "none"
  213. })
  214. })
  215. // 二维码
  216. await this.$refs.rCanvas.drawImage({
  217. url: this.qrCode,
  218. x: 85,
  219. y: 176,
  220. w: 130,
  221. h: 130
  222. }).catch(err_msg => {
  223. uni.showToast({
  224. title: err_msg,
  225. icon: "none"
  226. })
  227. })
  228. //文字
  229. await this.$refs.rCanvas.drawText({
  230. text: this.userinfo.firmInfoName ? this.userinfo.firmInfoName : '默认企业',
  231. max_width: 0,
  232. x: 56,
  233. y: 348,
  234. font_color: "#216ff7",
  235. font_size: 10
  236. }).catch(err_msg => {
  237. uni.showToast({
  238. title: err_msg,
  239. icon: "none"
  240. })
  241. })
  242. await this.$refs.rCanvas.drawText({
  243. text: this.userinfo.nickName ? this.userinfo.nickName : '匿名用户',
  244. max_width: 0,
  245. x: 122,
  246. y: 486,
  247. font_color: "#ffffff",
  248. font_size: 12
  249. }).catch(err_msg => {
  250. uni.showToast({
  251. title: err_msg,
  252. icon: "none"
  253. })
  254. })
  255. // 生成海报
  256. await this.$refs.rCanvas.draw((res) => {
  257. //res.tempFilePath:生成成功,返回base64图片
  258. uni.hideLoading()
  259. uni.showShareImageMenu({
  260. path: res.tempFilePath,
  261. success: (res) => console.log('分享成功', res),
  262. fail: (err) => console.error('分享失败', err),
  263. });
  264. // this.$refs.rCanvas.saveImage(res.tempFilePath)
  265. })
  266. })
  267. },
  268. refund() {
  269. this.$app.popup.confirm("退款按照购券记录进行逐笔退款,可能产生多笔退款到账记录,请注意查收。", "退款说明").then(confirm => {
  270. if (confirm) {
  271. this.$api.base("post", '/orderApi/refund', {}).then(res => {
  272. if (res.code == 0) {
  273. this.$app.popup.alert('退款成功!').then(() => {
  274. this.getMyAccount()
  275. });
  276. } else {
  277. this.$app.popup.alert(res.msg);
  278. }
  279. });
  280. }
  281. });;
  282. },
  283. openPrivacyContract() {
  284. uni.openPrivacyContract();
  285. },
  286. // 打开客服
  287. customerService() {
  288. const cs = this.$config.customerService;
  289. this.$app.act.customerService(cs.id, cs.url).catch(err => {
  290. console.log(err);
  291. this.$app.popup.alert('客服中心失联啦,请联系管理员!');
  292. });
  293. },
  294. getMyAccount() {
  295. // let channelUrl = 'http://192.168.110.241:9120/zs/channel/admin/'
  296. let channelUrl = 'https://channel-api.zonelife.cn/zs/channel/admin/'
  297. this.$api.base("post", "/userApi/getUserAccount", {}, { error: false }).then(res => {
  298. this.userinfo = res.accountInfo
  299. this.$app.storage.set('USER_INFO', res.accountInfo);
  300. // 识别用户是否通过分销码进入小程序
  301. if (uni.getStorageSync('ADMIN_USERID')) {
  302. uni.request({
  303. url: channelUrl + 'ums/umsAdminUser/distributionBindUser',
  304. method: 'POST',
  305. header: {
  306. 'content-type': 'application/json'
  307. },
  308. data: {
  309. userId: uni.getStorageSync('USER_INFO').id,
  310. adminUserId: parseInt(uni.getStorageSync('ADMIN_USERID')),
  311. },
  312. success: (res) => {
  313. setTimeout(() => {
  314. this.$app.storage.remove('ADMIN_USERID')
  315. }, 500)
  316. },
  317. fail(err) {
  318. console.log(err, '----错误信息');
  319. }
  320. });
  321. }
  322. })
  323. },
  324. get_firmId() {
  325. if (this.$app.storage.get('FRIM_ID')) {
  326. this.$api.base("post", "/userApi/add-firm-user?firmId=" + parseInt(this.$app.storage.get('FRIM_ID')), {}, {
  327. error: false
  328. }).then(res => {
  329. this.$app.popup.alert(res.msg);
  330. setTimeout(() => {
  331. this.$app.storage.remove('FRIM_ID')
  332. }, 500)
  333. }).catch(err => {
  334. setTimeout(() => {
  335. this.$app.storage.remove('FRIM_ID')
  336. }, 500)
  337. })
  338. }
  339. },
  340. onGetPhoneNumber(e) {
  341. if (e.detail.code) {
  342. this.$api.base("post", '/userApi/getPhone', {
  343. code: e.detail.code
  344. }).then(res => {
  345. this.$app.storage.set('USER_INFO', res.userInfo);
  346. this.getMyAccount();
  347. this.get_firmId()
  348. });
  349. }
  350. },
  351. }
  352. }
  353. </script>
  354. <style scoped>
  355. @import url("my.css");
  356. .refund_btn {
  357. position: absolute;
  358. font-size: 14px;
  359. color: #fff;
  360. background-color: #3EB6F8;
  361. padding: 2px 8px;
  362. border-radius: 10px 0 0 10px;
  363. bottom: 5px;
  364. right: 0;
  365. z-index: 99;
  366. }
  367. </style>