index.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. <template>
  2. <div class="app-container">
  3. <div v-if="isPercentage" class="percentage" style="width: 210px;height: 90px;background: #fff;position: fixed;bottom: 0;left: 0;z-index: 9999999999999;">
  4. <h4 style="padding-left: 10px;line-height: 0;">导出进度:</h4>
  5. <el-progress style="padding-left: 10px;" :text-inside="true" :stroke-width="26" :percentage="percentage" />
  6. </div>
  7. <div class="filter-container">
  8. <tree-select
  9. v-model="table.getdataListParm.partClassId"
  10. :height="200"
  11. :width="300"
  12. size="small"
  13. class="typeSelect"
  14. :data="equipmentCategory.list"
  15. :disabled="equipmentCategory.disabled"
  16. :default-props="equipmentCategory.defaultProps"
  17. :node-key="equipmentCategory.nodeKey"
  18. :placeholder="equipmentCategory.placeholder"
  19. :checked-keys="equipmentCategory.defaultCheckedKeys"
  20. style="display: inline-block;top: -3px;"
  21. @popoverHide="popoverHide"
  22. />
  23. <el-button class="filter-item" type="primary" icon="el-icon-search" @click="form_search">搜索</el-button>
  24. <el-button class="filter-item" type="info" icon="el-icon-tickets" @click="handleDownloadTemp">模板</el-button>
  25. <el-upload style="display: inline-block;" :headers="headers" :data="uploadData" :action="uploadExcelUrl" :show-file-list="false" :before-upload="beforeImportExcel" :on-success="handleImportExcelSuccess">
  26. <el-button class="filter-item" type="warning" icon="el-icon-download" @click="form_search">导入</el-button>
  27. </el-upload>
  28. <el-button class="filter-item" type="success" icon="el-icon-upload2" @click="handleDownload">导出</el-button>
  29. </div>
  30. <div class="operation">
  31. <el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-edit" @click="form_add">新增</el-button>
  32. </div>
  33. <el-table
  34. slot="reference"
  35. border
  36. :data="table.list"
  37. header-align="center"
  38. :row-style="rowStyle"
  39. :cell-style="cellStyle"
  40. class="elTable"
  41. >
  42. <el-table-column label="备件类别" min-width="240px" align="center">
  43. <template slot-scope="scope">
  44. <span v-if="scope.row.NoEdit || scope.row.isDispaly== false">{{ scope.row.partName }}</span>
  45. <tree-select
  46. v-else
  47. v-model="scope.row.partClassId"
  48. size="small"
  49. :width="200"
  50. :display="scope.row.dispaly"
  51. :data="equipmentCategory.list"
  52. :disabled="equipmentCategory.disabled"
  53. :default-props="equipmentCategory.defaultProps"
  54. :node-key="equipmentCategory.nodeKey"
  55. :placeholder="equipmentCategory.placeholder"
  56. :checked-keys="equipmentCategory.defaultCheckedKeys"
  57. style="display: inline-block;"
  58. @popoverHide="popoverHide2"
  59. />
  60. </tree-select>
  61. </template>
  62. </el-table-column>
  63. <el-table-column v-for="(item,index) in table.tablelist" :key="index" align="center" :property="item.property" :label="item.label" min-width="100">
  64. <template slot-scope="scope">
  65. <span v-if="scope.row.NoEdit">{{ scope.row[scope.column.property] }}</span>
  66. <el-input v-if="scope.row.Edit" v-model="scope.row[scope.column.property]" type="number" />
  67. </template>
  68. </el-table-column>
  69. <el-table-column label="操作" align="center" width="200" class-name="small-padding fixed-width" fixed="right">
  70. <template slot-scope="{row}">
  71. <el-button v-if="row.isCreate" :disabled="isokDisable" type="success" size="mini" @click="add_dialog_save(row)">保存</el-button>
  72. <el-button v-if="row.isCreate" type="danger" size="mini" @click="createCancel(row)">取消</el-button>
  73. <el-button v-if="row.isUpdate" type="success" size="mini" @click="form_edit(row)">编辑</el-button>
  74. <el-button v-if="row.isUpdateSave" :disabled="isokDisable" type="success" size="mini" @click="edit_dialog_save(row)">保存</el-button>
  75. <el-button v-if="row.isUpdateSave" type="danger" size="mini" @click="updateCancel(row)">取消</el-button>
  76. <el-button v-if="row.isUpdate" type="danger" size="mini" @click="handleRowDelete(row)">删除</el-button>
  77. </template>
  78. </el-table-column>
  79. </el-table>
  80. <pagination v-show="table.total>0" :total="table.total" :page.sync="table.getdataListParm.offset" :limit.sync="table.getdataListParm.pagecount" @pagination="getList" />
  81. </div>
  82. </template>
  83. <script>
  84. import { GetDataByName, StandardPart, updateAndInster, transData } from '@/api/common'
  85. import Pagination from '@/components/Pagination'
  86. import { MessageBox } from 'element-ui'
  87. import TreeSelect from '@/components/TreeSelect'
  88. import { getToken } from '@/utils/auth'
  89. import { json2excel } from '@/utils/index.js'
  90. export default {
  91. name: 'StandardStock',
  92. components: { Pagination, TreeSelect },
  93. data() {
  94. return {
  95. rowStyle: { maxHeight: 50 + 'px', height: 45 + 'px' },
  96. cellStyle: { padding: 0 + 'px' },
  97. equipmentCategory: {
  98. getdataListParm: { name: 'getStandardPartClass' },
  99. list: [], placeholder: '备件类别', nodeKey: 'id', defaultCheckedKeys: [], disabled: false,
  100. defaultProps: { children: 'children', label: 'partClassNameCode' }, display: 'none'
  101. },
  102. table: {
  103. tableKey: 0, list: [], tablelist: [], total: 0, listLoading: true, idsArray: [],
  104. getdataListParm: {
  105. partClassId: '', page: 1, offset: 1, pagecount: 10, returntype: 'Map', parammaps: {}
  106. }
  107. },
  108. createTemp: {},
  109. postDataParm: {},
  110. isokDisable: false,
  111. headers: {
  112. optname: 'insertcustompic', id: 1, token: getToken()
  113. },
  114. uploadImageUrl: process.env.VUE_APP_BASE_API + 'authdata/uploaderimage',
  115. isPercentage: false,
  116. percentage: 1,
  117. downloadParam: {}
  118. }
  119. },
  120. computed: {
  121. uploadData() {
  122. return {
  123. name: 'importPartsStandard',
  124. importParams: '牧场,一级备件类别,二级备件类别,标准库存(元)',
  125. sheetname: 'SheetJS'
  126. }
  127. },
  128. // 设置上传地址
  129. uploadExcelUrl() {
  130. return process.env.VUE_APP_BASE_API + 'authdata/ImportExcel'
  131. }
  132. },
  133. created() {
  134. this.getEquipmentCategoryList()
  135. this.getList()
  136. },
  137. methods: {
  138. getEquipmentCategoryList() {
  139. GetDataByName(this.equipmentCategory.getdataListParm).then(response => {
  140. if (response.data.list !== null) {
  141. this.equipmentCategory.list = transData(response.data.list, 'id', 'pid', 'children')
  142. } else {
  143. this.equipmentCategory.list = []
  144. }
  145. })
  146. },
  147. popoverHide(checkedIds, checkedData) {
  148. if (checkedIds !== null) {
  149. if (checkedData.children === undefined) {
  150. this.table.getdataListParm.partClassId = checkedData.partClassId
  151. } else {
  152. this.equipmentCategory.defaultCheckedKeys = []
  153. this.table.getdataListParm.partClassId = ''
  154. this.$message({ type: 'warning', message: '请选择具体设备类型' })
  155. }
  156. } else {
  157. this.equipmentCategory.defaultCheckedKeys = []
  158. this.table.getdataListParm.partClassId = ''
  159. }
  160. },
  161. getList() {
  162. this.table.listLoading = true
  163. StandardPart(this.table.getdataListParm).then(response => {
  164. if (response.data.list !== null) {
  165. console.log('table数据', response.data.list)
  166. this.table.tablelist = response.data.list[0]
  167. this.table.idsArray = []
  168. for (let i = 0; i < this.table.tablelist.length; i++) {
  169. this.table.idsArray.push(this.table.tablelist[i].id)
  170. }
  171. this.table.list = response.data.list[1]
  172. for (let i = 0; i < this.table.list.length; i++) {
  173. this.$set(this.table.list[i], 'Edit', false) // 编辑
  174. this.$set(this.table.list[i], 'NoEdit', true) // 不可编辑/输入
  175. this.$set(this.table.list[i], 'isCreate', false) // 新增操作
  176. this.$set(this.table.list[i], 'isUpdate', true) // 编辑操作
  177. this.$set(this.table.list[i], 'isUpdateSave', false) // 编辑保存
  178. this.$set(this.table.list[i], 'isDispaly', false)
  179. this.$set(this.table.list[i], 'dispaly', 'none')
  180. }
  181. this.table.pageNum = response.data.pageNum
  182. this.table.pageSize = response.data.pageSize
  183. this.table.total = response.data.total
  184. } else {
  185. this.table.tablelist = []
  186. this.table.list = []
  187. }
  188. setTimeout(() => {
  189. this.table.listLoading = false
  190. }, 100)
  191. })
  192. },
  193. form_search() {
  194. this.table.listLoading = true
  195. this.table.getdataListParm.offset = 1
  196. this.getList()
  197. },
  198. form_add() {
  199. console.log('新增')
  200. for (let i = 0; i < this.table.list.length; i++) {
  201. if (this.table.list[i].Edit === true) {
  202. this.$message({ type: 'error', message: '当前内容未保存,请点击取消或保存继续进行操作', duration: 2000 })
  203. return false
  204. }
  205. }
  206. var obj = {}
  207. for (let i = 0; i < this.table.tablelist.length; i++) {
  208. obj.myId = (new Date()).valueOf()
  209. obj.Edit = true
  210. obj.NoEdit = false
  211. obj.isCreate = true
  212. obj.isUpdate = false
  213. obj.isUpdateSave = false
  214. obj.display = 'block'
  215. obj.typeName = ''
  216. obj.partClassId = ''
  217. obj.eqCode = ''
  218. obj.typeName = ''
  219. obj.isDispaly = true
  220. obj.display = 'block'
  221. obj[this.table.tablelist[i].property] = ''
  222. var a = i + 1
  223. obj['pastureId' + a] = this.table.tablelist[i].id
  224. }
  225. this.equipmentCategory.defaultCheckedKeys = []
  226. this.createTemp = obj
  227. this.table.list.unshift(obj)
  228. },
  229. popoverHide2(checkedIds, checkedData) {
  230. console.log(checkedIds, checkedData)
  231. if (this.createTemp.isCreate == true) {
  232. if (checkedIds !== null) {
  233. if (checkedData.children == undefined) {
  234. this.createTemp.partClassId = checkedData.id
  235. this.createTemp.eqCode = checkedData.partClassCode
  236. this.createTemp.typeName = checkedData.partClassName
  237. } else {
  238. this.createTemp.partClassId = ''
  239. this.createTemp.eqCode = ''
  240. this.createTemp.typeName = ''
  241. this.$message({ type: 'warning', message: '请选择具体设备类型' })
  242. }
  243. } else {
  244. this.createTemp.partClassId = ''
  245. this.createTemp.eqCode = ''
  246. this.createTemp.typeName = ''
  247. }
  248. }
  249. },
  250. add_dialog_save(row) {
  251. console.log('新增保存', row)
  252. console.log(this.table.tablelist, 'this.table.tablelist')
  253. if (this.createTemp.partClassId == '') {
  254. this.$message({ type: 'error', message: '设备类别必填', duration: 2000 })
  255. return false
  256. }
  257. var arr = []
  258. for (let i = 0; i < this.table.tablelist.length; i++) {
  259. if (row[this.table.tablelist[i].property] !== '' && row[this.table.tablelist[i].property] !== 0 && row[this.table.tablelist[i].property] !== '0') {
  260. arr.push(row[this.table.tablelist[i].property])
  261. }
  262. }
  263. if (arr.length == 0) {
  264. this.$message({ type: 'error', message: '请检查录入数据,至少有一条不为0!', duration: 2000 })
  265. return false
  266. }
  267. MessageBox.confirm('是否保存?', '提示', {
  268. confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
  269. }).then(() => {
  270. for (let i = 0; i < this.table.tablelist.length; i++) {
  271. if (row[this.table.tablelist[i].property] == '') {
  272. row[this.table.tablelist[i].property] = 0
  273. }
  274. }
  275. this.postDataParm = {}
  276. this.postDataParm.check = 'insert'
  277. this.postDataParm.name = 'partStandard'
  278. this.postDataParm.param = {}
  279. this.postDataParm.param = this.createTemp
  280. updateAndInster(this.postDataParm).then(response => {
  281. if (response.msg !== 'fail') {
  282. this.$notify({ title: '成功', message: '新增成功', type: 'success', duration: 2000 })
  283. this.getList()
  284. } else {
  285. this.$notify({ title: '失败', message: '新增失败-' + response.data, type: 'danger', duration: 2000 })
  286. }
  287. })
  288. }).catch(() => {
  289. this.$message({ type: 'info', message: '已取消' })
  290. })
  291. },
  292. createCancel(row) {
  293. for (let i = 0; i < this.table.list.length; i++) {
  294. if (row.myId === this.table.list[i].myId) {
  295. var listIndex = this.table.list.indexOf(this.table.list[i])
  296. }
  297. if (listIndex > -1) {
  298. this.table.list.splice(listIndex, 1)
  299. return
  300. }
  301. }
  302. },
  303. form_edit(row) {
  304. for (let i = 0; i < this.table.list.length; i++) {
  305. if (this.table.list[i].Edit == true) {
  306. this.$message({ type: 'error', message: '当前内容未保存,请点击取消或保存继续进行操作', duration: 2000 })
  307. return false
  308. }
  309. }
  310. row.Edit = true
  311. row.NoEdit = false
  312. row.isCreate = false
  313. row.isUpdate = false
  314. row.isUpdateSave = true
  315. this.equipmentCategory.defaultCheckedKeys = [row.partClassId]
  316. this.createTemp = row
  317. },
  318. edit_dialog_save(row) {
  319. var arr = []
  320. for (let i = 0; i < this.table.tablelist.length; i++) {
  321. if (row[this.table.tablelist[i].property] !== '' && row[this.table.tablelist[i].property] !== 0 && row[this.table.tablelist[i].property] !== '0') {
  322. arr.push(row[this.table.tablelist[i].property])
  323. }
  324. }
  325. if (arr.length == 0) {
  326. this.$message({ type: 'error', message: '请检查录入数据,至少有一条不为0!', duration: 2000 })
  327. return false
  328. }
  329. console.log(arr.length)
  330. for (let i = 0; i < this.table.tablelist.length; i++) {
  331. if (row[this.table.tablelist[i].property] == '') {
  332. row[this.table.tablelist[i].property] = 0
  333. }
  334. }
  335. this.postDataParm = {}
  336. this.postDataParm.check = 'update'
  337. this.postDataParm.name = 'partStandard'
  338. this.postDataParm.param = {}
  339. this.postDataParm.param = this.createTemp
  340. console.log('编辑保存', this.postDataParm)
  341. updateAndInster(this.postDataParm).then(response => {
  342. if (response.msg !== 'fail') {
  343. this.getList()
  344. this.$notify({ title: '成功', message: '成功', type: 'success', duration: 2000 })
  345. } else {
  346. this.$notify({ title: '失败', message: '失败-' + response.data, type: 'danger', duration: 2000 })
  347. }
  348. })
  349. },
  350. updateCancel(row) {
  351. row.Edit = false
  352. row.NoEdit = true
  353. row.isCreate = false
  354. row.isUpdate = true
  355. row.isUpdateSave = false
  356. this.getList()
  357. },
  358. handleRowDelete(row) {
  359. MessageBox.confirm('是否确认删除此信息?', {
  360. confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
  361. }).then(() => {
  362. this.postDataParm = {}
  363. this.postDataParm.check = 'delete'
  364. this.postDataParm.name = 'partStandard'
  365. this.postDataParm.param = {}
  366. this.postDataParm.param = row
  367. updateAndInster(this.postDataParm).then(response => {
  368. if (response.msg !== 'fail') {
  369. this.getList()
  370. this.$notify({ title: '成功', message: '删除成功', type: 'success', duration: 2000 })
  371. } else {
  372. this.$notify({ title: '失败', message: '删除失败-' + response.data, type: 'danger', duration: 2000 })
  373. }
  374. })
  375. }).catch(() => {
  376. this.$message({ type: 'info', message: '已取消删除' })
  377. })
  378. },
  379. handleDownloadTemp() {
  380. const ExcelDatas = [
  381. {
  382. tHeader: ['牧场', '一级备件类别', '二级备件类别', '标准库存(元)'],
  383. filterVal: ['牧场', '一级备件类别', '二级备件类别', '标准库存(元)'],
  384. tableDatas: [],
  385. sheetName: 'SheetJS'
  386. }
  387. ]
  388. json2excel(ExcelDatas, '标准库存模板', true, 'xlsx')
  389. },
  390. handleDownload() {
  391. this.$alert('备件基础信息正在导出中,请勿刷新或离开本页面,若导出时间过长,建议缩小导出数据范围重新导出', {})
  392. this.isPercentage = true
  393. this.percentage = 1
  394. var timer = setInterval(() => {
  395. this.percentage += 5
  396. if (this.percentage > 95) {
  397. this.percentage = 99
  398. clearInterval(timer)
  399. }
  400. this.percentage = this.percentage
  401. }, 1000)
  402. this.downloadParam = {}
  403. this.downloadParam = this.table.getdataListParm
  404. StandardPart(this.downloadParam).then(response => {
  405. if (response.data.list !== '') {
  406. this.percentage = 99
  407. setTimeout(() => {
  408. this.isPercentage = false
  409. }, 2000)
  410. }
  411. var headerList = []
  412. var filterList = []
  413. for (let i = 0; i < response.data.list[0].length; i++) {
  414. headerList.push(response.data.list[0][i].label)
  415. filterList.push(response.data.list[0][i].property)
  416. }
  417. headerList.unshift('设备类别')
  418. filterList.unshift('partName')
  419. console.log(headerList, filterList)
  420. this.$nextTick(() => {
  421. const ExcelDatas = [
  422. { tHeader: headerList, filterVal: filterList, tableDatas: response.data.list[1], sheetName: '标准库存' }
  423. ]
  424. json2excel(ExcelDatas, '标准库存', true, 'xlsx')
  425. })
  426. })
  427. },
  428. beforeImportExcel(file) {
  429. const isLt2M = file.size / 1024 / 1024 < 10
  430. if (!isLt2M) {
  431. this.$message.error('上传文件大小不能超过 10MB!')
  432. }
  433. return isLt2M
  434. },
  435. handleImportExcelSuccess(res, file) {
  436. if (res.msg === 'ok') {
  437. this.$message({ title: '成功', message: '导入成功:' + res.data.success + '条!', type: 'success', duration: 2000 })
  438. if (res.data.err_count > 0) {
  439. this.$notify({ title: '失败', message: '导入失败:' + res.data.err_count + '条!', type: 'danger', duration: 2000 })
  440. import('@/vendor/Export2Excel').then(excel => {
  441. const list1 = res.data.result
  442. const tHeader = ['牧场', '一级备件类别', '二级备件类别', '标准库存']
  443. const filterVal = ['牧场', '一级备件类别', '二级备件类别', '标准库存']
  444. const data1 = this.formatJson(filterVal, list1)
  445. excel.export_json_to_excel({ header: tHeader, data: data1, filename: this.requestParam.parammaps.formType, autoWidth: true, bookType: 'xlsx' })
  446. })
  447. }
  448. } else {
  449. this.$notify({ title: '失败', message: '上传失败', type: 'danger', duration: 2000 })
  450. }
  451. }
  452. }
  453. }
  454. </script>
  455. <style lang="scss" scoped>
  456. .operation{margin-bottom: 10px;}
  457. </style>