users.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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" @on-change="setPage" @on-page-size-change="setPageSize" :page-size-opts="[10,20,30,50,100]" placement="top" show-elevator show-sizer show-total></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. "minWidth": 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.loadYet = true;
  151. this.getLists(true);
  152. }
  153. },
  154. canload(val) {
  155. if (val && !this.loadYet) {
  156. this.loadYet = true;
  157. this.getLists(true);
  158. }
  159. }
  160. },
  161. methods: {
  162. setPage(page) {
  163. this.listPage = page;
  164. this.getLists();
  165. },
  166. setPageSize(size) {
  167. if (Math.max($A.runNum(this.listPageSize), 10) != size) {
  168. this.listPageSize = size;
  169. this.getLists();
  170. }
  171. },
  172. getLists(resetLoad) {
  173. if (resetLoad === true) {
  174. this.listPage = 1;
  175. }
  176. if (this.projectid == 0) {
  177. this.lists = [];
  178. this.listTotal = 0;
  179. this.noDataText = "没有相关的数据";
  180. return;
  181. }
  182. this.loadIng++;
  183. $A.aAjax({
  184. url: 'project/users/lists',
  185. data: {
  186. page: Math.max(this.listPage, 1),
  187. pagesize: Math.max($A.runNum(this.listPageSize), 10),
  188. projectid: this.projectid,
  189. },
  190. complete: () => {
  191. this.loadIng--;
  192. },
  193. success: (res) => {
  194. if (res.ret === 1) {
  195. this.lists = res.data.lists;
  196. this.listTotal = res.data.total;
  197. } else {
  198. this.lists = [];
  199. this.listTotal = 0;
  200. this.noDataText = res.msg;
  201. }
  202. }
  203. });
  204. },
  205. addUser() {
  206. this.userValue = "";
  207. this.$Modal.confirm({
  208. render: (h) => {
  209. return h('div', [
  210. h('div', {
  211. style: {
  212. fontSize: '16px',
  213. fontWeight: '500',
  214. marginBottom: '20px',
  215. }
  216. }, '添加成员'),
  217. h('UseridInput', {
  218. props: {
  219. value: this.userValue,
  220. multiple: true,
  221. placeholder: '请输入昵称/用户名搜索'
  222. },
  223. on: {
  224. input: (val) => {
  225. this.userValue = val;
  226. }
  227. }
  228. })
  229. ])
  230. },
  231. loading: true,
  232. onOk: () => {
  233. if (this.userValue) {
  234. let username = this.userValue;
  235. $A.aAjax({
  236. url: 'project/users/join',
  237. data: {
  238. act: 'join',
  239. projectid: this.projectid,
  240. username: username,
  241. },
  242. error: () => {
  243. this.$Modal.remove();
  244. this.$Message.error(this.$L('网络繁忙,请稍后再试!'));
  245. },
  246. success: (res) => {
  247. this.$Modal.remove();
  248. setTimeout(() => {
  249. if (res.ret === 1) {
  250. this.$Message.success(res.msg);
  251. this.getLists();
  252. } else {
  253. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
  254. }
  255. }, 350);
  256. }
  257. });
  258. } else {
  259. this.$Modal.remove();
  260. }
  261. },
  262. });
  263. }
  264. }
  265. }
  266. </script>