home.vue 12 KB

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