shopTour.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. <template>
  2. <view>
  3. <web-view @message="onmessage" src="/hybrid/html/video.html"></web-view>
  4. </view>
  5. </template>
  6. <script>
  7. import { clzConfirm,saveBase64ToAliOss } from '@/libs/tools'
  8. import {taskStart,submitTask,updateTaskItem,getTaskDetail} from '@/api/task'
  9. import {getTaskItem,delTaskItem} from '@/api/taskItem'
  10. import {taskTargetSave,taskCommentsSave} from '@/api/taskTarget'
  11. import {findVsDeviceChannels,findStoreVsDevice,photoPaiZhao,getVideoUrl} from '@/api/store'
  12. export default {
  13. data() {
  14. return {
  15. wv: null,
  16. isClose: false, // 是否关闭当前窗口
  17. isEditImg: false, // 是否正在编辑图片
  18. showPz: false, // 是否正在拍照
  19. types: 'video', // 巡店类型,video,scene
  20. restart: '', // 是否重新巡店
  21. taskId: '', // 任务id
  22. storeId: '', // 门店id
  23. assessSchemeId: '', // 方案id
  24. };
  25. },
  26. methods: {
  27. // 监听html页面事件
  28. onmessage(event) {
  29. let data = event.detail.data[0]
  30. // console.log(data)
  31. // webview 窗口传过来的页面状态
  32. if(data.action == 'getWinStatus'){
  33. let d = JSON.parse(data.msg)
  34. this[d.key] = d.val
  35. }
  36. // 获取视频地址
  37. if(data.action == 'getVideoUrl'){
  38. this.getStoreVideoUrl(JSON.parse(data.msg))
  39. }
  40. // 抓拍图片
  41. if(data.action == 'takePhotos'){
  42. this.takePhotos(JSON.parse(data.msg))
  43. }
  44. // 保存编辑后的图片
  45. if(data.action == 'saveEditImg'){
  46. this.uploadImg(data.msg)
  47. }
  48. // 删除图片
  49. if(data.action == 'delImgs'){
  50. this.delImgs(data.msg)
  51. }
  52. // 删除考评项
  53. if(data.action == 'delKpItem'){
  54. this.delKpItem(data.msg)
  55. }
  56. // 评分,保存指标结果
  57. if(data.action == 'selZbResult'){
  58. this.saveZbResult(JSON.parse(data.msg))
  59. }
  60. // 指标评论,图片更新保存
  61. if(data.action == 'saveZbPlImgs'){
  62. this.saveZbPlImgs(JSON.parse(data.msg))
  63. }
  64. // 更新考评总计
  65. if(data.action == 'updateKpTj'){
  66. this.getTaskDetail()
  67. }
  68. // 提交巡店
  69. if(data.action == 'submitTask'){
  70. this.submitTask()
  71. }
  72. // 现场巡店下一步签字页面
  73. if(data.action == 'nextStep'){
  74. this.nextStep()
  75. }
  76. },
  77. //指标评论,图片更新保存
  78. saveZbPlImgs(data){
  79. console.log(data,'saveZbPlImgs')
  80. taskCommentsSave(data).then(res=>{
  81. if(res.status == 200){
  82. this.wv.evalJS("vm.saveZbPlImgsSuccess()")
  83. }
  84. uni.showToast({
  85. icon:'none',
  86. title: res.message
  87. })
  88. })
  89. },
  90. // 保存指标结果
  91. saveZbResult(data){
  92. console.log(data,'saveZbResult')
  93. taskTargetSave(data).then(res=>{
  94. if(res.status == 200){
  95. this.wv.evalJS("vm.saveZbResultSuccess('"+JSON.stringify(data)+"')")
  96. }
  97. uni.showToast({
  98. icon:'none',
  99. title: res.message
  100. })
  101. })
  102. },
  103. // 拍照截图,data.type 1 是列表按钮触发的,2 是弹框里触发的
  104. takePhotos(data){
  105. if(data.videoPlayerStatus == 'playing'){
  106. uni.showLoading({
  107. mask: true,
  108. title: '正在抓拍图片...'
  109. })
  110. photoPaiZhao({streamId:data.streamId}).then(res=>{
  111. console.log(res)
  112. if(res.data){
  113. this.wv.evalJS("vm.takePhotoSuccess('"+res.data.url+"')")
  114. }else{
  115. uni.showToast({
  116. icon:'none',
  117. title: res.message || '拍照截图失败,稍后重试'
  118. })
  119. }
  120. uni.hideLoading()
  121. })
  122. }else{
  123. uni.showToast({
  124. icon:'none',
  125. title: '开始播放视频后才可以拍照截图'
  126. })
  127. }
  128. },
  129. // 删除图片
  130. delImgs(index){
  131. const _this = this;
  132. clzConfirm({
  133. title: '提示',
  134. content: '确定删除此图片,删除后无法恢复?',
  135. success: function(res) {
  136. if (res.confirm || res.index == 0) {
  137. _this.wv.evalJS("vm.delImgsSuccess("+index+")")
  138. }
  139. }
  140. });
  141. },
  142. // 删除考评项
  143. delKpItem(id){
  144. const _this = this;
  145. clzConfirm({
  146. title: '提示',
  147. content: '确定删除此考评项,删除后无法恢复?',
  148. success: function(res) {
  149. if (res.confirm || res.index == 0) {
  150. delTaskItem({id:id}).then(ret=>{
  151. if(ret.status == 200){
  152. _this.wv.evalJS("vm.delKpItemSuccess("+id+")")
  153. }
  154. uni.showToast({
  155. icon:'none',
  156. title: ret.message
  157. })
  158. })
  159. }
  160. }
  161. });
  162. },
  163. // 上传编辑后的图片到阿里云
  164. uploadImg(formData) {
  165. const _this = this;
  166. saveBase64ToAliOss(formData,function(res){
  167. // console.log(res);
  168. // 关闭编辑图片
  169. _this.wv.evalJS("vm.closeImgsEdit()")
  170. // 更新编辑后的图片
  171. _this.wv.evalJS("vm.updateItemImg('"+res.data+"')")
  172. })
  173. },
  174. // 开始巡店(重新开始),isNew 0 新建,1 重新开始
  175. creatTask(isNew){
  176. // 新建任务,只传门店id
  177. let parms = {
  178. storeId:this.storeId,
  179. type: this.types == 'video' ? 'VIDEO_INSPECTION' : 'SPOT_INSPECTION'
  180. }
  181. // 重新开始,要传任务id
  182. if(isNew){
  183. parms.id = this.taskId
  184. }
  185. taskStart(parms).then(res => {
  186. console.log(res,parms,'taskStart')
  187. if(res.status == 200){
  188. this.taskId = res.data.id
  189. // 创建成功,查询任务明细
  190. this.getTaskDetail()
  191. this.getTaskItem()
  192. }else{
  193. uni.showToast({
  194. icon:'none',
  195. title: res.message
  196. })
  197. }
  198. })
  199. },
  200. // 查询任务明细
  201. getTaskDetail(){
  202. getTaskDetail({id:this.taskId}).then(res => {
  203. console.log(res,'getTaskDetail')
  204. this.assessSchemeId = res.data.assessSchemeId // 方案id
  205. this.wv.evalJS("vm.getTaskDetail('"+JSON.stringify(res.data)+"')")
  206. })
  207. },
  208. // 任务考评项目明细
  209. getTaskItem(){
  210. getTaskItem({id:this.taskId}).then(res => {
  211. console.log(res,this.taskId,'getTaskItem')
  212. this.wv.evalJS("vm.getTaskItem('"+JSON.stringify(res.data)+"')")
  213. })
  214. },
  215. // 更新方案项目
  216. updateTaskItem(schemeId){
  217. console.log(schemeId)
  218. updateTaskItem({schemeId,taskId:this.taskId}).then(res=>{
  219. if(res.status==200){
  220. // 重置页面
  221. this.wv.evalJS("vm.resetPage()")
  222. this.getTaskDetail()
  223. this.getTaskItem()
  224. }else{
  225. uni.showToast({
  226. icon:'none',
  227. title: res.message
  228. })
  229. }
  230. })
  231. },
  232. // 获取视频列表
  233. getVideoList(){
  234. let list = this.$store.state.vuex_storeVideoList
  235. this.wv.evalJS("vm.setVideoList('"+JSON.stringify(list)+"')")
  236. },
  237. // 获取视频地址
  238. getStoreVideoUrl(item){
  239. console.log({streamId:item.streamId,outProtocol:"hls"})
  240. getVideoUrl({streamId:item.streamId,outProtocol:"hls"}).then(res=>{
  241. console.log(res)
  242. if(res.status == 200&&res.data){
  243. this.wv.evalJS("vm.getVideoUrlSuccess('"+res.data.url+"')")
  244. }
  245. })
  246. },
  247. // 提交本次任务
  248. submitTask(){
  249. const _this = this;
  250. clzConfirm({
  251. title: '提示',
  252. content: '确定提交本次巡店?',
  253. success: function(res) {
  254. console.log(res,'--------')
  255. if (res.confirm || res.index == 0) {
  256. submitTask({
  257. id: _this.taskId
  258. }).then(ret=>{
  259. console.log(ret)
  260. if(ret.status == 200){
  261. _this.isClose = true
  262. // 打开完成页面
  263. uni.redirectTo({
  264. url:"/pages/shopTourCompleted/shopTourCompleted?taskId="+_this.taskId
  265. })
  266. }else{
  267. _this.isClose = false
  268. }
  269. uni.showToast({
  270. icon:'none',
  271. title: ret.message
  272. })
  273. })
  274. }
  275. }
  276. });
  277. },
  278. // 现场巡店下一步签字
  279. nextStep(){
  280. uni.navigateTo({
  281. url:"/pages/shopTourOver/shopTourOver?taskId="+this.taskId
  282. })
  283. }
  284. },
  285. onLoad(options) {
  286. console.log(options,'options')
  287. // 巡店类型,视频还时现场
  288. this.types = options.types
  289. this.taskId = options.taskId
  290. this.storeId = options.storeId
  291. this.restart = options.restart
  292. },
  293. onUnload() {
  294. uni.$off("resetTaskKpItem")
  295. uni.$off("closeTour")
  296. },
  297. onReady() {
  298. let _this = this
  299. _this.isClose = false
  300. // #ifdef APP-PLUS
  301. //获取当前页面的webview对象
  302. var currentWebview = this.$mp.page.$getAppWebview()
  303. //如果是页面初始化调用时,需要延时一下
  304. setTimeout(function() {
  305. _this.wv = currentWebview.children()[0]
  306. _this.wv.evalJS("vm.setTyps('"+_this.types+"')")
  307. // 获取视频列表
  308. if(_this.types == 'video'){
  309. _this.getVideoList()
  310. }
  311. if(_this.restart == 1){ // 重新开始
  312. _this.creatTask(1)
  313. }else if(_this.restart == 0){ // 继续上次巡店
  314. //查询任务明细
  315. _this.getTaskDetail()
  316. _this.getTaskItem()
  317. }else{
  318. // 首次新建
  319. _this.creatTask(0)
  320. }
  321. }, 500);
  322. // #endif
  323. // 监听选择方案后事件,schemeId 方案id
  324. uni.$on("resetTaskKpItem",(schemeId)=>{
  325. _this.updateTaskItem(schemeId)
  326. })
  327. // 关闭当前页面
  328. uni.$on("closeTour",(flag)=>{
  329. if(flag==1){
  330. this.isClose = true
  331. uni.navigateBack()
  332. }
  333. })
  334. },
  335. // 监听返回键
  336. onBackPress() {
  337. console.log(this.isEditImg,'onBackPress')
  338. let _this = this
  339. if(!_this.isClose){
  340. // 正在编辑图片
  341. if(this.isEditImg){
  342. // 关闭编辑图片
  343. _this.wv.evalJS("vm.closeImgsEdit()")
  344. }
  345. // 正在拍照
  346. else if(this.showPz){
  347. // 关闭拍照弹框
  348. _this.wv.evalJS("vm.onClosePz()")
  349. }else{
  350. clzConfirm({
  351. title: '提示',
  352. content: '巡店还未完成,确定退出吗?',
  353. success: function(res) {
  354. if (res.confirm || res.index == 0) {
  355. _this.isClose = true
  356. uni.navigateBack({
  357. delta: 1
  358. });
  359. }
  360. }
  361. });
  362. }
  363. return true
  364. }
  365. },
  366. // 添加考评模板
  367. onNavigationBarButtonTap(e) {
  368. // 且当前没编辑图片或抓拍图片
  369. if(e.index==0 && !this.isEditImg){
  370. uni.navigateTo({
  371. url: '/pages/evaluatePlan/evaluatePlan?id='+this.assessSchemeId
  372. })
  373. }else{
  374. uni.showToast({
  375. icon:"none",
  376. title:"正在编辑图片,不能选择考评方案"
  377. })
  378. }
  379. },
  380. }
  381. </script>
  382. <style>
  383. </style>