祥兆质量前端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

723 lines
23 KiB

2 years ago
  1. <template>
  2. <div class="mod-config">
  3. <!-- 收藏 -->
  4. <div>
  5. <span @click="favoriteFunction()">
  6. <icon-svg :name="favorite?'xiangqufill':'xiangqu'" class="sl-svg"></icon-svg>
  7. </span>
  8. </div>
  9. <!-- 条件查询 -->
  10. <el-form :inline="true" label-position="top" :model="searchData" @keyup.enter.native="getDataList()">
  11. <el-form-item :label="'BU'">
  12. <el-select v-model="searchData.buDesc" placeholder="请选择" clearable style="width: 130px">
  13. <el-option
  14. v-for = "i in userBuList"
  15. :key = "i.buNo"
  16. :label = "i.buDesc"
  17. :value = "i.buDesc">
  18. </el-option>
  19. </el-select>
  20. </el-form-item>
  21. <el-form-item :label="'方法编码:'">
  22. <el-input v-model="searchData.methodNo" clearable style="width: 120px"></el-input>
  23. </el-form-item>
  24. <el-form-item :label="'方法名称:'">
  25. <el-input v-model="searchData.methodName" clearable style="width: 120px"></el-input>
  26. </el-form-item>
  27. <el-form-item label="检验类型:">
  28. <el-select v-model="searchData.inspectionTypeNo" placeholder="请选择">
  29. <el-option label="全部" value=""></el-option>
  30. <el-option
  31. v-for = "i in options"
  32. :key = "i.inspectionTypeNo"
  33. :label = "i.inspectionTypeName"
  34. :value = "i.inspectionTypeNo">
  35. </el-option>
  36. </el-select>
  37. </el-form-item>
  38. <el-form-item :label="' '">
  39. <el-button v-if="!authSearch" type="primary" @click="getDataList()">查询</el-button>
  40. <el-button v-if="!authSave" type="primary" @click="addModal()">新增</el-button>
  41. <download-excel
  42. :fields="fields()"
  43. :data="exportData"
  44. type="xls"
  45. :name="exportName"
  46. :header="exportHeader"
  47. :footer="exportFooter"
  48. :fetch="createExportData"
  49. :before-generate="startDownload"
  50. :before-finish="finishDownload"
  51. worksheet="导出信息"
  52. class="el-button el-button--primary el-button--medium">
  53. {{ "导出" }}
  54. </download-excel>
  55. </el-form-item>
  56. </el-form>
  57. <!-- 展示列表 -->
  58. <el-table
  59. :height="height"
  60. :data="dataList"
  61. border
  62. style="width: 100%;">
  63. <el-table-column
  64. v-for="(item,index) in columnList" :key="index"
  65. :sortable="item.columnSortable"
  66. :prop="item.columnProp"
  67. :header-align="item.headerAlign"
  68. :show-overflow-tooltip="item.showOverflowTooltip"
  69. :align="item.align"
  70. :fixed="item.fixed==''?false:item.fixed"
  71. :width="item.columnWidth"
  72. :label="item.columnLabel">
  73. <template slot-scope="scope">
  74. <span v-if="!item.columnHidden"> {{ scope.row[item.columnProp] }}</span>
  75. <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]" style="width: 100px; height: 80px"/></span>
  76. </template>
  77. </el-table-column>
  78. <el-table-column
  79. fixed="right"
  80. header-align="center"
  81. align="center"
  82. width="160"
  83. label="操作">
  84. <template slot-scope="scope">
  85. <a v-if="!authUpdate" type="text" size="small" @click="updateModal(scope.row)">修改</a>
  86. <a v-if="!authDelete" type="text" size="small" @click="deleteModal(scope.row)">删除</a>
  87. </template>
  88. </el-table-column>
  89. </el-table>
  90. <el-pagination
  91. @size-change="sizeChangeHandle"
  92. @current-change="currentChangeHandle"
  93. :current-page="pageIndex"
  94. :page-sizes="[20, 50, 100, 200, 500]"
  95. :page-size="pageSize"
  96. :total="totalPage"
  97. layout="total, sizes, prev, pager, next, jumper">
  98. </el-pagination>
  99. <!-- 新增和修改 -->
  100. <el-dialog title="检验方法" :close-on-click-modal="false" v-drag :visible.sync="modalFlag" width="500px">
  101. <el-form :inline="true" label-position="top" :model="modalData" :rules="rules" style="margin-left: 7px;margin-top: -5px;">
  102. <el-form-item label="BU" prop="bu" :rules="rules.bu">
  103. <el-select v-model="modalData.bu" placeholder="请选择" :disabled="modalDisableFlag" style="width: 456px">
  104. <el-option
  105. v-for = "i in userBuList"
  106. :key = "i.buNo"
  107. :label = "i.buNo"
  108. :value = "i.buNo">
  109. <span style="float: left;width: 100px">{{ i.sitename }}</span>
  110. <span style="float: right; color: #8492a6;white-space:nowrap;overflow:hidden;text-overflow:ellipsis; font-size: 11px;width: 60px">
  111. {{ i.buDesc }}
  112. </span>
  113. </el-option>
  114. </el-select>
  115. </el-form-item>
  116. </el-form>
  117. <el-form :inline="true" label-position="top" :model="modalData" :rules="rules" style="margin-left: 7px;margin-top: -5px;">
  118. <el-form-item label="方法名称:" prop="methodName" :rules="rules.methodNameType">
  119. <el-input v-model="modalData.methodName" style="width: 221px"></el-input>
  120. </el-form-item>
  121. <el-form-item label="检验类型:" prop="inspectionTypeNo" :rules="rules.inspectionTypeNoType">
  122. <el-select v-model="modalData.inspectionTypeNo" placeholder="请选择" style="width: 221px">
  123. <el-option
  124. v-for = "i in options"
  125. :key = "i.inspectionTypeNo"
  126. :label = "i.inspectionTypeName"
  127. :value = "i.inspectionTypeNo">
  128. </el-option>
  129. </el-select>
  130. </el-form-item>
  131. </el-form>
  132. <el-form :inline="true" label-position="top" :model="modalData" style="margin-left: 7px;margin-top: -5px;">
  133. <el-form-item :label="'检验方法说明:'">
  134. <el-input v-model="modalData.methodRemark" style="width: 456px"></el-input>
  135. </el-form-item>
  136. </el-form>
  137. <el-footer style="height:40px;margin-top: 20px;text-align:center">
  138. <el-button type="primary" @click="saveData()">保存</el-button>
  139. <el-button type="primary" @click="modalFlag = false">关闭</el-button>
  140. </el-footer>
  141. </el-dialog>
  142. </div>
  143. </template>
  144. <script>
  145. import {
  146. qcMethodSearch, // 检验方法查询
  147. qcMethodSave, // 检验方法新增
  148. qcMethodUpdate, // 检验方法修改
  149. qcMethodDelete, // 检验方法删除
  150. inspectionTypeSearch, // 搜索所有检验类型
  151. getSiteAndBuByUserName
  152. } from "@/api/qc/qc.js"
  153. import {getTableDefaultListLanguage, getTableUserListLanguage} from "@/api/table.js"
  154. import {userFavoriteList, saveUserFavorite, removeUserFavorite} from '@/api/userFavorite.js'
  155. export default {
  156. data () {
  157. return {
  158. // 是否收藏
  159. favorite: false,
  160. // 导出 start
  161. exportData: [],
  162. exportName: "检验方法" + this.dayjs().format('YYYYMMDDHHmmss'),
  163. exportHeader: ["检验方法"],
  164. exportFooter: [],
  165. exportList: [],
  166. // 导出 end
  167. searchData: {
  168. site: '',
  169. userName: this.$store.state.user.name,
  170. methodNo: '',
  171. methodName: '',
  172. inspectionTypeNo: '',
  173. buDesc: '',
  174. page: 1,
  175. limit: 10,
  176. },
  177. pageIndex: 1,
  178. pageSize: 20,
  179. totalPage: 0,
  180. height: 200,
  181. dataList: [],
  182. modalFlag: false,
  183. modalDisableFlag: false,
  184. modalData: {
  185. site: '',
  186. bu: '',
  187. flag: '',
  188. methodNo: '',
  189. methodName: '',
  190. createBy: this.$store.state.user.name,
  191. updateBy: this.$store.state.user.name,
  192. methodRemark: '',
  193. inspectionTypeNo: ''
  194. },
  195. // 标头展示
  196. columnList: [
  197. {
  198. userId: this.$store.state.user.name,
  199. functionId: 301001,
  200. serialNumber: '301001TableBuDesc',
  201. tableId: "301001Table",
  202. tableName: "检验方法维护表",
  203. columnWidth: 100,
  204. columnProp: 'buDesc',
  205. headerAlign: 'center',
  206. align: "center",
  207. columnLabel: 'BU',
  208. columnHidden: false,
  209. columnImage: false,
  210. columnSortable: false,
  211. sortLv: 0,
  212. status: true,
  213. fixed: '',
  214. },
  215. {
  216. userId: this.$store.state.user.name,
  217. functionId: 301001,
  218. serialNumber: '301001TableMethodNo',
  219. tableId: "301001Table",
  220. tableName: "检验方法维护表",
  221. columnWidth: 185,
  222. columnProp: 'methodNo',
  223. headerAlign: 'center',
  224. align: "center",
  225. columnLabel: '方法编码',
  226. columnHidden: false,
  227. columnImage: false,
  228. columnSortable: false,
  229. sortLv: 0,
  230. status: true,
  231. fixed: '',
  232. },
  233. {
  234. userId: this.$store.state.user.name,
  235. functionId: 301001,
  236. serialNumber: '301001TableMethodName',
  237. tableId: "301001Table",
  238. tableName: "检验方法维护表",
  239. columnWidth: 182,
  240. columnProp: 'methodName',
  241. headerAlign: 'center',
  242. align: "center",
  243. columnLabel: '方法名称',
  244. columnHidden: false,
  245. columnImage: false,
  246. columnSortable: false,
  247. sortLv: 0,
  248. status: true,
  249. fixed: '',
  250. },
  251. {
  252. userId: this.$store.state.user.name,
  253. functionId: 301001,
  254. serialNumber: '301001TableMethodRemark',
  255. tableId: "301001Table",
  256. tableName: "检验方法维护表",
  257. columnWidth: 182,
  258. columnProp: 'methodRemark',
  259. headerAlign: 'center',
  260. align: "center",
  261. columnLabel: '方法说明',
  262. columnHidden: false,
  263. columnImage: false,
  264. columnSortable: false,
  265. sortLv: 0,
  266. status: true,
  267. fixed: '',
  268. },
  269. {
  270. userId: this.$store.state.user.name,
  271. functionId: 301001,
  272. serialNumber: '301001TableInspectionTypeName',
  273. tableId: "301001Table",
  274. tableName: "检验方法维护表",
  275. columnWidth: 182,
  276. columnProp: 'inspectionTypeName',
  277. headerAlign: 'center',
  278. align: "center",
  279. columnLabel: '检验类型',
  280. columnHidden: false,
  281. columnImage: false,
  282. columnSortable: false,
  283. sortLv: 0,
  284. status: true,
  285. fixed: '',
  286. },
  287. {
  288. userId: this.$store.state.user.name,
  289. functionId: 301001,
  290. serialNumber: '301001TableCreateDate',
  291. tableId: "301001Table",
  292. tableName: "检验方法维护表",
  293. columnWidth: 182,
  294. columnProp: 'createDate',
  295. headerAlign: 'center',
  296. align: "center",
  297. columnLabel: '创建时间',
  298. columnHidden: false,
  299. columnImage: false,
  300. columnSortable: false,
  301. sortLv: 0,
  302. status: true,
  303. fixed: '',
  304. },
  305. {
  306. userId: this.$store.state.user.name,
  307. functionId: 301001,
  308. serialNumber: '301001TableCreateBy',
  309. tableId: "301001Table",
  310. tableName: "检验方法维护表",
  311. columnWidth: 182,
  312. columnProp: 'createBy',
  313. headerAlign: 'center',
  314. align: "center",
  315. columnLabel: '创建人',
  316. columnHidden: false,
  317. columnImage: false,
  318. columnSortable: false,
  319. sortLv: 0,
  320. status: true,
  321. fixed: '',
  322. },
  323. {
  324. userId: this.$store.state.user.name,
  325. functionId: 301001,
  326. serialNumber: '301001TableUpdateDate',
  327. tableId: "301001Table",
  328. tableName: "检验方法维护表",
  329. columnWidth: 182,
  330. columnProp: 'updateDate',
  331. headerAlign: 'center',
  332. align: "center",
  333. columnLabel: '更新时间',
  334. columnHidden: false,
  335. columnImage: false,
  336. columnSortable: false,
  337. sortLv: 0,
  338. status: true,
  339. fixed: '',
  340. },
  341. {
  342. userId: this.$store.state.user.name,
  343. functionId: 301001,
  344. serialNumber: '301001TableUpdateBy',
  345. tableId: "301001Table",
  346. tableName: "检验方法维护表",
  347. columnWidth: 182,
  348. columnProp: 'updateBy',
  349. headerAlign: 'center',
  350. align: "center",
  351. columnLabel: '更新人',
  352. columnHidden: false,
  353. columnImage: false,
  354. columnSortable: false,
  355. sortLv: 0,
  356. status: true,
  357. fixed: '',
  358. },
  359. ],
  360. rules: {
  361. methodNameType:[
  362. {
  363. required: true,
  364. message: ' ',
  365. trigger: ['blur','change']
  366. }
  367. ],
  368. inspectionTypeNoType:[
  369. {
  370. required: true,
  371. message: ' ',
  372. trigger: ['blur','change']
  373. }
  374. ],
  375. bu:[
  376. {
  377. required: true,
  378. message: ' ',
  379. trigger: ['blur','change']
  380. }
  381. ]
  382. },
  383. options: [],
  384. userBuList: [],
  385. authSearch: false,
  386. authSave: false,
  387. authUpdate: false,
  388. authDelete: false,
  389. menuId: this.$route.meta.menuId,
  390. }
  391. },
  392. mounted () {
  393. this.$nextTick(() => {
  394. this.height = window.innerHeight - 180
  395. })
  396. },
  397. created () {
  398. // 按钮控制
  399. this.getButtonAuthData()
  400. // 获取用户的 site 和 bu
  401. this.getSiteAndBuByUserName()
  402. // 校验用户是否收藏
  403. this.favoriteIsOk()
  404. // 获取检验类型
  405. this.inspectionTypeSearch()
  406. // 动态列
  407. this.getTableUserColumn(this.$route.meta.menuId+'table',1)
  408. if (!this.authSearch) {
  409. // 获取数据列表
  410. this.getDataList()
  411. }
  412. },
  413. methods: {
  414. // 获取用户的bu
  415. getSiteAndBuByUserName () {
  416. let tempData = {
  417. username: this.$store.state.user.name,
  418. }
  419. getSiteAndBuByUserName(tempData).then(({data}) => {
  420. if (data.code === 0) {
  421. this.userBuList = data.rows
  422. }
  423. })
  424. },
  425. // 查询获取数据列表
  426. getDataList () {
  427. this.searchData.limit = this.pageSize
  428. this.searchData.page = this.pageIndex
  429. qcMethodSearch(this.searchData).then(({data}) => {
  430. if (data.code === 0) {
  431. this.dataList = data.page.list
  432. this.pageIndex = data.page.currPage
  433. this.pageSize = data.page.pageSize
  434. this.totalPage = data.page.totalCount
  435. }
  436. })
  437. },
  438. // 每页数
  439. sizeChangeHandle (val) {
  440. this.pageSize = val
  441. this.pageIndex = 1
  442. this.getDataList()
  443. },
  444. // 当前页
  445. currentChangeHandle (val) {
  446. this.pageIndex = val
  447. this.getDataList()
  448. },
  449. // 新增按钮
  450. addModal () {
  451. this.modalData = {
  452. flag: '1',
  453. site: '',
  454. bu: this.userBuList[0].buNo,
  455. createBy: this.$store.state.user.name,
  456. updateBy: this.$store.state.user.name,
  457. methodNo: '',
  458. methodName: '',
  459. methodRemark: '',
  460. inspectionTypeNo: ''
  461. }
  462. this.modalDisableFlag = false
  463. this.modalFlag = true
  464. },
  465. // 修改按钮
  466. updateModal (row) {
  467. this.modalData = {
  468. flag: '2',
  469. bu: row.site + '_' + row.buNo,
  470. site: row.site,
  471. createBy: this.$store.state.user.name,
  472. updateBy: this.$store.state.user.name,
  473. methodNo: row.methodNo,
  474. methodName: row.methodName,
  475. methodRemark: row.methodRemark,
  476. inspectionTypeNo: row.inspectionTypeNo
  477. }
  478. this.modalDisableFlag = true
  479. this.modalFlag = true
  480. },
  481. // 删除方法
  482. deleteModal (row) {
  483. this.$confirm(`是否删除这个检验方法?`, '提示', {
  484. confirmButtonText: '确定',
  485. cancelButtonText: '取消',
  486. type: 'warning'
  487. }).then(() => {
  488. qcMethodDelete(row).then(({data}) => {
  489. if (data && data.code === 0) {
  490. this.getDataList()
  491. this.$message({
  492. message: '操作成功',
  493. type: 'success',
  494. duration: 1500,
  495. onClose: () => {}
  496. })
  497. } else {
  498. this.$alert(data.msg, '错误', {
  499. confirmButtonText: '确定'
  500. })
  501. }
  502. })
  503. }).catch(() => {
  504. })
  505. },
  506. // 新增/修改方法
  507. saveData () {
  508. if (this.modalData.bu === '' || this.modalData.bu == null) {
  509. this.$message.warning('请选择BU!')
  510. return
  511. }
  512. if (this.modalData.methodName === '' || this.modalData.methodName == null) {
  513. this.$message.warning('请输入检验方法名称!')
  514. return
  515. }
  516. if(this.modalData.inspectionTypeNo === ''|| this.modalData.inspectionTypeNo == null){
  517. this.$message.warning('请选择检验类型!')
  518. return
  519. }
  520. if (this.modalData.flag === '1') { // 新增
  521. qcMethodSave(this.modalData).then(({data}) => {
  522. if (data && data.code === 0) {
  523. this.getDataList()
  524. this.modalFlag = false
  525. this.$message({
  526. message: '操作成功',
  527. type: 'success',
  528. duration: 1500,
  529. onClose: () => {}
  530. })
  531. } else {
  532. this.$alert(data.msg, '错误', {
  533. confirmButtonText: '确定'
  534. })
  535. }
  536. })
  537. } else { // 修改
  538. qcMethodUpdate(this.modalData).then(({data}) => {
  539. if (data && data.code === 0) {
  540. this.getDataList()
  541. this.modalFlag = false
  542. this.$message({
  543. message: '操作成功',
  544. type: 'success',
  545. duration: 1500,
  546. onClose: () => {}
  547. })
  548. } else {
  549. this.$alert(data.msg, '错误', {
  550. confirmButtonText: '确定'
  551. })
  552. }
  553. })
  554. }
  555. },
  556. // 查询检验类型
  557. inspectionTypeSearch () {
  558. let tempData = {
  559. site: this.$store.state.user.site
  560. }
  561. inspectionTypeSearch(tempData).then(({data}) => {
  562. if (data.code === 0) {
  563. this.options = data.rows
  564. }
  565. })
  566. },
  567. // 校验用户是否收藏
  568. favoriteIsOk () {
  569. let userFavorite = {
  570. userId: this.$store.state.user.id,
  571. languageCode: this.$i18n.locale
  572. }
  573. userFavoriteList(userFavorite).then(({data}) => {
  574. for (let i = 0; i < data.list.length; i++) {
  575. if(this.$route.meta.menuId === data.list[i].menuId){
  576. this.favorite = true
  577. }
  578. }
  579. })
  580. },
  581. // 收藏 OR 取消收藏
  582. favoriteFunction () {
  583. let userFavorite = {
  584. userId: this.$store.state.user.id,
  585. functionId: this.$route.meta.menuId,
  586. }
  587. if (this.favorite) {
  588. removeUserFavorite(userFavorite).then(({data}) => {
  589. this.$message.success(data.msg)
  590. this.favorite = false
  591. })
  592. } else {
  593. // 收藏
  594. saveUserFavorite(userFavorite).then(({data}) => {
  595. this.$message.success(data.msg)
  596. this.favorite = true
  597. })
  598. }
  599. },
  600. //导出excel
  601. async createExportData() {
  602. this.searchData.limit = -1
  603. this.searchData.page = 1
  604. await qcMethodSearch(this.searchData).then(({data}) => {
  605. this.exportList= data.rows
  606. })
  607. return this.exportList
  608. },
  609. startDownload() {},
  610. finishDownload() {},
  611. fields () {
  612. let json = "{"
  613. this.columnList.forEach((item, index) => {
  614. if (index == this.columnList.length - 1) {
  615. json += "\"" + item.columnLabel + "\"" + ":" + "\"" + item.columnProp + "\""
  616. } else {
  617. json += "\"" + item.columnLabel + "\"" + ":" + "\"" + item.columnProp + "\"" + ","
  618. }
  619. })
  620. json += "}"
  621. let s = eval("(" + json + ")")
  622. return s
  623. },
  624. // 动态列开始 获取 用户保存的 格式列
  625. async getTableUserColumn (tableId, columnId) {
  626. let queryTableUser = {
  627. userId: this.$store.state.user.name,
  628. functionId: this.$route.meta.menuId,
  629. tableId: tableId,
  630. status: true,
  631. languageCode: this.$i18n.locale
  632. }
  633. await getTableUserListLanguage(queryTableUser).then(({data}) => {
  634. if (data.rows.length > 0) {
  635. //this.columnList1 = []
  636. switch (columnId) {
  637. case 1:
  638. this.columnList = data.rows
  639. break;
  640. // case 2:
  641. // this.columnDetailList = data.rows
  642. // break;
  643. // case 3:
  644. // this.columnList2 = data.rows
  645. // break;
  646. // case 4:
  647. // this.columnList3 = data.rows
  648. // break;
  649. }
  650. } else {
  651. this.getColumnList(tableId, columnId)
  652. }
  653. })
  654. },
  655. // 获取 tableDefault 列
  656. async getColumnList (tableId, columnId) {
  657. let queryTable = {
  658. functionId: this.$route.meta.menuId,
  659. tableId: tableId,
  660. languageCode: this.$i18n.locale
  661. }
  662. await getTableDefaultListLanguage(queryTable).then(({data}) => {
  663. if (!data.rows.length == 0) {
  664. switch (columnId) {
  665. case 1:
  666. this.columnList = data.rows
  667. break;
  668. // case 2:
  669. // this.columnDetailList = data.rows
  670. // break;
  671. // case 3:
  672. // this.columnList2 = data.rows
  673. // break;
  674. // case 4:
  675. // this.columnList3 = data.rows
  676. // break;
  677. }
  678. } else {
  679. // this.showDefault = true.
  680. }
  681. })
  682. },
  683. //获取按钮的权限数据
  684. getButtonAuthData () {
  685. let searchFlag = this.isAuth(this.menuId+":search")
  686. let saveFlag = this.isAuth(this.menuId+":save")
  687. let updateFlag = this.isAuth(this.menuId+":update")
  688. let deleteFlag = this.isAuth(this.menuId+":delete")
  689. //处理页面的权限数据
  690. this.authSearch = !searchFlag
  691. this.authSave = !saveFlag
  692. this.authUpdate = !updateFlag
  693. this.authDelete = !deleteFlag
  694. },
  695. }
  696. }
  697. </script>