clockDetail.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. <template>
  2. <view class="clock-details">
  3. <view class="clock-details__header">
  4. <view class="clock-details__title">
  5. <uni-icons type="location-filled" color="#fff"></uni-icons>
  6. <view class="text">
  7. {{address || '暂未获取到具体地址'}}
  8. </view>
  9. </view>
  10. <view class="clock-details__title fixed-width" @click="updateCurrentLocation">
  11. <uni-icons :type="isPendingLocation?'spinner-cycle':'loop'" color="#fff"></uni-icons>
  12. <view class="text">
  13. 重新定位
  14. </view>
  15. </view>
  16. </view>
  17. <view class="clock-details__body">
  18. <view class="clock-details__img-container">
  19. <view class="clock-details__imgs">
  20. <view class="clock-details__img" v-for="item,index in urllist" :key="index+item">
  21. <view class="icon" @click="handleRemove(index)">
  22. <u-icon name="close" color="#fff"></u-icon>
  23. </view>
  24. <image :src="baseUrl+item" mode="aspectFit" class="img"></image>
  25. </view>
  26. <view class="clock-details__upload" @click="chooseImage" v-if="urllist.length<3">
  27. <u-icon size="20" name="plus" color="#409eff"></u-icon>
  28. </view>
  29. </view>
  30. </view>
  31. <view class="clock-details__area">
  32. <view class="clock-details__edit-icon" v-if="!isEdit" @click="isEdit=!isEdit">
  33. <uni-icons type="compose" color="#1B76FF"></uni-icons>
  34. </view>
  35. <u--textarea :focus="true" v-else v-model="message" placeholder="" :maxlength="200" autoHeight
  36. border="none">
  37. </u--textarea>
  38. </view>
  39. </view>
  40. <view class="clock-details__footer">
  41. <u-button type="primary" text="签到" @click="handleClockInSubmit"></u-button>
  42. </view>
  43. <!-- <ksp-image-cutter @ok="onok" @cancel="oncancle" :url="kpsurlL" :fixed="false" :blob="false" :maxWidth="500"
  44. :maxHeight="500"></ksp-image-cutter> -->
  45. <u-loading-page loading-text="加载中..." :loading="loading" font-size="16"></u-loading-page>
  46. </view>
  47. </template>
  48. <script>
  49. import * as taskService from '@/service/task.js';
  50. import {
  51. Debounce
  52. } from "@/util/anitthro.js";
  53. import {
  54. pullAt
  55. } from 'lodash-es';
  56. export default {
  57. data() {
  58. return {
  59. isEdit: false,
  60. // latitude: 39.909,
  61. // longitude: 116.39742,
  62. latitude: 0,
  63. longitude: 0,
  64. address: '',
  65. taskID: '',
  66. message: "",
  67. logs: [],
  68. kpsurlL: '',
  69. urllist: [],
  70. loading: false,
  71. isPendingLocation: false,
  72. };
  73. },
  74. onLoad(options) {
  75. console.warn('clock detail ', options)
  76. this.message = '';
  77. this.urllist = [];
  78. this.taskID = options.taskID;
  79. },
  80. mounted() {
  81. console.log('mounted clock detail')
  82. this.updateCurrentLocation();
  83. },
  84. methods: {
  85. updateCurrentLocation() {
  86. console.log('updateCurrentLocation ')
  87. if (this.isPendingLocation) {
  88. return
  89. }
  90. this.isPendingLocation = true;
  91. uni.getLocation({
  92. type: 'gcj02',
  93. // altitude: true, // 高度
  94. geocode: true,
  95. success: (res) => {
  96. console.warn(res, 'get location')
  97. console.log('当前位置的经度1:' + res.longitude);
  98. console.log('当前位置的纬度1:' + res.latitude);
  99. this.logs.push(`center-position:当前位置的经度${res.longitude};当前位置的纬度${res.latitude}`)
  100. this.latitude = res.latitude;
  101. this.longitude = res.longitude;
  102. if (res.address) {
  103. const {
  104. country,
  105. province,
  106. city,
  107. district,
  108. street,
  109. streetNum,
  110. poiName
  111. } = res.address || {};
  112. this.address = province + city + district + street + streetNum + poiName;
  113. }
  114. },
  115. fail(err) {
  116. console.warn(err, 'get location error')
  117. },
  118. complete: () => {
  119. console.log('complete get location')
  120. this.isPendingLocation = false;
  121. }
  122. });
  123. },
  124. validate() {
  125. if (!this.address) {
  126. throw new Error('请重新获取下定位信息');
  127. }
  128. if (!this.taskID) {
  129. throw new Error('请返回重新进行打卡操作');
  130. }
  131. if (!this.latitude && !this.longitude) {
  132. throw new Error('请重新获取下定位信息');
  133. }
  134. if (!this.urllist.length) {
  135. throw new Error('请先拍摄图片再进行打卡');
  136. }
  137. if (!this.message) {
  138. throw new Error('请输入内容');
  139. }
  140. },
  141. // 签到提交
  142. handleClockInSubmit() {
  143. try {
  144. this.validate();
  145. } catch (error) {
  146. return uni.$u.toast(error.message);
  147. }
  148. this.loading = true;
  149. console.log(this.urllist, '------------- clock in submit')
  150. const payload = {
  151. task_id: this.taskID,
  152. message: this.message,
  153. img_list: JSON.stringify(this.urllist),
  154. address: this.address,
  155. lng: this.longitude,
  156. lat: this.latitude
  157. }
  158. console.warn(payload, 'clock in data');
  159. taskService.addTaskClockInData(payload).then(res => {
  160. uni.$u.toast('打卡成功');
  161. // TODO 返回上一页
  162. setTimeout(() => {
  163. uni.switchTab({
  164. url: '/pages/index/index'
  165. })
  166. })
  167. }).finally(() => {
  168. this.loading = false;
  169. })
  170. },
  171. chooseImage() {
  172. uni.chooseImage({
  173. count: 1, //默认9
  174. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  175. sourceType: ['camera', 'album'], //从相册选择
  176. success: (res) => {
  177. console.log(res)
  178. // this.urllist.push(res.tempFilePaths[0])
  179. // this.kpsurlL = res.tempFilePaths[0]
  180. this.onok({path:res.tempFilePaths[0]})
  181. }
  182. });
  183. },
  184. handleRemove(index) {
  185. console.log(index, 'handle remove', this.urllist)
  186. if (index !== undefined) {
  187. // pullAt(this.urllist, index)
  188. this.urllist.splice(index, 1)
  189. console.log(this.urllist, 'remove finished ')
  190. }
  191. },
  192. oncancle() {
  193. this.kpsurlL = ""
  194. },
  195. onok(ev) {
  196. this.loading = true;
  197. Debounce(() => {
  198. uni.uploadFile({
  199. url: this.baseUrl +
  200. '/api/api_gateway?method=monitor_manage.cbd_manage.add_img', //仅为示例,非真实的接口地址
  201. filePath: ev.path,
  202. name: 'img_file',
  203. success: (uploadFileRes) => {
  204. console.log(JSON.parse(uploadFileRes.data).data.src)
  205. this.urllist.push(JSON.parse(uploadFileRes.data).data.src)
  206. console.log(this.urllist, ' upload file')
  207. this.kpsurlL = ""
  208. this.loading = false;
  209. },
  210. complete() {
  211. console.log('上传完成 1355566')
  212. this.loading = false;
  213. }
  214. });
  215. }, 1000)()
  216. },
  217. }
  218. }
  219. </script>
  220. <style lang="scss" scoped>
  221. .clock-details {
  222. &__header {
  223. height: 320rpx;
  224. display: flex;
  225. justify-content: space-between;
  226. align-items: flex-start;
  227. background-image: url(~@/static/image/task/clock.png);
  228. background-size: 100%;
  229. background-repeat: no-repeat;
  230. }
  231. &__title {
  232. // width: 0;
  233. flex: 1 1 auto;
  234. padding: 48rpx 24rpx;
  235. display: flex;
  236. align-items: flex-start;
  237. font-size: 12px;
  238. line-height: 18px;
  239. color: #FFFFFF;
  240. .text {
  241. margin-left: 10rpx;
  242. }
  243. &.fixed-width {
  244. width: 140rpx;
  245. flex: 0 0 auto;
  246. }
  247. }
  248. &__upload {
  249. width: 144rpx;
  250. height: 144rpx;
  251. border: 1px dashed #409eff;
  252. display: flex;
  253. justify-content: space-around;
  254. margin-left: 32rpx;
  255. margin-bottom: 30rpx;
  256. }
  257. &__img-container {
  258. border-bottom: 1px solid rgba(151, 151, 151, 0.09);
  259. // @include hairline-bottom(rgba(151, 151, 151, 0.09));
  260. }
  261. &__imgs {
  262. position: relative;
  263. display: flex;
  264. flex-wrap: wrap;
  265. align-items: center;
  266. padding: 40rpx 0;
  267. margin-left: -32rpx;
  268. }
  269. &__img {
  270. flex: 0 0 auto;
  271. width: 198rpx;
  272. height: 198rpx;
  273. margin-left: 32rpx;
  274. margin-bottom: 30rpx;
  275. position: relative;
  276. .img {
  277. width: 100%;
  278. height: 100%;
  279. }
  280. .icon {
  281. position: absolute;
  282. top: -20rpx;
  283. right: -20rpx;
  284. z-index: 9;
  285. width: 40rpx;
  286. height: 40rpx;
  287. border-radius: 50%;
  288. display: flex;
  289. justify-content: space-around;
  290. background-color: red;
  291. }
  292. }
  293. &__body {
  294. min-height: 600rpx;
  295. padding: 0 24rpx;
  296. margin: -156rpx 24rpx 0;
  297. border-radius: 16rpx;
  298. background-color: #fff;
  299. }
  300. &__area {
  301. font-size: 12px;
  302. line-height: 18px;
  303. color: #656565;
  304. font-weight: 400;
  305. }
  306. &__edit-icon {
  307. padding: 24rpx 0;
  308. }
  309. &__footer {
  310. position: fixed;
  311. left: 76rpx;
  312. right: 76rpx;
  313. bottom: 110rpx;
  314. }
  315. }
  316. </style>
  317. <style>
  318. page {
  319. background: #F7F8FB;
  320. }
  321. </style>