index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. <template>
  2. <div class="app-container">
  3. <el-form
  4. :model="queryParams"
  5. ref="queryForm"
  6. size="small"
  7. :inline="true"
  8. v-show="showSearch"
  9. label-width="100px"
  10. >
  11. <el-form-item label="物资柜编码" prop="cabinetCode">
  12. <el-input
  13. v-model="queryParams.cabinetCode"
  14. placeholder="请输入物资柜编码"
  15. clearable
  16. @keyup.enter.native="handleQuery"
  17. />
  18. </el-form-item>
  19. <el-form-item label="物资柜名称" prop="cabinetName">
  20. <el-input
  21. v-model="queryParams.cabinetName"
  22. placeholder="请输入物资柜名称"
  23. clearable
  24. @keyup.enter.native="handleQuery"
  25. />
  26. </el-form-item>
  27. <!-- <el-form-item label="物资状态" prop="loanState">
  28. <el-select v-model="queryParams.loanState" placeholder="状态">
  29. <el-option
  30. v-for="dict in dict.type.material_status"
  31. :key="dict.value"
  32. :label="dict.label"
  33. :value="dict.value"
  34. />
  35. </el-select>
  36. </el-form-item>
  37. <el-form-item label="物资类型" prop="materialsTypeId">
  38. <treeselect
  39. style="width: 318px"
  40. v-model="queryParams.materialsTypeId"
  41. :options="machinerytypeOptions"
  42. :normalizer="normalizer"
  43. placeholder="请选择物资类型"
  44. />
  45. </el-form-item>
  46. <el-form-item label="启用时间" prop="createTime">
  47. <el-date-picker
  48. v-model="createTime"
  49. type="datetimerange"
  50. :picker-options="pickerOptions"
  51. range-separator="-"
  52. start-placeholder="开始日期"
  53. end-placeholder="结束日期"
  54. align="right"
  55. >
  56. </el-date-picker>
  57. </el-form-item>
  58. <el-form-item label="所属柜" prop="materialsCabinetId">
  59. <el-select
  60. style="width: 348px"
  61. v-model="queryParams.materialsCabinetId"
  62. placeholder="请选择所属柜"
  63. >
  64. <el-option
  65. v-for="dict in cabinets"
  66. :key="dict.value"
  67. :label="dict.label"
  68. :value="dict.value"
  69. />
  70. </el-select>
  71. </el-form-item> -->
  72. <el-form-item>
  73. <el-button
  74. v-no-more-click
  75. type="primary"
  76. icon="el-icon-search"
  77. size="mini"
  78. @click="handleQuery"
  79. >搜索</el-button
  80. >
  81. <el-button
  82. v-no-more-click
  83. icon="el-icon-refresh"
  84. size="mini"
  85. @click="resetQuery"
  86. >重置</el-button
  87. >
  88. </el-form-item>
  89. </el-form>
  90. <el-row :gutter="10" class="mb8">
  91. <el-col :span="1.5">
  92. <el-button
  93. v-no-more-click
  94. type="primary"
  95. plain
  96. icon="el-icon-plus"
  97. size="mini"
  98. @click="handleAdd"
  99. v-hasPermi="['iscs:cabinet:add']"
  100. >新增
  101. </el-button>
  102. </el-col>
  103. <el-col :span="1.5">
  104. <el-button
  105. v-no-more-click
  106. type="danger"
  107. plain
  108. icon="el-icon-delete"
  109. size="mini"
  110. :disabled="multiple"
  111. @click="handleDelete"
  112. v-hasPermi="['mes:mat:info:batchremove']"
  113. >批量删除
  114. </el-button>
  115. </el-col>
  116. <right-toolbar
  117. :showSearch.sync="showSearch"
  118. @queryTable="getList"
  119. ></right-toolbar>
  120. </el-row>
  121. <el-table
  122. v-loading="loading"
  123. :data="materialsList"
  124. @selection-change="handleSelectionChange"
  125. >
  126. <el-table-column type="selection" width="55" align="center" />
  127. <el-table-column label="物资柜编码" align="center" prop="cabinetCode">
  128. </el-table-column>
  129. <el-table-column label="物资柜名称" align="center" prop="cabinetName" />
  130. <!-- <el-table-column
  131. label="物资类型"
  132. align="center"
  133. prop="materialsTypeName"
  134. /> -->
  135. <!-- <el-table-column label="所属柜" align="center" prop="cabinetName" /> -->
  136. <!-- <el-table-column label="物资状态" align="center" prop="loanState">
  137. <template slot-scope="scope">
  138. <span>{{ scope.row.loanState == 0 ? "借出" : "柜中" }}</span>
  139. </template>
  140. </el-table-column> -->
  141. <el-table-column label="创建时间" align="center" prop="createTime" />
  142. <el-table-column label="更新时间" align="center" prop="updateTime" />
  143. <el-table-column
  144. label="操作"
  145. align="center"
  146. class-name="small-padding fixed-width"
  147. >
  148. <template slot-scope="scope">
  149. <el-button
  150. v-no-more-click
  151. size="mini"
  152. type="text"
  153. icon="el-icon-edit"
  154. @click="handleUpdate(scope.row)"
  155. v-hasPermi="['iscs:cabinet:edit']"
  156. >编辑
  157. </el-button>
  158. <el-button
  159. v-no-more-click
  160. size="mini"
  161. type="text"
  162. icon="el-icon-delete"
  163. @click="handleDelete(scope.row)"
  164. v-hasPermi="['iscs:cabinet:remove']"
  165. >删除
  166. </el-button>
  167. </template>
  168. </el-table-column>
  169. </el-table>
  170. <pagination
  171. v-show="total > 0"
  172. :total="total"
  173. :page.sync="queryParams.pages"
  174. :limit.sync="queryParams.size"
  175. @pagination="getList"
  176. />
  177. <!-- 添加或修改班组对话框 -->
  178. <el-dialog :visible.sync="open" width="960px" append-to-body>
  179. <div slot="title" class="dialog-title">
  180. <i></i>
  181. <span class="title">{{ title }}</span>
  182. </div>
  183. <el-form ref="form" :model="form" :rules="rules" label-width="110px">
  184. <el-row>
  185. <el-col :span="12">
  186. <el-form-item label="物资柜编码" prop="cabinetCode">
  187. <el-input
  188. v-model="form.cabinetCode"
  189. placeholder="请输入物资柜编码"
  190. style="width: 200px; margin-right: 10px"
  191. />
  192. <el-switch
  193. v-model="autoGenFlag"
  194. active-color="#13ce66"
  195. active-text="自动生成"
  196. @change="handleAutoGenChange(autoGenFlag)"
  197. >
  198. </el-switch>
  199. </el-form-item>
  200. </el-col>
  201. <el-col :span="12">
  202. <el-form-item label="硬件名称" prop="hardwareId">
  203. <el-select
  204. style="width: 348px"
  205. v-model="form.workareaId"
  206. placeholder="请选择硬件名称"
  207. clearable
  208. >
  209. <el-option
  210. v-for="dict in this.hardWareList"
  211. :key="dict.value"
  212. :label="dict.label"
  213. :value="dict.value"
  214. />
  215. </el-select>
  216. </el-form-item>
  217. </el-col>
  218. </el-row>
  219. <el-row>
  220. <el-col :span="12">
  221. <el-form-item label="物资柜名称" prop="cabinetName">
  222. <el-input
  223. v-model="form.cabinetName"
  224. placeholder="请输入物资柜名称"
  225. />
  226. </el-form-item>
  227. </el-col>
  228. <el-col :span="12">
  229. <el-form-item label="区域名称" prop="workareaId">
  230. <treeselect
  231. style="width: 350px"
  232. v-model="form.workareaId"
  233. :options="workareaOptions"
  234. :normalizer="normalizer"
  235. placeholder="选择区域名称"
  236. />
  237. </el-form-item>
  238. </el-col>
  239. </el-row>
  240. <el-form-item label="备注" prop="remark">
  241. <el-input
  242. v-model="form.remark"
  243. type="textarea"
  244. placeholder="请输入内容"
  245. style="width: 420px"
  246. />
  247. </el-form-item>
  248. </el-form>
  249. <div slot="footer" class="dialog-footer">
  250. <el-button
  251. v-no-more-click
  252. type="primary"
  253. @click="cancel"
  254. v-if="optType == 'view'"
  255. >返回</el-button
  256. >
  257. <el-button v-no-more-click type="primary" @click="submitForm" v-else
  258. >确 定</el-button
  259. >
  260. <el-button v-no-more-click @click="cancel">取 消</el-button>
  261. </div>
  262. </el-dialog>
  263. </div>
  264. </template>
  265. <script>
  266. import {
  267. getMaterialsCabinet,
  268. addMaterialsCabinet,
  269. updateMaterialsCabinet,
  270. deleteMaterialsCabinet,
  271. selectMaterialsCabinetById,
  272. } from "@/api/mes/material/lockers.js";
  273. import {
  274. listWorkarea
  275. } from "@/api/mes/wa/workarea";
  276. import { listType } from "@/api/mes/material/typeindex";
  277. import { listHardware } from "@/api/mes/hw/hardwareinfo";
  278. import Treeselect from "@riophae/vue-treeselect";
  279. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  280. import { genCode } from "@/api/system/autocode/rule";
  281. export default {
  282. name: "Team",
  283. components: {
  284. Treeselect,
  285. },
  286. dicts: ["material_status"],
  287. data() {
  288. return {
  289. //自动生成编码
  290. autoGenFlag: false,
  291. optType: undefined,
  292. // 遮罩层
  293. loading: true,
  294. // 选中数组
  295. ids: [],
  296. codes: [],
  297. // 非单个禁用
  298. single: true,
  299. // 非多个禁用
  300. multiple: true,
  301. // 显示搜索条件
  302. showSearch: true,
  303. // 总条数
  304. total: 0,
  305. // 班组表格数据
  306. materialsList: [],
  307. // 弹出层标题
  308. title: "",
  309. // 是否显示弹出层
  310. open: false,
  311. // 查询参数
  312. createTime: "",
  313. queryParams: {
  314. pages: 1,
  315. size: 10,
  316. cabinetCode: null,
  317. cabinetName: null,
  318. },
  319. hardWareList: [],
  320. queryhwParams: {
  321. current: 1,
  322. size: -1,
  323. },
  324. // 查询参数
  325. queryParamsCabinets: {
  326. current: 1,
  327. size: -1,
  328. },
  329. pickerOptions: {
  330. shortcuts: [
  331. {
  332. text: "最近一周",
  333. onClick(picker) {
  334. const end = new Date();
  335. const start = new Date();
  336. start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
  337. picker.$emit("pick", [start, end]);
  338. },
  339. },
  340. {
  341. text: "最近一个月",
  342. onClick(picker) {
  343. const end = new Date();
  344. const start = new Date();
  345. start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
  346. picker.$emit("pick", [start, end]);
  347. },
  348. },
  349. {
  350. text: "最近三个月",
  351. onClick(picker) {
  352. const end = new Date();
  353. const start = new Date();
  354. start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
  355. picker.$emit("pick", [start, end]);
  356. },
  357. },
  358. ],
  359. },
  360. // 表单参数
  361. form: {},
  362. cabinets: [], //物资所属柜
  363. // 表单校验
  364. rules: {
  365. cabinetCode: [
  366. { required: true, message: "物资柜编码不能为空", trigger: "blur" },
  367. ],
  368. cabinetName: [
  369. { required: true, message: "物资柜名称不能为空", trigger: "blur" },
  370. ],
  371. },
  372. workareaOptions: [],
  373. };
  374. },
  375. created() {
  376. this.getList();
  377. this.getHardWare();
  378. this.getTreeselect();
  379. },
  380. mounted() {
  381. this.materialsCabinets();
  382. },
  383. methods: {
  384. getHardWare() {
  385. listHardware(this.queryhwParams).then((response) => {
  386. this.hardWareList = response.data.records.map((item) => {
  387. return {
  388. value: item.id,
  389. label: item.hardwareName,
  390. };
  391. });
  392. console.log(response, this.hardWareList, "获取硬件信息");
  393. });
  394. },
  395. /** 转换数据结构 */
  396. normalizer(node) {
  397. if (node.children && !node.children.length) {
  398. delete node.children;
  399. }
  400. return {
  401. id: node.materialsTypeId,
  402. label: node.materialsTypeName,
  403. children: node.children,
  404. };
  405. },
  406. /** 查询物资类型下拉树结构 */
  407. getTreeselect() {
  408. const data = {
  409. current: 1,
  410. size: 99999,
  411. };
  412. listType(data).then((response) => {
  413. this.machinerytypeOptions = this.handleTree(
  414. response.data.records,
  415. "materialsTypeId",
  416. "parentId",
  417. "children"
  418. );
  419. });
  420. },
  421. // 格式化日期查询数据
  422. formatDate(date) {
  423. if (date && date instanceof Date && !isNaN(date)) {
  424. // 使用本地时间
  425. return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(
  426. 2,
  427. "0"
  428. )}-${String(date.getDate()).padStart(2, "0")}`;
  429. }
  430. return null;
  431. },
  432. /** 查询物资信息列表 */
  433. getList() {
  434. this.loading = true;
  435. // 格式化日期并更新 queryParams
  436. if (Array.isArray(this.createTime) && this.createTime.length === 2) {
  437. this.queryParams.startTime = this.formatDate(this.createTime[0]);
  438. this.queryParams.endTime = this.formatDate(this.createTime[1]);
  439. }
  440. getMaterialsCabinet(this.queryParams).then((response) => {
  441. // console.log(response, "获取物资信息allList ");
  442. this.materialsList = response.data.records;
  443. this.total = response.data.total;
  444. this.machinerytypeList = this.handleTree(
  445. response.data.records,
  446. "materialsTypeId",
  447. "parentId",
  448. "children"
  449. );
  450. this.loading = false;
  451. });
  452. },
  453. //图片上传成功
  454. handleImgUplaoded(imgUrl) {
  455. this.form.sipUrl = imgUrl;
  456. },
  457. //图片移除
  458. handleImgRemoved(imgUrl) {
  459. this.form.sipUrl = null;
  460. },
  461. // 取消按钮
  462. cancel() {
  463. this.open = false;
  464. this.reset();
  465. },
  466. // 表单重置
  467. reset() {
  468. this.form = {
  469. cabinetCode: "",
  470. cabinetName: "",
  471. };
  472. this.resetForm("form");
  473. this.autoGenFlag = false;
  474. },
  475. /** 搜索按钮操作 */
  476. handleQuery() {
  477. this.queryParams.pageNum = 1;
  478. this.getList();
  479. },
  480. /** 重置按钮操作 */
  481. resetQuery() {
  482. this.createTime = "";
  483. this.queryParams.cabinetCode = null;
  484. this.queryParams.cabinetName = null;
  485. this.resetForm("queryForm");
  486. this.handleQuery();
  487. },
  488. // 多选框选中数据
  489. handleSelectionChange(selection) {
  490. this.ids = selection.map((item) => item.materialsId);
  491. this.codes = selection.map((item) => item.cabinetCode);
  492. this.single = selection.length !== 1;
  493. this.multiple = !selection.length;
  494. },
  495. // 物资所属柜
  496. materialsCabinets() {
  497. getIsMaterialsCabinets(this.queryParamsCabinets).then((response) => {
  498. if (response?.data?.records) {
  499. // 提取 cabinetId 和 cabinetName
  500. this.cabinets = response.data.records.map((item) => ({
  501. value: item.cabinetId,
  502. label: item.cabinetName,
  503. }));
  504. }
  505. });
  506. },
  507. /** 新增按钮操作 */
  508. handleAdd() {
  509. this.reset();
  510. this.open = true;
  511. this.title = "新增物资信息";
  512. this.optType = "add";
  513. this.form.materialsTypeId = undefined;
  514. },
  515. /** 修改按钮操作 */
  516. handleUpdate(row) {
  517. this.reset();
  518. selectMaterialsCabinetById(row.cabinetId).then((response) => {
  519. this.form = response.data;
  520. this.open = true;
  521. this.title = "编辑物资信息";
  522. this.optType = "edit";
  523. });
  524. },
  525. /** 提交按钮 */
  526. submitForm() {
  527. this.$refs["form"].validate((valid) => {
  528. if (valid) {
  529. if (this.form.materialsId != null) {
  530. updateMaterialsCabinet(this.form).then((response) => {
  531. console.log(response, "修改返回");
  532. this.$modal.msgSuccess("修改成功");
  533. this.open = false;
  534. this.getList();
  535. });
  536. } else {
  537. addMaterialsCabinet(this.form).then((response) => {
  538. console.log(response, "新增返回");
  539. this.$modal.msgSuccess("新增成功");
  540. this.open = false;
  541. this.getList();
  542. });
  543. }
  544. }
  545. });
  546. },
  547. /** 删除按钮操作 */
  548. handleDelete(row) {
  549. const materialsIds = row.cabinetIds || this.ids;
  550. const materialsCodes = row.cabinetCode || this.codes;
  551. this.$modal
  552. .confirm('是否确认删除编号为"' + materialsCodes + '"的数据项?')
  553. .then(function () {
  554. return deleteMaterialsCabinet(materialsIds);
  555. })
  556. .then(() => {
  557. this.getList();
  558. this.$modal.msgSuccess("删除成功");
  559. })
  560. .catch(() => {});
  561. },
  562. /** 导出按钮操作 */
  563. handleExport() {
  564. this.download(
  565. "cal/team/export",
  566. {
  567. ...this.queryParams,
  568. },
  569. `team_${new Date().getTime()}.xlsx`
  570. );
  571. },
  572. //自动生成编码
  573. handleAutoGenChange(autoGenFlag) {
  574. if (autoGenFlag) {
  575. genCode("MATERIALS_CABINET").then((response) => {
  576. this.form.cabinetCode = response;
  577. });
  578. } else {
  579. this.form.cabinetCode = null;
  580. }
  581. },
  582. },
  583. };
  584. </script>
  585. <style lang="scss" src="@/assets/styles/dialog-title.scss" scoped>
  586. .el-input-width {
  587. width: 380px !important;
  588. }
  589. </style>