shopTour.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  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. // 相同方案无需重置更新
  266. if(row.id == this.assessSchemeId){
  267. return
  268. }
  269. updateTaskItem({
  270. id: this.taskId,
  271. assessSchemeId: row.id,
  272. assessSchemeName: row.name
  273. }).then(res => {
  274. console.log(res, 'updateTaskItem');
  275. if (res.status == 200) {
  276. // 重置页面
  277. this.wv.evalJS('vm.resetPage()');
  278. this.getTaskDetail();
  279. this.getTaskItem();
  280. } else {
  281. uni.showToast({
  282. icon: 'none',
  283. title: res.message
  284. });
  285. }
  286. });
  287. },
  288. // 获取视频列表
  289. getVideoList() {
  290. let list = this.$store.state.vuex_storeVideoList;
  291. this.wv.evalJS("vm.setVideoList('" + JSON.stringify(list) + "')");
  292. },
  293. // 获取视频地址
  294. getStoreVideoUrl(item) {
  295. getVideoUrl({ streamId: item.streamId, outProtocol: 'hls' }).then(res => {
  296. console.log(res);
  297. if (res.status == 200 && res.data) {
  298. this.wv.evalJS("vm.getVideoUrlSuccess('" + res.data.url + "')");
  299. } else {
  300. uni.showToast({
  301. icon: 'none',
  302. title: '获取视频地址失败,请返回重试'
  303. });
  304. }
  305. });
  306. },
  307. // 提交本次任务
  308. submitTask() {
  309. const _this = this;
  310. clzConfirm({
  311. title: '提示',
  312. content: '确定提交本次巡店?',
  313. success: function(res) {
  314. console.log(res, '--------');
  315. if (res.confirm || res.index == 0) {
  316. submitTask({
  317. id: _this.taskId
  318. }).then(ret => {
  319. console.log(ret);
  320. if (ret.status == 200) {
  321. _this.isClose = true;
  322. // 打开完成页面
  323. uni.redirectTo({
  324. url: '/pages/shopTourCompleted/shopTourCompleted?taskId=' + _this.taskId
  325. });
  326. } else {
  327. _this.isClose = false;
  328. }
  329. uni.showToast({
  330. icon: 'none',
  331. title: ret.message
  332. });
  333. });
  334. }
  335. }
  336. });
  337. },
  338. // 现场巡店下一步签字
  339. nextStep() {
  340. uni.navigateTo({
  341. url: '/pages/shopTourOver/shopTourOver?taskId=' + this.taskId
  342. });
  343. }
  344. },
  345. onLoad(options) {
  346. console.log(options, 'options');
  347. // 巡店类型,视频还时现场
  348. this.types = options.types;
  349. this.taskId = options.taskId;
  350. this.storeId = options.storeId;
  351. this.restart = options.restart;
  352. },
  353. onUnload() {
  354. uni.$off('resetTaskKpItem');
  355. uni.$off('closeTour');
  356. },
  357. onReady() {
  358. let _this = this;
  359. _this.isClose = false;
  360. // #ifdef APP-PLUS
  361. //获取当前页面的webview对象
  362. var currentWebview = this.$mp.page.$getAppWebview();
  363. //如果是页面初始化调用时,需要延时一下
  364. setTimeout(function() {
  365. _this.wv = currentWebview.children()[0];
  366. _this.wv.evalJS("vm.setTyps('" + _this.types + "')");
  367. // 获取视频列表
  368. if (_this.types == 'video') {
  369. _this.getVideoList();
  370. }
  371. if (_this.restart == 1) {
  372. // 重新开始
  373. _this.creatTask(1);
  374. } else if (_this.restart == 0) {
  375. // 继续上次巡店
  376. //查询任务明细
  377. _this.getTaskDetail();
  378. _this.getTaskItem();
  379. } else {
  380. // 首次新建
  381. _this.creatTask(0);
  382. }
  383. }, 500);
  384. // #endif
  385. // 监听选择方案后事件,schemeId 方案id
  386. uni.$on('resetTaskKpItem', row => {
  387. _this.updateTaskItem(row);
  388. });
  389. // 关闭当前页面
  390. uni.$on('closeTour', flag => {
  391. if (flag == 1) {
  392. this.isClose = true;
  393. uni.navigateBack();
  394. }
  395. });
  396. },
  397. // 监听返回键
  398. onBackPress() {
  399. console.log(this.isEditImg, 'onBackPress');
  400. let _this = this;
  401. if (!_this.isClose) {
  402. // 正在编辑图片
  403. if (this.isEditImg) {
  404. // 关闭编辑图片
  405. _this.wv.evalJS('vm.closeImgsEdit()');
  406. }
  407. // 正在拍照
  408. else if (this.showPz) {
  409. // 关闭拍照弹框
  410. _this.wv.evalJS('vm.onClosePz()');
  411. } else {
  412. clzConfirm({
  413. title: '提示',
  414. content: '巡店还未完成,确定退出吗?',
  415. success: function(res) {
  416. if (res.confirm || res.index == 0) {
  417. _this.isClose = true;
  418. uni.navigateBack({
  419. delta: 1
  420. });
  421. }
  422. }
  423. });
  424. }
  425. return true;
  426. }
  427. },
  428. // 添加考评模板
  429. onNavigationBarButtonTap(e) {
  430. // 且当前没编辑图片或抓拍图片
  431. if (e.index == 0 && !this.isEditImg) {
  432. uni.navigateTo({
  433. url: '/pages/evaluatePlan/evaluatePlan?id=' + this.assessSchemeId
  434. });
  435. } else {
  436. uni.showToast({
  437. icon: 'none',
  438. title: '正在编辑图片,不能选择考评方案'
  439. });
  440. }
  441. }
  442. };
  443. </script>
  444. <style></style>