courseAdDeal.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  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. Number(item.amount) > 0 ? `+${item.amount}` : item.amount
  32. }}</span>
  33. </div>
  34. <p>{{ item.content }}</p>
  35. <span>{{ item.createTime }}</span>
  36. </div>
  37. </div>
  38. </div>
  39. </scroller>
  40. </div>
  41. <div class="courseShare" @click="comfirmCode">
  42. <span>赠送课程给好友(当前剩余:{{ courseDetail.amount }}套)</span>
  43. </div>
  44. <van-share-sheet
  45. v-model="showShare"
  46. title="立即赠送给好友"
  47. :options="options"
  48. @select="onSelect"
  49. :aria-label="giveLink"
  50. class="linkCodeShare"
  51. />
  52. <van-overlay :show="showGive" @click="showGive = false">
  53. <div class="wrapper" @click.stop>
  54. <div class="tit">赠送课程给好友<div class="cancle" @click="showGive = false"><van-icon name="cross" /></div></div>
  55. <div class="msg">请提醒好友尽快点击链接领取课程份额。链接分享后,1小时内有效。</div>
  56. <div class="copy">
  57. <p><van-icon name="info-o" /> 链接分享后,1小时内有效</p>
  58. <van-button style="padding: 0 1rem;border-radius: 0.4rem;" color="#26A2FF" @click="getCourseCode">复制链接</van-button>
  59. </div>
  60. </div>
  61. </van-overlay>
  62. </div>
  63. </template>
  64. <script>
  65. import { getCourseRecordList, createCourseCode } from "../api";
  66. import Clipboard from "clipboard";
  67. import axios from "axios";
  68. import courseList from "../components/courseList.vue";
  69. export default {
  70. name: "",
  71. components: { courseList },
  72. props: [],
  73. data() {
  74. return {
  75. showShare: false,
  76. canReq: true,
  77. loading: false,
  78. finished: false,
  79. activeTab: 0,
  80. title: "课程详情",
  81. giveLink: "",
  82. noDate: false,
  83. showGive:false,
  84. options: [
  85. // { name: '微信', icon: 'wechat' },
  86. { name: "复制链接", icon: "link" }
  87. // { name: '二维码', icon: 'qrcode' },
  88. ],
  89. page: {
  90. cur: 1,
  91. total: 0,
  92. size: 10
  93. },
  94. courseDetail: {
  95. id: 0, //资产id
  96. userId: 0, //用户id
  97. subjectId: 0, //课程id
  98. subjectName: "",
  99. subjectThumb: "", //缩略图
  100. subjectPrice: 0, //课程价格
  101. sectionsNum: 0, //章节数
  102. subjectEnable: 1, //是否上架
  103. amount: 0, //剩余名额
  104. statistics: {
  105. saleAmount: 0, //已卖出
  106. transferOutAmount: 0, //已转入
  107. transferInAmount: 0 //已转出
  108. }
  109. },
  110. recordList: []
  111. };
  112. },
  113. computed: {
  114. courseInfo() {
  115. let list = [];
  116. if (this.courseDetail && this.courseDetail.userId != 0) {
  117. list.push(this.courseDetail);
  118. }
  119. return list;
  120. }
  121. },
  122. created() {
  123. this.init();
  124. },
  125. methods: {
  126. // 分享课程方式选择
  127. onSelect(option) {
  128. if (option.name == "复制链接") {
  129. this.showGive = true;
  130. this.showShare = false;
  131. // this.$dialog
  132. // .confirm({
  133. // title: "赠送课程给好友",
  134. // message: "请提醒好友尽快点击链接领取课程份额。链接分享后,1小时内有效"
  135. // })
  136. // .then(() => {
  137. // this.showGive = true;
  138. // createCourseCode(this.courseDetail.subjectId).then(res => {
  139. // this.giveLink = `${
  140. // window.location.href.split("#")[0]
  141. // }#/courseDetail/${this.$route.params.id}?code=${res}`;
  142. // this.copyLink(this.giveLink);
  143. // });
  144. // })
  145. // .catch(err => {
  146. // this.showShare = false;
  147. // });
  148. }
  149. },
  150. // 获取课程码
  151. getCourseCode(){
  152. createCourseCode(this.courseDetail.subjectId).then(res => {
  153. this.giveLink = `${
  154. window.location.href.split("#")[0]
  155. }#/courseDetail/${this.$route.params.id}?code=${res}`;
  156. this.copyLink(this.giveLink);
  157. });
  158. },
  159. // 微信分享/未使用
  160. wxShare() {
  161. let that = this;
  162. let url = window.location.href;
  163. let newurl = url.split("#")[0];
  164. axios(
  165. "https://i.g107.com/564/Ajax/getJsSdk",
  166. {
  167. url: newurl
  168. },
  169. {
  170. headers: {
  171. "Content-Type": "application/x-www-form-urlencoded"
  172. },
  173. transformRequest: [
  174. function(data) {
  175. // 对 data 进行任意转换处理
  176. return qs.stringify(data);
  177. }
  178. ]
  179. }
  180. )
  181. .then(function(response) {
  182. console.log(response);
  183. var config = response.data;
  184. var adress = "ceshi";
  185. wx.config({
  186. debug: false,
  187. appId: config.appId,
  188. timestamp: config.timestamp,
  189. nonceStr: config.nonceStr,
  190. signature: config.signature,
  191. jsApiList: ["updateAppMessageShareData"]
  192. });
  193. wx.ready(function() {
  194. wx.updateAppMessageShareData({
  195. title: `${that.courseDetail.subjectName}`, // 分享标题
  196. desc: `分享简介`, // 分享描述
  197. link: `${window.location.href.split("#")[0]}#/courseAdDetail/${
  198. this.$route.params.id
  199. }/code=${res}`, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
  200. imgUrl: `${that.courseDetail.subjectThumb}`, // 分享图标
  201. success: function() {
  202. // 设置成功
  203. }
  204. });
  205. });
  206. })
  207. .catch(function(error) {
  208. console.log(error);
  209. });
  210. },
  211. // 复制剪切板
  212. copyLink() {
  213. //创建输入框
  214. var input = document.createElement("input");
  215. //对输入框进行赋值
  216. input.value = this.giveLink;
  217. //添加到body中。
  218. document.body.appendChild(input);
  219. input.select();
  220. var copyResult = document.execCommand("copy");
  221. if (copyResult) {
  222. this.$toast.success("复制成功~");
  223. this.showGive = false;
  224. //移除
  225. document.body.removeChild(input);
  226. } else {
  227. navigator.clipboard.writeText(str);
  228. this.$toast.success("复制成功~");
  229. this.showGive = false;
  230. }
  231. },
  232. // 分享弹出
  233. comfirmCode() {
  234. this.showGive = true;
  235. },
  236. // 触底加载
  237. getMoreList(done) {
  238. console.log("到底了");
  239. if (!this.noDate) {
  240. setTimeout(() => {
  241. this.getRecord(done);
  242. }, 300);
  243. } else {
  244. this.$refs.recordScroller.finishInfinite(true);
  245. }
  246. },
  247. // 获取课程变动记录
  248. getRecord(done) {
  249. let data = {
  250. page: this.page.cur,
  251. pageSize: this.page.size,
  252. subjectId: this.courseId
  253. };
  254. getCourseRecordList(data).then(res => {
  255. this.recordList = this.recordList.concat(res.list);
  256. this.page.cur = res.current;
  257. this.page.total = res.total;
  258. if (res.pages == res.current) {
  259. console.log('已无更多')
  260. if (done) done(true);
  261. this.noDate = true;
  262. } else {
  263. console.log('更多...')
  264. if (done) done();
  265. this.page.cur++; //下拉一次页数+1
  266. this.noDate = false;
  267. }
  268. });
  269. },
  270. // 返回
  271. onClickLeft() {
  272. this.$router.go(-1);
  273. },
  274. // 初始化
  275. init() {
  276. this.courseId = this.$route.params.id;
  277. this.courseDetail = JSON.parse(sessionStorage.getItem("course_detail"));
  278. this.getRecord();
  279. // this.wxShare();
  280. },
  281. destroyed() {
  282. sessionStorage.removeItem("course_detail");
  283. }
  284. }
  285. };
  286. </script>
  287. <style scoped lang="scss">
  288. * {
  289. margin: 0;
  290. padding: 0;
  291. }
  292. img {
  293. display: block;
  294. }
  295. .page {
  296. background-color: #fff;
  297. box-sizing: border-box;
  298. position: relative;
  299. .courseContent {
  300. height: calc(100vh - 0.9rem);
  301. position: relative;
  302. .record {
  303. border-top: 1px solid #efefef;
  304. border-bottom: 1px solid #efefef;
  305. & > p {
  306. font-size: 0.28rem;
  307. line-height: 0.8rem;
  308. color: #000;
  309. font-weight: 550;
  310. padding: 0 0.2rem;
  311. }
  312. .recordList {
  313. border-top: 0.02rem solid #efefef;
  314. // border-bottom: 1px solid #999;
  315. .recordLi {
  316. background: #fff;
  317. padding: 0 0.2rem;
  318. &:not(:nth-last-child(1)) {
  319. border-bottom: 1px solid #efefef;
  320. }
  321. .flex-name-num {
  322. display: flex;
  323. justify-content: space-between;
  324. align-items: center;
  325. & > p {
  326. font-size: 0.32rem;
  327. color: #000;
  328. line-height: 2;
  329. }
  330. & > span {
  331. font-size: 0.32rem;
  332. color: #000;
  333. line-height: 2;
  334. }
  335. }
  336. & > p {
  337. font-size: 0.28rem;
  338. color: #666;
  339. line-height: 2;
  340. }
  341. & > span {
  342. font-size: 0.28rem;
  343. color: #666;
  344. line-height: 2;
  345. }
  346. }
  347. }
  348. }
  349. }
  350. .courseShare {
  351. width: calc(100% - 0.6rem);
  352. height: 0.8rem;
  353. position: absolute;
  354. left: 0.3rem;
  355. bottom: 0.1rem;
  356. background-color: #26A2FF;
  357. display: flex;
  358. align-items: center;
  359. justify-content: center;
  360. border-radius: 0.15rem;
  361. span {
  362. font-size: 0.26rem;
  363. color: #fff;
  364. }
  365. }
  366. .wrapper{
  367. background: #fff;
  368. width: 75%;
  369. position: absolute;
  370. left: 50%;
  371. top: 50%;
  372. transform: translate(-50%, -50%);
  373. border-radius: 0.2rem;
  374. padding: 0.3rem 0.2rem;
  375. .tit{
  376. font-size: .32rem;
  377. color: #333;
  378. line-height: .8rem;
  379. text-align: center;
  380. position: relative;
  381. font-weight: 600;
  382. position: relative;
  383. .cancle{
  384. position: absolute;
  385. top: 0;
  386. right: 0;
  387. font-size: .3rem;
  388. line-height: .3rem;
  389. }
  390. }
  391. .msg{
  392. font-size: .27rem;
  393. text-align: center;
  394. padding: 0 0.1rem;
  395. }
  396. .copy{
  397. text-align: center;
  398. margin-top: 0.5rem;
  399. p{
  400. font-size: .22rem;
  401. color: #888;
  402. line-height: .3rem;
  403. margin-bottom: 0.15rem;
  404. }
  405. }
  406. }
  407. }
  408. </style>