orderRatingPopup.js 7.63 KB
import api from '../../api.js'
// import Util from '../../utils/util'
import { uploadImg } from '~/api/api'
const IMG_URL =
  'https://img02.glsx.com.cn/weapp/resource/dj-car-boutique-work-wechat/miniProgram/'
Component({
  options: {
    multipleSlots: true // 在组件定义时的选项中启用多slot支持
  },
  /*组件的属性列表*/
  properties: {
    title: {
      type: String,
      value: '标题'
    },
    // 弹窗内容
    content: {
      type: String,
      value: '内容'
    },
    // 弹窗取消按钮文字
    btn_no: {
      type: String,
      value: '取消'
    },
    // 弹窗确认按钮文字
    btn_ok: {
      type: String,
      value: '补录这笔订单'
    },
    //是否显示取消按钮
    isShowCancel: {
      type: Boolean,
      value: true
    },
    //是否显示右上角关闭按钮
    isShowClose: {
      type: Boolean,
      value: true
    },
    //应用于某些场景的button的open-type属性
    sureButtonType: {
      type: String,
      value: ''
    },
    //控制弹窗的显示
    flag: {
      type: Boolean,
      value: true
    },
    orderInfoSetting: {
      type: Object,
      value: {},
      observer: function (n) {
        console.log(n, 'orderInfoSetting')
        n && this.setOrderInfo(n)
      }
    }
  },
  /* 组件的初始数据 */
  data: {
    IMG_URL,
    wrapAnimate: 'wrapAnimate',
    popupAnimate: 'popupAnimate',
    searchSelectData: ['通过', '不通过'],
    searchSelectIndex: 0,
    showSelect: false,
    tags: [
      {
        name: '服务态度好',
        value: '1',
        checked: false
      },
      {
        name: '性价比高',
        value: '2',
        checked: false
      },
      {
        name: '价格便宜',
        value: '3',
        checked: false
      },
      {
        name: '一般',
        value: '4',
        checked: false
      }
    ],
    orderInfo: {}
  },
  lifetimes: {
    attached: function () {
      this.setData({
        userInfo: wx.$util.getUserInfo()
      })
      // 在组件实例进入页面节点树时执行
    },
    detached: function () {
      // 在组件实例被从页面节点树移除时执行
    }
  },
  /* 组件的方法列表 */
  methods: {
    optionTap(e) {
      let { orderInfo } = this.data
      let { index, sub, subindex } = e.currentTarget.dataset
      orderInfo.subOrderList[subindex].approveStatus = index == 0 ? 'Y' : 'N'
      this.setData({
        searchSelectIndex: index,
        showSelect: !this.data.showSelect,
        orderInfo
      })
      let params = {
        orderCode: orderInfo.orderCode,
        subOrderCode: sub,
        approveStatus: index == 0 ? 'Y' : 'N'
      }
      api.technicianApprove(params).then((result) => {
        wx.$util.showToast('审批成功')
      }).catch((err) => {
      });
      // this.searchEvent(true)
    },
    closeSelect() {
      this.setData({
        showSelect: false
      })
    },
    // 查询条件类型切换
    selectTap(e) {
      let { imgindex } = e.currentTarget.dataset
      this.setData({
        selectIndex: imgindex,
        showSelect: !this.data.showSelect
      })
    },
    updateCustomerphotos(params) {
      console.log(params, 'updateCustomerphotos')
      api
        .updateCustomerphotos(params)
        .then(res => {
          console.log(res)
        })
        .catch(err => {
          console.log(err)
        })
    },
    handleUpload(e) {
      let that = this
      // console.log(e);
      let { index } = e.currentTarget.dataset
      // console.log(index);
      let { constructionImgList, orderInfo } = this.data
      wx.chooseImage({
        count: 1,
        success(res) {
          let [tempFiles] = res.tempFilePaths
          let tempFilesList = tempFiles.split('.')
          let imgType = tempFilesList[tempFilesList.length - 1]
          let type = imgType == 'unknown' ? 'jpg' : imgType
          wx.getFileSystemManager().readFile({
            filePath: tempFiles, //选择图片返回的相对路径
            encoding: 'base64', //编码格式
            success(_res) {
              wx.$util.showLoading('上传中...')
              uploadImg({
                file: `${type}@${_res.data}`
              }).then(img => {
                wx.$util.hideLoading()
                let { code, data, message } = img
                if (code == 0) {
                  orderInfo.subOrderList[index].constructionImgList =
                    orderInfo.subOrderList[index].constructionImgList || []
                  orderInfo.subOrderList[index].constructionImgList.push(data)
                  that.setData({
                    orderInfo
                  })
                  const customerPhotos = orderInfo.subOrderList.reduce((pre, item) => {
                    if (item.constructionImgList) {
                      item.constructionImgList.map(el => {
                        pre.push({
                          customerPhoto: el,
                          subOrderCode: item.subOrderCode
                        })
                      })
                    }
                    return pre;
                  }, [])
                  that.updateCustomerphotos({
                    orderCode: orderInfo.orderCode,
                    customerPhotos
                  })
                } else {
                  wx.$util.showToast(message)
                }
              })
            }
          })
        }
      })
    },
    // 删除图片
    handleDelete(e) {
      let { index, imgindex } = e.currentTarget.dataset
      let { orderInfo, constructionImgList } = this.data
      if (orderInfo.subOrderList[imgindex].constructionImgList.length == 1) {
        return wx.$util.showToast('最少需要一张图片')
      }
      orderInfo.subOrderList[imgindex].constructionImgList.splice(index, 1)

      const customerPhotos = orderInfo.subOrderList.reduce((pre, item) => {
        if (item.constructionImgList) {
          item.constructionImgList.map(el => {
            pre.push({
              customerPhoto: el,
              subOrderCode: item.subOrderCode
            })
          })
        }
        return pre;
      }, [])
      this.updateCustomerphotos({
        orderCode: orderInfo.orderCode,
        customerPhotos
      })
      this.setData({
        orderInfo
      })
    },

    // 放大图片
    handlePreviewImg(e) {
      let { item, imgIndex } = e.currentTarget.dataset
      console.log(item)
      wx.$util.previewImage({
        urls: [item]
      })
    },
    setOrderInfo(orderInfo) {
      console.log(orderInfo, 'orderInfo')
      orderInfo?.packageGoodsList.forEach(e => {
        e.packageGoodsOrderList.forEach(child => {
          orderInfo.subOrderList.push(child)
        })
      })
      // constructionImgList
      orderInfo.customerPhotos.forEach(item => {
        orderInfo.subOrderList.forEach(el => {
          if (item.subOrderCode == el.subOrderCode) {
            if (el.constructionImgList) {
              el.constructionImgList.push(item.customerPhoto)
            } else {
              el.constructionImgList = [item.customerPhoto]
            }
          }
        })

      })
      orderInfo.evaluation = orderInfo.evaluation.split(',')
      console.log(orderInfo.subOrderList, 'orderInfo.evaluation')
      console.log(orderInfo.evaluation, 'orderInfo.evaluation')
      let { tags } = this.data
      tags.forEach((item, index) => {
        if (orderInfo.evaluation.includes(item.value)) {
          item.checked = true
        }
      })
      this.setData({
        orderInfo,
        tags
      })
    },
    /* 内部私有方法建议以下划线开头 triggerEvent 用于触发事件 */
    _close() {
      //触发取消回调
      this.triggerEvent('close')
    },
    _success() { }
  }
})