users.vue 10 KB

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