index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. <template>
  2. <div>
  3. <van-nav-bar title="项目管理" left-text="返回" @click-left="back" :right-text="canEdit?新增项目:''" @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" v-if="canEdit">
  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. canEdit:false,
  44. user: JSON.parse(localStorage.userInfo),
  45. showPickerUser: false,
  46. showPickerIncharger: false,
  47. userName:null,
  48. total: 0,
  49. page: 1,
  50. size: 1000,
  51. list: [],
  52. loading: false,
  53. finished: false,
  54. error: false,
  55. refreshing: false,
  56. allUserList:[],
  57. userList:[],
  58. inchargerUserList:[],
  59. show: false,
  60. title: "修改项目",
  61. form: {
  62. id: null,
  63. projectName: "",
  64. }
  65. };
  66. },
  67. created() {
  68. },
  69. methods: {
  70. choseIncharger(value, index) {
  71. this.showPickerIncharger = false;
  72. this.form.inchargerName = value.name;
  73. this.form.inchargerId = value.id;
  74. },
  75. onSearch(val) {
  76. console.log(val);
  77. this.userList = [];
  78. this.allUserList.forEach(u=>{if (u.name.startsWith(val)) {
  79. this.userList.push(u);
  80. }})
  81. },
  82. //刷新参与人
  83. refreshParticipate() {
  84. this.form.userNames = '';
  85. var that = this;
  86. that.inchargerUserList = [];
  87. that.form.userId = [];
  88. this.userList.filter(u=>u.isChecked).forEach(u=>{
  89. that.form.userNames+=(u.name+',');
  90. that.form.userId.push(u.id);
  91. that.inchargerUserList.push(u);
  92. });
  93. if (this.form.userNames.length > 0) {
  94. this.form.userNames = this.form.userNames.substring(0, this.form.userNames.length-1);
  95. }
  96. },
  97. onChange() {
  98. console.log('===');
  99. },
  100. choseUsers() {
  101. },
  102. clickPicker() {
  103. this.showPickerUser = true;
  104. },
  105. // 返回
  106. back() {
  107. history.back();
  108. },
  109. //获取用户列表
  110. getUsers() {
  111. this.$axios.post("/user/getEmployeeList", {
  112. departmentId: -1,
  113. pageIndex: 1,
  114. pageSize: 99999
  115. })
  116. .then(res => {
  117. if(res.code == "ok") {
  118. this.loading = false;
  119. this.userList = res.data.records;
  120. this.allUserList = res.data.records;
  121. } else {
  122. this.$toast.fail('获取失败');
  123. }
  124. }).catch(err=> {toast.clear();});
  125. },
  126. // 获取项目
  127. getProject() {
  128. if (this.refreshing) {
  129. this.list = [];
  130. this.refreshing = false;
  131. }
  132. if(this.total == this.list.length && this.list.length != 0) {
  133. this.loading = false;
  134. this.finished = true;
  135. return false;
  136. }
  137. this.$axios.post("/project/getProjectPage", {
  138. pageIndex: this.page,
  139. pageSize: this.size,
  140. })
  141. .then(res => {
  142. if(res.code == "ok") {
  143. this.loading = false;
  144. if (this.list.length == 0) {
  145. this.finished = true;
  146. }
  147. for(var i in res.data.records) {
  148. this.list.push(res.data.records[i])
  149. }
  150. this.total = res.data.total;
  151. this.page++;
  152. } else {
  153. this.$toast.fail('获取失败:'+res.msg);
  154. }
  155. }).catch(err=> {toast.clear();});
  156. },
  157. onRefresh() {
  158. this.finished = false;
  159. this.loading = true;
  160. this.page = 1;
  161. this.getProject();
  162. },
  163. // 新增、编辑项目
  164. openDialog(i) {
  165. if(i == -1) {
  166. this.title = "新增项目";
  167. this.form = {
  168. id: null,
  169. projectName: "",
  170. projectCode:null,
  171. inchargerName:null,
  172. inchargerId:null,
  173. userId:null,
  174. userNames:null
  175. }
  176. // this.userList.forEach(u=>u.isChecked=false);
  177. // this.refreshParticipate();
  178. } else {
  179. this.title = "修改项目";
  180. this.form = {
  181. id: this.list[i].id,
  182. projectName: this.list[i].projectName,
  183. projectCode: this.list[i].projectCode,
  184. inchargerId: this.list[i].inchargerId,
  185. inchargerName: this.list[i].inchargerName,
  186. }
  187. var part = this.list[i].participator;
  188. if (part.length>0) {
  189. for (var j in part) {
  190. this.userList.filter(u=>u.id == part[j].id)[0].isChecked = true;
  191. }
  192. this.refreshParticipate();
  193. }
  194. }
  195. this.show = true;
  196. },
  197. chargeBtn(action, done) {
  198. if (action === 'confirm') {
  199. this.show = false;
  200. const toast = this.$toast.loading({
  201. forbidClick: true,
  202. duration: 0
  203. });
  204. let formData = new FormData();
  205. formData.append("name", this.form.projectName);
  206. formData.append("code", this.form.projectCode);
  207. formData.append("inchargerId", this.form.inchargerId);
  208. for (var j in this.form.userId) {
  209. formData.append("userId", this.form.userId[j]);
  210. }
  211. let form = {
  212. name: this.form.projectName,
  213. code:this.form.projectCode,
  214. inchargerId: this.form.inchargerId,
  215. userId:this.form.userId
  216. }
  217. if(this.form.id != null) {
  218. // form.id = this.form.id;
  219. formData.append("id", this.form.id);
  220. }
  221. const config = {
  222. headers: {
  223. 'Content-Type': 'multipart/form-data'
  224. }
  225. }
  226. this.$axios.post("/project/editProject", formData, config)
  227. .then(res => {
  228. if(res.code == "ok") {
  229. toast.clear();
  230. this.$toast.success(this.form.id==null?'新增成功':'修改成功');
  231. this.list = [];
  232. this.page = 1;
  233. this.getProject();
  234. } else {
  235. toast.clear();
  236. this.$toast.fail(this.form.id==null?'新增失败':'修改失败');
  237. }
  238. }).catch(err=> {toast.clear();});
  239. } else {
  240. this.show = false;
  241. }
  242. done();
  243. },
  244. // 删除项目
  245. delPro(i) {
  246. this.$dialog.confirm({
  247. title: '删除项目',
  248. message: '确定要项目'+this.list[i].projectName+'吗?'
  249. }).then(() => {
  250. const toast = this.$toast.loading({
  251. forbidClick: true,
  252. duration: 0
  253. });
  254. this.$axios.post("/project/deleteProject", {id: this.list[i].id})
  255. .then(res => {
  256. if(res.code == "ok") {
  257. toast.clear();
  258. this.$toast.success('删除成功');
  259. this.list = [];
  260. this.page = 1;
  261. this.getProject();
  262. } else {
  263. toast.clear();
  264. this.$toast.fail(res.msg);
  265. }
  266. }).catch(err=> {toast.clear();});
  267. }).catch(() => {});
  268. },
  269. },
  270. mounted() {
  271. this.getUsers();
  272. this.canEdit = this.user.role==1||this.user.role==2||this.user.role==5
  273. }
  274. };
  275. </script>
  276. <style lang="less" scoped>
  277. .login_form {
  278. margin-top: 46px;
  279. }
  280. .one_report {
  281. margin-bottom: 15px;
  282. }
  283. .form_text {
  284. margin: 15px 0 30px;
  285. padding: 0 12px;
  286. }
  287. .form_btn {
  288. text-align: right;
  289. }
  290. .form_btn button {
  291. margin-left: 10px;
  292. }
  293. .one_report_data {
  294. margin-bottom: 20px;
  295. padding: 0 22px;
  296. div {
  297. line-height: 30px;
  298. }
  299. }
  300. .userCheckbox {
  301. padding: 10px;;
  302. }
  303. </style>
  304. <style lang="less">
  305. .van-nav-bar .van-icon , .van-nav-bar__text {
  306. color: #20a0ff;
  307. }
  308. </style>