shopTour.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  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. // 现场巡店,需要保存签到信息
  203. if(this.types == 'scene'){
  204. let signin = this.$store.state.vuex_sceneTaskSignIn
  205. parms.inspectorPositionAddr= signin.inspectorPositionAddr
  206. parms.inspectorPositionPhotoBasePath= signin.inspectorPositionPhotoBasePath
  207. parms.inspectorPositionPhotoPath= signin.inspectorPositionPhotoPath
  208. }
  209. taskStart(parms).then(res => {
  210. console.log(res,parms,'taskStart')
  211. if(res.status == 200){
  212. this.taskId = res.data.id
  213. // 创建成功,查询任务明细
  214. this.getTaskDetail()
  215. this.getTaskItem()
  216. }else{
  217. uni.showToast({
  218. icon:'none',
  219. title: res.message
  220. })
  221. }
  222. })
  223. },
  224. // 查询任务明细
  225. getTaskDetail(){
  226. getTaskDetail({id:this.taskId}).then(res => {
  227. this.assessSchemeId = res.data.assessSchemeId // 方案id
  228. this.wv.evalJS("vm.getTaskDetail('"+JSON.stringify(res.data)+"')")
  229. })
  230. },
  231. // 任务考评项目明细
  232. getTaskItem(){
  233. getTaskItem({id:this.taskId}).then(res => {
  234. console.log(res,'getTaskItem')
  235. this.wv.evalJS("vm.getTaskItem('"+JSON.stringify(res.data)+"')")
  236. })
  237. },
  238. // 更新方案项目
  239. updateTaskItem(row){
  240. console.log(row)
  241. updateTaskItem({
  242. id:this.taskId,
  243. assessSchemeId: row.id,
  244. assessSchemeName: row.name
  245. }).then(res=>{
  246. console.log(res,'updateTaskItem')
  247. if(res.status==200){
  248. // 重置页面
  249. this.wv.evalJS("vm.resetPage()")
  250. this.getTaskDetail()
  251. this.getTaskItem()
  252. }else{
  253. uni.showToast({
  254. icon:'none',
  255. title: res.message
  256. })
  257. }
  258. })
  259. },
  260. // 获取视频列表
  261. getVideoList(){
  262. let list = this.$store.state.vuex_storeVideoList
  263. this.wv.evalJS("vm.setVideoList('"+JSON.stringify(list)+"')")
  264. },
  265. // 获取视频地址
  266. getStoreVideoUrl(item){
  267. getVideoUrl({streamId:item.streamId,outProtocol:"hls"}).then(res=>{
  268. console.log(res)
  269. if(res.status == 200&&res.data){
  270. this.wv.evalJS("vm.getVideoUrlSuccess('"+res.data.url+"')")
  271. }else{
  272. uni.showToast({
  273. icon:'none',
  274. title: "获取视频地址失败,请返回重试"
  275. })
  276. }
  277. })
  278. },
  279. // 提交本次任务
  280. submitTask(){
  281. const _this = this;
  282. clzConfirm({
  283. title: '提示',
  284. content: '确定提交本次巡店?',
  285. success: function(res) {
  286. console.log(res,'--------')
  287. if (res.confirm || res.index == 0) {
  288. submitTask({
  289. id: _this.taskId
  290. }).then(ret=>{
  291. console.log(ret)
  292. if(ret.status == 200){
  293. _this.isClose = true
  294. // 打开完成页面
  295. uni.redirectTo({
  296. url:"/pages/shopTourCompleted/shopTourCompleted?taskId="+_this.taskId
  297. })
  298. }else{
  299. _this.isClose = false
  300. }
  301. uni.showToast({
  302. icon:'none',
  303. title: ret.message
  304. })
  305. })
  306. }
  307. }
  308. });
  309. },
  310. // 现场巡店下一步签字
  311. nextStep(){
  312. uni.navigateTo({
  313. url:"/pages/shopTourOver/shopTourOver?taskId="+this.taskId
  314. })
  315. }
  316. },
  317. onLoad(options) {
  318. console.log(options,'options')
  319. // 巡店类型,视频还时现场
  320. this.types = options.types
  321. this.taskId = options.taskId
  322. this.storeId = options.storeId
  323. this.restart = options.restart
  324. },
  325. onUnload() {
  326. uni.$off("resetTaskKpItem")
  327. uni.$off("closeTour")
  328. },
  329. onReady() {
  330. let _this = this
  331. _this.isClose = false
  332. // #ifdef APP-PLUS
  333. //获取当前页面的webview对象
  334. var currentWebview = this.$mp.page.$getAppWebview()
  335. //如果是页面初始化调用时,需要延时一下
  336. setTimeout(function() {
  337. _this.wv = currentWebview.children()[0]
  338. _this.wv.evalJS("vm.setTyps('"+_this.types+"')")
  339. // 获取视频列表
  340. if(_this.types == 'video'){
  341. _this.getVideoList()
  342. }
  343. if(_this.restart == 1){ // 重新开始
  344. _this.creatTask(1)
  345. }else if(_this.restart == 0){ // 继续上次巡店
  346. //查询任务明细
  347. _this.getTaskDetail()
  348. _this.getTaskItem()
  349. }else{
  350. // 首次新建
  351. _this.creatTask(0)
  352. }
  353. }, 500);
  354. // #endif
  355. // 监听选择方案后事件,schemeId 方案id
  356. uni.$on("resetTaskKpItem",(row)=>{
  357. _this.updateTaskItem(row)
  358. })
  359. // 关闭当前页面
  360. uni.$on("closeTour",(flag)=>{
  361. if(flag==1){
  362. this.isClose = true
  363. uni.navigateBack()
  364. }
  365. })
  366. },
  367. // 监听返回键
  368. onBackPress() {
  369. console.log(this.isEditImg,'onBackPress')
  370. let _this = this
  371. if(!_this.isClose){
  372. // 正在编辑图片
  373. if(this.isEditImg){
  374. // 关闭编辑图片
  375. _this.wv.evalJS("vm.closeImgsEdit()")
  376. }
  377. // 正在拍照
  378. else if(this.showPz){
  379. // 关闭拍照弹框
  380. _this.wv.evalJS("vm.onClosePz()")
  381. }else{
  382. clzConfirm({
  383. title: '提示',
  384. content: '巡店还未完成,确定退出吗?',
  385. success: function(res) {
  386. if (res.confirm || res.index == 0) {
  387. _this.isClose = true
  388. uni.navigateBack({
  389. delta: 1
  390. });
  391. }
  392. }
  393. });
  394. }
  395. return true
  396. }
  397. },
  398. // 添加考评模板
  399. onNavigationBarButtonTap(e) {
  400. // 且当前没编辑图片或抓拍图片
  401. if(e.index==0 && !this.isEditImg){
  402. uni.navigateTo({
  403. url: '/pages/evaluatePlan/evaluatePlan?id='+this.assessSchemeId
  404. })
  405. }else{
  406. uni.showToast({
  407. icon:"none",
  408. title:"正在编辑图片,不能选择考评方案"
  409. })
  410. }
  411. },
  412. }
  413. </script>
  414. <style>
  415. </style>