processComponent.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. <template>
  2. <div
  3. class="mainContentBox"
  4. style="padding: 0; box-shadow: 0px 2px 4px 0px rgba(0, 0, 0, 0.1)"
  5. >
  6. <div class="header">
  7. <div class="title">绑定工序</div>
  8. <el-space>
  9. <el-button :icon="Back" size="small" @click="back">返回</el-button>
  10. <el-button
  11. :type="isChanged ? 'danger' : 'primary'"
  12. :icon="Document"
  13. size="small"
  14. @click="save"
  15. >保存</el-button
  16. >
  17. </el-space>
  18. </div>
  19. <div class="types">
  20. <el-dropdown @command="handleCommand">
  21. <div class="typeBox addBtn">
  22. <el-icon class="icon"><CirclePlus /></el-icon>
  23. <div class="name">添加组件</div>
  24. </div>
  25. <template #dropdown>
  26. <el-dropdown-menu>
  27. <el-dropdown-item
  28. v-for="(com, index) in comTypes"
  29. :key="index"
  30. :command="com"
  31. >
  32. {{ com.compentName }}</el-dropdown-item
  33. >
  34. </el-dropdown-menu>
  35. </template>
  36. </el-dropdown>
  37. <VueDraggable
  38. v-model="selectProComs"
  39. :animation="150"
  40. ghostClass="ghost"
  41. @update="onUpdate"
  42. style="display: flex"
  43. >
  44. <div
  45. class="typeContainer"
  46. v-for="(item, index) in selectProComs"
  47. :key="index"
  48. @click="clickToolCom(item, index)"
  49. >
  50. <div class="typeBox others" :class="getNameClass(index)">
  51. <svg-icon :icon-class="item.compentType" size="30" />
  52. <div class="name">{{ item.compentName }}</div>
  53. </div>
  54. <Delete class="delete" @click.stop="clickDelete(index)" />
  55. </div>
  56. </VueDraggable>
  57. </div>
  58. <div class="binContainer">
  59. <div v-if="showCSJL"><TestCom /></div>
  60. <div v-else-if="showBraze">
  61. <BrazeTable />
  62. </div>
  63. <div v-else>
  64. <div v-if="isChanged || selectIndex === -1 || isNoneedEdit">
  65. <el-empty :image-size="200" :description="getTipContent()" />
  66. </div>
  67. <div v-else-if="tipTitle !== '编辑工序表单'">
  68. <div class="tipTitle">{{ tipTitle }}</div>
  69. <el-button
  70. type="primary"
  71. @click="creatNewData"
  72. style="margin-bottom: 15px"
  73. >新增</el-button
  74. >
  75. <el-button
  76. type="primary"
  77. @click="saveSortData"
  78. style="margin-bottom: 15px"
  79. >保存顺序</el-button
  80. >
  81. <BottomTable ref="bottomTableRef" :tableType="tableType" />
  82. </div>
  83. <div v-else>
  84. <div class="tipTitle">{{ tipTitle }}</div>
  85. <SetExcel />
  86. </div>
  87. </div>
  88. </div>
  89. </div>
  90. </template>
  91. <script setup>
  92. import { Back, Document, CirclePlus, Delete } from "@element-plus/icons-vue";
  93. import { VueDraggable } from "vue-draggable-plus";
  94. import BottomTable from "@/views/base/craftManagement/route/components/bottomTable.vue";
  95. import { comTypes } from "@/views/base/craftManagement/route/components/configs";
  96. import { saveCompoents, getCompoentsList } from "@/api/craft/process/index";
  97. import TestCom from "./testCom.vue";
  98. import BrazeTable from './brazeTable.vue';
  99. import SetExcel from "./setExcel/index.vue";
  100. import { useCommonStoreHook, useDictionaryStoreHook } from "@/store";
  101. import {
  102. processesByRouteId,
  103. saveProcessInRoute,
  104. } from "@/api/craft/route/index";
  105. const router = useRouter();
  106. const route = useRoute();
  107. //组件是否已经改变,如果改变了需要点击保存,才能展示下面的table
  108. const isChanged = ref(true);
  109. const isNoneedEdit = ref(false); //有些组件是不需要编辑的,所以下面也不展示table
  110. const loadTopList = () => {
  111. getCompoentsList(route.params.id).then((res) => {
  112. selectProComs.value = res.data || [];
  113. selectIndex.value = -1;
  114. isChanged.value = false;
  115. });
  116. };
  117. onMounted(async () => {
  118. operationId.value = route.params.id;
  119. await loadTopList();
  120. });
  121. // 顶部====================
  122. const back = () => {
  123. router.back();
  124. };
  125. const operationId = ref("");
  126. provide("operationId", operationId);
  127. const save = async () => {
  128. for (let i = 0; i < selectProComs.value.length; i++) {
  129. selectProComs.value[i].operationId = route.params.id;
  130. selectProComs.value[i].sortNum = i;
  131. }
  132. let p = {
  133. operationId: route.params.id,
  134. dtos: selectProComs.value,
  135. };
  136. let res = await saveCompoents(p);
  137. ElMessage.success("保存成功");
  138. loadTopList();
  139. };
  140. // Tools顶部组件 ==================
  141. // 已经存在的工序组件
  142. const selectProComs = ref([]);
  143. const selectIndex = ref(-1);
  144. const currentCom = ref({});
  145. const handleCommand = (item) => {
  146. let status = true;
  147. for (let i = 0; i < selectProComs.value.length; i++) {
  148. if (selectProComs.value[i].compentName == item.compentName) {
  149. status = false;
  150. }
  151. }
  152. if (status == true) {
  153. selectProComs.value.push(item);
  154. isChanged.value = true;
  155. selectIndex.value = -1;
  156. } else {
  157. ElMessage.error("请勿重复添加");
  158. }
  159. };
  160. // 点击某一个改变下面的table
  161. const showCSJL = ref(false);
  162. const showBraze = ref(false);
  163. const clickToolCom = (com, index) => {
  164. showCSJL.value = false;
  165. showBraze.value = false;
  166. // 如果上方组件更改了,提示先保存组件再操作
  167. if (isChanged.value) {
  168. ElMessage.warning("请先保存组件!!!");
  169. return;
  170. }
  171. tipTitle.value = "编辑" + com.compentName;
  172. selectIndex.value = index;
  173. currentCom.value = com;
  174. if (
  175. com.compentType === "jiluxiang" ||
  176. com.compentType === "mingpai" ||
  177. com.compentType === "duomeiticaiji" ||
  178. com.compentType === "tiaoshipipei" ||
  179. com.compentType === "jingu" ||
  180. com.compentType === "screwdriver"
  181. ) {
  182. isNoneedEdit.value = true;
  183. } else if (com.compentType === "ceshijilu") {
  184. showCSJL.value = true;
  185. } else if (com.compentType === "braze") {
  186. showBraze.value = true;
  187. } else {
  188. tableType.value = com.compentType;
  189. isNoneedEdit.value = false;
  190. }
  191. };
  192. const onUpdate = () => {
  193. console.log("update");
  194. isChanged.value = true;
  195. selectIndex.value = -1;
  196. };
  197. const clickDelete = (index) => {
  198. selectProComs.value.splice(index, 1);
  199. selectIndex.value = -1;
  200. isChanged.value = true;
  201. };
  202. const getNameClass = (index) => {
  203. return index === selectIndex.value ? "selected" : "normal";
  204. };
  205. // 底部table ===============
  206. let tipTitle = ref({});
  207. const bottomTableRef = ref({});
  208. const tableType = ref("MARTERIAL_BOM");
  209. const creatNewData = () => {
  210. bottomTableRef.value && bottomTableRef.value.startCreat();
  211. };
  212. const saveSortData = () => {
  213. bottomTableRef.value && bottomTableRef.value.saveSortData();
  214. };
  215. const getTipContent = (itemValue) => {
  216. if (isNoneedEdit.value) {
  217. return "标准组件无需编辑";
  218. }
  219. if (selectIndex.value === -1 && isChanged.value) {
  220. return "请先保存组件,然后再进行操作";
  221. }
  222. return "请先选择组件";
  223. };
  224. </script>
  225. <style lang="scss" scoped>
  226. .header {
  227. height: 50px;
  228. display: flex;
  229. background-color: #f5f7f9;
  230. justify-content: space-between;
  231. align-items: center;
  232. border-bottom: 1px solid rgba(0, 0, 0, 0.1);
  233. }
  234. .types {
  235. width: 100%;
  236. height: 116px;
  237. border-bottom: 1px solid rgba(0, 0, 0, 0.1);
  238. padding: 12px 20px;
  239. display: flex;
  240. .typeContainer {
  241. }
  242. .typeBox {
  243. height: 80px;
  244. width: 80px;
  245. border-radius: 4px 4px 4px 4px;
  246. display: flex;
  247. flex-direction: column;
  248. justify-content: center;
  249. align-items: center;
  250. .icon {
  251. height: 32px;
  252. width: 32px;
  253. }
  254. .name {
  255. width: 56px;
  256. height: 16px;
  257. font-weight: 500;
  258. font-size: 14px;
  259. line-height: 16px;
  260. text-align: center;
  261. font-style: normal;
  262. text-transform: none;
  263. }
  264. }
  265. .addBtn {
  266. border: 1px solid #0a59f7;
  267. color: #0a59f7;
  268. }
  269. .others {
  270. color: rgba(0, 0, 0, 0.9);
  271. border: 1px solid rgba(0, 0, 0, 0.9);
  272. margin-left: 20px;
  273. position: relative;
  274. }
  275. .delete {
  276. //position: absolute;
  277. //bottom: -20px;
  278. //left: 0;
  279. margin-left: 50px;
  280. width: 1em;
  281. height: 1em;
  282. color: red;
  283. visibility: hidden;
  284. }
  285. .typeContainer:hover {
  286. .delete {
  287. visibility: visible;
  288. }
  289. }
  290. .normal {
  291. background: #ffffff;
  292. border: 1px solid rgba(35, 32, 50, 0.1);
  293. }
  294. .selected {
  295. background: rgba(10, 89, 247, 0.2);
  296. border: 1px solid #0a59f7;
  297. }
  298. }
  299. .title {
  300. line-height: 44px;
  301. color: #6f7991;
  302. font-size: 14px;
  303. font-weight: bold;
  304. text-align: left;
  305. margin-left: 20px;
  306. }
  307. .binContainer {
  308. height: calc(100vh - 280px);
  309. width: 100%;
  310. background-color: #f5f7f9;
  311. overflow-y: auto;
  312. background-color: white;
  313. //margin-top: 16px;
  314. //margin-left: 20px;
  315. padding: 16px 20px;
  316. }
  317. .tipTitle {
  318. width: 84px;
  319. height: 16px;
  320. font-weight: 500;
  321. font-size: 14px;
  322. color: rgba(0, 0, 0, 0.9);
  323. line-height: 16px;
  324. text-align: left;
  325. font-style: normal;
  326. text-transform: none;
  327. margin-bottom: 16px;
  328. }
  329. </style>