shopTour.vue 10 KB

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