list.vue 9.2 KB

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