form.blade.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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. let role = {!!json_encode($role)?:'{}' !!}
  129. let permissions={!!json_encode($permissions)?:'{}' !!}
  130. let userPermissions={!!json_encode($userPermissions)?:'{}' !!}
  131. return {
  132. id:role.id,
  133. role:role,
  134. userPermissions:userPermissions,
  135. active:'0',
  136. activeName: 'first',
  137. permissions:permissions,
  138. form:{
  139. name:role.name,
  140. status:String(role.status)
  141. },
  142. arr:[],
  143. ischeckedAll:false,//是否全选
  144. }
  145. },
  146. mounted () {
  147. this.getChecked();
  148. },
  149. methods: {
  150. checkedAll(){
  151. this.permissions.forEach(item=>{
  152. item.checked = this.ischeckedAll;
  153. this.firstUpdate(item)
  154. })
  155. },
  156. goBack() {
  157. window.location.href = `{!! yzWebFullUrl('setting.shop.index') !!}`;
  158. },
  159. getChecked(){
  160. this.permissions.forEach((item,index) => {
  161. if(this.userPermissions.includes(item.key_name)){
  162. item.checked=true
  163. }else{
  164. item.checked=false
  165. }
  166. if(item.child&&item.child.length>0){
  167. item.child.forEach((list,index)=>{
  168. if(this.userPermissions.includes(list.key_name)){
  169. list.checked=true
  170. }else{
  171. list.checked=false
  172. }
  173. if(list.child&&list.child.length>0){
  174. list.child.forEach((obj,index)=>{
  175. if(this.userPermissions.includes(obj.key_name)){
  176. obj.checked=true
  177. }else{
  178. obj.checked=false
  179. }
  180. })
  181. }
  182. })
  183. }
  184. });
  185. this.$forceUpdate()
  186. },
  187. firstUpdate(item){
  188. if(item.checked){
  189. if(item.child&&item.child.length>0){
  190. item.child.forEach((list,index)=>{
  191. list.checked=true
  192. if(list.child&&list.child.length>0){
  193. list.child.forEach((obj,index)=>{
  194. obj.checked=true
  195. })
  196. }
  197. })
  198. }
  199. }else if(!item.checked){
  200. if(item.child&&item.child.length>0){
  201. item.child.forEach((list,index)=>{
  202. list.checked=false
  203. if(list.child&&list.child.length>0){
  204. list.child.forEach((obj,index)=>{
  205. obj.checked=false
  206. })
  207. }
  208. })
  209. }
  210. }
  211. },
  212. secondUpdate(item,list){
  213. if(list.checked){
  214. if(list.child&&list.child.length>0){
  215. list.child.forEach((obj,index)=>{
  216. obj.checked=true
  217. })
  218. }
  219. }else if(!list.checked){
  220. if(list.child&&list.child.length>0){
  221. list.child.forEach((obj,index)=>{
  222. obj.checked=false
  223. })
  224. }
  225. }
  226. let a=item.child.some((block,index)=>{
  227. return block.checked==true
  228. })
  229. if(a){
  230. item.checked=true
  231. }else{
  232. item.checked=false
  233. }
  234. this.$forceUpdate()
  235. },
  236. thirdUpdate(item,list,obj){
  237. if(list.child.length>0){
  238. let a=list.child.some((obj,index)=>{
  239. return obj.checked==true
  240. })
  241. if(a){
  242. list.checked=true
  243. }else{
  244. list.checked=false
  245. }
  246. }
  247. if(item.child.length>0){
  248. let b=item.child.some((list,index)=>{
  249. return list.checked==true
  250. })
  251. if(b){
  252. item.checked=true
  253. }else{
  254. item.checked=false
  255. }
  256. }
  257. this.$forceUpdate()
  258. },
  259. submit() {
  260. this.arr=[];
  261. this.permissions.forEach((item,index) => {
  262. if(item.checked){
  263. this.arr.push(item.key_name)
  264. if(item.child&&item.child.length>0){
  265. item.child.forEach((list,index)=>{
  266. if(list.checked){
  267. this.arr.push(list.key_name)
  268. if(list.child&&list.child.length>0){
  269. list.child.forEach((obj,index)=>{
  270. if(obj.checked){
  271. this.arr.push(obj.key_name)
  272. }
  273. })
  274. }
  275. }
  276. })
  277. }
  278. }
  279. });
  280. this.$http.post('{!! yzWebFullUrl('user.role.update') !!}',{YzRole:this.form,perms:this.arr,id:this.id}).then(function (response){
  281. if (response.data.result) {
  282. this.$message({message: "提交成功",type: 'success'});
  283. window.location.href='{!! yzWebFullUrl('user.role.index') !!}';
  284. this.loading = false;
  285. }else {
  286. this.$message({message: response.data.msg,type: 'error'});
  287. }
  288. },function (response) {
  289. this.$message({message: response.data.msg,type: 'error'});
  290. })
  291. },
  292. },
  293. });
  294. </script>
  295. @endsection