index.vue 15 KB

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