editask.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. <template>
  2. <div>
  3. <van-nav-bar :title="title" left-text="返回" @click-left="back" fixed left-arrow />
  4. <div class="content">
  5. <van-form>
  6. <!-- 类型 -->
  7. <van-field v-model="taskform.taskType" label="类型" @click="taskType.show = true" readonly clickable>
  8. <template #input><span>{{taskType.list[taskform.taskType]}}</span></template>
  9. </van-field>
  10. <van-popup v-model="taskType.show" position="bottom" v-if="canEdit">
  11. <van-picker
  12. show-toolbar
  13. :columns="taskType.list"
  14. @confirm="tasktypeChange"
  15. @cancel="taskType.show = false;$forceUpdate();"/>
  16. </van-popup>
  17. <!-- 任务内容 -->
  18. <van-field v-model="taskform.name" label="任务内容" placeholder="请输入任务内容" :rules="[{ required: true, message: '请输入任务内容' }]" type="textarea" :disabled="!canEdit"></van-field>
  19. <!-- 开始时间 -->
  20. <van-field v-if="taskform.type != 1" v-model="taskform.startDate" label="开始时间" placeholder="请选择开始时间" @click="startDateShow = true" readonly clickable></van-field>
  21. <van-popup v-model="startDateShow" position="bottom" v-if="canEdit">
  22. <van-datetime-picker
  23. type="date"
  24. title="选择开始时间"
  25. v-model="currentDate1"
  26. @confirm="startDateChange"
  27. @cancel="startDateShow = false;$forceUpdate();"
  28. :min-date="minDate"
  29. :max-date="maxDate"/>
  30. </van-popup>
  31. <!-- 截止时间 -->
  32. <van-field v-model="taskform.endDate" label="截止时间" placeholder="请选择截止时间" @click="endDateShow = true" readonly clickable></van-field>
  33. <van-popup v-model="endDateShow" position="bottom" v-if="canEdit">
  34. <van-datetime-picker
  35. type="date"
  36. title="选择截止时间"
  37. v-model="currentDate2"
  38. @confirm="endDateChange"
  39. @cancel="endDateShow = false;$forceUpdate();"
  40. :min-date="minDate"
  41. :max-date="maxDate"/>
  42. </van-popup>
  43. <!-- 完成时间 -->
  44. <van-field v-if="taskform.type == 1" v-model="taskform.finishDate" label="完成时间" placeholder="请选择完成时间" @click="finishDateShow = true" readonly clickable></van-field>
  45. <van-popup v-model="finishDateShow" position="bottom" v-if="canEdit">
  46. <van-datetime-picker
  47. type="date"
  48. title="选择完成时间"
  49. v-model="currentDate3"
  50. @confirm="finishDateChange"
  51. @cancel="finishDateShow = false;$forceUpdate();"
  52. :min-date="minDate"
  53. :max-date="maxDate"/>
  54. </van-popup>
  55. <!-- 执行人 -->
  56. <div style="border: 0.5px solid #87c3ff;margin:0.2rem;position:relative" v-for="item,index in taskform.executorList" :key="index">
  57. <van-field v-model="item.executorName" :label="'执行人' + (index + 1)" placeholder="请选择执行人" @click="executorChange(item,index)" readonly clickable>
  58. <template #input>
  59. <span v-if="!item.executorName"></span>
  60. <span v-else-if="user.userNameNeedTranslate != 1">{{item.executorName}}</span>
  61. <span v-else><ww-open-data type='userName' :openid='item.executorName'></ww-open-data></span>
  62. </template>
  63. </van-field>
  64. <van-field label="计划工时">
  65. <template #input>
  66. <van-stepper v-model="item.planHours" :disabled="!canEdit"/><span>{{'\u3000h'}}</span>
  67. </template>
  68. </van-field>
  69. <van-icon v-if="index != 0 && canEdit" class="delete_executor" name="delete-o" @click.stop="deleteExecutor(index)" />
  70. </div>
  71. <van-popup v-model="executor.show" position="bottom" v-if="canEdit">
  72. <van-search v-model="executor.searchText" placeholder="输入员工姓名搜索" @search="onSearch" v-if="user.userNameNeedTranslate != '1'"></van-search>
  73. <div style="minHeight:300px;">
  74. <van-radio-group v-model="executor.item">
  75. <van-radio v-for="uitem in executor.searchList" :key="uitem.id" :name="uitem" style="padding:10px">
  76. <span v-if="user.userNameNeedTranslate != 1">{{uitem.name}}</span>
  77. <span v-else><ww-open-data type='userName' :openid='uitem.name'></ww-open-data></span>
  78. </van-radio>
  79. </van-radio-group>
  80. <van-button style="width:100%;position: -webkit-sticky;position: sticky;bottom: 0;" @click="searchExecutor()">确定</van-button>
  81. </div>
  82. </van-popup>
  83. <!-- 添加执行人 -->
  84. <div class="add_executor" @click="addExecutor" v-if="canEdit">添加执行人</div>
  85. <!-- 优先级 -->
  86. <van-field v-model="taskform.taskLevel" label="优先级" @click="taskLevel.show = true" readonly clickable>
  87. <template #input><span>{{taskLevel.list[taskform.taskLevel]}}</span></template>
  88. </van-field>
  89. <van-popup v-model="taskLevel.show" position="bottom" v-if="canEdit">
  90. <van-picker
  91. show-toolbar
  92. :columns="taskLevel.list"
  93. @confirm="taskLevelChange"
  94. @cancel="taskLevel.show = false;$forceUpdate();"/>
  95. </van-popup>
  96. </van-form>
  97. <div class="form_btn" style="position:fixed; bottom:0px;width:100%;">
  98. <div style="padding-bottom:10px;">
  99. <van-button square block type="info" @click="submitTask" native-type="submit" style="width:100%;float:left;" :disabled="!canEdit">
  100. <div v-if="canEdit">保存</div>
  101. <div v-else>暂无权限编辑</div>
  102. </van-button>
  103. </div>
  104. </div>
  105. </div>
  106. </div>
  107. </template>
  108. <script>
  109. export default {
  110. data() {
  111. return {
  112. title: '编辑任务',
  113. user: JSON.parse(localStorage.userInfo),
  114. taskId: JSON.parse(sessionStorage.taskId),
  115. currentDate1: new Date(),
  116. currentDate2: new Date(),
  117. currentDate3: new Date(),
  118. minDate: new Date(2020,0,1),
  119. maxDate: new Date(2025,11,31),
  120. canEdit: true,
  121. taskform:{ // 表单
  122. taskType: 0,
  123. name: '',
  124. startDate: null,
  125. endDate: null,
  126. finishDate: null,
  127. taskLevel: 0,
  128. executorList: [{executorName: '',executorId: '',planHours: 8}],
  129. },
  130. taskType:{
  131. show: false,
  132. list: ['任务','里程碑','风险']
  133. },
  134. startDateShow: false,
  135. endDateShow: false,
  136. finishDateShow: false,
  137. taskLevel:{
  138. show: false,
  139. list: ['一般','重要','紧急']
  140. },
  141. executor:{
  142. show: false,
  143. item: {id:null,name:''},
  144. index: 0,
  145. list: [],
  146. searchList: [],
  147. searchText: ''
  148. }
  149. }
  150. },
  151. mounted() {
  152. if(!this.taskId.addNew){
  153. this.title = '编辑任务'
  154. this.getTask()
  155. }else{
  156. this.title = '新建任务'
  157. this.taskform = {
  158. projectId: JSON.parse(sessionStorage.projectId),
  159. groupId: this.taskId.groupId,
  160. stagesId: this.taskId.stagesId,
  161. taskType: 0,
  162. name: '',
  163. startDate: null,
  164. endDate: null,
  165. finishDate: null,
  166. taskLevel: 0,
  167. executorList: [{executorName: '',executorId: '',planHours: this.user.timeType.allday}]
  168. }
  169. }
  170. this.getUsersList()
  171. console.log('mounted',this.taskId,null);
  172. },
  173. methods: {
  174. back() {
  175. history.back();
  176. },
  177. formatDate(date) {
  178. let mon = date.getMonth() + 1
  179. return `${date.getFullYear()}-${mon<10?'0'+mon:mon}-${date.getDate()<10?'0'+date.getDate():date.getDate()}`;
  180. },
  181. tasktypeChange(value,key){ // 类型
  182. this.taskform.taskType = key
  183. this.taskType.show = false
  184. },
  185. startDateChange(date){ // 开始时间
  186. this.taskform.startDate = this.formatDate(date)
  187. this.startDateShow = false
  188. },
  189. endDateChange(date){ // 截止时间
  190. this.taskform.endDate = this.formatDate(date)
  191. this.endDateShow = false
  192. },
  193. finishDateChange(date){ // 完成时间
  194. this.taskform.finishDate = this.formatDate(date)
  195. this.finishDateShow = false
  196. },
  197. executorChange(item,index){ // 选择执行人
  198. this.executor.show = true
  199. this.executor.index = index
  200. this.executor.searchList.forEach(u=>{if (u.id == item.executorId) {
  201. this.executor.item = u
  202. }})
  203. },
  204. deleteExecutor(index){
  205. console.log('deleteExecutor');
  206. this.taskform.executorList.splice(index,1)
  207. this.$forceUpdate();
  208. },
  209. addExecutor(){
  210. console.log('addExecutor');
  211. this.taskform.executorList.push({
  212. executorName: '',
  213. executorId: '',
  214. planHours: this.user.timeType.allday
  215. })
  216. this.$forceUpdate();
  217. },
  218. onSearch(val) {
  219. console.log(val);
  220. this.executor.searchList = [];
  221. this.executor.list.forEach(u=>{if (u.name.startsWith(val)) {
  222. this.executor.searchList.push(u);
  223. }})
  224. },
  225. searchExecutor(){
  226. this.taskform.executorList[this.executor.index].executorId = this.executor.item.id
  227. this.taskform.executorList[this.executor.index].executorName = this.executor.item.name
  228. this.executor.show = false
  229. console.log('searchExecutor',this.executor.item,this.executor.item.name);
  230. },
  231. taskLevelChange(value,key){ // 优先级
  232. this.taskform.taskLevel = key
  233. this.taskLevel.show = false
  234. },
  235. submitTask(){
  236. console.log('submitTask');
  237. if(!this.taskform.name.replace(/^\s*|\s*$/g,"")){
  238. return
  239. }
  240. // 执行人查重
  241. let arr = this.taskform.executorList
  242. let json={};
  243. for(let i in arr){
  244. if(!json[arr[i].executorId]){
  245. json[arr[i].executorId]=1;
  246. }else{
  247. this.$toast.fail("执行人存在重复");
  248. return
  249. }
  250. }
  251. // 去除未选择执行人的执行人列表
  252. this.taskform.executorList = this.taskform.executorList.filter(item => item.executorId)
  253. this.taskform.executorListStr = JSON.stringify(this.taskform.executorList)
  254. delete this.taskform.executorList
  255. delete this.taskform.subTaskList;
  256. delete this.taskform.refTaskList;
  257. delete this.taskform.progress;
  258. this.$axios.post("/task/save", this.taskform)
  259. .then(res => {
  260. if(res.code == "ok") {
  261. this.$toast.success('保存成功');
  262. this.back()
  263. } else {
  264. this.$toast.fail('保存失败');
  265. }
  266. }).catch(err=> {this.$toast.clear();console.log(err)});
  267. },
  268. getTask(){
  269. this.$axios.post("/task/getTask", {
  270. id: this.taskId.id
  271. }).then(res => {
  272. if(res.code == "ok") {
  273. this.taskform = res.data
  274. this.taskform.createDate = null;
  275. this.taskform.indate = null;
  276. let projectManagement = false
  277. if(this.taskform.startDate){
  278. this.currentDate1 = new Date(this.taskform.startDate)
  279. }
  280. if(this.taskform.endDate){
  281. this.currentDate2 = new Date(this.taskform.endDate)
  282. }
  283. if(this.taskform.finishDate){
  284. this.currentDate3 = new Date(this.taskform.finishDate)
  285. }
  286. // 判断编辑权限
  287. for(let i in this.user.functionList){
  288. if(this.user.functionList[i].name == '查看全部项目'){
  289. projectManagement = true
  290. }
  291. }
  292. if(this.user.id == res.data.createrId || this.user.id == res.data.projectInchargerId || this.user.id == res.data.groupInchargerId || projectManagement || this.title == '新建任务'){
  293. this.canEdit = true
  294. }else{
  295. this.canEdit = false
  296. }
  297. // (
  298. // (
  299. // (addForm.executorListFront == null || addForm.executorListFront.length<10)
  300. // && (
  301. // addForm.id == null|| user.id == addForm.createrId || currentProject.inchargerId == user.id || permissions.projectManagement
  302. // )
  303. // )
  304. // || groupResponsibleId == user.id
  305. // )
  306. // this.canEdit = false
  307. } else {
  308. this.$toast.fail('获取失败');
  309. }
  310. }).catch(err=> {this.$toast.clear();console.log(err)});
  311. },
  312. getUsersList(){
  313. this.$axios.post("/user/getSimpleActiveUserList", {})
  314. .then(res => {
  315. if(res.code == "ok") {
  316. this.executor.list = res.data
  317. this.executor.searchList = res.data
  318. } else {
  319. this.$toast.fail('获取失败');
  320. }
  321. }).catch(err=> {this.$toast.clear();console.log(err)});
  322. }
  323. },
  324. }
  325. </script>
  326. <style lang="less" scoped>
  327. .content{
  328. margin-top: 46px;
  329. overflow: auto;
  330. .add_executor{
  331. font-size:13px;
  332. color:#1989fa;
  333. padding-left:0.42667rem;
  334. padding-bottom:.2rem;
  335. width:100px
  336. }
  337. .delete_executor{
  338. position: absolute;
  339. top: 3px;
  340. right: 3px;
  341. font-size: 22px;
  342. color: #c03131;
  343. }
  344. }
  345. </style>