users.vue 11 KB

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