shopTour.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. <template>
  2. <view><web-view @message="onmessage" src="/hybrid/html/video.html"></web-view></view>
  3. </template>
  4. <script>
  5. import { clzConfirm, saveBase64ToAliOss, saveImgToAliOss } from '@/libs/tools';
  6. import { taskStart, submitTask, updateTaskItem, getTaskDetail } from '@/api/task';
  7. import { getTaskItem, delTaskItem } from '@/api/taskItem';
  8. import { taskTargetSave, taskCommentsSave } from '@/api/taskTarget';
  9. import { photoPaiZhao, getVideoUrl } from '@/api/store';
  10. export default {
  11. data() {
  12. return {
  13. wv: null,
  14. isClose: false, // 是否关闭当前窗口
  15. isEditImg: false, // 是否正在编辑图片
  16. showPz: false, // 是否正在拍照
  17. types: 'video', // 巡店类型,video,scene
  18. restart: '', // 是否重新巡店
  19. taskId: '', // 任务id
  20. storeId: '', // 门店id
  21. assessSchemeId: '' // 方案id
  22. };
  23. },
  24. methods: {
  25. // 监听html页面事件
  26. onmessage(event) {
  27. let data = event.detail.data[0];
  28. // console.log(data)
  29. if (data.action == 'toast') {
  30. uni.showToast({
  31. icon: 'none',
  32. title: data.msg
  33. });
  34. }
  35. // webview 窗口传过来的页面状态
  36. if (data.action == 'getWinStatus') {
  37. let d = JSON.parse(data.msg);
  38. this[d.key] = d.val;
  39. }
  40. // 获取视频地址
  41. if (data.action == 'getVideoUrl') {
  42. this.getStoreVideoUrl(JSON.parse(data.msg));
  43. }
  44. // 抓拍图片
  45. if (data.action == 'takePhotos') {
  46. console.log('takePhotos');
  47. // 截图
  48. if (this.types == 'video') {
  49. this.takePhotos(JSON.parse(data.msg));
  50. }
  51. // 拍照
  52. if (this.types == 'scene') {
  53. console.log('camerPhotos');
  54. this.camerPhotos();
  55. }
  56. }
  57. // 保存编辑后的图片
  58. if (data.action == 'saveEditImg') {
  59. this.uploadImg(data.msg);
  60. }
  61. // 删除图片
  62. if (data.action == 'delImgs') {
  63. this.delImgs(data.msg);
  64. }
  65. // 预览图片
  66. if (data.action == 'previewImg') {
  67. this.previewImg(data.msg)
  68. }
  69. // 删除考评项
  70. if (data.action == 'delKpItem') {
  71. this.delKpItem(data.msg);
  72. }
  73. // 评分,保存指标结果
  74. if (data.action == 'selZbResult') {
  75. this.saveZbResult(JSON.parse(data.msg));
  76. }
  77. // 指标评论,图片更新保存
  78. if (data.action == 'saveZbPlImgs') {
  79. this.saveZbPlImgs(JSON.parse(data.msg));
  80. }
  81. // 更新考评总计
  82. if (data.action == 'updateKpTj') {
  83. this.getTaskDetail();
  84. }
  85. // 提交巡店
  86. if (data.action == 'submitTask') {
  87. this.submitTask();
  88. }
  89. // 现场巡店下一步签字页面
  90. if (data.action == 'nextStep') {
  91. this.nextStep();
  92. }
  93. },
  94. //指标评论,图片更新保存
  95. saveZbPlImgs(data) {
  96. let params = {
  97. id: data.id,
  98. comments: data.comments,
  99. taskTargetPhotoList: []
  100. };
  101. data.taskTargetPhotoList.map(item => {
  102. params.taskTargetPhotoList.push({
  103. photoPath: item.photoPath
  104. });
  105. });
  106. console.log(params, 'saveZbPlImgs');
  107. taskCommentsSave(params).then(res => {
  108. console.log(res);
  109. if (res.status == 200) {
  110. this.wv.evalJS('vm.saveZbPlImgsSuccess()');
  111. }
  112. uni.showToast({
  113. icon: 'none',
  114. title: res.message
  115. });
  116. });
  117. },
  118. // 保存指标结果
  119. saveZbResult(data) {
  120. console.log(data, 'saveZbResult');
  121. taskTargetSave(data).then(res => {
  122. if (res.status == 200) {
  123. this.wv.evalJS("vm.saveZbResultSuccess('" + JSON.stringify(data) + "')");
  124. }
  125. uni.showToast({
  126. icon: 'none',
  127. title: res.message
  128. });
  129. });
  130. },
  131. // 预览图片
  132. previewImg(path){
  133. uni.previewImage({
  134. urls:[path]
  135. })
  136. },
  137. // 拍照截图,data.type 1 是列表按钮触发的,2 是弹框里触发的
  138. takePhotos(data) {
  139. if (data.videoPlayerStatus == 'playing') {
  140. uni.showLoading({
  141. mask: true,
  142. title: '正在抓拍图片...'
  143. });
  144. photoPaiZhao({ streamId: data.streamId }).then(res => {
  145. console.log(res);
  146. if (res.data) {
  147. this.wv.evalJS("vm.takePhotoSuccess('" + res.data.url + "')");
  148. } else {
  149. uni.showToast({
  150. icon: 'none',
  151. title: res.message || '拍照截图失败,稍后重试'
  152. });
  153. }
  154. uni.hideLoading();
  155. });
  156. } else {
  157. uni.showToast({
  158. icon: 'none',
  159. title: '开始播放视频后才可以拍照截图'
  160. });
  161. }
  162. },
  163. // 摄像机拍照
  164. camerPhotos() {
  165. const _this = this;
  166. uni.chooseImage({
  167. count: 1, //最多可以选择的图片张数,默认9
  168. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  169. sourceType: ['camera'], //album 从相册选图,camera 使用相机,默认二者都有
  170. success: function(res) {
  171. // tempFilePaths 图片的本地文件路径列表,tempFiles 图片的本地文件列表,每一项是一个 File 对象
  172. uni.showLoading({
  173. title:'正在保存图片...',
  174. mask: true
  175. })
  176. saveImgToAliOss(res.tempFilePaths[0], function(ret) {
  177. _this.wv.evalJS("vm.takePhotoSuccess('" + ret.data + "')");
  178. uni.hideLoading()
  179. });
  180. }
  181. });
  182. },
  183. // 删除图片
  184. delImgs(index) {
  185. const _this = this;
  186. clzConfirm({
  187. title: '提示',
  188. content: '确定删除此图片,删除后无法恢复?',
  189. success: function(res) {
  190. if (res.confirm || res.index == 0) {
  191. _this.wv.evalJS('vm.delImgsSuccess(' + index + ')');
  192. }
  193. }
  194. });
  195. },
  196. // 删除考评项
  197. delKpItem(id) {
  198. const _this = this;
  199. clzConfirm({
  200. title: '提示',
  201. content: '确定删除此考评项,删除后无法恢复?',
  202. success: function(res) {
  203. if (res.confirm || res.index == 0) {
  204. delTaskItem({ id: id }).then(ret => {
  205. if (ret.status == 200) {
  206. _this.wv.evalJS('vm.delKpItemSuccess(' + id + ')');
  207. }
  208. uni.showToast({
  209. icon: 'none',
  210. title: ret.message
  211. });
  212. });
  213. }
  214. }
  215. });
  216. },
  217. // 上传编辑后的图片到阿里云
  218. uploadImg(formData) {
  219. const _this = this;
  220. saveBase64ToAliOss(formData, function(res) {
  221. // console.log(res);
  222. // 关闭编辑图片
  223. _this.wv.evalJS('vm.closeImgsEdit()');
  224. // 更新编辑后的图片
  225. _this.wv.evalJS("vm.updateItemImg('" + res.data + "')");
  226. });
  227. },
  228. // 开始巡店(重新开始),isNew 0 新建,1 重新开始
  229. creatTask(isNew) {
  230. // 新建任务,只传门店id
  231. let parms = {
  232. storeId: this.storeId,
  233. type: this.types == 'video' ? 'VIDEO_INSPECTION' : 'SPOT_INSPECTION'
  234. };
  235. // 重新开始,要传任务id
  236. if (isNew) {
  237. parms.id = this.taskId;
  238. }
  239. // 现场巡店,需要保存签到信息
  240. if (this.types == 'scene') {
  241. let signin = this.$store.state.vuex_sceneTaskSignIn;
  242. parms.inspectorPositionAddr = signin.inspectorPositionAddr;
  243. parms.inspectorPositionPhotoPath = signin.inspectorPositionPhotoPath;
  244. }
  245. console.log(parms,'taskStart')
  246. taskStart(parms).then(res => {
  247. if (res.status == 200) {
  248. this.taskId = res.data.id;
  249. // 创建成功,查询任务明细
  250. this.getTaskDetail();
  251. this.getTaskItem();
  252. } else {
  253. uni.showToast({
  254. icon: 'none',
  255. title: res.message
  256. });
  257. }
  258. });
  259. },
  260. // 查询任务明细
  261. getTaskDetail() {
  262. getTaskDetail({ id: this.taskId }).then(res => {
  263. this.assessSchemeId = res.data.assessSchemeId; // 方案id
  264. this.wv.evalJS("vm.getTaskDetail('" + JSON.stringify(res.data) + "')");
  265. });
  266. },
  267. // 任务考评项目明细
  268. getTaskItem() {
  269. getTaskItem({ id: this.taskId }).then(res => {
  270. // console.log(res, 'getTaskItem');
  271. let str = JSON.stringify(res.data)
  272. str = str.replace(/\\t|\\n|\\r|\\s/g,'')
  273. this.wv.evalJS("vm.getTaskItem('" + str + "')");
  274. });
  275. },
  276. // 更新方案项目
  277. updateTaskItem(row) {
  278. console.log(row);
  279. // 相同方案无需重置更新
  280. if(row.id == this.assessSchemeId){
  281. return
  282. }
  283. updateTaskItem({
  284. id: this.taskId,
  285. assessSchemeId: row.id,
  286. assessSchemeName: row.name
  287. }).then(res => {
  288. console.log(res, 'updateTaskItem');
  289. if (res.status == 200) {
  290. // 重置页面
  291. this.wv.evalJS('vm.resetPage()');
  292. this.getTaskDetail();
  293. this.getTaskItem();
  294. } else {
  295. uni.showToast({
  296. icon: 'none',
  297. title: res.message
  298. });
  299. }
  300. });
  301. },
  302. // 获取视频列表
  303. getVideoList() {
  304. let list = this.$store.state.vuex_storeVideoList;
  305. this.wv.evalJS("vm.setVideoList('" + JSON.stringify(list) + "')");
  306. },
  307. // 获取视频地址
  308. getStoreVideoUrl(item) {
  309. let _this = this
  310. getVideoUrl({ streamId: item.streamId, outProtocol: 'hls' }).then(res => {
  311. console.log(res);
  312. if (res.status == 200 && res.data) {
  313. this.wv.evalJS("vm.getVideoUrlSuccess('" + res.data.url + "')");
  314. } else {
  315. this.wv.evalJS("vm.getVideoUrlError('error')");
  316. uni.showToast({
  317. icon: 'none',
  318. title: '加载视频失败'
  319. });
  320. }
  321. });
  322. },
  323. // 提交本次任务
  324. submitTask() {
  325. const _this = this;
  326. clzConfirm({
  327. title: '提示',
  328. content: '确定提交本次巡店?',
  329. success: function(res) {
  330. console.log(res, '--------');
  331. if (res.confirm || res.index == 0) {
  332. submitTask({
  333. id: _this.taskId
  334. }).then(ret => {
  335. console.log(ret);
  336. if (ret.status == 200) {
  337. _this.isClose = true;
  338. // 打开完成页面
  339. uni.redirectTo({
  340. url: '/pages/shopTourCompleted/shopTourCompleted?taskId=' + _this.taskId
  341. });
  342. } else {
  343. _this.isClose = false;
  344. }
  345. uni.showToast({
  346. icon: 'none',
  347. title: ret.message
  348. });
  349. });
  350. }
  351. }
  352. });
  353. },
  354. // 现场巡店下一步签字
  355. nextStep() {
  356. uni.navigateTo({
  357. url: '/pages/shopTourOver/shopTourOver?taskId=' + this.taskId
  358. });
  359. }
  360. },
  361. onLoad(options) {
  362. console.log(options, 'options');
  363. // 巡店类型,视频还时现场
  364. this.types = options.types;
  365. this.taskId = options.taskId;
  366. this.storeId = options.storeId;
  367. this.restart = options.restart;
  368. },
  369. onUnload() {
  370. uni.$off('resetTaskKpItem');
  371. uni.$off('closeTour');
  372. },
  373. onReady() {
  374. let _this = this;
  375. _this.isClose = false;
  376. // #ifdef APP-PLUS
  377. //获取当前页面的webview对象
  378. var currentWebview = this.$mp.page.$getAppWebview();
  379. //如果是页面初始化调用时,需要延时一下
  380. setTimeout(function() {
  381. _this.wv = currentWebview.children()[0];
  382. _this.wv.evalJS("vm.setTyps('" + _this.types + "')");
  383. // 获取视频列表
  384. if (_this.types == 'video') {
  385. _this.getVideoList();
  386. }
  387. if (_this.restart == 1) {
  388. // 重新开始
  389. _this.creatTask(1);
  390. } else if (_this.restart == 0) {
  391. // 继续上次巡店
  392. //查询任务明细
  393. _this.getTaskDetail();
  394. _this.getTaskItem();
  395. } else {
  396. // 首次新建
  397. _this.creatTask(0);
  398. }
  399. }, 500);
  400. // #endif
  401. // 监听选择方案后事件,schemeId 方案id
  402. uni.$on('resetTaskKpItem', row => {
  403. _this.updateTaskItem(row);
  404. });
  405. // 关闭当前页面
  406. uni.$on('closeTour', flag => {
  407. if (flag == 1) {
  408. this.isClose = true;
  409. uni.navigateBack();
  410. }
  411. });
  412. },
  413. // 监听返回键
  414. onBackPress() {
  415. console.log(this.isEditImg, 'onBackPress');
  416. let _this = this;
  417. if (!_this.isClose) {
  418. // 正在编辑图片
  419. if (this.isEditImg) {
  420. // 关闭编辑图片
  421. _this.wv.evalJS('vm.closeImgsEdit()');
  422. }
  423. // 正在拍照
  424. else if (this.showPz) {
  425. // 关闭拍照弹框
  426. _this.wv.evalJS('vm.onClosePz()');
  427. } else {
  428. clzConfirm({
  429. title: '提示',
  430. content: '巡店还未完成,确定退出吗?',
  431. success: function(res) {
  432. if (res.confirm || res.index == 0) {
  433. _this.isClose = true;
  434. uni.navigateBack({
  435. delta: 1
  436. });
  437. }
  438. }
  439. });
  440. }
  441. return true;
  442. }
  443. },
  444. // 添加考评模板
  445. onNavigationBarButtonTap(e) {
  446. // 且当前没编辑图片或抓拍图片
  447. if (e.index == 0 && !this.isEditImg) {
  448. uni.navigateTo({
  449. url: '/pages/evaluatePlan/evaluatePlan?id=' + this.assessSchemeId + '&types='+this.types
  450. });
  451. } else {
  452. uni.showToast({
  453. icon: 'none',
  454. title: '正在编辑图片,不能选择考评方案'
  455. });
  456. }
  457. }
  458. };
  459. </script>
  460. <style></style>