index.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <template>
  2. <div>
  3. <el-button :disabled="disabled ? disabled : false" :type="type ? type : 'primary'" :size="size ? size : 'mini'" @click="submit">{{ btnName }}</el-button>
  4. </div>
  5. </template>
  6. <script>
  7. export default {
  8. name: '',
  9. props:{
  10. type: String,
  11. btnName: String,
  12. message: String,
  13. idName: String,
  14. keyName: String,
  15. id: [String,Number,Array],
  16. disabled: Boolean,
  17. idIsArr: Boolean,
  18. paramData: {
  19. type: Array,
  20. default () {
  21. return []
  22. }
  23. },
  24. dialog: Boolean,
  25. dialogTitle:String,
  26. dialogKey:String,
  27. checkContent: Boolean,
  28. size: String
  29. },
  30. data() {
  31. return {
  32. };
  33. },
  34. computed:{
  35. },
  36. watch:{
  37. },
  38. methods: {
  39. submit () {
  40. if (this.dialog) {
  41. this.$prompt(this.dialogTitle, '提示', {
  42. confirmButtonText: '确定',
  43. cancelButtonText: '取消',
  44. inputPattern: this.checkContent ? /^[\d.]+$/ : ''
  45. }).then(async ({ value }) => {
  46. let param = {
  47. content:{}
  48. }
  49. param.id = this.idName
  50. param.content[this.keyName] = this.idIsArr ? [this.id] : this.id
  51. this.paramData.forEach(item => {
  52. param.content[item.key] = item.value
  53. })
  54. param.content[this.dialogKey] = value
  55. let res = await this.$api.requested(param)
  56. this.tool.showMessage(res,() => {
  57. this.$emit('onSuccess',res.data)
  58. })
  59. })
  60. } else {
  61. this.$confirm(this.message,'提示',{
  62. confirmButtonText:'确定',
  63. cancelButtonText:'取消',
  64. type:'warning'
  65. }).then(async () => {
  66. let param = {
  67. content:{}
  68. }
  69. param.id = this.idName
  70. param.content[this.keyName] = this.idIsArr ? [this.id] : this.id
  71. this.paramData.forEach(item => {
  72. param.content[item.key] = item.value
  73. })
  74. let res = await this.$api.requested(param)
  75. this.tool.showMessage(res,() => {
  76. this.$emit('onSuccess',res.data)
  77. })
  78. })
  79. }
  80. }
  81. },
  82. };
  83. </script>
  84. <style scoped>
  85. </style>