ProjectUserList.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <template>
  2. <div class="container-fluid">
  3. <Navbar
  4. :title="projectName + '-项目人员'"
  5. :is-go-back="true"
  6. />
  7. <button
  8. type="button"
  9. class="btn btn-success"
  10. style="margin-bottom: 10px; margin-top: 10px;"
  11. @click="edit"
  12. >
  13. 编辑
  14. </button>
  15. <div v-if="editFlag">
  16. <div class="row">
  17. <div
  18. v-for="user in userList"
  19. :key="user.id"
  20. class="col-sm-6 col-md-4"
  21. >
  22. <div class="thumbnail">
  23. <div class="caption">
  24. <h4>
  25. <input
  26. v-model="user.selected"
  27. autocomplete="off"
  28. type="checkbox"
  29. :value="user.userId"
  30. />
  31. {{ user.name }}
  32. </h4>
  33. </div>
  34. </div>
  35. </div>
  36. </div>
  37. <button
  38. type="button"
  39. class="btn btn-danger"
  40. @click="save()"
  41. >
  42. 保存项目成员
  43. </button>
  44. </div>
  45. <div v-else>
  46. <p
  47. v-if="projectItemUsers == null || projectItemUsers.length == 0"
  48. class="bg-danger"
  49. style="padding: 15px;"
  50. >
  51. 该项目未有任何人员参与
  52. </p>
  53. <div class="row">
  54. <div
  55. v-for="user in projectItemUsers"
  56. :key="user.id"
  57. class="col-sm-6 col-md-4"
  58. >
  59. <div
  60. class="thumbnail"
  61. @click="openLine2(user)"
  62. >
  63. <div class="caption">
  64. <h4>
  65. {{ user.userName }}
  66. </h4>
  67. </div>
  68. </div>
  69. </div>
  70. </div>
  71. </div>
  72. </div>
  73. </template>
  74. <script>
  75. import Common from '../common/Common.js';
  76. import { Uuid } from 'pc-component-v3';
  77. import { Notify } from 'pc-component-v3';
  78. export default {
  79. components: {
  80. },
  81. data: function () {
  82. return {
  83. projectId: '',
  84. projectName: '',
  85. userList: [],
  86. projectItemUsers: [],
  87. // 编辑的标识符
  88. editFlag: false,
  89. };
  90. },
  91. mounted: function () {
  92. this.initData();
  93. this.initUsers();
  94. },
  95. methods: {
  96. /**
  97. * 初始化项目
  98. */
  99. initData: function () {
  100. this.projectId = this.$route.params.projectId;
  101. this.projectName = this.$route.query.projectName;
  102. },
  103. /**
  104. * 加载所有的人员
  105. * @author ZhangTeng 20190212
  106. */
  107. initUsers: function () {
  108. var _self = this;
  109. // 清空人员数组
  110. _self.userList = [];
  111. // _self.userList.splice(0, _self.userList.length);
  112. $.ajax({
  113. url: Common.getApiURL('userResource/listByClientId'),
  114. type: 'get',
  115. dataType: 'json',
  116. contentType: 'application/json',
  117. beforeSend: function (request) {
  118. Common.addTokenToRequest(request);
  119. },
  120. success: function (data) {
  121. // console.log(data);
  122. for (var index = 0; index < data.length; index++) {
  123. data[index].selected = false;
  124. _self.userList[index] = data[index];
  125. // _self.$set(_self.userList, index, data[index]);
  126. }
  127. console.log(_self.userList);
  128. _self.initProjectItemUser();
  129. },
  130. error: function (XMLHttpRequest, textStatus, errorThrown) {
  131. Common.processException(XMLHttpRequest, textStatus, errorThrown);
  132. },
  133. });
  134. },
  135. /**
  136. * 打开用户的任务
  137. */
  138. openLine2: function (user) {
  139. var uuid = Uuid.createUUID();
  140. var obj={
  141. userId:user.userId,
  142. userName:user.userName,
  143. };
  144. localStorage.setItem(uuid, JSON.stringify(obj));
  145. this.$router.push('/trace/userNotFinishedTrace/' + uuid);
  146. },
  147. /**
  148. * 编辑人员
  149. * @author ZhangTeng 20190212
  150. */
  151. edit: function () {
  152. this.editFlag = !this.editFlag;
  153. this.initProjectItemUser();
  154. },
  155. /**
  156. * 初始化项目用户
  157. * @author ZhangTeng 20190212
  158. */
  159. initProjectItemUser: function () {
  160. var _self = this;
  161. // 清空项目-人员数组
  162. _self.projectItemUsers = [];
  163. // _self.projectItemUsers.splice(0, _self.projectItemUsers.length);
  164. $.ajax({
  165. url: Common.getApiURL('ProjectItemUserResource/listByProjectItemId'),
  166. type: 'get',
  167. dataType: 'json',
  168. contentType: 'application/json',
  169. data: {
  170. 'projectItemId': this.projectId,
  171. },
  172. beforeSend: function (request) {
  173. Common.addTokenToRequest(request);
  174. },
  175. success: function (data) {
  176. // console.log(data);
  177. if(data == null){
  178. return;
  179. }
  180. for (var index1 = 0; index1 < _self.userList.length; index1++) {
  181. for (var index = 0; index < data.length; index++) {
  182. if (data[index].userId == _self.userList[index1].id) {
  183. _self.userList[index1].selected = true;
  184. }
  185. }
  186. }
  187. for (let index = 0; index < data.length; index++) {
  188. _self.projectItemUsers[index] = data[index];
  189. // _self.$set(_self.projectItemUsers, index, data[index]);
  190. }
  191. },
  192. error: function (XMLHttpRequest, textStatus, errorThrown) {
  193. Common.processException(XMLHttpRequest, textStatus, errorThrown);
  194. },
  195. });
  196. },
  197. /**
  198. * 保存项目用户
  199. */
  200. save: function () {
  201. var _self = this;
  202. var userIds = [];
  203. for (var index1 = 0; index1 < _self.userList.length; index1++) {
  204. if (true == _self.userList[index1].selected) {
  205. userIds.push(_self.userList[index1].id);
  206. }
  207. }
  208. if (userIds.length == 0) {
  209. Notify.error('不能保存', '至少需要选择一个人员', false);
  210. return;
  211. }
  212. $.ajax({
  213. url: Common.getApiURL('ProjectItemUserResource/save?projectItemId=' + this.projectId),
  214. type: 'post',
  215. contentType: 'application/json',
  216. data: JSON.stringify(userIds),
  217. beforeSend: function (request) {
  218. Common.addTokenToRequest(request);
  219. },
  220. success: function (data) {
  221. _self.edit();
  222. },
  223. error: function (XMLHttpRequest, textStatus, errorThrown) {
  224. Common.processException(XMLHttpRequest, textStatus, errorThrown);
  225. },
  226. });
  227. },
  228. },
  229. };
  230. </script>
  231. <style scoped>
  232. </style>