outside.nvue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. <template>
  2. <view class="setbox">
  3. <map
  4. id="container"
  5. class="map"
  6. :latitude="center.lat"
  7. :longitude="center.lng"
  8. :markers="covers"
  9. scale="15"
  10. :style="'width: 750rpx;height:' + mapheight + 'px;'"
  11. ></map>
  12. <view class="mapfot">
  13. <view class="txt" style="flex-direction: column;" v-if="isPhoto=='Y'">
  14. <view class="txta">
  15. <view><text class="txtaa">拍照</text></view>
  16. <image :src="photoimg" class="photoimg" @click="getphotoFn"></image>
  17. </view>
  18. <view class="imgsur" v-if="imgurlshow">
  19. <image :src='imgurlshow' class="txtimg" @click="getpreviewImage"></image>
  20. </view>
  21. </view>
  22. <view class="txt" style="align-items: flex-start;">
  23. <view><text class="txtaa">备注</text></view>
  24. <uni-easyinput class="input" :inputBorder="false" type="textarea" autoHeight v-model="chitext"
  25. placeholder="请填写原因">
  26. </uni-easyinput>
  27. </view>
  28. <view>
  29. <view class="mapfott"><text class="mapfotta">当前位置</text></view>
  30. <view class="mapfotx">
  31. <image :src="adrimg" class="mapfotxi"></image>
  32. <view class="mapfotxa"><text class="mapfotxaa" v-if="address">{{address}}</text></view>
  33. </view>
  34. </view>
  35. <view class="mapfotn" @click="getPunchFnes"><text class="mapfotna">确认打卡</text></view>
  36. </view>
  37. </view>
  38. </template>
  39. <script>
  40. import self from "@/utils/location.js"
  41. import {getRecordList,getPunchFn,getPunchputFn} from "@/api/work/check.js"
  42. import amapFile from '@/plugins/amap-wx.js';
  43. import {uploadPhoto} from "@/api/system/user.js"
  44. import config from '@/config.js'
  45. const baseUrl = config.baseUrl
  46. // #ifdef APP
  47. var myAmapFun = new amapFile.AMapWX({
  48. key: 'ccbe52b1ec5f66295fa4609c90a819b7',
  49. batch: true
  50. });
  51. // #endif
  52. export default{
  53. data(){
  54. return{
  55. serimg:require("@/work/static/clock/serch.png"),
  56. adrimg:require("@/work/static/clock/adress.png"),
  57. photoimg: require("@/work/static/clock/photo.png"),
  58. place:{
  59. lng:'',
  60. lat:'',
  61. },
  62. address:'',
  63. kaTime:'',
  64. kaYear:'',
  65. kaMonth:'',
  66. kaDay:'',
  67. kaWeek:'',
  68. gettime:'',
  69. timefn:'',
  70. isPhoto:'N',
  71. dakatype:'',
  72. recordList:[],
  73. mapheight:0,
  74. mapContext:'',
  75. covers: [{
  76. latitude: '',
  77. longitude: '',
  78. iconPath: require("@/work/static/clock/map.png"),
  79. anchor:{x: 0.5, y: 0.5}
  80. }],
  81. mapimg:require("@/work/static/clock/map.png"),
  82. center:{
  83. lng:'',
  84. lat:'',
  85. },
  86. location:'',
  87. imgurl:'',
  88. imgurlshow:'',
  89. //打卡参数
  90. formData: {
  91. "userId": '',
  92. "deptId": '',
  93. "ancestors":'',
  94. "deptName": "",
  95. "userName": "",
  96. "ancestors": "",
  97. "kaLog": "",
  98. "kaLat": "",
  99. "kaYear": "",
  100. "kaMonth": "",
  101. "kaDay": "",
  102. "kaWeek": "",
  103. "kaTime": "",
  104. "kaSort": "",
  105. "kaTimeAmIn": "", //打卡时间 -上午上班
  106. "kaTimeAmOut": "",
  107. "kaTimePmIn": "",
  108. "kaTimePmOut": "",
  109. "kaAddressAmIn": "", //打卡地点 上午上班
  110. "kaAddressAmOut": "",
  111. "kaAddressPmIn": "",
  112. "kaAddressPmOut": "",
  113. "kaTypeAmIn": "", //打卡类别-上午上班 1正常 2:迟到 3:外勤 4:早退
  114. "kaTypeAmOut": "",
  115. "kaTypesPmIn": "",
  116. "kaTypePmOut": "",
  117. "remarkAmIn": "", //备注 上午上班
  118. "remarkAmOut": "",
  119. "remarkPmIn": "",
  120. "remarkPmOut": "",
  121. "kaType": "",
  122. "kaStatus": "1", //打卡状态 1正常 2:异常
  123. },
  124. chitext:'',
  125. }
  126. },
  127. onLoad(e) {
  128. // this.isPhoto=e.isPhoto;
  129. // this.dakatype=e.dakatype;
  130. this.getcreateMap()
  131. // #ifdef H5
  132. this.center.lng=117.211954;
  133. this.center.lat=31.839676;
  134. this.covers = [];
  135. this.covers = [{
  136. latitude: '31.839676',
  137. longitude: '117.211954',
  138. iconPath: this.mapimg,
  139. anchor:{x: 0.5, y: 0.5}
  140. }]
  141. // #endif
  142. },
  143. onUnload() {
  144. clearInterval(this.timefn)
  145. },
  146. mounted() {
  147. this.formData.userId= this.$store.state.user.userId;
  148. this.formData.deptId= this.$store.state.user.deptId;
  149. this.formData.ancestors=this.$store.state.user.ancestors;
  150. this.formData.deptName=this.$store.state.user.deptName
  151. this.formData.userName=this.$store.state.user.userName
  152. this.getinfo()
  153. this.getlocation()
  154. // this.getRecordList();
  155. this.gettimeFn();
  156. },
  157. methods:{
  158. getcreateMap(){
  159. //mapId 就是你在 map 标签中定义的 id
  160. this.mapContext = uni.createMapContext('container', this);
  161. },
  162. // 获取当前屏幕信息
  163. getinfo(){
  164. var that=this;
  165. uni.getSystemInfo({
  166. success(e) {
  167. that.mapheight=e.windowHeight;
  168. },
  169. })
  170. },
  171. getCity(latitude, longitude) {
  172. var that = this;
  173. that.location = `${longitude},${latitude}`
  174. myAmapFun.getRegeo({
  175. //如果经纬度有问题会导致不进入回调方法,从而报错
  176. location: that.location,
  177. success: function(e) {
  178. //成功回调
  179. that.address='';
  180. that.address = e[0].regeocodeData.formatted_address; //详细地址
  181. },
  182. fail: function(info) {
  183. //失败回调
  184. console.log(info)
  185. }
  186. })
  187. },
  188. // 获取定位
  189. getlocation(){
  190. var that = this;
  191. uni.getLocation({
  192. type: 'gcj02',
  193. geocode: true,
  194. success: function(res) {
  195. that.center.lng=res.longitude;
  196. that.center.lat=res.latitude;
  197. that.covers = [];
  198. that.covers = [{
  199. latitude: res.latitude,
  200. longitude: res.longitude,
  201. iconPath: that.mapimg,
  202. anchor:{x: 0.5, y: 0.5}
  203. }]
  204. // #ifdef H5
  205. var adr= address.province+address.city+address.district+address.street+address.streetNum+address.poiName
  206. // that.address=res.longitude
  207. that.address=adr
  208. // #endif
  209. // #ifdef APP
  210. that.getCity(res.latitude, res.longitude)
  211. // #endif
  212. },
  213. fail: function(red) {
  214. uni.showToast({
  215. title:"获取定位失败"
  216. })
  217. },
  218. })
  219. },
  220. gettimeFn() {
  221. var that = this;
  222. that.time()
  223. that.timefn = setInterval(function() {
  224. that.time()
  225. }, 1000)
  226. },
  227. getRecordList() {
  228. var params = {
  229. deptId: this.$store.state.user.deptId,
  230. userId: this.$store.state.user.userId,
  231. kaTime: this.kaTime
  232. }
  233. getRecordList(params).then(res => {
  234. if (res.code == 200) {
  235. this.recordList=res.rows;
  236. if(res.rows.length){
  237. this.formData=res.rows[0]
  238. }
  239. } else {
  240. this.$modal.confirm(res.msg)
  241. }
  242. })
  243. // this.$toast("登录中,请耐心等待...")
  244. },
  245. // 打卡
  246. getPunchFnes(){
  247. var that=this;
  248. uni.redirectTo({
  249. url: '/work/pages/clock/success?tit=外勤打卡'
  250. });
  251. return
  252. if(that.isPhoto=='Y'&&!that.imgurl){
  253. uni.showToast({
  254. title:'请拍照上传',
  255. icon:'none'
  256. })
  257. return
  258. }
  259. var params=this.formData;
  260. params.kaTime=this.kaTime;
  261. params.kaYear=this.kaYear;
  262. params.kaMonth=this.kaMonth;
  263. params.kaDay=this.kaDay;
  264. params.kaWeek=this.kaWeek;
  265. params.deptName=this.$store.state.user.deptName
  266. params.userName=this.$store.state.user.name
  267. params.kaStatus=2
  268. var imgurl=this.imgurl;
  269. if(this.dakatype==1){
  270. params.kaTimeAmIn=this.gettime;
  271. params.kaAddressAmIn=this.address;
  272. params.kaAmInPhoto=imgurl;
  273. params.kaTypeAmIn=3
  274. params.kaSort=1;
  275. }else if(this.dakatype==2){
  276. params.kaSort=2;
  277. params.kaTimeAmOut=this.gettime;
  278. params.kaAddressAmOut=this.address;
  279. params.kaTypeAmOut=3
  280. params.kaAmOutPhoto=imgurl;
  281. }else if(this.dakatype==3){
  282. params.kaSort=3;
  283. params.kaTypePmIn=3
  284. params.kaTimePmIn=this.gettime;
  285. params.kaAddressPmIn=this.address;
  286. params.kaPmInPhoto=imgurl;
  287. }else{
  288. params.kaSort=4;
  289. params.kaTypePmOut=3
  290. params.kaTimePmOut=this.gettime;
  291. params.kaAddressPmOut=this.address;
  292. params.kaPmOutPhoto=imgurl;
  293. }
  294. if (this.recordList.length) {
  295. var len = this.recordList.length - 1
  296. params["recordId"] = this.recordList[0].recordId;
  297. // // 覆盖打卡
  298. getPunchputFn(params).then(res => {
  299. if (res.code == 200) {
  300. // 打卡成功
  301. // this.getRecordList()
  302. uni.redirectTo({
  303. url: '/work/pages/clock/success?tit=外勤打卡'
  304. });
  305. } else {
  306. this.$toast(res.msg)
  307. }
  308. })
  309. } else {
  310. params["recordId"] = '';
  311. getPunchFn(params).then(res => {
  312. if (res.code == 200) {
  313. // 打卡成功
  314. // this.getRecordList()
  315. uni.redirectTo({
  316. url: '/work/pages/clock/success?tit=外勤打卡'
  317. });
  318. } else {
  319. that.$modal.msgError(res.msg)
  320. }
  321. })
  322. }
  323. },
  324. time() {
  325. var date = new Date();
  326. var y = date.getFullYear();
  327. var m = date.getMonth() + 1;
  328. var d = date.getDate();
  329. var h = date.getHours();
  330. var min = date.getMinutes();
  331. var s = date.getSeconds();
  332. var week = date.getDay(); //获取当前星期X(0-6,0代表星期天)
  333. var weeks = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
  334. var yearStr = y + '-' + (m < 10 ? ('0' + m) : m) + '-' + (d < 10 ? ('0' + d) : d)
  335. var timeStr = (h < 10 ? ('0' + h) : h) + ':' + (min < 10 ? ('0' + min) : min) + ':' + (s < 10 ? (
  336. '0' + s) : s);
  337. this.kaTime = yearStr;
  338. this.kaYear = y;
  339. this.kaMonth = m < 10 ? "0" + m : m;
  340. this.kaDay = d < 10 ? "0" + d : d;
  341. this.kaWeek = week;
  342. this.gettime = timeStr
  343. // 年,月,日, 星期几 时分秒
  344. },
  345. getpreviewImage(e){
  346. var urlArr=[];
  347. urlArr[0]=this.imgurlshow;
  348. uni.previewImage({
  349. urls: urlArr,
  350. success: function(data) {
  351. console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
  352. },
  353. fail: function(err) {
  354. console.log(err.errMsg);
  355. }
  356. });
  357. },
  358. // 拍照
  359. getphotoFn(){
  360. var that=this;
  361. uni.chooseImage({
  362. count: 1, //默认9
  363. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  364. sourceType: ['camera'], //拍照
  365. success: function (res) {
  366. const tempFilePaths = res.tempFilePaths;
  367. // 文件上传
  368. let data = {name: 'file', filePath: res.tempFilePaths[0]}
  369. uploadPhoto(data).then(response => {
  370. that.imgurlshow=baseUrl+response.fileName;
  371. that.imgurl=response.fileName;
  372. // if(!that.chiflag){
  373. // that.getPunchFnes()
  374. // }
  375. })
  376. }
  377. });
  378. },
  379. }
  380. }
  381. </script>
  382. <style lang="scss" scoped>
  383. // .maptop{width:684rpx;height: 84rpx;background: #FFFFFF;box-shadow: 0px 0px 12rpx 0px rgba(75,75,75,0.35);border-radius: 6rpx;position: fixed;left: 34rpx;right: 34rpx;top: 24rpx;display: flex;align-items: center;padding: 0 32rpx;box-sizing: border-box;
  384. // image{width: 36rpx;height: 38rpx;margin-right: 16rpx;flex: 0 0 auto;}
  385. // input{font-size: 26rpx;color: #666666;flex: 1;}
  386. // }
  387. .mapfot /deep/ .uni-easyinput__content-textarea{min-height: 84rpx;margin: 0;}
  388. .mapfot{position: fixed;left: 34rpx;right: 34rpx;bottom: 24rpx;background: #FFFFFF;
  389. box-shadow: 0px 0px 12rpx 0px rgba(75,75,75,0.35);
  390. border-radius: 6rpx;padding: 40rpx 32rpx 32rpx;min-height:300rpx;}
  391. .mapfott{margin-bottom: 28rpx;}
  392. .mapfotta{font-size: 28rpx;font-weight: bold;color: #343434;}
  393. .mapfotx{display: flex;margin-bottom: 32rpx;flex-direction: row;min-height: 70rpx;}
  394. .mapfotxi{width: 26rpx;height: 28rpx;flex: 0 0 auto;margin-right: 12rpx;}
  395. .mapfotxa{flex: 1;line-height: 32rpx;}
  396. .mapfotxaa{font-size: 26rpx;color: #343434;}
  397. .photoimg{width: 46rpx;height: 40rpx;}
  398. .txta{display: flex;align-items: center;width: 610rpx;justify-content: space-between;margin-bottom: 20rpx;flex-direction: row;}
  399. .imgsur{width: 100%;padding-left: 80rpx;}
  400. .txtimg{width: 80rpx;height: 80rpx;margin: 0 12rpx 12rpx 0;}
  401. .mapfotn{width: 610rpx;height:76rpx;background: #1678ff;border-radius: 6rpx;display: flex;align-items: center;justify-content: center;}
  402. .mapfotna{font-size: 28rpx;color: #FFFFFF;}
  403. .txt {
  404. display: flex;
  405. align-items: center;
  406. margin-bottom: 28rpx;
  407. flex-direction: row;
  408. }
  409. .txtaa {font-size: 28rpx;color: #343434;font-weight: bold;flex: 0 0 auto;margin-right: 20rpx;}
  410. .input {font-size: 28rpx;flex: 1;text-align: right;}
  411. </style>