signIn.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <template>
  2. <view class="signIn-wrap">
  3. <!-- 门店名称 -->
  4. <view class="module-con first-con">
  5. <text class="info-tit">门店名称:</text>
  6. <view class="info-main">
  7. <text class="location-addr">{{ stores && stores.name }}</text>
  8. </view>
  9. </view>
  10. <!-- 定位 -->
  11. <view class="module-con">
  12. <text class="info-tit">当前位置:</text>
  13. <view class="info-main" @click="getLocation">
  14. <text class="location-addr">{{ location }}</text>
  15. <u-icon name="map" color="#2979ff" size="34" class="location-icon"></u-icon>
  16. </view>
  17. </view>
  18. <!-- 拍照签到 -->
  19. <view class="module-con">
  20. <text class="info-tit">拍照签到:</text>
  21. <view class="info-main">
  22. <view class="photograph-con" @click="photograph ? null : goPhotograph()">
  23. <u-icon v-show="photograph" name="close-circle-fill" color="#fa3534" size="50" class="close-circle-icon" @click="cancelPhotograph"></u-icon>
  24. <u-icon v-show="!photograph" name="camera" color="#bfbfbf" size="60" class="photograph-icon"></u-icon>
  25. <u-image v-show="photograph" width="100%" height="100%" :src="photograph" @click="previewPictures"></u-image>
  26. </view>
  27. </view>
  28. </view>
  29. <u-button type="primary" class="submit-btn" @click="signInFun">签到并开始巡店</u-button>
  30. </view>
  31. </template>
  32. <script>
  33. import { clzConfirm, saveImgToAliOss } from '@/libs/tools.js';
  34. import { validTaskPosition } from '@/api/task.js';
  35. export default {
  36. data() {
  37. return {
  38. stores: null, // 门店信息
  39. location: '', // 当前位置地址
  40. photograph: '', // 拍照临时地址
  41. position: null // 位置信息
  42. };
  43. },
  44. onShow() {
  45. this.init();
  46. },
  47. onLoad(opts) {
  48. this.stores = JSON.parse(opts.item);
  49. },
  50. methods: {
  51. // 初始化
  52. init() {
  53. this.getLocation();
  54. },
  55. // 获取当前位置
  56. getLocation() {
  57. const _this = this;
  58. uni.getLocation({
  59. type: 'gcj02',
  60. geocode: true,
  61. success: function(res) {
  62. console.log(res);
  63. _this.position = res;
  64. _this.location = res.address.province + res.address.city + res.address.district + res.address.street + res.address.streetNum +'靠近' + res.address.poiName
  65. // console.log(_this.location, '城市编码 ', res.address.cityCode)
  66. },
  67. fail: function(error){
  68. console.log(error)
  69. if(JSON.parse(error.errMsg.replace('getLocation:fail ','')).message){
  70. uni.showToast({
  71. icon: 'none',
  72. title: JSON.parse(error.errMsg.replace('getLocation:fail ','')).message
  73. })
  74. }
  75. }
  76. });
  77. },
  78. // 签到拍照
  79. goPhotograph() {
  80. const _this = this;
  81. uni.chooseImage({
  82. count: 1, //最多可以选择的图片张数,默认9
  83. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  84. sourceType: ['camera'], //album 从相册选图,camera 使用相机,默认二者都有
  85. success: function(res) {
  86. // tempFilePaths 图片的本地文件路径列表,tempFiles 图片的本地文件列表,每一项是一个 File 对象
  87. console.log(JSON.stringify(res.tempFilePaths));
  88. saveImgToAliOss(res.tempFilePaths[0],function(ret){
  89. console.log(ret)
  90. _this.photograph = ret.data
  91. })
  92. }
  93. });
  94. },
  95. // 预览签到图
  96. previewPictures() {
  97. const photograph = [this.photograph];
  98. uni.previewImage({
  99. urls: photograph
  100. });
  101. },
  102. // 删除签到图
  103. cancelPhotograph() {
  104. setTimeout(() => {
  105. this.photograph = '';
  106. }, 500);
  107. },
  108. // 签到
  109. signInFun() {
  110. if(!this.position || !this.position.latitude || !this.position.longitude){
  111. uni.showToast({ icon: 'none', title: '位置获取失败,请重新定位后再进行签到' })
  112. return
  113. }else if(!this.photograph){
  114. uni.showToast({ icon: 'none', title: '请拍照后再进行签到' })
  115. return
  116. }
  117. // 存储当前签到信息
  118. this.$u.vuex('vuex_sceneTaskSignIn',{
  119. inspectorPositionAddr: '',
  120. inspectorPositionPhotoBasePath:'',
  121. inspectorPositionPhotoPath: this.photograph
  122. })
  123. // 判断是否超出签到范围
  124. validTaskPosition({
  125. storeId: this.stores.id,
  126. point: {
  127. lat: this.position.latitude,
  128. lng: this.position.longitude,
  129. }
  130. }).then(res => {
  131. if (res.status == 200) {
  132. // 跳转开始巡店
  133. let item = this.stores
  134. // 重新开始巡店
  135. if(item.taskId&&item.restart){
  136. uni.navigateTo({
  137. url: '/pages/shopTour/shopTour?storeId=' + item.id + '&taskId='+ item.taskId + '&restart=1&types=scene'
  138. })
  139. }else{
  140. // 首次巡店
  141. uni.navigateTo({
  142. url: '/pages/shopTour/shopTour?storeId=' + item.id + '&types=scene'
  143. })
  144. }
  145. } else {
  146. uni.showToast({ icon: 'none', title: res.message })
  147. }
  148. });
  149. },
  150. }
  151. };
  152. </script>
  153. <style lang="scss" scoped>
  154. page {
  155. background-color: #f8f8f8;
  156. height: calc(100vh - 44px);
  157. }
  158. .signIn-wrap {
  159. height: 100%;
  160. background-color: #f8f8f8;
  161. .module-con {
  162. padding: 0 30upx 20upx;
  163. .info-main {
  164. margin-top: 14upx;
  165. padding: 20upx;
  166. border-radius: 12upx;
  167. background-color: #fff;
  168. .location-icon {
  169. padding-left: 10upx;
  170. vertical-align: bottom;
  171. }
  172. .photograph-con {
  173. border: 2upx dashed #bfbfbf;
  174. border-radius: 12upx;
  175. width: 160upx;
  176. height: 160upx;
  177. text-align: center;
  178. position: relative;
  179. .photograph-icon {
  180. display: inline-block;
  181. padding-top: 48upx;
  182. }
  183. .close-circle-icon {
  184. background-color: #fff;
  185. border-radius: 50%;
  186. position: absolute;
  187. right: -23upx;
  188. top: -23upx;
  189. z-index: 9;
  190. }
  191. }
  192. }
  193. }
  194. .first-con {
  195. padding-top: 30upx;
  196. }
  197. .submit-btn {
  198. width: 80%;
  199. margin-top: 50upx;
  200. }
  201. }
  202. </style>