station.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. <template>
  2. <div>
  3. <div class="query mg-b-8">
  4. <div class="query-items">
  5. <div class="query-item">
  6. <div class="lable">场站名称:</div>
  7. <div class="search-input">
  8. <el-input
  9. v-model="search"
  10. size="small"
  11. placeholder="输入场站名称"
  12. @input="filterStation"
  13. />
  14. </div>
  15. </div>
  16. </div>
  17. <div class="query-actions" style="margin-left: 50px">
  18. <button class="btn" @click="insertItem()">新增</button>
  19. </div>
  20. </div>
  21. <div class="df-table">
  22. <el-table :data="tableData" class="custom-table" height="80vh">
  23. <el-table-column type="index" label="序号" align="center" width="50" />
  24. <el-table-column prop="name" align="center" label="场站名称" />
  25. <el-table-column prop="id" align="center" label="场站编码" />
  26. <el-table-column prop="capacity" align="center" label="装机容量(MW)" />
  27. <el-table-column prop="model" align="center" label="风机型号" />
  28. <el-table-column prop="longitude" align="center" label="经度" />
  29. <el-table-column prop="latitude" align="center" label="纬度" />
  30. <el-table-column prop="manufacturer" align="center" label="风机厂商" />
  31. <el-table-column align="center" label="操作">
  32. <template v-slot="scope">
  33. <el-button type="text" @click="editItem(scope)">编辑</el-button>
  34. </template>
  35. </el-table-column>
  36. </el-table>
  37. <el-dialog
  38. :title="dialogTitle"
  39. v-model="dialogShow"
  40. width="50%"
  41. top="15vh"
  42. custom-class="modal"
  43. :close-on-click-modal="true"
  44. >
  45. <el-form
  46. ref="ruleFormRef"
  47. :model="ruleForm"
  48. :rules="rules"
  49. label-width="120px"
  50. size="default"
  51. >
  52. <div class="inlineItem">
  53. <el-form-item :label="`${ruleForm['name--name--']}:`" prop="name">
  54. <el-input
  55. v-model="ruleForm.name"
  56. :placeholder="`请输入${ruleForm['name--name--']}`"
  57. type="input"
  58. />
  59. </el-form-item>
  60. <el-form-item :label="`${ruleForm['id--name--']}:`" prop="id">
  61. <el-input
  62. v-model="ruleForm.id"
  63. :placeholder="`请输入${ruleForm['id--name--']}`"
  64. type="input"
  65. :disabled="codedisabled"
  66. />
  67. </el-form-item>
  68. </div>
  69. <div class="inlineItem">
  70. <el-form-item
  71. :label="`${ruleForm['capacity--name--']}:`"
  72. prop="capacity"
  73. >
  74. <el-input
  75. v-model="ruleForm.capacity"
  76. :placeholder="`请输入${ruleForm['capacity--name--']}`"
  77. type="input"
  78. />
  79. </el-form-item>
  80. <el-form-item
  81. :label="`${ruleForm['model--name--']}:`"
  82. prop="model"
  83. >
  84. <el-input
  85. v-model="ruleForm.model"
  86. :placeholder="`请输入${ruleForm['model--name--']}`"
  87. type="input"
  88. />
  89. </el-form-item>
  90. </div>
  91. <div class="inlineItem">
  92. <el-form-item
  93. :label="`${ruleForm['longitude--name--']}:`"
  94. prop="longitude"
  95. type="input"
  96. >
  97. <el-input
  98. v-model="ruleForm.longitude"
  99. :placeholder="'请输入风机型号用/隔开'"
  100. type="input"
  101. />
  102. </el-form-item>
  103. <el-form-item
  104. :label="`${ruleForm['latitude--name--']}:`"
  105. prop="latitude"
  106. >
  107. <el-input
  108. v-model="ruleForm.latitude"
  109. :placeholder="`请输入${ruleForm['latitude--name--']}`"
  110. type="input"
  111. />
  112. </el-form-item>
  113. </div>
  114. <div class="inlineItem">
  115. <el-form-item
  116. :label="`${ruleForm['manufacturer--name--']}:`"
  117. prop="manufacturer"
  118. >
  119. <el-select
  120. v-model="ruleForm.manufacturer"
  121. :placeholder="`请输入${ruleForm['manufacturer--name--']}`"
  122. popper-class="select"
  123. >
  124. <el-option
  125. v-for="item in manufacturerArray"
  126. :key="item.value"
  127. :value="item.value"
  128. :label="item.label"
  129. >
  130. </el-option>
  131. </el-select>
  132. </el-form-item>
  133. </div>
  134. </el-form>
  135. <template #footer>
  136. <span class="dialog-footer">
  137. <el-button type="info" size="medium" @click="cancel"
  138. >取消</el-button
  139. >
  140. <el-button
  141. type="success"
  142. size="medium"
  143. @click="submit('ruleFormRef')"
  144. >提交</el-button
  145. >
  146. </span>
  147. </template>
  148. </el-dialog>
  149. </div>
  150. </div>
  151. </template>
  152. <script>
  153. export default {
  154. data() {
  155. return {
  156. filterTableData: [],
  157. tableData: [],
  158. dialogTitle: "",
  159. dialogShow: false,
  160. codedisabled: false,
  161. ruleForm: {
  162. name: "",
  163. "name--name--": "场站名称",
  164. id: "",
  165. "id--name--": "场站编码",
  166. capacity: "",
  167. "capacity--name--": "装机容量",
  168. model: "",
  169. "model--name--": "风机型号",
  170. longitude: "",
  171. "longitude--name--": "经度",
  172. latitude: "",
  173. "latitude--name--": "经度",
  174. manufacturer: "",
  175. "manufacturer--name--": "风机厂商",
  176. },
  177. rules: {
  178. name: [
  179. {
  180. required: true,
  181. message: "不可为空",
  182. trigger: "blur",
  183. },
  184. ],
  185. id: [
  186. {
  187. required: true,
  188. message: "不可为空",
  189. trigger: "blur",
  190. },
  191. ],
  192. capacity: [
  193. {
  194. required: true,
  195. message: "不可为空",
  196. trigger: "blur",
  197. },
  198. ],
  199. model: [
  200. {
  201. required: true,
  202. message: "不可为空",
  203. trigger: "blur",
  204. },
  205. ],
  206. longitude: [
  207. {
  208. required: true,
  209. message: "不可为空",
  210. trigger: "blur",
  211. },
  212. ],
  213. latitude: [
  214. {
  215. required: true,
  216. message: "不可为空",
  217. trigger: "blur",
  218. },
  219. ],
  220. manufacturer: [
  221. {
  222. required: true,
  223. message: "不可为空",
  224. trigger: "blur",
  225. },
  226. ],
  227. },
  228. manufacturerArray: [
  229. { label: "联合动力", value: "联合动力" },
  230. { label: "华创", value: "华创" },
  231. ],
  232. };
  233. },
  234. created() {
  235. this.getStationType();
  236. this.renderRules();
  237. },
  238. methods: {
  239. filterStation(value) {
  240. if (value) {
  241. let tableData = [];
  242. this.filterTableData.forEach((ele) => {
  243. if (ele.name.indexOf(value) !== -1) {
  244. tableData.push(ele);
  245. }
  246. });
  247. this.tableData = tableData;
  248. } else {
  249. this.tableData = this.filterTableData;
  250. }
  251. },
  252. // 获取所有故障类型
  253. getStationType() {
  254. const that = this;
  255. this.API.requestData({
  256. subUrl: "basic/station/all",
  257. success(res) {
  258. that.tableData = res.data;
  259. that.filterTableData = res.data;
  260. },
  261. });
  262. },
  263. // 取消新增或编辑
  264. cancel() {
  265. this.dialogShow = false;
  266. },
  267. //新增
  268. insertItem() {
  269. this.resetForm();
  270. this.dialogShow = true;
  271. this.dialogTitle = "新增";
  272. this.codedisabled = false;
  273. },
  274. // 编辑某一条
  275. editItem({ row }) {
  276. for (let key in row) {
  277. if (key !== "time") {
  278. this.ruleForm[key] = row[key];
  279. }
  280. }
  281. this.dialogShow = true;
  282. this.dialogTitle = "编辑";
  283. this.codedisabled = true;
  284. },
  285. // 提交编辑或者新增数据
  286. submit(formName = "") {
  287. const that = this;
  288. that.$refs[formName].validate((valid) => {
  289. if (valid) {
  290. let data = {};
  291. for (let key in that.ruleForm) {
  292. if (key.indexOf("--name--") === -1) {
  293. data[key] = that.ruleForm[key];
  294. }
  295. }
  296. data.time = new Date().formatDate("yyyy-MM-dd hh:mm:ss");
  297. data.category = "GZ";
  298. that.API.request({
  299. method: "POST",
  300. subUrl: "know/fault/type/insert",
  301. data,
  302. success() {
  303. that.BASE.showMsg({
  304. type: "success",
  305. msg: `${data.id ? "编辑" : "新增"}成功`,
  306. });
  307. that.dialogShow = false;
  308. that.getStationType();
  309. },
  310. });
  311. } else {
  312. return false;
  313. }
  314. });
  315. },
  316. // 渲染 rules 中文描述
  317. renderRules() {
  318. for (let key in this.rules) {
  319. this.rules[key].forEach((ele) => {
  320. ele.message = `${this.ruleForm[key + "--name--"]}` + ele.message;
  321. });
  322. }
  323. },
  324. // 重置表单并且重置表单效验
  325. resetForm() {
  326. this.dialogTitle = "";
  327. this.ruleForm.id && delete this.ruleForm.id;
  328. for (let key in this.ruleForm) {
  329. if (key.indexOf("--name--") === -1) {
  330. this.ruleForm[key] = "";
  331. }
  332. }
  333. },
  334. },
  335. };
  336. </script>
  337. <style lang="less" scpoed>
  338. .el-form {
  339. margin-left: 50px;
  340. }
  341. .el-form .el-form-item {
  342. margin-top: 40px;
  343. width: 80%;
  344. display: flex;
  345. justify-items: center;
  346. }
  347. .el-form {
  348. display: flex;
  349. justify-content: start;
  350. align-items: center;
  351. flex-wrap: wrap;
  352. .inlineItem {
  353. width: 100%;
  354. display: flex;
  355. justify-content: start;
  356. align-items: center;
  357. height: 80px;
  358. .el-form-item {
  359. width: 100%;
  360. margin-bottom: 40px;
  361. .el-input__count {
  362. background: rgba(83, 98, 104, 0.2);
  363. color: #b3bdc0;
  364. }
  365. .el-input{
  366. width: 250px;
  367. }
  368. .el-select{
  369. width: 250px;
  370. }
  371. }
  372. }
  373. }
  374. </style>