spotCheck.vue 7.3 KB

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