feedback.js 8.1 KB

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