empDetail.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. <template>
  2. <view class="container">
  3. <u-navbar leftIconColor="#fff" titleStyle="color:#fff;fontSize:36rpx;" :autoBack="true" bgColor="#2C6FF3"
  4. :placeholder="true" :title="title"></u-navbar>
  5. <view class="content">
  6. <view class="list">
  7. <u-cell-group :border="false">
  8. <u-cell title="登录名">
  9. <input slot="value" placeholder="请输入登录名" type="text" v-model="params.account"
  10. class="u-slot-value"></input>
  11. </u-cell>
  12. <u-cell title="姓名">
  13. <input slot="value" placeholder="请输入姓名" type="text" v-model="params.name"
  14. class="u-slot-value"></input>
  15. </u-cell>
  16. <u-cell title="密码">
  17. <input slot="value" placeholder="请输入密码" type="password" v-model="params.password"
  18. class="u-slot-value"></input>
  19. </u-cell>
  20. <u-cell title="手机号">
  21. <input slot="value" placeholder="请输入手机号" type="number" v-model="params.tel"
  22. class="u-slot-value"></input>
  23. </u-cell>
  24. <!-- <u-cell title="邮箱">
  25. <input slot="value" placeholder="请输入邮箱" type="number" v-model="params.mail"
  26. class="u-slot-value"></input>
  27. </u-cell> -->
  28. <u-cell title="角色" :isLink="true" @click="popShow=true">
  29. <text slot="value">{{roleName}}</text>
  30. </u-cell>
  31. <u-cell title="备注">
  32. <input slot="value" placeholder="请输入备注" type="" v-model="params.remark"
  33. class="u-slot-value"></input>
  34. </u-cell>
  35. <u-cell title="可管理设备" :isLink="true" :url="`/pages/system/deviceManage?id=${params.userId}`">
  36. </u-cell>
  37. <u-cell title="支付宝" :isLink="true" @click="bindAli">
  38. <text slot="value">{{params.aliUserId?'已绑定':'未绑定'}}</text>
  39. </u-cell>
  40. <u-cell title="状态" :border="false">
  41. <view slot="value" @click="stop">
  42. {{params.status?'启用':'禁用'}}
  43. </view>
  44. </u-cell>
  45. </u-cell-group>
  46. </view>
  47. <view style="color: red;line-height: 60rpx;text-align: right;padding-right: 26rpx;">
  48. {{err}}
  49. </view>
  50. <view class="btn safe-bottom">
  51. <xbutton round="82rpx" size="large" @click="sure">保存</xbutton>
  52. </view>
  53. </view>
  54. <xpopup :show="popShow" @close="popClose" @confirm="popSubmit" :showBtn="true" title="选择角色">
  55. <view class="pop-content flex">
  56. <!-- 多选 -->
  57. <view class="u-page__tag-item" v-for="(item, index) in roleList" :key="item.name">
  58. <u-tag :text="item.name" :plain="!item.checked" type="warning" :name="index" @click="checkboxClick">
  59. </u-tag>
  60. </view>
  61. </view>
  62. </xpopup>
  63. </view>
  64. </template>
  65. <script>
  66. import {
  67. roleList,
  68. objByUserId,
  69. update
  70. } from "@/api/system/employee.js"
  71. import {
  72. showConfirm
  73. } from '@/utils/common'
  74. export default {
  75. data() {
  76. return {
  77. id: '',
  78. title: '',
  79. params: {
  80. name: "",
  81. tel: "",
  82. // "mail": "",
  83. password: "",
  84. roleIds: "",
  85. account: "",
  86. status: true,
  87. remark:""
  88. },
  89. popShow: false,
  90. roleList: [],
  91. err: ''
  92. }
  93. },
  94. computed: {
  95. roleName() {
  96. let val = []
  97. this.roleList.forEach(i => {
  98. if (i.checked) {
  99. val.push(i.name)
  100. }
  101. })
  102. return val.join(',')
  103. },
  104. roleIds() {
  105. let val = []
  106. this.roleList.forEach(i => {
  107. if (i.checked) {
  108. val.push(i.id)
  109. }
  110. })
  111. return val
  112. }
  113. },
  114. onLoad(o) {
  115. this.title = o.title;
  116. this.id = o.id;
  117. },
  118. async onShow() {
  119. await this.getRoleList()
  120. if (this.id) {
  121. await this.getDetail();
  122. }
  123. },
  124. methods: {
  125. getRoleList() {
  126. return new Promise((resolve, reject) => {
  127. roleList({
  128. page: {
  129. current: 1,
  130. size: 10000
  131. },
  132. sysId: uni.getStorageSync('sysId')
  133. }).then(res => {
  134. let data = res.data.records;
  135. if (data.length > 0) {
  136. let newData = data.map(i => {
  137. return {
  138. id: i.id,
  139. name: i.name,
  140. checked: false
  141. }
  142. })
  143. this.roleList = newData;
  144. } else {
  145. this.roleList = [];
  146. }
  147. resolve(data)
  148. }).catch(err => {
  149. reject(err)
  150. })
  151. })
  152. },
  153. getDetail(id) {
  154. objByUserId({
  155. userId: this.id
  156. }).then(res => {
  157. this.params = res.data;
  158. //反显角色
  159. this.roleList.forEach(i => {
  160. res.data.roleNames.forEach(j => {
  161. if (j == i.name) {
  162. i.checked = true
  163. }
  164. })
  165. })
  166. })
  167. },
  168. //禁用
  169. stop() {
  170. this.params.status = !this.params.status
  171. },
  172. //弹框关闭
  173. popClose() {
  174. this.popShow = false
  175. },
  176. //弹框提交
  177. popSubmit() {
  178. update({
  179. userId: this.params.userId,
  180. roleIds: this.roleIds
  181. }).then(res => {
  182. this.popClose()
  183. })
  184. setTimeout(() => {
  185. this.getDetail()
  186. }, 500)
  187. },
  188. checkboxClick(name) {
  189. this.roleList[name].checked = !this.roleList[name].checked
  190. },
  191. bindAli() {
  192. this.$tab.navigateTo('/pages/activeDevice/bindAliAcc?userId=' + this.id)
  193. },
  194. sure() {
  195. let params = {
  196. userId: this.params.userInfoId,
  197. name: this.params.name,
  198. tel: this.params.tel,
  199. account: this.params.account,
  200. roleIds: this.roleIds,
  201. status: this.params.status,
  202. remark:this.params.remark
  203. }
  204. update(params).then(res => {
  205. this.$modal.msg('保存成功')
  206. this.$tab.navigateBack()
  207. }).catch(err => {
  208. if (err.length > 15) {
  209. this.err = '请重试!'
  210. } else {
  211. this.err = err.substr(0, 12)
  212. }
  213. })
  214. }
  215. }
  216. }
  217. </script>
  218. <style lang="scss" scoped>
  219. .container {
  220. overflow: hidden;
  221. .content {
  222. padding: 0rpx 13rpx 12rpx;
  223. overflow: hidden;
  224. .list {
  225. width: 100%;
  226. margin-top: 24rpx;
  227. background-color: #fff;
  228. padding: 0rpx 30rpx;
  229. border-radius: 12rpx;
  230. input {
  231. text-align: right;
  232. }
  233. /deep/ .u-cell__body {
  234. padding: 30rpx 6rpx;
  235. }
  236. }
  237. }
  238. }
  239. .empty {
  240. margin-top: 40%;
  241. }
  242. .btn {
  243. width: 100%;
  244. position: fixed;
  245. left: 0;
  246. padding: 0 24rpx;
  247. }
  248. .del-popup-content {
  249. padding: 36rpx 24rpx;
  250. text-align: center;
  251. font-size: 32rpx;
  252. }
  253. .pop-content {
  254. padding: 24rpx;
  255. .u-page__tag-item {
  256. margin-right: 24rpx;
  257. }
  258. }
  259. </style>