shopTour.vue 7.6 KB

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