pubDialog.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <template>
  2. <!-- 公用弹窗组件 根据实际自行追加具体type 通用input -->
  3. <el-dialog
  4. :visible.sync="isShow"
  5. :close-on-click-modal="false"
  6. :modal-append-to-body="false"
  7. @close="cancelHandle"
  8. custom-class="public-dialog"
  9. center
  10. :width="dialogWidth"
  11. v-dialogDrag
  12. >
  13. <div slot="title" style="display: flex; align-items: center">
  14. <img
  15. :src="$icons.title_icon"
  16. style="color: #fff; width: 16px; height: 16px; marginright: 5px"
  17. v-if="title_icon"
  18. />
  19. <span style="font-size: 16px">{{ title }}</span>
  20. </div>
  21. <el-form
  22. ref="diaForm"
  23. class="form-cont"
  24. label-position="left"
  25. :hide-required-asterisk="isHideRequired"
  26. label-width="120px"
  27. :model="formData"
  28. :rules="formRules"
  29. >
  30. <el-form-item
  31. v-for="(item, index) in keysArr"
  32. :key="index"
  33. :label="item.label"
  34. :prop="item.prop"
  35. width="100%"
  36. >
  37. <el-input
  38. v-if="item.type === 'input'"
  39. :maxlength="item.maxlen"
  40. v-model.trim="formData[item.prop]"
  41. :placeholder="item.placeholder"
  42. />
  43. <el-select
  44. v-model="formData[item.prop]"
  45. :placeholder="item.placeholder"
  46. style="width: 80%;"
  47. v-else-if="item.type === 'select'"
  48. :multiple="item.multiple"
  49. clearable
  50. >
  51. <i slot="prefix" :class="item.prefixIco" v-if="item.prefixIco"></i>
  52. <el-option
  53. v-for="type in selectArr"
  54. :key="type.value"
  55. :label="type.name"
  56. :value="type.value"
  57. >
  58. </el-option>
  59. </el-select>
  60. </el-form-item>
  61. </el-form>
  62. <div class="dia-bot">
  63. <el-button
  64. type="primary"
  65. style="margin-right: 20px"
  66. @click="saveHandle"
  67. >{{ confimTxt[0] }}</el-button
  68. >
  69. <el-button type="primary" plain @click="cancelHandle">{{
  70. confimTxt[1]
  71. }}</el-button>
  72. </div>
  73. </el-dialog>
  74. </template>
  75. <script>
  76. import bus from "@/api/bus";
  77. export default {
  78. props: {
  79. isShow: {
  80. type: Boolean,
  81. required: true,
  82. },
  83. title: {
  84. type: String,
  85. default: '',
  86. },
  87. title_icon: {
  88. type: String,
  89. default: '',
  90. },
  91. dialogWidth: {
  92. type: String,
  93. default: '550px',
  94. },
  95. //显示必填
  96. isHideRequired: {
  97. type: Boolean,
  98. default: false,
  99. },
  100. //form 数据
  101. formData: {
  102. type: Object,
  103. default: () =>{},
  104. },
  105. //form 规则
  106. formRules: {
  107. type: Object,
  108. default: ()=>{},
  109. },
  110. //表单key数组 { label:对应的名称,prop:规则的key, type: input支持的类型 默认input,placeholder}
  111. keysArr: {
  112. type: Array,
  113. default: ()=>[],
  114. },
  115. /* select的数据 {name,value}格式 */
  116. selectArr: {
  117. type: Array,
  118. default: ()=>[],
  119. },
  120. confimTxt: {
  121. type: Array,
  122. default: ()=>[/* '保存' */bus.$i18nt.t('Dialog.confirm_save_btn'), /* '取消' */bus.$i18nt.t('Dialog.cancel_btn')],
  123. },
  124. },
  125. data() {
  126. return {};
  127. },
  128. methods: {
  129. cancelHandle() {
  130. this.$refs.diaForm.resetFields();
  131. this.$emit('cancel');
  132. },
  133. saveHandle() {
  134. this.$refs.diaForm.validate((valid) => {
  135. if (valid) {
  136. this.$emit('ensureCallBack', this.formData, this.title);
  137. }
  138. });
  139. },
  140. },
  141. created() {},
  142. mounted() {},
  143. };
  144. </script>
  145. <style lang="scss">
  146. .public-dialog {
  147. .el-form-item__content {
  148. margin-left: 0;
  149. }
  150. .form-cont {
  151. padding-left: 50px;
  152. }
  153. .el-input {
  154. width: 80%;
  155. }
  156. .dia-bot {
  157. margin: 52px 0 30px;
  158. display: flex;
  159. justify-content: center;
  160. }
  161. }
  162. </style>