store.blade.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. @extends('layouts.base')
  2. @section('content')
  3. <style>
  4. .content{
  5. background: #eff3f6;
  6. padding: 10px!important;
  7. }
  8. .con{
  9. padding-bottom:70px;
  10. position:relative;
  11. border-radius: 8px;
  12. min-height:100vh;
  13. background-color:#fff;
  14. }
  15. .el-collapse{
  16. border-top:none;
  17. }
  18. .con .setting .block{
  19. padding:10px;
  20. background-color:#fff;
  21. border-radius: 8px;
  22. }
  23. .con .setting .block .title{
  24. font-size:18px;
  25. margin-bottom:15px;
  26. display:flex;
  27. align-items:center;
  28. }
  29. .confirm-btn{
  30. width: calc(100% - 266px);
  31. position:fixed;
  32. bottom:0;
  33. right:0;
  34. margin-right:10px;
  35. line-height:63px;
  36. background-color: #ffffff;
  37. box-shadow: 0px 8px 23px 1px
  38. rgba(51, 51, 51, 0.3);
  39. background-color:#fff;
  40. text-align:center;
  41. }
  42. .el-form-item__label{
  43. margin-right:30px;
  44. }
  45. b{
  46. font-size:14px;
  47. }
  48. .el-checkbox{
  49. margin-right:0;
  50. }
  51. .vue-crumbs a {
  52. color: #333;
  53. }
  54. .vue-crumbs a:hover {
  55. color: #29ba9c;
  56. }
  57. .vue-crumbs {
  58. margin: 0 20px;
  59. font-size: 14px;
  60. color: #333;
  61. font-weight: 400;
  62. padding-bottom: 10px;
  63. line-height: 32px;
  64. }
  65. .el-checkbox__inner{
  66. border:solid 1px #56be69!important;
  67. z-index:0!important;
  68. }
  69. </style>
  70. <div id='re_content' >
  71. <div class="vue-crumbs">
  72. <a @click="goBack">系统</a> > 权限管理 > 角色管理 > 添加角色
  73. </div>
  74. <div class="con">
  75. <div class="setting">
  76. <el-form ref="form" :model="form" label-width="15%">
  77. <div class="block">
  78. <div class="title"><span style="width: 4px;height: 18px;background-color: #29ba9c;margin-right:15px;display:inline-block;"></span><b>角色信息</b></div>
  79. <el-form-item label="角色">
  80. <el-input v-model="form.name" style="width:60%;"></el-input>
  81. </el-form-item>
  82. <el-form-item label="是否启用" >
  83. <template>
  84. <el-switch
  85. v-model="form.status"
  86. active-value="2"
  87. inactive-value="1"
  88. >
  89. </el-switch>
  90. </template>
  91. <div>提示:如果禁用,则当前角色的操作员全部会禁止使用</div>
  92. </el-form-item>
  93. </div>
  94. <div style="background: #eff3f6;width:100%;height:15px;"></div>
  95. <div class="block">
  96. <div class="title"><span style="width: 4px;height: 18px;background-color: #29ba9c;margin-right:15px;display:inline-block;"></span><b>角色权限</b></div>
  97. <el-checkbox v-model="ischeckedAll" style="margin-left:30px;" @change="checkedAll"><b>一键勾选</b></el-checkbox>
  98. <el-collapse v-model="active" accordion>
  99. <template v-for="(item,index) in permissions" class="warp">
  100. <el-collapse-item :name="index">
  101. <template slot="title">
  102. <el-checkbox v-model="item.checked" @change="firstUpdate(item)" style="margin-left:30px;"><b>[[item.name]]</b></el-checkbox>
  103. </template>
  104. <div v-for="(list,index) in item.child" style="font-size:0;display:flex;border-bottom:1px solid #EBEEF5;padding:10px 0;">
  105. <div style="width:20%;"><el-checkbox v-model="list.checked" @change="secondUpdate(item,list)" style="width:200px;margin-left:45px"><b>[[list.name]]</b></el-checkbox></div>
  106. <div style="flex:1;display:flex;flex-wrap:wrap;">
  107. <div v-for="(obj,index) in list.child" style="width:200px;display:inline-block;">
  108. <el-checkbox v-model="obj.checked" @change="thirdUpdate(item,list,obj)" >[[obj.name]]</el-checkbox>
  109. </div>
  110. </div>
  111. </div>
  112. </el-collapse-item>
  113. </template>
  114. </el-collapse>
  115. </div>
  116. </div>
  117. <div class="confirm-btn">
  118. <el-button type="primary" @click="submit">提交</el-button>
  119. </div>
  120. </el-form>
  121. </div>
  122. </div>
  123. <script>
  124. var vm = new Vue({
  125. el: "#re_content",
  126. delimiters: ['[[', ']]'],
  127. data() {
  128. return {
  129. active:'0',
  130. activeName: 'first',
  131. permissions:[],
  132. form:{
  133. name:'',
  134. status:'1'
  135. },
  136. arr:[],
  137. ischeckedAll:false
  138. }
  139. },
  140. mounted () {
  141. this.getData();
  142. },
  143. methods: {
  144. checkedAll(){
  145. this.permissions.forEach(item=>{
  146. item.checked = this.ischeckedAll;
  147. this.firstUpdate(item)
  148. })
  149. },
  150. goBack() {
  151. window.location.href = `{!! yzWebFullUrl('setting.shop.index') !!}`;
  152. },
  153. firstUpdate(item){
  154. if(item.checked){
  155. if(item.child&&item.child.length>0){
  156. item.child.forEach((list,index)=>{
  157. list.checked=true
  158. if(list.child&&list.child.length>0){
  159. list.child.forEach((obj,index)=>{
  160. obj.checked=true
  161. })
  162. }
  163. })
  164. }
  165. }else if(!item.checked){
  166. if(item.child&&item.child.length>0){
  167. item.child.forEach((list,index)=>{
  168. list.checked=false
  169. if(list.child&&list.child.length>0){
  170. list.child.forEach((obj,index)=>{
  171. obj.checked=false
  172. })
  173. }
  174. })
  175. }
  176. }
  177. },
  178. secondUpdate(item,list){
  179. if(list.checked){
  180. if(list.child&&list.child.length>0){
  181. list.child.forEach((obj,index)=>{
  182. obj.checked=true
  183. })
  184. }
  185. }else if(!list.checked){
  186. item.checked=false
  187. if(list.child&&list.child.length>0){
  188. list.child.forEach((obj,index)=>{
  189. obj.checked=false
  190. })
  191. }
  192. }
  193. let a=item.child.some((block,index)=>{
  194. return block.checked==true
  195. })
  196. if(a){
  197. item.checked=true
  198. }else{
  199. item.checked=false
  200. }
  201. this.$forceUpdate()
  202. },
  203. thirdUpdate(item,list,obj){
  204. if(list.child.length>0){
  205. let a=list.child.some((obj,index)=>{
  206. return obj.checked==true
  207. })
  208. if(a){
  209. list.checked=true
  210. }else{
  211. list.checked=false
  212. }
  213. }
  214. if(item.child.length>0){
  215. let b=item.child.some((list,index)=>{
  216. return list.checked==true
  217. })
  218. if(b){
  219. item.checked=true
  220. }else{
  221. item.checked=false
  222. }
  223. }
  224. this.$forceUpdate()
  225. },
  226. getData(){
  227. this.$http.post('{!! yzWebFullUrl('user.role.store') !!}').then(function (response){
  228. if (response.data.result) {
  229. this.permissions=response.data.data.permissions
  230. this.permissions.forEach((item,index) => {
  231. item.checked=false
  232. if(item.child&&item.child.length>0){
  233. item.child.forEach((list,index)=>{
  234. list.checked=false
  235. if(list.child&&list.child.length>0){
  236. list.child.forEach((obj,index)=>{
  237. obj.checked=false
  238. })
  239. }
  240. })
  241. }
  242. });
  243. }else{
  244. this.$message({message: response.data.msg,type: 'error'});
  245. }
  246. },function (response) {
  247. this.$message({message: response.data.msg,type: 'error'});
  248. })
  249. },
  250. submit() {
  251. this.arr=[];
  252. this.permissions.forEach((item,index) => {
  253. if(item.checked){
  254. this.arr.push(item.key_name)
  255. if(item.child&&item.child.length>0){
  256. item.child.forEach((list,index)=>{
  257. if(list.checked){
  258. this.arr.push(list.key_name)
  259. if(list.child&&list.child.length>0){
  260. list.child.forEach((obj,index)=>{
  261. if(obj.checked){
  262. this.arr.push(obj.key_name)
  263. }
  264. })
  265. }
  266. }
  267. })
  268. }
  269. }
  270. });
  271. this.$http.post('{!! yzWebFullUrl('user.role.store') !!}',{YzRole:this.form,perms:this.arr}).then(function (response){
  272. if (response.data.result) {
  273. this.$message({message: "提交成功",type: 'success'});
  274. window.location.href='{!! yzWebFullUrl('user.role.index') !!}';
  275. this.loading = false;
  276. }else {
  277. this.$message({message: response.data.msg,type: 'error'});
  278. }
  279. },function (response) {
  280. this.$message({message: response.data.msg,type: 'error'});
  281. })
  282. },
  283. },
  284. });
  285. </script>
  286. @endsection