edit.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  1. <?php
  2. use common\helpers\ComponentHelper;
  3. ComponentHelper::loadComponentView('com-dialog-select');
  4. ComponentHelper::loadComponentView('com-select-cat');
  5. ComponentHelper::loadComponentView('com-rich-text');
  6. ComponentHelper::loadComponentView('com-image');
  7. ?>
  8. <div id="app" v-cloak>
  9. <el-card class="box-card" v-loading="cardLoading" shadow="never" style="border:0;min-width: 1500px;" body-style="background-color: #f3f3f3;padding: 10px 0 0;">
  10. <div slot="header">
  11. <el-breadcrumb separator="/">
  12. <el-breadcrumb-item>
  13. <span style="color: #409EFF;cursor: pointer" @click="$navigate({r:'plugin/course/admin/activity/index'})">
  14. 活动课程
  15. </span>
  16. </el-breadcrumb-item>
  17. <el-breadcrumb-item>添加/编辑活动</el-breadcrumb-item>
  18. </el-breadcrumb>
  19. </div>
  20. <div class="form-body">
  21. <el-form :model="ruleForm" :rules="rules" size="small" ref="ruleForm" label-width="150px" v-loading="formLoading">
  22. <el-row>
  23. <el-col :span="24">
  24. <el-form-item label="活动名称" prop="name">
  25. <el-input size="small" v-model="ruleForm.name" size="small" placeholder="活动名称"></el-input>
  26. </el-form-item>
  27. <el-form-item label="课程任选数量" prop="select_number">
  28. <el-input size="small" v-model="ruleForm.select_number" size="small" placeholder="课程任选数量"></el-input>
  29. </el-form-item>
  30. <el-form-item prop="logo">
  31. <label slot="label">
  32. <span>上传封面</span>
  33. </label>
  34. <com-attachment v-model="ruleForm.logo" :multiple="false" :max="1" @selected="selectedImg($event)">
  35. <el-button size="mini">选择图片</el-button>
  36. </com-attachment>
  37. <div class="pic-url-remark">
  38. 该图片将在活动列表展示,建议尺寸700*240(未设置则使用商城默认图片)
  39. </div>
  40. <div class="customize-share-title">
  41. <com-image mode="aspectFill" width='80px' height='80px' :src="ruleForm.logo ? ruleForm.logo : ''"></com-image>
  42. <el-button v-if="ruleForm.logo" class="del-btn" size="mini" type="danger" icon="el-icon-close" circle @click="ruleForm.logo = ''"></el-button>
  43. </div>
  44. </el-form-item>
  45. <el-form-item prop="banners" class="com-goods">
  46. <template slot="label">
  47. <span>活动轮播图</span>
  48. </template>
  49. <div class="pic-url-remark">
  50. 建议图片像素750*420,可拖拽使其改变顺序
  51. </div>
  52. <div flex="dir:left">
  53. <template v-if="(ruleForm.banners.length > 0)">
  54. <draggable v-model="ruleForm.banners" flex="dif:left">
  55. <transition-group flex>
  56. <div :data-id="index" v-for="(item,index) in ruleForm.banners" :key="index" style="margin-right: 20px;position: relative;cursor: move;">
  57. <com-attachment @selected="updatePicUrl" :params="{'currentIndex': index}">
  58. <com-image mode="aspectFill" width="100px" height='100px' :src="item">
  59. </com-image>
  60. </com-attachment>
  61. <el-button class="del-btn" size="mini" type="danger" icon="el-icon-close" circle @click="delPic(index)"></el-button>
  62. </div>
  63. </transition-group>
  64. </draggable>
  65. </template>
  66. <template v-if="ruleForm.banners.length < 99">
  67. <com-attachment style="margin-bottom: 10px;" :multiple="true" :max="9" @selected="picUrl">
  68. <el-tooltip class="item" effect="dark" content="建议尺寸:750 * 750" placement="top">
  69. <div flex="main:center cross:center" class="add-image-btn">
  70. + 添加图片
  71. </div>
  72. </el-tooltip>
  73. </com-attachment>
  74. </template>
  75. </div>
  76. </el-form-item>
  77. <el-form-item label="关联商品" prop="goods">
  78. <div style="display: inline-block;">
  79. <div flex="cross:center">
  80. <div style="margin-left: 10px;">
  81. <com-dialog-select :multiple="false" @selected="goodsSelect" title="商品选择">
  82. <el-button type="text">选择商品</el-button>
  83. </com-dialog-select>
  84. </div>
  85. </div>
  86. </div>
  87. </el-form-item>
  88. <el-form-item prop="goods">
  89. <template>
  90. <div style="color: #ff4544;">只能添加一个商品</div>
  91. <div style="max-height: 300px;overflow-y: auto">
  92. <el-table :data="goods" :show-header="false" border>
  93. <el-table-column label="">
  94. <template slot-scope="scope">
  95. <div flex>
  96. <div style="padding-right: 10px;flex-grow: 0">
  97. <com-image mode="aspectFill" :src="scope.row.cover_pic"></com-image>
  98. </div>
  99. <div style="flex-grow: 1;">
  100. <com-ellipsis :line="2">{{scope.row.name}}
  101. </com-ellipsis>
  102. </div>
  103. <div style="flex-grow: 0;">
  104. <el-button @click="deleteGoods(scope.$index)" type="text" circle size="mini">
  105. <el-tooltip class="item" effect="dark" content="删除" placement="top">
  106. <img src="resources/img/mall/del.png" alt="">
  107. </el-tooltip>
  108. </el-button>
  109. </div>
  110. </div>
  111. </template>
  112. </el-table-column>
  113. </el-table>
  114. </div>
  115. </template>
  116. </el-form-item>
  117. <el-form-item label="活动课程" prop="course_id">
  118. <div style="display: inline-block;">
  119. <div flex="cross:center">
  120. <el-button type="text" @click="showSelectCourseProp">选择课程</el-button>
  121. <el-dialog width="650" title="选择课程" :visible.sync="showSelectCourse":offset="380">
  122. <div class="input-item">
  123. <el-input @keyup.enter.native="search" size="small" placeholder="请输入课程名称" v-model="keyword" clearable @clear="search">
  124. <el-button slot="append" icon="el-icon-search" @click="search"></el-button>
  125. </el-input>
  126. </div>
  127. <el-table ref="multipleTable" :data="course_list" tooltip-effect="dark" style="width: 100%" @select="handleSelection" @select-all="handleSelectionAll" v-loading="listLoading">
  128. <el-table-column type="selection" width="55"> </el-table-column>
  129. <el-table-column max-width="50" property="id" label="课程ID">
  130. <template slot-scope="scope">
  131. <div size="small">{{scope.row.id}}</div>
  132. </template>
  133. </el-table-column>
  134. <el-table-column label="课程名称" prop="course_name" min-width="80" align="center">
  135. <template slot-scope="scope">
  136. <div size="small" v-if="scope.row.logo" class="flex-y-center flex-x-center">
  137. <com-image style="border-radius: 22px;" width='45px' height='45px' :src=scope.row.logo></com-image>
  138. <span style="padding-left: 10px;">{{scope.row.course_name}}</span>
  139. </div>
  140. </template>
  141. </el-table-column>
  142. <el-table-column min-width="50" property="price" label="售价">
  143. <template slot-scope="scope">
  144. <div size="small">{{scope.row.price}}</div>
  145. </template>
  146. </el-table-column>
  147. <el-table-column min-width="50" property="cate_name" label="课程分类">
  148. <template slot-scope="scope">
  149. <div size="small">{{scope.row.cate_name}}</div>
  150. </template>
  151. </el-table-column>
  152. </el-table>
  153. <div style="text-align: right;margin: 20px 0;">
  154. <el-pagination @current-change="pagination" background layout="prev, pager, next" :page-count="pageCount"></el-pagination>
  155. </div>
  156. <div style="margin-top: 20px" align="right">
  157. <el-button @click="cancelSelected">取消</el-button>
  158. <el-button type="primary" @click="yseCourseSelected">确定</el-button>
  159. </div>
  160. <el-button slot="reference">请选择课程</el-button>
  161. </el-dialog>
  162. <span style="margin-left: 15px;">已选择课程:{{activityCourse.length}} 个</span>
  163. </div>
  164. </div>
  165. </el-form-item>
  166. <el-form-item prop="courses">
  167. <template>
  168. <div style="max-height: 300px;overflow-y: auto">
  169. <el-table :data="activityCourse" :show-header="false" border>
  170. <el-table-column label="">
  171. <template slot-scope="scope">
  172. <div flex>
  173. <div style="padding-right: 10px;flex-grow: 0">
  174. <com-image mode="aspectFill" :src="scope.row.logo"></com-image>
  175. </div>
  176. <div style="flex-grow: 1;">
  177. <com-ellipsis :line="2">{{scope.row.course_name}}
  178. </com-ellipsis>
  179. </div>
  180. <div style="flex-grow: 0;">
  181. <el-button @click="deleteCourse(scope.$index)" type="text" circle size="mini">
  182. <el-tooltip class="item" effect="dark" content="删除" placement="top">
  183. <img src="resources/img/mall/del.png" alt="">
  184. </el-tooltip>
  185. </el-button>
  186. </div>
  187. </div>
  188. </template>
  189. </el-table-column>
  190. </el-table>
  191. </div>
  192. </template>
  193. </el-form-item>
  194. </el-col>
  195. </el-row>
  196. </el-form>
  197. </div>
  198. <el-button class="button-item" style="margin-bottom: 15px;" type="primary" @click="submitForm('ruleForm')" size="small">保存
  199. </el-button>
  200. </el-card>
  201. </div>
  202. <script src="/resources/js/Sortable.min.js"></script>
  203. <script src="/resources/unpkg/vuedraggable@2.18.1/dist/vuedraggable.umd.min.js"></script>
  204. <script>
  205. const app = new Vue({
  206. el: '#app',
  207. data() {
  208. return {
  209. form: {},
  210. cardLoading: false,
  211. btnLoading: false,
  212. listLoading: false,
  213. formLoading: false,
  214. // 选择课程中的课程列表数据
  215. course_list: [{
  216. date: '2016-05-02',
  217. name: '王小虎',
  218. address: '上海市普陀区金沙江路 1518 弄'
  219. }, {
  220. date: '2016-05-04',
  221. name: '王小虎',
  222. address: '上海市普陀区金沙江路 1518 弄'
  223. }, {
  224. date: '2016-05-01',
  225. name: '王小虎',
  226. address: '上海市普陀区金沙江路 1518 弄'
  227. }, {
  228. date: '2016-05-03',
  229. name: '王小虎',
  230. address: '上海市普陀区金沙江路 1518 弄'
  231. }],
  232. goods: [],
  233. ruleForm: {
  234. banners: [],
  235. course_id: [],
  236. logo: '',
  237. },
  238. rules: {
  239. name: [{
  240. required: true,
  241. message: '请输入课程名称',
  242. trigger: 'change'
  243. }, ],
  244. select_number: [{
  245. required: true,
  246. message: '请填写课程任选数量',
  247. trigger: 'change'
  248. }, ],
  249. // banners: [{
  250. // required: true,
  251. // message: '请上传轮播图',
  252. // trigger: 'change'
  253. // }, ],
  254. // goods: [{
  255. // required: true,
  256. // message: '请选择关联商品',
  257. // trigger: 'change'
  258. // }],
  259. course_id: [{
  260. required: true,
  261. message: '请选择活动课程',
  262. trigger: 'change'
  263. }]
  264. },
  265. page: 1,
  266. pageCount: 0,
  267. keyword: '',
  268. selectedCourseNumber: 0,
  269. // 弹窗弹出时的课程id
  270. old_course_id: [],
  271. showSelectCourse: false, //选择课程弹框
  272. shortActivityCourse: [], //暂存活动选中的课程
  273. activityCourse: [], //活动保存的课程
  274. };
  275. },
  276. mounted() {
  277. this.getCourseList();
  278. this.loadData();
  279. },
  280. methods: {
  281. // 关闭弹出层
  282. pclose() {
  283. this.$refs['popover'].doClose();
  284. },
  285. // 选择课程弹出框弹出时的回调
  286. popoverShow() {
  287. // console.log('show ... ');
  288. this.old_course_id = this.ruleForm.course_id;
  289. },
  290. search() {
  291. this.page = 1;
  292. this.getCourseList();
  293. },
  294. pagination(currentPage) {
  295. let self = this;
  296. self.page = currentPage;
  297. self.getCourseList();
  298. },
  299. loadData() {
  300. var params = {};
  301. var id = getQuery('id');
  302. if (id) {
  303. params = {
  304. r: 'course/activity/edit',
  305. id: id,
  306. };
  307. } else {
  308. params = {
  309. r: 'course/activity/edit',
  310. };
  311. }
  312. var self = this;
  313. request({
  314. params: params,
  315. method: 'get'
  316. }).then(e => {
  317. console.log(e)
  318. this.cardLoading = false;
  319. if (id) {
  320. if(e.data.data.activity_info!=''){
  321. self.ruleForm = e.data.data.activity_info;
  322. self.goods = e.data.data.goods;
  323. }
  324. self.activityCourse = e.data.data.activity_info.selected_course_info;
  325. self.selectedCourseNumber = self.ruleForm.course_id.length;
  326. }
  327. }).catch(e => {
  328. console.log(e);
  329. });
  330. },
  331. // 课程弹框
  332. showSelectCourseProp(){
  333. this.showSelectCourse = true;
  334. // this.page = 1;
  335. this.getCourseList();
  336. },
  337. // 获取课程列表
  338. getCourseList() {
  339. this.listLoading = true;
  340. var self = this;
  341. self.shortActivityCourse = [];
  342. request({
  343. params: {
  344. r: 'course/activity/course-list',
  345. page: self.page,
  346. course_name: self.keyword
  347. },
  348. method: 'get'
  349. }).then(e => {
  350. self.listLoading = false;
  351. if (0 == e.data.code) {
  352. self.course_list = e.data.data.list;
  353. self.pageCount = e.data.data.page_count;
  354. var checkArr = [];
  355. e.data.data.list.forEach((item) => {
  356. var index = self.ruleForm.course_id.indexOf(item.id);
  357. if (index != -1) {
  358. checkArr.push(item);
  359. }
  360. });
  361. // self.$nextTick(() => {
  362. // if (checkArr.length) {
  363. // checkArr.forEach((item) => {
  364. // self.$refs.multipleTable.toggleRowSelection(item);
  365. // self.shortActivityCourse.push(item);
  366. // });
  367. // }
  368. // })
  369. } else {
  370. self.$message.error(e.data.msg);
  371. }
  372. }).catch(e => {
  373. self.$message.error('网络错误');
  374. });
  375. },
  376. // 课程选中(单个选中)
  377. handleSelection(selection, val) {
  378. this.shortActivityCourse = selection;
  379. },
  380. // 课程选中(全选)
  381. handleSelectionAll(selection) {
  382. this.shortActivityCourse = selection;
  383. },
  384. // 取消选择课程
  385. cancelSelected() {
  386. this.showSelectCourse = false;
  387. },
  388. // 确定添加课程
  389. yseCourseSelected(){
  390. this.showSelectCourse = false;
  391. console.info(this.course_list);
  392. this.course_list.forEach(v => { //删除这一页选中的数据
  393. let index = this.activityCourse.findIndex(vv => vv.id == v.id);
  394. if(index != -1){
  395. this.activityCourse.splice(index,1);
  396. }
  397. })
  398. console.info(this.shortActivityCourse);
  399. this.activityCourse.push(...this.shortActivityCourse);
  400. this.ruleForm.course_id = [];
  401. this.activityCourse.forEach(v => {
  402. this.ruleForm.course_id.push(v.id);
  403. });
  404. },
  405. deleteCourse(index){
  406. // console.info(this.ruleForm.course_id);
  407. // console.info(this.activityCourse);
  408. this.activityCourse.splice(index,1);
  409. this.ruleForm.course_id.splice(index,1);
  410. },
  411. submitForm(formName) {
  412. let self = this;
  413. this.$refs[formName].validate((valid, obj) => {
  414. if (valid) {
  415. if (!self.ruleForm.banners.length) {
  416. self.$message.error('请上传轮播图');
  417. return false;
  418. }
  419. if (!self.ruleForm.goods_id) {
  420. self.$message.error('请选择关联商品');
  421. return false;
  422. }
  423. // self.formLoading = true;
  424. var params = {};
  425. var id = getQuery('id');
  426. if (id) {
  427. params = {
  428. r: 'course/activity/edit',
  429. };
  430. } else {
  431. params = {
  432. r: 'course/activity/edit',
  433. };
  434. }
  435. request({
  436. params: params,
  437. method: 'post',
  438. data: self.ruleForm
  439. }).then(e => {
  440. self.formLoading = false;
  441. if (e.data.code == 0) {
  442. this.$message({
  443. message: e.data.msg,
  444. type: 'success'
  445. });
  446. setTimeout(function() {
  447. navigateTo({ r: 'course/activity/index' })
  448. }, 1000);
  449. } else {
  450. self.$message.error(e.data.msg);
  451. }
  452. }).catch(e => {
  453. self.$message.error(e.data.msg);
  454. self.btnLoading = false;
  455. });
  456. } else {
  457. var msg = '';
  458. for (let index in obj) {
  459. msg = msg + '*' + obj[index][0].message + ' ';
  460. }
  461. this.$message({
  462. message: msg,
  463. type: 'error'
  464. });
  465. return false;
  466. }
  467. });
  468. },
  469. goodsSelect(list) {
  470. if (this.goods.length > 0) {
  471. this.$message.error('只能选择一个商品');
  472. return null;
  473. }
  474. this.ruleForm.goods_id = list.id;
  475. this.goods.push({
  476. id: list.id,
  477. name: list.name,
  478. cover_pic: list.cover_pic,
  479. });
  480. },
  481. deleteGoods(index) {
  482. this.ruleForm.goods_id = null;
  483. this.goods.splice(index, 1);
  484. },
  485. updatePicUrl(e, params) {
  486. this.ruleForm.banners.push(e[0].url);
  487. this.$forceUpdate();
  488. },
  489. delPic(index) {
  490. this.ruleForm.banners.splice(index, 1)
  491. },
  492. // 轮播图
  493. picUrl(e) {
  494. if (e.length) {
  495. let self = this;
  496. e.forEach(function(item, index) {
  497. if (self.ruleForm.banners.length >= 99) {
  498. return;
  499. }
  500. self.ruleForm.banners.push(item.url);
  501. });
  502. }
  503. },
  504. // 选中图片
  505. selectedImg(e) {
  506. console.log(e);
  507. this.ruleForm.logo = e[0].url;
  508. },
  509. }
  510. });
  511. </script>
  512. <style>
  513. .el-popover{
  514. padding: 30px;
  515. }
  516. .form-body {
  517. padding: 20px;
  518. background-color: #fff;
  519. margin-bottom: 20px;
  520. padding-right: 20%;
  521. min-width: 900px;
  522. }
  523. .form-body .el-form-item {
  524. padding-right: 25%;
  525. min-width: 850px;
  526. }
  527. .form-button {
  528. margin: 0;
  529. }
  530. .form-button .el-form-item__content {
  531. margin-left: 0 !important;
  532. }
  533. .button-item {
  534. padding: 9px 25px;
  535. }
  536. .check-group {
  537. font-size: 14px !important;
  538. }
  539. .check-group .el-col {
  540. display: flex;
  541. }
  542. .check-group .el-input {
  543. margin: 0 5px;
  544. }
  545. .check-group .el-col .el-checkbox {
  546. display: flex;
  547. align-items: center;
  548. }
  549. .check-group .el-col .el-input {
  550. width: 100px;
  551. }
  552. .check-group .el-col .el-input .el-input__inner {
  553. height: 30px;
  554. width: 100px;
  555. }
  556. .el-checkbox-group .el-col {
  557. margin-bottom: 10px;
  558. }
  559. .inp {
  560. width: 140px;
  561. }
  562. .inp .el-input__inner {
  563. border-radius: 4px 0 0 4px;
  564. }
  565. .inp2 {
  566. width: 60px;
  567. }
  568. .inp-text {
  569. background: #EFEFEF;
  570. border: 1px solid #E3E2E5;
  571. font-size: 15px;
  572. padding: 0px 15px;
  573. border-radius: 0 4px 4px 0;
  574. height: 32px;
  575. }
  576. /* flex公共样式 */
  577. .flex {
  578. display: -webkit-box;
  579. display: -webkit-flex;
  580. display: flex;
  581. }
  582. .flex-x-center {
  583. display: -webkit-box;
  584. display: -webkit-flex;
  585. display: flex;
  586. -webkit-box-pack: center;
  587. -webkit-justify-content: center;
  588. -ms-flex-pack: center;
  589. justify-content: center;
  590. }
  591. .flex-x-between {
  592. display: -webkit-box;
  593. display: -webkit-flex;
  594. display: flex;
  595. -webkit-box-pack: space-between;
  596. -webkit-justify-content: space-between;
  597. -ms-flex-pack: space-between;
  598. justify-content: space-between;
  599. }
  600. .flex-y-center {
  601. display: -webkit-box;
  602. display: -webkit-flex;
  603. display: flex;
  604. -webkit-box-align: center;
  605. -webkit-align-items: center;
  606. -ms-flex-align: center;
  607. -ms-grid-row-align: center;
  608. align-items: center;
  609. }
  610. .flex-y-bottom {
  611. display: -webkit-box;
  612. display: -webkit-flex;
  613. display: flex;
  614. -webkit-box-align: end;
  615. -webkit-align-items: flex-end;
  616. -ms-flex-align: end;
  617. -ms-grid-row-align: flex-end;
  618. align-items: flex-end;
  619. }
  620. .pic-url-remark {
  621. font-size: 13px;
  622. color: #c9c9c9;
  623. margin-bottom: 12px;
  624. }
  625. .add-image-btn {
  626. width: 100px;
  627. height: 100px;
  628. color: #419EFB;
  629. border: 1px solid #e2e2e2;
  630. cursor: pointer;
  631. }
  632. .del-btn{
  633. position: absolute;
  634. right: -14px;
  635. top: -14px;
  636. }
  637. </style>