users.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <template>
  2. <drawer-tabs-container>
  3. <div class="project-complete">
  4. <!-- 按钮 -->
  5. <Button :loading="loadIng > 0" type="primary" icon="md-add" @click="addUser">添加成员</Button>
  6. <!-- 列表 -->
  7. <Table class="tableFill" ref="tableRef" :columns="columns" :data="lists" :loading="loadIng > 0" :no-data-text="noDataText" stripe></Table>
  8. <!-- 分页 -->
  9. <Page class="pageBox" :total="listTotal" :current="listPage" :disabled="loadIng > 0" @on-change="setPage" @on-page-size-change="setPageSize" :page-size-opts="[10,20,30,50,100]" placement="top" show-elevator show-sizer show-total transfer></Page>
  10. </div>
  11. </drawer-tabs-container>
  12. </template>
  13. <style lang="scss" scoped>
  14. .project-complete {
  15. padding: 0 12px;
  16. .tableFill {
  17. margin: 12px 0 20px;
  18. }
  19. }
  20. </style>
  21. <script>
  22. import DrawerTabsContainer from "../DrawerTabsContainer";
  23. export default {
  24. name: 'ProjectUsers',
  25. components: {DrawerTabsContainer},
  26. props: {
  27. projectid: {
  28. default: 0
  29. },
  30. canload: {
  31. type: Boolean,
  32. default: true
  33. },
  34. },
  35. data () {
  36. return {
  37. loadYet: false,
  38. loadIng: 0,
  39. columns: [],
  40. lists: [],
  41. listPage: 1,
  42. listTotal: 0,
  43. noDataText: "数据加载中.....",
  44. }
  45. },
  46. created() {
  47. this.columns = [{
  48. "title": "头像",
  49. "minWidth": 60,
  50. "maxWidth": 100,
  51. render: (h, params) => {
  52. return h('img', {
  53. style: {
  54. width: "32px",
  55. height: "32px",
  56. verticalAlign: "middle",
  57. objectFit: "cover",
  58. borderRadius: "50%"
  59. },
  60. attrs: {
  61. src: params.row.userimg
  62. },
  63. });
  64. }
  65. }, {
  66. "title": "昵称",
  67. "minWidth": 80,
  68. "ellipsis": true,
  69. render: (h, params) => {
  70. return h('span', params.row.nickname || '-');
  71. }
  72. }, {
  73. "title": "用户名",
  74. "key": 'username',
  75. "minWidth": 80,
  76. "ellipsis": true,
  77. }, {
  78. "title": "职位/职称",
  79. "minWidth": 100,
  80. "ellipsis": true,
  81. render: (h, params) => {
  82. return h('span', params.row.profession || '-');
  83. }
  84. }, {
  85. "title": "成员角色",
  86. "minWidth": 100,
  87. render: (h, params) => {
  88. return h('span', params.row.isowner ? '项目负责人' : '成员');
  89. }
  90. }, {
  91. "title": "加入时间",
  92. "width": 160,
  93. render: (h, params) => {
  94. return h('span', $A.formatDate("Y-m-d H:i:s", params.row.indate));
  95. }
  96. }, {
  97. "title": "操作",
  98. "key": 'action',
  99. "width": 80,
  100. "align": 'center',
  101. render: (h, params) => {
  102. return h('Button', {
  103. props: {
  104. type: 'primary',
  105. size: 'small'
  106. },
  107. style: {
  108. fontSize: '12px'
  109. },
  110. on: {
  111. click: () => {
  112. this.$Modal.confirm({
  113. title: '移出成员',
  114. content: '你确定要将此成员移出项目吗?',
  115. loading: true,
  116. onOk: () => {
  117. $A.aAjax({
  118. url: 'project/users/join',
  119. data: {
  120. act: 'delete',
  121. projectid: params.row.projectid,
  122. username: params.row.username,
  123. },
  124. error: () => {
  125. this.$Modal.remove();
  126. alert(this.$L('网络繁忙,请稍后再试!'));
  127. },
  128. success: (res) => {
  129. this.$Modal.remove();
  130. this.getLists();
  131. setTimeout(() => {
  132. if (res.ret === 1) {
  133. this.$Message.success(res.msg);
  134. }else{
  135. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg });
  136. }
  137. }, 350);
  138. }
  139. });
  140. }
  141. });
  142. }
  143. }
  144. }, '删除');
  145. }
  146. }];
  147. },
  148. mounted() {
  149. if (this.canload) {
  150. this.loadYet = true;
  151. this.getLists(true);
  152. }
  153. },
  154. watch: {
  155. projectid() {
  156. if (this.loadYet) {
  157. this.getLists(true);
  158. }
  159. },
  160. canload(val) {
  161. if (val && !this.loadYet) {
  162. this.loadYet = true;
  163. this.getLists(true);
  164. }
  165. }
  166. },
  167. methods: {
  168. setPage(page) {
  169. this.listPage = page;
  170. this.getLists();
  171. },
  172. setPageSize(size) {
  173. if (Math.max($A.runNum(this.listPageSize), 10) != size) {
  174. this.listPageSize = size;
  175. this.getLists();
  176. }
  177. },
  178. getLists(resetLoad) {
  179. if (resetLoad === true) {
  180. this.listPage = 1;
  181. }
  182. if (this.projectid == 0) {
  183. this.lists = [];
  184. this.listTotal = 0;
  185. this.noDataText = "没有相关的数据";
  186. return;
  187. }
  188. this.loadIng++;
  189. this.noDataText = "数据加载中.....";
  190. $A.aAjax({
  191. url: 'project/users/lists',
  192. data: {
  193. page: Math.max(this.listPage, 1),
  194. pagesize: Math.max($A.runNum(this.listPageSize), 10),
  195. projectid: this.projectid,
  196. },
  197. complete: () => {
  198. this.loadIng--;
  199. },
  200. error: () => {
  201. this.noDataText = "数据加载失败!";
  202. },
  203. success: (res) => {
  204. if (res.ret === 1) {
  205. this.lists = res.data.lists;
  206. this.listTotal = res.data.total;
  207. this.noDataText = "没有相关的数据";
  208. } else {
  209. this.lists = [];
  210. this.listTotal = 0;
  211. this.noDataText = res.msg;
  212. }
  213. }
  214. });
  215. },
  216. addUser() {
  217. this.userValue = "";
  218. this.$Modal.confirm({
  219. render: (h) => {
  220. return h('div', [
  221. h('div', {
  222. style: {
  223. fontSize: '16px',
  224. fontWeight: '500',
  225. marginBottom: '20px',
  226. }
  227. }, '添加成员'),
  228. h('UseridInput', {
  229. props: {
  230. value: this.userValue,
  231. multiple: true,
  232. noprojectid: this.projectid,
  233. placeholder: '请输入昵称/用户名搜索'
  234. },
  235. on: {
  236. input: (val) => {
  237. this.userValue = val;
  238. }
  239. }
  240. })
  241. ])
  242. },
  243. loading: true,
  244. onOk: () => {
  245. if (this.userValue) {
  246. let username = this.userValue;
  247. $A.aAjax({
  248. url: 'project/users/join',
  249. data: {
  250. act: 'join',
  251. projectid: this.projectid,
  252. username: username,
  253. },
  254. error: () => {
  255. this.$Modal.remove();
  256. alert(this.$L('网络繁忙,请稍后再试!'));
  257. },
  258. success: (res) => {
  259. this.$Modal.remove();
  260. this.getLists();
  261. setTimeout(() => {
  262. if (res.ret === 1) {
  263. this.$Message.success(res.msg);
  264. } else {
  265. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
  266. }
  267. }, 350);
  268. }
  269. });
  270. } else {
  271. this.$Modal.remove();
  272. }
  273. },
  274. });
  275. }
  276. }
  277. }
  278. </script>