shopTour.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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.js'
  10. import {taskTargetSave,taskCommentsSave} from '@/api/taskTarget'
  11. export default {
  12. data() {
  13. return {
  14. wv: null,
  15. isClose: false, // 是否关闭当前窗口
  16. isEditImg: false, // 是否正在编辑图片
  17. showPz: false, // 是否正在拍照
  18. types: 'video', // 巡店类型,video,scene
  19. restart: '', // 是否重新巡店
  20. taskId: '', // 任务id
  21. storeId: '', // 门店id
  22. assessSchemeId: '', // 方案id
  23. };
  24. },
  25. methods: {
  26. // 监听html页面事件
  27. onmessage(event) {
  28. let data = event.detail.data[0]
  29. // console.log(data)
  30. // webview 窗口传过来的页面状态
  31. if(data.action == 'getWinStatus'){
  32. let d = JSON.parse(data.msg)
  33. this[d.key] = d.val
  34. }
  35. // 保存编辑后的图片
  36. if(data.action == 'saveEditImg'){
  37. this.uploadImg(data.msg)
  38. }
  39. // 删除图片
  40. if(data.action == 'delImgs'){
  41. this.delImgs(data.msg)
  42. }
  43. // 删除考评项
  44. if(data.action == 'delKpItem'){
  45. this.delKpItem(data.msg)
  46. }
  47. // 评分,保存指标结果
  48. if(data.action == 'selZbResult'){
  49. this.saveZbResult(JSON.parse(data.msg))
  50. }
  51. // 指标评论,图片更新保存
  52. if(data.action == 'saveZbPlImgs'){
  53. this.saveZbPlImgs(JSON.parse(data.msg))
  54. }
  55. // 更新考评总计
  56. if(data.action == 'updateKpTj'){
  57. this.getTaskDetail()
  58. }
  59. },
  60. //指标评论,图片更新保存
  61. saveZbPlImgs(data){
  62. taskCommentsSave(data).then(res=>{
  63. if(res.status == 200){
  64. this.wv.evalJS("vm.saveZbPlImgsSuccess()")
  65. }
  66. uni.showToast({
  67. icon:'none',
  68. title: res.message
  69. })
  70. })
  71. },
  72. // 保存指标结果
  73. saveZbResult(data){
  74. taskTargetSave(data).then(res=>{
  75. if(res.status == 200){
  76. this.wv.evalJS("vm.saveZbResultSuccess("+data.id+",'"+data.result+"')")
  77. }
  78. uni.showToast({
  79. icon:'none',
  80. title: res.message
  81. })
  82. })
  83. },
  84. // 删除图片
  85. delImgs(index){
  86. const _this = this;
  87. clzConfirm({
  88. title: '提示',
  89. content: '确定删除此图片,删除后无法恢复?',
  90. success: function(res) {
  91. if (res.confirm || res.index == 0) {
  92. _this.wv.evalJS("vm.delImgsSuccess("+index+")")
  93. }
  94. }
  95. });
  96. },
  97. // 删除考评项
  98. delKpItem(id){
  99. const _this = this;
  100. clzConfirm({
  101. title: '提示',
  102. content: '确定删除此考评项,删除后无法恢复?',
  103. success: function(res) {
  104. if (res.confirm || res.index == 0) {
  105. delTaskItem({id:id}).then(res=>{
  106. if(res.status == 200){
  107. _this.wv.evalJS("vm.delKpItemSuccess("+id+")")
  108. }
  109. uni.showToast({
  110. icon:'none',
  111. title: res.message
  112. })
  113. })
  114. }
  115. }
  116. });
  117. },
  118. // 上传编辑后的图片到阿里云
  119. uploadImg(formData) {
  120. const _this = this;
  121. saveBase64ToAliOss(formData,function(res){
  122. // console.log(res);
  123. // 关闭编辑图片
  124. _this.wv.evalJS("vm.closeImgsEdit()")
  125. // 更新编辑后的图片
  126. _this.wv.evalJS("vm.updateItemImg('"+res.data+"')")
  127. })
  128. },
  129. // 开始巡店(重新开始),isNew 0 新建,1 重新开始
  130. creatTask(isNew){
  131. // 新建任务,只传门店id
  132. let parms = {
  133. storeId:this.storeId
  134. }
  135. // 重新开始,要传任务id
  136. if(isNew){
  137. parms.taskId = this.taskId
  138. }
  139. taskStart(parms).then(res => {
  140. if(res.status == 200){
  141. // 创建成功,查询任务明细
  142. this.getTaskDetail()
  143. this.getTaskItem()
  144. }else{
  145. uni.showToast({
  146. icon:'none',
  147. title: res.message
  148. })
  149. }
  150. })
  151. },
  152. // 查询任务明细
  153. getTaskDetail(){
  154. getTaskDetail({id:this.taskId}).then(res => {
  155. this.assessSchemeId = res.data.assessSchemeId // 方案id
  156. this.wv.evalJS("vm.getTaskDetail('"+JSON.stringify(res.data)+"')")
  157. })
  158. },
  159. // 任务考评项目明细
  160. getTaskItem(){
  161. getTaskItem({id:this.taskId}).then(res => {
  162. this.wv.evalJS("vm.getTaskItem('"+JSON.stringify(res.data)+"')")
  163. })
  164. },
  165. // 更新方案项目
  166. updateTaskItem(schemeId){
  167. console.log(schemeId)
  168. updateTaskItem({schemeId,taskId:this.taskId}).then(res=>{
  169. if(res.status==200){
  170. // 重置页面
  171. this.wv.evalJS("vm.resetPage()")
  172. this.getTaskDetail()
  173. this.getTaskItem()
  174. }else{
  175. uni.showToast({
  176. icon:'none',
  177. title: res.message
  178. })
  179. }
  180. })
  181. }
  182. },
  183. onLoad(options) {
  184. // 巡店类型,视频还时现场
  185. this.types = options.types
  186. this.taskId = options.taskId
  187. this.storeId = options.storeId
  188. this.restart = options.restart
  189. },
  190. onReady() {
  191. let _this = this
  192. // #ifdef APP-PLUS
  193. //获取当前页面的webview对象
  194. var currentWebview = this.$mp.page.$getAppWebview()
  195. //如果是页面初始化调用时,需要延时一下
  196. setTimeout(function() {
  197. _this.wv = currentWebview.children()[0]
  198. _this.wv.evalJS("vm.setTyps('"+_this.types+"')")
  199. if(_this.restart == 1){ // 重新开始
  200. _this.creatTask(1)
  201. }else if(_this.restart == 0){ // 继续上次巡店
  202. //查询任务明细
  203. _this.getTaskDetail()
  204. }else{
  205. // 首次新建
  206. _this.creatTask(0)
  207. }
  208. }, 500);
  209. // #endif
  210. // 监听选择方案后事件,schemeId 方案id
  211. uni.$on("resetTaskKpItem",(schemeId)=>{
  212. _this.updateTaskItem(schemeId)
  213. })
  214. },
  215. // 监听返回键
  216. onBackPress() {
  217. console.log(this.isEditImg,'onBackPress')
  218. let _this = this
  219. if(!_this.isClose){
  220. // 正在编辑图片
  221. if(this.isEditImg){
  222. // 关闭编辑图片
  223. _this.wv.evalJS("vm.closeImgsEdit()")
  224. }
  225. // 正在拍照
  226. else if(this.showPz){
  227. // 关闭拍照弹框
  228. _this.wv.evalJS("vm.onClosePz()")
  229. }else{
  230. clzConfirm({
  231. title: '提示',
  232. content: '巡店还未完成,确定退出吗?',
  233. success: function(res) {
  234. if (res.confirm || res.index == 0) {
  235. _this.isClose = true
  236. uni.navigateBack({
  237. delta: 1
  238. });
  239. }
  240. }
  241. });
  242. }
  243. return true
  244. }
  245. },
  246. // 添加考评模板
  247. onNavigationBarButtonTap(e) {
  248. // 且当前没编辑图片或抓拍图片
  249. if(e.index==0 && !this.isEditImg){
  250. uni.navigateTo({
  251. url: '/pages/evaluatePlan/evaluatePlan?id='+this.assessSchemeId
  252. })
  253. }else{
  254. uni.showToast({
  255. icon:"none",
  256. title:"正在编辑图片,不能选择考评方案"
  257. })
  258. }
  259. },
  260. }
  261. </script>
  262. <style>
  263. </style>