feedback.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. import {
  2. get,
  3. post,
  4. api_url
  5. } from '../../utils/http';
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. maxlength: 500,
  12. number: 0,
  13. value: "",
  14. imgs: [],
  15. // imgs: [
  16. // {
  17. // type: "image",
  18. // url: "https://img1.baidu.com/it/u=202543353,3627416815&fm=26&fmt=auto"
  19. // },
  20. // {
  21. // type: "image",
  22. // url: "https://img0.baidu.com/it/u=745609344,230882238&fm=26&fmt=auto"
  23. // },
  24. // {
  25. // type: "image",
  26. // url: "https://img0.baidu.com/it/u=286636366,3227707112&fm=26&fmt=auto"
  27. // },
  28. // {
  29. // type: "image",
  30. // url: "https://img1.baidu.com/it/u=2450865760,444795162&fm=26&fmt=auto"
  31. // },
  32. // {
  33. // type: "image",
  34. // url: "https://img0.baidu.com/it/u=4226275504,4103997964&fm=26&fmt=auto"
  35. // },
  36. // {
  37. // type: "image",
  38. // url: "https://img0.baidu.com/it/u=2247422843,411257408&fm=26&fmt=auto"
  39. // },
  40. // ],
  41. raterList: [
  42. {
  43. text: '整体满意度',
  44. num: 1
  45. },
  46. {
  47. text: '效果认可度',
  48. num: 2
  49. },
  50. {
  51. text: '价格接受度',
  52. num: 3
  53. },
  54. {
  55. text: '类别满意度',
  56. num: 4
  57. },
  58. {
  59. text: '安全认可度',
  60. num: 5
  61. },
  62. ],
  63. raterStatus: {
  64. 1: '差',
  65. 2: '较差',
  66. 3: '一般',
  67. 4: '满意',
  68. 5: '非常好',
  69. },
  70. edit: "false"
  71. },
  72. /**
  73. * 生命周期函数--监听页面加载
  74. */
  75. onLoad: function (options) {
  76. console.log(options)
  77. if(options.orderId) {
  78. this.setData({
  79. orderId: options.orderId,
  80. cover: options.cover,
  81. name: options.name,
  82. edit: options.edit || "false"
  83. })
  84. if(options.edit == "true") {
  85. this.getfeedbackInfo(options.orderId)
  86. }
  87. }
  88. },
  89. /**
  90. * 生命周期函数--监听页面初次渲染完成
  91. */
  92. onReady: function () {
  93. },
  94. /**
  95. * 生命周期函数--监听页面显示
  96. */
  97. onShow: function () {
  98. },
  99. /**
  100. * 生命周期函数--监听页面隐藏
  101. */
  102. onHide: function () {
  103. },
  104. /**
  105. * 生命周期函数--监听页面卸载
  106. */
  107. onUnload: function () {
  108. },
  109. /**
  110. * 页面相关事件处理函数--监听用户下拉动作
  111. */
  112. onPullDownRefresh: function () {
  113. },
  114. /**
  115. * 页面上拉触底事件的处理函数
  116. */
  117. onReachBottom: function () {
  118. },
  119. /**
  120. * 用户点击右上角分享
  121. */
  122. onShareAppMessage: function () {
  123. },
  124. /**
  125. * 监听文本域
  126. */
  127. bindTextAreaInput(e) {
  128. this.setData({
  129. number: e.detail.cursor,
  130. value: e.detail.value
  131. })
  132. },
  133. /**
  134. * 预览图片和视频
  135. */
  136. previewMedia(e) {
  137. let arr = this.data.imgs
  138. let current = e.currentTarget.dataset.index
  139. wx.previewMedia({
  140. sources: arr,
  141. current
  142. })
  143. },
  144. /**
  145. * 删除列表项
  146. */
  147. onDeleteItem(e) {
  148. let imgs = this.data.imgs;
  149. imgs.splice(e.currentTarget.dataset.index, 1);
  150. this.setData({ imgs })
  151. console.log(imgs)
  152. },
  153. /**
  154. * 选择图片
  155. */
  156. chooseImage() {
  157. let that = this;
  158. let imgs = this.data.imgs;
  159. let count = 9 - this.data.imgs.length
  160. wx.chooseImage({
  161. count,
  162. sizeType: ['original', 'compressed'],
  163. sourceType: ['album', 'camera'],
  164. success (res) {
  165. wx.showLoading({
  166. title: '正在上传图片',
  167. mask: true
  168. });
  169. const tempFiles = res.tempFiles
  170. tempFiles.forEach((item) => {
  171. that.upload(item.path).then((data) => {
  172. imgs.push({
  173. type: 'image',
  174. url: data.data.url,
  175. })
  176. that.setData({ imgs })
  177. wx.hideLoading()
  178. });
  179. })
  180. }
  181. })
  182. },
  183. /**
  184. * 选择视频
  185. */
  186. chooseVideo(){
  187. let that = this;
  188. let imgs = this.data.imgs;
  189. wx.chooseMedia({
  190. count: 1,
  191. mediaType: ['video'],
  192. sourceType: ['album', 'camera'],
  193. maxDuration: 30,
  194. camera: 'back',
  195. success(res) {
  196. wx.showLoading({
  197. title: '正在上传视频',
  198. mask: true
  199. });
  200. const tempFiles = res.tempFiles
  201. that.upload(tempFiles[0].thumbTempFilePath).then((data) => {
  202. if(imgs.length > 0 && imgs[0].type == 'video') {
  203. that.setData({
  204. ['imgs[' + 0 + '].thumb']: data.data.url
  205. })
  206. } else {
  207. imgs.unshift({
  208. type: 'video',
  209. thumb: data.data.url,
  210. url: ''
  211. })
  212. that.setData({ imgs })
  213. }
  214. // that.setData({ imgs })
  215. wx.hideLoading()
  216. });
  217. that.upload(tempFiles[0].tempFilePath).then((data) => {
  218. if(imgs.length > 0 && imgs[0].type == 'video') {
  219. that.setData({
  220. ['imgs[' + 0 + '].url']: data.data.url
  221. })
  222. } else {
  223. imgs.unshift({
  224. type: 'video',
  225. thumb: '',
  226. url: data.data.url
  227. })
  228. that.setData({ imgs })
  229. }
  230. // imgs.unshift({
  231. // type: 'video',
  232. // thumb: tempFiles[0].thumbTempFilePath,
  233. // url: data.data.url
  234. // })
  235. // that.setData({ imgs })
  236. wx.hideLoading()
  237. });
  238. }
  239. })
  240. },
  241. /**
  242. * 选择星星
  243. */
  244. onChange(e) {
  245. let index = e.currentTarget.dataset.index
  246. let value = e.detail.value
  247. this.setData({
  248. ['raterList[' + index + '].num']: value
  249. })
  250. },
  251. /**
  252. * 提交反馈
  253. */
  254. onSubmit() {
  255. // api/feedback/add
  256. let { orderId,value,raterList,edit } = this.data;
  257. console.log(this.data.imgs)
  258. console.log(edit)
  259. if(edit == "true") {
  260. this.editFeedbackUpdate()
  261. } else {
  262. post('api/feedback/add',{
  263. order_id: orderId,
  264. content: value,
  265. media_list: JSON.stringify(this.data.imgs),
  266. score_whole: raterList[0].num,
  267. score_effect: raterList[1].num,
  268. score_price: raterList[2].num,
  269. score_kind: raterList[3].num,
  270. score_safe: raterList[4].num,
  271. },(res) => {
  272. console.log(res)
  273. wx.showToast({
  274. title: res.msg,
  275. icon: 'none'
  276. })
  277. setTimeout(() => {
  278. wx.navigateBack()
  279. }, 1500);
  280. })
  281. }
  282. },
  283. /**
  284. * 上传视频/图片
  285. */
  286. upload(filePath) {
  287. let that = this;
  288. // 上传类型/业务类型:avatar头像,order订单反馈,check检查表反馈
  289. return new Promise((resolve,reject) => {
  290. let { imgs } = this.data;
  291. wx.uploadFile({
  292. url: `${api_url}api/upload`,
  293. header: {
  294. token: wx.getStorageSync('token') || '',
  295. },
  296. filePath,
  297. name: 'file',
  298. formData: {
  299. 'type': 'order'
  300. },
  301. success(res) {
  302. console.log(res)
  303. if(res.statusCode == 200 && res.data) {
  304. let data = JSON.parse(res.data);
  305. if(data.code == 200 && data.data) {
  306. resolve(data)
  307. } else {
  308. wx.showToast({
  309. title: '上传失败',
  310. icon: 'none'
  311. })
  312. }
  313. } else {
  314. wx.showToast({
  315. title: '上传失败',
  316. icon: 'none'
  317. })
  318. }
  319. },
  320. fail(err) {
  321. wx.showToast({
  322. title: '上传失败',
  323. icon: 'none'
  324. })
  325. }
  326. })
  327. })
  328. },
  329. /**
  330. * 获取订单反馈详情
  331. * api/feedback/info
  332. */
  333. getfeedbackInfo(id) {
  334. get('api/feedback/info',{ id },(res) => {
  335. this.setData({
  336. value: res.data.content,
  337. imgs: JSON.parse(res.data.media_list),
  338. raterList: []
  339. })
  340. })
  341. },
  342. /**
  343. * 编辑反馈记录
  344. * api/feedback/update
  345. */
  346. editFeedbackUpdate() {
  347. let { orderId,value,imgs } = this.data;
  348. post('api/feedback/update',{
  349. id: orderId,
  350. content: value,
  351. media_list: JSON.stringify(imgs)
  352. },(res) => {
  353. wx.showToast({
  354. title: res.msg,
  355. icon: 'none'
  356. })
  357. setTimeout(() => {
  358. wx.navigateBack()
  359. }, 1500);
  360. console.log(res)
  361. })
  362. }
  363. })