shopTour.vue 10 KB

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