the_clock.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. <template>
  2. <view>
  3. <view class='wrap'>
  4. <view class="c-row">
  5. <view class="title">打卡原因</view>
  6. <view style='padding:0;' class="con-list">
  7. <u-radio-group activeColor="#22C572" v-model="typevalue">
  8. <u-radio key="3" label="下班" name="3">下班</u-radio>
  9. <u-radio key="1" label="上班" name="1">上班</u-radio>
  10. </u-radio-group>
  11. </view>
  12. </view>
  13. <view class="c-row">
  14. <view class="title">目标位置</view>
  15. <view class="con-list">
  16. <view @click='show=true'>{{detailData.targetLocation}}</view>
  17. <u-picker :range="warehouseBaseInfoList" range-key="warehouseName" @confirm='targetLPicker($event)'
  18. v-model="show" mode="selector">
  19. </u-picker>
  20. </view>
  21. </view>
  22. <view class="c-row">
  23. <view class="title">打卡距离</view>
  24. <view class="con-list">
  25. <view>{{clockDistance}}</view>
  26. </view>
  27. </view>
  28. </view>
  29. <view>
  30. </view>
  31. <!-- <view class="footer">
  32. <view @click='clockRecord' class="button">记录</view>
  33. <view @click='submit' class="button">提交</view>
  34. </view> -->
  35. <u-toast ref="uToast" />
  36. <view class="bottom-btn">
  37. <u-button type="primary" class="submit" hover-class="none" @click="clockRecord">记录</u-button>
  38. <u-button type="primary" class="submit" hover-class="none" @click="submit">提交</u-button>
  39. </view>
  40. </view>
  41. </template>
  42. <script>
  43. export default {
  44. data() {
  45. return {
  46. typevalue: '1',
  47. show: false,
  48. detailData: {
  49. compId: '',
  50. clockType: '',
  51. otherReasons: '',
  52. targetLocation: '请选择目标位置',
  53. clockDistance: '重新获取',
  54. },
  55. clockDistance: "",
  56. warehouseType: '1',
  57. warehouseBaseInfoList: [],
  58. }
  59. },
  60. onLoad() {
  61. if(uni.getStorageSync("clockwerehouse")){
  62. this.detailData.targetLocation=uni.getStorageSync("clockwerehouse")
  63. }
  64. this.getWarehouse()
  65. this.getLocation()
  66. },
  67. methods: {
  68. calculate() {
  69. const query = uni.createSelectorQuery().in(this);
  70. query.selectAll('.left')
  71. console.log(query)
  72. },
  73. getWarehouse() {
  74. var that = this
  75. uni.showLoading({
  76. title: "正在加载"
  77. })
  78. this.$api.doRequest('get', '/warehouseBaseInfo/selectWarehouse', {
  79. compId: uni.getStorageSync("pcUserInfo").compId,
  80. warehouseType: '1'
  81. }).then(res => {
  82. if (res.data.data.length != 0) {
  83. that.warehouseBaseInfoList = res.data.data
  84. uni.getLocation({
  85. type: 'gcj02',
  86. geocode: true,
  87. success: function(res) {
  88. console.log('获取位置数据:', res);
  89. console.log('当前位置的经度:' + res.longitude);
  90. console.log('当前位置的纬度:' + res.latitude);
  91. that.lat2 = res.latitude
  92. that.lng2 = res.longitude
  93. if (that.warehouseBaseInfoList.length > 0) {
  94. if(that.detailData.targetLocation){
  95. for(var i = 0 ; i < that.warehouseBaseInfoList.length ; i++){
  96. if(that.warehouseBaseInfoList[i].warehouseName==that.detailData.targetLocation){
  97. that.clockDistance = that.utils.getDistance(that
  98. .warehouseBaseInfoList[i].warehousePositioning.split(',')[
  99. 0],
  100. that.warehouseBaseInfoList[i].warehousePositioning.split(
  101. ',')[1], that.lat2, that.lng2)
  102. }
  103. }
  104. }
  105. else{
  106. that.clockDistance = that.utils.getDistance(that
  107. .warehouseBaseInfoList[0].warehousePositioning.split(',')[
  108. 0],
  109. that.warehouseBaseInfoList[0].warehousePositioning.split(
  110. ',')[1], that.lat2, that.lng2)
  111. that.detailData.targetLocation = that.warehouseBaseInfoList[0].warehouseName
  112. }
  113. }
  114. },
  115. fail: function(req) {
  116. console.log(req)
  117. }
  118. });
  119. }
  120. uni.hideLoading()
  121. })
  122. },
  123. targetLPicker(e) {
  124. uni.setStorageSync("clockwerehouse",this.warehouseBaseInfoList[e[0]].warehouseName)
  125. this.detailData.targetLocation = this.warehouseBaseInfoList[e[0]].warehouseName
  126. this.clockDistance = this.utils.getDistance(this.warehouseBaseInfoList[e[0]].warehousePositioning.split(
  127. ',')[0],
  128. this.warehouseBaseInfoList[e[0]].warehousePositioning.split(',')[1], this.lat2, this.lng2)
  129. },
  130. submit() {
  131. if (!this.typevalue) {
  132. this.$api.msg('打卡原因不能为空')
  133. return
  134. }
  135. if (!this.detailData.targetLocation) {
  136. this.$api.msg('请选择目标位置')
  137. return
  138. }
  139. var that = this
  140. uni.showModal({
  141. content: "确定提交打卡信息?",
  142. showCancel: true,
  143. confirmText: '提交',
  144. success: function(res) {
  145. if (res.confirm) {
  146. that.detailData.compId = uni.getStorageSync('pcUserInfo').compId
  147. that.detailData.commonId = uni.getStorageSync('pcUserInfo').userId
  148. that.detailData.dept = uni.getStorageSync('pcUserInfo').deptName
  149. that.detailData.phone = uni.getStorageSync('pcUserInfo').userMobilePhone
  150. that.detailData.empName = uni.getStorageSync('userInfo').userName
  151. that.detailData.clockType = that.typevalue
  152. if(that.clockDistance.indexOf("km") > -1){
  153. that.detailData.clockDistance = that.clockDistance.replace("km","")*1000
  154. }else{
  155. that.detailData.clockDistance = that.clockDistance.replace("m","")
  156. }
  157. console.log(that.detailData)
  158. // if(that.detailData.clockDistance > 2000){
  159. // that.$api.msg('请在目标位置2km范围内进行打卡')
  160. // return
  161. // }else{
  162. that.$api.doRequest('post', '/clockInfo/api/addClock', that.detailData)
  163. .then(res => {
  164. console.log(res.data)
  165. if (res.data.code == 200) {
  166. that.$api.msg('提交成功')
  167. } else if(res.data.message == '上班时间未打卡'){
  168. that.$api.msg(res.data.message)
  169. }
  170. else{
  171. that.$api.msg('提交失败')
  172. }
  173. })
  174. // }
  175. }
  176. }
  177. })
  178. },
  179. clockRecord() {
  180. uni.navigateTo({
  181. url: '/pages/clock/the_clock_record'
  182. })
  183. },
  184. },
  185. }
  186. </script>
  187. <style lang='scss' scoped>
  188. page {
  189. background: #F5F6FA;
  190. }
  191. .title_b {
  192. margin: 20rpx 20rpx 0rpx 20rpx;
  193. padding: 20rpx 10rpx 20rpx 10rpx;
  194. font-size: 18px;
  195. font-weight: 550;
  196. }
  197. .c-row {
  198. display: -webkit-box;
  199. display: -webkit-flex;
  200. display: flex;
  201. -webkit-box-align: center;
  202. -webkit-align-items: center;
  203. align-items: center;
  204. padding: 20rpx 30rpx;
  205. position: relative;
  206. }
  207. .con-list {
  208. -webkit-box-flex: 1;
  209. -webkit-flex: 1;
  210. flex: 1;
  211. display: -webkit-box;
  212. display: -webkit-flex;
  213. display: flex;
  214. -webkit-box-orient: vertical;
  215. -webkit-box-direction: normal;
  216. -webkit-flex-direction: column;
  217. flex-direction: column;
  218. color: #303133;
  219. line-height: 40rpx;
  220. text-align: right;
  221. padding-right: 20rpx;
  222. }
  223. .wrap {
  224. padding-bottom: 10px;
  225. font-size: 14px;
  226. background: #fff;
  227. margin: 10px;
  228. border-radius: 10px;
  229. input {
  230. font-size: 14px;
  231. }
  232. >.title {
  233. padding: 10px 16px;
  234. }
  235. }
  236. /* .footer {
  237. background: #fff;
  238. position: fixed;
  239. bottom: 0;
  240. width: 100%;
  241. padding: 20px 10px;
  242. z-index: 10;
  243. .button {
  244. background: #22C572;
  245. width: 90%;
  246. margin: 20rpx auto;
  247. padding: 10px;
  248. color: #fff;
  249. text-align: center;
  250. border-radius: 30px;
  251. }
  252. } */
  253. .submit {
  254. width: 40%;
  255. background: #22C572;
  256. border-radius: 10rpx;
  257. }
  258. .bottom-btn {
  259. padding: 30rpx;
  260. background: #FFFFFF;
  261. width: 100%;
  262. position: fixed;
  263. bottom: 0rpx;
  264. display: flex;
  265. z-index: 9999;
  266. }
  267. .buns_item {
  268. display: flex;
  269. padding: 80rpx 0 50rpx 0;
  270. justify-content: space-around;
  271. }
  272. .but_css {
  273. background: #22C572;
  274. width: 40%;
  275. padding: 20rpx;
  276. color: #fff;
  277. text-align: center;
  278. border-radius: 20rpx;
  279. }
  280. /deep/.u-radio-group {
  281. flex-direction: row-reverse;
  282. }
  283. </style>