spotCheck.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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. const params = {
  141. id: this.taskId,
  142. taskTargetDTOList: data
  143. }
  144. console.log(params,'savePointTask')
  145. clzConfirm({
  146. title: '提示',
  147. content: '确定提交本次点检任务?',
  148. success: function(res) {
  149. if (res.confirm || res.index == 0) {
  150. savePointTask(params).then(ret=>{
  151. console.log(ret)
  152. if(ret.status == 200){
  153. _this.isClose = true
  154. // 打开完成页面
  155. uni.redirectTo({
  156. url: '/pages/spotCheckCenter/spotCheckResult?id=' + _this.taskId
  157. });
  158. // 刷新列表
  159. uni.$emit('updatePointTaskList')
  160. }else{
  161. _this.isClose = false
  162. }
  163. uni.showToast({
  164. icon:'none',
  165. title: ret.message
  166. })
  167. })
  168. }
  169. }
  170. });
  171. },
  172. },
  173. onLoad(options) {
  174. // 巡店类型,视频还时现场
  175. this.types = options.types
  176. this.taskId = options.taskId
  177. this.storeId = options.storeId
  178. this.storeName = options.storeName
  179. console.log(options,this.taskId)
  180. },
  181. onUnload() {
  182. uni.$off("closeTour")
  183. },
  184. onReady() {
  185. let _this = this
  186. // #ifdef APP-PLUS
  187. //获取当前页面的webview对象
  188. var currentWebview = this.$mp.page.$getAppWebview()
  189. //如果是页面初始化调用时,需要延时一下
  190. setTimeout(function() {
  191. _this.wv = currentWebview.children()[0]
  192. _this.wv.evalJS("vm.setTyps('"+_this.types+"','"+_this.storeName+"')")
  193. // 获取视频列表
  194. if(_this.types == 'video'){
  195. _this.getVideoList()
  196. }
  197. //查询任务项明细
  198. _this.getTaskDetail()
  199. }, 500);
  200. // #endif
  201. // 关闭当前页面
  202. uni.$on("closeTour",(flag)=>{
  203. if(flag==1){
  204. this.isClose = true
  205. uni.navigateBack()
  206. }
  207. })
  208. },
  209. // 监听返回键
  210. onBackPress() {
  211. let _this = this
  212. if(!_this.isClose){
  213. // 正在编辑图片
  214. if(this.isEditImg){
  215. // 关闭编辑图片
  216. _this.wv.evalJS("vm.closeImgsEdit()")
  217. }
  218. // 正在拍照
  219. else if(this.showPz){
  220. // 关闭拍照弹框
  221. _this.wv.evalJS("vm.onClosePz()")
  222. }else{
  223. clzConfirm({
  224. title: '提示',
  225. content: '点检还未完成,确定退出吗?',
  226. success: function(res) {
  227. if (res.confirm || res.index == 0) {
  228. _this.isClose = true
  229. uni.navigateBack({
  230. delta: 1
  231. });
  232. }
  233. }
  234. });
  235. }
  236. return true
  237. }
  238. },
  239. }
  240. </script>
  241. <style>
  242. </style>