Edit.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <template>
  2. <el-dialog
  3. :close-on-click-modal="false"
  4. :close-on-press-escape="false"
  5. :title="title"
  6. :append-to-body="true"
  7. :visible.sync="isVisible"
  8. :width="width"
  9. top="50px"
  10. >
  11. <el-form ref="form" :model="tenant" :rules="rules" label-position="right" label-width="130px">
  12. <el-form-item :label='$t("lineSide.form.name")' prop="name">
  13. <el-input v-model="tenant.name" :placeholder='$t("common.pleaseEnter")'/>
  14. </el-form-item>
  15. <el-form-item :label='$t("lineSide.form.status")' prop="status">
  16. <template>
  17. <el-radio v-model="tenant.status" label="1">{{$t("common.show")}}</el-radio>
  18. <el-radio v-model="tenant.status" label="0">{{$t("common.hide")}}</el-radio>
  19. </template>
  20. </el-form-item>
  21. </el-form>
  22. <div slot="footer" class="dialog-footer">
  23. <el-button plain type="warning" @click="isVisible = false">{{ $t('common.cancel') }}</el-button>
  24. <el-button plain type="primary" :disabled="confirmDisabled" @click="submitForm">{{ $t('common.confirm') }}</el-button>
  25. </div>
  26. </el-dialog>
  27. </template>
  28. <script>
  29. // 【仓库类型管理】-API
  30. import warehouseTypeMgrApi from "@/api/modelingCenter/warehouseTypeMgr"
  31. export default {
  32. name: 'TenantEdit',
  33. props: {
  34. dialogVisible: {
  35. type: Boolean,
  36. default: false
  37. },
  38. title: {
  39. type: String,
  40. default: ''
  41. }
  42. },
  43. data () {
  44. return {
  45. type: 'add',
  46. tenant: this.initTenant(),
  47. screenWidth: 0,
  48. width: this.initWidth(),
  49. confirmDisabled: false,
  50. dicts:{
  51. NATION: {}
  52. },
  53. roles: [],
  54. rules: {
  55. name: [
  56. { required: true, message: this.$t("rules.require"), trigger: 'blur' }
  57. ]
  58. }
  59. }
  60. },
  61. computed: {
  62. isVisible: {
  63. get () {
  64. return this.dialogVisible
  65. },
  66. set () {
  67. this.close()
  68. this.reset()
  69. }
  70. }
  71. },
  72. mounted () {
  73. window.onresize = () => {
  74. return (() => {
  75. this.width = this.initWidth()
  76. })()
  77. }
  78. },
  79. methods: {
  80. initTenant () {
  81. return {
  82. id: '',
  83. name: '',
  84. status: '1'
  85. }
  86. },
  87. initWidth () {
  88. this.screenWidth = document.body.clientWidth
  89. if (this.screenWidth < 991) {
  90. return '90%'
  91. } else if (this.screenWidth < 1400) {
  92. return '45%'
  93. } else {
  94. return '800px'
  95. }
  96. },
  97. setTenant (val, dicts) {
  98. if(val){
  99. this.tenant = { ...val }
  100. }
  101. // 字典表
  102. this.dicts = dicts
  103. },
  104. close () {
  105. this.$emit('close')
  106. },
  107. reset () {
  108. // 先清除校验,再清除表单,不然有奇怪的bug
  109. this.$refs.form.clearValidate()
  110. this.$refs.form.resetFields()
  111. this.tenant = this.initTenant()
  112. },
  113. submitForm () {
  114. this.$refs.form.validate((valid) => {
  115. if (valid) {
  116. this.confirmDisabled = true
  117. if (this.type === 'add') {
  118. this.save()
  119. } else {
  120. this.update()
  121. }
  122. } else {
  123. return false
  124. }
  125. })
  126. },
  127. save () {
  128. warehouseTypeMgrApi.save(this.tenant)
  129. .then((response) => {
  130. const res = response.data
  131. if (res.isSuccess) {
  132. this.isVisible = false
  133. this.$message({
  134. message: this.$t('tips.createSuccess'),
  135. type: 'success'
  136. })
  137. // 通知列表
  138. this.$emit("success");
  139. // 通知列表-并关闭弹出框
  140. this.$emit("close");
  141. }
  142. }).finally(() => {
  143. this.confirmDisabled = false
  144. return true
  145. })
  146. },
  147. update () {
  148. warehouseTypeMgrApi.update(this.tenant)
  149. .then((response) => {
  150. const res = response.data
  151. if (res.isSuccess) {
  152. this.isVisible = false
  153. this.$message({
  154. message: this.$t('tips.updateSuccess'),
  155. type: 'success'
  156. })
  157. // 通知列表
  158. this.$emit("success");
  159. // 通知列表-并关闭弹出框
  160. this.$emit("close");
  161. }
  162. }).finally(() => {
  163. this.confirmDisabled = false
  164. return true
  165. })
  166. }
  167. }
  168. }
  169. </script>
  170. <style lang="scss" >
  171. .avatar-uploader .el-upload {
  172. border: 1px dashed #d9d9d9;
  173. border-radius: 6px;
  174. cursor: pointer;
  175. position: relative;
  176. overflow: hidden;
  177. }
  178. .avatar-uploader .el-upload:hover {
  179. border-color: #409eff;
  180. }
  181. .avatar-uploader-icon {
  182. font-size: 28px;
  183. color: #8c939d;
  184. width: 100px;
  185. height: 100px;
  186. line-height: 100px;
  187. text-align: center;
  188. }
  189. .avatar {
  190. width: 100px;
  191. height: 100px;
  192. display: block;
  193. }
  194. .checkUsed{
  195. display: inline-block;
  196. margin-left: 10px;
  197. color: #1890ff;
  198. }
  199. </style>