shopTour.vue 11 KB

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