index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. <template>
  2. <view class="uni-app">
  3. <view class="status-bar" />
  4. <view class="main-container">
  5. <!-- #ifndef MP-WEIXIN -->
  6. <wk-nav-bar
  7. title="团队成员"
  8. :refresh-prev="refreshPrevPage">
  9. <template v-if="!showEdit">
  10. <button class="button white-btn" @click="handleToEdit">
  11. <text class="wk wk-edit edit-icon" />
  12. </button>
  13. <button class="button white-btn" @click="handleAdd">
  14. <text class="wk wk-plus plus-icon" />
  15. </button>
  16. </template>
  17. <template v-else>
  18. <button class="button white-btn" @click="handleSave">
  19. 保存
  20. </button>
  21. </template>
  22. </wk-nav-bar>
  23. <!-- #endif -->
  24. <!-- #ifdef MP-WEIXIN -->
  25. <wk-nav-bar
  26. :command-list="commandList"
  27. :refresh-prev="refreshPrevPage"
  28. title="团队成员"
  29. theme="white"
  30. class="nav-bar"
  31. @command="handleCommand" />
  32. <!-- #endif -->
  33. <view class="container">
  34. <view v-if="teamList.length > 0" class="list">
  35. <view v-for="(item, index) in teamList" :key="index" class="list-item">
  36. <view class="content">
  37. <view class="info">
  38. <wk-avatar :name="item.realname" :avatar="item.img" class="avatar" />
  39. <view class="info-content">
  40. <view class="box">
  41. <text class="name">
  42. {{ item.realname }}
  43. </text>
  44. <text
  45. v-if="!showEdit || Number(item.power) === 3"
  46. class="role">
  47. {{ getRoleText(item.power) }}
  48. </text>
  49. <text
  50. v-else
  51. class="control"
  52. @click="handleDelete(index)">
  53. &times;
  54. </text>
  55. </view>
  56. <view class="box">
  57. <text class="position">
  58. {{ item.name }}
  59. </text>
  60. </view>
  61. </view>
  62. </view>
  63. <view class="permission" @click="handleEdit(item)">
  64. <view class="label">
  65. 权限
  66. </view>
  67. <view class="text">
  68. {{ getPowerText(item.power) }}
  69. <text class="wk wk-arrow-right icon" />
  70. </view>
  71. </view>
  72. </view>
  73. </view>
  74. </view>
  75. </view>
  76. <!-- #ifdef MP-WEIXIN -->
  77. <view v-if="showEdit" class="footer-btn-group">
  78. <button class="button" @click="handleSave">
  79. 保存
  80. </button>
  81. </view>
  82. <!-- #endif -->
  83. </view>
  84. <uni-popup ref="popup">
  85. <view v-if="showEditPop" class="pop-wrapper">
  86. <view
  87. v-for="(item, index) in popOptions"
  88. :key="index"
  89. class="pop-item"
  90. @click.stop="handleSelectOptions(item)">
  91. {{ item.label }}
  92. </view>
  93. </view>
  94. <uni-popup-dialog
  95. v-else
  96. :content="dialogMsg"
  97. type="warning"
  98. @confirm="handleDialogConfirm" />
  99. </uni-popup>
  100. </view>
  101. </template>
  102. <script>
  103. import {
  104. GetMembers as CustomerGet,
  105. DeleteMembers as CustomerDelete,
  106. UpdateMembers as CustomerUpdate
  107. } from 'API/crm/customer'
  108. import {
  109. GetMembers as BusinessGet,
  110. DeleteMembers as BusinessDelete,
  111. UpdateMembers as BusinessUpdate
  112. } from 'API/crm/business'
  113. import {
  114. GetMembers as ContractGet,
  115. DeleteMembers as ContractDelete,
  116. UpdateMembers as ContractUpdate
  117. } from 'API/crm/contract'
  118. export default {
  119. name: 'GroupIndex',
  120. data() {
  121. return {
  122. id: null,
  123. type: null,
  124. routerQuery: {},
  125. teamList: [],
  126. deleteList: [],
  127. editItem: null,
  128. showEdit: false,
  129. showEditPop: false,
  130. dialogMsg: '',
  131. popType: null,
  132. popOptions: [
  133. {label: '只读', value: 1},
  134. {label: '读写', value: 2}
  135. ],
  136. apiMap: {
  137. customer: {
  138. get: CustomerGet,
  139. delete: CustomerDelete,
  140. update: CustomerUpdate,
  141. fields: 'id'
  142. },
  143. business: {
  144. get: BusinessGet,
  145. delete: BusinessDelete,
  146. update: BusinessUpdate,
  147. fields: 'id'
  148. },
  149. contract: {
  150. get: ContractGet,
  151. delete: ContractDelete,
  152. update: ContractUpdate,
  153. fields: 'id'
  154. }
  155. },
  156. commandList: [
  157. {
  158. label: '编辑',
  159. imgIcon: 'update',
  160. auth: '',
  161. value: 'update'
  162. },
  163. {
  164. label: '新增成员',
  165. icon: 'wk-plus',
  166. auth: '',
  167. value: 'add'
  168. },
  169. ],
  170. refreshPage: false, // 刷新页面标志
  171. refreshPrevPage: false
  172. }
  173. },
  174. onLoad(options) {
  175. this.routerQuery = options
  176. this.id = options.id
  177. this.type = options.type
  178. if (this.apiMap.hasOwnProperty(this.type)) {
  179. this.getTeamList()
  180. }
  181. },
  182. onShow() {
  183. if (this.refreshPage) {
  184. this.$nextTick(() => {
  185. this.refreshPage = false
  186. this.refreshPrevPage = true
  187. this.getTeamList()
  188. })
  189. }
  190. },
  191. onBackPress(evt) {
  192. if (evt.from === 'backbutton' && this.refreshPrevPage) {
  193. this.$refreshAndToPrev(this)
  194. return true // 返回值为 true 时,表示不执行默认的返回
  195. }
  196. return false
  197. },
  198. methods: {
  199. getPowerText(power) {
  200. return {
  201. 1: '只读',
  202. 2: '读写',
  203. 3: '负责人权限'
  204. }[power]
  205. },
  206. getRoleText(power) {
  207. // 3 负责人 1 2 普通员工
  208. if (Number(power) === 3) return '负责人'
  209. return '普通员工'
  210. },
  211. getTeamList() {
  212. this.deleteList = []
  213. this.apiMap[this.type].get({
  214. id: this.id,
  215. }).then(res => {
  216. console.log('teamList: ', res)
  217. this.teamList = res
  218. })
  219. },
  220. handleCommand(command) {
  221. if (command.value === 'update') {
  222. this.handleToEdit()
  223. } else {
  224. this.handleAdd()
  225. }
  226. },
  227. handleAdd() {
  228. this.$Router.navigateTo({
  229. url: '/pages_crm/group/add',
  230. query: this.routerQuery
  231. })
  232. },
  233. /**
  234. * 点击删除
  235. */
  236. handleDelete(index) {
  237. this.deleteList.push(this.teamList[index].userId)
  238. this.deleteList = [...new Set(this.deleteList)]
  239. this.teamList.splice(index, 1)
  240. },
  241. handleToEdit() {
  242. this.showEdit = !this.showEdit
  243. },
  244. handleEdit(item) {
  245. if (Number(item.power) === 3) {
  246. this.$toast('不允许编辑负责人')
  247. return
  248. }
  249. this.showEditPop = true
  250. this.editItem = item
  251. this.$refs.popup.open()
  252. },
  253. handleSelectOptions(opt) {
  254. this.dialogMsg = '确定要修改权限吗?'
  255. this.showEditPop = false
  256. this.editItem.powerValue = opt.value
  257. this.popType = 'update'
  258. },
  259. handleSave() {
  260. if (this.deleteList.length === 0) {
  261. this.showEdit = !this.showEdit
  262. this.deleteList = []
  263. return
  264. }
  265. this.dialogMsg = '确定要保存更改吗?'
  266. this.showEditPop = false
  267. this.popType = 'save'
  268. this.$refs.popup.open()
  269. },
  270. handleDialogConfirm(next) {
  271. switch (this.popType) {
  272. case 'update':
  273. this.apiMap[this.type].update({
  274. ids: [this.id],
  275. memberIds: [this.editItem.userId],
  276. power: this.editItem.powerValue
  277. }).then(response => {
  278. this.$toast('修改成功')
  279. this.showEdit = false
  280. this.refreshPrevPage = true
  281. this.getTeamList()
  282. }).catch()
  283. this.editItem = null
  284. break
  285. case 'save':
  286. this.showEdit = !this.showEdit
  287. this.apiMap[this.type].delete({
  288. ids: [this.id],
  289. memberIds: this.deleteList
  290. }).then(response => {
  291. this.deleteList = []
  292. this.$toast('删除成功')
  293. this.refreshPrevPage = true
  294. this.getTeamList()
  295. }).catch()
  296. break
  297. }
  298. next()
  299. }
  300. }
  301. }
  302. </script>
  303. <style scoped lang="scss">
  304. .edit-icon {
  305. font-weight: bold;
  306. }
  307. .edit-icon, .plus-icon {
  308. font-size: 36rpx;
  309. line-height: 1;
  310. }
  311. .container {
  312. width: 100%;
  313. flex: 1;
  314. overflow: auto;
  315. padding-bottom: 20rpx;
  316. margin-top: 20rpx;
  317. .list {
  318. width: 100%;
  319. background-color: white;
  320. .list-item {
  321. border-bottom: 1rpx solid $border-color;
  322. display: flex;
  323. .content {
  324. flex: 1;
  325. padding-right: 30rpx;
  326. .info {
  327. @include left;
  328. .avatar {
  329. width: 70rpx;
  330. height: 70rpx;
  331. border-radius: 50%;
  332. margin: 0 26rpx 0 30rpx;
  333. }
  334. .info-content {
  335. flex: 1;
  336. border-bottom: 1rpx solid $border-color;
  337. padding: 28rpx 0 26rpx 0;
  338. .box {
  339. @include left;
  340. .name {
  341. flex: 1;
  342. font-size: 32rpx;
  343. color: $dark;
  344. }
  345. .role {
  346. font-size: 26rpx;
  347. color: $light;
  348. }
  349. .control {
  350. font-size: 42rpx;
  351. color: #FF6767;
  352. line-height: 1;
  353. }
  354. .position {
  355. font-size: 26rpx;
  356. color: $light;
  357. line-height: 2;
  358. }
  359. }
  360. }
  361. }
  362. .permission {
  363. height: 80rpx;
  364. font-size: 26rpx;
  365. color: $gray;
  366. margin-left: 126rpx;
  367. @include left;
  368. .label {
  369. flex: 1;
  370. }
  371. .text {
  372. line-height: 1;
  373. @include left;
  374. .icon {
  375. font-size: 24rpx;
  376. color: $light;
  377. margin-left: 26rpx;
  378. }
  379. }
  380. }
  381. }
  382. &:last-child {
  383. border-bottom: 0 none;
  384. }
  385. }
  386. }
  387. }
  388. </style>