courseAdDeal.vue 12 KB

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