add_rank.blade.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  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;">
  38. <div style="display:flex;align-items:center;"><span
  39. style="width: 4px;height: 18px;background-color: #29ba9c;margin-right:15px;display:inline-block;"></span><b>添加榜单</b>
  40. </div>
  41. </div>
  42. <el-form-item label="榜单名称">
  43. <el-input v-model="form.name" type="text" style="width:50%;"></el-input>
  44. </el-form-item>
  45. <el-form-item label="榜单分类">
  46. <el-select v-model="form.category_id" placeholder="榜单分类"
  47. style="margin-right:16px;width:12%;" clearable>
  48. <el-option
  49. v-for="item in category"
  50. :key="item.id"
  51. :label="item.name"
  52. :value="item.id">
  53. </el-option>
  54. </el-select>
  55. </el-form-item>
  56. <el-form-item label="榜单显示商品数量">
  57. <el-input v-model="form.show_count" type="text" style="width:20%;"></el-input>
  58. </el-form-item>
  59. <el-form-item label="排行周期">
  60. <el-select v-model="form.rank_type" placeholder="排行周期"
  61. style="margin-right:16px;width:12%;">
  62. <el-option
  63. v-for="item in options"
  64. :key="item.id"
  65. :label="item.label"
  66. :value="item.id">
  67. </el-option>
  68. </el-select>
  69. </el-form-item>
  70. <el-form-item label="榜单商品" prop="goods_id">
  71. <span>指定商品</span>
  72. <div style="display:flex;flex-wrap: wrap;width:70%;">
  73. <div class="good" v-for="(item,index,key) in thumbList"
  74. style="width:120px;display:flex;margin-right:20px;flex-direction: column">
  75. <div class="img" style="position:relative;">
  76. <a style="color:#333;">
  77. <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%;"
  78. @click="delGoods(item)">X
  79. </div>
  80. </a>
  81. <img :src="item.thumb" style="width:120px;height:120px;">
  82. </div>
  83. <div style="display: -webkit-box;-webkit-box-orient: vertical;-webkit-line-clamp: 2;overflow: hidden;font-size:12px;">
  84. [[item.title]][ID:[[item.id]]]
  85. </div>
  86. </div>
  87. <div class="add-goods" @click="openGoods()">
  88. <a style="font-size:32px;color: #999999;"><i class="el-icon-plus"></i></a>
  89. <div style="color: #999999;">选择商品</div>
  90. </div>
  91. </div>
  92. </el-form-item>
  93. <el-form-item label="榜单商品" prop="catetory_id">
  94. <span>指定分类商品</span>
  95. <div class="form-group">
  96. <label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
  97. <div class="col-sm-8 col-xs-12 category-container">
  98. {!!$catetory_menus!!}
  99. </div>
  100. </div>
  101. <div class="form-group">
  102. <label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
  103. <div class="btn btn-info col-sm-2 col-xs-2 @if (isset($type) && $type == 'edit') editCategory @else plusCategory @endif">
  104. 添加分类
  105. </div>
  106. </div>
  107. </el-form-item>
  108. <el-form-item label="榜单商品" prop="filtering_id">
  109. <span>指定标签商品</span>
  110. @foreach ($filtering as $parent)
  111. <div class="form-group">
  112. <label class="col-xs-12 col-sm-3 col-md-1 control-label"></label>
  113. <div class="col-xs-12 chks">
  114. <label class="checkbox-inline">
  115. <input type="checkbox" onclick="quang(this)"
  116. value="{{$parent['id']}}"
  117. @if ( in_array( $parent['id'],$filtering_ids)) checked="true" @endif /> {{$parent['name']}}
  118. </label>
  119. </div>
  120. </div>
  121. <div class="form-group">
  122. <label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
  123. <div id="{{$parent['id']}}" class="col-sm-9 col-xs-12 chks">
  124. @foreach ($parent['value'] as $son)
  125. <label class="checkbox-inline">
  126. <input type="checkbox" class='duo' name="widgets[filtering][]"
  127. value="{{$son['id']}}"
  128. @if ( in_array( $son['id'],$filtering_ids)) checked="true" @endif /> {{$son['name']}}
  129. </label>
  130. @endforeach
  131. </div>
  132. </div>
  133. @endforeach
  134. </el-form-item>
  135. <upload-img :upload-show="uploadShow" :name="chooseImgName" @replace="changeProp"
  136. @sure="sureImg"></upload-img>
  137. <el-form-item label="榜单banner" prop="head_img_url">
  138. <div class="upload-box" @click="openUpload('banner')"
  139. v-if="!form.banner_url">
  140. <i class="el-icon-plus" style="font-size:32px"></i>
  141. </div>
  142. <div @click="openUpload('banner')" class="upload-boxed"
  143. v-if="form.banner">
  144. <img :src="form.banner_url" alt=""
  145. style="width:150px;height:150px;border-radius: 5px;cursor: pointer;">
  146. <div class="upload-boxed-text">点击重新上传</div>
  147. </div>
  148. <div class="tip">建议尺寸:750*1334 , 为长方形图片</div>
  149. </el-form-item>
  150. </el-form>
  151. <el-dialog :visible.sync="goodsShow" width="60%" center title="选择商品">
  152. <div>
  153. <div style="text-align: center">
  154. <el-input v-model="search_form.keyword" style="width:80%"></el-input>
  155. <el-button type="primary" @click="searchGoods()" style="margin-left:20px;">搜索
  156. </el-button>
  157. </div>
  158. <el-table :data="goods_list" style="width: 100%;height:500px;overflow:auto">
  159. <el-table-column label="ID" prop="id" align="center"></el-table-column>
  160. <el-table-column label="商品信息" align="center">
  161. <template slot-scope="scope">
  162. <div v-if="scope.row"
  163. style="display:flex;align-items: center;justify-content:center;">
  164. <img v-if="scope.row.thumb" :src="scope.row.thumb"
  165. style="width:50px;height:50px"></img>
  166. <div style="margin-left:10px">[[scope.row.title]]</div>
  167. </div>
  168. </template>
  169. </el-table-column>
  170. <el-table-column prop="refund_time" label="操作" align="center">
  171. <template slot-scope="scope">
  172. <el-button @click="sureGoods(scope.row)" v-if="!scope.row.checked">
  173. 选择
  174. </el-button>
  175. <el-button disabled v-if="scope.row.checked">
  176. 选择
  177. </el-button>
  178. </template>
  179. </el-table-column>
  180. </el-table>
  181. </div>
  182. <el-row>
  183. <el-col :span="24" align="right" migra style="padding:15px 5% 15px 0" v-loading="loading">
  184. <el-pagination background layout="prev, pager, next" @current-change="currentChange"
  185. :total="page_total"
  186. :page-size="page_size" :current-page="current_page"></el-pagination>
  187. </el-col>
  188. </el-row>
  189. </el-dialog>
  190. <div class="confirm-btn">
  191. <el-button @click="submit" type="primary">提交</el-button>
  192. </div>
  193. </div>
  194. </template>
  195. </div>
  196. </div>
  197. </div>
  198. @include('public.admin.uploadImg')
  199. {!!$catetory_script!!}
  200. <script>
  201. const custom = `{!! resource_get('plugins/pack-fixed-price/assets/image/custom.png') !!}`;
  202. const normal = `{!! resource_get('plugins/pack-fixed-price/assets/image/normal.png') !!}`;
  203. var vm = new Vue({
  204. el: "#re_content",
  205. delimiters: ['[[', ']]'],
  206. data() {
  207. let info =
  208. {!!json_encode($data?:'{}') !!}
  209. return {
  210. dialogVisible: false,
  211. custom: custom,
  212. normal: normal,
  213. info: info,
  214. id: info.id ? info.id : '',
  215. loading: false,
  216. page_total: 0,
  217. page_size: 0,
  218. current_page: 0,
  219. goodsShow: false,
  220. goods_list: [],
  221. uploadShow: false,
  222. chooseImgName: '',
  223. uploadListShow: false,
  224. chooseImgListName: '',
  225. thumbList: [],
  226. area_ids: [],
  227. province_ids: [],
  228. areas: '',
  229. areaIds: '',
  230. provinceIds: '',
  231. chooseAreas: [],
  232. chooseAreaIds: [],
  233. chooseProvinceIds: [],
  234. centerDialogVisible: false,
  235. showVisible: false,
  236. treeData: [],
  237. props: {
  238. label: 'areaname',
  239. children: 'children',
  240. isLeaf: 'isLeaf'
  241. },
  242. category: [],
  243. options: [
  244. {
  245. id: 1,
  246. label: '天'
  247. },
  248. {
  249. id: 2,
  250. label: '周'
  251. },
  252. {
  253. id: 3,
  254. label: '月'
  255. },
  256. {
  257. id: 4,
  258. label: '季度'
  259. },
  260. ],
  261. search_form: {},
  262. form: {
  263. name: info.name ? info.name : '',
  264. rank_type: info.rank_type ? info.rank_type : '',
  265. category_id: info.category_id ? info.category_id : '',
  266. show_count: info.show_count ? info.show_count : '',
  267. goods_count: info.goods_count ? info.goods_count : '',
  268. rule: info.hasOwnProperty('rule') ? String(info.rule) : '0',
  269. banner: info.banner ? info.banner : '',
  270. banner_url: info.banner_url ? info.banner_url : '',
  271. goods_id: [],
  272. catetory_id: '',
  273. filtering_id: '',
  274. },
  275. }
  276. },
  277. mounted() {
  278. $(".img").removeAttr("style");
  279. if (this.info.hasOwnProperty('goods')) {
  280. this.info.goods.forEach((item, index) => {
  281. this.thumbList.push(item)
  282. this.form.goods_id.push(item.id)
  283. })
  284. }
  285. this.$http.post('{!! yzWebFullUrl('plugin.goods-ranking.admin.category.category-list') !!}')
  286. .then(function (response) {
  287. this.category = response.data.data.data;
  288. }
  289. );
  290. },
  291. methods: {
  292. goback() {
  293. window.history.go(-1)
  294. },
  295. openDia() {
  296. this.dialogVisible = true
  297. },
  298. openUpload(str) {
  299. this.chooseImgName = str;
  300. this.uploadShow = true;
  301. },
  302. changeProp(val) {
  303. if (val == true) {
  304. this.uploadShow = false;
  305. } else {
  306. this.uploadShow = true;
  307. }
  308. },
  309. sureImg(name, image, image_url) {
  310. this.form[name] = image;
  311. this.form[name + '_url'] = image_url;
  312. },
  313. openGoods() {
  314. this.goodsShow = true;
  315. },
  316. currentChange(val) {
  317. this.loading = true;
  318. this.$http.post('{!! yzWebFullUrl('plugin.goods-ranking.admin.goods.get-list') !!}', {
  319. page: val,
  320. search: this.search_form.keyword,
  321. rank_id: this.id,
  322. }).then(function (response) {
  323. let datas = response.data.data;
  324. this.page_total = datas.total;
  325. this.goods_list = datas.data;
  326. this.page_size = datas.per_page;
  327. this.current_page = datas.current_page;
  328. this.loading = false;
  329. this.goods_list.forEach((item, index) => {
  330. if (this.form.goods_id == item.id) {
  331. item.checked = true
  332. } else {
  333. item.checked = false
  334. }
  335. })
  336. this.goods_list.push({})
  337. this.goods_list.splice(this.goods_list.length - 1, 1)
  338. }, function (response) {
  339. console.log(response);
  340. this.loading = false;
  341. }
  342. );
  343. },
  344. delGoods(item) {
  345. this.thumbList.forEach((list, index) => {
  346. if (list.id == item.id) {
  347. this.goods_list.forEach((obj, index) => {
  348. if (obj.id == item.id) {
  349. obj.checked = false
  350. }
  351. })
  352. this.thumbList.splice(index, 1)
  353. this.form.goods_id.splice(index, 1)
  354. }
  355. })
  356. this.goods_list.push({})
  357. this.goods_list.splice(this.goods_list.length - 1, 1)
  358. },
  359. searchGoods() {
  360. if (!this.search_form.keyword) {
  361. this.$message({message: '请输入关键词搜索', type: 'error'});
  362. return
  363. }
  364. let that = this;
  365. this.$http.post('{!! yzWebFullUrl('plugin.goods-ranking.admin.goods.get-list') !!}', {
  366. search: this.search_form.keyword,
  367. rank_id: this.id
  368. }).then(response => {
  369. if (response.data.result) {
  370. let data = response.data.data;
  371. this.page_total = data.total;
  372. this.goods_list = data.data;
  373. this.page_size = data.per_page;
  374. this.current_page = data.current_page;
  375. this.goods_list.forEach((item, index) => {
  376. if (this.form.goods_id.includes(item.id)) {
  377. item.checked = true
  378. } else {
  379. item.checked = false
  380. }
  381. })
  382. this.$forceUpdate()
  383. } else {
  384. this.$message({message: response.data.msg, type: 'error'});
  385. }
  386. }, response => {
  387. this.$message({message: response.data.msg, type: 'error'});
  388. });
  389. },
  390. sureGoods(item) {
  391. if (item.status == 1) {
  392. this.$message({message: '商品已关联其他榜单', type: 'error'});
  393. return
  394. } else {
  395. item.checked = true
  396. this.thumbList.push(item)
  397. this.form.goods_id.push(item.id)
  398. this.goods_list.push({})
  399. this.goods_list.splice(this.goods_list.length - 1, 1)
  400. this.goods_list.forEach((item, index) => {
  401. if (this.form.goods_id.includes(item.id)) {
  402. item.checked = true
  403. } else {
  404. item.checked = false
  405. }
  406. })
  407. this.goods_list.push({})
  408. this.goods_list.splice(this.goods_list.length - 1, 1)
  409. this.goodsShow = false
  410. }
  411. },
  412. submit() {
  413. {{--if ($(':input[name="category[parentid][]"]').val() != 0 && $(':input[name="category[childid][]"]').val() == 0) {--}}
  414. {{-- $('#myTab a[href="#tab_basic"]').tab('show');--}}
  415. {{-- Tip.focus(':input[name="category[childid][]"]', "请选择二级分类!");--}}
  416. {{-- return false;--}}
  417. {{--}--}}
  418. {{--@if($shopset['cat_level'] == 3)--}}
  419. {{--if ($(':input[name="category[childid][]"]').val() != 0 && $(':input[name="category[thirdid][]"]').val() == 0) {--}}
  420. {{-- $('#myTab a[href="#tab_basic"]').tab('show');--}}
  421. {{-- Tip.focus(':input[name="category[thirdid][]"]', "请选择三级分类!");--}}
  422. {{-- return false;--}}
  423. {{--}--}}
  424. {{-- @endif--}}
  425. var parent_status = 0;
  426. $(':input[name="category[parentid][]"]').each(function (i) {
  427. if ($(this).val() == 0) {
  428. parent_status = 1;
  429. }
  430. });
  431. // if (parent_status != 0) {
  432. // Tip.focus(':input[name="category[parentid][]"]', "请选择一级分类!");
  433. // return false;
  434. // }
  435. var child_status = 0;
  436. $(':input[name="category[childid][]"]').each(function (i) {
  437. if ($(this).val() == 0) {
  438. child_status = 1;
  439. }
  440. });
  441. // if (child_status != 0) {
  442. // Tip.focus(':input[name="category[childid][]"]', "请选择二级分类!");
  443. // return false;
  444. // }
  445. this.form.goods_ids = this.form.goods_id.join(',');
  446. var catetory_id = '';
  447. @if($shopset['cat_level'] == 2 || is_null($shopset['cat_level']))
  448. $(':input[name="category[childid][]"]').each(function (i) {
  449. if (0 == i) {
  450. catetory_id = $(this).val();
  451. } else {
  452. catetory_id += ("," + $(this).val());
  453. }
  454. });
  455. @elseif($shopset['cat_level'] == 3)
  456. var third_status = 0;
  457. $(':input[name="category[thirdid][]"]').each(function (i) {
  458. if ($(this).val() == 0) {
  459. third_status = 1;
  460. }
  461. if (0 == i) {
  462. catetory_id = $(this).val();
  463. } else {
  464. catetory_id += ("," + $(this).val());
  465. }
  466. });
  467. // if (third_status != 0) {
  468. // Tip.focus(':input[name="category[thirdid][]"]', "请选择三级分类!");
  469. // return false;
  470. // }
  471. @endif
  472. this.form.goods_category_ids = catetory_id;
  473. var filtering_id = '';
  474. $("input:checkbox:checked").each(function (i) {
  475. if (0 == i) {
  476. filtering_id = $(this).val();
  477. } else {
  478. filtering_id += ("," + $(this).val());
  479. }
  480. });
  481. this.form.goods_filtering_ids = filtering_id;
  482. let json = Object.assign({}, this.form)
  483. json.start_at = String(json.start_at).slice(0, 10)
  484. json.end_at = String(json.end_at).slice(0, 10)
  485. let ajaxurl = '{!! yzWebFullUrl('plugin.goods-ranking.admin.rank.add') !!}';
  486. if (this.id != '') {
  487. ajaxurl = '{!! yzWebFullUrl('plugin.goods-ranking.admin.rank.edit') !!}';
  488. }
  489. this.$http.post(ajaxurl, {
  490. 'data': json,
  491. 'id': this.id
  492. }).then(function (response) {
  493. if (response.data.result) {
  494. this.$message({message: response.data.msg, type: 'success'});
  495. window.location.href = '{!! yzWebFullUrl('plugin.goods-ranking.admin.rank.index') !!}'
  496. } else {
  497. this.$message({message: response.data.msg, type: 'error'});
  498. }
  499. }, function (response) {
  500. this.$message({message: response.data.msg, type: 'error'});
  501. })
  502. },
  503. },
  504. });
  505. </script>
  506. <script type="text/javascript">
  507. $('#brand').select2();
  508. $('.plusCategory').click(function () {
  509. appendHtml = $(this).parents().find('.tpl-category-container').html();
  510. $(this).parents().find('.category-container').append('<div class="row row-fix tpl-category-container">' + appendHtml + '<div>');
  511. });
  512. $('.editCategory').click(function () {
  513. appendHtml = $(this).parents().find('.tpl-category-container').html();
  514. $(this).parents().find('.category-container').append('<div class="row row-fix tpl-category-container">' + appendHtml + '<div>');
  515. $('.category-container').children(':last').children().children('select').find("option[value='0']").attr("selected", true)
  516. var seconde_category = $('.category-container').children(':last').children().children('select:eq(1)');
  517. var third_category = $('.category-container').children(':last').children().children('select:eq(2)');
  518. if (seconde_category.length > 0) {
  519. seconde_category.children(':gt(0)').remove();
  520. }
  521. if (third_category.length > 0) {
  522. third_category.children(':gt(0)').remove();
  523. }
  524. });
  525. $(document).on('click', '.delCategory', function () {
  526. var count = $(this).parents('.tpl-category-container').siblings('.tpl-category-container').length;
  527. if (count >= 1) {
  528. $(this).parents('.tpl-category-container').remove();
  529. } else {
  530. alert('商品分类必选');
  531. }
  532. });
  533. function quang(obj) {
  534. var parent_id = $(obj).val();
  535. var xuan = $("#" + parent_id).find('.duo');
  536. if ($(obj).prop('checked')) {
  537. for (var i = 0; i < xuan.length; i++) {
  538. $(xuan[i]).prop('checked', true);
  539. }
  540. } else {
  541. for (var i = 0; i < xuan.length; i++) {
  542. $(xuan[i]).prop('checked', false);
  543. }
  544. }
  545. }
  546. </script>
  547. @endsection