index.js 4.07 KB
// tabRepairOrder/components/outboundPopup/index.js
const IMG_URL =
  'https://img02.glsx.com.cn/weapp/resource/dj-car-boutique-work-wechat/'
import { createQrcodeImage } from '~/api/api'
import api from '../../api'
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    show: {
      type: Boolean,
      observer: function (n) {
        if (n) {
          this.setData({
            scrollTop: 0
          })
          let { infoData } = this.data
          if (infoData) {
            this.getDetailInfo(infoData)
          }
        }
      }
    },
    title: String,
    detailInfo: {
      type: Object,
      observer: function (n) {
        if (n) {
          this.setData({
            infoData: wx.$util.deepClone(n)
          })
        }
      }
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    IMG_URL,
    infoData: {},
    filmRollNoList: [],
    scrollTop: 0
  },

  /**
   * 组件的方法列表
   */
  methods: {
    async getDetailInfo(data) {
      let oParams = {}
      oParams.appId = 'wx570d9331f9ace0bd'
      oParams.qrcodeType = 'QR_WXA_UNLIMIT'
      oParams.path = 'tabRepairOrder/pages/repairOrderDetail/repairOrderDetail'
      oParams.scene = `merchantId=${data.merchantId}&yqMerchantId=${data.sellerMerchantId}&id=${data.id}&constructionCode=${data.constructionCode}&orderCode=${data.orderCode}`
      oParams.channelType = 1
      // const res = await createQrcodeImage(oParams)
      // this.setData({
      //   weappQrcode: res.data
      // })
    },
    // 选择膜卷号
    handleRollNumber(e) {
      let { target, index } = e.currentTarget.dataset
      let { detailInfo } = this.data
      // 获取膜卷号数据
      api
        .getfilmRollNoByGoods({
          upgradeGoodsId: target.upgradeGoodsId,
          yqMerchantId: detailInfo?.sellerMerchantId,
          merchantId: detailInfo?.merchantId
        })
        .then(res => {
          let { code, data, message } = res
          if (code == 0) {
            this.setData({
              filmRollNoList: data || [],
              filmRollNoVisible: true,
              filmSelectedItem: target.rollNumber,
              selectRollIndex: index
            })
          } else {
            wx.$util.showToast(message)
          }
        })
    },
    // 膜卷号确认
    changefilmRollNo(e) {
      let { selectRollIndex } = this.data
      this.setData({
        [`infoData.subOrderList[${selectRollIndex}].rollNumber`]: e.detail
      })
      this.handelCancelRollPopup()
    },
    // 膜卷号取消
    handelCancelRollPopup() {
      this.setData({ filmRollNoVisible: false })
    },
    // 实际用料输入框
    handleInput(e) {
      const { index } = e.currentTarget.dataset
      let value = e.detail.value
      value = value.replace(/[^\d.]/g, '')
      // 处理多个小数点的情况,只保留第一个
      const dotIndex = value.indexOf('.')
      if (dotIndex !== -1) {
        value =
          value.substring(0, dotIndex + 1) +
          value.substring(dotIndex + 1).replace(/\./g, '')
      }
      // 限制小数点后最多两位
      if (dotIndex !== -1) {
        const decimalPart = value.substring(dotIndex + 1)
        if (decimalPart.length > 2) {
          value = value.substring(0, dotIndex + 3)
        }
      }
      // 转换为数字进行最大值验证
      const numValue = parseFloat(value || 0)
      if (!isNaN(numValue) && numValue > 99999.99) {
        value = '99999.99'
      }
      this.setData({
        [`infoData.subOrderList[${index}].materialsUsed`]: value
      })
    },
    // 产品出库时间
    handleOutboundTime() {
      this.setData({
        timeVisible: true
      })
    },
    // 产品出库时间确认
    onTimeConfirm(e) {
      this.setData({
        'infoData.outBoundTime': e.detail
      })
      this.onClosePicker()
    },
    // 产品出库时间弹窗取消
    onClosePicker() {
      this.setData({ timeVisible: false })
    },
    // 关闭物料出库弹窗
    cancel() {
      this.triggerEvent('cancel')
    },
    confirm() {
      let { infoData } = this.data
      this.triggerEvent('confirm', infoData)
    }
  }
})