dayreport.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. <template>
  2. <view style="width: 100%;height: 100%;">
  3. <view id="header">
  4. <u-row customStyle="border-bottom:1rpx solid lightgrey">
  5. <u-col span="6">
  6. <uni-datetime-picker type="date" :value="selectDate" @change="getData" placeholder="请选择汇报日期"
  7. :border="false"></uni-datetime-picker>
  8. </u-col>
  9. <u-col span="6">
  10. <view style="display: flex;flex-direction: row-reverse;padding-right: 30rpx;">
  11. <u-icon name="plus" color="blue" size="26px" @click="add"></u-icon>
  12. </view>
  13. </u-col>
  14. </u-row>
  15. </view>
  16. <scroll-view :style="{height:s_height+'px'}">
  17. <uni-group v-for="group in reports" :title="group.taskName+' ---用时:'+group.sumHours">
  18. <u-row v-for="(item,index) in group.item" customStyle="border-bottom:1rpx solid lightgrey" gutter="4">
  19. <u-col span="9">
  20. <text @click="openDetail(item)">{{item.content}}</text>
  21. </u-col>
  22. <u-col span="1">
  23. <text>{{item.workHours}}</text>
  24. </u-col>
  25. <u-col span="1">
  26. <u-icon name="edit-pen" size="26px" color="blue" @click="edit(item)"></u-icon>
  27. </u-col>
  28. <u-col span="1">
  29. <u-icon name="trash" size="26px" color="red" @click="deleteReport(item)"></u-icon>
  30. </u-col>
  31. </u-row>
  32. </uni-group>
  33. </scroll-view>
  34. <u-popup :show="showDetail">
  35. <view style="width: 100%;height: 100%;">
  36. <uni-group title="汇报任务">
  37. <u-row customStyle="border-bottom:1rpx solid lightgrey" @click="showTasks">
  38. <u-col span="3">
  39. <text>任务名称:</text>
  40. </u-col>
  41. <u-col span="9">
  42. <text>{{currRow.task||'请选择任务'}}</text>
  43. </u-col>
  44. </u-row>
  45. </uni-group>
  46. <uni-group title="汇报对象">
  47. <scroll-view scroll-y="true" style="height: 100px;">
  48. <u-checkbox-group placement="column" v-model="selectObject" :disabled="!allowEdit">
  49. <u-grid :border="true">
  50. <u-grid-item v-for="(item,index) in reportObjects">
  51. <view class="checkbox">
  52. <u-checkbox :label="item.value" :name="item.id" size="20"></u-checkbox>
  53. </view>
  54. </u-grid-item>
  55. </u-grid>
  56. </u-checkbox-group>
  57. </scroll-view>
  58. </uni-group>
  59. <uni-group title="汇报内容">
  60. <u-textarea v-model="currRow.content" autoheight :disabled="!allowEdit"></u-textarea>
  61. </uni-group>
  62. <uni-group title="工作时间">
  63. <u-row>
  64. <u-col span="6">
  65. <picker mode="time" :value="beginTime" @change="selectBeginTime" :disabled="!allowEdit">
  66. <text>开始时间:{{beginTime}}</text>
  67. </picker>
  68. </u-col>
  69. <u-col span="6">
  70. <picker mode="time" :value="endTime" @change="selectEndTime" :disabled="!allowEdit">
  71. <text>终止时间:{{endTime}}</text>
  72. </picker>
  73. </u-col>
  74. </u-row>
  75. <u-row>
  76. <text>工作时数:</text>
  77. <u-input type="number" :disabled="!allowEdit" placeholder="请输入工作时数" v-model="currRow.workHours">
  78. </u-input>
  79. </u-row>
  80. </uni-group>
  81. <!-- <uni-group title="附加文件">
  82. <u-text text="上传文件" prefixIcon="attach" @click="fileOpen" margin="0rpx 0rpx 30rpx 0rpx">
  83. </u-text>
  84. <scroll-view style="height: 100px;">
  85. <u-row v-for="item in fileList" customStyle="margin-top:5px">
  86. <u-col span="11">
  87. <u-text :text="item.fileOriginName" color="blue" @click="downFile(item)"></u-text>
  88. </u-col>
  89. <u-col span="1">
  90. <u-icon name="trash" color="red" size="26px" @click="deleteFile(item)"></u-icon>
  91. </u-col>
  92. </u-row>
  93. </scroll-view>
  94. </uni-group> -->
  95. <u-row>
  96. <u-col span="6">
  97. <u-button @click="close" text="关闭" color="red"></u-button>
  98. </u-col>
  99. <u-col span="6">
  100. <u-button @click="btnOk" text="确定" type="primary" :disabled="!allowEdit"></u-button>
  101. </u-col>
  102. </u-row>
  103. </view>
  104. </u-popup>
  105. <u-popup :show="showTask">
  106. <scroll-view style="height: 90vh;">
  107. <uni-group v-for="item in tasks" :title="item.title">
  108. <view v-for="task in item.children" style="width: 100%;">
  109. <u-row customStyle="height:80rpx;border-bottom:1rpx solid lightgrey"
  110. @click="selectTask(task)">
  111. <text>{{task.title}}</text>
  112. </u-row>
  113. <u-row v-for="child in task.children" customStyle="height:80rpx;border-bottom:1rpx solid lightgrey" @click="selectTask(child)">
  114. <u-col span="1"></u-col>
  115. <u-col span="11">{{child.title}}</u-col>
  116. </u-row>
  117. </view>
  118. </uni-group>
  119. </scroll-view>
  120. </u-popup>
  121. </view>
  122. </template>
  123. <script>
  124. import taskReport from '../../api/taskReport.js'
  125. import auth from "../../utils/js/auth.js"
  126. export default {
  127. data() {
  128. return {
  129. selectDate: "", //选定的汇报日期
  130. s_height: 0, //汇报列表高度,scrollview使用
  131. reports: [], //任务汇报列表,按照任务分组
  132. showDetail: false, //是否显示明细
  133. allowEdit: false, //是否允许编辑,查看明细时不允许编辑
  134. isAdd: false, //是否是新增汇报
  135. currRow: {}, //当前处理的汇报行
  136. beginTime: "", //汇报起始时间
  137. endTime: "", //汇报终止时间
  138. reportObjects: [], //汇报服务对象
  139. selectObject: [], //选定的汇报服务对象
  140. showTask: false, //是否打开选择任务界面
  141. tasks: [], //任务
  142. isReload: false //是否重新加载
  143. }
  144. },
  145. onReady() {
  146. let that = this
  147. uni.getSystemInfo({
  148. success(res) {
  149. const w_height = res.windowHeight;
  150. var query = uni.createSelectorQuery();
  151. query.select('#header').boundingClientRect();
  152. query.exec(function(res) {
  153. that.s_height = w_height - res[0].height;
  154. })
  155. }
  156. })
  157. },
  158. onLoad() {
  159. var currDate = new Date();
  160. this.selectDate = currDate.getFullYear() + "-" + (currDate.getMonth() + 1) + "-" + currDate.getDate()
  161. this.getData(this.selectDate)
  162. this.getReportObject()
  163. },
  164. methods: {
  165. getData(e) {
  166. if(this.selectDate!=e){
  167. this.selectDate=e
  168. }
  169. taskReport.getDayReports(e, auth.getId()).then(res => {
  170. if (res.data.success) {
  171. this.reports = res.data.data
  172. this.getReportTasks(e)
  173. }
  174. })
  175. },
  176. getReportTasks(date) {
  177. taskReport.getReportTasks(date).then(res => {
  178. if (res.data.success) {
  179. this.tasks = res.data.data
  180. }
  181. })
  182. },
  183. getReportObject() {
  184. taskReport.getReportObject().then((res) => {
  185. if (res.data.success) {
  186. this.reportObjects = res.data.data
  187. }
  188. })
  189. },
  190. add() {
  191. this.showDetail = true
  192. this.allowEdit = true
  193. this.isAdd = true
  194. this.currRow = {}
  195. },
  196. edit(e) {
  197. this.currRow = e
  198. this.beginTime = e.beginTime
  199. this.endTime = e.endTime
  200. this.showDetail = true
  201. this.allowEdit = true
  202. this.isAdd = false
  203. if (e.reportObjects) {
  204. e.reportObjects.forEach((item) => {
  205. this.selectObject.push(item.id)
  206. })
  207. }
  208. },
  209. deleteReport(e) {
  210. let _this = this
  211. uni.showModal({
  212. title: "是否确认删除?",
  213. success(option) {
  214. if (option.confirm) {
  215. taskReport.personDayReportDelete([{
  216. "id": e.id
  217. }]).then(res => {
  218. if (res.data.success) {
  219. uni.showToast({
  220. title: "删除成功",
  221. icon: "none"
  222. })
  223. _this.reports.forEach(group=>{
  224. _this.removeItem(group.item, e)
  225. if(group.item.length==0){
  226. _this.removeItem(_this.reports,group)
  227. }
  228. })
  229. }
  230. })
  231. }
  232. }
  233. })
  234. },
  235. openDetail(e) {
  236. this.currRow = e
  237. this.beginTime = e.beginTime
  238. this.endTime = e.endTime
  239. this.showDetail = true
  240. this.allowEdit = false
  241. this.isAdd = false
  242. if (e.reportObjects) {
  243. e.reportObjects.forEach((item) => {
  244. this.selectObject.push(item.id)
  245. })
  246. }
  247. },
  248. close() {
  249. this.currRow = {}
  250. this.beginTime = ""
  251. this.endTime = ""
  252. this.showDetail = false
  253. this.selectObject = []
  254. if (this.isReload) {
  255. this.getData(this.selectDate)
  256. this.isReload = false
  257. }
  258. },
  259. selectBeginTime(e) {
  260. this.beginTime = this.currRow.beginTime = e.target.value
  261. if (this.beginTime && this.endTime) {
  262. this.calcWorkHours(this.beginTime, this.endTime)
  263. }
  264. },
  265. selectEndTime(e) {
  266. this.endTime = this.currRow.endTime = e.target.value
  267. if (this.beginTime && this.endTime) {
  268. this.calcWorkHours(this.beginTime, this.endTime)
  269. }
  270. },
  271. calcWorkHours(beginTime, endTime) {
  272. let beginTimeLst = beginTime.split(':')
  273. let endTimeLst = endTime.split(':')
  274. let beginTimeStamp = Number(beginTimeLst[0] * 3600) + Number(beginTimeLst[1] * 60)
  275. let endTimeStamp = Number(endTimeLst[0] * 3600) + Number(endTimeLst[1] * 60)
  276. let workHours = ((endTimeStamp - beginTimeStamp) / 3600).toFixed(2)
  277. if (beginTime < '12:00' && endTime > '13:30') {
  278. workHours -= 1.5
  279. }
  280. this.currRow.workHours = workHours
  281. },
  282. showTasks() {
  283. if (this.allowEdit) {
  284. this.showTask = true
  285. }
  286. },
  287. selectTask(task) {
  288. this.currRow.task = task.title
  289. this.currRow.taskId = task.key
  290. this.showTask = false
  291. },
  292. btnOk() {
  293. if (!this.currRow.taskId) {
  294. uni.showModal({
  295. title: "汇报任务不允许为空",
  296. showCancel: false
  297. })
  298. return
  299. }
  300. if (this.selectObject.length == 0) {
  301. uni.showModal({
  302. title: "汇报对象不允许为空",
  303. showCancel: false
  304. })
  305. return
  306. }
  307. if (!this.currRow.content) {
  308. uni.showModal({
  309. title: "汇报内容不允许为空",
  310. showCancel: false
  311. })
  312. return
  313. }
  314. if (!this.currRow.workHours) {
  315. uni.showModal({
  316. title: "工作时数不允许为空",
  317. showCancel: false
  318. })
  319. return
  320. }
  321. this.currRow.reportObjects = this.selectObject
  322. this.currRow.files = []
  323. this.currRow.needDeleteFileIds = []
  324. if (this.isAdd) {
  325. this.currRow.reportDate = this.selectDate
  326. taskReport.personDayReportAdd(this.currRow).then(res => {
  327. if (res.data.success) {
  328. this.isReload = true
  329. uni.showToast({
  330. title: "新增成功",
  331. icon: "none"
  332. })
  333. this.currRow={}
  334. this.beginTime=""
  335. this.endTime=""
  336. this.selectObject=[]
  337. }
  338. })
  339. } else {
  340. taskReport.personDayReportEdit(this.currRow).then(res => {
  341. if (res.data.success) {
  342. uni.showToast({
  343. title: "修改成功",
  344. icon: "none"
  345. })
  346. }
  347. })
  348. }
  349. },
  350. }
  351. }
  352. </script>
  353. <style>
  354. .checkbox {
  355. height: 50rpx;
  356. width: 100%;
  357. }
  358. </style>