index.vue 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174
  1. <template>
  2. <div>
  3. <van-nav-bar title="填写日报" left-text="返回" @click-left="back" fixed left-arrow/>
  4. <van-form class="login_form" @submit="register">
  5. <van-field readonly clickable name="datetimePicker" :value="form.createDate" label="时间选择" placeholder="点击选择时间"
  6. @click="showPicker = true" :rules="rules.createDate" />
  7. <van-popup v-model="showPicker" position="bottom">
  8. <van-datetime-picker v-model="currentDate" type="date" :min-date="minDate" :max-date="maxDate" @confirm="changeTime" @cancel="showPicker = false"/>
  9. </van-popup>
  10. <van-cell title="总时长(h)" v-if="reportTimeType.type == 3">
  11. <template>
  12. <van-stepper :disabled="!canEdit" v-model="reportTimeType.allday" @change="changeAllTime" min="0.5" max="12" step="0.5" :decimal-length="1" />
  13. </template>
  14. </van-cell>
  15. <!-- <van-cell title="待分配时长" :value="report.time + 'h'" size="large"></van-cell> -->
  16. <div class="form_domains" v-for="(item,index) in form.domains" :key="item.id">
  17. <div style="float:right;margin-top:10px;margin-right:10px;">
  18. <!-- <van-tag v-if="canEdit&&item.projectName.length>0" color="#fff"
  19. @click="copyProject(index)" style="border: 1px solid #20a0ff;padding:5px;"
  20. icon="plus" type="default" ><span style="color:#666;padding: 0 5px;">复制项目</span></van-tag> -->
  21. <van-tag v-if="index>0&&canEdit" color="#fff"
  22. @click="delPro(index)" style="border: 1px solid #ff0000;padding:5px;margin-left:10px;"
  23. icon="plus" type="default" ><span style="color:#666;padding: 0 5px;">删除项目</span></van-tag>
  24. </div>
  25. <!-- <van-icon v-if="index>0&&canEdit" class="form_del" name="delete" @click="delPro(index)" /> -->
  26. <van-cell-group :title="'项目' + (index+1)">
  27. <van-field readonly name="projectId" clickable :value="item.projectName" label="投入项目" placeholder="请选择投入项目" @click="clickPicker(index)"
  28. :rules="[{ required: true, message: '请选择投入项目' }]"/>
  29. <van-popup v-model="showPickerProject" position="bottom">
  30. <van-picker show-toolbar :columns="project" value-key="projectName" @confirm="choseProject" @cancel="showPickerProject = false" />
  31. </van-popup>
  32. <!-- 相关维度 -->
  33. <van-field :value="item.weiduName" v-if="item.projectId && user.timeType.customDegreeActive == 1" readonly name="id" clickable :label="user.timeType.customDegreeName" placeholder="请选择" @click="clickPickers(index)"/>
  34. <van-popup v-model="showPickerProjects" position="bottom">
  35. <van-picker show-toolbar :columns="item.wuduList" value-key="name" @confirm="choseProjects" @cancel="showPickerProjects = false" />
  36. </van-popup>
  37. <van-cell title="专业进度" v-if="user.company.packageEngineering == 1">
  38. </van-cell>
  39. <van-field :disabled="!canEdit"
  40. type="number" :name="'progress_'+pItem.professionId" input-align="right"
  41. v-for="pItem in item.professionProgress" :key="pItem.professionId"
  42. :label="'-- '+pItem.professionName"
  43. >
  44. <template slot="input">
  45. <van-stepper v-model="pItem.progress" integer min="0" max="100" />%
  46. </template>
  47. </van-field>
  48. <van-field v-if="user.company.packageProject == 1" readonly name="taskId" :value="item.taskName" label="关联任务" placeholder="请选择关联任务" @click="clickPickerTask(index)"
  49. />
  50. <van-popup v-model="showPickerTask" position="bottom">
  51. <van-picker show-toolbar :columns="item.taskList" value-key="taskName" @confirm="choseTask" @cancel="showPickerTask = false" />
  52. </van-popup>
  53. <!-- <van-field readonly clickable class="form_input" :value="item.workingTime" name="workingTime" label="工作时长" placeholder="请输入工作时长(单位:小时)"
  54. :rules="[{ required: true, message: '请输入工作时长(单位:小时)' }]" @touchstart.native.stop="showNumberKey = true"/>
  55. <van-number-keyboard v-model="item.workingTime" :show="showNumberKey" close-button-text="完成" extra-key="." :maxlength="4" @blur="showNumberKey = false" /> -->
  56. <!-- 常规选择时间的方式 -->
  57. <!-- 全天上下午模式 -->
  58. <div v-if="reportTimeType.multiWorktime==0">
  59. <van-field v-if="reportTimeType.type < 2" readonly clickable :value="reportTimeType.type==0?item.label:(parseFloat(item.workingTime).toFixed(1)+'h')" label="工作时长" placeholder="请选择工作时长(小时)" @click="clickTimePicker(index)"
  60. :rules="[{ required: true, message: '请选择工作时长' }]"/>
  61. <van-popup v-model="showPickerTime" position="bottom">
  62. <van-picker show-toolbar :columns="timeType" value-key="label" @confirm="choseTimePick" @cancel="showPickerTime = false" />
  63. </van-popup>
  64. <!-- 选择数字时间长度模式 -->
  65. <van-popup v-model="showPickerHours" position="bottom">
  66. <van-picker show-toolbar :columns="timeRange"
  67. :default-index="15"
  68. @confirm="choseTimePick" @cancel="showPickerHours = false" />
  69. </van-popup>
  70. <!-- 时间段选择模式 -->
  71. <van-field readonly v-if="reportTimeType.type == 2" clickable name="datetimePicker" :value="item.startTime" label="开始时间" placeholder="点击选择时间"
  72. @click="canEdit?showStartTime = true:''" :disabled="!canEdit" />
  73. <van-popup v-model="showStartTime" position="bottom">
  74. <van-datetime-picker
  75. v-model="startTime"
  76. type="time"
  77. @confirm="confirmTime(item,0);"
  78. @cancel="showStartTime = false"
  79. :min-hour="0"
  80. :max-hour="23"
  81. />
  82. <!-- :filter="filter" 原本这个属性在里面 -->
  83. </van-popup>
  84. <van-field v-if="reportTimeType.type == 2" readonly clickable name="datetimePicker" :value="item.endTime" label="结束时间" placeholder="点击选择时间"
  85. @click="canEdit?showEndTime = true:''" :disabled="!canEdit" />
  86. <van-popup v-model="showEndTime" position="bottom" >
  87. <van-datetime-picker
  88. v-model="endTime"
  89. type="time"
  90. :min-hour="0"
  91. :max-hour="23"
  92. @confirm="confirmTime(item,1)"
  93. @cancel="showEndTime = false"
  94. />
  95. <!-- :filter="filter" 原本这个属性在里面 -->
  96. </van-popup>
  97. <van-cell v-if="reportTimeType.type == 3" >
  98. <template >
  99. <div>
  100. <span>用时占比</span>
  101. <van-slider :disabled="!canEdit" :min="10" :step="10" style="width:120px;display:inline-block;margin-left:50px;" v-model="item.progress" :value="100" @change="item.workingTime = (reportTimeType.allday*item.progress/100).toFixed(1)" >
  102. <template #button>
  103. <div class="custom-button">{{ item.progress }}%</div>
  104. </template>
  105. </van-slider>
  106. <span style="margin-left:10px;float:right;">{{item.workingTime}}小时</span>
  107. </div>
  108. </template>
  109. </van-cell>
  110. <van-field class="form_input" :disabled = "!canEdit"
  111. v-model="item.content" name="content" type="textarea" label="工作事项" placeholder="请输入工作事项"
  112. rows="3" autosize />
  113. </div>
  114. <!-- 多个时间和工作事项的选择方式 -->
  115. <div v-if="reportTimeType.multiWorktime==1">
  116. <div v-for="(timeItem, tindex) in item.worktimeList" :key="tindex" style="position:relative;border:#ccc 0.5px solid;margin:7px;">
  117. <van-tag v-if="tindex>0 && canEdit" style="position:absolute; right:-7px;top:-7px;z-index:10;"
  118. @click="removeTimeItem(item,tindex)">X</van-tag>
  119. <!-- 时间段选择模式 -->
  120. <van-field readonly v-if="reportTimeType.type == 2" :clickable="canEdit" name="datetimePicker"
  121. :value="timeItem.startTime" label="开始时间" placeholder="点击选择时间"
  122. :rules="[{ required: true, message: '必填项' }]"
  123. @click="canEdit?showStartDialog(timeItem):''" />
  124. <van-field v-if="reportTimeType.type == 2" readonly :clickable="canEdit" name="datetimePicker"
  125. :value="timeItem.endTime" label="结束时间" placeholder="点击选择时间"
  126. :rules="[{ required: true, message: '必填项' }]"
  127. @click="canEdit?showEndDialog(timeItem):''" />
  128. <van-field class="form_input" :disabled="!canEdit" style="color:#333;-webkit-text-fill-color:#646566;"
  129. v-model="timeItem.content" name="content" type="textarea" label="工作事项" placeholder="请输入工作事项"
  130. :rules="[{ required: true, message: '必填项' }]"
  131. rows="1" autosize />
  132. </div>
  133. <!--时间选择器 , 做统一处理,不能放到循环里,不然会有多个公用showStartTime,最后一个会现在最上层UI,导致BUG -->
  134. <van-popup v-model="showWorkStartTime" position="bottom">
  135. <van-datetime-picker
  136. v-model="startTime"
  137. type="time"
  138. @confirm="confirmWorkTime(0);"
  139. @cancel="showWorkStartTime = false"
  140. :min-hour="0"
  141. :max-hour="23"
  142. />
  143. <!-- :filter="filter" 原本这个属性在里面 -->
  144. </van-popup>
  145. <van-popup v-model="showWorkEndTime" position="bottom" >
  146. <van-datetime-picker
  147. v-model="endTime"
  148. type="time"
  149. :min-hour="0"
  150. :max-hour="23"
  151. @confirm="confirmWorkTime(1)"
  152. @cancel="showWorkEndTime = false"
  153. />
  154. <!-- :filter="filter" 原本这个属性在里面 -->
  155. </van-popup>
  156. </div>
  157. <div style="width:100%;" v-if="canEdit&&reportTimeType.multiWorktime==1">
  158. <van-tag style="text-align:center;padding:5px;margin-left:15px;border: 1px solid #20a0ff;"
  159. :disabled="!canEdit" @click="addNewWorktime(index, item)"
  160. icon="plus" color="#ffffff" ><span style="color:#999;text-align:center;padding: 0 5px;"> 添加工时 </span></van-tag>
  161. </div>
  162. <div class="overtime" >
  163. <van-checkbox :disabled="!canEdit" v-model="item.isOvertime" v-if="reportTimeType.multiWorktime !=1">加班</van-checkbox>
  164. <van-tag style="position:absolute;right:10px;" v-if="isCorpWX&&canEdit" type="primary" size="large" @click="takePhoto(index)">拍照上传</van-tag>
  165. </div>
  166. <div style="padding:5px;text-align:center;" v-if="!isIOSystem">
  167. <span v-for="(p, index) in item.pics" :key="p" style="margin-right:15px;">
  168. <img :src="p" style="width:100px; height:100px;" @click="showLargeImg(item.pics, index)"/>
  169. </span>
  170. </div>
  171. <div style="padding:5px;text-align:center;" v-if="isIOSystem">
  172. <span v-for="(p, index) in item.iospics" :key="p" style="margin-right:15px;">
  173. <img :src="p" style="width:100px; height:100px;" @click="showLargeImg(item.iospics, index)"/>
  174. </span>
  175. </div>
  176. <van-popup v-model="imgShow" position="bottom" closeable >
  177. <van-swipe class="my-swipe" indicator-color="white">
  178. <van-swipe-item v-for="(picItem, index) in tmpPics" :key="index">
  179. <img :src="picItem" style="width:100%;" />
  180. </van-swipe-item>
  181. </van-swipe>
  182. </van-popup>
  183. </van-cell-group>
  184. </div>
  185. <div style="text-align:center;" >
  186. <van-tag v-if="canEdit" size="large" style="text-align:center;margin:10px;padding:12px;margin-bottom:120px;border: 1px solid #20a0ff;"
  187. :disabled="!canEdit" @click="addNewPro"
  188. icon="plus" color="#ffffff" ><span style="color:#999;text-align:center;padding: 0 50px;"> + 新增项目 </span></van-tag>
  189. </div>
  190. <div class="form_btn" style="position:fixed; bottom:0px;width:100%;">
  191. <van-button v-if="canEdit" block type="info" native-type="submit"> 提交 </van-button>
  192. <p v-if="canEdit&&form.domains.length>0 && form.domains[0].id != null" block type="default"
  193. style="padding-top:30px;font-size:15px;color:#666;margin:0 auto;text-align:center;padding-bottom:10px;background:#ffffff;" @click="deleteReport"> 删除 </p>
  194. </div>
  195. </van-form>
  196. <div style="position:fixed; bottom:0px;width:100%;">
  197. <van-button v-if="canCancel" block type="default" @click="cancel"> 撤销 </van-button>
  198. </div>
  199. <div class="form_tip" v-if="!canEdit && !canCancel"> 已审核无法修改 </div>
  200. </div>
  201. </template>
  202. <script src="//res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
  203. <script>
  204. import wx from 'weixin-js-sdk'
  205. // Vue.prototype.$wx = wx
  206. export default {
  207. data() {
  208. return {
  209. showWorkStartTime:false,
  210. showWorkEndTime:false,
  211. curWorktime:null,
  212. isIOSystem:false,
  213. imgShow: false,
  214. isCorpWX:false,
  215. isWX: false,
  216. showPickerTask:false,
  217. canCancel:false,
  218. canEdit:false,
  219. showEndTime: false,
  220. showStartTime: false,
  221. startTime:'09:00',
  222. endTime: '18:00',
  223. nowTime:new Date(),
  224. showPickerHours: false,
  225. timeRange:[0.5,1.0,1.5,2.0,2.5,3.0,3.5,4.0,4.5,5.0,5.5,6.0,6.5,7.0,7.5,8.0,8.5,9.0,9.5,10.0,10.5,11.0,11.5,12.5,13.0,13.5,14.0,14.5,15.0],
  226. selectTime:null,
  227. reportTimeType:{},
  228. user: JSON.parse(localStorage.userInfo),
  229. minDate: new Date(2010, 0, 1),
  230. maxDate: new Date(new Date().getFullYear(),new Date().getMonth(),new Date().getDate()+7),
  231. currentDate: new Date(),
  232. showPickerTime: false,
  233. showPicker: false,
  234. showPickerProject: false,
  235. showPickerProjects: false,
  236. clickIndex: 0,
  237. clickTimeIndex: 0,
  238. showNumberKey: false,
  239. canClick: 2,
  240. timeType:[],
  241. form: {
  242. createDate: this.format(new Date(new Date()),"yyyy-MM-dd"),
  243. domains: [{
  244. id: null,
  245. projectId: "",
  246. projectName: "",
  247. workingTime: "",
  248. content: "",
  249. state: 2,
  250. multiWorktime:0,
  251. worktimeList:{},
  252. degreeId: ''
  253. // pics:["https://worktime.ttkuaiban.com/upload/bc4df504fa724e6cab69872e2c1cfb35.png",
  254. // "https://worktime.ttkuaiban.com/upload/bc4df504fa724e6cab69872e2c1cfb35.png",
  255. // "https://worktime.ttkuaiban.com/upload/bc4df504fa724e6cab69872e2c1cfb35.png",]
  256. }],
  257. },
  258. rules: {
  259. createDate: [{ required: true, message: '请选择填报日期' }],
  260. },
  261. project: [],
  262. report: "",
  263. loading: false,
  264. finished: false,
  265. // isOvertime: false
  266. tmpPics:[],
  267. dateAr: []
  268. };
  269. },
  270. created() {
  271. },
  272. methods: {
  273. showEndDialog(timeItem) {
  274. this.curWorktime = timeItem;
  275. this.showWorkEndTime = true;
  276. },
  277. showStartDialog(timeItem) {
  278. this.curWorktime = timeItem;
  279. this.showWorkStartTime = true;
  280. },
  281. removeTimeItem(item, index) {
  282. item.worktimeList.splice(index, 1);
  283. },
  284. isIOS(){
  285. var u = navigator.userAgent;
  286. var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
  287. return isiOS;
  288. },
  289. showLargeImg(item, index) {
  290. this.imgShow = true;
  291. this.tmpPics = item;
  292. },
  293. //拍照上传
  294. takePhoto(index) {
  295. var that = this;
  296. wx.chooseImage({
  297. count: 3, // 默认9
  298. sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有
  299. sourceType: ['camera'], // 可以指定来源是相册还是相机,默认二者都有
  300. defaultCameraMode: "batch", //表示进入拍照界面的默认模式,目前有normal与batch两种选择,normal表示普通单拍模式,batch表示连拍模式,不传该参数则为normal模式。从3.0.26版本开始支持front和batch_front两种值,其中front表示默认为前置摄像头单拍模式,batch_front表示默认为前置摄像头连拍模式。(注:用户进入拍照界面仍然可自由切换两种模式)
  301. isSaveToAlbum: 0, //整型值,0表示拍照时不保存到系统相册,1表示自动保存,默认值是1
  302. success: function (res) {
  303. var localIds = res.localIds; // 返回选定照片的本地ID列表,
  304. // andriod中localId可以作为img标签的src属性显示图片;
  305. // iOS应当使用 getLocalImgData 获取图片base64数据,从而用于img标签的显示(在img标签内使用 wx.chooseImage 的 localid 显示可能会不成功)
  306. if (that.isIOSystem) {
  307. var retArray = [];
  308. for (var i=0;i<localIds.length; i++) {
  309. wx.getLocalImgData({
  310. localId: localIds[i], // 图片的localID
  311. success: function (res) {
  312. var localData = res.localData; // localData是图片的base64数据,可以用img标签显示
  313. retArray.push(localData);
  314. }
  315. });
  316. }
  317. that.form.domains[index].iospics = retArray;
  318. that.form.domains[index].pics = localIds;
  319. } else {
  320. that.form.domains[index].pics = localIds;
  321. that.$forceUpdate();
  322. }
  323. var serverIdList = [];
  324. //立即就上传到企业微信服务器
  325. for (var i=0;i<localIds.length; i++) {
  326. wx.uploadImage({
  327. localId: localIds[i], // 需要上传的图片的本地ID,由chooseImage接口获得
  328. isShowProgressTips: 1, // 默认为1,显示进度提示
  329. success: function (res) {
  330. var serverId = res.serverId; // 返回图片的服务器端ID
  331. serverIdList.push(serverId);
  332. }
  333. });
  334. }
  335. that.form.domains[index].serverPics = serverIdList;
  336. }
  337. });
  338. },
  339. copyProject(index) {
  340. var leftProgress = 10;
  341. if (this.reportTimeType.type == 3) {
  342. //计算已经待分配工时比例
  343. let array = this.form.domains;
  344. let totalProgress = 0;
  345. for (var i=0;i<array.length; i++) {
  346. totalProgress += array[i].progress;
  347. }
  348. if (totalProgress < 100) {
  349. leftProgress = 100 - totalProgress;
  350. }
  351. }
  352. var newIndex = index+1;
  353. var pName = "";
  354. if (this.form.domains[index].projectId != '') {
  355. pName = this.project.filter(p=>p.id == this.form.domains[index].projectId)[0].projectName;
  356. }
  357. var itemDomain = {
  358. id: null,
  359. projectId: this.form.domains[index].projectId,
  360. projectName: pName,
  361. workingTime: this.reportTimeType.type==3?(leftProgress*this.reportTimeType.allday/100).toFixed(1):"",
  362. progress:leftProgress,
  363. content: "",
  364. state: 2,
  365. isOvertime:false,
  366. };
  367. this.form.domains.splice(newIndex, 0,itemDomain);
  368. },
  369. //删除日报
  370. deleteReport() {
  371. this.$dialog.confirm({
  372. title: '删除日报',
  373. message: '确定要删除当天日报吗?'
  374. }).then(() => {
  375. const toast = this.$toast.loading({
  376. forbidClick: true,
  377. duration: 0
  378. });
  379. this.$axios.post("/report/delete", {userId: this.user.id, date:this.form.createDate})
  380. .then(res => {
  381. if(res.code == "ok") {
  382. toast.clear();
  383. this.$toast.success('删除成功');
  384. window.location.reload();
  385. } else {
  386. toast.clear();
  387. this.$toast.fail('删除失败');
  388. }
  389. }).catch(err=> {toast.clear();});
  390. }).catch(() => {});
  391. },
  392. changeAllTime() {
  393. //总时长发生改变,自动按比例计算
  394. this.form.domains.forEach(d=>{
  395. d.workingTime = (d.progress*this.reportTimeType.allday/100).toFixed(1);
  396. });
  397. },
  398. cancel() {
  399. const toast = this.$toast.loading({
  400. forbidClick: true,
  401. duration: 0
  402. });
  403. var ids = '';
  404. var data = this.form.domains;
  405. data.forEach(element => {
  406. if (element.id != null && element.id != '') {
  407. ids +=(element.id+',');
  408. }
  409. });
  410. this.$axios.post("/report/cancel", {userId: this.user.id, reportIds:ids})
  411. .then(res => {
  412. if(res.code == "ok") {
  413. toast.clear();
  414. this.$toast.success('撤销成功');
  415. this.getReport();
  416. } else {
  417. toast.clear();
  418. this.$toast.fail('获取失败');
  419. }
  420. }).catch(err=> {toast.clear();});
  421. },
  422. confirmWorkTime(field) {
  423. if (field == 0) {
  424. this.curWorktime.startTime = this.startTime;
  425. this.showWorkStartTime = false;
  426. } else {
  427. this.curWorktime.endTime = this.endTime;
  428. this.showWorkEndTime = false;
  429. }
  430. },
  431. confirmTime(item, field) {
  432. if (field == 0) {
  433. item.startTime = this.startTime;
  434. this.showStartTime = false;
  435. } else {
  436. item.endTime = this.endTime;
  437. this.showEndTime = false;
  438. }
  439. },
  440. filter(type, options) {
  441. if (type === 'minute') {
  442. return options.filter(option => option % 30 === 0);
  443. }
  444. return options;
  445. },
  446. choseTimePick(value, index) {
  447. //选中时间
  448. if (this.reportTimeType.type == 0) {
  449. this.form.domains[this.clickTimeIndex].timeType = value.value;
  450. this.form.domains[this.clickTimeIndex].workingTime = value.hours;
  451. this.form.domains[this.clickTimeIndex].label = value.label;
  452. this.showPickerTime = false;
  453. } else if (this.reportTimeType.type == 1) {
  454. console.log('this.reportTimeType.type=='+value);
  455. this.form.domains[this.clickTimeIndex].workingTime = value;
  456. this.form.domains[this.clickTimeIndex].label = value.toFixed(1)+'小时';
  457. this.showPickerHours = false;
  458. }
  459. },
  460. clickTimePicker(i) {
  461. if (!this.canEdit) {
  462. return;
  463. }
  464. this.clickTimeIndex = i;
  465. if (this.reportTimeType.type == 0) {
  466. this.showPickerTime = true;
  467. } else if (this.reportTimeType.type == 1) {
  468. this.showPickerHours = true;
  469. }
  470. },
  471. getTimeType() {
  472. this.$axios.post('/time-type/getCompanyTimeSetting', { companyId: this.user.companyId})
  473. .then(res => {
  474. if(res.code == "ok") {
  475. var t = res.data;
  476. this.reportTimeType = t;
  477. //转化时间格式
  478. if (t.allday != null) {
  479. this.timeType.push({value:0, label:'全天 - '+t.allday+'小时', hours:t.allday});
  480. }
  481. if (t.am != null) {
  482. this.timeType.push({value:1, label:'上午 - '+t.am+'小时', hours: t.am});
  483. }
  484. if (t.pm != null) {
  485. this.timeType.push({value:2, label:'下午 - '+t.pm+'小时', hours: t.pm});
  486. }
  487. } else {
  488. toast.clear();
  489. this.$toast.fail(res.msg);
  490. }
  491. }).catch(err=> {toast.clear();});
  492. },
  493. // 返回
  494. back() {
  495. history.back();
  496. },
  497. // 时间转换
  498. format(date, pattern) {
  499. pattern = pattern || "yyyy-MM-dd";
  500. var _this = this;
  501. return pattern.replace(/([yMdhsm])(\1*)/g, function ($0) {
  502. switch ($0.charAt(0)) {
  503. case 'y': return _this.padding(date.getFullYear(), $0.length);
  504. case 'M': return _this.padding(date.getMonth() + 1, $0.length);
  505. case 'd': return _this.padding(date.getDate(), $0.length);
  506. case 'w': return date.getDay() + 1;
  507. case 'h': return _this.padding(date.getHours(), $0.length);
  508. case 'm': return _this.padding(date.getMinutes(), $0.length);
  509. case 's': return _this.padding(date.getSeconds(), $0.length);
  510. }
  511. });
  512. },
  513. padding(s, len) {
  514. var len = len - (s + '').length;
  515. for (var i = 0; i < len; i++) { s = '0' + s; }
  516. return s;
  517. },
  518. // 获取项目
  519. getProject() {
  520. const toast = this.$toast.loading({
  521. forbidClick: true,
  522. duration: 0
  523. });
  524. this.$axios.post("/project/getProjectList", {})
  525. .then(res => {
  526. if(res.code == "ok") {
  527. toast.clear();
  528. this.project = res.data;
  529. // if (this.project.length > 0) {
  530. // console.log('this.project[0].id=='+this.project[0].id);
  531. // this.getTaskList(this.project[0].id);
  532. // }
  533. } else {
  534. toast.clear();
  535. this.$toast.fail('获取失败:'+res.msg);
  536. }
  537. }).catch(err=> {toast.clear();});
  538. },
  539. // 获取日报
  540. getReport() {
  541. const toast = this.$toast.loading({
  542. forbidClick: true,
  543. duration: 0
  544. });
  545. this.$axios.post("/report/getReport", {date: this.form.createDate})
  546. .then(res => {
  547. if(res.code == "ok") {
  548. toast.clear();
  549. this.report = res.data;
  550. var t = res.data.timeType;
  551. var timeType=[];
  552. //转化时间格式
  553. if (t.allday != null) {
  554. timeType.push({value:0, label:'全天 - '+t.allday+'小时', hours:t.allday});
  555. }
  556. if (t.am != null) {
  557. timeType.push({value:1, label:'上午 - '+t.am+'小时', hours: t.am});
  558. }
  559. if (t.pm != null) {
  560. timeType.push({value:2, label:'下午 - '+t.pm+'小时', hours: t.pm});
  561. }
  562. var list = res.data.report;
  563. if(list.length != 0) {
  564. this.canEdit = false;
  565. this.canCancel = false;
  566. let array = [];
  567. for(var i in list) {
  568. var projectName = "";
  569. var flg = (list[i].isOvertime == 1);
  570. for(var j in this.project) {
  571. if(this.project[j].id == list[i].projectId) {
  572. projectName = this.project[j].projectName;
  573. }
  574. }
  575. let tname = '';
  576. if (list[i].taskId != null && list[i].taskList.length > 0) {
  577. let filterList = list[i].taskList.filter(t=>t.taskId == list[i].taskId);
  578. if (filterList.length > 0) {
  579. tname = filterList[0].taskName;
  580. }
  581. }
  582. let mmm = list[i].degreeId
  583. let sss = list[i].degreeList
  584. let wuduName = ''
  585. for (var s in sss) {
  586. if(sss[s].id == mmm) {
  587. wuduName = sss[s].name
  588. }
  589. }
  590. array.push({
  591. id: list[i].id,
  592. projectId: list[i].projectId,
  593. projectName: projectName,
  594. workingTime: String(list[i].workingTime),
  595. content: list[i].content,
  596. state: list[i].state,
  597. timeType: list[i].timeType,
  598. label: timeType[list[i].timeType].label,
  599. startTime: list[i].startTime,
  600. endTime: list[i].endTime,
  601. isOvertime: flg,
  602. progress: list[i].progress,
  603. taskList: list[i].taskList,
  604. taskId: list[i].taskId,
  605. taskName:tname,
  606. professionProgress:list[i].professionProgressList,
  607. pics: list[i].pics,
  608. iospics:list[i].pics,
  609. multiWorktime:t.multiWorktime,
  610. worktimeList:list[i].worktimeList,
  611. wuduList: list[i].degreeList,
  612. weiduName: wuduName,
  613. degreeId: list[i].degreeId
  614. })
  615. if (list[i].state >= 2) {
  616. this.canEdit = true;
  617. } else if (list[i].state == 0) {
  618. this.canCancel = true;
  619. }
  620. }
  621. this.form.domains = array;
  622. } else {
  623. this.canCancel = false;
  624. this.canEdit = true;
  625. //没有填报的可以点击提交
  626. this.form.domains = [{
  627. id: null,
  628. projectId: "",
  629. projectName: "",
  630. workingTime: t.type==3?(t.allday).toFixed(1):"8.0",
  631. content: "",
  632. state: 2,
  633. progress:100,
  634. isOvertime:false,
  635. professionProgress:[],
  636. multiWorktime:t.multiWorktime,
  637. worktimeList:[{}]
  638. }]
  639. this.canEdit = true;
  640. }
  641. } else {
  642. toast.clear();
  643. this.$toast.fail('获取失败:'+res.msg);
  644. }
  645. }).catch(err=> {toast.clear();});
  646. },
  647. // 改变时间
  648. changeTime(time) {
  649. this.form.createDate = this.format(new Date(time),"yyyy-MM-dd");
  650. this.currentDate = time;
  651. this.showPicker = false;
  652. this.getReport();
  653. },
  654. // 选择项目
  655. clickPicker(i) {
  656. if (!this.canEdit) return;
  657. this.clickIndex = i;
  658. this.showPickerProject = true;
  659. },
  660. clickPickers(i) {
  661. if (!this.canEdit) return;
  662. this.clickIndex = i;
  663. this.showPickerProjects = true;
  664. },
  665. //选择任务
  666. clickPickerTask(i) {
  667. if (!this.canEdit) return;
  668. this.clickIndex = i;
  669. this.showPickerTask = true;
  670. },
  671. choseTask(value, index) {
  672. this.form.domains[this.clickIndex].taskId = value.taskId;
  673. this.form.domains[this.clickIndex].taskName = value.taskName;
  674. this.showPickerTask = false;
  675. },
  676. choseProjects(value, index) {
  677. // console.log(value)
  678. this.form.domains[this.clickIndex].weiduName = value.name;
  679. this.form.domains[this.clickIndex].degreeId = value.id;
  680. this.showPickerProjects = false;
  681. },
  682. choseProject(value, index) {
  683. this.form.domains[this.clickIndex].projectId = value.id;
  684. this.form.domains[this.clickIndex].projectName = value.projectName;
  685. this.showPickerProject = false;
  686. this.getTaskList(value.id);
  687. this.dimension(value.id) // 获取维度
  688. //加载项目相关的工程进度
  689. if (this.user.company.packageEngineering == 1) {
  690. this.getProjectProfessions(this.form.domains[this.clickIndex], index);
  691. }
  692. },
  693. getProjectProfessions(domain, index) {
  694. this.$axios.post("/project-profession/getMyProfession", {projectId: domain.projectId})
  695. .then(res => {
  696. if(res.code == "ok") {
  697. this.form.domains[this.clickIndex].professionProgress = res.data;
  698. this.$forceUpdate();
  699. } else {
  700. this.$toast.fail('获取失败');
  701. }
  702. }).catch(err=> {toast.clear();});
  703. },
  704. // 获取维度
  705. dimension(projectId) {
  706. this.$axios.post("/project/getDegreeList", {projectId: projectId})
  707. .then(res => {
  708. if(res.code == "ok") {
  709. this.form.domains[this.clickIndex].wuduList = res.data;
  710. this.$forceUpdate();
  711. } else {
  712. this.$toast.fail('获取失败');
  713. }
  714. }).catch(err=> {toast.clear();});
  715. },
  716. getTaskList(projectId) {
  717. //如果是专业版,需要列出任务列表
  718. if (this.user.company.packageProject == 1) {
  719. this.$axios.post("/task/getRecentTask", {projectId: projectId})
  720. .then(res => {
  721. if(res.code == "ok") {
  722. this.form.domains[this.clickIndex].taskList = res.data;
  723. this.$forceUpdate();
  724. } else {
  725. this.$toast.fail('获取失败');
  726. }
  727. }).catch(err=> {toast.clear();});
  728. }
  729. },
  730. //添加工时
  731. addNewWorktime(index, item) {
  732. item.worktimeList.push({});
  733. },
  734. // 添加项目
  735. addNewPro() {
  736. var leftProgress = 10;
  737. if (this.reportTimeType.type == 3) {
  738. //计算已经待分配工时比例
  739. let array = this.form.domains;
  740. let totalProgress = 0;
  741. for (var i=0;i<array.length; i++) {
  742. totalProgress += array[i].progress;
  743. }
  744. if (totalProgress < 100) {
  745. leftProgress = 100 - totalProgress;
  746. }
  747. }
  748. this.form.domains.push({
  749. id: null,
  750. projectId: "",
  751. projectName: "",
  752. workingTime: this.reportTimeType.type==3?(leftProgress*this.reportTimeType.allday/100).toFixed(1):"4.0",
  753. progress:leftProgress,
  754. content: "",
  755. state: 2,
  756. isOvertime:false,
  757. multiWorktime: this.reportTimeType.multiWorktime,
  758. worktimeList:[{}],
  759. degreeId: null
  760. })
  761. },
  762. // 移除项目
  763. delPro(i) {
  764. this.$dialog.confirm({
  765. title: '',
  766. message: '是否移除当前项目'
  767. }).then(() => {
  768. this.form.domains.splice(i,1);
  769. }).catch(() => {
  770. });
  771. },
  772. // 判断时间段
  773. fns() {
  774. for (let k in this.dateAr) {
  775. if (!this.judege(k)) {
  776. return false
  777. }
  778. }
  779. return true
  780. },
  781. judege(idx){
  782. for (let k in this.dateAr) {
  783. if (idx !== k) {
  784. if (this.dateAr[k].s <= this.dateAr[idx].s && this.dateAr[k].e > this.dateAr[idx].s) {
  785. return false
  786. }
  787. if (this.dateAr[k].s < this.dateAr[idx].e && this.dateAr[k].e >= this.dateAr[idx].e) {
  788. return false
  789. }
  790. }
  791. }
  792. return true
  793. },
  794. // 提交日报
  795. register() {
  796. console.log(this.form, '看啊可能')
  797. // return
  798. this.dateAr = []
  799. let alp = []
  800. if(this.user.timeType.multiWorktime == 1) {
  801. for(var p in this.form.domains) {
  802. var slll = this.form.domains[p]
  803. for(var o in slll.worktimeList) {
  804. if(slll.worktimeList[o].startTime || slll.worktimeList[o].endTime) {
  805. let objs = {}
  806. objs.s = slll.worktimeList[o].startTime
  807. objs.e = slll.worktimeList[o].endTime
  808. alp.push(objs)
  809. }
  810. }
  811. }
  812. this.dateAr = alp
  813. if(this.dateAr.length > 0) {
  814. let trus = this.fns()
  815. if(!trus) {
  816. this.$toast('填写的时间段重叠')
  817. return
  818. }
  819. }
  820. }
  821. // return
  822. const toast = this.$toast.loading({
  823. forbidClick: true,
  824. duration: 0
  825. });
  826. let formData = new FormData();
  827. if (this.reportTimeType.type == 0) {
  828. var alldayNum = 0;
  829. var amNum = 0;
  830. var pmNum = 0;
  831. for(var i in this.form.domains) {
  832. if (this.form.domains[i].timeType == 0) {
  833. alldayNum ++;
  834. } else if (this.form.domains[i].timeType == 1) {
  835. amNum++;
  836. } else if (this.form.domains[i].timeType == 2) {
  837. pmNum++;
  838. }
  839. }
  840. if (alldayNum > 1) {
  841. this.$toast.fail("工作时间-全天,只能选择一次");
  842. return;
  843. }
  844. if (amNum > 1) {
  845. this.$toast.fail("工作时间-上午,只能选择一次");
  846. return;
  847. }
  848. if (pmNum > 1) {
  849. this.$toast.fail("工作时间-下午,只能选择一次");
  850. return;
  851. }
  852. if (alldayNum == 1 && (amNum > 0 || pmNum > 0)) {
  853. this.$toast.fail("工作时间-全天,不能和上下午同时存在");
  854. return;
  855. }
  856. } else if (this.reportTimeType.type == 3) {
  857. //总百分比不能超过100%
  858. let total = 0;
  859. this.form.domains.forEach(w=>{total += w.progress});
  860. if (total > 100) {
  861. this.$toast.fail("用时比例之和不能超过100%");
  862. return;
  863. } else if (total < 100) {
  864. this.$toast.fail("工时尚未完全分配,无法提交");
  865. return;
  866. }
  867. }
  868. //填字段
  869. for(var i in this.form.domains) {
  870. if (this.user.timeType.customDegreeActive == 1) {
  871. if(this.form.domains[i].degreeId) {
  872. formData.append("degreeId", this.form.domains[i].degreeId);
  873. } else {
  874. formData.append("degreeId", -1);
  875. }
  876. }
  877. if (this.form.domains[i].id != null) {
  878. formData.append("id", this.form.domains[i].id);
  879. } else {
  880. formData.append("id", -1);
  881. }
  882. formData.append("projectId", parseFloat(this.form.domains[i].projectId));
  883. if (this.form.domains[i].subProjectId != null) {
  884. formData.append("subProjectId", this.form.domains[i].subProjectId);
  885. } else {
  886. formData.append("subProjectId", 0);
  887. }
  888. formData.append("reportTimeType", this.reportTimeType.type);
  889. formData.append("multiWorktime", this.reportTimeType.multiWorktime);
  890. if (this.reportTimeType.type == 0) {
  891. formData.append("timeType", this.form.domains[i].timeType);
  892. formData.append("workingTime", parseFloat(this.form.domains[i].workingTime));
  893. } else if (this.reportTimeType.type == 1) {
  894. formData.append("workingTime", parseFloat(this.form.domains[i].workingTime));
  895. } else if (this.reportTimeType.type == 2) {
  896. formData.append("startTime", this.form.domains[i].startTime);
  897. formData.append("endTime",this.form.domains[i].endTime);
  898. } else if (this.reportTimeType.type == 3) {
  899. formData.append("progress", this.form.domains[i].progress);
  900. formData.append("workingTime",this.form.domains[i].workingTime);
  901. }
  902. if (this.form.domains[i].taskId == null) {
  903. formData.append("taskId", 0);
  904. } else {
  905. formData.append("taskId", this.form.domains[i].taskId);
  906. }
  907. formData.append("createDate", this.form.createDate);
  908. formData.append("isOvertime", this.form.domains[i].isOvertime?1:0);
  909. //项目专业进度
  910. if (this.form.domains[i].professionProgress != null) {
  911. let m = JSON.stringify(this.form.domains[i].professionProgress);
  912. m = m.replace(/,/g,"@");//replaceAll(',','@');企业微信不兼容replaceAll
  913. formData.append("professionProgress", m);
  914. } else {
  915. formData.append("professionProgress", "[]");
  916. }
  917. //图片的处理,只处理当前通过手机拍摄的新的照片
  918. if (this.form.domains[i].serverPics!= null && this.form.domains[i].serverPics.length > 0) {
  919. let m = JSON.stringify(this.form.domains[i].serverPics);
  920. m = m.replace(/,/g,"@");//replaceAll(',','@');企业微信不兼容replaceAll
  921. formData.append("pics", m);
  922. } else {
  923. formData.append("pics", "@");
  924. }
  925. //处理多个时间事项
  926. if (this.reportTimeType.multiWorktime == 1) {
  927. //检查时间是否有重叠
  928. var workList = this.form.domains[i].worktimeList;
  929. for (var j=0;j<workList.length; j++) {
  930. var curItem = workList[j];
  931. if (curItem.startTime == null || curItem.endTime == null) {
  932. this.$toast.fail("请设置工作时间");
  933. return;
  934. }
  935. //检查开始时间是否大于结束时间
  936. if (curItem.startTime >= curItem.endTime) {
  937. this.$toast.fail("时间段"+curItem.startTime+'-'+curItem.endTime+"有误:"+
  938. "结束时间必须大于开始时间");
  939. return;
  940. }
  941. for (var p = j+1;p<workList.length; p++) {
  942. var jItem = workList[p];
  943. if ((jItem.startTime>=curItem.startTime&&jItem.startTime < curItem.endTime)
  944. || (jItem.endTime>curItem.startTime&&jItem.endTime <= curItem.endTime)) {
  945. this.$toast.fail("时间段"+curItem.startTime+'-'+curItem.endTime+"与"+
  946. jItem.startTime+'-'+jItem.endTime+ "存在重叠,请修改。");
  947. return;
  948. }
  949. }
  950. }
  951. let m = JSON.stringify(this.form.domains[i].worktimeList);
  952. m = m.replace(/,/g,"@");//replaceAll(',','@');企业微信不兼容replaceAll
  953. formData.append("content", m);
  954. } else {
  955. if (this.form.domains[i].content == null || this.form.domains[i].content == '') {
  956. formData.append("content", '-');
  957. } else {
  958. formData.append("content", this.form.domains[i].content);
  959. }
  960. }
  961. }
  962. this.$axios.post("/report/editReport", formData)
  963. .then(res => {
  964. if(res.code == "ok") {
  965. toast.clear();
  966. this.$toast.success('填报成功');
  967. this.$router.push("/index");
  968. } else {
  969. toast.clear();
  970. this.$toast.fail('填报失败');
  971. }
  972. }).catch(err=> {toast.clear();});
  973. },
  974. //初始化参数
  975. initWxConfig() {
  976. var curUrl=location.href.split("#")[0];
  977. this.$axios.post("/wxcorp/getCorpWXConfig", {url: curUrl, token: this.user.id})
  978. .then(res => {
  979. if(res.code == "ok") {
  980. var data=res.data;
  981. wx.config({
  982. beta: true,
  983. debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  984. appId: data.appid, // 必填,公众号的唯一标识
  985. timestamp: data.timestamp, // 必填,生成签名的时间戳
  986. nonceStr: data.noncestr, // 必填,生成签名的随机串
  987. signature: data.sign, // 必填,签名,见附录1
  988. jsApiList: [
  989. 'chooseImage',
  990. 'previewImage',
  991. 'uploadImage',
  992. 'downloadImage',
  993. 'previewFile',
  994. 'getLocation',
  995. ]
  996. });
  997. wx.ready(function(){
  998. // config信息验证后会执行ready方法,所有接口调用都必须在config接口获得结果之后,config是一个客户端的异步操作,所以如果需要在页面加载时就调用相关接口,则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中。
  999. console.log('企业微信初始化执行成功了。 ');
  1000. });
  1001. } else {
  1002. this.$toast.fail('获取失败');
  1003. }
  1004. }).catch(err=> {this.$toast.fail('发生异常'+err);console.log(err)});
  1005. }
  1006. },
  1007. mounted() {
  1008. var ua = navigator.userAgent.toLowerCase();
  1009. this.isIOSystem = this.isIOS();
  1010. if (ua.indexOf("wxwork") > 0) {
  1011. this.isCorpWX = true;
  1012. } else if (ua.indexOf("micromessenger") > 0) {
  1013. this.isWX = true;
  1014. }
  1015. //获取传递过来的日期
  1016. var passDate = this.$route.query.date;
  1017. if (passDate != null) {
  1018. this.form.createDate = this.$route.query.date;
  1019. }
  1020. this.getProject();
  1021. this.getReport();
  1022. this.getTimeType();
  1023. //初始化微信js-sdk参数
  1024. if (this.isCorpWX) {
  1025. this.initWxConfig();
  1026. }
  1027. }
  1028. };
  1029. </script>
  1030. <style lang="less" scope>
  1031. .my-swipe .van-swipe-item {
  1032. color: #fff;
  1033. font-size: 20px;
  1034. line-height: 150px;
  1035. text-align: center;
  1036. background-color: #39a9ed;
  1037. }
  1038. .van-field__control:disabled {
  1039. -webkit-text-fill-color:#646566;
  1040. }
  1041. .login_form {
  1042. margin-top: 46px;
  1043. }
  1044. .form_domains {
  1045. position: relative;
  1046. .form_copy {
  1047. position: absolute;
  1048. right: 85px;
  1049. top: 10px;
  1050. }
  1051. .form_addNew {
  1052. text-align: center;
  1053. margin:10px;
  1054. }
  1055. .form_del {
  1056. position: absolute;
  1057. right: 10px;
  1058. top: 10px;
  1059. }
  1060. // .form_del {
  1061. // color: #ff0000;
  1062. // font-size: 22px;
  1063. // position: absolute;
  1064. // right: 15px;
  1065. // top: 10px;
  1066. // }
  1067. }
  1068. .form_tip {
  1069. text-align: center;
  1070. margin-top: 20px;
  1071. color: #afafaf;
  1072. font-size: 14px;
  1073. }
  1074. .card__footer {
  1075. padding-top: 10px;
  1076. }
  1077. .card__tags {
  1078. .van-tag {
  1079. margin-right: 5px;
  1080. }
  1081. }
  1082. </style>
  1083. <style lang="less">
  1084. .van-nav-bar .van-icon , .van-nav-bar__text {
  1085. color: #20a0ff;
  1086. }
  1087. .overtime {
  1088. height: 50px;
  1089. box-sizing: border-box;
  1090. padding-left: 10px;
  1091. display: flex;
  1092. align-items: center;
  1093. }
  1094. .custom-button {
  1095. width: 40px;
  1096. color: #fff;
  1097. font-size: 10px;
  1098. line-height: 16px;
  1099. text-align: center;
  1100. background-color: #1989fa;
  1101. border-radius: 100px;
  1102. }
  1103. </style>