index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. <template>
  2. <div class="container1">
  3. <div class="header" v-show="!addStatus && !editStatus">
  4. <Search :searchOptions="searchForm" ref="searchRef" />
  5. </div>
  6. <div class="table" v-if="!addStatus && !editStatus">
  7. <el-button
  8. type="primary"
  9. size="small"
  10. class="btn"
  11. style="margin-bottom: 10px"
  12. @click="toAdd"
  13. >新增</el-button
  14. >
  15. <el-table
  16. :data="tableData"
  17. border
  18. :style="{ height: maxHeight - 80 + 'px' }"
  19. >
  20. <el-table-column prop="taskCode" label="任务编号" />
  21. <el-table-column prop="prodtModel" label="产品型号" />
  22. <el-table-column prop="operationName" label="工序名称" />
  23. <el-table-column prop="source" label="采集数据源" />
  24. <el-table-column prop="param" label="控制参数" />
  25. <el-table-column prop="chart" label="控制图" />
  26. <el-table-column prop="address" label="预警规则">
  27. <template #default="{ row }">
  28. <el-button
  29. type="primary"
  30. class="btn"
  31. style="height: 25px"
  32. link
  33. @click="toRuler(row)"
  34. >编辑</el-button
  35. >
  36. </template>
  37. </el-table-column>
  38. <el-table-column prop="processCount" label="工序采集点数" />
  39. <el-table-column prop="centralValue" label="中心值" />
  40. <el-table-column prop="upperLimit" label="上限" />
  41. <el-table-column prop="floor" label="下限" />
  42. <el-table-column prop="created" label="创建时间" />
  43. <el-table-column
  44. align="center"
  45. width="160"
  46. prop=""
  47. label="操作"
  48. id="opear"
  49. >
  50. <template #default="{ row }">
  51. <el-button
  52. type="primary"
  53. class="btn"
  54. style="height: 25px"
  55. @click="toEdit(row)"
  56. link
  57. >编辑</el-button
  58. >
  59. <el-button
  60. type="info"
  61. class="btn"
  62. style="height: 25px"
  63. link
  64. @click="toDelete(row.id)"
  65. >删除</el-button
  66. >
  67. </template>
  68. </el-table-column>
  69. </el-table>
  70. <Pagination
  71. :total="currentOption.total"
  72. :page="currentOption.page"
  73. :limit="currentOption.limit"
  74. :pageSizes="currentOption.pageSizes"
  75. v-model:page="currentOption.page"
  76. v-model:limit="currentOption.limit"
  77. @pagination="getData"
  78. />
  79. </div>
  80. <div v-if="addStatus || editStatus" class="formView">
  81. <div class="formTitle">
  82. {{ addStatus ? "新增任务" : "编辑任务" }}
  83. </div>
  84. <el-scrollbar style="height: calc(100% - 60px)">
  85. <el-form
  86. ref="ruleFormRef"
  87. :model="formData"
  88. :rules="rules"
  89. label-width="auto"
  90. class="formStyle"
  91. >
  92. <el-form-item label="任务编号" prop="taskCode">
  93. <el-input v-model="formData.taskCode" />
  94. </el-form-item>
  95. <el-form-item label="产品型号" prop="Index1">
  96. <el-select v-model="formData.Index1">
  97. <el-option
  98. v-for="(item, index) in opInfoData"
  99. :key="index"
  100. :label="item.prodtModel"
  101. :value="index"
  102. />
  103. </el-select>
  104. </el-form-item>
  105. <el-form-item label="工序名称" prop="Index2">
  106. <el-select v-model="formData.Index2">
  107. <el-option
  108. v-for="(item, index) in opOptions"
  109. :key="index"
  110. :label="item.dictLabel"
  111. :value="index"
  112. />
  113. </el-select>
  114. </el-form-item>
  115. <el-form-item label="采集数据来源" prop="source">
  116. <el-select v-model="formData.source">
  117. <el-option label="自动" value="自动" />
  118. <el-option label="手动" value="手动" />
  119. </el-select>
  120. </el-form-item>
  121. <el-form-item label="控制参数" prop="param">
  122. <el-input v-model="formData.param" />
  123. </el-form-item>
  124. <el-form-item label="控制图" prop="chart">
  125. <el-input :disabled="true" v-model="formData.chart" />
  126. </el-form-item>
  127. <el-form-item label="工序采集点数" prop="processCount">
  128. <el-input-number
  129. v-model="formData.processCount"
  130. :min="1"
  131. :step="1"
  132. />
  133. </el-form-item>
  134. <el-form-item label="上限" prop="upperLimit">
  135. <el-input-number v-model="formData.upperLimit" />
  136. </el-form-item>
  137. <el-form-item label="下限" prop="floor">
  138. <el-input-number v-model="formData.floor" />
  139. </el-form-item>
  140. <el-form-item label="中心值" prop="centralValue">
  141. <el-input-number
  142. :min="formData.floor"
  143. :max="formData.upperLimit"
  144. v-model="formData.centralValue"
  145. />
  146. </el-form-item>
  147. </el-form>
  148. <div style="display: flex; justify-content: space-evenly">
  149. <el-button
  150. type="primary"
  151. size="small"
  152. style="margin-top: 10px"
  153. class="btn"
  154. @click="toSubmit"
  155. >提交</el-button
  156. >
  157. <el-button
  158. type="info"
  159. size="small"
  160. style="margin-top: 10px"
  161. class="btn"
  162. @click="toCancel"
  163. >取消</el-button
  164. >
  165. </div>
  166. </el-scrollbar>
  167. </div>
  168. </div>
  169. </template>
  170. <script setup>
  171. import Search from "@/components/Search/index.vue";
  172. import { useDictionaryStore, useSpcStore } from "@/store";
  173. import {
  174. getTableData,
  175. getBaseData,
  176. add,
  177. updateData,
  178. deleteData,
  179. } from "@/api/spc";
  180. defineOptions({
  181. name: "SPCrules",
  182. });
  183. const store = useSpcStore();
  184. const addStatus = ref(false);
  185. const editStatus = ref(false);
  186. const router = useRouter();
  187. const formData = ref({
  188. source: "手动",
  189. chart: "X-R",
  190. });
  191. const currentOption = reactive({
  192. total: 0,
  193. page: 1,
  194. limit: 10,
  195. });
  196. const showStatus = ref(true);
  197. const tableData = ref([]);
  198. const searchRef = ref(null);
  199. const searchForm = [
  200. {
  201. label: "创建时间",
  202. prop: "created",
  203. type: "daterange",
  204. },
  205. {
  206. label: "任务编号",
  207. prop: "taskCode",
  208. type: "input",
  209. },
  210. {
  211. label: "产品型号",
  212. prop: "prodtModel",
  213. type: "input",
  214. },
  215. ];
  216. const maxHeight = ref(null);
  217. const setHeight = () => {
  218. maxHeight.value = document.querySelector(".table").clientHeight;
  219. };
  220. const opInfoData2 = computed(() => {
  221. if (formData.value.Index1 != null) {
  222. return opInfoData.value[formData.value.Index1].operations;
  223. } else {
  224. return [];
  225. }
  226. });
  227. const toCancel = () => {
  228. reset();
  229. };
  230. const toRuler = (row) => {
  231. store.spcTaskObj = row;
  232. router.push({ name: "SPCrules" });
  233. };
  234. const getData = async (obj) => {
  235. const { data, code } = await getTableData({
  236. ...searchRef.value.searchForm,
  237. pageNo: currentOption.page,
  238. pageSize: currentOption.limit,
  239. });
  240. if (code == "200") {
  241. tableData.value = data.records;
  242. currentOption.total = data.totalCount;
  243. }
  244. };
  245. const ruleFormRef = ref(null);
  246. const { dicts } = useDictionaryStore();
  247. const opOptions = ref([...dicts.spc_operation]);
  248. const rules = {
  249. taskCode: [
  250. {
  251. required: true,
  252. trigger: "change",
  253. message: "请输入任务编号",
  254. },
  255. ],
  256. Index1: [
  257. {
  258. required: true,
  259. message: "请选择产品型号",
  260. trigger: "change",
  261. },
  262. ],
  263. Index2: [
  264. {
  265. required: true,
  266. message: "请选择工序名称",
  267. trigger: "change",
  268. },
  269. ],
  270. operationName: [
  271. {
  272. required: true,
  273. trigger: "change",
  274. message: "请选择工序名称",
  275. },
  276. ],
  277. source: [
  278. {
  279. required: true,
  280. trigger: "change",
  281. },
  282. ],
  283. chart: [
  284. {
  285. required: true,
  286. trigger: "change",
  287. },
  288. ],
  289. param: [
  290. {
  291. required: true,
  292. trigger: "change",
  293. },
  294. ],
  295. unit: [
  296. {
  297. required: true,
  298. trigger: "change",
  299. },
  300. ],
  301. processCount: [
  302. {
  303. required: true,
  304. trigger: "change",
  305. },
  306. ],
  307. centralValue: [
  308. {
  309. required: true,
  310. trigger: "change",
  311. },
  312. ],
  313. upperLimit: [
  314. {
  315. required: true,
  316. trigger: "change",
  317. },
  318. ],
  319. floor: [
  320. {
  321. required: true,
  322. trigger: "change",
  323. },
  324. ],
  325. };
  326. const opInfoData = ref([]);
  327. const toAdd = () => {
  328. addStatus.value = true;
  329. };
  330. const setEditFormData = (row) => {
  331. opInfoData.value.forEach((item, index) => {
  332. if (item.prodtCode == row.prodtCode) {
  333. formData.value.Index1 = index;
  334. }
  335. });
  336. opOptions.value.forEach((item, index) => {
  337. if (item.dictLabel == row.operationName) {
  338. formData.value.Index2 = index;
  339. }
  340. });
  341. };
  342. const toEdit = (row) => {
  343. formData.value = row;
  344. //设置index1 index2
  345. setEditFormData(row);
  346. editStatus.value = true;
  347. };
  348. const toDelete = async (id) => {
  349. const { code } = await deleteData({ id });
  350. if (code == "200") {
  351. ElMessage.success("操作成功");
  352. getData();
  353. }
  354. };
  355. const reset = () => {
  356. formData.value = {
  357. source: "手动",
  358. chart: "X-R",
  359. };
  360. addStatus.value = false;
  361. editStatus.value = false;
  362. };
  363. const toSubmit = async () => {
  364. if (addStatus.value) {
  365. await ruleFormRef.value.validate(async (valid, fields) => {
  366. if (valid) {
  367. const { data, code } = await add({
  368. chart: formData.value.chart,
  369. operationCode: opOptions.value[formData.value.Index2].dictValue,
  370. operationName: opOptions.value[formData.value.Index2].dictLabel,
  371. prodtCode: opInfoData.value[formData.value.Index1].prodtCode,
  372. prodtModel: opInfoData.value[formData.value.Index1].prodtModel,
  373. prodtName: opInfoData.value[formData.value.Index1].prodtName,
  374. unit: opInfoData.value[formData.value.Index1].unit,
  375. param: formData.value.param,
  376. source: formData.value.source,
  377. processCount: formData.value.processCount,
  378. centralValue: formData.value.centralValue,
  379. upperLimit: formData.value.upperLimit,
  380. floor: formData.value.floor,
  381. taskCode: formData.value.taskCode,
  382. });
  383. if (code == "200") {
  384. ElMessage.success("添加成功!");
  385. reset();
  386. getData();
  387. }
  388. } else {
  389. ElMessage.error("请检查表单信息");
  390. }
  391. });
  392. } else {
  393. await ruleFormRef.value.validate(async (valid, fields) => {
  394. if (valid) {
  395. const { data, code } = await updateData({
  396. ...formData.value,
  397. operationCode: opOptions.value[formData.value.Index2].dictValue,
  398. operationName: opOptions.value[formData.value.Index2].dictLabel,
  399. prodtCode: opInfoData.value[formData.value.Index1].prodtCode,
  400. prodtModel: opInfoData.value[formData.value.Index1].prodtModel,
  401. prodtName: opInfoData.value[formData.value.Index1].prodtName,
  402. unit: opInfoData.value[formData.value.Index1].unit,
  403. });
  404. if (code == "200") {
  405. ElMessage.success("修改成功!");
  406. reset();
  407. getData();
  408. }
  409. } else {
  410. ElMessage.error("请检查表单信息");
  411. }
  412. });
  413. }
  414. };
  415. const getBaseDatas = async () => {
  416. const { data, code } = await getBaseData();
  417. opInfoData.value = data;
  418. };
  419. onMounted(() => {
  420. setHeight();
  421. getBaseDatas();
  422. getData();
  423. });
  424. </script>
  425. <style scoped lang="scss">
  426. .container1 {
  427. background-color: white;
  428. width: 100%;
  429. height: 100%;
  430. padding: 20px;
  431. display: flex;
  432. flex-direction: column;
  433. .header {
  434. width: 100%;
  435. height: auto;
  436. }
  437. .table {
  438. flex: 1;
  439. padding-bottom: 20px;
  440. }
  441. .formView {
  442. width: 100%;
  443. height: 100%;
  444. display: flex;
  445. flex-direction: column;
  446. align-items: center;
  447. .formTitle {
  448. text-align: center;
  449. font-size: 20px;
  450. margin-bottom: 20px;
  451. }
  452. .formStyle {
  453. width: 400px;
  454. }
  455. }
  456. }
  457. </style>