index.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  1. <style>
  2. .table-body {
  3. padding: 20px;
  4. background-color: #fff;
  5. }
  6. .input-item {
  7. display: inline-block;
  8. width: 250px;
  9. margin: 0 0 20px;
  10. }
  11. .input-item .el-input__inner {
  12. border-right: 0;
  13. }
  14. .input-item .el-input__inner:hover {
  15. border: 1px solid #dcdfe6;
  16. border-right: 0;
  17. outline: 0;
  18. }
  19. .input-item .el-input__inner:focus {
  20. border: 1px solid #dcdfe6;
  21. border-right: 0;
  22. outline: 0;
  23. }
  24. .input-item .el-input-group__append {
  25. background-color: #fff;
  26. border-left: 0;
  27. width: 10%;
  28. padding: 0;
  29. }
  30. .input-item .el-input-group__append .el-button {
  31. padding: 0;
  32. }
  33. .input-item .el-input-group__append .el-button {
  34. margin: 0;
  35. }
  36. .table-body .el-button {
  37. padding: 0 !important;
  38. border: 0;
  39. margin: 0 5px;
  40. }
  41. .form-body {
  42. background-color: #fff;
  43. margin-bottom: 20px;
  44. }
  45. .el-tabs__header {
  46. background-color: #fff;
  47. }
  48. .el-tabs__item {
  49. width: 100px;
  50. text-align: center;
  51. }
  52. .el-table th>.cell {
  53. color: #333;
  54. font-weight: bold;
  55. font-size: 14px;
  56. }
  57. .el-table__footer-wrapper,
  58. .el-table__header-wrapper {
  59. border-bottom: 1.4px solid #D6D6D6;
  60. }
  61. .input-search {
  62. margin-right: 30px;
  63. flex-shrink: 0;
  64. }
  65. </style>
  66. <div id="app" v-cloak>
  67. <el-card shadow="never" body-style="background-color: #f3f3f3;padding: 10px 0 0;">
  68. <div slot="header">
  69. <div>
  70. <span>课程列表</span>
  71. <div style="float: right">
  72. <el-button type="primary" size="small" style="padding: 9px 15px !important;" @click="edit">创建课程
  73. </el-button>
  74. </div>
  75. </div>
  76. </div>
  77. <div class="table-body">
  78. <div style="margin-bottom: 15px;" flex>
  79. <div flex>
  80. <div flex="cross:center" class="input-search">
  81. <!-- <div style="flex-shrink: 0;">课程名称:</div> -->
  82. <el-input @keyup.enter.native="search" size="small" placeholder="请输入课程名称" v-model="searchData.keyword" @clear="search"></el-input>
  83. </div>
  84. <!-- <div flex="cross:center" class="input-search">
  85. <div class="input-item-name">状态:</div>
  86. <div>
  87. <el-select v-model="searchData.status" placeholder="请选择" size="small">
  88. <el-option label="全部" :value="0"></el-option>
  89. <el-option v-for="(item,index) in status_text" :key="index" :label="item" :value="index">{{item}}
  90. </el-option>
  91. </el-select>
  92. </div>
  93. </div> -->
  94. </div>
  95. <div>
  96. <el-button type="primary" size="small" @click="search" style="padding: 9px 15px !important;">搜索</el-button>
  97. <el-button type="warning" @click="clereSearch" v-if="searchData.keyword || searchData.start_time || searchData.end_time || searchData.cate_id" style="padding: 9px 15px !important;">清除搜索条件</el-button>
  98. </div>
  99. </div>
  100. <el-table v-loading="listLoading" :data="list" stripe style="width: 100%">
  101. <el-table-column label="课程 ID" prop="id" min-width="80" align="center">
  102. <template slot-scope="scope"> {{scope.row.id}} </template>
  103. </el-table-column>
  104. <el-table-column label="课程封面" prop="logo" min-width="80" align="center">
  105. <template slot-scope="scope">
  106. <div style="display: flex;align-items: center;">
  107. <div style="padding-right: 10px;">
  108. <com-image mode="aspectFill" :src="scope.row.logo"></com-image>
  109. </div>
  110. </div>
  111. </template>
  112. </el-table-column>
  113. <el-table-column label="课程名称" prop="name" min-width="180">
  114. <template slot-scope="scope">
  115. <div size="small">{{scope.row.name}}</div>
  116. </template>
  117. </el-table-column>
  118. <el-table-column label="课程分类" prop="cat_id" min-width="180" align="center">
  119. <template slot-scope="scope">
  120. <div size="small" v-if="scope.row.cat_id == 0"></div>
  121. <div size="small" v-else>{{scope.row.cat_name}}</div>
  122. </template>
  123. </el-table-column>
  124. <el-table-column label="课程售价" prop="price" min-width="180" align="center">
  125. <template slot-scope="scope">
  126. <div size="small" v-if="scope.row.sell_type==3">免费</div>
  127. <div size="small" v-else-if="scope.row.sell_type==1">¥{{scope.row.price}}</div>
  128. <div size="small" v-else-if="scope.row.sell_type==2">特定会员身份:{{scope.row.allow_member_levels_name}}</div>
  129. <div size="small" v-if="scope.row.sell_type==4">转发观看</div>
  130. </template>
  131. </el-table-column>
  132. <el-table-column label="销量" prop="sales" min-width="180" align="center">
  133. <template slot-scope="scope">
  134. <div size="small">{{scope.row.sales}}</div>
  135. </template>
  136. </el-table-column>
  137. <el-table-column label="观看数" prop="views" min-width="90" align="center">
  138. <template slot-scope="scope">
  139. <div size="small">实际:{{scope.row.views}}</div>
  140. <div size="small">虚拟:{{scope.row.vm_views}}</div>
  141. </template>
  142. </el-table-column>
  143. <el-table-column label="点赞数" prop="likes" min-width="80" align="center">
  144. <template slot-scope="scope">
  145. <div size="small">实际:{{scope.row.likes}}</div>
  146. <div size="small">虚拟:{{scope.row.vm_likes}}</div>
  147. </template>
  148. </el-table-column>
  149. <el-table-column label="评论数" prop="comments" min-width="80" align="center">
  150. <template slot-scope="scope">
  151. <div size="small">实际:{{scope.row.comments}}</div>
  152. </template>
  153. </el-table-column>
  154. <el-table-column label="排序" prop="sales" width="150" align="center">
  155. <template slot-scope="scope">
  156. <div v-if="sort_id != scope.row.id">
  157. <el-tooltip class="item" effect="dark" content="排序" placement="top">
  158. <span>{{scope.row.sort}}</span>
  159. </el-tooltip>
  160. <el-button class="edit-sort" type="text" @click="edits(scope.row,'sort')">
  161. <img src="resources/img/mall/order/edit.png" alt="">
  162. </el-button>
  163. </div>
  164. <div style="display: flex;align-items: center" v-else>
  165. <el-input style="min-width: 70px" type="number" size="mini" class="change" v-model="sort" autocomplete="off"></el-input>
  166. <el-button class="change-quit" type="text" style="color: #F56C6C;padding: 0 5px" icon="el-icon-error" circle @click="cancelEdit('sort')"></el-button>
  167. <el-button class="change-success" type="text" style="margin-left: 0;color: #67C23A;padding: 0 5px" icon="el-icon-success" circle @click="do_sort(scope.row)">
  168. </el-button>
  169. </div>
  170. </template>
  171. </el-table-column>
  172. <!-- <el-table-column label="状态" prop="status" min-width="80" align="center">-->
  173. <!-- <template slot-scope="scope">-->
  174. <!-- <com-ellipsis :line="1">{{scope.row.status==1?'已上架':'已下架'}}</com-ellipsis>-->
  175. <!-- </template>-->
  176. <!-- </el-table-column>-->
  177. <el-table-column align="center" label="上架状态" min-width="100">
  178. <template slot-scope="scope">
  179. <el-tooltip class="item" effect="dark" content="点击更改状态" placement="top">
  180. <el-switch
  181. @change="((val)=>{switchFun(val,scope.row)})"
  182. v-model="scope.row.status"
  183. :active-value="1"
  184. :inactive-value="0"
  185. >
  186. </el-switch>
  187. </el-tooltip>
  188. </template>
  189. </el-table-column>
  190. <el-table-column label="创建时间" prop="created_at" min-width="110" align="center">
  191. <template slot-scope="scope">
  192. <div size="small">{{scope.row.created_at|dateTimeFormat('Y-m-d H:i:s')}}</div>
  193. </template>
  194. </el-table-column>
  195. <el-table-column label="操作" min-width="250" align="center">
  196. <template slot-scope="scope">
  197. <el-button circle size="mini" type="text" @click="giveCourse(scope.row.id)"> 发放课程 </el-button>
  198. <el-button circle size="mini" type="text" @click="editDistribution(scope.row.id)"> 分佣设置 </el-button>
  199. <el-button circle size="mini" type="text" @click="chapters(scope.row.id)"> 内容管理 </el-button>
  200. <!-- <el-button v-if="scope.row.status==0" circle size="mini" type="text" @click.stop="putOn(scope.row)"> 立即上架 </el-button>-->
  201. <!-- <el-button v-if="scope.row.status==1" circle size="mini" type="text" @click.stop="putOff(scope.row)"> 立即下架 </el-button>-->
  202. <el-button v-if="scope.row.status==1" circle size="mini" type="text" @click="copy(scope.row)" class="copy_btn"> 复制链接 </el-button>
  203. <el-button circle size="mini" type="text" @click="courseDelete(scope.row, scope.$index)"> 删除 </el-button>
  204. </template>
  205. </el-table-column>
  206. </el-table>
  207. <div style="text-align: right;margin: 20px 0;">
  208. <el-pagination @current-change="pagination" background layout="prev, pager, next" :page-count="pageCount"></el-pagination>
  209. </div>
  210. </div>
  211. </el-card>
  212. <!-- 这个是立即下架弹窗 -->
  213. <!-- 这个是立即上架弹窗 -->
  214. <el-dialog title="提示" :visible.sync="dialogVisible" width="30%" v-loading="dialogLoading2">
  215. <span>{{dialogText}}</span>
  216. <span slot="footer" class="dialog-footer">
  217. <el-button @click="noConfirm">取 消</el-button>
  218. <el-button type="primary" @click="comfirm">确 定</el-button>
  219. </span>
  220. </el-dialog>
  221. <!-- 这个是复制链接弹窗 -->
  222. <el-dialog :visible.sync="showGiveCourse" width="20%" title="选择发放用户">
  223. <div>
  224. <el-form ref="ruleForm" :model="ruleForm" :rules="rules" size="small" label-width="150px">
  225. <el-form-item label="用户:" prop="user_id">
  226. <el-autocomplete size="small" v-model="ruleForm.nickname" value-key="nickname"
  227. @keyup.enter.native="keyUp"
  228. :fetch-suggestions="querySearchAsync" placeholder="请输入用户昵称/id/手机号"
  229. @select="areaClick"></el-autocomplete>
  230. </el-form-item>
  231. <el-form-item label="用户信息:" prop='' v-if="ruleForm.user_id != ''">
  232. <div style="display: flex;align-items:center;">
  233. <el-image class="table-info-img circle" :src="ruleForm.avatar_url" style="width:50px;">
  234. <div slot="error" class="image-slot">
  235. <com-image src="/resources/img/common/default-avatar.png"></com-image>
  236. </div>
  237. </el-image>
  238. <span style="margin-left:10px;">{{ruleForm.nickname}}</span>
  239. </div>
  240. </el-form-item>
  241. </el-form>
  242. </template>
  243. </div>
  244. <span slot="footer" class="dialog-footer">
  245. <el-button @click="showGiveCourse = false" type="default" size="small">取消</el-button>
  246. <el-button type="primary" :loading="btnLoading" style="margin-bottom: 10px;" size="small"
  247. @click="giveUserCourse">发放课程</el-button>
  248. </span>
  249. </el-dialog>
  250. </div>
  251. <script src="/resources/unpkg/clipboard@1.0.0/dist/clipboard.min.js"></script>
  252. <script>
  253. const app = new Vue({
  254. el: '#app',
  255. data() {
  256. return {
  257. status: 0,
  258. list: [],
  259. listLoading: false,
  260. page: 1,
  261. pageCount: 0,
  262. lableLoading: false,
  263. btnLoading: false,
  264. dialogLoading2: false,
  265. dialogText: '',
  266. dialogVisible: false,
  267. searchData: {
  268. keyword: '',
  269. start_time: null,
  270. end_time: null,
  271. cate_id: null,
  272. },
  273. sort:0,
  274. sort_id: 0,
  275. ruleForm: {
  276. id: '',
  277. user_id: '',
  278. },
  279. showGiveCourse: false,
  280. rules: {
  281. user_id: [
  282. {
  283. required: true,
  284. validator: (rule, value, callback) => {},
  285. trigger: 'blur'
  286. },
  287. ],
  288. },
  289. };
  290. },
  291. methods: {
  292. search() {
  293. this.page = 1;
  294. this.getList();
  295. },
  296. clereSearch() {
  297. this.searchData.keyword = '';
  298. this.searchData.start_time = null;
  299. this.searchData.end_time = null;
  300. this.searchData.cate_id = null;
  301. this.getList();
  302. },
  303. pagination(currentPage) {
  304. let self = this;
  305. self.page = currentPage;
  306. self.getList();
  307. },
  308. // 0.1 获取课程列表
  309. getList() {
  310. let self = this;
  311. self.listLoading = true;
  312. request({
  313. params: {
  314. r: 'course/default/index',
  315. page: self.page,
  316. ...this.searchData
  317. },
  318. method: 'get',
  319. }).then(e => {
  320. self.listLoading = false;
  321. self.list = e.data.data.list;
  322. self.pageCount = e.data.data.page_count;
  323. localStorage.setItem('h5_domain', e.data.data.h5_domain)
  324. localStorage.setItem('mall_sign', e.data.data.mall_sign)
  325. }).catch(e => {
  326. console.log(e);
  327. });
  328. },
  329. //管理章节
  330. chapters(id) {
  331. if (id) {
  332. navigateTo({
  333. r: 'course/course/chapter-list',
  334. id: id,
  335. });
  336. } else {
  337. navigateTo({
  338. r: 'course/course/chapter-list',
  339. });
  340. }
  341. },
  342. // 新建或编辑
  343. edit(id) {
  344. if (!id) {
  345. id = 0;
  346. }
  347. navigateTo({
  348. r: 'course/course/course-edit',
  349. id: id,
  350. });
  351. },
  352. // 新建或编辑
  353. editDistribution(id) {
  354. if (!id) {
  355. id = 0;
  356. }
  357. navigateTo({
  358. r: 'course/course/course-edit',
  359. id: id,
  360. activeName: 'distribution_setting',
  361. });
  362. },
  363. //删除
  364. courseDelete(row, index) {
  365. let self = this;
  366. self.$confirm('删除该课程, 是否继续?', '提示', {
  367. confirmButtonText: '确定',
  368. cancelButtonText: '取消',
  369. type: 'warning'
  370. }).then(() => {
  371. self.listLoading = true;
  372. request({
  373. params: {
  374. r: 'course/course/delete',
  375. },
  376. method: 'post',
  377. data: {
  378. id: row.id,
  379. }
  380. }).then(e => {
  381. self.listLoading = false;
  382. if (e.data.code === 0) {
  383. self.$message.success(e.data.msg);
  384. self.list.splice(index, 1);
  385. } else {
  386. self.$message.error(e.data.msg);
  387. }
  388. }).catch(e => {
  389. console.log(e);
  390. });
  391. }).catch(() => {
  392. self.$message.info('已取消删除')
  393. });
  394. },
  395. switchFun(event,row){
  396. if (event == 1) {
  397. this.putOn(row);
  398. } else {
  399. this.putOff(row);
  400. }
  401. },
  402. //立即下架
  403. putOff(row) {
  404. this.dialogText = "是否设置该课程立即下架?"
  405. this.status = 0;
  406. this.id = row.id;
  407. this.dialogVisible = true;
  408. },
  409. //立即上架
  410. putOn(row) {
  411. this.dialogText = "是否设置该课程立即上架?"
  412. this.status = 1;
  413. this.id = row.id;
  414. this.dialogVisible = true;
  415. },
  416. comfirm() {
  417. let obj = {
  418. id: this.id,
  419. status: this.status
  420. }
  421. this.dialogLoading2 = true;
  422. //console.log("请求前得参数="+JSON.stringify(obj))
  423. request({
  424. method: 'post',
  425. params: {
  426. r: 'course/course/switch-status',
  427. },
  428. data: obj
  429. }).then(e => {
  430. this.dialogVisible = false;
  431. this.dialogLoading2 = false;
  432. //console.log("请求结果="+JSON.stringify(e))
  433. this.getList();
  434. if (e.data.code === 0) {
  435. this.$message.success(e.data.msg);
  436. } else {
  437. this.$message.error(e.data.msg);
  438. }
  439. }).catch(e => {
  440. this.$message.error('网络错误');
  441. });
  442. },
  443. noConfirm() {
  444. this.getList();
  445. this.dialogVisible = false;
  446. },
  447. //复制链接
  448. copy(row) {
  449. var id = row.id;
  450. //复制链接
  451. var url = localStorage.getItem('h5_domain');
  452. var clipboard = new ClipboardJS('.copy_btn', {
  453. text: function() {
  454. return url + 'plugins/course/details?courseId=' + id + '&sign=' + localStorage.getItem('mall_sign');
  455. }
  456. });
  457. var self = this;
  458. clipboard.on('success', function(e) {
  459. self.$message.success('复制成功');
  460. e.clearSelection();
  461. clipboard.destroy()
  462. });
  463. clipboard.on('error', function(e) {
  464. self.$message.error('复制失败,请手动复制');
  465. });
  466. },
  467. edits(row, type) {
  468. switch (type) {
  469. case 'sort':
  470. this.sort = row.sort;
  471. this.sort_id = row.id;
  472. break;
  473. }
  474. },
  475. cancelEdit(type) {
  476. switch (type) {
  477. case 'sort':
  478. this.sort = 0;
  479. this.sort_id = 0;
  480. break;
  481. }
  482. },
  483. do_sort(data) {
  484. let self = this;
  485. let id = data ? parseInt(data.id) : '';
  486. request({
  487. params: {
  488. r: 'course/course/update-sort',
  489. },
  490. method: 'post',
  491. data: {
  492. id: id,
  493. sort: this.sort
  494. }
  495. }).then(e => {
  496. if (e.data.code == 0) {
  497. this.sort_id = 0;
  498. self.$message.success(e.data.msg);
  499. self.getList();
  500. } else {
  501. self.$message.error(e.data.msg);
  502. }
  503. }).catch(e => {
  504. console.log(e);
  505. });
  506. },
  507. giveCourse(id) {
  508. this.ruleForm = {
  509. id: id,
  510. user_id: '',
  511. nickname: '',
  512. };
  513. this.ruleForm.id = id;
  514. this.showGiveCourse = true;
  515. },
  516. querySearchAsync(queryString, cb) {
  517. this.ruleForm.user_id = 0;
  518. this.ruleForm.keyword = queryString;
  519. this.get_user(cb);
  520. },
  521. get_user(cb) {
  522. request({
  523. params: {
  524. r: 'course/default/search-user',
  525. keyword: this.ruleForm.keyword
  526. }
  527. }).then(res => {
  528. if (res.data.code == 0) {
  529. cb(res.data.data.list)
  530. } else {
  531. this.$message.error(res.data.msg);
  532. }
  533. });
  534. },
  535. areaClick(row) {
  536. //console.log('选择了用户row='+JSON.stringify(row))
  537. this.ruleForm = {...this.ruleForm, ...row};
  538. if (row.mobile != '') this.mobile = row.mobile
  539. this.$refs.ruleForm.rules.user_id[0].validator = (rule, value, callback) => {
  540. if (this.ruleForm.user_id != '') {
  541. callback();
  542. } else {
  543. callback(new Error('请选择用户'));
  544. }
  545. }
  546. console.log('ruleForm', this.ruleForm);
  547. },
  548. //发放课程
  549. giveUserCourse() {
  550. this.$refs.ruleForm.rules.user_id[0].validator = (rule, value, callback) => {
  551. if (this.ruleForm.user_id != '') {
  552. callback();
  553. } else {
  554. callback(new Error('请选择用户'));
  555. }
  556. }
  557. this.$refs['ruleForm'].validate((valid) => {
  558. if (valid) {
  559. this.btnLoading = true;
  560. request({
  561. params: {
  562. r: 'course/default/give-user-course',
  563. },
  564. method: 'post',
  565. data: this.ruleForm
  566. }).then(e => {
  567. this.btnLoading = false;
  568. this.showGiveCourse = false;
  569. if (e.data.code == 0) {
  570. this.$message.success(e.data.msg);
  571. } else {
  572. this.$message.error(e.data.msg);
  573. }
  574. }).catch(e => {
  575. this.$message.error(e);
  576. this.btnLoading = false;
  577. })
  578. } else {
  579. this.btnLoading = false;
  580. console.log('error submit!!');
  581. return false;
  582. }
  583. });
  584. },
  585. },
  586. mounted: function() {
  587. this.getList();
  588. }
  589. });
  590. </script>