edit.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  1. <template>
  2. <div>
  3. <van-nav-bar title="编辑项目" left-text="返回" @click-left="back" fixed left-arrow />
  4. <div class="content">
  5. <van-form ref="projectSubmit">
  6. <van-field v-model="projectDetail.projectCode" label="项目编号" :disabled="!editCodeAndName"></van-field>
  7. <van-field v-model="projectDetail.projectName" label="项目名称" :disabled="!editCodeAndName"></van-field>
  8. <!-- 主项目 -->
  9. <van-field label="主项目" @click="mainProjectShow = true" readonly clickable v-if="user.timeType.mainProjectState == '1'">
  10. <template #input>
  11. <span>{{projectDetail.projectMainName}}</span>
  12. </template>
  13. </van-field>
  14. <van-popup v-model="mainProjectShow" position="bottom">
  15. <van-picker
  16. show-toolbar
  17. value-key="name"
  18. :columns="mainProjectList"
  19. @confirm="mainProjectConfirm"
  20. @cancel="mainProjectShow = false"
  21. ></van-picker>
  22. </van-popup>
  23. <!-- 项目分类 -->
  24. <van-field label="项目分类" @click="categoryShow = true" readonly clickable v-if="user.timeType.mainProjectState != '1'">
  25. <template #input>
  26. <span>{{projectDetail.categoryName}}</span>
  27. </template>
  28. </van-field>
  29. <van-popup v-model="categoryShow" position="bottom">
  30. <van-picker
  31. show-toolbar
  32. value-key="name"
  33. :columns="categoryList"
  34. @confirm="categoryConfirm"
  35. @cancel="categoryShow = false"
  36. ></van-picker>
  37. </van-popup>
  38. <!-- 项目描述 -->
  39. <van-field v-model="projectDetail.projectDesc" label="项目描述"></van-field>
  40. <!-- 项目类型 -->
  41. <van-field label="项目类型" @click="publicShow = true" readonly clickable>
  42. <template #input>
  43. <span>{{publicList[projectDetail.isPublic]}}</span>
  44. </template>
  45. </van-field>
  46. <van-popup v-model="publicShow" position="bottom">
  47. <van-picker
  48. show-toolbar
  49. :columns="publicList"
  50. @confirm="publicConfirm"
  51. @cancel="publicShow = false"
  52. ></van-picker>
  53. </van-popup>
  54. <!-- 项目级别 -->
  55. <van-field label="项目级别" @click="levelShow = true" readonly clickable>
  56. <template #input>
  57. <span>{{projectDetail.levelLabel}}</span>
  58. </template>
  59. </van-field>
  60. <van-popup v-model="levelShow" position="bottom">
  61. <van-picker
  62. show-toolbar
  63. value-key="label"
  64. :columns="levelList"
  65. @confirm="levelConfirm"
  66. @cancel="levelShow = false"
  67. ></van-picker>
  68. </van-popup>
  69. <!-- 参与人 -->
  70. <van-button @click="test">test</van-button>
  71. <van-field label="全部参与人" @click="userNamesShow = true" readonly clickable v-show="projectDetail.isPublic == 0">
  72. <template #input>
  73. <span v-if="!projectDetail.userNames"></span>
  74. <span v-else-if="user.userNameNeedTranslate == '1'">
  75. <span v-for="item,index in projectDetail.userNames.split(',')" :key="item">
  76. <ww-open-data type='userName' :openid='item'></ww-open-data>
  77. <span v-if="index != (projectDetail.userNames.split(',').length - 1)">,</span>
  78. </span>
  79. </span>
  80. <span v-else>{{projectDetail.userNames}}</span>
  81. </template>
  82. </van-field>
  83. <van-popup v-model="userNamesShow" position="bottom">
  84. <van-search v-model="userName" placeholder="输入员工姓名搜索" @search="onSearch" v-if="user.userNameNeedTranslate != '1'"></van-search>
  85. <div style="minHeight:300px;">
  86. <template v-if="user.userNameNeedTranslate == '1'">
  87. <van-checkbox class="userCheckbox" v-for="(item) in userList" :key="item.id" v-model="item.isChecked" ><ww-open-data type='userName' :openid='item.name'></ww-open-data></van-checkbox>
  88. </template>
  89. <template v-else>
  90. <van-checkbox class="userCheckbox" v-for="(item) in userList" :key="item.id" v-model="item.isChecked" >{{item.name}}</van-checkbox>
  91. </template>
  92. <van-button style="width:100%;position: -webkit-sticky;position: sticky;bottom: 0;" @click="userNamesConfirm();userNamesShow=false">确定</van-button>
  93. </div>
  94. </van-popup>
  95. <!-- 项目经理 -->
  96. <van-field label="项目经理" @click="inchargerShow = true" readonly clickable>
  97. <template #input>
  98. <span v-if="user.userNameNeedTranslate == '1'"><ww-open-data type='userName' :openid='projectDetail.inchargerName'></ww-open-data></span>
  99. <span v-else>{{projectDetail.inchargerName}}</span>
  100. </template>
  101. </van-field>
  102. <van-popup v-model="inchargerShow" position="bottom">
  103. <van-picker
  104. show-toolbar
  105. value-key="name"
  106. :columns="inchargerList"
  107. @confirm="inchargerConfirm"
  108. @cancel="inchargerShow = false"
  109. >
  110. <template #option="item">
  111. <span v-if="user.userNameNeedTranslate == '1'"><ww-open-data type='userName' :openid='item.name'></ww-open-data></span>
  112. <span v-else>{{item.name}}</span>
  113. </template>
  114. </van-picker>
  115. </van-popup>
  116. <!-- 开始日期 -->
  117. <van-field label="计划开始日期" @click="startDateShow = true" readonly clickable>
  118. <template #input>
  119. <span>{{projectDetail.planStartDate}}</span>
  120. </template>
  121. </van-field>
  122. <van-popup v-model="startDateShow" position="bottom">
  123. <van-datetime-picker
  124. v-model="currentStartDate"
  125. type="date"
  126. title="选择年月日"
  127. :min-date="minDate"
  128. :max-date="maxDate"
  129. @confirm="startDateConfirm"
  130. @cancel="startDateShow = false"
  131. />
  132. </van-popup>
  133. <!-- 结束日期 -->
  134. <van-field label="计划结束日期" @click="endDateShow = true" readonly clickable>
  135. <template #input>
  136. <span>{{projectDetail.planEndDate}}</span>
  137. </template>
  138. </van-field>
  139. <van-popup v-model="endDateShow" position="bottom">
  140. <van-datetime-picker
  141. v-model="currentEndDate"
  142. type="date"
  143. title="选择年月日"
  144. :min-date="minDate"
  145. :max-date="maxDate"
  146. @confirm="endDateConfirm"
  147. @cancel="endDateShow = false"
  148. />
  149. </van-popup>
  150. </van-form>
  151. <div class="form_btn" style="position: fixed; bottom: 0px; width: 100%">
  152. <div style="padding-bottom: 10px">
  153. <van-button square block type="info" @click="deleteProject()" style="width: 50%; float: left">删除</van-button>
  154. <van-button square block type="danger" @click="submitProject" style="width: 50%; float: left">保存</van-button>
  155. </div>
  156. </div>
  157. </div>
  158. </div>
  159. </template>
  160. <script>
  161. export default {
  162. data() {
  163. return {
  164. user: JSON.parse(localStorage.userInfo),
  165. projectId: JSON.parse(sessionStorage.projectId),
  166. minDate: new Date(2020,0,1),
  167. maxDate: new Date(2025,11,31),
  168. projectDetail: {},
  169. editCodeAndName: false,
  170. mainProjectList: [],
  171. mainProjectShow: false,
  172. categoryList: [],
  173. categoryShow: false,
  174. publicList: ['普通项目','公共项目'],
  175. publicShow: false,
  176. levelList: [],
  177. levelShow: false,
  178. userName: null,
  179. allUserList: [],
  180. userList: [],
  181. userNamesShow: false,
  182. inchargerList: [],
  183. inchargerShow: false,
  184. currentStartDate: new Date(),
  185. startDateShow: false,
  186. currentEndDate: new Date(),
  187. endDateShow: false
  188. }
  189. },
  190. mounted() {
  191. this.getProjectDetail()
  192. if(this.user.timeType.mainProjectState == '1'){
  193. this.getMainProjectList()
  194. }else{
  195. this.getCategoryList()
  196. }
  197. },
  198. methods: {
  199. back() {
  200. history.back();
  201. },
  202. formatDate(date) {
  203. let mon = date.getMonth() + 1
  204. return `${date.getFullYear()}-${mon<10?'0'+mon:mon}-${date.getDate()<10?'0'+date.getDate():date.getDate()}`;
  205. },
  206. test(){
  207. console.log(this.projectDetail);
  208. },
  209. mainProjectConfirm(value,key){
  210. this.projectDetail.projectMainId = value.id
  211. this.projectDetail.projectMainName = value.name
  212. this.categoryShow = false
  213. },
  214. categoryConfirm(value,key){
  215. this.projectDetail.category = value.id
  216. this.projectDetail.categoryName = value.name
  217. this.categoryShow = false
  218. },
  219. publicConfirm(value,key){
  220. this.projectDetail.isPublic = key
  221. this.publicShow = false
  222. },
  223. levelConfirm(value,key){
  224. this.projectDetail.level = value.id
  225. this.projectDetail.levelLabel = value.label
  226. this.levelShow = false
  227. },
  228. onSearch(val) {
  229. console.log(val);
  230. this.userList = [];
  231. this.allUserList.forEach(u=>{if (u.name.startsWith(val)) {
  232. this.userList.push(u);
  233. }})
  234. },
  235. userNamesConfirm(){
  236. let that = this;
  237. that.inchargerList = [];
  238. that.projectDetail.userId = [];
  239. let userNames = ''
  240. this.userList.filter(u=>u.isChecked).forEach(u=>{
  241. userNames+=(u.name+',');
  242. that.projectDetail.userId.push(u.id);
  243. that.inchargerList.push(u);
  244. });
  245. if (userNames.length > 0) {
  246. userNames = userNames.substring(0, userNames.length-1);
  247. }
  248. this.$set(this.projectDetail,'userNames',userNames)
  249. },
  250. inchargerConfirm(value,key){
  251. this.projectDetail.inchargerId = value.id
  252. this.projectDetail.inchargerName = value.name
  253. this.inchargerShow = false
  254. },
  255. startDateConfirm(value){
  256. this.projectDetail.planStartDate = this.formatDate(value)
  257. this.startDateShow = false
  258. },
  259. endDateConfirm(value){
  260. this.projectDetail.planEndDate = this.formatDate(value)
  261. this.endDateShow = false
  262. },
  263. submitProject(){
  264. // this.$refs.projectSubmit.validate().then(()=>{
  265. let formData = new FormData();
  266. formData.append("id", this.projectDetail.id);
  267. formData.append("name", this.projectDetail.projectName);
  268. formData.append("code", this.projectDetail.projectCode ? this.projectDetail.projectCode : '');
  269. if(this.projectDetail.projectMainId && this.user.timeType.mainProjectState == '1') {
  270. formData.append("projectMainId", this.addForm.projectMainId);
  271. }
  272. if(this.projectDetail.category) {
  273. formData.append("category", this.projectDetail.category);
  274. }
  275. formData.append("projectDesc", this.projectDetail.projectDesc ? this.projectDetail.projectDesc : '');
  276. formData.append("isPublic", this.projectDetail.isPublic);
  277. if(this.projectDetail.userId.length != 0 && this.projectDetail.isPublic == 0) {
  278. for(let i in this.projectDetail.userId) {
  279. formData.append("userId", this.projectDetail.userId[i]);
  280. }
  281. }
  282. if(this.projectDetail.inchargerId) {
  283. formData.append("inchargerId", this.projectDetail.inchargerId);
  284. }
  285. if(this.projectDetail.planStartDate) {
  286. formData.append("planStartDate", this.projectDetail.planStartDate);
  287. }
  288. if(this.projectDetail.planEndDate) {
  289. formData.append("planEndDate", this.projectDetail.planEndDate);
  290. }
  291. this.$axios.post("/project/editProject", formData)
  292. .then(res => {
  293. if(res.code == "ok") {
  294. this.$toast.success('修改成功')
  295. this.back()
  296. } else {
  297. this.$toast.fail('获取失败');
  298. }
  299. }).catch(err=> {this.$toast.clear();console.log(err)});
  300. // }).catch(()=>{return})
  301. },
  302. deleteProject(){
  303. this.$dialog.confirm({
  304. title: '删除项目',
  305. message: '确定要删除项目'+this.projectDetail.projectName+'吗?'
  306. }).then(() => {
  307. const toast = this.$toast.loading({
  308. forbidClick: true,
  309. duration: 0
  310. });
  311. this.$axios.post("/project/deleteProject", {id: this.projectDetail.id})
  312. .then(res => {
  313. if(res.code == "ok") {
  314. this.$toast.clear();
  315. this.$toast.success('删除成功');
  316. this.$router.push('/project');
  317. } else if(res.code == 'reconfirm'){
  318. this.$toast.clear();
  319. this.forceDelete(res.msg)
  320. } else {
  321. this.$toast.clear();
  322. this.$toast.fail(res.msg);
  323. }
  324. }).catch(err=> {this.$toast.clear();});
  325. }).catch(() => {});
  326. },
  327. forceDelete(msg){
  328. this.$dialog.confirm({
  329. title: '删除项目',
  330. message: msg
  331. }).then(() => {
  332. const toast = this.$toast.loading({
  333. forbidClick: true,
  334. duration: 0
  335. });
  336. this.$axios.post("/project/deleteProject", {id: this.projectDetail.id, force: 1})
  337. .then(res => {
  338. if(res.code == "ok") {
  339. this.$toast.clear();
  340. this.$toast.success('删除成功');
  341. this.back();
  342. } else {
  343. this.$toast.clear();
  344. this.$toast.fail(res.msg);
  345. }
  346. }).catch(err=> {this.$toast.clear();});
  347. }).catch(() => {});
  348. },
  349. getProjectDetail(){
  350. this.$axios.post("/project/detail", {id: this.projectId})
  351. .then(res => {
  352. if(res.code == "ok") {
  353. this.projectDetail = res.data
  354. let userNames = ''
  355. let userId = []
  356. for(let i in res.data.participationList){
  357. if(res.data.participationList[i].id && res.data.participationList[i].id != 'null'){
  358. userNames += res.data.participationList[i].name + ','
  359. userId.push(res.data.participationList[i].id)
  360. this.inchargerList.push(res.data.participationList[i])
  361. }
  362. }
  363. this.$set(this.projectDetail,'userNames',userNames ? userNames.substring(0,userNames.length - 1) : '')
  364. this.$set(this.projectDetail,'userId',userId)
  365. if(res.data.planStartDate){
  366. this.currentStartDate = new Date(res.data.planStartDate)
  367. }
  368. if(res.data.planEndDate){
  369. this.currentEndDate = new Date(res.data.planEndDate)
  370. }
  371. this.getUserList()
  372. if(this.user.timeType.projectLevelState == 1){
  373. this.getLevelList()
  374. }else{
  375. this.levelList = [
  376. {label: '正常' ,id: 1},
  377. {label: '紧急' ,id: 2},
  378. {label: '重要' ,id: 3},
  379. {label: '重要且紧急' ,id: 4},
  380. ]
  381. this.projectDetail.levelLabel = this.levelList[this.projectDetail.level - 1].label
  382. }
  383. if(this.user.id == res.data.creatorId){
  384. this.editCodeAndName = true
  385. return
  386. }
  387. for(let i in this.user.functionList){
  388. if(this.user.functionList[i].name == '编辑负责项目编码和名称' || this.user.functionList[i].name == '管理全部项目'){
  389. this.editCodeAndName = true
  390. }
  391. }
  392. } else {
  393. this.$toast.fail('获取失败');
  394. }
  395. }).catch(err=> {this.$toast.clear();console.log(err)});
  396. },
  397. getMainProjectList(){
  398. this.$axios.post("/project-main/list", {})
  399. .then(res => {
  400. if(res.code == "ok") {
  401. this.mainProjectList = res.data
  402. } else {
  403. this.$toast.fail('获取失败');
  404. }
  405. }).catch(err=> {this.$toast.clear();console.log(err)});
  406. },
  407. getCategoryList(){
  408. this.$axios.get("/project-category/list", {})
  409. .then(res => {
  410. if(res.code == "ok") {
  411. this.categoryList = res.data
  412. } else {
  413. this.$toast.fail('获取失败');
  414. }
  415. }).catch(err=> {this.$toast.clear();console.log(err)});
  416. },
  417. getLevelList(){
  418. this.$axios.get("/project-level/list", {})
  419. .then(res => {
  420. if(res.code == "ok") {
  421. this.levelList = res.data
  422. let list = this.levelList.filter(u => u.id == this.projectDetail.level)
  423. this.projectDetail.levelLabel = list.length != 0 ? list[0].label : ''
  424. } else {
  425. this.$toast.fail('获取失败');
  426. }
  427. }).catch(err=> {this.$toast.clear();console.log(err)});
  428. },
  429. getUserList(){
  430. this.$axios.post("/user/getEmployeeList", {departmentId: -1,pageIndex: 1,pageSize: -1})
  431. .then(res => {
  432. if(res.code == "ok") {
  433. let list = res.data.records
  434. for (let i in list) {
  435. let length = this.projectDetail.participationList.filter(u => u.id == list[i].id).length
  436. if(length){
  437. list[i].isChecked = true
  438. }else{
  439. list[i].isChecked = false
  440. }
  441. }
  442. this.allUserList = list;
  443. this.userList = list;
  444. } else {
  445. this.$toast.fail('获取失败');
  446. }
  447. }).catch(err=> {this.$toast.clear();console.log(err)});
  448. }
  449. },
  450. }
  451. </script>
  452. <style lang="less" scoped>
  453. .content{
  454. margin-top: 46px;
  455. overflow: auto;
  456. .userCheckbox {
  457. padding: 10px;
  458. }
  459. }
  460. </style>