spotCheck.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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 == 'previewImg') {
  58. this.previewImg(data.msg)
  59. }
  60. // 提交巡店
  61. if(data.action == 'submitTask'){
  62. this.submitTask(JSON.parse(data.msg))
  63. }
  64. },
  65. // 删除图片
  66. delImgs(index){
  67. const _this = this;
  68. clzConfirm({
  69. title: '提示',
  70. content: '确定删除此图片,删除后无法恢复?',
  71. success: function(res) {
  72. if (res.confirm || res.index == 0) {
  73. _this.wv.evalJS("vm.delImgsSuccess("+index+")")
  74. }
  75. }
  76. });
  77. },
  78. // 预览图片
  79. previewImg(path){
  80. uni.previewImage({
  81. urls:[path]
  82. })
  83. },
  84. // 拍照截图,data.type 1 是列表按钮触发的,2 是弹框里触发的
  85. takePhotos(data){
  86. if(data.videoPlayerStatus == 'playing'){
  87. uni.showLoading({
  88. mask: true,
  89. title: '正在抓拍图片...'
  90. })
  91. photoPaiZhao({streamId:data.streamId}).then(res=>{
  92. console.log(res)
  93. if(res.data){
  94. this.wv.evalJS("vm.takePhotoSuccess('"+res.data.url+"')")
  95. }else{
  96. uni.showToast({
  97. icon:'none',
  98. title: res.message || '拍照截图失败,稍后重试'
  99. })
  100. }
  101. uni.hideLoading()
  102. })
  103. }else{
  104. uni.showToast({
  105. icon:'none',
  106. title: '开始播放视频后才可以拍照截图'
  107. })
  108. }
  109. },
  110. // 上传编辑后的图片到阿里云
  111. uploadImg(formData) {
  112. const _this = this;
  113. saveBase64ToAliOss(formData,function(res){
  114. // console.log(res);
  115. // 关闭编辑图片
  116. _this.wv.evalJS("vm.closeImgsEdit()")
  117. // 更新编辑后的图片
  118. _this.wv.evalJS("vm.updateItemImg('"+res.data+"')")
  119. })
  120. },
  121. // 查询任务明细
  122. getTaskDetail(){
  123. getTaskTargetById({taskId:this.taskId}).then(res => {
  124. console.log(res.data)
  125. this.wv.evalJS("vm.getTaskDetail('"+JSON.stringify(res.data)+"')")
  126. })
  127. },
  128. // 获取视频列表
  129. getVideoList(){
  130. let list = this.$store.state.vuex_storeVideoList
  131. this.wv.evalJS("vm.setVideoList('"+JSON.stringify(list)+"')")
  132. },
  133. // 获取视频地址
  134. getStoreVideoUrl(item){
  135. getVideoUrl({streamId:item.streamId,outProtocol:"hls"}).then(res=>{
  136. console.log(res)
  137. if(res.status == 200&&res.data){
  138. this.wv.evalJS("vm.getVideoUrlSuccess('"+res.data.url+"')")
  139. }else{
  140. uni.showToast({
  141. icon:'none',
  142. title: "获取视频地址失败,请返回重试"
  143. })
  144. }
  145. })
  146. },
  147. // 提交本次任务
  148. submitTask(data){
  149. const _this = this;
  150. const params = {
  151. id: this.taskId,
  152. taskTargetDTOList: data
  153. }
  154. console.log(params,'savePointTask')
  155. clzConfirm({
  156. title: '提示',
  157. content: '确定提交本次点检任务?',
  158. success: function(res) {
  159. if (res.confirm || res.index == 0) {
  160. savePointTask(params).then(ret=>{
  161. console.log(ret)
  162. if(ret.status == 200){
  163. _this.isClose = true
  164. // 打开完成页面
  165. uni.redirectTo({
  166. url: '/pages/spotCheckCenter/spotCheckResult?id=' + _this.taskId
  167. });
  168. // 刷新列表
  169. uni.$emit('updatePointTaskList')
  170. }else{
  171. _this.isClose = false
  172. }
  173. uni.showToast({
  174. icon:'none',
  175. title: ret.message
  176. })
  177. })
  178. }
  179. }
  180. });
  181. },
  182. },
  183. onLoad(options) {
  184. // 巡店类型,视频还时现场
  185. this.types = options.types
  186. this.taskId = options.taskId
  187. this.storeId = options.storeId
  188. this.storeName = options.storeName
  189. console.log(options,this.taskId)
  190. },
  191. onUnload() {
  192. uni.$off("closeTour")
  193. },
  194. onReady() {
  195. let _this = this
  196. // #ifdef APP-PLUS
  197. //获取当前页面的webview对象
  198. var currentWebview = this.$mp.page.$getAppWebview()
  199. //如果是页面初始化调用时,需要延时一下
  200. setTimeout(function() {
  201. _this.wv = currentWebview.children()[0]
  202. _this.wv.evalJS("vm.setTyps('"+_this.types+"','"+_this.storeName+"')")
  203. // 获取视频列表
  204. if(_this.types == 'video'){
  205. _this.getVideoList()
  206. }
  207. //查询任务项明细
  208. _this.getTaskDetail()
  209. }, 500);
  210. // #endif
  211. // 关闭当前页面
  212. uni.$on("closeTour",(flag)=>{
  213. if(flag==1){
  214. this.isClose = true
  215. uni.navigateBack()
  216. }
  217. })
  218. },
  219. // 监听返回键
  220. onBackPress() {
  221. let _this = this
  222. if(!_this.isClose){
  223. // 正在编辑图片
  224. if(this.isEditImg){
  225. // 关闭编辑图片
  226. _this.wv.evalJS("vm.closeImgsEdit()")
  227. }
  228. // 正在拍照
  229. else if(this.showPz){
  230. // 关闭拍照弹框
  231. _this.wv.evalJS("vm.onClosePz()")
  232. }else{
  233. clzConfirm({
  234. title: '提示',
  235. content: '点检还未完成,确定退出吗?',
  236. success: function(res) {
  237. if (res.confirm || res.index == 0) {
  238. _this.isClose = true
  239. uni.navigateBack({
  240. delta: 1
  241. });
  242. }
  243. }
  244. });
  245. }
  246. return true
  247. }
  248. },
  249. }
  250. </script>
  251. <style>
  252. </style>