my.vue 9.9 KB

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