shopTour.vue 12 KB

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