// component/dialog/dialog.js
const wxService = require('../../utils/wxService')

Component({
  options: {
    multipleSlots: true // 在组件定义时的选项中启用多slot支持
  },
  /**
   * 组件的属性列表
   */
  properties: {
    type: {
      type: String,
      value: 'alert'
    },
    stopMask: {
      type: Boolean,
      value: false
    },
    show: {
      type: Boolean,
      value: false,
      observer: '_showChange'
    },
    dialog: {
      type: Object,
      value: null,
      observer: '_configChange'
    },
    showDefalut: {
      type: Boolean,
      value: true,
      observer: '_showDefalutChange'
    }
  },

  /**
   * 组件的初始数据
   */
  data: {

  },

  /**
   * 组件的方法列表
   */
  methods: {
    _handleGo() {
      this.triggerEvent('handleGo')
    },
    _updateData(data) {
      if (data) {
        this.setData(data)
      }
    },
    _showChange(newV, oldV) {
      if (newV !== oldV) {
        this._updateData({
          show: newV
        })
      }
    },
    _showDefalutChange(newV, oldV) {
      if (newV !== oldV) {
        this._updateData({
          showDefalut: newV
        })
      }
    },
    _configChange(newV, oldV) {
      if (newV !== oldV) {
        this._updateData({
          config: newV
        })
      }
    },
    _close(e) {
      let o = e.currentTarget.dataset
      if (this.data.stopMask && o.id === 'mask') {
        return false
      }
      this._updateData({
        show: false
      })
    
    },
    confirm(){
      this._updateData({
        show: false
      })
      // 触发父级事件
      wxService.nextTick(() => {
        this.triggerEvent('_closeDialog')
      })
    }
  }
})
