add.blade.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. @extends('layouts.base')
  2. @section('title', '活动管理')
  3. @section('content')
  4. <link rel="stylesheet" type="text/css" href="{{static_url('yunshop/goods/vue-ohter.css')}}"/>
  5. <link rel="stylesheet" href="{{static_url('css/public-number.css')}}">
  6. <link rel="stylesheet" type="text/css" href="{{static_url('yunshop/goods/vue-goods1.css')}}"/>
  7. <style>
  8. .main-panel{
  9. margin-top:50px;
  10. }
  11. .add-goods{
  12. width: 120px;
  13. height: 120px;
  14. border: dashed 1px #dde2ee;
  15. display:flex;
  16. flex-direction:column;
  17. justify-content:center;
  18. align-items:center;
  19. }
  20. .num{
  21. width:60px;
  22. height:40px;
  23. }
  24. .num .el-input__inner{
  25. width:60px;
  26. height:40px;
  27. }
  28. </style>
  29. <div id='re_content' >
  30. <div class="vue-crumbs">
  31. <a @click="goback">活动列表</a> > 添加活动
  32. </div>
  33. <div class="con">
  34. <div class="setting">
  35. <div class="block">
  36. <el-form label-width="15%">
  37. <div class="title" style="justify-content: space-between;"><div style="display:flex;align-items:center;"><span style="width: 4px;height: 18px;background-color: #29ba9c;margin-right:15px;display:inline-block;"></span><b>添加活动</b><span></div></div>
  38. <el-form-item label="活动名称" >
  39. <el-input placeholder="如:一口价20元3件" v-model="form.activity_name" type="text" style="width:50%;" ></el-input>
  40. </el-form-item>
  41. <el-form-item label="活动时间" >
  42. <el-date-picker
  43. v-model="form.start_at"
  44. type="datetime"
  45. format="yyyy-MM-dd HH:mm:ss"
  46. value-format="timestamp"
  47. placeholder="选择日期">
  48. </el-date-picker>
  49. <el-date-picker
  50. v-model="form.end_at"
  51. type="datetime"
  52. format="yyyy-MM-dd HH:mm:ss"
  53. value-format="timestamp"
  54. placeholder="选择日期">
  55. </el-date-picker>
  56. </el-form-item>
  57. <el-form-item label="活动详情" >
  58. <el-input v-model="form.pack_price" type="text" style="width:20%;"></el-input><span style="margin-left:10px;margin-right:10px;">元</span>,
  59. 任选
  60. <el-input v-model="form.goods_count" type="text" style="width:20%;"></el-input><span style="margin-left:10px;">件</span>
  61. <div>如:指定活动商品,顾客可以花100元(不含运费)任选3件。</div>
  62. </el-form-item>
  63. <el-form-item label="活动商品" prop="goods_id">
  64. <div style="display:flex;flex-wrap: wrap;width:70%;">
  65. <div class="good" v-for="(item,index,key) in thumbList" style="width:120px;display:flex;margin-right:20px;flex-direction: column">
  66. <div class="img" style="position:relative;">
  67. <a style="color:#333;"><div style="width: 20px;height: 20px;background-color: #dde2ee;display:flex;align-items:center;justify-content:center; #999999;position:absolute;right:-10px;top:-10px;border-radius:50%;" @click="delGoods(item)">X</div></a>
  68. <img :src="item.thumb" style="width:120px;height:120px;">
  69. </div>
  70. <div style="display: -webkit-box;-webkit-box-orient: vertical;-webkit-line-clamp: 2;overflow: hidden;font-size:12px;">[[item.title]][ID:[[item.id]]]</div>
  71. </div>
  72. <div class="add-goods" @click="openGoods()" >
  73. <a style="font-size:32px;color: #999999;"><i class="el-icon-plus" ></i></a>
  74. <div style="color: #999999;">选择商品</div>
  75. </div>
  76. </div>
  77. <div style="width:60%;">只能选择平台自营、供应商、供应链、聚合供应链、应用市场商品!</div>
  78. </el-form-item>
  79. <el-form-item label="活动页展示规则" >
  80. <template>
  81. <el-radio-group v-model="form.rule">
  82. <el-radio label="0">默认文案</el-radio>
  83. <el-radio label="1">自定义图片</el-radio>
  84. </el-radio-group>
  85. </template>
  86. <div v-show="form.rule=='0'">根据优惠设置自动生成规则文案,在活动页顶部展示</div>
  87. <div v-show="form.rule=='1'">用自制的图片在活动页顶部展示(无默认文案)</div>
  88. </el-form-item>
  89. <el-form-item label=" " >
  90. <span style="color:red;cursor:pointer;" @click="openDia">查看示例</span>
  91. </el-form-item>
  92. <upload-img :upload-show="uploadShow" :name="chooseImgName" @replace="changeProp" @sure="sureImg"></upload-img>
  93. <el-form-item label="" prop="head_img_url" v-if="form.rule=='1'">
  94. <div class="upload-box" @click="openUpload('custom_thumb')" v-if="!form.custom_thumb_url">
  95. <i class="el-icon-plus" style="font-size:32px"></i>
  96. </div>
  97. <div @click="openUpload('custom_thumb')" class="upload-boxed" v-if="form.custom_thumb_url" >
  98. <img :src="form.custom_thumb_url" alt="" style="width:150px;height:150px;border-radius: 5px;cursor: pointer;">
  99. <div class="upload-boxed-text">点击重新上传</div>
  100. </div>
  101. <div class="tip">建议尺寸:750*1334 , 为长方形图片</div>
  102. </el-form-item>
  103. <div style="position: absolute;right: 100px;top: 50px;">
  104. <img :src="normal" style="width: 290px;height: 499px;">
  105. </div>
  106. </el-form>
  107. <el-dialog
  108. center
  109. title="示例图片"
  110. :visible.sync="dialogVisible"
  111. width="60%">
  112. <div style="display:flex;justify-content: center;">
  113. <img :src="normal" style="width:45%;">
  114. <img :src="custom" style="width:45%;">
  115. </div>
  116. </el-dialog>
  117. <el-dialog :visible.sync="goodsShow" width="60%" center title="选择商品">
  118. <div>
  119. <div style="text-align: center">
  120. <el-input v-model="search_form.keyword" style="width:80%"></el-input>
  121. <el-button type="primary" @click="searchGoods()" style="margin-left:20px;">搜索</el-button>
  122. </div>
  123. <el-table :data="goods_list" style="width: 100%;height:500px;overflow:auto"
  124. ref="caseTable"
  125. @select="handleTableSelect"
  126. @select-all="handleTableSelectAll"
  127. >
  128. <el-table-column type="selection" width="55" :selectable='isDisabled'></el-table-column>
  129. <el-table-column label="ID" prop="id" align="center" ></el-table-column>
  130. <el-table-column label="商品信息">
  131. <template slot-scope="scope">
  132. <div v-if="scope.row" style="display:flex;align-items: center;justify-content:flex-start;">
  133. <img v-if="scope.row.thumb" :src="scope.row.thumb" style="width:50px;height:50px"></img>
  134. <div style="margin-left:10px">[[scope.row.title]]</div>
  135. </div>
  136. </template>
  137. </el-table-column>
  138. <!-- <el-table-column prop="refund_time" label="操作" align="center" >
  139. <template slot-scope="scope">
  140. <el-button @click="sureGoods(scope.row)" v-if="!scope.row.checked">
  141. 选择
  142. </el-button>
  143. <el-button disabled v-if="scope.row.checked">
  144. 选择
  145. </el-button>
  146. </template>
  147. </el-table-column> -->
  148. </el-table>
  149. </div>
  150. <el-row>
  151. <el-col :span="24" align="right" migra style="padding:15px 5% 15px 0" v-loading="loading">
  152. <el-pagination background layout="prev, pager, next" @current-change="currentChange" :total="page_total"
  153. :page-size="page_size" :current-page="current_page"></el-pagination>
  154. </el-col>
  155. </el-row>
  156. <span slot="footer" class="dialog-footer">
  157. <el-button @click="goodsShow = false">取 消</el-button>
  158. <el-button type="primary" @click="sureGoods">确 定 </el-button>
  159. </span>
  160. </el-dialog>
  161. <div class="confirm-btn">
  162. <el-button @click="submit" type="primary">提交</el-button>
  163. </div>
  164. </div>
  165. </template>
  166. </div>
  167. </div>
  168. </div>
  169. @include('public.admin.uploadImg')
  170. <script>
  171. const custom = `{!! resource_get('plugins/pack-fixed-price/assets/image/custom.png') !!}`;
  172. const normal = `{!! resource_get('plugins/pack-fixed-price/assets/image/normal.png') !!}`;
  173. var vm = new Vue({
  174. el: "#re_content",
  175. delimiters: ['[[', ']]'],
  176. data() {
  177. let info={!!json_encode($data?:'{}') !!}
  178. return {
  179. dialogVisible:false,
  180. custom:custom,
  181. normal:normal,
  182. info:info,
  183. id:info.id?info.id:'',
  184. loading:false,
  185. page_total:0,
  186. page_size:0,
  187. current_page:0,
  188. goodsShow:false,
  189. goods_list:[],
  190. uploadShow:false,
  191. chooseImgName:'',
  192. uploadListShow:false,
  193. chooseImgListName:'',
  194. thumbList:[],
  195. search_form:{},
  196. // 商品多选
  197. choosed_goods:[],
  198. choosed_goods_id:[],
  199. re_choosed_goods:[],
  200. last_row:[],
  201. form:{
  202. activity_name:info.activity_name?info.activity_name:'',
  203. start_at:info.start_at?info.start_at*1000:'',
  204. end_at:info.end_at?info.end_at*1000:'',
  205. pack_price:info.pack_price?info.pack_price:'',
  206. goods_count:info.goods_count?info.goods_count:'',
  207. rule:info.hasOwnProperty('rule')?String(info.rule):'0',
  208. custom_thumb:info.custom_thumb?info.custom_thumb:'',
  209. custom_thumb_url:info.custom_thumb_url?info.custom_thumb_url:'',
  210. goods_id:[]
  211. },
  212. }
  213. },
  214. mounted () {
  215. if(this.info.hasOwnProperty('goods')){
  216. this.info.goods.forEach((item,index)=>{
  217. this.thumbList.push(item)
  218. this.form.goods_id.push(item.id)
  219. })
  220. }
  221. },
  222. methods: {
  223. goback(){
  224. window.history.go(-1)
  225. },
  226. openDia(){
  227. this.dialogVisible=true
  228. },
  229. openUpload(str) {
  230. this.chooseImgName = str;
  231. this.uploadShow = true;
  232. },
  233. changeProp(val) {
  234. if(val == true) {
  235. this.uploadShow = false;
  236. }
  237. else {
  238. this.uploadShow = true;
  239. }
  240. },
  241. sureImg(name,image,image_url) {
  242. this.form[name] = image;
  243. this.form[name+'_url'] = image_url;
  244. },
  245. openGoods() {
  246. this.goodsShow = true;
  247. this.choosed_goods = JSON.parse(JSON.stringify(this.thumbList));
  248. this.choosed_goods_id = this.choosed_goods.map((item) => {
  249. return item.id;
  250. });
  251. if(this.search_form.keyword) {
  252. this.searchGoods();
  253. }
  254. if(this.goods_list.length>0) {
  255. this.$refs.caseTable.clearSelection();
  256. }
  257. this.choosed_goods.forEach((item,index)=> {
  258. this.goods_list.forEach((item1,index1) => {
  259. if(item1.id == item.id)
  260. this.$refs.caseTable.toggleRowSelection(item1,true);
  261. })
  262. })
  263. console.log(this.choosed_goods)
  264. },
  265. currentChange(val) {
  266. this.loading = true;
  267. this.$http.post('{!! yzWebFullUrl('plugin.pack-fixed-price.admin.goods.get-list') !!}',{page:val,search:this.search_form.keyword}).then(function (response){
  268. let datas = response.data.data;
  269. this.page_total = datas.total;
  270. this.goods_list = datas.data;
  271. this.page_size = datas.per_page;
  272. this.current_page = datas.current_page;
  273. this.loading = false;
  274. this.goods_list.forEach((item,index)=>{
  275. if(this.form.goods_id==item.id){
  276. item.checked=true
  277. }else{
  278. item.checked=false
  279. }
  280. })
  281. this.goods_list.push({})
  282. this.goods_list.splice(this.goods_list.length-1,1)
  283. },function (response) {
  284. console.log(response);
  285. this.loading = false;
  286. }
  287. );
  288. },
  289. delGoods(item){
  290. if(this.id){
  291. this.$http.post('{!! yzWebFullUrl('plugin.pack-fixed-price.admin.activity.delete-relation') !!}',{'activity_id':this.id,'goods_id':item.id}).then(function (response){
  292. if (response.data.result) {
  293. this.$message({message: response.data.msg,type: 'success'});
  294. this.thumbList.forEach((list,index)=>{
  295. if(list.id==item.id){
  296. this.goods_list.forEach((obj,index)=>{
  297. if(obj.id==item.id){
  298. obj.checked=false
  299. }
  300. })
  301. this.thumbList.splice(index,1)
  302. this.form.goods_id.splice(index,1)
  303. }
  304. })
  305. this.goods_list.push({})
  306. this.goods_list.splice(this.goods_list.length-1,1)
  307. }else {
  308. this.$message({message: response.data.msg,type: 'error'});
  309. }
  310. ;
  311. },function (response) {
  312. this.$message({message: response.data.msg,type: 'error'});
  313. loading.close();
  314. })
  315. }else{
  316. this.thumbList.forEach((list,index)=>{
  317. if(list.id==item.id){
  318. this.goods_list.forEach((obj,index)=>{
  319. if(obj.id==item.id){
  320. obj.checked=false
  321. }
  322. })
  323. this.thumbList.splice(index,1)
  324. this.form.goods_id.splice(index,1)
  325. }
  326. })
  327. this.goods_list.push({})
  328. this.goods_list.splice(this.goods_list.length-1,1)
  329. }
  330. },
  331. searchGoods() {
  332. if(!this.search_form.keyword){
  333. this.$message({message: '请输入关键词搜索',type: 'error'});
  334. return
  335. }
  336. let that = this;
  337. this.$http.post('{!! yzWebFullUrl('plugin.pack-fixed-price.admin.goods.get-list') !!}',{search:this.search_form.keyword}).then(response => {
  338. if (response.data.result) {
  339. let data = response.data.data;
  340. this.page_total = data.total;
  341. this.goods_list = data.data;
  342. this.page_size = data.per_page;
  343. this.current_page = data.current_page;
  344. this.goods_list.forEach((item,index)=>{
  345. if(this.form.goods_id.includes(item.id)){
  346. item.checked=true
  347. }else{
  348. item.checked=false
  349. }
  350. })
  351. setTimeout(()=> {
  352. if(this.goods_list.length>0) {
  353. this.$refs.caseTable.clearSelection();
  354. }
  355. this.choosed_goods.forEach((item,index)=> {
  356. this.goods_list.forEach((item1,index1) => {
  357. if(item1.id == item.id) {
  358. console.log(item1.id)
  359. this.$refs.caseTable.toggleRowSelection(item1,true);
  360. }
  361. })
  362. })
  363. },100)
  364. this.$forceUpdate()
  365. } else {
  366. this.$message({message: response.data.msg,type: 'error'});
  367. }
  368. },response => {
  369. this.$message({message: response.data.msg,type: 'error'});
  370. });
  371. },
  372. // sureGoods(item) {
  373. // if(this.id){
  374. // this.$http.post('{!! yzWebFullUrl('plugin.pack-fixed-price.admin.activity.add-relation') !!}',{'activity_id':this.id,'goods_id':item.id}).then(function (response){
  375. // if (response.data.result) {
  376. // this.$message({message: response.data.msg,type: 'success'});
  377. // item.checked=true
  378. // this.thumbList.push(item)
  379. // this.form.goods_id.push(item.id)
  380. // this.goods_list.push({})
  381. // this.goods_list.splice(this.goods_list.length-1,1)
  382. // this.goods_list.forEach((item,index)=>{
  383. // if(this.form.goods_id.includes(item.id)){
  384. // item.checked=true
  385. // }else{
  386. // item.checked=false
  387. // }
  388. // })
  389. // this.goods_list.push({})
  390. // this.goods_list.splice(this.goods_list.length-1,1)
  391. // this.goodsShow=false
  392. // }else {
  393. // this.$message({message: response.data.msg,type: 'error'});
  394. // }
  395. // ;
  396. // },function (response) {
  397. // this.$message({message: response.data.msg,type: 'error'});
  398. // loading.close();
  399. // })
  400. // }else{
  401. // if(item.status==1){
  402. // this.$message({message:'商品已关联其他活动',type: 'error'});
  403. // return
  404. // }else{
  405. // item.checked=true
  406. // this.thumbList.push(item)
  407. // this.form.goods_id.push(item.id)
  408. // // this.goods_list.push({})
  409. // // this.goods_list.splice(this.goods_list.length-1,1)
  410. // this.goods_list.forEach((item,index)=>{
  411. // if(this.form.goods_id.includes(item.id)){
  412. // item.checked=true
  413. // }else{
  414. // item.checked=false
  415. // }
  416. // })
  417. // this.goods_list.push({})
  418. // this.goods_list.splice(this.goods_list.length-1,1)
  419. // this.goodsShow=false
  420. // }
  421. // }
  422. // },
  423. sureGoods() {
  424. if(this.id){
  425. let new_list = [];
  426. this.choosed_goods.forEach((item,index)=> {
  427. let is_true = false;
  428. this.thumbList.some((item1,index1) => {
  429. if(item1.id == item.id){
  430. is_true = true;
  431. return true
  432. }
  433. })
  434. if(!is_true) {
  435. new_list.push(item)
  436. }
  437. })
  438. console.log(new_list)
  439. for(let i=0;i<new_list.length;i++) {
  440. this.$http.post('{!! yzWebFullUrl('plugin.pack-fixed-price.admin.activity.add-relation') !!}',{'activity_id':this.id,'goods_id':new_list[i].id}).then(function (response){
  441. if (response.data.result) {
  442. this.$message({message: response.data.msg,type: 'success'});
  443. this.thumbList.push(new_list[i])
  444. this.form.goods_id.push(new_list[i].id)
  445. // this.goods_list.push({})
  446. // this.goods_list.splice(this.goods_list.length-1,1)
  447. this.goods_list.forEach((item,index)=>{
  448. if(this.form.goods_id.includes(item.id)){
  449. item.checked=true
  450. }else{
  451. item.checked=false
  452. }
  453. })
  454. }else {
  455. this.$message({message: response.data.msg,type: 'error'});
  456. }
  457. ;
  458. },function (response) {
  459. this.$message({message: response.data.msg,type: 'error'});
  460. loading.close();
  461. })
  462. if(i==new_list.length-1) {
  463. this.goodsShow=false
  464. }
  465. }
  466. }else{
  467. // this.current_value[this.value.goods_type] = [...list];
  468. this.choosed_goods.forEach((item,index) => {
  469. item.checked = true;
  470. })
  471. this.thumbList = [...this.choosed_goods]
  472. this.form.goods_id = [];
  473. this.thumbList.forEach((item,index) => {
  474. this.form.goods_id.push(item.id)
  475. })
  476. console.log(this.form.goods_id)
  477. // this.thumbList = [...this.choosed_goods]
  478. this.goodsShow = false;
  479. }
  480. },
  481. submit() {
  482. // this.form.goods_id=this.form.goods_id.join(',')
  483. let goods_id=this.form.goods_id.join(',')
  484. let json=Object.assign({},this.form)
  485. json.start_at=String(json.start_at).slice(0,10)
  486. json.end_at=String(json.end_at).slice(0,10)
  487. json.goods_id=goods_id;
  488. this.$http.post('{!! yzWebFullUrl('plugin.pack-fixed-price.admin.activity.add') !!}',{'data':json,'id':this.id}).then(function (response){
  489. if (response.data.result) {
  490. this.$message({message: response.data.msg,type: 'success'});
  491. window.location.href='{!! yzWebFullUrl('plugin.pack-fixed-price.admin.activity.index') !!}'
  492. }else {
  493. this.$message({message: response.data.msg,type: 'error'});
  494. }
  495. ;
  496. },function (response) {
  497. this.$message({message: response.data.msg,type: 'error'});
  498. })
  499. },
  500. handleTableSelect(sel,row) {
  501. console.log(sel)
  502. console.log(row)
  503. console.log(row.id);
  504. if(!row.checked) { //选中
  505. this.choosed_goods.push(row);
  506. this.choosed_goods_id.push(row.id);
  507. }
  508. else {
  509. this.choosed_goods_id= this.choosed_goods_id.filter(function(item) {
  510. return item != row.id
  511. });
  512. this.choosed_goods = this.choosed_goods.filter(function(item) {
  513. return item.id != row.id
  514. });
  515. }
  516. this.goods_list.forEach((item,index) => {
  517. if(item.id == row.id) {
  518. this.goods_list[index].checked = this.goods_list[index].checked== true?false:true
  519. }
  520. })
  521. console.log(this.choosed_goods)
  522. },
  523. handleTableSelectAll(sel) {
  524. console.log(sel)
  525. if(sel.length>0) {
  526. this.choosed_goods = sel;
  527. this.choosed_goods_id = sel.map((item) => {
  528. return item.id;
  529. });
  530. }
  531. else {
  532. this.choosed_goods = [];
  533. this.selectedRowKeys = [];
  534. }
  535. console.log(this.choosed_goods)
  536. },
  537. isDisabled(row){
  538. if(row.status == '1'){
  539. return 0;
  540. }
  541. return 1;
  542. },
  543. },
  544. });
  545. </script>
  546. @endsection