users.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <template>
  2. <drawer-tabs-container>
  3. <div class="book-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. .book-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: 'BookUsers',
  25. components: {DrawerTabsContainer},
  26. props: {
  27. id: {
  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. "width": 160,
  88. render: (h, params) => {
  89. return h('span', $A.formatDate("Y-m-d H:i:s", params.row.indate));
  90. }
  91. }, {
  92. "title": this.$L("操作"),
  93. "key": 'action',
  94. "width": 80,
  95. "align": 'center',
  96. render: (h, params) => {
  97. return h('Button', {
  98. props: {
  99. type: 'primary',
  100. size: 'small'
  101. },
  102. style: {
  103. fontSize: '12px'
  104. },
  105. on: {
  106. click: () => {
  107. this.$Modal.confirm({
  108. title: this.$L('移出成员'),
  109. content: this.$L('你确定要将此成员移出项目吗?'),
  110. loading: true,
  111. onOk: () => {
  112. $A.apiAjax({
  113. url: 'docs/users/join',
  114. data: {
  115. act: 'delete',
  116. id: params.row.id,
  117. username: params.row.username,
  118. },
  119. error: () => {
  120. this.$Modal.remove();
  121. alert(this.$L('网络繁忙,请稍后再试!'));
  122. },
  123. success: (res) => {
  124. this.$Modal.remove();
  125. this.getLists();
  126. setTimeout(() => {
  127. if (res.ret === 1) {
  128. this.$Message.success(res.msg);
  129. }else{
  130. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg });
  131. }
  132. }, 350);
  133. }
  134. });
  135. }
  136. });
  137. }
  138. }
  139. }, this.$L('删除'));
  140. }
  141. }];
  142. },
  143. mounted() {
  144. if (this.canload) {
  145. this.loadYet = true;
  146. this.getLists(true);
  147. }
  148. },
  149. watch: {
  150. id() {
  151. if (this.loadYet) {
  152. this.getLists(true);
  153. }
  154. },
  155. canload(val) {
  156. if (val && !this.loadYet) {
  157. this.loadYet = true;
  158. this.getLists(true);
  159. }
  160. }
  161. },
  162. methods: {
  163. setPage(page) {
  164. this.listPage = page;
  165. this.getLists();
  166. },
  167. setPageSize(size) {
  168. if (Math.max($A.runNum(this.listPageSize), 10) != size) {
  169. this.listPageSize = size;
  170. this.getLists();
  171. }
  172. },
  173. getLists(resetLoad) {
  174. if (resetLoad === true) {
  175. this.listPage = 1;
  176. }
  177. if (this.id == 0) {
  178. this.lists = [];
  179. this.listTotal = 0;
  180. this.noDataText = this.$L("没有相关的数据");
  181. return;
  182. }
  183. this.loadIng++;
  184. this.noDataText = this.$L("数据加载中.....");
  185. $A.apiAjax({
  186. url: 'docs/users/lists',
  187. data: {
  188. page: Math.max(this.listPage, 1),
  189. pagesize: Math.max($A.runNum(this.listPageSize), 10),
  190. id: this.id,
  191. },
  192. complete: () => {
  193. this.loadIng--;
  194. },
  195. error: () => {
  196. this.noDataText = this.$L("数据加载失败!");
  197. },
  198. success: (res) => {
  199. if (res.ret === 1) {
  200. this.lists = res.data.lists;
  201. this.listTotal = res.data.total;
  202. this.noDataText = this.$L("没有相关的数据");
  203. } else {
  204. this.lists = [];
  205. this.listTotal = 0;
  206. this.noDataText = res.msg;
  207. }
  208. }
  209. });
  210. },
  211. addUser() {
  212. this.userValue = "";
  213. this.$Modal.confirm({
  214. render: (h) => {
  215. return h('div', [
  216. h('div', {
  217. style: {
  218. fontSize: '16px',
  219. fontWeight: '500',
  220. marginBottom: '20px',
  221. }
  222. }, this.$L('添加成员')),
  223. h('UserInput', {
  224. props: {
  225. value: this.userValue,
  226. multiple: true,
  227. nousername: $A.getUserName(),
  228. nobookid: this.id,
  229. placeholder: this.$L('请输入昵称/用户名搜索')
  230. },
  231. on: {
  232. input: (val) => {
  233. this.userValue = val;
  234. }
  235. }
  236. })
  237. ])
  238. },
  239. loading: true,
  240. onOk: () => {
  241. if (this.userValue) {
  242. let username = this.userValue;
  243. $A.apiAjax({
  244. url: 'docs/users/join',
  245. data: {
  246. act: 'join',
  247. id: this.id,
  248. username: username,
  249. },
  250. error: () => {
  251. this.$Modal.remove();
  252. alert(this.$L('网络繁忙,请稍后再试!'));
  253. },
  254. success: (res) => {
  255. this.$Modal.remove();
  256. this.getLists();
  257. setTimeout(() => {
  258. if (res.ret === 1) {
  259. this.$Message.success(res.msg);
  260. } else {
  261. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
  262. }
  263. }, 350);
  264. }
  265. });
  266. } else {
  267. this.$Modal.remove();
  268. }
  269. },
  270. });
  271. }
  272. }
  273. }
  274. </script>