spotCheck.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. <template>
  2. <view>
  3. <web-view @message="onmessage" src="/hybrid/html/ddvideo.html"></web-view>
  4. </view>
  5. </template>
  6. <script>
  7. import { clzConfirm,saveBase64ToAliOss } from '@/libs/tools'
  8. import {getTaskDetail,savePointTask} from '@/api/task'
  9. import {getTaskTargetById} from '@/api/taskTarget'
  10. import { photoPaiZhao, getVideoUrl } from '@/api/store';
  11. export default {
  12. data() {
  13. return {
  14. wv: null,
  15. isClose: false, // 是否关闭当前窗口
  16. isEditImg: false, // 是否正在编辑图片
  17. showPz: false, // 是否正在拍照
  18. types: 'video', // 巡店类型,video,scene
  19. taskId: '', // 任务id
  20. storeId: '', // 门店id
  21. storeName: '',// 门店名称
  22. };
  23. },
  24. methods: {
  25. // 监听html页面事件
  26. onmessage(event) {
  27. let data = event.detail.data[0]
  28. // console.log(data)
  29. if(data.action == 'toast'){
  30. uni.showToast({
  31. icon:'none',
  32. title: data.msg
  33. })
  34. }
  35. // webview 窗口传过来的页面状态
  36. if(data.action == 'getWinStatus'){
  37. let d = JSON.parse(data.msg)
  38. this[d.key] = d.val
  39. }
  40. // 获取视频地址
  41. if(data.action == 'getVideoUrl'){
  42. this.getStoreVideoUrl(JSON.parse(data.msg))
  43. }
  44. // 抓拍图片
  45. if(data.action == 'takePhotos'){
  46. this.takePhotos(JSON.parse(data.msg))
  47. }
  48. // 保存编辑后的图片
  49. if(data.action == 'saveEditImg'){
  50. this.uploadImg(data.msg)
  51. }
  52. // 删除图片
  53. if(data.action == 'delImgs'){
  54. this.delImgs(data.msg)
  55. }
  56. // 提交巡店
  57. if(data.action == 'submitTask'){
  58. this.submitTask(JSON.parse(data.msg))
  59. }
  60. },
  61. // 删除图片
  62. delImgs(index){
  63. const _this = this;
  64. clzConfirm({
  65. title: '提示',
  66. content: '确定删除此图片,删除后无法恢复?',
  67. success: function(res) {
  68. if (res.confirm || res.index == 0) {
  69. _this.wv.evalJS("vm.delImgsSuccess("+index+")")
  70. }
  71. }
  72. });
  73. },
  74. // 拍照截图,data.type 1 是列表按钮触发的,2 是弹框里触发的
  75. takePhotos(data){
  76. if(data.videoPlayerStatus == 'playing'){
  77. uni.showLoading({
  78. mask: true,
  79. title: '正在抓拍图片...'
  80. })
  81. photoPaiZhao({streamId:data.streamId}).then(res=>{
  82. console.log(res)
  83. if(res.data){
  84. this.wv.evalJS("vm.takePhotoSuccess('"+res.data.url+"')")
  85. }else{
  86. uni.showToast({
  87. icon:'none',
  88. title: res.message || '拍照截图失败,稍后重试'
  89. })
  90. }
  91. uni.hideLoading()
  92. })
  93. }else{
  94. uni.showToast({
  95. icon:'none',
  96. title: '开始播放视频后才可以拍照截图'
  97. })
  98. }
  99. },
  100. // 上传编辑后的图片到阿里云
  101. uploadImg(formData) {
  102. const _this = this;
  103. saveBase64ToAliOss(formData,function(res){
  104. // console.log(res);
  105. // 关闭编辑图片
  106. _this.wv.evalJS("vm.closeImgsEdit()")
  107. // 更新编辑后的图片
  108. _this.wv.evalJS("vm.updateItemImg('"+res.data+"')")
  109. })
  110. },
  111. // 查询任务明细
  112. getTaskDetail(){
  113. getTaskTargetById({taskId:this.taskId}).then(res => {
  114. console.log(res.data)
  115. this.wv.evalJS("vm.getTaskDetail('"+JSON.stringify(res.data)+"')")
  116. })
  117. },
  118. // 获取视频列表
  119. getVideoList(){
  120. let list = this.$store.state.vuex_storeVideoList
  121. this.wv.evalJS("vm.setVideoList('"+JSON.stringify(list)+"')")
  122. },
  123. // 获取视频地址
  124. getStoreVideoUrl(item){
  125. getVideoUrl({streamId:item.streamId,outProtocol:"hls"}).then(res=>{
  126. console.log(res)
  127. if(res.status == 200&&res.data){
  128. this.wv.evalJS("vm.getVideoUrlSuccess('"+res.data.url+"')")
  129. }else{
  130. uni.showToast({
  131. icon:'none',
  132. title: "获取视频地址失败,请返回重试"
  133. })
  134. }
  135. })
  136. },
  137. // 提交本次任务
  138. submitTask(data){
  139. const _this = this;
  140. console.log(data,'savePointTask')
  141. clzConfirm({
  142. title: '提示',
  143. content: '确定提交本次点检任务?',
  144. success: function(res) {
  145. if (res.confirm || res.index == 0) {
  146. savePointTask(data).then(ret=>{
  147. console.log(ret)
  148. if(ret.status == 200){
  149. _this.isClose = true
  150. // 打开完成页面
  151. uni.redirectTo({
  152. url: '/pages/spotCheckCenter/spotCheckResult?id=' + _this.taskId
  153. });
  154. // 刷新列表
  155. uni.$emit('updatePointTaskList')
  156. }else{
  157. _this.isClose = false
  158. }
  159. uni.showToast({
  160. icon:'none',
  161. title: ret.message
  162. })
  163. })
  164. }
  165. }
  166. });
  167. },
  168. },
  169. onLoad(options) {
  170. // 巡店类型,视频还时现场
  171. this.types = options.types
  172. this.taskId = options.taskId
  173. this.storeId = options.storeId
  174. this.storeName = options.storeName
  175. console.log(options,this.taskId)
  176. },
  177. onUnload() {
  178. uni.$off("closeTour")
  179. },
  180. onReady() {
  181. let _this = this
  182. // #ifdef APP-PLUS
  183. //获取当前页面的webview对象
  184. var currentWebview = this.$mp.page.$getAppWebview()
  185. //如果是页面初始化调用时,需要延时一下
  186. setTimeout(function() {
  187. _this.wv = currentWebview.children()[0]
  188. _this.wv.evalJS("vm.setTyps('"+_this.types+"','"+_this.storeName+"')")
  189. // 获取视频列表
  190. if(_this.types == 'video'){
  191. _this.getVideoList()
  192. }
  193. //查询任务项明细
  194. _this.getTaskDetail()
  195. }, 500);
  196. // #endif
  197. // 关闭当前页面
  198. uni.$on("closeTour",(flag)=>{
  199. if(flag==1){
  200. this.isClose = true
  201. uni.navigateBack()
  202. }
  203. })
  204. },
  205. // 监听返回键
  206. onBackPress() {
  207. let _this = this
  208. if(!_this.isClose){
  209. // 正在编辑图片
  210. if(this.isEditImg){
  211. // 关闭编辑图片
  212. _this.wv.evalJS("vm.closeImgsEdit()")
  213. }
  214. // 正在拍照
  215. else if(this.showPz){
  216. // 关闭拍照弹框
  217. _this.wv.evalJS("vm.onClosePz()")
  218. }else{
  219. clzConfirm({
  220. title: '提示',
  221. content: '点检还未完成,确定退出吗?',
  222. success: function(res) {
  223. if (res.confirm || res.index == 0) {
  224. _this.isClose = true
  225. uni.navigateBack({
  226. delta: 1
  227. });
  228. }
  229. }
  230. });
  231. }
  232. return true
  233. }
  234. },
  235. }
  236. </script>
  237. <style>
  238. </style>