feedback.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  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].thumbTempFilePath).then((data) => {
  201. if(imgs.length > 0 && imgs[0].type == 'video') {
  202. that.setData({
  203. ['imgs[' + 0 + '].thumb']: data.data.url
  204. })
  205. } else {
  206. imgs.unshift({
  207. type: 'video',
  208. thumb: data.data.url,
  209. url: ''
  210. })
  211. that.setData({ imgs })
  212. }
  213. // that.setData({ imgs })
  214. wx.hideLoading()
  215. });
  216. that.upload(tempFiles[0].tempFilePath).then((data) => {
  217. if(imgs.length > 0 && imgs[0].type == 'video') {
  218. that.setData({
  219. ['imgs[' + 0 + '].url']: data.data.url
  220. })
  221. } else {
  222. imgs.unshift({
  223. type: 'video',
  224. thumb: '',
  225. url: data.data.url
  226. })
  227. that.setData({ imgs })
  228. }
  229. // imgs.unshift({
  230. // type: 'video',
  231. // thumb: tempFiles[0].thumbTempFilePath,
  232. // url: data.data.url
  233. // })
  234. // that.setData({ imgs })
  235. wx.hideLoading()
  236. });
  237. }
  238. })
  239. },
  240. /**
  241. * 选择星星
  242. */
  243. onChange(e) {
  244. let index = e.currentTarget.dataset.index
  245. let value = e.detail.value
  246. this.setData({
  247. ['raterList[' + index + '].num']: value
  248. })
  249. },
  250. /**
  251. * 提交反馈
  252. */
  253. onSubmit() {
  254. // api/feedback/add
  255. let { orderId,value,raterList,edit } = this.data;
  256. console.log(this.data.imgs)
  257. console.log(edit)
  258. if(edit == "true") {
  259. this.editFeedbackUpdate()
  260. } else {
  261. post('api/feedback/add',{
  262. order_id: orderId,
  263. content: value,
  264. media_list: JSON.stringify(this.data.imgs),
  265. score_whole: raterList[0].num,
  266. score_effect: raterList[1].num,
  267. score_price: raterList[2].num,
  268. score_kind: raterList[3].num,
  269. score_safe: raterList[4].num,
  270. },(res) => {
  271. console.log(res)
  272. wx.showToast({
  273. title: res.msg,
  274. icon: 'none'
  275. })
  276. setTimeout(() => {
  277. wx.navigateBack()
  278. }, 1500);
  279. })
  280. }
  281. },
  282. /**
  283. * 上传视频/图片
  284. */
  285. upload(filePath) {
  286. let that = this;
  287. // 上传类型/业务类型:avatar头像,order订单反馈,check检查表反馈
  288. return new Promise((resolve,reject) => {
  289. let { imgs } = this.data;
  290. wx.uploadFile({
  291. url: 'https://store.test-api.ijolijoli.com/api/upload',
  292. header: {
  293. token: wx.getStorageSync('token') || '',
  294. },
  295. filePath,
  296. name: 'file',
  297. formData: {
  298. 'type': 'order'
  299. },
  300. success(res) {
  301. console.log(res)
  302. if(res.statusCode == 200 && res.data) {
  303. let data = JSON.parse(res.data);
  304. if(data.code == 200 && data.data) {
  305. resolve(data)
  306. } else {
  307. wx.showToast({
  308. title: '上传失败',
  309. icon: 'none'
  310. })
  311. }
  312. } else {
  313. wx.showToast({
  314. title: '上传失败',
  315. icon: 'none'
  316. })
  317. }
  318. },
  319. fail(err) {
  320. wx.showToast({
  321. title: '上传失败',
  322. icon: 'none'
  323. })
  324. }
  325. })
  326. })
  327. },
  328. /**
  329. * 获取订单反馈详情
  330. * api/feedback/info
  331. */
  332. getfeedbackInfo(id) {
  333. get('api/feedback/info',{ id },(res) => {
  334. this.setData({
  335. value: res.data.content,
  336. imgs: JSON.parse(res.data.media_list),
  337. raterList: []
  338. })
  339. })
  340. },
  341. /**
  342. * 编辑反馈记录
  343. * api/feedback/update
  344. */
  345. editFeedbackUpdate() {
  346. let { orderId,value,imgs } = this.data;
  347. post('api/feedback/update',{
  348. id: orderId,
  349. content: value,
  350. media_list: JSON.stringify(imgs)
  351. },(res) => {
  352. wx.showToast({
  353. title: res.msg,
  354. icon: 'none'
  355. })
  356. setTimeout(() => {
  357. wx.navigateBack()
  358. }, 1500);
  359. console.log(res)
  360. })
  361. }
  362. })