shopTour.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  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. console.log(JSON.stringify(res.tempFilePaths));
  163. saveImgToAliOss(res.tempFilePaths[0], function(ret) {
  164. console.log(ret);
  165. _this.wv.evalJS("vm.takePhotoSuccess('" + ret.data + "')");
  166. });
  167. }
  168. });
  169. },
  170. // 删除图片
  171. delImgs(index) {
  172. const _this = this;
  173. clzConfirm({
  174. title: '提示',
  175. content: '确定删除此图片,删除后无法恢复?',
  176. success: function(res) {
  177. if (res.confirm || res.index == 0) {
  178. _this.wv.evalJS('vm.delImgsSuccess(' + index + ')');
  179. }
  180. }
  181. });
  182. },
  183. // 删除考评项
  184. delKpItem(id) {
  185. const _this = this;
  186. clzConfirm({
  187. title: '提示',
  188. content: '确定删除此考评项,删除后无法恢复?',
  189. success: function(res) {
  190. if (res.confirm || res.index == 0) {
  191. delTaskItem({ id: id }).then(ret => {
  192. if (ret.status == 200) {
  193. _this.wv.evalJS('vm.delKpItemSuccess(' + id + ')');
  194. }
  195. uni.showToast({
  196. icon: 'none',
  197. title: ret.message
  198. });
  199. });
  200. }
  201. }
  202. });
  203. },
  204. // 上传编辑后的图片到阿里云
  205. uploadImg(formData) {
  206. const _this = this;
  207. saveBase64ToAliOss(formData, function(res) {
  208. // console.log(res);
  209. // 关闭编辑图片
  210. _this.wv.evalJS('vm.closeImgsEdit()');
  211. // 更新编辑后的图片
  212. _this.wv.evalJS("vm.updateItemImg('" + res.data + "')");
  213. });
  214. },
  215. // 开始巡店(重新开始),isNew 0 新建,1 重新开始
  216. creatTask(isNew) {
  217. // 新建任务,只传门店id
  218. let parms = {
  219. storeId: this.storeId,
  220. type: this.types == 'video' ? 'VIDEO_INSPECTION' : 'SPOT_INSPECTION'
  221. };
  222. // 重新开始,要传任务id
  223. if (isNew) {
  224. parms.id = this.taskId;
  225. }
  226. // 现场巡店,需要保存签到信息
  227. if (this.types == 'scene') {
  228. let signin = this.$store.state.vuex_sceneTaskSignIn;
  229. parms.inspectorPositionAddr = signin.inspectorPositionAddr;
  230. parms.inspectorPositionPhotoPath = signin.inspectorPositionPhotoPath;
  231. }
  232. console.log(parms)
  233. taskStart(parms).then(res => {
  234. console.log(res, parms, 'taskStart');
  235. if (res.status == 200) {
  236. this.taskId = res.data.id;
  237. // 创建成功,查询任务明细
  238. this.getTaskDetail();
  239. this.getTaskItem();
  240. } else {
  241. uni.showToast({
  242. icon: 'none',
  243. title: res.message
  244. });
  245. }
  246. });
  247. },
  248. // 查询任务明细
  249. getTaskDetail() {
  250. getTaskDetail({ id: this.taskId }).then(res => {
  251. this.assessSchemeId = res.data.assessSchemeId; // 方案id
  252. this.wv.evalJS("vm.getTaskDetail('" + JSON.stringify(res.data) + "')");
  253. });
  254. },
  255. // 任务考评项目明细
  256. getTaskItem() {
  257. getTaskItem({ id: this.taskId }).then(res => {
  258. console.log(res, 'getTaskItem');
  259. this.wv.evalJS("vm.getTaskItem('" + JSON.stringify(res.data) + "')");
  260. });
  261. },
  262. // 更新方案项目
  263. updateTaskItem(row) {
  264. console.log(row);
  265. updateTaskItem({
  266. id: this.taskId,
  267. assessSchemeId: row.id,
  268. assessSchemeName: row.name
  269. }).then(res => {
  270. console.log(res, 'updateTaskItem');
  271. if (res.status == 200) {
  272. // 重置页面
  273. this.wv.evalJS('vm.resetPage()');
  274. this.getTaskDetail();
  275. this.getTaskItem();
  276. } else {
  277. uni.showToast({
  278. icon: 'none',
  279. title: res.message
  280. });
  281. }
  282. });
  283. },
  284. // 获取视频列表
  285. getVideoList() {
  286. let list = this.$store.state.vuex_storeVideoList;
  287. this.wv.evalJS("vm.setVideoList('" + JSON.stringify(list) + "')");
  288. },
  289. // 获取视频地址
  290. getStoreVideoUrl(item) {
  291. getVideoUrl({ streamId: item.streamId, outProtocol: 'hls' }).then(res => {
  292. console.log(res);
  293. if (res.status == 200 && res.data) {
  294. this.wv.evalJS("vm.getVideoUrlSuccess('" + res.data.url + "')");
  295. } else {
  296. uni.showToast({
  297. icon: 'none',
  298. title: '获取视频地址失败,请返回重试'
  299. });
  300. }
  301. });
  302. },
  303. // 提交本次任务
  304. submitTask() {
  305. const _this = this;
  306. clzConfirm({
  307. title: '提示',
  308. content: '确定提交本次巡店?',
  309. success: function(res) {
  310. console.log(res, '--------');
  311. if (res.confirm || res.index == 0) {
  312. submitTask({
  313. id: _this.taskId
  314. }).then(ret => {
  315. console.log(ret);
  316. if (ret.status == 200) {
  317. _this.isClose = true;
  318. // 打开完成页面
  319. uni.redirectTo({
  320. url: '/pages/shopTourCompleted/shopTourCompleted?taskId=' + _this.taskId
  321. });
  322. } else {
  323. _this.isClose = false;
  324. }
  325. uni.showToast({
  326. icon: 'none',
  327. title: ret.message
  328. });
  329. });
  330. }
  331. }
  332. });
  333. },
  334. // 现场巡店下一步签字
  335. nextStep() {
  336. uni.navigateTo({
  337. url: '/pages/shopTourOver/shopTourOver?taskId=' + this.taskId
  338. });
  339. }
  340. },
  341. onLoad(options) {
  342. console.log(options, 'options');
  343. // 巡店类型,视频还时现场
  344. this.types = options.types;
  345. this.taskId = options.taskId;
  346. this.storeId = options.storeId;
  347. this.restart = options.restart;
  348. },
  349. onUnload() {
  350. uni.$off('resetTaskKpItem');
  351. uni.$off('closeTour');
  352. },
  353. onReady() {
  354. let _this = this;
  355. _this.isClose = false;
  356. // #ifdef APP-PLUS
  357. //获取当前页面的webview对象
  358. var currentWebview = this.$mp.page.$getAppWebview();
  359. //如果是页面初始化调用时,需要延时一下
  360. setTimeout(function() {
  361. _this.wv = currentWebview.children()[0];
  362. _this.wv.evalJS("vm.setTyps('" + _this.types + "')");
  363. // 获取视频列表
  364. if (_this.types == 'video') {
  365. _this.getVideoList();
  366. }
  367. if (_this.restart == 1) {
  368. // 重新开始
  369. _this.creatTask(1);
  370. } else if (_this.restart == 0) {
  371. // 继续上次巡店
  372. //查询任务明细
  373. _this.getTaskDetail();
  374. _this.getTaskItem();
  375. } else {
  376. // 首次新建
  377. _this.creatTask(0);
  378. }
  379. }, 500);
  380. // #endif
  381. // 监听选择方案后事件,schemeId 方案id
  382. uni.$on('resetTaskKpItem', row => {
  383. _this.updateTaskItem(row);
  384. });
  385. // 关闭当前页面
  386. uni.$on('closeTour', flag => {
  387. if (flag == 1) {
  388. this.isClose = true;
  389. uni.navigateBack();
  390. }
  391. });
  392. },
  393. // 监听返回键
  394. onBackPress() {
  395. console.log(this.isEditImg, 'onBackPress');
  396. let _this = this;
  397. if (!_this.isClose) {
  398. // 正在编辑图片
  399. if (this.isEditImg) {
  400. // 关闭编辑图片
  401. _this.wv.evalJS('vm.closeImgsEdit()');
  402. }
  403. // 正在拍照
  404. else if (this.showPz) {
  405. // 关闭拍照弹框
  406. _this.wv.evalJS('vm.onClosePz()');
  407. } else {
  408. clzConfirm({
  409. title: '提示',
  410. content: '巡店还未完成,确定退出吗?',
  411. success: function(res) {
  412. if (res.confirm || res.index == 0) {
  413. _this.isClose = true;
  414. uni.navigateBack({
  415. delta: 1
  416. });
  417. }
  418. }
  419. });
  420. }
  421. return true;
  422. }
  423. },
  424. // 添加考评模板
  425. onNavigationBarButtonTap(e) {
  426. // 且当前没编辑图片或抓拍图片
  427. if (e.index == 0 && !this.isEditImg) {
  428. uni.navigateTo({
  429. url: '/pages/evaluatePlan/evaluatePlan?id=' + this.assessSchemeId
  430. });
  431. } else {
  432. uni.showToast({
  433. icon: 'none',
  434. title: '正在编辑图片,不能选择考评方案'
  435. });
  436. }
  437. }
  438. };
  439. </script>
  440. <style></style>