shopTour.vue 5.9 KB

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