index.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. // pages/noticeDetail/detail.js
  2. const app = getApp();
  3. let id = 0;
  4. //创建播放管理器
  5. let innerAudioContext = null;
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. showModal: false, // 显示modal弹窗
  12. single: false,
  13. reason: '',
  14. details: {},
  15. detail: [],
  16. taskContent: {
  17. title: '任务内容',
  18. showImg: '/images/icons/play.png',
  19. playImg: '/images/icons/play.png',
  20. stopPlayImg: '/images/icons/zanting.png',
  21. taskRadioType: 1,
  22. radioUrl: '',
  23. second: ''
  24. },
  25. star: 5,
  26. starMap: [
  27. '较差',
  28. '一般',
  29. '良好',
  30. '优秀',
  31. '完美'
  32. ],
  33. checked: '/images/icons/check_star.png',
  34. unchecked: '/images/icons/shoudaopingjia@2x.png'
  35. },
  36. /**
  37. * 生命周期函数--监听页面加载
  38. */
  39. onLoad: function (options) {
  40. id = options.id;
  41. this.showData();
  42. // this.showTypeData();
  43. },
  44. /**
  45. * 生命周期函数--监听页面显示
  46. */
  47. onShow: function () {
  48. var that = this;
  49. app.ajaxReadyCallback = res => {
  50. var apiname = res.data.apiname;
  51. if (apiname == 'cancel') {
  52. wx.showToast({
  53. title: '取消成功!',
  54. icon: 'success',
  55. duration: 1500
  56. });
  57. that.setData({
  58. reason: ''
  59. });
  60. that.showData();
  61. } else if (apiname == 'comment') {
  62. wx.showToast({
  63. title: '感谢您的评价!',
  64. icon: 'success',
  65. duration: 1500
  66. });
  67. that.setData({
  68. complain: ''
  69. });
  70. that.showData();
  71. } else if (apiname == 'orderConveyType') {
  72. var arr = [];
  73. var detail = res.data.data;
  74. for (var i in detail) {
  75. var genre = {
  76. genre: i,
  77. detail: detail[i]
  78. }
  79. arr.push(genre);
  80. }
  81. that.setData({
  82. detail: arr,
  83. });
  84. } else {
  85. var detail = res.data.data;
  86. if (!detail.images) {
  87. detail.images = [];
  88. } else {
  89. detail.images = detail.images.split(',');
  90. }
  91. if (!detail.lastFinishImg) {
  92. detail.lastFinishImg = [];
  93. } else {
  94. detail.lastFinishImg = detail.lastFinishImg.split(',');
  95. }
  96. that.setData({
  97. details: detail,
  98. });
  99. wx.setNavigationBarTitle({
  100. title: '订单查看'
  101. })
  102. }
  103. }
  104. },
  105. showData: function () {
  106. app.ajax({
  107. url: app.globalData.serverUrl + '/orders/detail',
  108. type: 'POST',
  109. data: {
  110. orderId: id
  111. }
  112. });
  113. },
  114. showTypeData: function () {
  115. app.ajax({
  116. url: app.globalData.serverUrl + '/orderConveyType/list',
  117. type: 'POST',
  118. apiname: 'orderConveyType',
  119. data: {
  120. orderId: id
  121. }
  122. });
  123. },
  124. //图片预览
  125. previewImage: function (e) {
  126. var current = e.target.dataset.src;
  127. wx.previewImage({
  128. current: current, // 当前显示图片的http链接
  129. urls: this.data.details.images || this.data.details.lastFinishImg, // 需要预览的图片http链接列表
  130. success: function (e) {
  131. console.log(e);
  132. }
  133. })
  134. },
  135. handlePreviewImage: function (e) {
  136. var current = e.target.dataset.src;
  137. wx.previewImage({
  138. current: current, // 当前显示图片的http链接
  139. urls: this.data.details.lastFinishImg, // 需要预览的图片http链接列表
  140. success: function (e) {
  141. console.log(e);
  142. }
  143. })
  144. },
  145. handleShowModel: function () {
  146. this.setData({ showModal: true })
  147. },
  148. //播放录音
  149. playRadio: function (event) {
  150. var taskContent = this.data.taskContent;
  151. var radioType = taskContent.taskRadioType;
  152. if (radioType == 1) {
  153. if (!this.data.details.voices) {
  154. wx.showToast({
  155. title: '无音频文件!',
  156. icon: 'none',
  157. duration: 1500
  158. })
  159. return false;
  160. }
  161. var radioUrl = this.data.details.voices.split(',');
  162. innerAudioContext = null;
  163. innerAudioContext = wx.createInnerAudioContext();
  164. innerAudioContext.autoplay = false;
  165. innerAudioContext.src = radioUrl[0];
  166. innerAudioContext.play();
  167. setTimeout(() => {
  168. innerAudioContext.duration;
  169. },300)
  170. innerAudioContext.onTimeUpdate(() => {
  171. var task = this.data.taskContent;
  172. task.second = innerAudioContext.duration.toFixed(1)+'"';
  173. this.setData({
  174. taskContent: task
  175. });
  176. })
  177. innerAudioContext.onPlay(() => {
  178. taskContent.taskRadioType = 2;
  179. taskContent.showImg = taskContent.stopPlayImg;
  180. this.setData({
  181. taskContent: taskContent
  182. })
  183. });
  184. innerAudioContext.onError((res) => {
  185. wx.showToast({
  186. title: '语音播放失败!',
  187. icon: 'none',
  188. duration: 500
  189. })
  190. });
  191. //监听音频自然播放至结束的事件
  192. innerAudioContext.onEnded((res) => {
  193. taskContent.taskRadioType = 1;
  194. taskContent.showImg = taskContent.playImg;
  195. this.setData({
  196. taskContent: taskContent
  197. })
  198. });
  199. } else if (radioType == 2) {
  200. innerAudioContext.stop();
  201. //监听音频停止事件
  202. innerAudioContext.onStop((res) => {
  203. taskContent.taskRadioType = 1;
  204. taskContent.showImg = taskContent.playImg;
  205. this.setData({
  206. taskContent: taskContent
  207. })
  208. });
  209. }
  210. },
  211. videotap: function (e) {
  212. var video = e.target.dataset.video;
  213. app.gotopage('/pages/video/index', { video: video });
  214. },
  215. handleStarChoose(e) {
  216. let star = parseInt(e.target.dataset.star) || 0;
  217. this.setData({
  218. star: star,
  219. });
  220. },
  221. // 点击取消按钮的回调函数
  222. modalCancel() {
  223. this.setData({ showModal: false })
  224. },
  225. getValue(e) {
  226. this.setData({
  227. reason: e.detail.value
  228. })
  229. },
  230. // 取消订单
  231. handleCancelOrder: function () {
  232. if (this.data.reason == '') {
  233. wx.showToast({
  234. title: '取消原因不能为空!',
  235. icon: 'none',
  236. duration: 1500
  237. })
  238. setTimeout(function () {
  239. wx.hideToast()
  240. }, 2000)
  241. } else {
  242. app.ajax({
  243. url: app.globalData.serverUrl + 'orders/updateOrderModeByUser',
  244. type: 'POST',
  245. apiname: 'cancel',
  246. data: {
  247. orderId: this.data.details.id,
  248. reason: this.data.reason,
  249. }
  250. });
  251. }
  252. },
  253. // 评价
  254. handleComplainOrder: function (e) {
  255. if (e.detail.value.content.length == 0 || e.detail.value.content == '') {
  256. wx.showToast({
  257. title: '评价内容不能为空!',
  258. icon: 'none',
  259. duration: 1500
  260. })
  261. setTimeout(function () {
  262. wx.hideToast()
  263. }, 2000)
  264. } else {
  265. app.ajax({
  266. url: app.globalData.serverUrl + '/comment/add',
  267. type: 'POST',
  268. apiname: 'comment',
  269. data: {
  270. score: this.data.star,
  271. content: e.detail.value.content,
  272. type: this.data.details.workTypeMode,
  273. fromId: this.data.details.id
  274. }
  275. });
  276. }
  277. },
  278. handleTransportType(event) {
  279. var id = event.currentTarget.dataset.id;
  280. var type = event.currentTarget.dataset.type;
  281. var num = event.currentTarget.dataset.num;
  282. wx.navigateTo({
  283. url: '/pages/order/type/index?id=' + id + '&type=' + type + '&num=' + num
  284. })
  285. }
  286. })