spotCheck.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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 {findVsDeviceChannels} 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. // webview 窗口传过来的页面状态
  30. if(data.action == 'getWinStatus'){
  31. let d = JSON.parse(data.msg)
  32. this[d.key] = d.val
  33. }
  34. // 保存编辑后的图片
  35. if(data.action == 'saveEditImg'){
  36. this.uploadImg(data.msg)
  37. }
  38. // 删除图片
  39. if(data.action == 'delImgs'){
  40. this.delImgs(data.msg)
  41. }
  42. // 提交巡店
  43. if(data.action == 'submitTask'){
  44. this.submitTask(JSON.parse(data.msg))
  45. }
  46. },
  47. // 删除图片
  48. delImgs(index){
  49. const _this = this;
  50. clzConfirm({
  51. title: '提示',
  52. content: '确定删除此图片,删除后无法恢复?',
  53. success: function(res) {
  54. if (res.confirm || res.index == 0) {
  55. _this.wv.evalJS("vm.delImgsSuccess("+index+")")
  56. }
  57. }
  58. });
  59. },
  60. // 上传编辑后的图片到阿里云
  61. uploadImg(formData) {
  62. const _this = this;
  63. saveBase64ToAliOss(formData,function(res){
  64. // console.log(res);
  65. // 关闭编辑图片
  66. _this.wv.evalJS("vm.closeImgsEdit()")
  67. // 更新编辑后的图片
  68. _this.wv.evalJS("vm.updateItemImg('"+res.data+"')")
  69. })
  70. },
  71. // 查询任务明细
  72. getTaskDetail(){
  73. getTaskTargetById({taskId:this.taskId}).then(res => {
  74. console.log(res.data)
  75. this.wv.evalJS("vm.getTaskDetail('"+JSON.stringify(res.data)+"')")
  76. })
  77. },
  78. // 获取视频列表
  79. getVideoList(){
  80. findVsDeviceChannels({storeId:this.storeId}).then(res=>{
  81. if(res.status==200){
  82. this.wv.evalJS("vm.setVideoList('"+JSON.stringify(res.data)+"')")
  83. }
  84. })
  85. },
  86. // 提交本次任务
  87. submitTask(data){
  88. const _this = this;
  89. console.log(data,'savePointTask')
  90. clzConfirm({
  91. title: '提示',
  92. content: '确定提交本次点检任务?',
  93. success: function(res) {
  94. if (res.confirm || res.index == 0) {
  95. savePointTask(data).then(ret=>{
  96. console.log(ret)
  97. if(ret.status == 200){
  98. _this.isClose = true
  99. // 打开完成页面
  100. uni.redirectTo({
  101. url: '/pages/spotCheckCenter/spotCheckResult?id=' + _this.taskId
  102. });
  103. // 刷新列表
  104. uni.$emit('updatePointTaskList')
  105. }else{
  106. _this.isClose = false
  107. }
  108. uni.showToast({
  109. icon:'none',
  110. title: ret.message
  111. })
  112. })
  113. }
  114. }
  115. });
  116. },
  117. },
  118. onLoad(options) {
  119. // 巡店类型,视频还时现场
  120. this.types = options.types
  121. this.taskId = options.taskId
  122. this.storeId = options.storeId
  123. this.storeName = options.storeName
  124. },
  125. onUnload() {
  126. uni.$off("closeTour")
  127. },
  128. onReady() {
  129. let _this = this
  130. // #ifdef APP-PLUS
  131. //获取当前页面的webview对象
  132. var currentWebview = this.$mp.page.$getAppWebview()
  133. //如果是页面初始化调用时,需要延时一下
  134. setTimeout(function() {
  135. _this.wv = currentWebview.children()[0]
  136. _this.wv.evalJS("vm.setTyps('"+_this.types+"','"+_this.storeName+"')")
  137. // 获取视频列表
  138. if(_this.types == 'video'){
  139. _this.getVideoList()
  140. }
  141. //查询任务项明细
  142. _this.getTaskDetail()
  143. }, 500);
  144. // #endif
  145. // 关闭当前页面
  146. uni.$on("closeTour",(flag)=>{
  147. if(flag==1){
  148. this.isClose = true
  149. uni.navigateBack()
  150. }
  151. })
  152. },
  153. // 监听返回键
  154. onBackPress() {
  155. let _this = this
  156. if(!_this.isClose){
  157. // 正在编辑图片
  158. if(this.isEditImg){
  159. // 关闭编辑图片
  160. _this.wv.evalJS("vm.closeImgsEdit()")
  161. }
  162. // 正在拍照
  163. else if(this.showPz){
  164. // 关闭拍照弹框
  165. _this.wv.evalJS("vm.onClosePz()")
  166. }else{
  167. clzConfirm({
  168. title: '提示',
  169. content: '点检还未完成,确定退出吗?',
  170. success: function(res) {
  171. if (res.confirm || res.index == 0) {
  172. _this.isClose = true
  173. uni.navigateBack({
  174. delta: 1
  175. });
  176. }
  177. }
  178. });
  179. }
  180. return true
  181. }
  182. },
  183. }
  184. </script>
  185. <style>
  186. </style>