123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393 |
- import {
- get,
- post,
- api_url
- } from '../../utils/http';
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- maxlength: 500,
- number: 0,
- value: "",
- imgs: [],
- // imgs: [
- // {
- // type: "image",
- // url: "https://img1.baidu.com/it/u=202543353,3627416815&fm=26&fmt=auto"
- // },
- // {
- // type: "image",
- // url: "https://img0.baidu.com/it/u=745609344,230882238&fm=26&fmt=auto"
- // },
- // {
- // type: "image",
- // url: "https://img0.baidu.com/it/u=286636366,3227707112&fm=26&fmt=auto"
- // },
- // {
- // type: "image",
- // url: "https://img1.baidu.com/it/u=2450865760,444795162&fm=26&fmt=auto"
- // },
- // {
- // type: "image",
- // url: "https://img0.baidu.com/it/u=4226275504,4103997964&fm=26&fmt=auto"
- // },
- // {
- // type: "image",
- // url: "https://img0.baidu.com/it/u=2247422843,411257408&fm=26&fmt=auto"
- // },
- // ],
- raterList: [
- {
- text: '整体满意度',
- num: 1
- },
- {
- text: '效果认可度',
- num: 2
- },
- {
- text: '价格接受度',
- num: 3
- },
- {
- text: '类别满意度',
- num: 4
- },
- {
- text: '安全认可度',
- num: 5
- },
- ],
- raterStatus: {
- 1: '差',
- 2: '较差',
- 3: '一般',
- 4: '满意',
- 5: '非常好',
- },
- edit: "false",
- score: false
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- console.log(options)
- console.log(options)
- if(options.orderId) {
- this.setData({
- orderId: options.orderId,
- cover: options.cover,
- name: options.name,
- edit: options.edit || "false",
- score: options.score
- })
- if(options.edit == "true") {
- this.getfeedbackInfo(options.orderId)
- }
- }
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- },
- /**
- * 监听文本域
- */
- bindTextAreaInput(e) {
- this.setData({
- number: e.detail.cursor,
- value: e.detail.value
- })
- },
- /**
- * 预览图片和视频
- */
- previewMedia(e) {
- let arr = this.data.imgs
- let current = e.currentTarget.dataset.index
- wx.previewMedia({
- sources: arr,
- current
- })
- },
- /**
- * 删除列表项
- */
- onDeleteItem(e) {
- let imgs = this.data.imgs;
- imgs.splice(e.currentTarget.dataset.index, 1);
- this.setData({ imgs })
- console.log(imgs)
- },
- /**
- * 选择图片
- */
- chooseImage() {
- let that = this;
- let imgs = this.data.imgs;
- let count = 9 - this.data.imgs.length
- wx.chooseImage({
- count,
- sizeType: ['original', 'compressed'],
- sourceType: ['album', 'camera'],
- success (res) {
- wx.showLoading({
- title: '正在上传图片',
- mask: true
- });
- const tempFiles = res.tempFiles
- tempFiles.forEach((item) => {
- that.upload(item.path).then((data) => {
- imgs.push({
- type: 'image',
- url: data.data.url,
- })
- that.setData({ imgs })
- wx.hideLoading()
- });
- })
-
- }
- })
- },
- /**
- * 选择视频
- */
- chooseVideo(){
- let that = this;
- let imgs = this.data.imgs;
- wx.chooseMedia({
- count: 1,
- mediaType: ['video'],
- sourceType: ['album', 'camera'],
- maxDuration: 30,
- camera: 'back',
- success(res) {
- wx.showLoading({
- title: '正在上传视频',
- mask: true
- });
- const tempFiles = res.tempFiles
- that.upload(tempFiles[0].thumbTempFilePath).then((data) => {
- if(imgs.length > 0 && imgs[0].type == 'video') {
- that.setData({
- ['imgs[' + 0 + '].thumb']: data.data.url
- })
- } else {
- imgs.unshift({
- type: 'video',
- thumb: data.data.url,
- url: ''
- })
- that.setData({ imgs })
- }
- // that.setData({ imgs })
- wx.hideLoading()
- });
- that.upload(tempFiles[0].tempFilePath).then((data) => {
- if(imgs.length > 0 && imgs[0].type == 'video') {
- that.setData({
- ['imgs[' + 0 + '].url']: data.data.url
- })
- } else {
- imgs.unshift({
- type: 'video',
- thumb: '',
- url: data.data.url
- })
- that.setData({ imgs })
- }
- // imgs.unshift({
- // type: 'video',
- // thumb: tempFiles[0].thumbTempFilePath,
- // url: data.data.url
- // })
- // that.setData({ imgs })
- wx.hideLoading()
- });
- }
- })
- },
- /**
- * 选择星星
- */
- onChange(e) {
- let index = e.currentTarget.dataset.index
- let value = e.detail.value
- this.setData({
- ['raterList[' + index + '].num']: value
- })
- },
- /**
- * 提交反馈
- */
- onSubmit() {
- // api/feedback/add
- let { orderId,value,raterList,edit } = this.data;
- console.log(this.data.imgs)
- console.log(edit)
- if(edit == "true") {
- this.editFeedbackUpdate()
- } else {
- post('api/feedback/add',{
- order_id: orderId,
- content: value,
- media_list: JSON.stringify(this.data.imgs),
- score_whole: raterList[0].num,
- score_effect: raterList[1].num,
- score_price: raterList[2].num,
- score_kind: raterList[3].num,
- score_safe: raterList[4].num,
- },(res) => {
- console.log(res)
- wx.showToast({
- title: res.msg,
- icon: 'none'
- })
- setTimeout(() => {
- wx.navigateBack()
- }, 1500);
- })
- }
- },
- /**
- * 上传视频/图片
- */
- upload(filePath) {
- let that = this;
- // 上传类型/业务类型:avatar头像,order订单反馈,check检查表反馈
- return new Promise((resolve,reject) => {
- let { imgs } = this.data;
- wx.uploadFile({
- url: `${api_url}api/upload`,
- header: {
- token: wx.getStorageSync('token') || '',
- },
- filePath,
- name: 'file',
- formData: {
- 'type': 'order'
- },
- success(res) {
- console.log(res)
- if(res.statusCode == 200 && res.data) {
- let data = JSON.parse(res.data);
- if(data.code == 200 && data.data) {
- resolve(data)
- } else {
- wx.showToast({
- title: '上传失败',
- icon: 'none'
- })
- }
- } else {
- wx.showToast({
- title: '上传失败',
- icon: 'none'
- })
- }
- },
- fail(err) {
- wx.showToast({
- title: '上传失败',
- icon: 'none'
- })
- }
- })
- })
- },
- /**
- * 获取订单反馈详情
- * api/feedback/info
- */
- getfeedbackInfo(id) {
- get('api/feedback/info',{ id },(res) => {
- this.setData({
- value: res.data.content,
- imgs: JSON.parse(res.data.media_list),
- raterList: []
- })
- })
- },
- /**
- * 编辑反馈记录
- * api/feedback/update
- */
- editFeedbackUpdate() {
- let { orderId,value,imgs } = this.data;
- post('api/feedback/update',{
- id: orderId,
- content: value,
- media_list: JSON.stringify(imgs)
- },(res) => {
- wx.showToast({
- title: res.msg,
- icon: 'none'
- })
- setTimeout(() => {
- wx.navigateBack()
- }, 1500);
- console.log(res)
- })
- }
- })
|