editask.vue 15 KB

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