list.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. <template>
  2. <view class="work-container">
  3. <view class="header" style="padding:0 20rpx">
  4. <u-search placeholder="请输入用户手机号" :showAction="false" :clearabled="true" @clear="searchDept" @custom="searchDept" v-model="search.userName" @search="searchDept"></u-search>
  5. </view>
  6. <view style="margin-top: 20rpx;padding-bottom: 100rpx;">
  7. <uni-card title="管理员" extra="额外信息" padding="0" thumbnail="/static/images/user/user.png" v-for="item in userList">
  8. <template v-slot:cover>
  9. <view style="position: relative;display: flex;flex-direction: row;margin:20rpx;border-bottom: 1px solid lightgray;height: 60rpx">
  10. <view style="width: 60rpx;height: 40rpx;position: absolute;top: 2rpx;">
  11. <u-image :showLoading="true" src="/static/images/user/user.png" width="60rpx" height="40rpx" ></u-image>
  12. </view>
  13. <view style="font-size: 24rpx;margin-left:10rpx;position: absolute;top: 8rpx;left: 64rpx;font-weight: bold">
  14. {{ item.nickName }}
  15. </view>
  16. <view style="position: absolute;right:-14rpx;top:-2rpx">
  17. <u-tag v-if="item.status == 0" text="启用" type="warning" bgColor="rgb(222,242,228)" color="#48C373" borderColor="rgb(222,242,228)"></u-tag>
  18. <u-tag v-if="item.status == 1" text="禁用" bgColor="rgb(239,239,239)" color="rgb(180,180,180)" borderColor="rgb(239,239,239)" ></u-tag>
  19. </view>
  20. </view>
  21. </template>
  22. <template v-slot:title>
  23. <view style="position: relative;display: flex;flex-direction: column;margin:20rpx;height: 120rpx; line-height: 66rpx;
  24. color: #545454; ">
  25. <view>
  26. 联系电话:{{ item.phonenumber }}
  27. </view>
  28. <view>
  29. 创建时间:{{ item.createTime }}
  30. </view>
  31. </view>
  32. </template>
  33. <template v-slot:actions>
  34. <view style="position: relative;display: flex;flex-direction: row;margin:20rpx;line-height: 60rpx;
  35. color: #545454; ">
  36. <view v-if="isCanEdit()" @click="modifyUser(item)" style="display:flex;flex-direction: row;margin-left: 100rpx;">
  37. <u-image src="/static/images/user/edit.png" width="50rpx" height="50rpx"></u-image>
  38. <view style="margin-left: 10rpx">修改</view>
  39. </view>
  40. <view v-if="isCanEdit()" @click="delUser(item)" style="display:flex;flex-direction: row;margin-left: 180rpx;">
  41. <u-image src="/static/images/user/del.png" width="50rpx" height="50rpx"></u-image>
  42. <view style="margin-left: 10rpx"> 删除</view>
  43. </view>
  44. </view>
  45. </template>
  46. </uni-card>
  47. </view>
  48. <view v-if="isCanEdit()" style="position: fixed;bottom: 0px;text-align: center;width: 100%">
  49. <u-button type="primary" text="新增用户" @click="newUser"></u-button>
  50. </view>
  51. <u-modal :show="showAdd || showEdit" title="编辑用户" @cancel="closeDlg" :showCancelButton="true" @confirm="doAddUser" >
  52. <view class="slot-content">
  53. <u--form
  54. labelPosition="left"
  55. :model="model1"
  56. ref="uForm"
  57. >
  58. <u-form-item
  59. label="昵称:"
  60. prop="chooseUser.nickName"
  61. borderBottom
  62. ref="item1"
  63. labelWidth="auto"
  64. >
  65. <u--input
  66. v-model="chooseUser.nickName"
  67. border="none"
  68. ></u--input>
  69. </u-form-item>
  70. <u-form-item
  71. label="手机号:"
  72. prop="chooseUser.phonenumber"
  73. borderBottom
  74. ref="item1"
  75. labelWidth="auto"
  76. >
  77. <u--input
  78. v-model="chooseUser.phonenumber"
  79. border="none"
  80. ></u--input>
  81. </u-form-item>
  82. <u-form-item
  83. label="密码:"
  84. prop="chooseUser.password"
  85. borderBottom
  86. ref="item1"
  87. labelWidth="auto"
  88. >
  89. <u--input v-if="showAdd"
  90. v-model="chooseUser.password"
  91. border="none"
  92. ></u--input>
  93. <view style="width:100rpx" v-if="showEdit">
  94. <u-button width="100rpx" type="warning" size="mini" @click="resetPwd()" text="重置密码"></u-button>
  95. </view>
  96. </u-form-item>
  97. <u-form-item
  98. label="登录账号:"
  99. borderBottom
  100. ref="item1"
  101. labelWidth="auto"
  102. >
  103. <u--input
  104. v-model="chooseUser.phonenumber"
  105. border="none"
  106. disabled
  107. ></u--input>
  108. </u-form-item>
  109. <u-form-item
  110. label="状态:"
  111. prop="chooseUser.password"
  112. borderBottom
  113. ref="item1"
  114. labelWidth="auto"
  115. >
  116. <u-radio-group
  117. v-model="statusValue"
  118. placement="row"
  119. >
  120. <u-radio
  121. v-for="(item, index) in statusList"
  122. :key="index"
  123. :label="item.name"
  124. :name="item.name"
  125. @change="statusChange"
  126. >
  127. </u-radio>
  128. </u-radio-group>
  129. </u-form-item>
  130. </u--form>
  131. </view>
  132. </u-modal>
  133. </view>
  134. </template>
  135. <script>
  136. import authObj from '@/plugins/auth.js';
  137. import {getDeptList,getUserListByDept,addUser,editUser,resetPwd,deleteUser,getUserById} from '@/api/user/user';
  138. import UText from "../../uni_modules/uview-ui/components/u-text/u-text";
  139. import UButton from "../../uni_modules/uview-ui/components/u-button/u-button";
  140. import UImage from "../../uni_modules/uview-ui/components/u--image/u--image";
  141. export default {
  142. components: {UImage, UButton, UText},
  143. data() {
  144. return {
  145. statusList:[{ name: '启用',
  146. disabled: false
  147. },
  148. {
  149. name: '禁用',
  150. disabled: false
  151. }],
  152. statusValue: '启用',
  153. userList:[],
  154. search:{
  155. userName:""
  156. },
  157. deptId:0,
  158. showEdit:false,
  159. showAdd:false,
  160. chooseUser:{},
  161. }
  162. },
  163. onLoad(opt){
  164. this.deptId = opt.deptId;
  165. if(this.deptId == 'undefined'){
  166. this.deptId = 0;
  167. }
  168. this.getUser();
  169. },
  170. methods: {
  171. isCanEdit(){
  172. return authObj.authRoleAdmin(["companymgr",'admin'])
  173. },
  174. delUser(user){
  175. let self = this;
  176. uni.showModal({
  177. title: '提示',
  178. content: '确认要删除该用户么?',
  179. success: function (res) {
  180. if (res.confirm) {
  181. deleteUser(user.userId).then(res=>{
  182. self.$modal.showToast("操作成功");
  183. self.getUser();
  184. });
  185. } else if (res.cancel) {
  186. console.log('用户点击取消');
  187. }
  188. }
  189. });
  190. },
  191. modifyUser(user){
  192. let self = this;
  193. getUserById(user.userId).then(res=>{
  194. self.chooseUser = res.data;
  195. self.chooseUser.roleIds = res.roleIds;
  196. self.showEdit = true;
  197. })
  198. },
  199. statusChange(e){
  200. console.log(e);
  201. },
  202. closeDlg(){
  203. this.showEdit = false;
  204. this.showAdd = false;
  205. this.chooseUser = {};
  206. },
  207. newUser(){
  208. this.showAdd = true;
  209. },
  210. doAddUser(){
  211. let self = this;
  212. this.chooseUser.postIds=[];
  213. if(this.statusValue == '启用'){
  214. this.chooseUser.status = 0;
  215. }else{
  216. this.chooseUser.status = 1;
  217. }
  218. this.chooseUser.userName = this.chooseUser.phonenumber;
  219. if(this.showAdd){
  220. addUser(this.chooseUser).then(res=>{
  221. self.getUser()
  222. self.closeDlg();
  223. });
  224. }
  225. if(this.showEdit){
  226. editUser(this.chooseUser).then(res=>{
  227. self.getUser()
  228. self.closeDlg();
  229. });
  230. }
  231. },
  232. resetPwd(){
  233. this.showEdit = false;
  234. let self = this;
  235. let userId = this.chooseUser.userId;
  236. uni.showModal({
  237. title: '提示',
  238. editable:true,
  239. placeholderText: '请输入新密码',
  240. success: function (res) {
  241. if (res.confirm) {
  242. resetPwd({userId:userId,password:res.content}).then(res=>{
  243. self.$modal.showToast("操作成功");
  244. })
  245. } else if (res.cancel) {
  246. console.log('用户点击取消');
  247. }
  248. }
  249. });
  250. },
  251. searchDept(){
  252. this.getUser();
  253. },
  254. change(item){
  255. console.log(item)
  256. },
  257. getUser(){
  258. let id = this.deptId;
  259. getUserListByDept(id,this.search.userName).then(res=>{
  260. this.userList = res.rows;
  261. for(const user of this.userList){
  262. }
  263. });
  264. },
  265. }
  266. }
  267. </script>
  268. <style lang="scss">
  269. /* #ifndef APP-NVUE */
  270. .u-collapse-content{
  271. display: flex;
  272. flex-direction: column;
  273. }
  274. page {
  275. display: flex;
  276. flex-direction: column;
  277. box-sizing: border-box;
  278. background-color: #fff;
  279. min-height: 100%;
  280. height: auto;
  281. }
  282. view {
  283. font-size: 14px;
  284. line-height: inherit;
  285. }
  286. /* #endif */
  287. .text {
  288. text-align: center;
  289. font-size: 26rpx;
  290. margin-top: 10rpx;
  291. }
  292. .grid-item-box {
  293. flex: 1;
  294. /* #ifndef APP-NVUE */
  295. display: flex;
  296. /* #endif */
  297. flex-direction: column;
  298. align-items: center;
  299. justify-content: center;
  300. padding: 15px 0;
  301. }
  302. .uni-margin-wrap {
  303. width: 690rpx;
  304. width: 100%;
  305. ;
  306. }
  307. .swiper {
  308. height: 300rpx;
  309. }
  310. .swiper-box {
  311. height: 150px;
  312. }
  313. .swiper-item {
  314. /* #ifndef APP-NVUE */
  315. display: flex;
  316. /* #endif */
  317. flex-direction: column;
  318. justify-content: center;
  319. align-items: center;
  320. color: #fff;
  321. height: 300rpx;
  322. line-height: 300rpx;
  323. }
  324. @media screen and (min-width: 500px) {
  325. .uni-swiper-dot-box {
  326. width: 400px;
  327. /* #ifndef APP-NVUE */
  328. margin: 0 auto;
  329. /* #endif */
  330. margin-top: 8px;
  331. }
  332. .image {
  333. width: 100%;
  334. }
  335. }
  336. </style>