Edit.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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.no")+ ":"' prop="no">
  13. <el-input v-model="tenant.no" :placeholder='$t("common.pleaseEnter")'/>
  14. </el-form-item>
  15. <el-form-item :label='$t("lineSide.form.name")+ ":"' prop="name">
  16. <el-input v-model="tenant.name" :placeholder='$t("common.pleaseEnter")'/>
  17. </el-form-item>
  18. <el-form-item :label='$t("lineSide.form.parentFloor")+ ":"' prop="shelvesId">
  19. <el-input :disabled="true" v-model="currNodeName" :placeholder='$t("common.pleaseEnter")'/>
  20. </el-form-item>
  21. <el-form-item :label='$t("lineSide.form.wareType")+ ":"' prop="storgeTypeId">
  22. <el-select v-model="tenant.storgeTypeId" :placeholder='$t("common.pleaseSelect")' style="width: 100%;">
  23. <el-option v-for="item in wareTypeList" :key="item.id" :label="item.name" :value="item.id"></el-option>
  24. </el-select>
  25. </el-form-item>
  26. <el-form-item :label='$t("common.weight")+":"' prop="weight">
  27. <el-input-number v-model="tenant.weight" :min="0" :max="99999999999" label=""></el-input-number>
  28. </el-form-item>
  29. <el-form-item :label='$t("lineSide.form.status")+":"' prop="status">
  30. <template>
  31. <el-radio v-model="tenant.status" label="1">{{$t("common.status.valid")}}</el-radio>
  32. <el-radio v-model="tenant.status" label="0">{{$t("common.status.stop")}}</el-radio>
  33. </template>
  34. </el-form-item>
  35. </el-form>
  36. <div slot="footer" class="dialog-footer">
  37. <el-button plain type="warning" @click="isVisible = false">{{ $t('common.cancel') }}</el-button>
  38. <el-button plain type="primary" :disabled="confirmDisabled" @click="submitForm">{{ $t('common.confirm') }}</el-button>
  39. </div>
  40. </el-dialog>
  41. </template>
  42. <script>
  43. // 【仓库类型管理】-API
  44. import warehouseTypeMgrApi from "@/api/modelingCenter/warehouseTypeMgr"
  45. // 【库位管理】-API
  46. import locationMgrApi from "@/api/lineSideLibrary/locationMgr"
  47. export default {
  48. name: 'TenantEdit',
  49. props: {
  50. dialogVisible: {
  51. type: Boolean,
  52. default: false
  53. },
  54. title: {
  55. type: String,
  56. default: ''
  57. }
  58. },
  59. data () {
  60. let validateExsit = (rule, value, callback) => {
  61. //后台方法
  62. if(this.type=="edit" && value === this.oldName){
  63. return callback()
  64. }
  65. this.checkExist(value).then(res => {
  66. res = res.data;
  67. // console.log("check验证:", res);
  68. if (res && res.data) {
  69. callback(new Error('名称已存在'))
  70. }else{
  71. callback()
  72. }
  73. })
  74. }
  75. return {
  76. type: 'add',
  77. currNodeName: '',
  78. oldName: '',
  79. tenant: this.initTenant(),
  80. screenWidth: 0,
  81. width: this.initWidth(),
  82. confirmDisabled: false,
  83. wareTypeList: [], // 库位类型下拉数据
  84. dicts:{
  85. NATION: {}
  86. },
  87. roles: [],
  88. rules: {
  89. no: [
  90. { required: true, message: this.$t("rules.require"), trigger: 'blur' }
  91. ],
  92. name: [
  93. { required: true, message: this.$t("rules.require"), trigger: 'blur' },
  94. { validator: validateExsit, trigger: 'blur'}
  95. ],
  96. storgeTypeId: [
  97. { required: true, message: this.$t("rules.require"), trigger: 'change' }
  98. ],
  99. weight: [
  100. { required: true, message: this.$t("rules.require"), trigger: 'change' }
  101. ],
  102. status: [
  103. { required: true, message: this.$t("rules.require"), trigger: 'change' }
  104. ]
  105. }
  106. }
  107. },
  108. // 实例已经在内存中创建好,此时data和methods已将ok,如果要操作data中的数据或是调用methods中的方法,最早只能在created中操作
  109. created() {
  110. // 获取【库位类型】数据
  111. this.getWareTypeList()
  112. },
  113. computed: {
  114. isVisible: {
  115. get () {
  116. return this.dialogVisible
  117. },
  118. set () {
  119. this.close()
  120. this.reset()
  121. }
  122. }
  123. },
  124. mounted () {
  125. window.onresize = () => {
  126. return (() => {
  127. this.width = this.initWidth()
  128. })()
  129. }
  130. },
  131. methods: {
  132. initTenant () {
  133. return {
  134. id: '',
  135. no: '',
  136. name: '',
  137. shelvesId: '',
  138. storgeTypeId: '',
  139. status: '1'
  140. }
  141. },
  142. initWidth () {
  143. this.screenWidth = document.body.clientWidth
  144. if (this.screenWidth < 991) {
  145. return '90%'
  146. } else if (this.screenWidth < 1400) {
  147. return '45%'
  148. } else {
  149. return '800px'
  150. }
  151. },
  152. setTenant (val, dicts, currNode) {
  153. console.log("货架数据:", currNode)
  154. if(val){
  155. this.tenant = { ...val }
  156. this.oldName = val.name
  157. }else{ // 如果是新增
  158. // 给【上级层】显示使用
  159. this.currNodeName = currNode.name
  160. // 给【上级层】赋值id
  161. this.tenant.shelvesId = currNode.id
  162. }
  163. // 字典表
  164. this.dicts = dicts
  165. },
  166. close () {
  167. this.$emit('close')
  168. },
  169. checkExist(name){
  170. return locationMgrApi.checkField({"name":name})
  171. },
  172. reset () {
  173. // 先清除校验,再清除表单,不然有奇怪的bug
  174. this.$refs.form.clearValidate()
  175. this.$refs.form.resetFields()
  176. this.tenant = this.initTenant()
  177. },
  178. submitForm () {
  179. this.$refs.form.validate((valid) => {
  180. if (valid) {
  181. this.confirmDisabled = true
  182. if (this.type === 'add') {
  183. this.save()
  184. } else {
  185. this.update()
  186. }
  187. } else {
  188. return false
  189. }
  190. })
  191. },
  192. save () {
  193. locationMgrApi.save(this.tenant)
  194. .then((response) => {
  195. const res = response.data
  196. if (res.isSuccess) {
  197. this.isVisible = false
  198. this.$message({
  199. message: this.$t('tips.createSuccess'),
  200. type: 'success'
  201. })
  202. // 通知列表
  203. this.$emit("success");
  204. // 通知列表-并关闭弹出框
  205. this.$emit("close");
  206. }
  207. }).finally(() => {
  208. this.confirmDisabled = false
  209. return true
  210. })
  211. },
  212. update () {
  213. locationMgrApi.update(this.tenant)
  214. .then((response) => {
  215. const res = response.data
  216. if (res.isSuccess) {
  217. this.isVisible = false
  218. this.$message({
  219. message: this.$t('tips.updateSuccess'),
  220. type: 'success'
  221. })
  222. // 通知列表
  223. this.$emit("success");
  224. // 通知列表-并关闭弹出框
  225. this.$emit("close");
  226. }
  227. }).finally(() => {
  228. this.confirmDisabled = false
  229. return true
  230. })
  231. },
  232. // 【库位类型】数据
  233. getWareTypeList(){
  234. warehouseTypeMgrApi.getList({}).then(res => {
  235. res = res.data
  236. if(res.isSuccess){
  237. this.wareTypeList = res.data
  238. }
  239. })
  240. }
  241. }
  242. }
  243. </script>
  244. <style lang="scss" >
  245. .avatar-uploader .el-upload {
  246. border: 1px dashed #d9d9d9;
  247. border-radius: 6px;
  248. cursor: pointer;
  249. position: relative;
  250. overflow: hidden;
  251. }
  252. .avatar-uploader .el-upload:hover {
  253. border-color: #409eff;
  254. }
  255. .avatar-uploader-icon {
  256. font-size: 28px;
  257. color: #8c939d;
  258. width: 100px;
  259. height: 100px;
  260. line-height: 100px;
  261. text-align: center;
  262. }
  263. .avatar {
  264. width: 100px;
  265. height: 100px;
  266. display: block;
  267. }
  268. .checkUsed{
  269. display: inline-block;
  270. margin-left: 10px;
  271. color: #1890ff;
  272. }
  273. </style>