shopTour.vue 8.7 KB

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