user.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  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 {setWxConfig} from './utils'
  157. import {
  158. getWxApiToken,
  159. getUSerInfo,
  160. getDealerCourseList,
  161. getUserCourseList
  162. } from "./api";
  163. export default {
  164. name: "courseUser",
  165. components: {
  166. courseList
  167. },
  168. data() {
  169. return {
  170. active:1,
  171. defaultImgUrl:require('../../assets/images/headLogo.jpg'),
  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. activated(){
  207. this.init();
  208. if(this.$isWx){
  209. setWxConfig();
  210. }
  211. },
  212. methods: {
  213. //底部导航变化
  214. activeChange(){
  215. if(this.active != 1){
  216. this.$router.push('/courseHome');
  217. this.active = 1;
  218. }
  219. },
  220. // 推广/学习标签切换
  221. selectTbs(i) {
  222. if (this.user_info.marketable) {
  223. if (i == 0 && this.tbsIndex != 0) {
  224. this.tbsIndex = 0;
  225. this.showLoad = true;
  226. setTimeout(() => {
  227. this.getDealerCourseList();
  228. }, 1000);
  229. } else if (i == 1 && this.tbsIndex != 1) {
  230. this.tbsIndex = 1;
  231. this.showLoad = true;
  232. setTimeout(() => {
  233. this.getUserCourseList();
  234. }, 1000);
  235. }
  236. }
  237. },
  238. //查看名额变动明细
  239. toMoreUrl() {
  240. // this.$router.push(`/course/adlist`);
  241. this.$router.push(`/course/limitChange`);
  242. },
  243. // 清楚本地存储/测试用
  244. changeUSer() {
  245. localStorage.clear();
  246. this.getUerInfo(this.wxId);
  247. },
  248. // 获取指定用户信息/测试用
  249. getUerInfo(wxid) {
  250. getWxApiToken(wxid).then(token => {
  251. getUSerInfo(token).then(res => {
  252. this.user_info = JSON.parse(localStorage.getItem("wx_user_info"));
  253. if (this.user_info.marketable) {
  254. getDealerCourseList();
  255. } else if (!this.user_info.marketable) {
  256. this.tbsIndex = 1;
  257. }
  258. getUserCourseList();
  259. });
  260. });
  261. },
  262. //获取用户数据
  263. init() {
  264. this.user_info = JSON.parse(localStorage.getItem("wx_user_info"));
  265. if (this.user_info.marketable) {
  266. this.getDealerCourseList();
  267. } else if (!this.user_info.marketable) {
  268. this.tbsIndex = 1;
  269. }
  270. this.getUserCourseList();
  271. },
  272. //获取经销推广课程列表
  273. getDealerCourseList(done) {
  274. getDealerCourseList().then(res => {
  275. this.courseClass.proCourse.total = res.total;
  276. this.courseClass.proCourse.courseList = res.list;
  277. this.showLoad = false;
  278. if (done) done();
  279. });
  280. },
  281. //获取用户消费的课程列表
  282. getUserCourseList(done) {
  283. getUserCourseList().then(res => {
  284. this.courseClass.learnCourse.total = res.total;
  285. let list = [];
  286. res.list.forEach(item => {
  287. let data = {
  288. subjectName: item.name,
  289. subjectId: item.id,
  290. subjectPrice: item.price,
  291. subjectThumb: item.thumb,
  292. subjectEnable: item.enable,
  293. sectionsNum: item.sectionsNum
  294. };
  295. list.push(data);
  296. });
  297. this.courseClass.learnCourse.courseList = list;
  298. this.showLoad = false;
  299. if (done) done();
  300. });
  301. },
  302. // 打开二维码
  303. qropen() {
  304. this.qrVisible = true;
  305. this.$nextTick(() => {
  306. this.creatQrCode();
  307. });
  308. },
  309. // 创建二维码
  310. creatQrCode() {
  311. if (!this.qrcodeStatus) {
  312. this.qrcode = new QRCode(this.$refs.qrCodeUrl, {
  313. text: `${window.location.href.split("#")[0]}#/courseLogin?pid=${
  314. JSON.parse(localStorage.getItem("wx_user_info")).id
  315. }`, // 需要转换为二维码的内容
  316. width: 200,
  317. height: 200,
  318. colorDark: "#000000",
  319. colorLight: "#ffffff",
  320. correctLevel: QRCode.CorrectLevel.H
  321. });
  322. this.qrcodeStatus = true;
  323. }
  324. },
  325. //复制剪切板
  326. copyLink(event) {
  327. let that = this;
  328. //这里是复制目标的类名
  329. that.clipboard = new Clipboard(event, {
  330. text: function(trigger) {
  331. return trigger.getAttribute("aria-label");
  332. }
  333. });
  334. that.clipboard.on("success", function(e) {
  335. e.clearSelection(); //清除选中的文字的选择状态
  336. that.$toast.success("ID复制成功~");
  337. });
  338. that.clipboard.on("error", function(e) {
  339. console.error(e);
  340. });
  341. },
  342. //跳转内页
  343. toUrl(url, params) {
  344. this.$router.push({
  345. path: url
  346. });
  347. }
  348. }
  349. };
  350. </script>
  351. <style scoped lang="scss">
  352. @import "../../assets/iconfont.css";
  353. * {
  354. margin: 0;
  355. padding: 0;
  356. }
  357. img {
  358. display: block;
  359. }
  360. .curPage {
  361. height: 100%;
  362. position: relative !important;
  363. padding-top: 0.4rem;
  364. background: #f3f2ee;
  365. background: linear-gradient(90deg, #f3f2ee, #e7eff9);
  366. .userInfo {
  367. padding: 0.24rem 0.32rem 0.12rem;
  368. .userImage {
  369. display: flex;
  370. align-items: center;
  371. flex: 1;
  372. .info {
  373. display: flex;
  374. flex-direction: column;
  375. justify-content: center;
  376. margin-left: 0.2rem;
  377. span {
  378. font-size: 0.32rem;
  379. font-weight: 600;
  380. color: #000;
  381. line-height: 2;
  382. display: block;
  383. }
  384. p {
  385. font-size: 0.22rem;
  386. color: #222;
  387. line-height: 1;
  388. display: block;
  389. i {
  390. font-size: 0.22rem;
  391. color: #222;
  392. line-height: 1;
  393. }
  394. }
  395. }
  396. }
  397. .user_leave {
  398. padding: 0.05rem 0.3rem;
  399. font-size: 0.26rem;
  400. font-weight: 550;
  401. color: #a66666;
  402. border: 1px solid #c9c3c0;
  403. border-radius: 0.1rem;
  404. line-height: 1.5;
  405. }
  406. }
  407. .user_tabs {
  408. padding: 0 0.2rem;
  409. margin-top: 0.15rem;
  410. .tabs_content {
  411. box-sizing: border-box;
  412. height: 1.5rem;
  413. padding: 0.1rem 0;
  414. display: flex;
  415. justify-content: space-around;
  416. border-radius: 0.1rem;
  417. background: #fff;
  418. .tabsLi {
  419. // flex: 1;
  420. display: flex;
  421. flex-direction: column;
  422. justify-content: center;
  423. align-items: center;
  424. span {
  425. font-size: 0.24rem;
  426. color: #333;
  427. line-height: 0.3rem;
  428. }
  429. }
  430. }
  431. }
  432. .user_course_tabs {
  433. margin: 0.15rem 0.2rem 0;
  434. display: flex;
  435. justify-content: space-between;
  436. align-items: center;
  437. background-color: #fff;
  438. border-radius: .1rem;
  439. overflow: hidden;
  440. .ctbsL {
  441. width: 2rem;
  442. display: flex;
  443. align-items: center;
  444. }
  445. .tbsL {
  446. width: 60%;
  447. display: flex;
  448. align-items: center;
  449. .tbsi {
  450. padding: 0 0.15rem;
  451. border-radius: 0.25rem;
  452. border: 0.02rem solid #999;
  453. font-size: 0.24rem;
  454. color: #444;
  455. line-height: 0.4rem;
  456. text-align: center;
  457. margin-right: 0.2rem;
  458. &.active {
  459. border: 1px solid rgb(22, 132, 252);
  460. background-color: rgba(38, 162, 255, 0.1);
  461. color: rgb(22, 132, 252);
  462. }
  463. }
  464. }
  465. .tbsR {
  466. display: flex;
  467. align-items: center;
  468. margin-right: .2rem;
  469. span {
  470. font-size: 0.24rem;
  471. color: #333;
  472. line-height: 0.4rem;
  473. }
  474. }
  475. }
  476. .courScroll {
  477. height: calc(100vh - 2.75rem) !important;
  478. position: relative;
  479. .cScroll {
  480. height: 100%;
  481. position: relative !important;
  482. }
  483. .myCourseList {
  484. &:nth-child(2) {
  485. padding-bottom: 0.4rem;
  486. }
  487. padding: 0 0.2rem;
  488. // margin-top: 0.2rem;
  489. }
  490. }
  491. .wrapper {
  492. display: flex;
  493. justify-content: center;
  494. align-items: center;
  495. height: 100vh;
  496. .qrContent {
  497. width: 70%;
  498. border-radius: 0.2rem;
  499. overflow: hidden;
  500. background-color: #FFF;
  501. .btm{
  502. font-size: .23rem;
  503. color: #666;
  504. line-height: .6rem;
  505. text-align: center;
  506. border: 0;
  507. }
  508. .tit {
  509. position: relative;
  510. width: 100%;
  511. text-align: center;
  512. font-size: 0.3rem;
  513. color: #333;
  514. line-height: 0.8rem;
  515. &::after {
  516. content: "X";
  517. position: absolute;
  518. right: 0.2rem;
  519. top: 0.2rem;
  520. font-size: 0.3rem;
  521. line-height: 0.3rem;
  522. }
  523. }
  524. .qrcode-wrap {
  525. padding: 0.2rem .2rem 0;
  526. background-color: #fff;
  527. text-align: center;
  528. display: flex;
  529. justify-content: center;
  530. }
  531. }
  532. }
  533. }
  534. /deep/ .van-search .van-cell {
  535. padding: 0.1rem 0.16rem 0.1rem 0.16rem;
  536. }
  537. /deep/ .van-tabs--line .van-tabs__wrap{
  538. height: .68rem;
  539. }
  540. /deep/ .van-tab--active{
  541. font-weight: 600;
  542. }
  543. </style>