edit.vue 19 KB

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