list.vue 10 KB

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