users.vue 11 KB

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