shopTour.vue 9.8 KB

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