index.vue 6.08 KB
<template>
  <div
    :class="center == 'editCenter' ? 'fix-dialog-height' : ''"
    class="app-add-dialog"
  >
    <div v-if="noCache" :class="heightClass" :style="heightStyle">
      <el-dialog
        v-dialogDrag
        v-if="dialogVisible"
        ref="dialog"
        :title="title"
        :visible.sync="dialogVisible"
        :width="diaWidth"
        :top="diaTop"
        :show-close="isShowClose"
        :before-close="handleClose"
      >
        <div v-if="title == 'editTitle'" ref="dialogTitle" slot="title">
          <slot name="titleOut" />
        </div>

        <div
          ref="dialogCenter"
          :class="center == 'editCenter' ? 'center-out' : ''"
          class="container"
        >
          <slot name="center" />
        </div>

        <div
          v-if="footer == 'editFooter'"
          ref="dialogFooter"
          slot="footer"
          class="dialog-footer footer-out"
        >
          <slot name="footerOut" />
        </div>
        <span v-else ref="dialogFooter" slot="footer" class="dialog-footer">
          <el-button v-if="isShowCancel" @click="hideDialog">取 消</el-button>
          <el-button
            v-if="isShowConfirm"
            :loading="loading"
            :disabled="isDisable"
            type="primary"
            @click="handleComfrim"
          >确 定</el-button
          >
        </span>
      </el-dialog>
    </div>
    <div v-else :class="heightClass">
      <el-dialog
        v-dialogDrag
        ref="dialog"
        :title="title"
        :visible.sync="dialogVisible"
        :width="diaWidth"
        :top="diaTop"
        :show-close="isShowClose"
        :before-close="handleClose"
      >
        <div v-if="title == 'editTitle'" ref="dialogTitle" slot="title">
          <slot name="titleOut" />
        </div>

        <div
          ref="dialogCenter"
          :class="center == 'editCenter' ? 'center-out' : ''"
          class="container"
        >
          <slot name="center" />
        </div>

        <div
          v-if="footer == 'editFooter'"
          ref="dialogFooter"
          slot="footer"
          class="dialog-footer footer-out"
        >
          <slot name="footerOut" />
        </div>
        <span v-else ref="dialogFooter" slot="footer" class="dialog-footer">
          <el-button v-if="isShowCancel" @click="hideDialog">取 消</el-button>
          <el-button
            v-if="isShowConfirm"
            :loading="loading"
            :disabled="isDisable"
            type="primary"
            @click="handleComfrim"
          >{{ footerName }}</el-button
          >
          <slot name="btnSlot"/>
        </span>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import '@/directive/directives.js'
export default {
  props: {
    noCache: {
      type: Boolean,
      default: false
    },
    isDisable: {
      type: Boolean,
      default: false
    },
    isVisible: {
      type: Boolean,
      default: false
    },
    isCloseNoComfrimAgain: {
      type: Boolean,
      default: false
    },
    isShowClose: {
      type: Boolean,
      default: true
    },
    isShowCancel: {
      type: Boolean,
      default: true
    },
    isShowConfirm: {
      type: Boolean,
      default: true
    },
    diaWidth: {
      type: String,
      default: '40%'
    },
    diaTop: {
      type: String,
      default: '50px'
    },
    heightClass: {
      type: String,
      default: ''
    },
    heightStyle: {
      type: Object,
      default: () => {
        return {}
      }
    },
    title: {
      type: String,
      default: '提示'
    },
    center: {
      type: String,
      default: ''
    },
    footer: {
      type: String,
      default: ''
    },
    footerName: {
      type: String,
      default: '确 定'
    },
    loading: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      dialogVisible: false,
      isDisableState: false
    }
  },
  //   computed:{
  //     dialogVisible: {
  //         get(){
  //             console.log('get')
  //             return this.isVisible
  //         },
  //         set(){
  //             console.log('set')
  //             this.isVisible = false
  //             return false
  //         }
  //     }
  //   },
  watch: {
    isVisible(val) {
      this.dialogVisible = val
    }
  },
  created() {},
  methods: {
    handleClose(done) {
      // console.log("gua");
      if (this.isCloseNoComfrimAgain) {
        this.$emit('hideDialog')
        done()
      } else {
        this.$confirm('确认关闭?')
          .then((_) => {
            this.$emit('hideDialog')
            done()
          })
          .catch((_) => {})
      }
    },
    handleComfrim() {
      //   this.dialogVisible = false;
      // console.log("子点击了确认按钮");
      // this.isDisableState = true;
      // setTimeout(()=>{
      //   this.isDisableState = false;
      // },2000)
      this.$emit('comfrim-click')
    },
    hideDialog() {
      this.$emit('hideDialog')
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" >
.app-add-dialog {
  .el-dialog__header {
    padding: 20px;
  }
  .el-dialog__footer {
    padding: 10px;
    background: #fff;
  }
  &.fix-dialog-height {
    .el-dialog__body {
      height: 400px !important;
    }
  }
  .move-dialog-height {
    .el-dialog__body {
      height: 590px !important;
      max-height: 800px !important;
    }
  }
  .move-dialog-height-500 {
    .el-dialog__body {
      height: 500px !important;
      max-height: 800px !important;
    }
  }
  .el-dialog__body {
    padding: 0;
    border-top: 1px solid #eaeefb;
    border-bottom: 1px solid #eaeefb;
    min-height: 250px;
    max-height: 500px;
    overflow-y: auto;
    .container {
      > span {
        display: block;
      }
      overflow-y: auto;
      padding: 20px 20px;
      .el-radio {
        height: 40px;
        line-height: 40px;
      }
    }
    .center-out {
      &.container {
        padding: 0;
      }
    }
  }
  .footer-out {
    width: 100%;
    .el-pagination__total {
      float: left;
    }
  }
  .hide-dialog-header {
    .el-dialog__header {
      // height: 2px;
      display: none;
    }
  }
}
</style>