plm前端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

436 lines
14 KiB

2 years ago
2 years ago
2 years ago
2 years ago
  1. <script>
  2. import {selectDeviceList,editDevice, removeDevice, saveDevice} from "../../../api/cdc/device";
  3. import dayjs from "dayjs";
  4. const tableId = "2000001"
  5. const tableName = "设备信息"
  6. const table1 = "2000001Table1"
  7. export default {
  8. name: "device",
  9. props:{
  10. height:{
  11. type:Number,
  12. default:700
  13. },
  14. component:{
  15. type:Boolean,
  16. default: false
  17. }
  18. },
  19. data(){
  20. return{
  21. // 遮罩层
  22. loading: true,
  23. // 设备信息表格数据
  24. infoList: [],
  25. // 弹出层标题
  26. title: "设备信息",
  27. // 是否显示弹出层
  28. open: false,
  29. // 查询参数
  30. queryParams: {
  31. deviceNo: '',
  32. deviceDesc: null,
  33. deviceType: "",
  34. },
  35. // 表单参数
  36. form: {},
  37. // 表单校验
  38. rules: {
  39. deviceDesc: [
  40. { required: true, message: "设备描述不能为空", trigger: "blur" }
  41. ],
  42. deviceType: [
  43. { required: true, message: "设备类型不能为空", trigger: "change" }
  44. ],
  45. deviceIp: [
  46. { required: true, message: "采集HTTP信息不能为空", trigger: "blur" }
  47. ],
  48. deviceNo: [
  49. { required: true, message: "设备号不能为空", trigger: "blur" }
  50. ],
  51. },
  52. deviceColumns:[
  53. {
  54. userId: this.$store.state.user.name,
  55. functionId: tableId,
  56. serialNumber: `${table1}DeviceNo`,
  57. tableId: table1,
  58. tableName: tableName,
  59. columnProp: 'deviceNo',
  60. headerAlign: 'center',
  61. align: 'left',
  62. columnLabel: '设备号',
  63. columnHidden: false,
  64. columnImage: false,
  65. columnSortable: false,
  66. sortLv: 0,
  67. status: true,
  68. fixed: '',
  69. columnWidth: 100
  70. },{
  71. userId: this.$store.state.user.name,
  72. functionId: tableId,
  73. serialNumber: `${table1}DeviceDesc`,
  74. tableId: table1,
  75. tableName: tableName,
  76. columnProp: 'deviceDesc',
  77. headerAlign: 'center',
  78. align: 'left',
  79. columnLabel: '设备描述',
  80. columnHidden: false,
  81. columnImage: false,
  82. columnSortable: false,
  83. sortLv: 0,
  84. status: true,
  85. fixed: '',
  86. columnWidth: 120
  87. },{
  88. userId: this.$store.state.user.name,
  89. functionId: tableId,
  90. serialNumber: `${table1}DeviceType`,
  91. tableId: table1,
  92. tableName: tableName,
  93. columnProp: 'deviceType',
  94. headerAlign: 'center',
  95. align: 'left',
  96. columnLabel: '设备类型',
  97. columnHidden: false,
  98. columnImage: false,
  99. columnSortable: false,
  100. sortLv: 0,
  101. status: true,
  102. fixed: '',
  103. columnWidth: 100
  104. },{
  105. userId: this.$store.state.user.name,
  106. functionId: tableId,
  107. serialNumber: `${table1}AddressDesc`,
  108. tableId: table1,
  109. tableName: tableName,
  110. columnProp: 'addressDesc',
  111. headerAlign: 'center',
  112. align: 'left',
  113. columnLabel: '位置描述',
  114. columnHidden: false,
  115. columnImage: false,
  116. columnSortable: false,
  117. sortLv: 0,
  118. status: true,
  119. fixed: '',
  120. columnWidth: 120
  121. },{
  122. userId: this.$store.state.user.name,
  123. functionId: tableId,
  124. serialNumber: `${table1}DeviceIp`,
  125. tableId: table1,
  126. tableName: tableName,
  127. columnProp: 'deviceIp',
  128. headerAlign: 'center',
  129. align: 'left',
  130. columnLabel: '采集HTTP信息',
  131. columnHidden: false,
  132. columnImage: false,
  133. columnSortable: false,
  134. sortLv: 0,
  135. status: true,
  136. fixed: '',
  137. columnWidth: 120
  138. },{
  139. userId: this.$store.state.user.name,
  140. functionId: tableId,
  141. serialNumber: `${table1}Active`,
  142. tableId: table1,
  143. tableName: tableName,
  144. columnProp: 'active',
  145. headerAlign: 'center',
  146. align: 'center',
  147. columnLabel: '在用',
  148. columnHidden: false,
  149. columnImage: false,
  150. columnSortable: false,
  151. sortLv: 0,
  152. status: true,
  153. fixed: '',
  154. columnWidth: 80
  155. },{
  156. userId: this.$store.state.user.name,
  157. functionId: tableId,
  158. serialNumber: `${table1}CreateBy`,
  159. tableId: table1,
  160. tableName: tableName,
  161. columnProp: 'createBy',
  162. headerAlign: 'center',
  163. align: 'left',
  164. columnLabel: '录入人',
  165. columnHidden: false,
  166. columnImage: false,
  167. columnSortable: false,
  168. sortLv: 0,
  169. status: true,
  170. fixed: '',
  171. columnWidth: 100
  172. },{
  173. userId: this.$store.state.user.name,
  174. functionId: tableId,
  175. serialNumber: `${table1}CreateTime`,
  176. tableId: table1,
  177. tableName: tableName,
  178. columnProp: 'createTime',
  179. headerAlign: 'center',
  180. align: 'center',
  181. columnLabel: '录入时间',
  182. columnHidden: false,
  183. columnImage: false,
  184. columnSortable: false,
  185. sortLv: 0,
  186. status: true,
  187. fixed: '',
  188. columnWidth: 120
  189. },
  190. ],
  191. }
  192. },
  193. methods:{
  194. /** 查询设备信息列表 */
  195. getList() {
  196. let params = {
  197. ...this.queryParams,
  198. site:this.$store.state.user.site
  199. }
  200. this.loading = true;
  201. selectDeviceList(params).then(({data}) => {
  202. if (data && data.code === 0){
  203. this.infoList = data.rows;
  204. }
  205. this.loading = false;
  206. }).catch(() => {
  207. this.loading = false;
  208. });
  209. },
  210. // 取消按钮
  211. cancel() {
  212. this.open = false;
  213. this.reset();
  214. },
  215. // 表单重置
  216. reset() {
  217. this.form = {
  218. deviceNo: '',
  219. site: null,
  220. deviceDesc: null,
  221. deviceType: '',
  222. addressDesc: null,
  223. deviceIp: null,
  224. deviceAddress: null,
  225. active: 'Y',
  226. createBy: null,
  227. createTime: null
  228. };
  229. this.resetForm("form");
  230. },
  231. /** 搜索按钮操作 */
  232. handleQuery() {
  233. this.getList();
  234. },
  235. /** 新增按钮操作 */
  236. handleAdd() {
  237. this.reset();
  238. this.open = true;
  239. },
  240. /** 修改按钮操作 */
  241. handleUpdate(row) {
  242. this.reset();
  243. this.form = {...row}
  244. this.form.newDeviceNo = this.form.deviceNo;
  245. this.open = true;
  246. },
  247. /** 提交按钮 */
  248. submitForm() {
  249. this.$refs["form"].validate((valid,obj) => {
  250. if (valid) {
  251. if (!this.form.newDeviceNo) {
  252. this.form.site = this.$store.state.user.site;
  253. this.form.createBy = this.$store.state.user.name;
  254. this.form.createTime = dayjs().format("YYYY-MM-DD HH:mm:ss");
  255. saveDevice(this.form).then(({data}) => {
  256. this.form.site = null;
  257. if (data && data.code === 0){
  258. this.$message.success(data.msg);
  259. this.open = false;
  260. this.getList();
  261. }else {
  262. this.$message.warning(data.msg);
  263. }
  264. }).catch((error)=>{
  265. this.$message.error(error);
  266. });
  267. } else {
  268. editDevice(this.form).then(({data}) => {
  269. if (data && data.code === 0){
  270. this.$message.success(data.msg);
  271. this.open = false;
  272. this.getList();
  273. }else {
  274. this.$message.warning(data.msg);
  275. }
  276. }).catch((error)=>{
  277. this.$message.error(error);
  278. });
  279. }
  280. }else {
  281. Object.keys(obj).forEach((key)=>{
  282. this.$message.warning(obj[key][0].message);
  283. return
  284. })
  285. }
  286. });
  287. },
  288. handleDelete(row) {
  289. this.$confirm('此操作将永久删除该设备信息, 是否继续?', '提示', {
  290. confirmButtonText: '确定',
  291. cancelButtonText: '取消',
  292. type: 'warning'
  293. }).then(() => {
  294. removeDevice(row).then(({data})=>{
  295. if (data && data.code === 0){
  296. this.$message.success(data.msg);
  297. this.getList();
  298. }else {
  299. this.$message.success(data.msg);
  300. }
  301. }).catch((error)=>{
  302. this.$message.error(error);
  303. })
  304. }).catch(() => {
  305. });
  306. },
  307. },
  308. watch:{
  309. "queryParams.deviceNo"(newVal, oldVal){
  310. this.queryParams.deviceNo = newVal.toUpperCase();
  311. },
  312. "form.deviceNo"(newVal, oldVal){
  313. this.form.deviceNo = newVal.toUpperCase();
  314. },
  315. },
  316. created() {
  317. this.getList();
  318. }
  319. }
  320. </script>
  321. <template>
  322. <div class="app-container">
  323. <el-form :model="queryParams" label-position="top" ref="queryForm" :inline="true" label-width="68px">
  324. <el-form-item label="设备号" prop="deviceNo">
  325. <el-input
  326. v-model="queryParams.deviceNo"
  327. placeholder="请输入设备号"
  328. clearable
  329. />
  330. </el-form-item>
  331. <el-form-item label="设备描述" prop="deviceDesc">
  332. <el-input
  333. v-model="queryParams.deviceDesc"
  334. placeholder="请输入设备描述"
  335. clearable
  336. />
  337. </el-form-item>
  338. <el-form-item label="设备类型" prop="deviceType">
  339. <el-select v-model="queryParams.deviceType" placeholder="请选择设备类型" >
  340. <el-option label="全部" value=""/>
  341. <el-option label="涂布机器-大线" value="涂布机器-大线"/>
  342. <el-option label="涂布机器-小线" value="涂布机器-小线"/>
  343. <el-option label="涂布机器-浓度-大线" value="涂布机器-浓度-大线"/>
  344. <el-option label="涂布机器-浓度-小线" value="涂布机器-浓度-小线"/>
  345. <el-option label="配胶间设备" value="配胶间设备"/>
  346. </el-select>
  347. </el-form-item>
  348. <el-form-item label=" ">
  349. <el-button type="primary" @click="handleQuery" plain>查询</el-button>
  350. <el-button type="primary" @click="handleAdd" v-if="!component">新增</el-button>
  351. </el-form-item>
  352. </el-form>
  353. <el-table v-loading="loading" border :data="infoList" :height="height">
  354. <el-table-column label="操作" align="center" v-if="!component">
  355. <template slot-scope="scope">
  356. <el-link @click="handleUpdate(scope.row)">编辑</el-link>
  357. <el-link @click="handleDelete(scope.row)">删除</el-link>
  358. </template>
  359. </el-table-column>
  360. <el-table-column
  361. v-for="(item,index) in deviceColumns" :key="index"
  362. :sortable="item.columnSortable"
  363. :prop="item.columnProp"
  364. :header-align="item.headerAlign"
  365. :show-overflow-tooltip="item.showOverflowTooltip"
  366. :align="item.align"
  367. :fixed="item.fixed === ''?false:item.fixed"
  368. :min-width="item.columnWidth"
  369. :label="item.columnLabel">
  370. <template slot-scope="scope">
  371. <span v-if="!item.columnHidden">{{ scope.row[item.columnProp] }}</span>
  372. <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]" style="width: 100px; height: 80px"/></span>
  373. </template>
  374. </el-table-column>
  375. </el-table>
  376. <!-- 添加或修改设备信息对话框 -->
  377. <el-dialog :title="title" v-if="!component" v-drag :visible.sync="open" width="500px" append-to-body>
  378. <el-form ref="form" label-position="top" :model="form" :rules="rules" label-width="80px">
  379. <el-row :gutter="10">
  380. <el-col :span="6">
  381. <el-form-item label="设备号" prop="deviceNo" :show-message="false">
  382. <el-input v-model="form.deviceNo" :disabled="form.newDeviceNo" placeholder="请输入设备号" />
  383. </el-form-item>
  384. </el-col>
  385. <el-col :span="18">
  386. <el-form-item label="设备描述" prop="deviceDesc" :show-message="false">
  387. <el-input v-model="form.deviceDesc" placeholder="请输入设备描述" />
  388. </el-form-item>
  389. </el-col>
  390. <el-col :span="6">
  391. <el-form-item label="设备类型" prop="deviceType" :show-message="false">
  392. <el-select v-model="form.deviceType" placeholder="请选择设备类型">
  393. <el-option label="涂布机器-大线" value="涂布机器-大线"/>
  394. <el-option label="涂布机器-小线" value="涂布机器-小线"/>
  395. <el-option label="涂布机器-浓度-大线" value="涂布机器-浓度-大线"/>
  396. <el-option label="涂布机器-浓度-小线" value="涂布机器-浓度-小线"/>
  397. <el-option label="配胶间设备" value="配胶间设备"/>
  398. </el-select>
  399. </el-form-item>
  400. </el-col>
  401. <el-col :span="18">
  402. <el-form-item label="位置描述" prop="addressDesc" :show-message="false">
  403. <el-input v-model="form.addressDesc" placeholder="请输入位置描述" />
  404. </el-form-item>
  405. </el-col>
  406. <el-col :span="18">
  407. <el-form-item label="采集IP" prop="deviceIp" :show-message="false">
  408. <el-input v-model="form.deviceAddress" placeholder="请输入采集IP" />
  409. </el-form-item>
  410. </el-col>
  411. <el-col :span="18">
  412. <el-form-item label="采集HTTP信息" prop="deviceIp" :show-message="false">
  413. <el-input v-model="form.deviceIp" placeholder="请输入采集HTTP信息" />
  414. </el-form-item>
  415. </el-col>
  416. <el-col :span="6">
  417. <el-form-item label=" " prop="active" :show-message="false">
  418. <el-checkbox v-model="form.active" true-label="Y" false-label="N">在用</el-checkbox>
  419. </el-form-item>
  420. </el-col>
  421. </el-row>
  422. </el-form>
  423. <div slot="footer" class="dialog-footer">
  424. <el-button type="primary" @click="submitForm"> </el-button>
  425. <el-button @click="cancel"> </el-button>
  426. </div>
  427. </el-dialog>
  428. </div>
  429. </template>
  430. <style scoped>
  431. </style>