feedback.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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. },
  70. /**
  71. * 生命周期函数--监听页面加载
  72. */
  73. onLoad: function (options) {
  74. if(options.orderId) {
  75. this.setData({
  76. orderId: options.orderId,
  77. cover: options.cover,
  78. name: options.name
  79. })
  80. }
  81. },
  82. /**
  83. * 生命周期函数--监听页面初次渲染完成
  84. */
  85. onReady: function () {
  86. },
  87. /**
  88. * 生命周期函数--监听页面显示
  89. */
  90. onShow: function () {
  91. },
  92. /**
  93. * 生命周期函数--监听页面隐藏
  94. */
  95. onHide: function () {
  96. },
  97. /**
  98. * 生命周期函数--监听页面卸载
  99. */
  100. onUnload: function () {
  101. },
  102. /**
  103. * 页面相关事件处理函数--监听用户下拉动作
  104. */
  105. onPullDownRefresh: function () {
  106. },
  107. /**
  108. * 页面上拉触底事件的处理函数
  109. */
  110. onReachBottom: function () {
  111. },
  112. /**
  113. * 用户点击右上角分享
  114. */
  115. onShareAppMessage: function () {
  116. },
  117. /**
  118. * 监听文本域
  119. */
  120. bindTextAreaInput(e) {
  121. this.setData({
  122. number: e.detail.cursor,
  123. value: e.detail.value
  124. })
  125. },
  126. /**
  127. * 预览图片和视频
  128. */
  129. previewMedia(e) {
  130. let arr = this.data.imgs
  131. let current = e.currentTarget.dataset.index
  132. wx.previewMedia({
  133. sources: arr,
  134. current
  135. })
  136. },
  137. /**
  138. * 删除列表项
  139. */
  140. onDeleteItem(e) {
  141. let imgs = this.data.imgs;
  142. imgs.splice(e.currentTarget.dataset.index, 1);
  143. this.setData({ imgs })
  144. console.log(imgs)
  145. },
  146. /**
  147. * 选择图片
  148. */
  149. chooseImage() {
  150. let that = this;
  151. let imgs = this.data.imgs;
  152. let count = 9 - this.data.imgs.length
  153. wx.chooseImage({
  154. count,
  155. sizeType: ['original', 'compressed'],
  156. sourceType: ['album', 'camera'],
  157. success (res) {
  158. wx.showLoading({
  159. title: '正在上传图片',
  160. mask: true
  161. });
  162. const tempFiles = res.tempFiles
  163. tempFiles.forEach((item) => {
  164. that.upload(item.path).then((data) => {
  165. imgs.push({
  166. type: 'image',
  167. url: data.data.url,
  168. })
  169. that.setData({ imgs })
  170. wx.hideLoading()
  171. });
  172. })
  173. }
  174. })
  175. },
  176. /**
  177. * 选择视频
  178. */
  179. chooseVideo(){
  180. let that = this;
  181. let imgs = this.data.imgs;
  182. wx.chooseMedia({
  183. count: 1,
  184. mediaType: ['video'],
  185. sourceType: ['album', 'camera'],
  186. maxDuration: 30,
  187. camera: 'back',
  188. success(res) {
  189. wx.showLoading({
  190. title: '正在上传视频',
  191. mask: true
  192. });
  193. const tempFiles = res.tempFiles
  194. that.upload(tempFiles[0].tempFilePath).then((data) => {
  195. imgs.unshift({
  196. type: 'video',
  197. thumb: tempFiles[0].thumbTempFilePath,
  198. url: data.data.url
  199. })
  200. that.setData({ imgs })
  201. wx.hideLoading()
  202. });
  203. return;
  204. tempFiles.forEach((item) => {
  205. imgs.unshift({
  206. type: 'video',
  207. thumb: item.thumbTempFilePath,
  208. url: item.tempFilePath
  209. })
  210. })
  211. that.setData({ imgs })
  212. }
  213. })
  214. },
  215. /**
  216. * 选择星星
  217. */
  218. onChange(e) {
  219. let index = e.currentTarget.dataset.index
  220. let value = e.detail.value
  221. this.setData({
  222. ['raterList[' + index + '].num']: value
  223. })
  224. },
  225. /**
  226. * 提交反馈
  227. */
  228. onSubmit() {
  229. // api/feedback/add
  230. let { orderId,value,raterList } = this.data;
  231. console.log(this.data.imgs)
  232. post('api/feedback/add',{
  233. order_id: orderId,
  234. content: value,
  235. media_list: JSON.stringify(this.data.imgs),
  236. score_whole: raterList[0].num,
  237. score_effect: raterList[1].num,
  238. score_price: raterList[2].num,
  239. score_kind: raterList[3].num,
  240. score_safe: raterList[4].num,
  241. },(res) => {
  242. console.log(res)
  243. })
  244. },
  245. /**
  246. * 上传视频/图片
  247. */
  248. upload(filePath) {
  249. let that = this;
  250. // 上传类型/业务类型:avatar头像,order订单反馈,check检查表反馈
  251. return new Promise((resolve,reject) => {
  252. let { imgs } = this.data;
  253. wx.uploadFile({
  254. url: 'https://store.test-api.ijolijoli.com/api/upload',
  255. header: {
  256. token: wx.getStorageSync('token') || '',
  257. },
  258. filePath,
  259. name: 'file',
  260. formData: {
  261. 'type': 'order'
  262. },
  263. success(res) {
  264. console.log(res)
  265. if(res.statusCode == 200 && res.data) {
  266. let data = JSON.parse(res.data);
  267. if(data.code == 200 && data.data) {
  268. resolve(data)
  269. } else {
  270. wx.showToast({
  271. title: '上传失败',
  272. icon: 'none'
  273. })
  274. }
  275. } else {
  276. wx.showToast({
  277. title: '上传失败',
  278. icon: 'none'
  279. })
  280. }
  281. },
  282. fail(err) {
  283. wx.showToast({
  284. title: '上传失败',
  285. icon: 'none'
  286. })
  287. }
  288. })
  289. })
  290. },
  291. })