index.vue 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. <template>
  2. <div class="tenant">
  3. <!-- <Banner /> -->
  4. <div class="content">
  5. <byTable
  6. :source="sourceList.data"
  7. :pagination="sourceList.pagination"
  8. :config="config"
  9. :loading="loading"
  10. highlight-current-row
  11. :selectConfig="selectConfig"
  12. :table-events="{
  13. //element talbe事件都能传
  14. select: select,
  15. }"
  16. :action-list="[
  17. {
  18. text: '添加工艺',
  19. action: () => openModal('add'),
  20. },
  21. ]"
  22. @get-list="getList"
  23. >
  24. <template #slotName="{ item }">
  25. {{ item.createTime }}
  26. </template>
  27. </byTable>
  28. </div>
  29. <el-dialog
  30. :title="modalType == 'add' ? '添加工艺' : '编辑工艺'"
  31. v-model="dialogVisible"
  32. width="800"
  33. v-loading="loading"
  34. >
  35. <byForm
  36. :formConfig="formConfig"
  37. :formOption="formOption"
  38. v-model="formData.data"
  39. :rules="rules"
  40. ref="byform"
  41. >
  42. <template #lineSlot>
  43. <el-transfer
  44. v-model="selectLine"
  45. filterable
  46. filter-placeholder="搜索"
  47. :data="lineData"
  48. :titles="['可选', '已选']"
  49. >
  50. <template #default="{ option }">
  51. <div
  52. draggable="true"
  53. @dragstart="dragStar($event, option)"
  54. @dragover="dragOver($event, option)"
  55. style="cursor: default"
  56. >
  57. {{ option.label }}
  58. </div>
  59. </template>
  60. </el-transfer>
  61. </template>
  62. <template #productSlot>
  63. <div>
  64. <el-button type="primary" @click="openProduct = true">
  65. 添加产品
  66. </el-button>
  67. <div style="margin-top: 15px">
  68. <el-tag
  69. class="ml-2"
  70. type="info"
  71. closable
  72. v-for="(product, index) in productList"
  73. :key="product.id"
  74. @close="handleRemove(index)"
  75. >{{ product.name }}</el-tag
  76. >
  77. </div>
  78. </div>
  79. </template>
  80. <!-- :filter-method="filterMethod" -->
  81. </byForm>
  82. <template #footer>
  83. <el-button @click="dialogVisible = false" size="large">取 消</el-button>
  84. <el-button
  85. type="primary"
  86. @click="submitForm('byform')"
  87. size="large"
  88. :loading="submitLoading"
  89. >
  90. 确 定
  91. </el-button>
  92. </template>
  93. </el-dialog>
  94. <el-dialog
  95. v-model="openProduct"
  96. title="选择产品"
  97. width="70%"
  98. :before-close="handleClose"
  99. >
  100. <SelectProduct @handleSelect="handleSelect"></SelectProduct>
  101. <template #footer>
  102. <span class="dialog-footer">
  103. <el-button @click="openProduct = false">取消</el-button>
  104. </span>
  105. </template>
  106. </el-dialog>
  107. </div>
  108. </template>
  109. <script setup>
  110. /* eslint-disable vue/no-unused-components */
  111. import { ElMessage, ElMessageBox } from "element-plus";
  112. import byTable from "@/components/byTable/index";
  113. import byForm from "@/components/byForm/index";
  114. import SelectProduct from "@/components/iot/SelectProduct";
  115. import { computed, defineComponent, ref, toRaw } from "vue";
  116. const loading = ref(false);
  117. const submitLoading = ref(false);
  118. const sourceList = ref({
  119. data: [],
  120. pagination: {
  121. total: 3,
  122. pageNum: 1,
  123. pageSize: 10,
  124. },
  125. });
  126. let lineData = reactive([
  127. {
  128. key: "1",
  129. label: "测试1",
  130. disabled: false,
  131. },
  132. {
  133. key: "2",
  134. label: "测试2",
  135. disabled: false,
  136. },
  137. {
  138. key: "3",
  139. label: "测试3",
  140. disabled: false,
  141. },
  142. {
  143. key: "4",
  144. label: "测试4",
  145. disabled: false,
  146. },
  147. ]);
  148. let selectLine = ref([]);
  149. let dialogVisible = ref(false);
  150. let openProduct = ref(false);
  151. let modalType = ref("add");
  152. let rules = ref({
  153. type: [{ required: true, message: "请选择车间类型", trigger: "change" }],
  154. name: [{ required: true, message: "请输入车间名称", trigger: "blur" }],
  155. personLiableId: [
  156. { required: true, message: "请选择负责人", trigger: "change" },
  157. ],
  158. });
  159. const { proxy } = getCurrentInstance();
  160. const selectConfig = reactive([
  161. // {
  162. // label: "车间类型",
  163. // prop: "type",
  164. // data: [
  165. // {
  166. // label: "普通车间",
  167. // value: "1",
  168. // },
  169. // {
  170. // label: "半自动化车间",
  171. // value: "2",
  172. // },
  173. // {
  174. // label: "自动化车间",
  175. // value: "3",
  176. // },
  177. // ],
  178. // },
  179. ]);
  180. const config = computed(() => {
  181. return [
  182. {
  183. attrs: {
  184. label: "工艺名称",
  185. prop: "name",
  186. width: 150,
  187. },
  188. },
  189. {
  190. attrs: {
  191. label: "工艺路线",
  192. prop: "remarks",
  193. },
  194. },
  195. {
  196. attrs: {
  197. label: "适用产品",
  198. prop: "type",
  199. width: 120,
  200. },
  201. render(type) {
  202. return type == 1
  203. ? "普通车间"
  204. : type == 2
  205. ? "半自动化车间"
  206. : type == "3"
  207. ? "自动化车间"
  208. : "";
  209. },
  210. },
  211. {
  212. attrs: {
  213. label: "工艺说明",
  214. prop: "remarks",
  215. },
  216. },
  217. {
  218. attrs: {
  219. label: "操作",
  220. width: "200",
  221. align: "right",
  222. },
  223. // 渲染 el-button,一般用在最后一列。
  224. renderHTML(row) {
  225. return [
  226. {
  227. attrs: {
  228. label: "修改",
  229. type: "primary",
  230. text: true,
  231. },
  232. el: "button",
  233. click() {
  234. getDtl(row);
  235. },
  236. },
  237. {
  238. attrs: {
  239. label: "删除",
  240. type: "danger",
  241. text: true,
  242. },
  243. el: "button",
  244. click() {
  245. // 弹窗提示是否删除
  246. ElMessageBox.confirm(
  247. "此操作将永久删除该数据, 是否继续?",
  248. "提示",
  249. {
  250. confirmButtonText: "确定",
  251. cancelButtonText: "取消",
  252. type: "warning",
  253. }
  254. ).then(() => {
  255. // 删除
  256. proxy
  257. .post("/workshop/delete", {
  258. id: row.id,
  259. })
  260. .then((res) => {
  261. ElMessage({
  262. message: "删除成功",
  263. type: "success",
  264. });
  265. getList();
  266. });
  267. });
  268. },
  269. },
  270. ];
  271. },
  272. },
  273. ];
  274. });
  275. let formData = reactive({
  276. data: {
  277. type: "1",
  278. },
  279. });
  280. const formOption = reactive({
  281. inline: true,
  282. labelWidth: 100,
  283. itemWidth: 100,
  284. rules: [],
  285. });
  286. const byform = ref(null);
  287. const formConfig = computed(() => {
  288. return [
  289. {
  290. type: "input",
  291. prop: "name",
  292. label: "工艺名称",
  293. required: true,
  294. },
  295. {
  296. type: "slot",
  297. slotName: "lineSlot",
  298. label: "工艺路线",
  299. },
  300. {
  301. type: "slot",
  302. slotName: "productSlot",
  303. label: "适用产品",
  304. },
  305. {
  306. type: "input",
  307. prop: "remarks",
  308. label: "车间说明",
  309. itemType: "textarea",
  310. },
  311. ];
  312. });
  313. const getList = async (req) => {
  314. sourceList.value.pagination = { ...sourceList.value.pagination, ...req };
  315. loading.value = true;
  316. proxy.post("/workshop/page", sourceList.value.pagination).then((message) => {
  317. console.log(message);
  318. sourceList.value.data = message.rows;
  319. sourceList.value.pagination.total = message.total;
  320. setTimeout(() => {
  321. loading.value = false;
  322. }, 200);
  323. });
  324. };
  325. const openModal = () => {
  326. dialogVisible.value = true;
  327. modalType.value = "add";
  328. formData.data = {};
  329. };
  330. const submitForm = () => {
  331. console.log(byform.value);
  332. byform.value.handleSubmit((valid) => {
  333. submitLoading.value = true;
  334. proxy.post("/workshop/" + modalType.value, formData.data).then(
  335. (res) => {
  336. ElMessage({
  337. message: modalType.value == "add" ? "添加成功" : "编辑成功",
  338. type: "success",
  339. });
  340. dialogVisible.value = false;
  341. submitLoading.value = false;
  342. getList();
  343. },
  344. (err) => {
  345. console.log(err, "aswwwww");
  346. submitLoading.value = false;
  347. }
  348. );
  349. });
  350. };
  351. const getDtl = (row) => {
  352. modalType.value = "edit";
  353. proxy.post("/workshop/detail", { id: row.id }).then((res) => {
  354. res.type = res.type + "";
  355. formData.data = res;
  356. console.log(formData);
  357. dialogVisible.value = true;
  358. });
  359. };
  360. const filterMethod = (query, item) => {
  361. return item.initial.toLowerCase().includes(query.toLowerCase());
  362. };
  363. const productList = ref([]);
  364. const handleSelect = (row) => {
  365. const flag = productList.value.some((x) => x.id === row.id);
  366. if (flag)
  367. return ElMessage({
  368. message: "该产品已选择",
  369. type: "info",
  370. });
  371. productList.value.push(row);
  372. return ElMessage({
  373. message: "选择成功",
  374. type: "success",
  375. });
  376. };
  377. const handleRemove = (index) => {
  378. productList.value.splice(index, 1);
  379. return ElMessage({
  380. message: "删除成功",
  381. type: "success",
  382. });
  383. };
  384. // const renderDom = (h, option) => {
  385. // console.log(option, "ass");
  386. // h(lineData.map(x=> {
  387. // return `<div>${x.x.label}}</div>`
  388. // })
  389. // };
  390. // getList();
  391. let dom = ref(null);
  392. let selectItem = ref({});
  393. const dragStar = (e, option) => {
  394. dom.value = e.target;
  395. const target = e.target;
  396. selectItem.value = option;
  397. e.dataTransfer.setData("text/plain", target.id);
  398. e.dataTransfer.effectAllowed = "move";
  399. };
  400. const dragOver = (e, option) => {
  401. e.preventDefault();
  402. const index = selectLine.value.findIndex(
  403. (x) => x.key === selectItem.value.key
  404. );
  405. const index1 = selectLine.value.findIndex((x) => x.key === toRaw(option).key);
  406. const item = selectLine.value[index];
  407. selectLine.value[index] = selectLine.value[index1];
  408. selectLine.value[index1] = item;
  409. console.log(selectLine.value);
  410. };
  411. </script>
  412. <style lang="scss" scoped>
  413. .tenant {
  414. padding: 20px;
  415. }
  416. </style>