index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  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="instructionsTitle">
  12. <el-input
  13. v-model="queryParams.instructionsTitle"
  14. placeholder="请输入标题"
  15. clearable
  16. @keyup.enter.native="handleQuery"
  17. />
  18. </el-form-item>
  19. <el-form-item label="物资类型" prop="materialsTypeId">
  20. <treeselect
  21. style="width: 200px"
  22. v-model="queryParams.materialsTypeId"
  23. :options="materialstypeOptions"
  24. :normalizer="materialnormalizer"
  25. placeholder="请选择物资类型"
  26. />
  27. </el-form-item>
  28. <el-form-item label="类型" prop="fileType">
  29. <el-select v-model="queryParams.fileType" placeholder="类型">
  30. <el-option
  31. v-for="dict in dict.type.file_type"
  32. :key="dict.value"
  33. :label="dict.label"
  34. :value="dict.value"
  35. />
  36. </el-select>
  37. </el-form-item>
  38. <el-form-item>
  39. <el-button
  40. v-no-more-click
  41. type="primary"
  42. icon="el-icon-search"
  43. size="mini"
  44. @click="handleQuery"
  45. >搜索
  46. </el-button>
  47. <el-button
  48. v-no-more-click
  49. icon="el-icon-refresh"
  50. size="mini"
  51. @click="resetQuery"
  52. >重置
  53. </el-button>
  54. </el-form-item>
  55. </el-form>
  56. <el-row :gutter="10" class="mb8">
  57. <el-col :span="1.5">
  58. <el-button
  59. v-no-more-click
  60. type="primary"
  61. plain
  62. icon="el-icon-plus"
  63. size="mini"
  64. @click="handleAdd"
  65. v-hasPermi="['iscs:instructions:add']"
  66. >新增
  67. </el-button>
  68. </el-col>
  69. <el-col :span="1.5">
  70. <el-button
  71. v-no-more-click
  72. type="danger"
  73. plain
  74. icon="el-icon-delete"
  75. size="mini"
  76. :disabled="multiple"
  77. @click="handleDelete"
  78. v-hasPermi="['iscs:instructions:remove']"
  79. >批量删除
  80. </el-button>
  81. </el-col>
  82. <right-toolbar
  83. :showSearch.sync="showSearch"
  84. @queryTable="getList"
  85. ></right-toolbar>
  86. </el-row>
  87. <el-table
  88. v-loading="loading"
  89. :data="materialsList"
  90. @selection-change="handleSelectionChange"
  91. >
  92. <el-table-column type="selection" width="55" align="center" />
  93. <el-table-column
  94. label="说明编号"
  95. align="center"
  96. prop="instructionsId"
  97. width="200"
  98. >
  99. </el-table-column>
  100. <el-table-column
  101. prop="orderNum"
  102. label="排序"
  103. width="100"
  104. ></el-table-column>
  105. <el-table-column
  106. label="标题"
  107. align="center"
  108. prop="instructionsTitle"
  109. />
  110. <el-table-column
  111. label="物资类型"
  112. align="center"
  113. prop="materialsTypeName"
  114. />
  115. <el-table-column label="类型" align="center" prop="fileType">
  116. <template slot-scope="scope">
  117. <dict-tag
  118. :options="dict.type.file_type"
  119. :value="scope.row.fileType"
  120. />
  121. </template>
  122. </el-table-column>
  123. <el-table-column label="文件" align="center" prop="fileUrl">
  124. <template slot-scope="scope">
  125. <a :href="scope.row.fileUrl" target="_blank" style="color: #1890ff"
  126. >查看</a
  127. >
  128. </template>
  129. </el-table-column>
  130. <el-table-column label="添加时间" prop="createTime" align="center">
  131. </el-table-column>
  132. <el-table-column
  133. label="操作"
  134. align="center"
  135. class-name="small-padding fixed-width"
  136. >
  137. <template slot-scope="scope">
  138. <el-button
  139. v-no-more-click
  140. size="mini"
  141. type="text"
  142. icon="el-icon-edit"
  143. @click="handleUpdate(scope.row)"
  144. v-hasPermi="['iscs:instructions:edit']"
  145. >编辑
  146. </el-button>
  147. <el-button
  148. v-no-more-click
  149. size="mini"
  150. type="text"
  151. icon="el-icon-delete"
  152. @click="handleDelete(scope.row)"
  153. v-hasPermi="['iscs:instructions:remove']"
  154. >删除
  155. </el-button>
  156. </template>
  157. </el-table-column>
  158. </el-table>
  159. <pagination
  160. v-show="total > 0"
  161. :total="total"
  162. :page.sync="queryParams.current"
  163. :limit.sync="queryParams.size"
  164. @pagination="getList"
  165. />
  166. <!-- 添加或修改物资对话框 -->
  167. <el-dialog :visible.sync="open" width="500px" append-to-body>
  168. <div slot="title" class="dialog-title">
  169. <i></i>
  170. <span class="title">{{ title }}</span>
  171. </div>
  172. <el-form ref="form" :model="form" :rules="rules" label-width="90px">
  173. <el-form-item label="标题" prop="instructionsTitle">
  174. <el-input
  175. style="width: 350px"
  176. v-model="form.instructionsTitle"
  177. placeholder="请输入标题"
  178. />
  179. </el-form-item>
  180. <el-form-item label="物资类型" prop="materialsTypeId">
  181. <treeselect
  182. style="width: 350px"
  183. v-model="form.materialsTypeId"
  184. :options="materialstypeOptions"
  185. :normalizer="materialnormalizer"
  186. placeholder="选择物资类型"
  187. />
  188. </el-form-item>
  189. <el-form-item label="类型" prop="fileType">
  190. <el-select
  191. v-model="form.fileType"
  192. placeholder="文件类型"
  193. style="width: 350px"
  194. >
  195. <el-option
  196. v-for="dict in dict.type.file_type"
  197. :key="dict.value"
  198. :label="dict.label"
  199. :value="dict.value"
  200. />
  201. </el-select>
  202. </el-form-item>
  203. <el-form-item label="显示排序" prop="orderNum">
  204. <el-input-number
  205. style="width: 350px"
  206. v-model="form.orderNum"
  207. controls-position="right"
  208. :min="0"
  209. />
  210. </el-form-item>
  211. <el-form-item label="文件" prop="fileUrl">
  212. <div v-if="form.fileUrl">
  213. <div v-if="isVideo(form.fileUrl)">
  214. <video
  215. :src="form.fileUrl"
  216. width="300"
  217. height="200"
  218. controls
  219. ></video>
  220. </div>
  221. <div v-if="isPdf(form.fileUrl)">
  222. <embed
  223. :src="form.fileUrl"
  224. width="300"
  225. height="200"
  226. type="application/pdf"
  227. />
  228. </div>
  229. <el-button
  230. v-no-more-click
  231. type="danger"
  232. size="mini"
  233. @click="deleteFile"
  234. >删除</el-button
  235. >
  236. </div>
  237. <div v-else>
  238. <el-button
  239. v-no-more-click
  240. type="info"
  241. plain
  242. icon="el-icon-upload2"
  243. size="mini"
  244. @click="handleFileUpload"
  245. v-hasPermi="['iscs:sop:import']"
  246. >导入</el-button
  247. >
  248. </div>
  249. </el-form-item>
  250. </el-form>
  251. <div slot="footer" class="dialog-footer">
  252. <el-button v-no-more-click type="primary" @click="submitForm"
  253. >确 定
  254. </el-button>
  255. <el-button v-no-more-click @click="cancel">取 消</el-button>
  256. </div>
  257. </el-dialog>
  258. <!-- 说明上传-->
  259. <el-dialog
  260. :title="upload.title"
  261. :visible.sync="upload.open"
  262. width="400px"
  263. append-to-body
  264. >
  265. <el-upload
  266. ref="upload"
  267. :limit="1"
  268. accept=".mp4, .pdf"
  269. :headers="upload.headers"
  270. :action="upload.url + '?updateSupport=' + upload.updateSupport"
  271. :disabled="upload.isUploading"
  272. :on-progress="handleFileUploadProgress"
  273. :on-success="handleFileSuccess"
  274. :auto-upload="false"
  275. drag
  276. >
  277. <i class="el-icon-upload"></i>
  278. <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
  279. <div class="el-upload__tip text-center" slot="tip">
  280. <span>mp4、pdf格式文件。</span>
  281. </div>
  282. </el-upload>
  283. <div slot="footer" class="dialog-footer">
  284. <el-button v-no-more-click type="primary" @click="submitFileForm"
  285. >确 定</el-button
  286. >
  287. <el-button v-no-more-click @click="upload.open = false"
  288. >取 消</el-button
  289. >
  290. </div>
  291. </el-dialog>
  292. </div>
  293. </template>
  294. <script>
  295. import {
  296. listInstructions,
  297. getInstructionsInfo,
  298. addInstructions,
  299. updateInstructions,
  300. delInstructions,
  301. } from "@/api/mes/instructions/index.js";
  302. import Treeselect from "@riophae/vue-treeselect";
  303. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  304. import Template from "@/views/print/printtemplate/list.vue";
  305. import { listType } from "@/api/mes/material/typeindex";
  306. import { getToken } from "@/utils/auth";
  307. export default {
  308. name: "Team",
  309. components: {
  310. Template,
  311. Treeselect,
  312. },
  313. dicts: ["material_status", "file_type"],
  314. data() {
  315. return {
  316. //自动生成编码
  317. autoGenFlag: false,
  318. optType: undefined,
  319. // 遮罩层
  320. loading: true,
  321. // 选中数组
  322. ids: [],
  323. codes: [],
  324. // 非单个禁用
  325. single: true,
  326. // 非多个禁用
  327. multiple: true,
  328. // 显示搜索条件
  329. showSearch: true,
  330. // 总条数
  331. total: 0,
  332. // 班组表格数据
  333. materialsList: [],
  334. // 弹出层标题
  335. title: "",
  336. // 是否显示弹出层
  337. open: false,
  338. // 查询参数
  339. createTime: "",
  340. queryParams: {
  341. current: 1,
  342. size: 10,
  343. instructionsTitle: "",
  344. },
  345. // 表单参数
  346. form: {
  347. fileUrl: "",
  348. },
  349. // 表单校验
  350. rules: {
  351. materialsName: [
  352. { required: true, message: "物资名称不能为空", trigger: "blur" },
  353. ],
  354. materialsTypeId: [
  355. { required: true, message: "物资类型不能为空", trigger: "blur" },
  356. ],
  357. },
  358. materialstypeOptions: [],
  359. // 用户导入参数
  360. upload: {
  361. // 是否显示弹出层(用户导入)
  362. open: false,
  363. // 弹出层标题(用户导入)
  364. title: "",
  365. // 是否禁用上传
  366. isUploading: false,
  367. // 是否更新已经存在的用户数据
  368. updateSupport: 0,
  369. // 设置上传的请求头部
  370. headers: { Authorization: "Bearer " + getToken() },
  371. // 上传的地址
  372. url: process.env.VUE_APP_BASE_API + "/common/upload",
  373. },
  374. };
  375. },
  376. created() {
  377. this.getList();
  378. this.getTreeselect();
  379. },
  380. methods: {
  381. isVideo(url) {
  382. return url && (url.endsWith(".mp4") || url.includes("mp4"));
  383. },
  384. isPdf(url) {
  385. return url && (url.endsWith(".pdf") || url.includes("pdf"));
  386. },
  387. handleFileUpload() {
  388. this.upload.title = "导入";
  389. this.upload.open = true;
  390. },
  391. deleteFile() {
  392. this.form.fileUrl = ""; // 删除文件
  393. },
  394. // 提交上传文件
  395. submitFileForm() {
  396. this.$refs.upload.submit();
  397. },
  398. /** 查询物资信息列表 */
  399. getList() {
  400. this.loading = true;
  401. listInstructions(this.queryParams).then((response) => {
  402. console.log(response, "获取物资说明 ");
  403. this.materialsList = response.data.records;
  404. this.total = response.data.total;
  405. this.machinerytypeList = this.handleTree(
  406. response.data.records,
  407. "materialsTypeId",
  408. "parentId",
  409. "children"
  410. );
  411. this.loading = false;
  412. });
  413. },
  414. /** 查询物资类型下拉树结构 */
  415. getTreeselect() {
  416. const data = {
  417. current: 1,
  418. size: -1,
  419. };
  420. listType(data).then((response) => {
  421. console.log(response, "物资类型树形结构");
  422. this.materialstypeOptions = this.handleTree(
  423. response.data.records,
  424. "materialsTypeId",
  425. "parentId",
  426. "children"
  427. );
  428. });
  429. },
  430. /** 查询物资类型下拉树结构 */
  431. materialnormalizer(node) {
  432. if (node.children && !node.children.length) {
  433. delete node.children;
  434. }
  435. return {
  436. id: node.materialsTypeId,
  437. label: node.materialsTypeName,
  438. children: node.children,
  439. };
  440. },
  441. // 文件上传中处理
  442. handleFileUploadProgress(event, file, fileList) {
  443. this.upload.isUploading = true;
  444. },
  445. // 文件上传成功处理
  446. handleFileSuccess(response, file, fileList) {
  447. // console.log(response,file, fileList,'文件上传成功回返')
  448. this.form.fileUrl = response.url;
  449. this.upload.open = false;
  450. this.upload.isUploading = false;
  451. this.$refs.upload.clearFiles();
  452. this.$alert(
  453. "<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" +
  454. response.msg +
  455. "</div>",
  456. "导入结果",
  457. { dangerouslyUseHTMLString: true }
  458. );
  459. this.getList();
  460. },
  461. // 取消按钮
  462. cancel() {
  463. this.open = false;
  464. this.reset();
  465. },
  466. // 表单重置
  467. reset() {
  468. this.form = {
  469. instructionsTitle: "",
  470. fileType: "",
  471. fileUrl: "",
  472. orderNum: 0,
  473. };
  474. this.resetForm("form");
  475. this.autoGenFlag = false;
  476. },
  477. /** 搜索按钮操作 */
  478. handleQuery() {
  479. this.getList();
  480. },
  481. /** 重置按钮操作 */
  482. resetQuery() {
  483. this.resetForm("queryForm");
  484. this.handleQuery();
  485. },
  486. // 多选框选中数据
  487. handleSelectionChange(selection) {
  488. this.ids = selection.map((item) => item.instructionsId);
  489. this.multiple = !selection.length;
  490. },
  491. /** 新增按钮操作 */
  492. handleAdd() {
  493. this.reset();
  494. this.open = true;
  495. this.title = "新增物资说明";
  496. this.optType = "add";
  497. },
  498. /** 修改按钮操作 */
  499. handleUpdate(row) {
  500. this.reset();
  501. getInstructionsInfo(row.instructionsId).then((response) => {
  502. this.form = response.data;
  503. this.open = true;
  504. this.title = "编辑物资说明";
  505. this.optType = "edit";
  506. });
  507. },
  508. /** 提交按钮 */
  509. submitForm() {
  510. this.$refs["form"].validate((valid) => {
  511. if (valid) {
  512. if (this.form.instructionsId != null) {
  513. updateInstructions(this.form).then((response) => {
  514. console.log(response, "修改返回");
  515. this.$modal.msgSuccess("修改成功");
  516. this.open = false;
  517. this.getList();
  518. });
  519. } else {
  520. console.log(this.form, "新增参数");
  521. addInstructions(this.form).then((response) => {
  522. console.log(response, "新增返回");
  523. this.$modal.msgSuccess("新增成功");
  524. this.open = false;
  525. this.getList();
  526. });
  527. }
  528. }
  529. });
  530. },
  531. /** 删除按钮操作 */
  532. handleDelete(row) {
  533. const instructionsId = row.instructionsId || this.ids;
  534. this.$modal
  535. .confirm('是否确认删除编号为"' + instructionsId + '"的数据项?')
  536. .then(function () {
  537. return delInstructions(instructionsId);
  538. })
  539. .then(() => {
  540. this.getList();
  541. this.$modal.msgSuccess("删除成功");
  542. })
  543. .catch(() => {});
  544. },
  545. },
  546. };
  547. </script>
  548. <style lang="scss" src="@/assets/styles/dialog-title.scss" scoped>
  549. .el-input-width {
  550. width: 380px !important;
  551. }
  552. </style>