editask.vue 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. <template>
  2. <div class="editaskBox">
  3. <van-nav-bar :title="title" left-text="返回" @click-left="back" fixed left-arrow />
  4. <div class="content">
  5. <van-form>
  6. <div v-if="showOrNot">
  7. <van-cell title="所属项目" :value="select_project" @click="select_project_show = true,select_project_show_searchText = '',onSearchProject()"></van-cell>
  8. <van-popup v-model="select_project_show" position="bottom">
  9. <van-search v-model.trim="select_project_show_searchText" placeholder="输入项目名称搜索" @input="onSearchProject"></van-search>
  10. <div style="minHeight:300px;">
  11. <van-radio-group v-model="taskform.projectId">
  12. <div class="ewProjectlist">近期选择项目</div>
  13. <van-radio v-for="(uitem, index) in integrationProjectList" :key="index" :name="uitem" style="padding:10px">
  14. <span>{{uitem.projectName}}</span>
  15. </van-radio>
  16. </van-radio-group>
  17. <van-radio-group v-model="taskform.projectId">
  18. <div class="ewProjectlist">全部项目</div>
  19. <van-radio v-for="uitem in select_project_array" :key="uitem.id" :name="uitem" style="padding:10px">
  20. <span>{{uitem.projectName}}</span>
  21. </van-radio>
  22. </van-radio-group>
  23. <van-button style="width:100%;position: -webkit-sticky;position: sticky;bottom: 0;" @click="selectProject()">确定</van-button>
  24. </div>
  25. </van-popup>
  26. <van-cell title="所属任务分组" :value="select_grouping" @click="select_grouping_show = true"></van-cell>
  27. <van-popup v-model="select_grouping_show" position="bottom">
  28. <van-picker
  29. show-toolbar
  30. :columns="select_grouping_array"
  31. @confirm="selectGrouping"
  32. @cancel="select_grouping_show = false;$forceUpdate();">
  33. <template #option="item">
  34. {{item.name}}
  35. </template>
  36. </van-picker>
  37. </van-popup>
  38. <van-cell title="所属任务列表" :value="select_list" @click="select_list_show = true"></van-cell>
  39. <van-popup v-model="select_list_show" position="bottom">
  40. <van-picker
  41. show-toolbar
  42. :columns="select_list_array"
  43. @confirm="selectList"
  44. @cancel="select_list_show = false;$forceUpdate();">
  45. <template #option="item">
  46. {{item.stagesName}}
  47. </template>
  48. </van-picker>
  49. </van-popup>
  50. </div>
  51. <!-- 类型 -->
  52. <van-field v-model="taskform.taskType" label="类型" @click="taskType.show = true" readonly clickable>
  53. <template #input><span>{{taskType.list[taskform.taskType]}}</span></template>
  54. </van-field>
  55. <van-popup v-model="taskType.show" position="bottom" v-if="canEdit">
  56. <van-picker
  57. show-toolbar
  58. :columns="taskType.list"
  59. @confirm="tasktypeChange"
  60. @cancel="taskType.show = false;$forceUpdate();"/>
  61. </van-popup>
  62. <!-- 任务内容 -->
  63. <van-field v-model="taskform.name" label="任务内容" placeholder="请输入任务内容" :rules="[{ required: true, message: '请输入任务内容' }]" type="textarea" :disabled="!canEdit" :maxlength="40" show-word-limit></van-field>
  64. <!-- 开始时间 -->
  65. <van-field v-if="taskform.type != 1" v-model="taskform.startDate" label="开始时间" placeholder="请选择开始时间" @click="startDateShow = true" readonly clickable></van-field>
  66. <van-popup v-model="startDateShow" position="bottom" v-if="canEdit">
  67. <van-datetime-picker
  68. type="date"
  69. title="选择开始时间"
  70. v-model="currentDate1"
  71. @confirm="startDateChange"
  72. @cancel="startDateShow = false;$forceUpdate();"
  73. :min-date="minDate"
  74. :max-date="maxDate"/>
  75. </van-popup>
  76. <!-- 截止时间 -->
  77. <van-field v-model="taskform.endDate" label="截止时间" placeholder="请选择截止时间" @click="endDateShow = true" readonly clickable></van-field>
  78. <van-popup v-model="endDateShow" position="bottom" v-if="canEdit">
  79. <van-datetime-picker
  80. type="date"
  81. title="选择截止时间"
  82. v-model="currentDate2"
  83. @confirm="endDateChange"
  84. @cancel="endDateShow = false;$forceUpdate();"
  85. :min-date="minDate"
  86. :max-date="maxDate"/>
  87. </van-popup>
  88. <!-- 完成时间 -->
  89. <van-field v-if="taskform.type == 1" v-model="taskform.finishDate" label="完成时间" placeholder="请选择完成时间" @click="finishDateShow = true" readonly clickable></van-field>
  90. <van-popup v-model="finishDateShow" position="bottom" v-if="canEdit">
  91. <van-datetime-picker
  92. type="date"
  93. title="选择完成时间"
  94. v-model="currentDate3"
  95. @confirm="finishDateChange"
  96. @cancel="finishDateShow = false;$forceUpdate();"
  97. :min-date="minDate"
  98. :max-date="maxDate"/>
  99. </van-popup>
  100. <!-- 执行人 -->
  101. <div style="border: 0.5px solid #87c3ff;margin:0.2rem;position:relative" v-for="item,index in taskform.executorList" :key="index">
  102. <van-field v-model="item.executorName" :label="'执行人' + (index + 1)" placeholder="请选择执行人" @click="executorChange(item,index)" readonly clickable>
  103. <template #input>
  104. <span v-if="!item.executorName"></span>
  105. <span v-else-if="user.userNameNeedTranslate != 1">{{item.executorName}}</span>
  106. <span v-else><ww-open-data type='userName' :openid='item.executorName'></ww-open-data></span>
  107. </template>
  108. </van-field>
  109. <van-field label="计划工时">
  110. <template #input>
  111. <van-stepper v-model="item.planHours" :disabled="!canEdit"/><span>{{'\u3000h'}}</span>
  112. </template>
  113. </van-field>
  114. <van-icon v-if="index != 0 && canEdit" class="delete_executor" name="delete-o" @click.stop="deleteExecutor(index)" />
  115. </div>
  116. <van-popup v-model="executor.show" position="bottom" v-if="canEdit" style="height: 90%">
  117. <!-- <van-search v-model="executor.searchText" placeholder="输入员工姓名搜索" @input="onSearch"></van-search>
  118. <div style="minHeight:300px;">
  119. <van-radio-group v-model="executor.item">
  120. <van-radio v-for="uitem in executor.searchList" :key="uitem.id" :name="uitem" style="padding:10px">
  121. <span v-if="user.userNameNeedTranslate != 1">{{uitem.name}}</span>
  122. <span v-else><ww-open-data type='userName' :openid='uitem.name'></ww-open-data></span>
  123. <span class="xinmingghao">{{uitem.jobNumber}}</span>
  124. </van-radio>
  125. </van-radio-group>
  126. <van-button style="width:100%;position: -webkit-sticky;position: sticky;bottom: 0;" @click="searchExecutor()">确定</van-button>
  127. </div> -->
  128. <div class="popupDiv">
  129. <div class="popupSearch" v-if="user.userNameNeedTranslate != '1'">
  130. <van-search v-model="executor.searchText" placeholder="输入员工姓名搜索" @search="onSearch" shape="round" background="#F4F4F4"></van-search>
  131. </div>
  132. <div class="popupCon conBorder">
  133. <van-radio-group v-model="executor.item" class="popupItem marginNone borderNone">
  134. <van-radio v-for="uitem in executor.searchList" :key="uitem.id" :name="uitem" style="padding:10px">
  135. <span v-if="user.userNameNeedTranslate != 1" class="userNameClass_left">{{uitem.name}}</span>
  136. <span v-else class="userNameClass_left"><ww-open-data type='userName' :openid='uitem.name'></ww-open-data></span>
  137. <span class="userNameClass_right">{{ uitem.jobNumber }}</span>
  138. </van-radio>
  139. </van-radio-group>
  140. </div>
  141. <div class="popupBtn">
  142. <van-button style="width:100%;background: #1989fa;color: #ffffff;position: -webkit-sticky;position: sticky;bottom: 0;" round @click="searchExecutor()">确定</van-button>
  143. </div>
  144. </div>
  145. </van-popup>
  146. <!-- 添加执行人 -->
  147. <div class="add_executor" @click="addExecutor" v-if="canEdit">添加执行人</div>
  148. <!-- 优先级 -->
  149. <van-field v-model="taskform.taskLevel" label="优先级" @click="taskLevel.show = true" readonly clickable>
  150. <template #input><span>{{taskLevel.list[taskform.taskLevel]}}</span></template>
  151. </van-field>
  152. <van-popup v-model="taskLevel.show" position="bottom" v-if="canEdit">
  153. <van-picker
  154. show-toolbar
  155. :columns="taskLevel.list"
  156. @confirm="taskLevelChange"
  157. @cancel="taskLevel.show = false;$forceUpdate();"/>
  158. </van-popup>
  159. <van-cell title="任务描述"/>
  160. <vue-html5-editor :content="taskform.taskDesc" :height="300" @change="htmleditor"></vue-html5-editor>
  161. </van-form>
  162. <div class="form_btn" style="position:fixed; bottom:0px;width:100%;z-index: 99">
  163. <div style="padding-bottom:10px;">
  164. <van-button square block type="info" loading-text="保存中..." @click="submitTask" native-type="submit" :loading="submitTaskBtn" style="width:100%;float:left;" :disabled="!canEdit">
  165. <div v-if="canEdit">保存</div>
  166. <div v-else>暂无权限编辑</div>
  167. </van-button>
  168. </div>
  169. </div>
  170. </div>
  171. </div>
  172. </template>
  173. <script>
  174. export default {
  175. data() {
  176. return {
  177. showOrNot: false,
  178. title: '编辑任务',
  179. user: JSON.parse(localStorage.userInfo),
  180. taskId: JSON.parse(sessionStorage.taskId),
  181. currentDate1: new Date(),
  182. currentDate2: new Date(),
  183. currentDate3: new Date(),
  184. minDate: new Date(2020,0,1),
  185. maxDate: new Date(2025,11,31),
  186. canEdit: true,
  187. onSearchTime: null,
  188. taskform:{ // 表单
  189. taskType: 0,
  190. name: '',
  191. startDate: null,
  192. endDate: null,
  193. finishDate: null,
  194. taskLevel: 0,
  195. executorList: [{executorName: '',executorId: '',planHours: 8}],
  196. },
  197. taskType:{
  198. show: false,
  199. list: ['任务','里程碑','风险']
  200. },
  201. startDateShow: false,
  202. endDateShow: false,
  203. finishDateShow: false,
  204. submitTaskBtn: false,
  205. taskLevel:{
  206. show: false,
  207. list: ['一般','重要','紧急']
  208. },
  209. executor:{
  210. show: false,
  211. item: {id:null,name:''},
  212. index: 0,
  213. list: [],
  214. searchList: [],
  215. searchText: ''
  216. },
  217. select_project_show: false,
  218. select_grouping_show: false,
  219. select_list_show: false,
  220. select_project: '请选择',
  221. select_grouping: '请选择',
  222. select_list: '请选择',
  223. select_project_array: [],
  224. select_project_array_tow: [],
  225. select_grouping_array: [],
  226. select_list_array: [],
  227. select_project_show_searchText: '',
  228. integrationProjectList: []
  229. }
  230. },
  231. mounted() {
  232. this.showOrNot = this.taskId.showOrNot
  233. this.getProjectList()
  234. if(!this.taskId.addNew){
  235. this.title = '编辑任务'
  236. this.getTask()
  237. }else{
  238. this.title = '新建任务'
  239. this.taskform = {
  240. projectId: '',
  241. groupId: '',
  242. stagesId: '',
  243. taskType: 0,
  244. name: '',
  245. startDate: null,
  246. endDate: null,
  247. finishDate: null,
  248. taskDesc: '',
  249. taskLevel: 0,
  250. executorList: [{executorName: '',executorId: '',planHours: this.user.timeType.allday}]
  251. }
  252. if(!this.taskId.showOrNot) {
  253. this.taskform.groupId = this.taskId.groupId
  254. this.taskform.stagesId = this.taskId.stagesId
  255. this.taskform.projectId = JSON.parse(sessionStorage.projectId)
  256. }
  257. }
  258. this.getUsersList()
  259. console.log('mounted',this.taskId,null);
  260. },
  261. methods: {
  262. selectProject(value,key) {
  263. this.select_project = this.taskform.projectId.projectName
  264. this.taskform.projectId = this.taskform.projectId.id
  265. console.log(this.taskform)
  266. this.getTaskGrouping()
  267. this.select_project_show_searchText = ''
  268. this.select_project_show = false
  269. this.select_list = ''
  270. this.select_grouping = ''
  271. this.taskform.groupId = ''
  272. this.taskform.stagesId = ''
  273. },
  274. selectGrouping(value){
  275. this.select_grouping = value.name
  276. this.taskform.groupId = value.id
  277. this.getStageList()
  278. this.select_grouping_show = false
  279. this.select_list = ''
  280. this.taskform.stagesId = ''
  281. },
  282. selectList(value) {
  283. console.log(value)
  284. this.select_list = value.stagesName
  285. this.taskform.stagesId = value.id
  286. this.select_list_show = false
  287. },
  288. onSearchProject() {
  289. let text = this.select_project_show_searchText
  290. if(text != '') {
  291. let projectArr = this.select_project_array_tow
  292. var arr = []
  293. for(var i in projectArr) {
  294. if(projectArr[i].projectName.indexOf(text) != '-1') {
  295. arr.push(projectArr[i])
  296. }
  297. }
  298. this.select_project_array = arr
  299. } else {
  300. this.select_project_array = this.select_project_array_tow
  301. }
  302. },
  303. getProjectList() {
  304. this.$axios.post("/project/getProjectList", {})
  305. .then(res => {
  306. if(res.code == "ok") {
  307. this.select_project_array = res.data
  308. this.select_project_array_tow = res.data
  309. this.getRecentlyProject()
  310. } else {
  311. this.$toast.fail('失败');
  312. }
  313. }).catch(err=> {this.$toast.clear();console.log(err)});
  314. },
  315. getRecentlyProject() {
  316. this.$axios.post('/project/nearProject',{})
  317. .then(res => {
  318. if(res.code == 'ok'){
  319. this.integrationProjectList = res.data
  320. }
  321. }).catch(err => {this.$toast.clear();this.cardRefLoading = false;})
  322. },
  323. getTaskGrouping() {
  324. this.$axios.post("/task-group/list", {projectId:this.taskform.projectId})
  325. .then(res => {
  326. if(res.code == "ok") {
  327. this.select_grouping_array = res.data
  328. } else {
  329. this.$toast.fail('失败');
  330. }
  331. }).catch(err=> {this.$toast.clear();console.log(err)});
  332. },
  333. getStageList() {
  334. this.$axios.post("/stages/list", {
  335. projectId: this.taskform.projectId,
  336. groupId: this.taskform.groupId,
  337. order: 'seq',
  338. isDesc: false
  339. })
  340. .then(res => {
  341. if(res.code == "ok") {
  342. this.select_list_array = res.data.list
  343. } else {
  344. this.$toast.fail('失败');
  345. }
  346. }).catch(err=> {this.$toast.clear();console.log(err)});
  347. },
  348. back() {
  349. history.back();
  350. },
  351. formatDate(date) {
  352. let mon = date.getMonth() + 1
  353. return `${date.getFullYear()}-${mon<10?'0'+mon:mon}-${date.getDate()<10?'0'+date.getDate():date.getDate()}`;
  354. },
  355. tasktypeChange(value,key){ // 类型
  356. this.taskform.taskType = key
  357. this.taskType.show = false
  358. },
  359. startDateChange(date){ // 开始时间
  360. this.taskform.startDate = this.formatDate(date)
  361. this.startDateShow = false
  362. },
  363. endDateChange(date){ // 截止时间
  364. this.taskform.endDate = this.formatDate(date)
  365. this.endDateShow = false
  366. },
  367. finishDateChange(date){ // 完成时间
  368. this.taskform.finishDate = this.formatDate(date)
  369. this.finishDateShow = false
  370. },
  371. executorChange(item,index){ // 选择执行人
  372. this.executor.show = true
  373. this.executor.index = index
  374. this.executor.searchList.forEach(u=>{if (u.id == item.executorId) {
  375. this.executor.item = u
  376. }})
  377. },
  378. deleteExecutor(index){
  379. console.log('deleteExecutor');
  380. this.taskform.executorList.splice(index,1)
  381. this.$forceUpdate();
  382. },
  383. addExecutor(){
  384. console.log('addExecutor');
  385. this.taskform.executorList.push({
  386. executorName: '',
  387. executorId: '',
  388. planHours: this.user.timeType.allday
  389. })
  390. this.$forceUpdate();
  391. },
  392. onSearch(val) {
  393. if(this.user.userNameNeedTranslate != 1) {
  394. this.executor.searchList = [];
  395. this.executor.list.forEach(u=>{if (u.name.startsWith(val)) {
  396. this.executor.searchList.push(u);
  397. }})
  398. } else {
  399. if (this.onSearchTime != null) {
  400. clearTimeout(this.onSearchTime)
  401. }
  402. var that = this
  403. this.onSearchTime = setTimeout(() => {
  404. that.getOnSearch(val)
  405. }, 500)
  406. }
  407. },
  408. getOnSearch(val) {
  409. this.$axios.post("/user/getEmployeeList", {
  410. departmentId: -1,
  411. pageIndex: 1,
  412. pageSize: 200,
  413. keyword: val,
  414. status: 1,
  415. roleId: '',
  416. cursor: '',
  417. onlyDirect: 0,
  418. })
  419. .then(res => {
  420. if(res.code == "ok") {
  421. this.executor.searchList = res.data.records
  422. } else {
  423. this.$toast.fail('搜索失败');
  424. }
  425. }).catch(err=> {this.$toast.clear();console.log(err)});
  426. },
  427. searchExecutor(){
  428. this.taskform.executorList[this.executor.index].executorId = this.executor.item.id
  429. this.taskform.executorList[this.executor.index].executorName = this.executor.item.name
  430. this.executor.show = false
  431. console.log('searchExecutor',this.executor.item,this.executor.item.name);
  432. },
  433. taskLevelChange(value,key){ // 优先级
  434. this.taskform.taskLevel = key
  435. this.taskLevel.show = false
  436. },
  437. submitTask(){
  438. console.log('submitTask');
  439. if(!this.taskform.name.replace(/^\s*|\s*$/g,"")){
  440. return
  441. }
  442. // 执行人查重
  443. let arr = this.taskform.executorList
  444. let json={};
  445. for(let i in arr){
  446. if(!json[arr[i].executorId]){
  447. json[arr[i].executorId]=1;
  448. }else{
  449. this.$toast.fail("执行人存在重复");
  450. return
  451. }
  452. }
  453. if(this.taskform.projectId == '' || this.taskform.projectId == null) {
  454. this.$toast.fail("请选择所属项目");
  455. return
  456. }
  457. if(this.taskform.groupId == '' || this.taskform.groupId == null) {
  458. this.$toast.fail("请选择所属任务分组");
  459. return
  460. }
  461. if(this.taskform.stagesId == '' || this.taskform.stagesId == null) {
  462. this.$toast.fail("请选择所属任务列表");
  463. return
  464. }
  465. // 去除未选择执行人的执行人列表
  466. this.taskform.executorList = this.taskform.executorList.filter(item => item.executorId)
  467. this.taskform.executorListStr = JSON.stringify(this.taskform.executorList)
  468. delete this.taskform.executorList
  469. delete this.taskform.subTaskList;
  470. delete this.taskform.refTaskList;
  471. delete this.taskform.progress;
  472. this.submitTaskBtn = true
  473. // return
  474. this.$axios.post("/task/save", this.taskform)
  475. .then(res => {
  476. this.submitTaskBtn = false
  477. if(res.code == "ok") {
  478. this.$toast.success('保存成功');
  479. this.back()
  480. } else {
  481. this.$toast.fail('保存失败');
  482. }
  483. }).catch(err=> {this.$toast.clear();console.log(err);this.submitTaskBtn = false});
  484. },
  485. htmleditor(e) {
  486. this.taskform.taskDesc = e
  487. console.log()
  488. },
  489. getTask(){
  490. this.$axios.post("/task/getTask", {
  491. id: this.taskId.id
  492. }).then(res => {
  493. if(res.code == "ok") {
  494. this.taskform = res.data
  495. this.taskform.createDate = null;
  496. this.taskform.indate = null;
  497. let projectManagement = false
  498. if(!this.taskform.taskDesc){
  499. this.taskform.taskDesc = ''
  500. }
  501. if(this.taskform.startDate){
  502. this.currentDate1 = new Date(this.taskform.startDate)
  503. }
  504. if(this.taskform.endDate){
  505. this.currentDate2 = new Date(this.taskform.endDate)
  506. }
  507. if(this.taskform.finishDate){
  508. this.currentDate3 = new Date(this.taskform.finishDate)
  509. }
  510. // 判断编辑权限
  511. for(let i in this.user.functionList){
  512. if(this.user.functionList[i].name == '查看全部项目'){
  513. projectManagement = true
  514. }
  515. }
  516. if(this.user.id == res.data.createrId || this.user.id == res.data.projectInchargerId || this.user.id == res.data.groupInchargerId || projectManagement || this.title == '新建任务'){
  517. this.canEdit = true
  518. }else{
  519. this.canEdit = false
  520. }
  521. // (
  522. // (
  523. // (addForm.executorListFront == null || addForm.executorListFront.length<10)
  524. // && (
  525. // addForm.id == null|| user.id == addForm.createrId || currentProject.inchargerId == user.id || permissions.projectManagement
  526. // )
  527. // )
  528. // || groupResponsibleId == user.id
  529. // )
  530. // this.canEdit = false
  531. } else {
  532. this.$toast.fail('获取失败');
  533. }
  534. }).catch(err=> {this.$toast.clear();console.log(err)});
  535. },
  536. getUsersList(){
  537. this.$axios.post("/user/getSimpleActiveUserList", {})
  538. .then(res => {
  539. if(res.code == "ok") {
  540. this.executor.list = res.data
  541. this.executor.searchList = res.data
  542. } else {
  543. this.$toast.fail('获取失败');
  544. }
  545. }).catch(err=> {this.$toast.clear();console.log(err)});
  546. }
  547. },
  548. }
  549. </script>
  550. <style lang="less" scoped>
  551. .content{
  552. margin-top: 46px;
  553. overflow: auto;
  554. .add_executor{
  555. font-size:13px;
  556. color:#1989fa;
  557. padding-left:0.42667rem;
  558. padding-bottom:.2rem;
  559. width:100px
  560. }
  561. .delete_executor{
  562. position: absolute;
  563. top: 3px;
  564. right: 3px;
  565. font-size: 22px;
  566. color: #c03131;
  567. }
  568. }
  569. .xinmingghao {
  570. overflow: hidden;
  571. text-overflow: ellipsis;
  572. width: 200px;
  573. display: inline-block;
  574. float: right;
  575. }
  576. .ewProjectlist {
  577. padding: 10px 10px 10px 20px;
  578. border-bottom: 1px solid #666;
  579. color: #a5a5a5;
  580. }
  581. </style>
  582. <style>
  583. .editaskBox .van-radio__label {
  584. width: 100%;
  585. display: inline-block;
  586. }
  587. </style>