index.vue 10 KB

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