courseAdDeal.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. <template>
  2. <div class="page">
  3. <van-nav-bar
  4. :title="title"
  5. left-text="返回"
  6. left-arrow
  7. @click-left="onClickLeft"
  8. ></van-nav-bar>
  9. <div id="linkCode" style="display: none;" :data-clipboard-text="giveLink">
  10. {{ giveLink }}
  11. </div>
  12. <div class="courseContent">
  13. <scroller
  14. ref="recordScroller"
  15. :on-infinite="getMoreList"
  16. :list="recordList"
  17. noDataText="没有更多..."
  18. >
  19. <courseList :dataList="courseInfo" :showNum="2"></courseList>
  20. <div class="record">
  21. <p>名额变动明细</p>
  22. <div class="recordList">
  23. <div
  24. class="recordLi"
  25. v-for="(item, index) in recordList"
  26. :key="index"
  27. >
  28. <div class="flex-name-num">
  29. <p>{{ item.subjectName }}</p>
  30. <span
  31. :style="{
  32. color: Number(item.amount) > 0 ? '#26A2FF' : 'red'
  33. }"
  34. >{{
  35. Number(item.amount) > 0 ? `+${item.amount}` : item.amount
  36. }}</span
  37. >
  38. </div>
  39. <p>{{ item.content }}</p>
  40. <span>{{ item.createTime }}</span>
  41. </div>
  42. </div>
  43. </div>
  44. </scroller>
  45. </div>
  46. <div class="courseShare" @click="comfirmCode">
  47. <span>赠送课程给好友(当前剩余:{{ courseDetail.amount }}套)</span>
  48. </div>
  49. <van-share-sheet
  50. v-model="showShare"
  51. title="立即赠送给好友"
  52. :options="options"
  53. @select="onSelect"
  54. class="linkCodeShare"
  55. />
  56. <van-overlay :show="showGive" @click="showGive = false">
  57. <div class="wrapper" @click.stop>
  58. <div class="tit">
  59. 赠送课程给好友
  60. <div class="cancle" @click="showGive = false">
  61. <van-icon name="cross" />
  62. </div>
  63. </div>
  64. <div class="msg">
  65. 请提醒好友尽快点击链接领取课程名额。链接分享后,1小时内有效。
  66. </div>
  67. <div class="copy">
  68. <p><van-icon name="info-o" /> 链接分享后,1小时内有效</p>
  69. <!-- <van-button
  70. style="padding: 0 1rem;border-radius: 0.4rem;"
  71. color="#26A2FF"
  72. class="copyCode"
  73. @click="getCourseCode"
  74. >复制链接</van-button> -->
  75. <button ref="copys" id="copyLink" data-clipboard-action="copy" data-clipboard-target="#copy_text" @click="copy">复制链接</button>
  76. </div>
  77. </div>
  78. </van-overlay>
  79. <input type="text" v-model="giveLink" id="copy_text" style="opacity: 0">
  80. </div>
  81. </template>
  82. <script>
  83. import { getCourseRecordList, createCourseCode ,getDealerCourseDetail} from "../api";
  84. import {setWxConfig} from '../utils'
  85. import Clipboard from "clipboard";
  86. import courseList from "../components/courseList.vue";
  87. import wx from "weixin-js-sdk";
  88. export default {
  89. name: "courseAdDetail",
  90. components: { courseList },
  91. props: [],
  92. data() {
  93. return {
  94. subjectId:0,
  95. courseId:0,
  96. showShare: false,
  97. loading: false,
  98. finished: false,
  99. activeTab: 0,
  100. title: "课程详情",
  101. giveLink: "",
  102. noDate: false,
  103. showGive: false,
  104. options: [
  105. // { name: '微信', icon: 'wechat' },
  106. { name: "复制链接", icon: "link" }
  107. // { name: '二维码', icon: 'qrcode' },
  108. ],
  109. page: {
  110. cur: 1,
  111. total: 0,
  112. size: 10
  113. },
  114. courseDetail: {
  115. id: 0, //资产id
  116. userId: 0, //用户id
  117. subjectId: 0, //课程id
  118. subjectName: "",
  119. subjectThumb: "", //缩略图
  120. subjectPrice: 0, //课程价格
  121. sectionsNum: 0, //章节数
  122. subjectEnable: 1, //是否上架
  123. amount: 0, //剩余名额
  124. statistics: {
  125. saleAmount: 0, //已卖出
  126. transferOutAmount: 0, //已转入
  127. transferInAmount: 0 //已转出
  128. }
  129. },
  130. recordList: [],
  131. copyBtn:null,
  132. };
  133. },
  134. computed: {
  135. courseInfo() {
  136. let list = [];
  137. if (this.courseDetail && this.courseDetail.userId != 0) {
  138. list.push(this.courseDetail);
  139. }
  140. return list;
  141. }
  142. },
  143. created() {
  144. this.init();
  145. // setWxConfig();
  146. },
  147. mounted(){
  148. this.copyBtn = new Clipboard(this.$refs.copys);
  149. },
  150. methods: {
  151. //分享链接
  152. shareLink(){
  153. if(this.$isWx){
  154. wx.updateAppMessageShareData({
  155. title: this.courseDetail.subjectName, // 分享标题
  156. desc: '点击查看课程', // 分享描述
  157. link: this.giveLink, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
  158. imgUrl: this.courseDetail.subjectThumb, // 分享图标
  159. success: function () {
  160. // 设置成功
  161. console.log("分享成功")
  162. // this.$toast.success('')
  163. }
  164. })
  165. }else{
  166. this.$toast.fail('请在微信中打开分享')
  167. }
  168. },
  169. //复制
  170. copy () {
  171. let _this = this
  172. let clipboard = _this.copyBtn
  173. clipboard.on('success', function () {
  174. _this.$toast.success('复制成功')
  175. })
  176. clipboard.on('error', function (e) {
  177. console.error('复制失败',e)
  178. })
  179. },
  180. // 分享课程方式选择
  181. onSelect(option) {
  182. if (option.name == "复制链接") {
  183. this.showGive = true;
  184. this.showShare = false;
  185. }
  186. },
  187. //获取课程详情
  188. getCourseDetail(){
  189. getDealerCourseDetail(this.courseId).then(res=>{
  190. this.courseDetail = res
  191. })
  192. },
  193. // 获取课程码
  194. getCourseCode() {
  195. createCourseCode(this.courseDetail.subjectId).then(res => {
  196. this.giveLink = `点我领取课程,1小时内可领取有效 ${window.location.href.split("#")[0]}#/courseDetail/${
  197. this.subjectId
  198. }?code=${res}`;
  199. console.log(this.giveLink)
  200. this.showGive = true;
  201. // this.getCourseDetail();
  202. // this.copyLink().then(()=>{
  203. // this.$toast.success('复制成功')
  204. // this.showGive = false;
  205. // })
  206. });
  207. },
  208. // 复制剪切板
  209. copyLink() {
  210. let oInput = document.createElement("input");
  211. oInput.value = this.giveLink;
  212. document.body.appendChild(oInput);
  213. oInput.select(); // 选择对象
  214. if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) {//兼容ios
  215. if (!document.execCommand("Copy")) {
  216. oInput.setSelectionRange(0, oInput.value.length);
  217. }
  218. }
  219. document.execCommand("Copy"); // 执行浏览器复制命令
  220. document.body.removeChild(oInput);
  221. return new Promise((resolve,reject)=>{
  222. if (document.execCommand("Copy")) {
  223. resolve(this.giveLink);
  224. }else{
  225. reject(this.giveLink);
  226. }
  227. })
  228. },
  229. // 分享弹出
  230. comfirmCode() {
  231. // this.showGive = true;
  232. this.getCourseCode()
  233. },
  234. // 触底加载
  235. getMoreList(done) {
  236. if (!this.noDate) {
  237. setTimeout(() => {
  238. this.getRecord(done);
  239. }, 300);
  240. } else {
  241. this.$refs.recordScroller.finishInfinite(true);
  242. }
  243. },
  244. // 获取课程变动记录
  245. getRecord(done) {
  246. let data = {
  247. page: this.page.cur,
  248. pageSize: this.page.size,
  249. subjectId: this.subjectId
  250. };
  251. getCourseRecordList(data).then(res => {
  252. this.recordList = this.recordList.concat(res.list);
  253. this.page.cur = res.current;
  254. this.page.total = res.total;
  255. if (res.pages == res.current || res.pages == 0) {
  256. if (done) done(true);
  257. this.noDate = true;
  258. } else {
  259. if (done) done();
  260. this.page.cur++; //下拉一次页数+1
  261. this.noDate = false;
  262. }
  263. });
  264. },
  265. // 返回
  266. onClickLeft() {
  267. this.$router.go(-1);
  268. },
  269. // 初始化
  270. init() {
  271. let arr = this.$route.params.id.split('-')
  272. this.courseId = arr[0];
  273. this.subjectId = arr[1]
  274. this.getCourseDetail();
  275. this.getRecord();
  276. },
  277. destroyed() {
  278. sessionStorage.removeItem("course_detail");
  279. }
  280. }
  281. };
  282. </script>
  283. <style scoped lang="scss">
  284. @import url('../utils/navBar.scss');
  285. * {
  286. margin: 0;
  287. padding: 0;
  288. }
  289. img {
  290. display: block;
  291. }
  292. .page {
  293. background-color: #fff;
  294. box-sizing: border-box;
  295. position: relative;
  296. .courseContent {
  297. height: calc(100vh - 1.9rem);
  298. position: relative;
  299. .record {
  300. border-top: 1px solid #efefef;
  301. border-bottom: 1px solid #efefef;
  302. & > p {
  303. font-size: 0.28rem;
  304. line-height: 0.8rem;
  305. color: #000;
  306. font-weight: 550;
  307. padding: 0 0.2rem;
  308. }
  309. .recordList {
  310. border-top: 0.02rem solid #efefef;
  311. // border-bottom: 1px solid #999;
  312. .recordLi {
  313. background: #fff;
  314. padding: 0 0.2rem;
  315. overflow: hidden;
  316. &:not(:nth-last-child(1)) {
  317. border-bottom: 1px solid #efefef;
  318. }
  319. .flex-name-num {
  320. display: flex;
  321. justify-content: space-between;
  322. align-items: center;
  323. padding-top: 0.1rem;
  324. & > p {
  325. font-size: 0.32rem;
  326. color: #000;
  327. line-height: 1.5;
  328. }
  329. & > span {
  330. font-size: 0.32rem;
  331. color: #000;
  332. line-height: 2;
  333. margin-left: 0.1rem;
  334. }
  335. }
  336. & > p {
  337. font-size: 0.28rem;
  338. color: #666;
  339. line-height: 1;
  340. }
  341. & > span {
  342. font-size: 0.28rem;
  343. color: #666;
  344. line-height: 1;
  345. display: block;
  346. margin-top: 0.2rem;
  347. margin-bottom: 0.1rem;
  348. }
  349. }
  350. }
  351. }
  352. }
  353. .courseShare {
  354. width: calc(100% - 0.6rem);
  355. height: 0.8rem;
  356. position: absolute;
  357. left: 0.3rem;
  358. bottom: 0.1rem;
  359. background-color: #26a2ff;
  360. display: flex;
  361. align-items: center;
  362. justify-content: center;
  363. border-radius: 0.15rem;
  364. span {
  365. font-size: 0.26rem;
  366. color: #fff;
  367. }
  368. }
  369. .wrapper {
  370. background: #fff;
  371. width: 75%;
  372. position: absolute;
  373. left: 50%;
  374. top: 50%;
  375. transform: translate(-50%, -50%);
  376. border-radius: 0.2rem;
  377. padding: 0.3rem 0.2rem;
  378. .tit {
  379. font-size: 0.32rem;
  380. color: #333;
  381. line-height: 0.8rem;
  382. text-align: center;
  383. position: relative;
  384. font-weight: 600;
  385. position: relative;
  386. .cancle {
  387. position: absolute;
  388. top: 0;
  389. right: 0;
  390. font-size: 0.3rem;
  391. line-height: 0.3rem;
  392. }
  393. }
  394. .msg {
  395. font-size: 0.27rem;
  396. text-align: center;
  397. padding: 0 0.1rem;
  398. }
  399. .copy {
  400. text-align: center;
  401. margin-top: 0.5rem;
  402. #copyLink{
  403. padding: 0px 1rem;
  404. border-radius: 0.4rem;
  405. color: white;
  406. background: rgb(38, 162, 255);
  407. border-color: rgb(38, 162, 255);
  408. line-height: .75rem;
  409. border: 0;
  410. outline: none;
  411. }
  412. p {
  413. font-size: 0.22rem;
  414. color: #888;
  415. line-height: 0.3rem;
  416. margin-bottom: 0.15rem;
  417. }
  418. }
  419. }
  420. }
  421. /deep/ .van-tab--active{
  422. font-weight: 600;
  423. }
  424. </style>