Edit.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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.toolName")+":"' 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.no")+":"' prop="no">
  16. <el-input v-model="tenant.no" :placeholder='$t("common.pleaseEnter")'/>
  17. </el-form-item>
  18. <!-- <el-form-item :label='$t("lineSide.form.type")+":"' prop="type">
  19. <template>
  20. <el-radio v-model="tenant.type" label="1">{{$t("lineSide.common.tool")}}</el-radio>
  21. <el-radio v-model="tenant.type" label="0">{{$t("lineSide.common.local")}}</el-radio>
  22. </template>
  23. </el-form-item>-->
  24. <el-form-item :label='$t("lineSide.form.toolType")+":"' prop="toolType">
  25. <template>
  26. <el-radio v-model="tenant.toolType" label="0">{{$t("lineSide.common.central")}}</el-radio>
  27. <el-radio v-model="tenant.toolType" label="1">{{$t("lineSide.common.lathe")}}</el-radio>
  28. <el-radio v-model="tenant.toolType" label="2">机器人随行货架</el-radio>
  29. <el-radio v-model="tenant.toolType" label="3">机床刀具缓存库</el-radio>
  30. <el-radio v-model="tenant.toolType" label="4">接驳位</el-radio>
  31. <el-radio v-model="tenant.toolType" label="5">随行工装</el-radio>
  32. </template>
  33. </el-form-item>
  34. <el-form-item :label='$t("lineSide.form.pic")+":"' prop="pic">
  35. <el-input v-model="tenant.pic" :placeholder='$t("common.pleaseEnter")'/>
  36. </el-form-item>
  37. <el-form-item :label='$t("lineSide.form.address")+":"' prop="address">
  38. <el-input v-model="tenant.address" :placeholder='$t("common.pleaseEnter")'/>
  39. </el-form-item>
  40. <!-- <el-form-item :label='$t("lineSide.form.parentTool")' prop="parentId">
  41. &lt;!&ndash; 调用树形下拉框组件 &ndash;&gt;
  42. <tree-select
  43. key='100'
  44. :props="props"
  45. :options="list"
  46. :value="tenant.parentId"
  47. :clearable="isClearable"
  48. :accordion="isAccordion"
  49. @getValue="getValue($event)"
  50. style="width: 100%;"
  51. />
  52. </el-form-item>-->
  53. <el-form-item :label='$t("lineSide.form.deviceId")' prop="deviceId" >
  54. <el-select v-model="tenant.deviceId" style="width: 50%">
  55. <el-option v-for="(item, index) in deviceList" :key="index" :label="item.name" :value="item.id" />
  56. </el-select>
  57. </el-form-item>
  58. <!-- <el-form-item :label='$t("lineSide.form.weight")+":"' prop="weight">
  59. <el-input-number v-model="tenant.weight" :min="0" :max="9999999999"></el-input-number>
  60. </el-form-item>-->
  61. <el-form-item :label='$t("lineSide.form.status")+":"' prop="status">
  62. <template>
  63. <el-radio v-model="tenant.status" label="1">{{$t("common.show")}}</el-radio>
  64. <el-radio v-model="tenant.status" label="0">{{$t("common.hide")}}</el-radio>
  65. </template>
  66. </el-form-item>
  67. </el-form>
  68. <div slot="footer" class="dialog-footer">
  69. <el-button plain type="warning" @click="isVisible = false">{{ $t('common.cancel') }}</el-button>
  70. <el-button plain type="primary" :disabled="confirmDisabled" @click="submitForm">{{ $t('common.confirm') }}</el-button>
  71. </div>
  72. </el-dialog>
  73. </template>
  74. <script>
  75. // 【货架管理】-API
  76. import toolManagementApi from "@/api/modelingCenter/toolManagement";
  77. import TreeSelect from "@/components/TreeSelect/TreeSelect";
  78. export default {
  79. name: 'TenantEdit',
  80. components: {
  81. TreeSelect
  82. },
  83. props: {
  84. dialogVisible: {
  85. type: Boolean,
  86. default: false
  87. },
  88. title: {
  89. type: String,
  90. default: ''
  91. }
  92. },
  93. data () {
  94. let validateExsit = (rule, value, callback) => {
  95. //后台方法
  96. if(this.type=="edit" && value === this.oldName){
  97. return callback()
  98. }
  99. this.checkExist(value).then(res => {
  100. res = res.data
  101. if (res && res.data) {
  102. callback(new Error('名称已存在'))
  103. }else{
  104. callback()
  105. }
  106. })
  107. }
  108. return {
  109. isClearable: true, // 可清空(可选)
  110. isAccordion: true, // 可收起(可选)
  111. props: {
  112. // 配置项(必选)
  113. value: "id",
  114. label: "name",
  115. children: "children"
  116. // disabled:true
  117. },
  118. // 选项列表(必选)
  119. list: [],
  120. deviceList: [],
  121. type: 'add',
  122. oldName: '',
  123. tenant: this.initTenant(),
  124. screenWidth: 0,
  125. width: this.initWidth(),
  126. confirmDisabled: false,
  127. showToolType: false,
  128. dicts:{
  129. NATION: {}
  130. },
  131. roles: [],
  132. rules: {
  133. name: [
  134. { required: true, message: this.$t("rules.require"), trigger: 'blur' },
  135. { validator: validateExsit, trigger: 'blur'}
  136. ],
  137. no: [
  138. { required: true, message: this.$t("lineSide.rules.no"), trigger: 'blur' }
  139. ],
  140. type: [
  141. { required: true, message: this.$t("rules.require"), trigger: 'blur' }
  142. ],
  143. toolType: [
  144. { required: true, message: this.$t("rules.require"), trigger: 'blur' }
  145. ],
  146. }
  147. }
  148. },
  149. // 实例已经在内存中创建好,此时data和methods已将ok,如果要操作data中的数据或是调用methods中的方法,最早只能在created中操作
  150. created() {
  151. },
  152. computed: {
  153. isVisible: {
  154. get () {
  155. return this.dialogVisible
  156. },
  157. set () {
  158. this.close()
  159. this.reset()
  160. }
  161. }
  162. },
  163. mounted () {
  164. window.onresize = () => {
  165. return (() => {
  166. this.width = this.initWidth()
  167. })()
  168. }
  169. },
  170. methods: {
  171. // 取值
  172. getValue(value) {
  173. this.tenant.parentId = value;
  174. console.log(this.tenant.parentId);
  175. },
  176. getDeviceValue(value) {
  177. this.tenant.deviceId = value;
  178. console.log("tenant.deviceId:", this.tenant.deviceId);
  179. },
  180. initTenant () {
  181. return {
  182. id: '',
  183. name: '',
  184. parentId: '',
  185. deviceId: '',
  186. weight: null,
  187. status: '1',
  188. pic: null,
  189. address: null
  190. }
  191. },
  192. initWidth () {
  193. this.screenWidth = document.body.clientWidth
  194. if (this.screenWidth < 991) {
  195. return '90%'
  196. } else if (this.screenWidth < 1400) {
  197. return '45%'
  198. } else {
  199. return '800px'
  200. }
  201. },
  202. setTenant (val, dicts) {
  203. if(val){
  204. this.tenant = { ...val }
  205. this.oldName = val.name
  206. console.log("row数据:", val)
  207. }else{
  208. // 新增没有数据
  209. this.tenant.parentId = '0'
  210. }
  211. // 字典表
  212. this.dicts = dicts
  213. // 加载列表数据
  214. this.getTreeList()
  215. this.getProductionresourceList()
  216. },
  217. close () {
  218. this.$emit('close')
  219. },
  220. checkExist(name){
  221. return toolManagementApi.checkField({"name":name})
  222. },
  223. reset () {
  224. // 先清除校验,再清除表单,不然有奇怪的bug
  225. this.$refs.form.clearValidate()
  226. this.$refs.form.resetFields()
  227. this.tenant = this.initTenant()
  228. // 清楚数据
  229. this.tenant.parentId = ''
  230. },
  231. submitForm () {
  232. this.$refs.form.validate((valid) => {
  233. if (valid) {
  234. this.confirmDisabled = true
  235. if (this.type === 'add') {
  236. this.save()
  237. } else {
  238. this.update()
  239. }
  240. } else {
  241. return false
  242. }
  243. })
  244. },
  245. save () {
  246. toolManagementApi.save(this.tenant)
  247. .then((response) => {
  248. const res = response.data
  249. if (res.isSuccess) {
  250. this.isVisible = false
  251. this.$message({
  252. message: this.$t('tips.createSuccess'),
  253. type: 'success'
  254. })
  255. // 通知列表
  256. this.$emit("success");
  257. // 通知列表-并关闭弹出框
  258. this.$emit("close");
  259. }
  260. }).finally(() => {
  261. this.confirmDisabled = false
  262. return true
  263. })
  264. },
  265. update () {
  266. toolManagementApi.update(this.tenant)
  267. .then((response) => {
  268. const res = response.data
  269. if (res.isSuccess) {
  270. this.isVisible = false
  271. this.$message({
  272. message: this.$t('tips.updateSuccess'),
  273. type: 'success'
  274. })
  275. // 通知列表
  276. this.$emit("success");
  277. // 通知列表-并关闭弹出框
  278. this.$emit("close");
  279. }
  280. }).finally(() => {
  281. this.confirmDisabled = false
  282. return true
  283. })
  284. },
  285. // 获取【上级货架】下拉数据
  286. getTreeList(){
  287. toolManagementApi.getTreeList({}).then(res => {
  288. res = res.data
  289. if(res.isSuccess){
  290. console.log("获取【上级货架】下拉数据: ", res)
  291. this.list = res.data
  292. }
  293. })
  294. },
  295. /*updateShowToolType() {
  296. // 根据选择的 type 控制是否显示 toolType 输入框
  297. this.showToolType = this.tenant.toolType === '1'; // 或者根据其他条件设置 showToolType 的值
  298. },*/
  299. // 获取【上级货架】下拉数据
  300. getProductionresourceList(){
  301. toolManagementApi.getAllList({}).then(res => {
  302. res = res.data
  303. if(res.isSuccess){
  304. console.log("获取【设备】下拉数据: ", res)
  305. this.deviceList = res.data
  306. if (this.deviceList.length == 1) {
  307. this.deviceId = this.deviceList[0].id;
  308. }
  309. }
  310. })
  311. }
  312. }
  313. }
  314. </script>
  315. <style lang="scss" >
  316. .avatar-uploader .el-upload {
  317. border: 1px dashed #d9d9d9;
  318. border-radius: 6px;
  319. cursor: pointer;
  320. position: relative;
  321. overflow: hidden;
  322. }
  323. .avatar-uploader .el-upload:hover {
  324. border-color: #409eff;
  325. }
  326. .avatar-uploader-icon {
  327. font-size: 28px;
  328. color: #8c939d;
  329. width: 100px;
  330. height: 100px;
  331. line-height: 100px;
  332. text-align: center;
  333. }
  334. .avatar {
  335. width: 100px;
  336. height: 100px;
  337. display: block;
  338. }
  339. .checkUsed{
  340. display: inline-block;
  341. margin-left: 10px;
  342. color: #1890ff;
  343. }
  344. </style>