shopTour.vue 10 KB

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