Edit.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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. this.checkExist(value).then(res => {
  63. res = res.data;
  64. // console.log("check验证:", res);
  65. if (res && res.data) {
  66. callback(new Error('名称已存在'))
  67. }else{
  68. callback()
  69. }
  70. })
  71. }
  72. return {
  73. type: 'add',
  74. currNodeName: '',
  75. tenant: this.initTenant(),
  76. screenWidth: 0,
  77. width: this.initWidth(),
  78. confirmDisabled: false,
  79. wareTypeList: [], // 库位类型下拉数据
  80. dicts:{
  81. NATION: {}
  82. },
  83. roles: [],
  84. rules: {
  85. no: [
  86. { required: true, message: this.$t("rules.require"), trigger: 'blur' }
  87. ],
  88. name: [
  89. { required: true, message: this.$t("rules.require"), trigger: 'blur' },
  90. { validator: validateExsit, trigger: 'blur'}
  91. ],
  92. storgeTypeId: [
  93. { required: true, message: this.$t("rules.require"), trigger: 'change' }
  94. ],
  95. weight: [
  96. { required: true, message: this.$t("rules.require"), trigger: 'change' }
  97. ],
  98. status: [
  99. { required: true, message: this.$t("rules.require"), trigger: 'change' }
  100. ]
  101. }
  102. }
  103. },
  104. // 实例已经在内存中创建好,此时data和methods已将ok,如果要操作data中的数据或是调用methods中的方法,最早只能在created中操作
  105. created() {
  106. // 获取【库位类型】数据
  107. this.getWareTypeList()
  108. },
  109. computed: {
  110. isVisible: {
  111. get () {
  112. return this.dialogVisible
  113. },
  114. set () {
  115. this.close()
  116. this.reset()
  117. }
  118. }
  119. },
  120. mounted () {
  121. window.onresize = () => {
  122. return (() => {
  123. this.width = this.initWidth()
  124. })()
  125. }
  126. },
  127. methods: {
  128. initTenant () {
  129. return {
  130. id: '',
  131. no: '',
  132. name: '',
  133. shelvesId: '',
  134. storgeTypeId: '',
  135. status: '1'
  136. }
  137. },
  138. initWidth () {
  139. this.screenWidth = document.body.clientWidth
  140. if (this.screenWidth < 991) {
  141. return '90%'
  142. } else if (this.screenWidth < 1400) {
  143. return '45%'
  144. } else {
  145. return '800px'
  146. }
  147. },
  148. setTenant (val, dicts, currNode) {
  149. console.log("货架数据:", currNode)
  150. if(val){
  151. this.tenant = { ...val }
  152. }else{ // 如果是新增
  153. // 给【上级层】显示使用
  154. this.currNodeName = currNode.name
  155. // 给【上级层】赋值id
  156. this.tenant.shelvesId = currNode.id
  157. }
  158. // 字典表
  159. this.dicts = dicts
  160. },
  161. close () {
  162. this.$emit('close')
  163. },
  164. checkExist(name){
  165. return locationMgrApi.checkField({"name":name})
  166. },
  167. reset () {
  168. // 先清除校验,再清除表单,不然有奇怪的bug
  169. this.$refs.form.clearValidate()
  170. this.$refs.form.resetFields()
  171. this.tenant = this.initTenant()
  172. },
  173. submitForm () {
  174. this.$refs.form.validate((valid) => {
  175. if (valid) {
  176. this.confirmDisabled = true
  177. if (this.type === 'add') {
  178. this.save()
  179. } else {
  180. this.update()
  181. }
  182. } else {
  183. return false
  184. }
  185. })
  186. },
  187. save () {
  188. locationMgrApi.save(this.tenant)
  189. .then((response) => {
  190. const res = response.data
  191. if (res.isSuccess) {
  192. this.isVisible = false
  193. this.$message({
  194. message: this.$t('tips.createSuccess'),
  195. type: 'success'
  196. })
  197. // 通知列表
  198. this.$emit("success");
  199. // 通知列表-并关闭弹出框
  200. this.$emit("close");
  201. }
  202. }).finally(() => {
  203. this.confirmDisabled = false
  204. return true
  205. })
  206. },
  207. update () {
  208. locationMgrApi.update(this.tenant)
  209. .then((response) => {
  210. const res = response.data
  211. if (res.isSuccess) {
  212. this.isVisible = false
  213. this.$message({
  214. message: this.$t('tips.updateSuccess'),
  215. type: 'success'
  216. })
  217. // 通知列表
  218. this.$emit("success");
  219. // 通知列表-并关闭弹出框
  220. this.$emit("close");
  221. }
  222. }).finally(() => {
  223. this.confirmDisabled = false
  224. return true
  225. })
  226. },
  227. // 【库位类型】数据
  228. getWareTypeList(){
  229. warehouseTypeMgrApi.getList({}).then(res => {
  230. res = res.data
  231. if(res.isSuccess){
  232. this.wareTypeList = res.data
  233. }
  234. })
  235. }
  236. }
  237. }
  238. </script>
  239. <style lang="scss" >
  240. .avatar-uploader .el-upload {
  241. border: 1px dashed #d9d9d9;
  242. border-radius: 6px;
  243. cursor: pointer;
  244. position: relative;
  245. overflow: hidden;
  246. }
  247. .avatar-uploader .el-upload:hover {
  248. border-color: #409eff;
  249. }
  250. .avatar-uploader-icon {
  251. font-size: 28px;
  252. color: #8c939d;
  253. width: 100px;
  254. height: 100px;
  255. line-height: 100px;
  256. text-align: center;
  257. }
  258. .avatar {
  259. width: 100px;
  260. height: 100px;
  261. display: block;
  262. }
  263. .checkUsed{
  264. display: inline-block;
  265. margin-left: 10px;
  266. color: #1890ff;
  267. }
  268. </style>