RemarkPopup.js 2.62 KB
// components/RemarkPopup/RemarkPopup.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    show: {
      type: Boolean,
      value: false,
      observer: function (n) {
        // if (n) this.getLetter()
        console.log(n)
      }
    },
    placeholder: String,
    maxlength: Number,
    value: {
      type: String
    },
    // isFormComponent: {
    //   type: Boolean,
    //   value: false
    // },
    title: {
      type: String,
      value: '备注'
    },
    btnName: {
      type: String
    },
    isLimitNum: {
      type: Boolean,
      value: false
    },
    isInt: {
      type: Boolean,
      value: false
    },
    required: {
      type: Boolean,
      value: false
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    inputValue: '',
    isEdit: false
  },

  /**
   * 组件的方法列表
   */
  methods: {
    noScroll() {},
    blur(e) {
      this.setData({
        inputValue: e.detail.value,
        isEdit: true
      })
    },
    showPopup(e) {
      // console.log()
      let { name, btnName } = e.currentTarget.dataset
      // if (btnName == 'cancel') {
      //   this.setData({
      //     value: ''
      //   })
      // }
      // console.log(name)
      // 判断是不是来自组件 不是调用页面的数据修改
      // 是用方法回传关闭
      // let { isFormComponent } = this.data
      // if (!isFormComponent) {
      let thisPage = wx.$router.getPageInstance()
      // console.log(thisPage)
      console.log(thisPage)
      thisPage.setData({
        [name]: false
      })
      // 组件中使用
      this.triggerEvent('cancel')
      this.setData({
        isEdit: false
      })
      // } else {
      //   // console.log('tri')
      //   this.triggerEvent('closePop')
      // }
    },
    remarkConfirm() {
      // console.log('confirm')
      let { isInt, value, inputValue, isEdit, required } = this.data
      let confirmValue = isEdit ? inputValue : value
      console.log('1', confirmValue)
      console.log('confirmValue', confirmValue.length)
      if (isInt && !confirmValue.toString().length) {
        return wx.showToast({
          title: '修改值不能为空',
          icon: 'none'
        })
      }
      if (required && !confirmValue.length) {
        return wx.showToast({
          title: '内容不能为空',
          icon: 'none'
        })
      }

      // let { isFormComponent } = this.data
      this.triggerEvent('confirm', confirmValue)
      // if (!isFormComponent) {
      this.showPopup({
        currentTarget: {
          dataset: {
            name: 'showRemark'
          }
        }
      })
      // }
    }
  }
})