index.vue 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155
  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. array.push({
  583. id: list[i].id,
  584. projectId: list[i].projectId,
  585. projectName: projectName,
  586. workingTime: String(list[i].workingTime),
  587. content: list[i].content,
  588. state: list[i].state,
  589. timeType: list[i].timeType,
  590. label: timeType[list[i].timeType].label,
  591. startTime: list[i].startTime,
  592. endTime: list[i].endTime,
  593. isOvertime: flg,
  594. progress: list[i].progress,
  595. taskList: list[i].taskList,
  596. taskId: list[i].taskId,
  597. taskName:tname,
  598. professionProgress:list[i].professionProgressList,
  599. pics: list[i].pics,
  600. iospics:list[i].pics,
  601. multiWorktime:t.multiWorktime,
  602. worktimeList:list[i].worktimeList
  603. })
  604. if (list[i].state >= 2) {
  605. this.canEdit = true;
  606. } else if (list[i].state == 0) {
  607. this.canCancel = true;
  608. }
  609. }
  610. this.form.domains = array;
  611. } else {
  612. this.canCancel = false;
  613. this.canEdit = true;
  614. //没有填报的可以点击提交
  615. this.form.domains = [{
  616. id: null,
  617. projectId: "",
  618. projectName: "",
  619. workingTime: t.type==3?(t.allday).toFixed(1):"8.0",
  620. content: "",
  621. state: 2,
  622. progress:100,
  623. isOvertime:false,
  624. professionProgress:[],
  625. multiWorktime:t.multiWorktime,
  626. worktimeList:[{}]
  627. }]
  628. this.canEdit = true;
  629. }
  630. } else {
  631. toast.clear();
  632. this.$toast.fail('获取失败:'+res.msg);
  633. }
  634. }).catch(err=> {toast.clear();});
  635. },
  636. // 改变时间
  637. changeTime(time) {
  638. this.form.createDate = this.format(new Date(time),"yyyy-MM-dd");
  639. this.currentDate = time;
  640. this.showPicker = false;
  641. this.getReport();
  642. },
  643. // 选择项目
  644. clickPicker(i) {
  645. if (!this.canEdit) return;
  646. this.clickIndex = i;
  647. this.showPickerProject = true;
  648. },
  649. clickPickers(i) {
  650. if (!this.canEdit) return;
  651. this.clickIndex = i;
  652. this.showPickerProjects = true;
  653. },
  654. //选择任务
  655. clickPickerTask(i) {
  656. if (!this.canEdit) return;
  657. this.clickIndex = i;
  658. this.showPickerTask = true;
  659. },
  660. choseTask(value, index) {
  661. this.form.domains[this.clickIndex].taskId = value.taskId;
  662. this.form.domains[this.clickIndex].taskName = value.taskName;
  663. this.showPickerTask = false;
  664. },
  665. choseProjects(value, index) {
  666. // console.log(value)
  667. this.form.domains[this.clickIndex].weiduName = value.name;
  668. this.form.domains[this.clickIndex].degreeId = value.id;
  669. this.showPickerProjects = false;
  670. },
  671. choseProject(value, index) {
  672. this.form.domains[this.clickIndex].projectId = value.id;
  673. this.form.domains[this.clickIndex].projectName = value.projectName;
  674. this.showPickerProject = false;
  675. this.getTaskList(value.id);
  676. this.dimension(value.id) // 获取维度
  677. //加载项目相关的工程进度
  678. if (this.user.company.packageEngineering == 1) {
  679. this.getProjectProfessions(this.form.domains[this.clickIndex], index);
  680. }
  681. },
  682. getProjectProfessions(domain, index) {
  683. this.$axios.post("/project-profession/getMyProfession", {projectId: domain.projectId})
  684. .then(res => {
  685. if(res.code == "ok") {
  686. this.form.domains[this.clickIndex].professionProgress = res.data;
  687. this.$forceUpdate();
  688. } else {
  689. this.$toast.fail('获取失败');
  690. }
  691. }).catch(err=> {toast.clear();});
  692. },
  693. // 获取维度
  694. dimension(projectId) {
  695. this.$axios.post("/project/getDegreeList", {projectId: projectId})
  696. .then(res => {
  697. if(res.code == "ok") {
  698. this.form.domains[this.clickIndex].wuduList = res.data;
  699. this.$forceUpdate();
  700. } else {
  701. this.$toast.fail('获取失败');
  702. }
  703. }).catch(err=> {toast.clear();});
  704. },
  705. getTaskList(projectId) {
  706. //如果是专业版,需要列出任务列表
  707. if (this.user.company.packageProject == 1) {
  708. this.$axios.post("/task/getRecentTask", {projectId: projectId})
  709. .then(res => {
  710. if(res.code == "ok") {
  711. this.form.domains[this.clickIndex].taskList = res.data;
  712. this.$forceUpdate();
  713. } else {
  714. this.$toast.fail('获取失败');
  715. }
  716. }).catch(err=> {toast.clear();});
  717. }
  718. },
  719. //添加工时
  720. addNewWorktime(index, item) {
  721. item.worktimeList.push({});
  722. },
  723. // 添加项目
  724. addNewPro() {
  725. var leftProgress = 10;
  726. if (this.reportTimeType.type == 3) {
  727. //计算已经待分配工时比例
  728. let array = this.form.domains;
  729. let totalProgress = 0;
  730. for (var i=0;i<array.length; i++) {
  731. totalProgress += array[i].progress;
  732. }
  733. if (totalProgress < 100) {
  734. leftProgress = 100 - totalProgress;
  735. }
  736. }
  737. this.form.domains.push({
  738. id: null,
  739. projectId: "",
  740. projectName: "",
  741. workingTime: this.reportTimeType.type==3?(leftProgress*this.reportTimeType.allday/100).toFixed(1):"4.0",
  742. progress:leftProgress,
  743. content: "",
  744. state: 2,
  745. isOvertime:false,
  746. multiWorktime: this.reportTimeType.multiWorktime,
  747. worktimeList:[{}],
  748. degreeId: ''
  749. })
  750. },
  751. // 移除项目
  752. delPro(i) {
  753. this.$dialog.confirm({
  754. title: '',
  755. message: '是否移除当前项目'
  756. }).then(() => {
  757. this.form.domains.splice(i,1);
  758. }).catch(() => {
  759. });
  760. },
  761. // 判断时间段
  762. fns() {
  763. for (let k in this.dateAr) {
  764. if (!this.judege(k)) {
  765. return false
  766. }
  767. }
  768. return true
  769. },
  770. judege(idx){
  771. for (let k in this.dateAr) {
  772. if (idx !== k) {
  773. if (this.dateAr[k].s <= this.dateAr[idx].s && this.dateAr[k].e > this.dateAr[idx].s) {
  774. return false
  775. }
  776. if (this.dateAr[k].s < this.dateAr[idx].e && this.dateAr[k].e >= this.dateAr[idx].e) {
  777. return false
  778. }
  779. }
  780. }
  781. return true
  782. },
  783. // 提交日报
  784. register() {
  785. console.log(this.form, '看啊可能')
  786. // return
  787. this.dateAr = []
  788. let alp = []
  789. if(this.user.timeType.multiWorktime == 1) {
  790. for(var p in this.form.domains) {
  791. var slll = this.form.domains[p]
  792. for(var o in slll.worktimeList) {
  793. if(slll.worktimeList[o].startTime || slll.worktimeList[o].endTime) {
  794. let objs = {}
  795. objs.s = slll.worktimeList[o].startTime
  796. objs.e = slll.worktimeList[o].endTime
  797. alp.push(objs)
  798. }
  799. }
  800. }
  801. this.dateAr = alp
  802. if(this.dateAr.length > 0) {
  803. let trus = this.fns()
  804. if(!trus) {
  805. this.$toast('填写的时间段重叠')
  806. return
  807. }
  808. }
  809. }
  810. // return
  811. const toast = this.$toast.loading({
  812. forbidClick: true,
  813. duration: 0
  814. });
  815. let formData = new FormData();
  816. if (this.reportTimeType.type == 0) {
  817. var alldayNum = 0;
  818. var amNum = 0;
  819. var pmNum = 0;
  820. for(var i in this.form.domains) {
  821. if (this.form.domains[i].timeType == 0) {
  822. alldayNum ++;
  823. } else if (this.form.domains[i].timeType == 1) {
  824. amNum++;
  825. } else if (this.form.domains[i].timeType == 2) {
  826. pmNum++;
  827. }
  828. }
  829. if (alldayNum > 1) {
  830. this.$toast.fail("工作时间-全天,只能选择一次");
  831. return;
  832. }
  833. if (amNum > 1) {
  834. this.$toast.fail("工作时间-上午,只能选择一次");
  835. return;
  836. }
  837. if (pmNum > 1) {
  838. this.$toast.fail("工作时间-下午,只能选择一次");
  839. return;
  840. }
  841. if (alldayNum == 1 && (amNum > 0 || pmNum > 0)) {
  842. this.$toast.fail("工作时间-全天,不能和上下午同时存在");
  843. return;
  844. }
  845. } else if (this.reportTimeType.type == 3) {
  846. //总百分比不能超过100%
  847. let total = 0;
  848. this.form.domains.forEach(w=>{total += w.progress});
  849. if (total > 100) {
  850. this.$toast.fail("用时比例之和不能超过100%");
  851. return;
  852. } else if (total < 100) {
  853. this.$toast.fail("工时尚未完全分配,无法提交");
  854. return;
  855. }
  856. }
  857. //填字段
  858. for(var i in this.form.domains) {
  859. if (this.form.domains[i].id != null) {
  860. formData.append("id", this.form.domains[i].id);
  861. } else {
  862. formData.append("id", -1);
  863. }
  864. formData.append("projectId", parseFloat(this.form.domains[i].projectId));
  865. if (this.form.domains[i].subProjectId != null) {
  866. formData.append("subProjectId", this.form.domains[i].subProjectId);
  867. } else {
  868. formData.append("subProjectId", 0);
  869. }
  870. formData.append("reportTimeType", this.reportTimeType.type);
  871. formData.append("multiWorktime", this.reportTimeType.multiWorktime);
  872. if (this.reportTimeType.type == 0) {
  873. formData.append("timeType", this.form.domains[i].timeType);
  874. formData.append("workingTime", parseFloat(this.form.domains[i].workingTime));
  875. } else if (this.reportTimeType.type == 1) {
  876. formData.append("workingTime", parseFloat(this.form.domains[i].workingTime));
  877. } else if (this.reportTimeType.type == 2) {
  878. formData.append("startTime", this.form.domains[i].startTime);
  879. formData.append("endTime",this.form.domains[i].endTime);
  880. } else if (this.reportTimeType.type == 3) {
  881. formData.append("progress", this.form.domains[i].progress);
  882. formData.append("workingTime",this.form.domains[i].workingTime);
  883. }
  884. if (this.form.domains[i].taskId == null) {
  885. formData.append("taskId", 0);
  886. } else {
  887. formData.append("taskId", this.form.domains[i].taskId);
  888. }
  889. formData.append("createDate", this.form.createDate);
  890. formData.append("isOvertime", this.form.domains[i].isOvertime?1:0);
  891. //项目专业进度
  892. if (this.form.domains[i].professionProgress != null) {
  893. let m = JSON.stringify(this.form.domains[i].professionProgress);
  894. m = m.replace(/,/g,"@");//replaceAll(',','@');企业微信不兼容replaceAll
  895. formData.append("professionProgress", m);
  896. } else {
  897. formData.append("professionProgress", "[]");
  898. }
  899. //图片的处理,只处理当前通过手机拍摄的新的照片
  900. if (this.form.domains[i].serverPics!= null && this.form.domains[i].serverPics.length > 0) {
  901. let m = JSON.stringify(this.form.domains[i].serverPics);
  902. m = m.replace(/,/g,"@");//replaceAll(',','@');企业微信不兼容replaceAll
  903. formData.append("pics", m);
  904. } else {
  905. formData.append("pics", "@");
  906. }
  907. //处理多个时间事项
  908. if (this.reportTimeType.multiWorktime == 1) {
  909. //检查时间是否有重叠
  910. var workList = this.form.domains[i].worktimeList;
  911. for (var j=0;j<workList.length; j++) {
  912. var curItem = workList[j];
  913. if (curItem.startTime == null || curItem.endTime == null) {
  914. this.$toast.fail("请设置工作时间");
  915. return;
  916. }
  917. //检查开始时间是否大于结束时间
  918. if (curItem.startTime >= curItem.endTime) {
  919. this.$toast.fail("时间段"+curItem.startTime+'-'+curItem.endTime+"有误:"+
  920. "结束时间必须大于开始时间");
  921. return;
  922. }
  923. for (var p = j+1;p<workList.length; p++) {
  924. var jItem = workList[p];
  925. if ((jItem.startTime>=curItem.startTime&&jItem.startTime < curItem.endTime)
  926. || (jItem.endTime>curItem.startTime&&jItem.endTime <= curItem.endTime)) {
  927. this.$toast.fail("时间段"+curItem.startTime+'-'+curItem.endTime+"与"+
  928. jItem.startTime+'-'+jItem.endTime+ "存在重叠,请修改。");
  929. return;
  930. }
  931. }
  932. }
  933. let m = JSON.stringify(this.form.domains[i].worktimeList);
  934. m = m.replace(/,/g,"@");//replaceAll(',','@');企业微信不兼容replaceAll
  935. formData.append("content", m);
  936. } else {
  937. if (this.form.domains[i].content == null || this.form.domains[i].content == '') {
  938. formData.append("content", '-');
  939. } else {
  940. formData.append("content", this.form.domains[i].content);
  941. }
  942. }
  943. }
  944. this.$axios.post("/report/editReport", formData)
  945. .then(res => {
  946. if(res.code == "ok") {
  947. toast.clear();
  948. this.$toast.success('填报成功');
  949. this.$router.push("/index");
  950. } else {
  951. toast.clear();
  952. this.$toast.fail('填报失败');
  953. }
  954. }).catch(err=> {toast.clear();});
  955. },
  956. //初始化参数
  957. initWxConfig() {
  958. var curUrl=location.href.split("#")[0];
  959. this.$axios.post("/wxcorp/getCorpWXConfig", {url: curUrl, token: this.user.id})
  960. .then(res => {
  961. if(res.code == "ok") {
  962. var data=res.data;
  963. wx.config({
  964. beta: true,
  965. debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  966. appId: data.appid, // 必填,公众号的唯一标识
  967. timestamp: data.timestamp, // 必填,生成签名的时间戳
  968. nonceStr: data.noncestr, // 必填,生成签名的随机串
  969. signature: data.sign, // 必填,签名,见附录1
  970. jsApiList: [
  971. 'chooseImage',
  972. 'previewImage',
  973. 'uploadImage',
  974. 'downloadImage',
  975. 'previewFile',
  976. 'getLocation',
  977. ]
  978. });
  979. wx.ready(function(){
  980. // config信息验证后会执行ready方法,所有接口调用都必须在config接口获得结果之后,config是一个客户端的异步操作,所以如果需要在页面加载时就调用相关接口,则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中。
  981. console.log('企业微信初始化执行成功了。 ');
  982. });
  983. } else {
  984. this.$toast.fail('获取失败');
  985. }
  986. }).catch(err=> {this.$toast.fail('发生异常'+err);console.log(err)});
  987. }
  988. },
  989. mounted() {
  990. var ua = navigator.userAgent.toLowerCase();
  991. this.isIOSystem = this.isIOS();
  992. if (ua.indexOf("wxwork") > 0) {
  993. this.isCorpWX = true;
  994. } else if (ua.indexOf("micromessenger") > 0) {
  995. this.isWX = true;
  996. }
  997. //获取传递过来的日期
  998. var passDate = this.$route.query.date;
  999. if (passDate != null) {
  1000. this.form.createDate = this.$route.query.date;
  1001. }
  1002. this.getProject();
  1003. this.getReport();
  1004. this.getTimeType();
  1005. //初始化微信js-sdk参数
  1006. if (this.isCorpWX) {
  1007. this.initWxConfig();
  1008. }
  1009. }
  1010. };
  1011. </script>
  1012. <style lang="less" scope>
  1013. .my-swipe .van-swipe-item {
  1014. color: #fff;
  1015. font-size: 20px;
  1016. line-height: 150px;
  1017. text-align: center;
  1018. background-color: #39a9ed;
  1019. }
  1020. .van-field__control:disabled {
  1021. -webkit-text-fill-color:#646566;
  1022. }
  1023. .login_form {
  1024. margin-top: 46px;
  1025. }
  1026. .form_domains {
  1027. position: relative;
  1028. .form_copy {
  1029. position: absolute;
  1030. right: 85px;
  1031. top: 10px;
  1032. }
  1033. .form_addNew {
  1034. text-align: center;
  1035. margin:10px;
  1036. }
  1037. .form_del {
  1038. position: absolute;
  1039. right: 10px;
  1040. top: 10px;
  1041. }
  1042. // .form_del {
  1043. // color: #ff0000;
  1044. // font-size: 22px;
  1045. // position: absolute;
  1046. // right: 15px;
  1047. // top: 10px;
  1048. // }
  1049. }
  1050. .form_tip {
  1051. text-align: center;
  1052. margin-top: 20px;
  1053. color: #afafaf;
  1054. font-size: 14px;
  1055. }
  1056. .card__footer {
  1057. padding-top: 10px;
  1058. }
  1059. .card__tags {
  1060. .van-tag {
  1061. margin-right: 5px;
  1062. }
  1063. }
  1064. </style>
  1065. <style lang="less">
  1066. .van-nav-bar .van-icon , .van-nav-bar__text {
  1067. color: #20a0ff;
  1068. }
  1069. .overtime {
  1070. height: 50px;
  1071. box-sizing: border-box;
  1072. padding-left: 10px;
  1073. display: flex;
  1074. align-items: center;
  1075. }
  1076. .custom-button {
  1077. width: 40px;
  1078. color: #fff;
  1079. font-size: 10px;
  1080. line-height: 16px;
  1081. text-align: center;
  1082. background-color: #1989fa;
  1083. border-radius: 100px;
  1084. }
  1085. </style>