feedback.js 7.5 KB

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