shopTour.vue 8.5 KB

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