import TyComponent from '../common/component'

TyComponent({
  /**
   * 组件的属性列表
   */
  properties: {
    selector: {
      type: String,
      value: '#ht-dialog'
    },
    show: {
      type: Boolean
    },
    title: {
      type: String
    },
    width: {
      type: [String, Number],
      value: '320px'
    },
    message: {
      type: String
    },
    messageAlign: {
      type: String,
      value: 'center'
    },
    zIndex: {
      type: Number,
      value: 100
    },
    className: {
      type: String
    },
    customStyle: {
      type: String
    },
    showConfirmButton: {
      type: Boolean,
      value: true
    },
    showCancelButton: {
      type: Boolean,
      value: false
    },
    confirmButtonText: {
      type: String,
      value: '确认'
    },
    cancelButtonText: {
      type: String,
      value: '取消'
    },
    confirmButtonColor: {
      type: String,
      value: '#096DD9'
    },
    cancelButtonColor: {
      type: String,
      value: '#8C8C8C'
    },
    overlay: {
      type: Boolean,
      value: true
    },
    overlayStyle: {
      type: Object
    },
    closeOnClickOverlay: {
      type: Boolean,
      value: false
    },
    useSlot: {
      type: Boolean,
      value: false
    },
    useTitleSlot: {
      type: Boolean,
      value: false
    },
    asyncClose: {
      type: Boolean,
      value: false
    },
    transition: {
      type: String,
      value: 'scale'
    },
    confirmButtonOpenType: {
      type: String
    }

  },

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

  },

  /**
   * 组件的方法列表
   */
  methods: {
    handleAction(detail, action) {
      if (this.data[action]) {
        this.data[action](detail)
      }
    },
    handleClose({detail}) {
      this.triggerEvent('close', detail)
      this.handleAction(detail, 'Close')
    },
    handleConfirm({detail}) {
      this.triggerEvent('confirm', detail)
      this.handleAction(detail, 'Confirm')
    },
    handleCancel({detail}) {
      this.triggerEvent('cancel', detail)
      this.handleAction(detail, 'Cancel')
    },
    handleGetuserinfo({detail}) {
      this.triggerEvent('getuserinfo', detail)
    },
    handleContact({detail}) {
      this.triggerEvent('contact', detail)
    },
    handleGetphonenumber({detail}) {
      this.triggerEvent('getphonenumber', detail)
    },
    handleError({detail}) {
      this.triggerEvent('error', detail)
    },
    handleOpensetting({detail}) {
      this.triggerEvent('opensetting', detail)
    },
    close() {
      this.setData({
        show: false
      })
    },
    stopLoading() {
      this.setData({
        loading: {
          confirm: false,
          cancel: false
        }
      })
    }
  }
})
