set.blade.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. @extends('layouts.base')
  2. @section('title', '折扣设置')
  3. @section('content')
  4. <link rel="stylesheet" type="text/css" href="{{static_url('yunshop/goods/vue-goods1.css')}}"/>
  5. <style>
  6. .el-tabs__item,.is-top{font-size:16px}
  7. .el-tabs__active-bar { height: 3px;}
  8. .el-scrollbar__wrap{
  9. overflow-x: hidden;
  10. }
  11. .firstCate{
  12. width: 100%;
  13. text-align: center;
  14. }
  15. .firstCate .el-checkbox__inner{
  16. display: none;
  17. }
  18. .el-checkbox-group {
  19. text-align: left;
  20. }
  21. .el-checkbox {
  22. padding-left: 20px;
  23. text-align: left;
  24. }
  25. .active-no-color {
  26. color: #666;
  27. }
  28. .checkbox-pane {
  29. display: flex;
  30. }
  31. .checkbox-color {
  32. color: #29BA9C;
  33. }
  34. .checkbox-name {
  35. line-height: 19px;
  36. margin-left: 5px;
  37. cursor: pointer;
  38. }
  39. .el-select-dropdown__list {
  40. margin-bottom: 20px;
  41. }
  42. .category-style {
  43. text-align:left;
  44. background-color:#eff3f6;
  45. border:3px solid #eff3f6;
  46. padding-left:5px;
  47. }
  48. .scrollbar-style {
  49. height:400px;
  50. border:3px solid #eff3f6;
  51. width:auto;
  52. }
  53. </style>
  54. <div class="all">
  55. <div id="app" v-cloak>
  56. <!-- <div class="vue-nav">
  57. <el-tabs v-model="activeName" @tab-click="handleClick">
  58. <el-tab-pane label="折扣全局设置" name="1"></el-tab-pane>
  59. <el-tab-pane label="折扣设置" name="2"></el-tab-pane>
  60. <el-tab-pane label="运费批量设置" name="3"></el-tab-pane>
  61. </el-tabs>
  62. </div> -->
  63. <div class="vue-crumbs">
  64. <a @click="goParent">折扣设置</a> > 批量折扣设置
  65. </div>
  66. <div class="vue-main">
  67. <div class="vue-main-title">
  68. <div class="vue-main-title-left"></div>
  69. <div class="vue-main-title-content">批量折扣设置</div>
  70. </div>
  71. <div class="vue-main-form">
  72. <el-form ref="form" :model="form" :rules="rules" label-width="15%">
  73. <el-form-item label="选择分类" prop="classification">
  74. <el-input :value="classification" style="width:60%;" disabled></el-input>
  75. <el-button type="primary" @click="visDia()">选择分类</el-button>
  76. <p class="help-block">只能选择商品的二级、三级分类</p>
  77. <el-dialog title="选择分类" :visible.sync="dialogTableVisible" @close="closeDialog">
  78. <!-- :placeholder="form.classification" -->
  79. <el-select
  80. default-first-option
  81. value-key="id"
  82. v-model="search_categorys"
  83. filterable
  84. multiple
  85. remote
  86. reserve-keyword
  87. :remote-method="loadCategorys"
  88. :loading="loading"
  89. style="width:100%;margin-bottom:20px">
  90. <el-option
  91. v-for="item in categorys"
  92. :key="item.id"
  93. :label="'[ID:'+item.id+'][分类:'+item.name+']'"
  94. :value="item"
  95. >
  96. <!-- :value="'[ID:'+item.id+'][分类:'+item.name+']'" -->
  97. </el-option>
  98. </el-select>
  99. <!-- <el-button @click="search()">搜索</el-button><br> -->
  100. <el-row :gutter="0">
  101. <el-col :span="8" >
  102. <div class="category-style">一级分类</div>
  103. <el-scrollbar class="scrollbar-style">
  104. <el-checkbox-group v-model="checkedFirstCate" class="firstCate" @change="loadSecond">
  105. <el-checkbox style="display:block;" v-for="(item, index) in firstCate"
  106. :label="item.id" :value="item.id" name="type">[[item.name]]
  107. </el-checkbox>
  108. </el-checkbox-group>
  109. </el-scrollbar>
  110. </el-col>
  111. <el-col :span="8" >
  112. <div class="category-style">二级分类</div>
  113. <el-scrollbar class="scrollbar-style">
  114. <!-- <el-checkbox-group v-model="checkedSecondCate" style="width:100%;text-align: center" @change="loadThird"> -->
  115. <div v-for="(item, index) in secondCate" class="checkbox-pane" :key="index">
  116. <el-checkbox style="display:block;" :label="item.id" :value="item.id" name="type" v-model="item.checked" @change="loadThird($event,item, index)">[[empty]]</el-checkbox>
  117. <span @click="tapCheckBox(item, index)" :class="item.color ? 'checkbox-color checkbox-name' : 'checkbox-name'">[[item.name]]</span>
  118. </div>
  119. <!-- </el-checkbox-group> -->
  120. </el-scrollbar>
  121. </el-col>
  122. <el-col :span="8" >
  123. <div class="category-style">三级分类</div>
  124. <el-scrollbar class="scrollbar-style">
  125. <!-- <el-checkbox-group v-model="checkedThirdCate" style="width:100%;text-align: center" style="width:100%" @change="loadThree"> -->
  126. <div v-for="(item, index) in thirdCate" class="checkbox-pane">
  127. <el-checkbox style="display:block;" :label="item.id" :value="item.id" name="type" v-model="item.checked" @change="loadThree($event,item, index)">[[empty]]</el-checkbox>
  128. <span class="checkbox-name">[[item.name]]</span>
  129. </div>
  130. <!-- </el-checkbox-group> -->
  131. </el-scrollbar>
  132. </el-col>
  133. </el-row>
  134. <span slot="footer" class="dialog-footer">
  135. <!-- <el-button @click="dialogVisible = false">取 消</el-button> -->
  136. <el-button type="primary" @click="choose()">确 定</el-button>
  137. </span>
  138. </el-dialog>
  139. </el-form-item>
  140. <el-form-item label="折扣类型" prop="type">
  141. <el-radio v-model="form.discount_type" :label="1">会员等级</el-radio>
  142. </el-form-item>
  143. <el-form-item label="折扣方式" prop="method">
  144. <el-radio v-model="form.discount_method" :label="1">折扣</el-radio>
  145. <el-radio v-model="form.discount_method" :label="2">固定金额</el-radio>
  146. </el-form-item>
  147. <el-form-item prop="">
  148. <template v-for="(item,index) in member_list">
  149. <el-input type="number" v-model.number="form.discount_value[item.id]" style="width:70%;padding:10px 0;">
  150. <template slot="prepend">[[item.level_name]]</template>
  151. <template slot="append" v-if="form.discount_method==1">折</template>
  152. <template slot="append" v-if="form.discount_method==2">元</template>
  153. </el-input>
  154. </template>
  155. </el-form-item>
  156. </el-form>
  157. </div>
  158. </div>
  159. <!-- 分页 -->
  160. <div class="vue-page">
  161. <div class="vue-center">
  162. <el-button type="primary" @click="submitForm('form')">保存设置</el-button>
  163. <el-button @click="goBack">返回</el-button>
  164. </div>
  165. </div>
  166. <!--end-->
  167. </div>
  168. </div>
  169. <script>
  170. var vm = new Vue({
  171. el:"#app",
  172. delimiters: ['[[', ']]'],
  173. data() {
  174. let member_list = {!! $levels?:'{}' !!};
  175. let url = {!! $url !!};
  176. let categoryDiscount = {!! $categoryDiscount?:'{}' !!};
  177. let classify = JSON.parse('{!! $classify?:'{}' !!}');
  178. let form ={
  179. discount_type:1,
  180. discount_method:1,
  181. discount_value:[],
  182. category_ids:[],
  183. ...categoryDiscount,
  184. };
  185. let template_list = JSON.parse('{!! $list?:"{}" !!}');
  186. let classic =[];
  187. let classification = classic.join(",");
  188. let firstCate = JSON.parse('{!! $firstCate?:"{}" !!}');
  189. let secondCate = [];
  190. let thirdCate = [];
  191. let checkedFirstCate = [];
  192. let checkedSecondCate = [];
  193. let checkedThirdCate = [];
  194. let showCate=[];
  195. // var checkNumber = (rule, value, callback) => {
  196. // if (!Number.isInteger(value)) {
  197. // callback(new Error('请输入数字'));
  198. // }
  199. // setTimeout(() => {
  200. // callback();
  201. // }, 1000);
  202. // };
  203. return{
  204. url:url,
  205. form:form,
  206. classic:classic,
  207. member_list:member_list,
  208. categorys:[],
  209. dialogVisible:true,
  210. dialogTableVisible:false,
  211. loading: false,
  212. submit_loading: false,
  213. firstCate,
  214. secondCate,
  215. thirdCate,
  216. checkedFirstCate,
  217. checkedSecondCate,
  218. checkedThirdCate,
  219. classify,
  220. rules: {
  221. // discount_value: [
  222. // { required: false,type: 'number', message: '请输入数字'},
  223. // { type: 'number', min: 1, max: 99999, message: '请输入1-99999'},
  224. // { validator : checkNumber }
  225. // ],
  226. // name: [
  227. // { required: true,message: '请输入分类名称', trigger: 'blur' },
  228. // { max : 45,message: '不能超过45个字符', }
  229. // ],
  230. // thumb: [
  231. // { required: true, message: '请选择图片'},
  232. // ]
  233. },
  234. keyword:"",//搜索分类
  235. checkedFirstText:[], //获取二级点击文字时的id
  236. categoryArr:[], //保存回显编辑的数据
  237. empty:"",
  238. search_categorys:[],
  239. classification:"",
  240. }
  241. },
  242. mounted() {
  243. if(this.form.category_ids.length) {
  244. // for(var j=0;j<this.form.category_ids.length;j++){
  245. // this.classic[j] = "[ID:"+this.form.category_ids[j].id+"][分类:"+this.form.category_ids[j].name+"]";
  246. // }
  247. // console.log(this.classic)
  248. this.categoryArr = this.form.category_ids;
  249. for(let item of this.form.category_ids) {
  250. this.classification += `[ID:${item.id}][分类: ${item.name}],`;
  251. }
  252. }
  253. },
  254. methods: {
  255. change(item){
  256. this.form.category_ids = item;
  257. // for(var k=0;k<item.length;k++){
  258. // this.classic[k] = "[ID:"+item[k].id+"][分类:"+item[k].name+"]";
  259. // }
  260. // if(this.form.search_categorys.indexOf(item) == -1){
  261. // this.form.search_categorys.push(item)
  262. // }
  263. // const categorys = this.form.search_categorys.map(v => {
  264. // if(typeof v !== "string" && v.id){
  265. // delete v.thumb
  266. // v = {...v};
  267. // this.form.category_ids.push(v);
  268. // return `[ID:${v.id}][分类:${v.name}]`;
  269. // }
  270. // return v;
  271. // })
  272. // // 去重
  273. // this.form.search_categorys = [...new Set(categorys)]
  274. // this.form.classification = this.form.search_categorys.join(",");
  275. },
  276. visDia(){
  277. if(this.categoryArr.length) {
  278. this.getCategoryData();
  279. return
  280. }
  281. this.dialogTableVisible=true;
  282. },
  283. choose(){
  284. this.dialogTableVisible=false;
  285. },
  286. goBack() {
  287. window.location.href='{!! yzWebFullUrl('discount.batch-discount.index') !!}';
  288. },
  289. loadCategorys(query) {
  290. if (query !== '') {
  291. this.loading = true;
  292. this.$http.get("{!! yzWebUrl('discount.batch-discount.select-category', ['keyword' => '']) !!}" + query).then(response => {
  293. this.categorys = response.data.data;
  294. this.data=response.data.data;
  295. this.loading = false;
  296. }, response => {
  297. });
  298. } else {
  299. this.categorys = [];
  300. }
  301. },
  302. submitForm(formName) {
  303. // if(this.form.discount_method == 1){
  304. // for(let i=0;i<this.member_list.length;i++){
  305. // if(this.form.discount_value[i]<10||this.form.discount_value[i]>0){
  306. // this.$message({message: "折扣数值不能大于10或者小于0",type: 'error'});
  307. // return false;
  308. // }
  309. // }
  310. // }
  311. this.$refs[formName].validate((valid) => {
  312. if (valid) {
  313. let loading = this.$loading({target:document.querySelector(".content"),background: 'rgba(0, 0, 0, 0)'});
  314. this.$http.post(this.url,{'form_data':this.form}).then(response => {
  315. if (response.data.result) {
  316. this.$message({type: 'success',message: '操作成功!'});
  317. window.location.href='{!! yzWebFullUrl('discount.batch-discount.index') !!}';
  318. } else {
  319. this.$message({message: response.data.msg,type: 'error'});
  320. }
  321. loading.close();
  322. },response => {
  323. loading.close();
  324. });
  325. }
  326. else {
  327. return false;
  328. }
  329. });
  330. },
  331. goParent() {
  332. window.location.href = `{!! yzWebFullUrl('discount.batch-discount.index') !!}`;
  333. },
  334. getCategoryData() {
  335. this.$http.get("{!! yzWebUrl('discount.batch-dispatch.get-all-cate') !!}").then(({data}) => {
  336. if(data.result) {
  337. this.categorys = data.data;
  338. this.search_categorys = this.categoryArr;
  339. this.dialogTableVisible = true;
  340. }else {
  341. this.$message.error(data.msg);
  342. }
  343. });
  344. },
  345. // 关闭弹窗回调
  346. closeDialog() {
  347. let newArr = [];
  348. this.classification = "";
  349. for(let item of this.search_categorys) {
  350. this.classification += `[ID:${item.id}][分类: ${item.name}],`
  351. newArr.push(item.id);
  352. }
  353. this.categoryArr = this.search_categorys;
  354. this.form.category_ids = newArr;
  355. },
  356. //根据选择的第一级分类请求第二级分类
  357. loadSecond(data){
  358. let val = data[data.length - 1];
  359. this.checkedFirstCate = [val];
  360. this.$http.get("{!! yzWebUrl('discount.batch-dispatch.get-child') !!}"+`&level=2&cate=${val}`).then(({data}) => {
  361. if(data.result) {
  362. this.secondCate = data.data;
  363. this.thirdCate = [];
  364. this.checkedFirstText = [];
  365. // 回显二级分类 ✔
  366. for(let item of this.search_categorys) {
  367. for(let cItem of this.secondCate) {
  368. this.$set(cItem,'checked',false)
  369. if(item.id == cItem.id) {
  370. this.$nextTick(() => {
  371. this.$set(cItem,'checked',true)
  372. })
  373. break;
  374. }
  375. }
  376. }
  377. }else {
  378. this.$message.error(data.msg);
  379. }
  380. });
  381. },
  382. tapCheckBox(row,index) {
  383. // 处理多选搜索
  384. this.$set(this.secondCate[index],'color',this.secondCate[index].color ? false : true);
  385. console.log(this.checkedFirstText);
  386. let secondIndex = this.checkedFirstText.findIndex(item => {
  387. return item == row.id
  388. })
  389. if(secondIndex == -1) {
  390. this.checkedFirstText.push(row.id);
  391. }else {
  392. this.checkedFirstText.splice(secondIndex,1);
  393. }
  394. this.$http.get("{!! yzWebUrl('discount.batch-dispatch.get-child') !!}"+`&level=3&cate=${this.checkedFirstText}`).then(({data}) => {
  395. if(data.result) {
  396. this.thirdCate = data.data;
  397. // 回显三级分类 ✔
  398. for(let item of this.search_categorys) {
  399. for(let cItem of this.thirdCate) {
  400. this.$set(cItem,'checked',false)
  401. if(item.id == cItem.id) {
  402. this.$nextTick(() => {
  403. this.$set(cItem,'checked',true)
  404. })
  405. break;
  406. }
  407. }
  408. }
  409. }else {
  410. this.$message.error(data.msg);
  411. }
  412. });
  413. },
  414. //根据选择的第二级分类请求第三级分类
  415. loadThird($event,row,index){
  416. if(!row.checked) {
  417. // 删除多选框
  418. let secondIndex = this.search_categorys.findIndex(item => {
  419. return item.id == row.id
  420. })
  421. this.search_categorys.splice(secondIndex,1);
  422. return
  423. }
  424. // 选中后添加复选框
  425. this.categorys = [row];
  426. let secondIndex = this.search_categorys.findIndex(item => {
  427. return item.id == row.id
  428. })
  429. if(secondIndex == -1) {
  430. this.search_categorys.push(row);
  431. }
  432. },
  433. loadThree($event,row,index) {
  434. if(!row.checked) {
  435. // 删除多选框
  436. let currentIndex = this.search_categorys.findIndex(item => {
  437. return item.id == row.id
  438. })
  439. this.search_categorys.splice(currentIndex,1);
  440. return
  441. }
  442. // 选中后添加复选框
  443. this.categorys = [row];
  444. let currentIndex = this.search_categorys.findIndex(item => {
  445. return item.id == row.id
  446. })
  447. if(currentIndex == -1) {
  448. this.search_categorys.push(row);
  449. }
  450. }
  451. },
  452. });
  453. </script>
  454. @endsection