user.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. <template>
  2. <div class="curPage">
  3. <div class="userInfo">
  4. <van-row
  5. type="flex"
  6. class="imageName"
  7. justify="space-between"
  8. align="center"
  9. >
  10. <div class="userImage">
  11. <userImage
  12. class="about-me__avatar"
  13. :img_url="user_info.imgUrl"
  14. :user_name="user_info.name"
  15. width="1.12rem"
  16. height="1.12rem"
  17. v-if="user_info.imgUrl"
  18. ></userImage>
  19. <div style="background: #26A2FF;border-radius: 50%;overflow: hidden;" v-else>
  20. <userImage
  21. class="about-me__avatar"
  22. :img_url="defaultImgUrl"
  23. user_name="用户"
  24. width="1.12rem"
  25. height="1.12rem"
  26. ></userImage>
  27. </div>
  28. <div class="info">
  29. <span
  30. >{{ user_info.name ? user_info.name : "新用户"
  31. }}<van-icon
  32. name="notes-o"
  33. color="#E1B98B"
  34. style="margin-left: .1rem;"
  35. /></span>
  36. <!-- <p>手机:{{ user_info.tel }}</p> -->
  37. <!-- <p
  38. class="userId"
  39. :aria-label="user_info.id"
  40. @click="copyLink('.userId')"
  41. >
  42. <i class="courseIcon icon-fuzhi"></i>复制身份ID
  43. </p> -->
  44. </div>
  45. </div>
  46. <div class="user_leave">
  47. <van-icon name="gem-o" color="#a66666" />
  48. {{ user_info.marketable ? "经销商" : "学员" }}
  49. </div>
  50. </van-row>
  51. </div>
  52. <div class="user_tabs" v-if="user_info.marketable">
  53. <div class="tabs_content">
  54. <div class="tabsLi" @click="toUrl('/courseTeam/1')">
  55. <van-image
  56. src="static/images/course_team.png"
  57. style="width: .8rem;height: .8rem;"
  58. type="contain"
  59. />
  60. <span>我的团队</span>
  61. </div>
  62. <div class="tabsLi" @click="qropen">
  63. <van-image
  64. src="static/images/course_ewm.png"
  65. style="width: .8rem;height: .8rem;"
  66. type="contain"
  67. />
  68. <span>邀请二维码</span>
  69. </div>
  70. <div class="tabsLi" @click="toUrl('/courseTeam/2')">
  71. <van-image
  72. src="static/images/course_dingdan.png"
  73. style="width: .8rem;height: .8rem;"
  74. type="contain"
  75. />
  76. <span>交易往来</span>
  77. </div>
  78. </div>
  79. </div>
  80. <div class="user_course_tabs" v-if='user_info.marketable'>
  81. <van-tabs v-model="tbsIndex" style="width: 60%;">
  82. <van-tab title="我的推广"></van-tab>
  83. <van-tab title="我的学习"></van-tab>
  84. </van-tabs>
  85. <!-- <div class="tbsL" v-if='user_info.marketable'>
  86. <div class="tbsi" :class="{active:tbsIndex==0}" @click="selectTbs(0)">我的推广</div>
  87. <div class="tbsi" :class="{active:tbsIndex==1}" @click="selectTbs(1)">我的学习</div>
  88. </div> -->
  89. <div class="tbsR" v-if="user_info.marketable" @click="toMoreUrl">
  90. <span>名额变动明细<van-icon name="arrow" /></span>
  91. </div>
  92. </div>
  93. <!-- <van-search
  94. v-model="wxId"
  95. placeholder="请输入wxid替换当前账号"
  96. show-action
  97. style="margin: 0.1rem 0.2rem 0;border-radius: 0.1rem;"
  98. @search="changeUSer"
  99. /> -->
  100. <div
  101. class="courScroll"
  102. :style="{
  103. height: user_info.marketable
  104. ? 'calc(100vh - 5.38rem) !important'
  105. : 'calc(-3.05rem + 100vh) !important'
  106. }"
  107. >
  108. <scroller ref="scroller" :isInitRefresh="false">
  109. <van-loading
  110. v-show="showLoad"
  111. style="margin: 0px auto;position: relative;left: 50%;transform: translateX(-0.25rem);"
  112. />
  113. <div
  114. class="myCourseList"
  115. v-if="user_info.marketable && tbsIndex == 0 && !showLoad"
  116. >
  117. <courseList
  118. :dataList="courseClass.proCourse.courseList"
  119. :showNum="1"
  120. :fixedTitle="courseClass.proCourse.title"
  121. ></courseList>
  122. </div>
  123. <div class="myCourseList" v-if="tbsIndex == 1 && !showLoad">
  124. <courseList
  125. :dataList="courseClass.learnCourse.courseList"
  126. :fixedTitle="courseClass.learnCourse.title"
  127. isNoAd
  128. ></courseList>
  129. </div>
  130. </scroller>
  131. <van-tabbar v-model="active" @change="activeChange">
  132. <van-tabbar-item icon="home-o">首页</van-tabbar-item>
  133. <van-tabbar-item icon="friends-o">我的</van-tabbar-item>
  134. </van-tabbar>
  135. </div>
  136. <van-overlay :show="qrVisible" @click="qrVisible = false">
  137. <div class="wrapper">
  138. <div class="qrContent">
  139. <div class="tit">
  140. 邀请二维码
  141. </div>
  142. <div class="qrcode-wrap" ref="qrCodeUrl"></div>
  143. <div class="btm">
  144. <p>邀请朋友成为经销商,并加入你的团队</p>
  145. </div>
  146. </div>
  147. </div>
  148. </van-overlay>
  149. </div>
  150. </template>
  151. <script>
  152. import Clipboard from "clipboard";
  153. import QRCode from "qrcodejs2";
  154. import courseList from "./components/courseList.vue";
  155. import {setDocumentTitle} from '../../components/vueHashCalendar/utils/util'
  156. import {isWeChatMobile,isWeChatPC,isWeChat} from './utils'
  157. import {
  158. getWxApiToken,
  159. getUSerInfo,
  160. getDealerCourseList,
  161. getUserCourseList
  162. } from "./api";
  163. export default {
  164. name: "courseHome",
  165. components: {
  166. courseList
  167. },
  168. data() {
  169. return {
  170. active:1,
  171. defaultImgUrl:require('../../assets/images/courseUser.png'),
  172. showLoad: false,
  173. tbsIndex: 0,
  174. clipboard: null,
  175. qrVisible: false,
  176. qrcode: null,
  177. qrcodeStatus: false,
  178. isAndroid: this.$getCache("isAndroid"),
  179. user_info: {
  180. imgUrl: "",
  181. id: "0",
  182. name: "用户名",
  183. mobile: "0",
  184. marketable: false
  185. },
  186. page: {
  187. cur: 1,
  188. size: 10,
  189. total: 0
  190. },
  191. courseClass: {
  192. proCourse: {
  193. title: "我推广的课程",
  194. total: 0,
  195. courseList: []
  196. },
  197. learnCourse: {
  198. title: "我学习的课程",
  199. total: 0,
  200. courseList: []
  201. }
  202. },
  203. wxId: "11770"
  204. };
  205. },
  206. created() {
  207. this.init();
  208. console.log(isWeChat()?isWeChatMobile()?'手机微信':isWeChatPC()?'电脑微信':'无法判断':'不是微信')
  209. },
  210. watch: {
  211. $route(to) {
  212. if (to.path == "/courseUser") {
  213. this.init();
  214. }
  215. }
  216. },
  217. methods: {
  218. //底部导航变化
  219. activeChange(){
  220. if(this.active != 1){
  221. this.$router.push('/courseHome');
  222. this.active = 1;
  223. }
  224. },
  225. // 推广/学习标签切换
  226. selectTbs(i) {
  227. if (this.user_info.marketable) {
  228. if (i == 0 && this.tbsIndex != 0) {
  229. this.tbsIndex = 0;
  230. this.showLoad = true;
  231. setTimeout(() => {
  232. this.getDealerCourseList();
  233. }, 1000);
  234. } else if (i == 1 && this.tbsIndex != 1) {
  235. this.tbsIndex = 1;
  236. this.showLoad = true;
  237. setTimeout(() => {
  238. this.getUserCourseList();
  239. }, 1000);
  240. }
  241. }
  242. },
  243. //查看名额变动明细
  244. toMoreUrl() {
  245. // this.$router.push(`/course/adlist`);
  246. this.$router.push(`/course/limitChange`);
  247. },
  248. // 清楚本地存储/测试用
  249. changeUSer() {
  250. localStorage.clear();
  251. this.getUerInfo(this.wxId);
  252. },
  253. // 获取指定用户信息/测试用
  254. getUerInfo(wxid) {
  255. getWxApiToken(wxid).then(token => {
  256. getUSerInfo(token).then(res => {
  257. this.user_info = JSON.parse(localStorage.getItem("wx_user_info"));
  258. if (this.user_info.marketable) {
  259. getDealerCourseList();
  260. } else if (!this.user_info.marketable) {
  261. this.tbsIndex = 1;
  262. }
  263. getUserCourseList();
  264. });
  265. });
  266. },
  267. //获取用户数据
  268. init() {
  269. setDocumentTitle('首页')
  270. this.user_info = JSON.parse(localStorage.getItem("wx_user_info"));
  271. if (this.user_info.marketable) {
  272. this.getDealerCourseList();
  273. } else if (!this.user_info.marketable) {
  274. this.tbsIndex = 1;
  275. }
  276. this.getUserCourseList();
  277. },
  278. //获取经销推广课程列表
  279. getDealerCourseList(done) {
  280. getDealerCourseList().then(res => {
  281. this.courseClass.proCourse.total = res.total;
  282. this.courseClass.proCourse.courseList = res.list;
  283. this.showLoad = false;
  284. if (done) done();
  285. });
  286. },
  287. //获取用户消费的课程列表
  288. getUserCourseList(done) {
  289. getUserCourseList().then(res => {
  290. this.courseClass.learnCourse.total = res.total;
  291. let list = [];
  292. res.list.forEach(item => {
  293. let data = {
  294. subjectName: item.name,
  295. subjectId: item.id,
  296. subjectPrice: item.price,
  297. subjectThumb: item.thumb,
  298. subjectEnable: item.enable,
  299. sectionsNum: item.sectionsNum
  300. };
  301. list.push(data);
  302. });
  303. this.courseClass.learnCourse.courseList = list;
  304. this.showLoad = false;
  305. if (done) done();
  306. });
  307. },
  308. // 打开二维码
  309. qropen() {
  310. this.qrVisible = true;
  311. this.$nextTick(() => {
  312. this.creatQrCode();
  313. });
  314. },
  315. // 创建二维码
  316. creatQrCode() {
  317. if (!this.qrcodeStatus) {
  318. this.qrcode = new QRCode(this.$refs.qrCodeUrl, {
  319. text: `${window.location.href.split("#")[0]}#/courseLogin?pid=${
  320. JSON.parse(localStorage.getItem("wx_user_info")).id
  321. }`, // 需要转换为二维码的内容
  322. width: 200,
  323. height: 200,
  324. colorDark: "#000000",
  325. colorLight: "#ffffff",
  326. correctLevel: QRCode.CorrectLevel.H
  327. });
  328. this.qrcodeStatus = true;
  329. }
  330. },
  331. //复制剪切板
  332. copyLink(event) {
  333. let that = this;
  334. //这里是复制目标的类名
  335. that.clipboard = new Clipboard(event, {
  336. text: function(trigger) {
  337. return trigger.getAttribute("aria-label");
  338. }
  339. });
  340. that.clipboard.on("success", function(e) {
  341. e.clearSelection(); //清除选中的文字的选择状态
  342. that.$toast.success("ID复制成功~");
  343. });
  344. that.clipboard.on("error", function(e) {
  345. console.error(e);
  346. });
  347. },
  348. //跳转内页
  349. toUrl(url, params) {
  350. this.$router.push({
  351. path: url
  352. });
  353. }
  354. }
  355. };
  356. </script>
  357. <style scoped lang="scss">
  358. @import "../../assets/iconfont.css";
  359. * {
  360. margin: 0;
  361. padding: 0;
  362. }
  363. img {
  364. display: block;
  365. }
  366. .curPage {
  367. height: 100%;
  368. position: relative !important;
  369. padding-top: 0.4rem;
  370. background: #f3f2ee;
  371. background: linear-gradient(90deg, #f3f2ee, #e7eff9);
  372. .userInfo {
  373. padding: 0.24rem 0.32rem 0.12rem;
  374. .userImage {
  375. display: flex;
  376. align-items: center;
  377. flex: 1;
  378. .info {
  379. display: flex;
  380. flex-direction: column;
  381. justify-content: center;
  382. margin-left: 0.2rem;
  383. span {
  384. font-size: 0.32rem;
  385. font-weight: 600;
  386. color: #000;
  387. line-height: 2;
  388. display: block;
  389. }
  390. p {
  391. font-size: 0.22rem;
  392. color: #222;
  393. line-height: 1;
  394. display: block;
  395. i {
  396. font-size: 0.22rem;
  397. color: #222;
  398. line-height: 1;
  399. }
  400. }
  401. }
  402. }
  403. .user_leave {
  404. padding: 0.05rem 0.3rem;
  405. font-size: 0.26rem;
  406. font-weight: 550;
  407. color: #a66666;
  408. border: 1px solid #c9c3c0;
  409. border-radius: 0.1rem;
  410. line-height: 1.5;
  411. }
  412. }
  413. .user_tabs {
  414. padding: 0 0.2rem;
  415. margin-top: 0.15rem;
  416. .tabs_content {
  417. box-sizing: border-box;
  418. height: 1.5rem;
  419. padding: 0.1rem 0;
  420. display: flex;
  421. justify-content: space-around;
  422. border-radius: 0.1rem;
  423. background: #fff;
  424. .tabsLi {
  425. // flex: 1;
  426. display: flex;
  427. flex-direction: column;
  428. justify-content: center;
  429. align-items: center;
  430. span {
  431. font-size: 0.24rem;
  432. color: #333;
  433. line-height: 0.3rem;
  434. }
  435. }
  436. }
  437. }
  438. .user_course_tabs {
  439. margin: 0.15rem 0.2rem 0;
  440. display: flex;
  441. justify-content: space-between;
  442. align-items: center;
  443. background-color: #fff;
  444. border-radius: .1rem;
  445. overflow: hidden;
  446. .ctbsL {
  447. width: 2rem;
  448. display: flex;
  449. align-items: center;
  450. }
  451. .tbsL {
  452. width: 60%;
  453. display: flex;
  454. align-items: center;
  455. .tbsi {
  456. padding: 0 0.15rem;
  457. border-radius: 0.25rem;
  458. border: 0.02rem solid #999;
  459. font-size: 0.24rem;
  460. color: #444;
  461. line-height: 0.4rem;
  462. text-align: center;
  463. margin-right: 0.2rem;
  464. &.active {
  465. border: 1px solid rgb(22, 132, 252);
  466. background-color: rgba(38, 162, 255, 0.1);
  467. color: rgb(22, 132, 252);
  468. }
  469. }
  470. }
  471. .tbsR {
  472. display: flex;
  473. align-items: center;
  474. margin-right: .2rem;
  475. span {
  476. font-size: 0.24rem;
  477. color: #333;
  478. line-height: 0.4rem;
  479. }
  480. }
  481. }
  482. .courScroll {
  483. height: calc(100vh - 2.75rem) !important;
  484. position: relative;
  485. .cScroll {
  486. height: 100%;
  487. position: relative !important;
  488. }
  489. .myCourseList {
  490. &:nth-child(2) {
  491. padding-bottom: 0.4rem;
  492. }
  493. padding: 0 0.2rem;
  494. // margin-top: 0.2rem;
  495. }
  496. }
  497. .wrapper {
  498. display: flex;
  499. justify-content: center;
  500. align-items: center;
  501. height: 100vh;
  502. .qrContent {
  503. width: 70%;
  504. border-radius: 0.2rem;
  505. overflow: hidden;
  506. background-color: #FFF;
  507. .btm{
  508. font-size: .23rem;
  509. color: #666;
  510. line-height: .6rem;
  511. text-align: center;
  512. border: 0;
  513. }
  514. .tit {
  515. position: relative;
  516. width: 100%;
  517. text-align: center;
  518. font-size: 0.3rem;
  519. color: #333;
  520. line-height: 0.8rem;
  521. &::after {
  522. content: "X";
  523. position: absolute;
  524. right: 0.2rem;
  525. top: 0.2rem;
  526. font-size: 0.3rem;
  527. line-height: 0.3rem;
  528. }
  529. }
  530. .qrcode-wrap {
  531. padding: 0.2rem .2rem 0;
  532. background-color: #fff;
  533. text-align: center;
  534. display: flex;
  535. justify-content: center;
  536. }
  537. }
  538. }
  539. }
  540. /deep/ .van-search .van-cell {
  541. padding: 0.1rem 0.16rem 0.1rem 0.16rem;
  542. }
  543. /deep/ .van-tabs--line .van-tabs__wrap{
  544. height: .68rem;
  545. }
  546. /deep/ .van-tab--active{
  547. font-weight: 600;
  548. }
  549. </style>