index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. <template>
  2. <div>
  3. <van-nav-bar title="项目管理" left-text="返回" @click-left="back" right-text="新增项目" @click-right="openDialog(-1)" fixed left-arrow/>
  4. <div class="login_form">
  5. <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
  6. <van-list v-model="loading" :finished="finished" finished-text="没有更多了" :error.sync="error" error-text="请求失败,点击重新加载" @load="getProject">
  7. <van-swipe-cell v-for="(item,index) in list" :key="index">
  8. <van-cell :border="false" :title="item.projectName" :value="item.projectCode"/>
  9. <template slot="right">
  10. <van-button square type="info" text="编辑" @click="openDialog(index)"/>
  11. <van-button square type="danger" text="删除" @click="delPro(index)"/>
  12. </template>
  13. </van-swipe-cell>
  14. </van-list>
  15. </van-pull-refresh>
  16. <van-dialog v-model="show" :title="title" show-cancel-button :beforeClose="chargeBtn">
  17. <van-form style="margin: 0.4rem 0;">
  18. <van-field v-model="form.projectCode" name="项目编号" label="项目编号" placeholder="请填写项目编号" />
  19. <van-field v-model="form.projectName" name="项目名称" label="项目名称" placeholder="请填写项目名称" :rules="[{ required: true, message: '请填写项目名称' }]"/>
  20. <van-field readonly clickable name="userNames" v-model="form.userNames" label="参与人"
  21. placeholder="请选择参与人" @click="clickPicker()" />
  22. <van-field readonly clickable v-model="form.inchargerName" label="负责人"
  23. placeholder="请选择负责人" @click="showPickerIncharger = true" />
  24. </van-form>
  25. </van-dialog>
  26. <van-popup v-model="showPickerUser" position="bottom">
  27. <van-search v-model="userName" placeholder="输入员工姓名搜索" @search="onSearch"></van-search>
  28. <div style="minHeight:300px;">
  29. <van-checkbox class="userCheckbox" v-for="(item) in userList" :key="item.id" v-model="item.isChecked" >{{item.name}}</van-checkbox>
  30. <van-button style="width:100%;" @click="refreshParticipate();showPickerUser=false">确定</van-button>
  31. </div>
  32. </van-popup>
  33. <van-popup v-model="showPickerIncharger" position="bottom">
  34. <van-picker show-toolbar :columns="inchargerUserList" value-key="name" @confirm="choseIncharger" @cancel="showPickerIncharger = false" />
  35. </van-popup>
  36. </div>
  37. </div>
  38. </template>
  39. <script>
  40. export default {
  41. data() {
  42. return {
  43. user: JSON.parse(localStorage.userInfo),
  44. showPickerUser: false,
  45. showPickerIncharger: false,
  46. userName:null,
  47. total: 0,
  48. page: 1,
  49. size: 20,
  50. list: [],
  51. loading: false,
  52. finished: false,
  53. error: false,
  54. refreshing: false,
  55. allUserList:[],
  56. userList:[],
  57. inchargerUserList:[],
  58. show: false,
  59. title: "标题",
  60. form: {
  61. id: null,
  62. projectName: "",
  63. }
  64. };
  65. },
  66. created() {
  67. },
  68. methods: {
  69. choseIncharger(value, index) {
  70. this.showPickerIncharger = false;
  71. this.form.inchargerName = value.name;
  72. this.form.inchargerId = value.id;
  73. },
  74. onSearch(val) {
  75. console.log(val);
  76. this.userList = [];
  77. this.allUserList.forEach(u=>{if (u.name.startsWith(val)) {
  78. this.userList.push(u);
  79. }})
  80. },
  81. //刷新参与人
  82. refreshParticipate() {
  83. this.form.userNames = '';
  84. var that = this;
  85. that.inchargerUserList = [];
  86. that.form.userId = [];
  87. this.userList.filter(u=>u.isChecked).forEach(u=>{
  88. that.form.userNames+=(u.name+',');
  89. that.form.userId.push(u.id);
  90. that.inchargerUserList.push(u);
  91. });
  92. if (this.form.userNames.length > 0) {
  93. this.form.userNames = this.form.userNames.substring(0, this.form.userNames.length-1);
  94. }
  95. },
  96. onChange() {
  97. console.log('===');
  98. },
  99. choseUsers() {
  100. },
  101. clickPicker() {
  102. this.showPickerUser = true;
  103. },
  104. // 返回
  105. back() {
  106. history.back();
  107. },
  108. //获取用户列表
  109. getUsers() {
  110. this.$axios.post("/user/getEmployeeList", {
  111. departmentId: -1,
  112. pageIndex: 1,
  113. pageSize: 99999
  114. })
  115. .then(res => {
  116. if(res.code == "ok") {
  117. this.loading = false;
  118. this.userList = res.data.records;
  119. this.allUserList = res.data.records;
  120. } else {
  121. this.$toast.fail('获取失败');
  122. }
  123. }).catch(err=> {toast.clear();});
  124. },
  125. // 获取项目
  126. getProject() {
  127. if (this.refreshing) {
  128. this.list = [];
  129. this.refreshing = false;
  130. }
  131. if(this.total == this.list.length && this.list.length != 0) {
  132. this.loading = false;
  133. this.finished = true;
  134. return false;
  135. }
  136. this.$axios.post("/project/getProjectPage", {
  137. pageIndex: this.page,
  138. pageSize: this.size,
  139. })
  140. .then(res => {
  141. if(res.code == "ok") {
  142. this.loading = false;
  143. for(var i in res.data.records) {
  144. this.list.push(res.data.records[i])
  145. }
  146. this.total = res.data.total;
  147. } else {
  148. this.$toast.fail('获取失败');
  149. }
  150. }).catch(err=> {toast.clear();});
  151. },
  152. onRefresh() {
  153. this.finished = false;
  154. this.loading = true;
  155. this.page = 1;
  156. this.getProject();
  157. },
  158. // 新增、编辑项目
  159. openDialog(i) {
  160. if(i == -1) {
  161. this.form = {
  162. id: null,
  163. projectName: "",
  164. projectCode:null,
  165. inchargerName:null,
  166. inchargerId:null,
  167. userId:null,
  168. userNames:null
  169. }
  170. // this.userList.forEach(u=>u.isChecked=false);
  171. // this.refreshParticipate();
  172. } else {
  173. this.form = {
  174. id: this.list[i].id,
  175. projectName: this.list[i].projectName,
  176. projectCode: this.list[i].projectCode,
  177. inchargerId: this.list[i].inchargerId,
  178. inchargerName: this.list[i].inchargerName,
  179. }
  180. var part = this.list[i].participator;
  181. if (part.length>0) {
  182. for (var j in part) {
  183. this.userList.filter(u=>u.id == part[j].id)[0].isChecked = true;
  184. }
  185. this.refreshParticipate();
  186. }
  187. }
  188. this.show = true;
  189. },
  190. chargeBtn(action, done) {
  191. if (action === 'confirm') {
  192. this.show = false;
  193. const toast = this.$toast.loading({
  194. forbidClick: true,
  195. duration: 0
  196. });
  197. let formData = new FormData();
  198. formData.append("name", this.form.projectName);
  199. formData.append("code", this.form.projectCode);
  200. formData.append("inchargerId", this.form.inchargerId);
  201. for (var j in this.form.userId) {
  202. formData.append("userId", this.form.userId[j]);
  203. }
  204. let form = {
  205. name: this.form.projectName,
  206. code:this.form.projectCode,
  207. inchargerId: this.form.inchargerId,
  208. userId:this.form.userId
  209. }
  210. if(this.form.id != null) {
  211. // form.id = this.form.id;
  212. formData.append("id", this.form.id);
  213. }
  214. const config = {
  215. headers: {
  216. 'Content-Type': 'multipart/form-data'
  217. }
  218. }
  219. this.$axios.post("/project/editProject", formData, config)
  220. .then(res => {
  221. if(res.code == "ok") {
  222. toast.clear();
  223. this.$toast.success(this.form.id==null?'新增成功':'修改成功');
  224. this.list = [];
  225. this.page = 1;
  226. this.getProject();
  227. } else {
  228. toast.clear();
  229. this.$toast.fail(this.form.id==null?'新增失败':'修改失败');
  230. }
  231. }).catch(err=> {toast.clear();});
  232. } else {
  233. this.show = false;
  234. }
  235. done();
  236. },
  237. // 删除项目
  238. delPro(i) {
  239. this.$dialog.confirm({
  240. title: '删除项目',
  241. message: '确定要项目'+this.list[i].projectName+'吗?'
  242. }).then(() => {
  243. const toast = this.$toast.loading({
  244. forbidClick: true,
  245. duration: 0
  246. });
  247. this.$axios.post("/project/deleteProject", {id: this.list[i].id})
  248. .then(res => {
  249. if(res.code == "ok") {
  250. toast.clear();
  251. this.$toast.success('删除成功');
  252. this.list = [];
  253. this.page = 1;
  254. this.getProject();
  255. } else {
  256. toast.clear();
  257. this.$toast.fail('删除失败');
  258. }
  259. }).catch(err=> {toast.clear();});
  260. }).catch(() => {});
  261. },
  262. },
  263. mounted() {
  264. this.getUsers();
  265. }
  266. };
  267. </script>
  268. <style lang="less" scoped>
  269. .login_form {
  270. margin-top: 46px;
  271. }
  272. .one_report {
  273. margin-bottom: 15px;
  274. }
  275. .form_text {
  276. margin: 15px 0 30px;
  277. padding: 0 12px;
  278. }
  279. .form_btn {
  280. text-align: right;
  281. }
  282. .form_btn button {
  283. margin-left: 10px;
  284. }
  285. .one_report_data {
  286. margin-bottom: 20px;
  287. padding: 0 22px;
  288. div {
  289. line-height: 30px;
  290. }
  291. }
  292. .userCheckbox {
  293. padding: 10px;;
  294. }
  295. </style>
  296. <style lang="less">
  297. .van-nav-bar .van-icon , .van-nav-bar__text {
  298. color: #20a0ff;
  299. }
  300. </style>