index.blade.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. @extends('layouts.app')
  2. @section('title')查询-用户@endsection
  3. @section('content')
  4. <div class="container-fluid">
  5. <div class="card">
  6. <div id="form_div"></div>
  7. <div class="card-body">
  8. @if(Session::has('successTip'))
  9. <div class="alert alert-success h1">{{Session::get('successTip')}}</div>
  10. @endif
  11. <div id="list">
  12. @include("maintenance.user._resetPwd")
  13. @include("maintenance.user._allocationOwner")
  14. <table class="table table-striped table-sm td-min-width-80" id="table">
  15. <tr v-for="(user,i) in users" @click="selectTr===i+1?selectTr=0:selectTr=i+1" :class="selectTr===i+1?'focusing' : ''">
  16. <td class="text-muted"><span>@{{user.id}}</span></td>
  17. <td><span>@{{user.name}}</span></td>
  18. <td>
  19. <span class="text-danger" v-if="user.isSuperAdmin">超级管理员</span>
  20. <ul v-if="user.roles.length>0" class="list-group">
  21. <li v-for="role in user.roles" style="list-style: none">@{{ role.name }}</li>
  22. </ul>
  23. </td>
  24. <td><span v-if="user.workgroup&&user.workgroup.length>0">@{{ user.workgroup[0].name }}</span></td>
  25. <td>
  26. <ul v-if="user.logistics.length>0" class="list-group">
  27. <li v-for="logistic in user.logistics" style="list-style: none">@{{ logistic.name }}</li>
  28. </ul>
  29. </td>
  30. <td>
  31. <ul v-if="user.suppliers.length>0" class="list-group">
  32. <li v-for="supplier in user.suppliers" style="list-style: none">@{{ supplier.name }}</li>
  33. </ul>
  34. </td>
  35. <td><span>@{{user.email}}</span></td>
  36. <td class="text-muted"><span>@{{user.created_at}}</span></td>
  37. <td>
  38. @can('用户-编辑')
  39. <button class="btn btn-sm btn-warning" @click="openResetPwdModal(user)">重置密码</button>
  40. <button class="btn btn-sm btn-info ml-1" @click="allocationOwner(user)">分配货主</button>
  41. <button class="btn btn-sm btn-outline-primary ml-1" @click="edit(user.id)">改</button> @endcan
  42. @can('用户-删除')
  43. <button class="btn btn-sm btn-outline-dark" @click="destroy(user)">删</button> @endcan
  44. </td>
  45. </tr>
  46. </table>
  47. {{$users->links()}}
  48. </div>
  49. </div>
  50. </div>
  51. </div>
  52. @endsection
  53. @section('lastScript')
  54. <script>
  55. </script>
  56. <script type="text/javascript" src="{{mix('js/queryForm/queryForm.js')}}"></script>
  57. <script type="text/javascript" src="{{mix('js/queryForm/header.js')}}"></script>{{--新版2--}}
  58. <script>
  59. new Vue({
  60. el:"#list",
  61. data:{
  62. users:{!! $users->toJson() !!}['data'],
  63. form:'',
  64. owners:[
  65. @foreach($owners as $owner)
  66. {name:'{{$owner->id}}',value:'{{$owner->name}}'},
  67. @endforeach
  68. ],
  69. selectTr:0,
  70. user:{},
  71. switchStatus:false,
  72. switchOwner:[],
  73. },
  74. mounted:function(){
  75. let data = [
  76. [{name:'name',type:'input',tip:'用户名:可在两侧添加百分号(%)进行模糊搜索',placeholder:'用户名'},
  77. {name:'role',type:'input',tip:'可支持多角色名,模糊搜索可在两侧添加百分号(%)进行',placeholder:'角色名'},
  78. {name:'owners',type:'select_multiple_select',tip:['输入关键词快速定位下拉列表,回车确定','选择要显示的客户'],
  79. placeholder:['货主','定位或多选货主'],data:this.owners},
  80. ]
  81. ];
  82. this.form = new query({
  83. el: '#form_div',
  84. condition: data,
  85. });
  86. this.form.init();
  87. let column = [
  88. {name:'id',value: 'ID'},
  89. {name:'name',value: '用户名'},
  90. {name:'role_name',value: '角色', neglect: true},
  91. {name:'workgroup_name',value: '工作组', neglect: true},
  92. {name:'carrier_name',value: '配置承运商', neglect: true},
  93. {name:'supplier_name',value: '配置供应商', neglect: true},
  94. {name:'email',value: '邮件地址'},
  95. {name:'created_at',value: '创建时间'},
  96. {name:'operation',value: '操作', neglect: true},
  97. ];
  98. new Header({
  99. el:"table",
  100. name:"user",
  101. column: column,
  102. data: this.users,
  103. fixedTop: ($('#form_div').height())+2,
  104. isRestorationColumnAsc:true,
  105. isCheckAllBox:false,
  106. }).init();
  107. },
  108. methods:{
  109. edit:function(id){
  110. location.href = "{{url('maintenance/user')}}/"+id+"/edit";
  111. },
  112. destroy:function(user){
  113. if(!confirm('确定要删除用户“' + user.name + '”吗?'))return;
  114. let data=this;
  115. let url = "{{url('maintenance/user')}}/"+user.id;
  116. axios.delete(url,{id:user.id})
  117. .then(function (response) {
  118. if(response.data.success){
  119. for (let i = 0; i < data.users.length; i++) {
  120. if (data.users[i].id===user.id){
  121. data.users.splice(i,1);
  122. break;
  123. }
  124. }
  125. tempTip.setDuration(1000);
  126. tempTip.showSuccess('删除用户"'+user.name+'"成功!')
  127. }else{
  128. tempTip.setDuration(1000);
  129. tempTip.show('删除用户"'+user.name+'"失败!')
  130. }
  131. })
  132. .catch(function (err) {
  133. tempTip.setDuration(3000);
  134. tempTip.show('删除用户失败!'+'网络错误:' + err)
  135. });
  136. },
  137. openResetPwdModal(user){
  138. this.user = user;
  139. $("#modal").modal("show");
  140. },
  141. resetPwd(){
  142. window.tempTip.setIndex(1099);
  143. window.tempTip.setDuration(3000);
  144. if (this.user.pwd.length<6){
  145. window.tempTip.show("密码最少为六位");
  146. return;
  147. }
  148. if (this.user.pwd!==this.user.rePwd){
  149. window.tempTip.show("两次密码输入不一致");
  150. return;
  151. }
  152. window.tempTip.postBasicRequest("{{url('maintenance/user/resetPassword')}}",this.user,()=>{
  153. $("#modal").modal("hide");
  154. return "已重置用户:“"+this.user.name+"”的密码";
  155. },true);
  156. },
  157. allocationOwner(user){
  158. this.switchOwner = [];
  159. this._updateOwnerShow(this.switchStatus);
  160. this.user = user;
  161. if (!user.owners){
  162. window.tempTip.postBasicRequest("{{url('maintenance/user/getOwners')}}", {id:user.id},res=>{
  163. this.user.owners = res;
  164. this.switchOwner = res ? res : [];
  165. });
  166. }else{
  167. this.switchOwner = user.owners;
  168. }
  169. $("#allocation-owner").modal('show');
  170. },
  171. changeSwitchStatus(){
  172. if (!this.user.owners || this.user.owners.length===0){
  173. this._updateOwnerShow(!this.switchStatus);
  174. }else{
  175. this.owners.forEach(owner=>{
  176. owner.hide = !(this.isExist(this.user.owners,owner.name) && this.switchStatus);
  177. });
  178. this.$forceUpdate();
  179. }
  180. },
  181. _updateOwnerShow(isHide){
  182. this.owners.forEach(owner=>{
  183. owner.hide = isHide;
  184. })
  185. this.$forceUpdate();
  186. },
  187. seekOwner(e){
  188. let val = e.target.value;
  189. this.owners.forEach(owner=>{
  190. if (owner.value.indexOf(val) > -1){
  191. owner.hide = (this.switchStatus && !this.isExist(this.user.owners,owner.name)) || !this.switchStatus;
  192. }else{
  193. owner.hide = true;
  194. }
  195. })
  196. this.$forceUpdate();
  197. },
  198. executeAllocation(){
  199. window.tempTip.postBasicRequest("{{url('maintenance/user/bindOwner')}}", {id:this.user.id,owners:this.switchOwner},()=>{
  200. this.user.owners = this.switchOwner;
  201. return "绑定成功";
  202. },true);
  203. },
  204. isExist(arr, tar){
  205. return arr.some(val=>{
  206. return val == tar;
  207. });
  208. },
  209. cloneTarget(){
  210. let val = $("#seek-owner").val();
  211. window.tempTip.postBasicRequest("{{url('maintenance/user/cloneBindOwner')}}", {id:this.user.id,target:val},()=>{
  212. return "克隆成功";
  213. },true);
  214. },
  215. }
  216. });
  217. </script>
  218. @endsection