list.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  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. :rules="rules"
  57. ref="uForm"
  58. >
  59. <u-form-item
  60. label="昵称:"
  61. prop="chooseUser.nickName"
  62. borderBottom
  63. ref="item1"
  64. labelWidth="auto"
  65. >
  66. <u--input
  67. v-model="chooseUser.nickName"
  68. border="none"
  69. ></u--input>
  70. </u-form-item>
  71. <u-form-item
  72. label="手机号:"
  73. prop="chooseUser.phonenumber"
  74. borderBottom
  75. ref="item1"
  76. labelWidth="auto"
  77. >
  78. <u--input
  79. v-model="chooseUser.phonenumber"
  80. border="none"
  81. ></u--input>
  82. </u-form-item>
  83. <u-form-item
  84. label="密码:"
  85. prop="chooseUser.password"
  86. borderBottom
  87. ref="item1"
  88. labelWidth="auto"
  89. >
  90. <u--input v-if="showAdd"
  91. v-model="chooseUser.password"
  92. border="none"
  93. ></u--input>
  94. <view style="width:100rpx" v-if="showEdit">
  95. <u-button width="100rpx" type="warning" size="mini" @click="resetPwd()" text="重置密码"></u-button>
  96. </view>
  97. </u-form-item>
  98. <u-form-item
  99. label="登录账号:"
  100. borderBottom
  101. ref="item1"
  102. labelWidth="auto"
  103. >
  104. <u--input
  105. v-model="chooseUser.phonenumber"
  106. border="none"
  107. disabled
  108. ></u--input>
  109. </u-form-item>
  110. <u-form-item
  111. label="状态:"
  112. prop="chooseUser.password"
  113. borderBottom
  114. ref="item1"
  115. labelWidth="auto"
  116. >
  117. <u-radio-group
  118. v-model="statusValue"
  119. placement="row"
  120. >
  121. <u-radio
  122. v-for="(item, index) in statusList"
  123. :key="index"
  124. :label="item.name"
  125. :name="item.name"
  126. @change="statusChange"
  127. >
  128. </u-radio>
  129. </u-radio-group>
  130. </u-form-item>
  131. </u--form>
  132. </view>
  133. </u-modal>
  134. </view>
  135. </template>
  136. <script>
  137. import authObj from '@/plugins/auth.js';
  138. import {getDeptList,getUserListByDept,addUser,editUser,resetPwd,deleteUser,getUserById} from '@/api/user/user';
  139. import UText from "../../uni_modules/uview-ui/components/u-text/u-text";
  140. import UButton from "../../uni_modules/uview-ui/components/u-button/u-button";
  141. import UImage from "../../uni_modules/uview-ui/components/u--image/u--image";
  142. export default {
  143. components: {UImage, UButton, UText},
  144. data() {
  145. return {
  146. statusList:[{ name: '启用',
  147. disabled: false
  148. },
  149. {
  150. name: '禁用',
  151. disabled: false
  152. }],
  153. statusValue: '启用',
  154. userList:[],
  155. search:{
  156. userName:""
  157. },
  158. deptId:0,
  159. showEdit:false,
  160. showAdd:false,
  161. chooseUser:{},
  162. rules: {
  163. 'chooseUser.nickName': {
  164. type: 'string',
  165. required: true,
  166. message: '请填写姓名',
  167. trigger: ['blur', 'change']
  168. },
  169. 'chooseUser.phonenumber': {
  170. type: 'number',
  171. len: 11,
  172. required: true,
  173. message: '请选择男或女',
  174. trigger: ['blur', 'change'],
  175. },
  176. },
  177. }
  178. },
  179. onLoad(opt){
  180. this.deptId = opt.deptId;
  181. if(this.deptId == 'undefined'){
  182. this.deptId = 0;
  183. }
  184. this.getUser();
  185. },
  186. methods: {
  187. isCanEdit(){
  188. return authObj.authRoleAdmin(["companymgr",'admin'])
  189. },
  190. delUser(user){
  191. let self = this;
  192. uni.showModal({
  193. title: '提示',
  194. content: '确认要删除该用户么?',
  195. success: function (res) {
  196. if (res.confirm) {
  197. deleteUser(user.userId).then(res=>{
  198. self.$modal.showToast("操作成功");
  199. self.getUser();
  200. });
  201. } else if (res.cancel) {
  202. console.log('用户点击取消');
  203. }
  204. }
  205. });
  206. },
  207. modifyUser(user){
  208. let self = this;
  209. getUserById(user.userId).then(res=>{
  210. self.chooseUser = res.data;
  211. self.chooseUser.roleIds = res.roleIds;
  212. self.showEdit = true;
  213. })
  214. },
  215. statusChange(e){
  216. console.log(e);
  217. },
  218. closeDlg(){
  219. this.showEdit = false;
  220. this.showAdd = false;
  221. this.chooseUser = {};
  222. },
  223. newUser(){
  224. this.showAdd = true;
  225. },
  226. doAddUser(){
  227. let self = this;
  228. this.chooseUser.postIds=[];
  229. if(this.statusValue == '启用'){
  230. this.chooseUser.status = 0;
  231. }else{
  232. this.chooseUser.status = 1;
  233. }
  234. this.chooseUser.userName = this.chooseUser.phonenumber;
  235. if(this.showAdd){
  236. addUser(this.chooseUser).then(res=>{
  237. self.getUser()
  238. self.closeDlg();
  239. });
  240. }
  241. if(this.showEdit){
  242. editUser(this.chooseUser).then(res=>{
  243. self.getUser()
  244. self.closeDlg();
  245. });
  246. }
  247. },
  248. resetPwd(){
  249. this.showEdit = false;
  250. let self = this;
  251. let userId = this.chooseUser.userId;
  252. uni.showModal({
  253. title: '提示',
  254. editable:true,
  255. placeholderText: '请输入新密码',
  256. success: function (res) {
  257. if (res.confirm) {
  258. resetPwd({userId:userId,password:res.content}).then(res=>{
  259. self.$modal.showToast("操作成功");
  260. })
  261. } else if (res.cancel) {
  262. console.log('用户点击取消');
  263. }
  264. }
  265. });
  266. },
  267. searchDept(){
  268. this.getUser();
  269. },
  270. change(item){
  271. console.log(item)
  272. },
  273. getUser(){
  274. let id = this.deptId;
  275. getUserListByDept(id,this.search.userName).then(res=>{
  276. this.userList = res.rows;
  277. for(const user of this.userList){
  278. }
  279. });
  280. },
  281. }
  282. }
  283. </script>
  284. <style lang="scss">
  285. /* #ifndef APP-NVUE */
  286. .u-collapse-content{
  287. display: flex;
  288. flex-direction: column;
  289. }
  290. page {
  291. display: flex;
  292. flex-direction: column;
  293. box-sizing: border-box;
  294. background-color: #fff;
  295. min-height: 100%;
  296. height: auto;
  297. }
  298. view {
  299. font-size: 14px;
  300. line-height: inherit;
  301. }
  302. /* #endif */
  303. .text {
  304. text-align: center;
  305. font-size: 26rpx;
  306. margin-top: 10rpx;
  307. }
  308. .grid-item-box {
  309. flex: 1;
  310. /* #ifndef APP-NVUE */
  311. display: flex;
  312. /* #endif */
  313. flex-direction: column;
  314. align-items: center;
  315. justify-content: center;
  316. padding: 15px 0;
  317. }
  318. .uni-margin-wrap {
  319. width: 690rpx;
  320. width: 100%;
  321. ;
  322. }
  323. .swiper {
  324. height: 300rpx;
  325. }
  326. .swiper-box {
  327. height: 150px;
  328. }
  329. .swiper-item {
  330. /* #ifndef APP-NVUE */
  331. display: flex;
  332. /* #endif */
  333. flex-direction: column;
  334. justify-content: center;
  335. align-items: center;
  336. color: #fff;
  337. height: 300rpx;
  338. line-height: 300rpx;
  339. }
  340. @media screen and (min-width: 500px) {
  341. .uni-swiper-dot-box {
  342. width: 400px;
  343. /* #ifndef APP-NVUE */
  344. margin: 0 auto;
  345. /* #endif */
  346. margin-top: 8px;
  347. }
  348. .image {
  349. width: 100%;
  350. }
  351. }
  352. </style>