c73b244b0575d96c2359c2ebcd54d8f8a070cd2a.svn-base 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. <template>
  2. <div class="app-container">
  3. <div class="search">
  4. <el-input v-model="table.getdataListParm.parammaps.Code" placeholder="设备编号" style="width: 180px;" class="filter-item" clearable />
  5. <el-input v-model="table.getdataListParm.parammaps.name" placeholder="设备名称" style="width: 180px;" class="filter-item" clearable />
  6. <el-select v-model="table.getdataListParm.parammaps.enable" filterable placeholder="是否启用" class="filter-item" style="width: 120px;" clearable>
  7. <el-option v-for="item in enableList" :key="item.id" :label="item.name" :value="item.id" />
  8. </el-select>
  9. <el-button class="successBorder" @click="handleSearch">查询</el-button>
  10. <el-button class="successBorder" @click="handleRefresh">重置</el-button>
  11. </div>
  12. <div class="operation">
  13. <el-button v-if="isRoleEdit" class="success" icon="el-icon-plus" @click="handleCreate">新增</el-button>
  14. <el-button v-if="isRoleEdit" class="danger" icon="el-icon-delete" @click="handleDelete">删除</el-button>
  15. </div>
  16. <div class="table">
  17. <el-form ref="form" :rules="table.rules" :model="table">
  18. <el-table
  19. :key="table.tableKey"
  20. v-loading="table.listLoading"
  21. element-loading-text="给我一点时间"
  22. :data="table.list"
  23. border
  24. fit
  25. highlight-current-row
  26. style="width: 100%;"
  27. :row-style="rowStyle"
  28. :cell-style="cellStyle"
  29. class="elTable table-fixed"
  30. @selection-change="handleSelectionChange"
  31. >
  32. <el-table-column type="selection" align="center" width="50" />
  33. <el-table-column label="序号" align="center" type="index" width="50px">
  34. <template slot-scope="scope">
  35. <span v-if="table.pageNum">{{ scope.$index + (table.pageNum-1) * table.pageSize + 1 }}</span>
  36. <span v-else>1</span>
  37. </template>
  38. </el-table-column>
  39. <el-table-column label="设备类型" min-width="110px" align="center">
  40. <template slot-scope="scope">
  41. <span v-if="scope.row.NoEdit">{{ scope.row.tclassname }}</span>
  42. <el-select v-if="scope.row.Edit" v-model="scope.row.tclassid" @change="changeTclass">
  43. <el-option v-for="item in equipmentTypeList" :key="item.id" :label="item.label" :value="item.id" />
  44. </el-select>
  45. </template>
  46. </el-table-column>
  47. <el-table-column label="设备编号" min-width="110px" align="center">
  48. <template slot-scope="scope">
  49. <span v-if="scope.row.NoEdit">{{ scope.row.Code }}</span>
  50. <el-input v-if="scope.row.Edit" v-model="scope.row.Code" placeholder="1-32个字符" type="textarea" :autosize="{ minRows: 1.3, maxRows: 4}" maxlength="32" style="width:80%;padding:10px 0;" />
  51. </template>
  52. </el-table-column>
  53. <el-table-column label="设备名称" min-width="110px" align="center">
  54. <template slot-scope="scope">
  55. <span v-if="scope.row.NoEdit">{{ scope.row.name }}</span>
  56. <el-input v-if="scope.row.Edit" v-model="scope.row.name" type="textarea" :autosize="{ minRows: 1.3, maxRows: 4}" style="width:80%;padding:10px 0;" maxlength="32" />
  57. </template>
  58. </el-table-column>
  59. <el-table-column label="数据采集卡编号" min-width="110px" align="center">
  60. <template slot-scope="scope">
  61. <span v-if="scope.row.NoEdit">{{ scope.row.infoCode }}</span>
  62. <el-input v-if="scope.row.Edit" v-model="scope.row.infoCode" type="number" step="0.01" style="width:80%;padding:10px 0;" />
  63. </template>
  64. </el-table-column>
  65. <el-table-column label="备注" min-width="110px" align="center">
  66. <template slot-scope="scope">
  67. <span v-if="scope.row.NoEdit">{{ scope.row.remark }}</span>
  68. <el-input v-if="scope.row.Edit" v-model="scope.row.remark" type="textarea" :autosize="{ minRows: 1.3, maxRows: 4}" style="width:95%;padding:10px 0;" />
  69. </template>
  70. </el-table-column>
  71. <el-table-column label="是否启用" min-width="110px" align="center">
  72. <template slot-scope="scope">
  73. <el-switch v-model="scope.row.enable" :disabled="scope.row.NoEdit==true" active-color="#13ce66" inactive-color="#ff4949" :active-value="1" :inactive-value="0" @change="handleEnableChange(scope.$index, scope.row)" />
  74. </template>
  75. </el-table-column>
  76. <el-table-column label="操作" align="center" width="80" class-name="small-padding fixed-width" fixed="right">
  77. <template slot-scope="{row}">
  78. <!-- 新增 -->
  79. <el-button v-if="row.isCreate" :disabled="isokDisable" icon="el-icon-folder-checked" class="miniSuccess" @click="createData(row)" />
  80. <span v-if="row.isCreate" class="centerSpan">|</span>
  81. <el-button v-if="row.isCreate" class="minCancel" icon="el-icon-close" @click="createCancel(row)" />
  82. <!-- 编辑 -->
  83. <el-button v-if="row.isUpdate && isRoleEdit" class="miniSuccess" icon="el-icon-edit-outline" @click="handleUpdate(row)" />
  84. <span v-if="row.isUpdate && isRoleEdit" class="centerSpan">|</span>
  85. <el-button v-if="row.isUpdate && isRoleEdit" class="miniDanger" icon="el-icon-delete" @click="handleRowDelete(row)" />
  86. <!-- 编辑保存 -->
  87. <el-button v-if="row.isUpdateSave" :disabled="isokDisable" icon="el-icon-folder-checked" class="miniSuccess" @click="updateData(row)" />
  88. <span v-if="row.isUpdateSave" class="centerSpan">|</span>
  89. <el-button v-if="row.isUpdateSave" class="minCancel" icon="el-icon-close" @click="updateCancel(row)" />
  90. </template>
  91. </el-table-column>
  92. </el-table>
  93. </el-form>
  94. <pagination v-show="table.total>=0" :total="table.total" :page.sync="table.getdataListParm.offset" :limit.sync="table.getdataListParm.pagecount" @pagination="getList" />
  95. </div>
  96. </div>
  97. </template>
  98. <script>
  99. import { GetDataByName, PostDataByName, failproccess, ExecDataByConfig, checkButtons } from '@/api/common'
  100. import Cookies from 'js-cookie'
  101. import Pagination from '@/components/Pagination'
  102. import { MessageBox } from 'element-ui'
  103. export default {
  104. name: 'ForkliftManagement',
  105. components: { Pagination },
  106. data() {
  107. return {
  108. isRoleEdit: [],
  109. enableList: [{ id: 1, name: '是' }, { id: 0, name: '否' }],
  110. equipmentTypeList: [{ id: '0', name: '设备' }, { id: '6', name: '推料车' }, { id: '7', name: '推粪车' }],
  111. getdownListParm: {
  112. name: 'getDictByName',
  113. page: 1,
  114. offset: 1,
  115. pagecount: '',
  116. returntype: 'Map',
  117. parammaps: {
  118. dictname: '其他设备管理'
  119. }
  120. },
  121. table: {
  122. rules: {
  123. name: { type: 'string', required: true, message: '必填字段', trigger: 'change' }
  124. },
  125. getdataListParm: {
  126. name: 'getTmrEquipment',
  127. page: 1,
  128. offset: 1,
  129. pagecount: parseInt(Cookies.get('pageCount')),
  130. returntype: 'Map',
  131. parammaps: {
  132. pastureId: Cookies.get('pastureid'),
  133. Code: '',
  134. tclassname: '',
  135. enable: ''
  136. }
  137. },
  138. tableKey: 0,
  139. list: [],
  140. total: 0,
  141. listLoading: true,
  142. temp: {}
  143. },
  144. requestParam: {},
  145. isokDisable: false,
  146. selectList: [],
  147. rowStyle: { maxHeight: 30 + 'px', height: 30 + 'px' },
  148. cellStyle: { padding: 0 + 'px' }
  149. }
  150. },
  151. created() {
  152. this.getList()
  153. this.getButtons()
  154. this.getDownList()
  155. },
  156. methods: {
  157. getDownList() {
  158. GetDataByName(this.getdownListParm).then(response => {
  159. this.equipmentTypeList = response.data.list
  160. })
  161. },
  162. getButtons() {
  163. const Edit = 'ForkliftManagement'
  164. const isRoleEdit = checkButtons(JSON.parse(sessionStorage.getItem('buttons')), Edit)
  165. this.isRoleEdit = isRoleEdit
  166. },
  167. getList() {
  168. this.table.listLoading = true
  169. GetDataByName(this.table.getdataListParm).then(response => {
  170. if (response.data !== null && response.data.list !== null) {
  171. console.log('table数据', response.data.list)
  172. for (let i = 0; i < response.data.list.length; i++) {
  173. this.$set(response.data.list[i], 'Edit', false) // 编辑
  174. this.$set(response.data.list[i], 'NoEdit', true) // 不可编辑/输入
  175. this.$set(response.data.list[i], 'isCreate', false) // 新增操作
  176. this.$set(response.data.list[i], 'isUpdate', true) // 编辑操作
  177. this.$set(response.data.list[i], 'isUpdateSave', false) // 编辑保存
  178. }
  179. this.table.list = response.data.list
  180. this.table.pageNum = response.data.pageNum
  181. this.table.pageSize = response.data.pageSize
  182. this.table.total = response.data.total
  183. } else {
  184. this.table.list = []
  185. }
  186. setTimeout(() => {
  187. this.table.listLoading = false
  188. }, 100)
  189. })
  190. },
  191. handleEnableChange() {
  192. console.log('点击了是否启用')
  193. },
  194. changeTclass(item) {
  195. this.table.temp.tclassname = this.equipmentTypeList.find(obj => obj.id == item).name
  196. console.log(this.table.temp)
  197. },
  198. handleSearch() {
  199. console.log('点击了查询')
  200. this.table.getdataListParm.offset = 1
  201. this.getList()
  202. },
  203. handleRefresh() {
  204. console.log('点击了重置')
  205. this.table.getdataListParm.parammaps.Code = ''
  206. this.table.getdataListParm.parammaps.name = ''
  207. this.table.getdataListParm.parammaps.enable = ''
  208. this.table.getdataListParm.offset = 1
  209. this.getList()
  210. },
  211. handleCreate() {
  212. console.log('点击了新增')
  213. // 编辑true/不可编辑false
  214. // 新增操true,编辑false,编辑保存false
  215. for (let i = 0; i < this.table.list.length; i++) {
  216. if (this.table.list[i].Edit == true) {
  217. this.$message({ type: 'error', message: '当前内容未保存,请点击取消或保存继续进行操作', duration: 2000 })
  218. return false
  219. }
  220. }
  221. this.table.list.unshift({ 'myId': (new Date()).valueOf(), 'Edit': true, 'NoEdit': false, 'isCreate': true, 'isUpdate': false, 'isUpdateSave': false, 'enable': 1, 'Code': '', 'name': '', 'infoCode': '' })
  222. },
  223. createData(row) {
  224. console.log('点击了新增保存')
  225. this.table.temp.pastureId = Cookies.get('pastureid')
  226. this.table.temp.Code = row.Code
  227. this.table.temp.name = row.name
  228. this.table.temp.infoCode = row.infoCode
  229. this.table.temp.enable = row.enable
  230. this.table.temp.remark = row.remark
  231. this.table.temp.tclassid = row.tclassid
  232. if (this.table.temp.tclassid == '' && this.table.temp.Code == '' && this.table.temp.name == '' && this.table.temp.infoCode == '') {
  233. this.$message({ type: 'error', message: '设备类型/设备编号/设备名称/数据采集卡编号不能为空', duration: 2000 })
  234. return false
  235. } else if (this.table.temp.Code == '' && this.table.temp.name == '' && this.table.temp.infoCode == '') {
  236. this.$message({ type: 'error', message: '设备编号/设备名称/数据采集卡编号不能为空', duration: 2000 })
  237. return false
  238. } else if (this.table.temp.name == '' && this.table.temp.infoCode == '') {
  239. this.$message({ type: 'error', message: '设备名称/数据采集卡编号不能为空', duration: 2000 })
  240. return false
  241. } else if (this.table.temp.tclassid == '') {
  242. this.$message({ type: 'error', message: '设备类型不能为空', duration: 2000 })
  243. return false
  244. } else if (this.table.temp.name == '') {
  245. this.$message({ type: 'error', message: '设备名称不能为空', duration: 2000 })
  246. return false
  247. } else if (this.table.temp.Code == '') {
  248. this.$message({ type: 'error', message: '设备编号不能为空', duration: 2000 })
  249. return false
  250. } else if (this.table.temp.infoCode == '') {
  251. this.$message({ type: 'error', message: '数据采集卡编号不能为空', duration: 2000 })
  252. return false
  253. }
  254. const infoCode = /^([0-9]|(1[0-5]))$/
  255. if (!infoCode.test(parseInt(this.table.temp.infoCode))) {
  256. this.$message({ type: 'error', message: '数据采集卡请输入0-15之间整数', duration: 2000 })
  257. return false
  258. }
  259. const pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~!@#¥……&*()——|{}【】‘;:”“'。,、?]")
  260. console.log(this.table.temp.Code)
  261. if (pattern.test(this.table.temp.Code)) {
  262. this.$message({ type: 'error', message: '设备编号不可输入特殊字符', duration: 2000 })
  263. return false
  264. }
  265. if (pattern.test(this.table.temp.name)) {
  266. this.$message({ type: 'error', message: '设备名称不可输入特殊字符', duration: 2000 })
  267. return false
  268. }
  269. this.isokDisable = true
  270. setTimeout(() => {
  271. this.isokDisable = false
  272. }, 1000)
  273. this.requestParam.name = 'insertTmrEquipment'
  274. this.requestParam.parammaps = this.table.temp
  275. PostDataByName(this.requestParam).then(response => {
  276. console.log('新增保存发送参数', this.requestParam)
  277. if (response.msg !== 'fail') {
  278. this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
  279. this.getList()
  280. } else {
  281. const isRepeat = new RegExp('Duplicate entry :code')
  282. const isRepeat2 = new RegExp('Duplicate entry :infocode')
  283. if (isRepeat.test(response.data)) {
  284. this.$notify({ type: 'error', message: '设备编号不可重复,请重新录入', duration: 2000 })
  285. return false
  286. }
  287. if (isRepeat2.test(response.data)) {
  288. this.$notify({ type: 'error', message: '数据采集编号不可重复,请重新录入', duration: 2000 })
  289. return false
  290. }
  291. this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
  292. }
  293. })
  294. },
  295. createCancel(row) {
  296. console.log('点击了新增取消')
  297. for (let i = 0; i < this.table.list.length; i++) {
  298. if (row.myId === this.table.list[i].myId) {
  299. var listIndex = this.table.list.indexOf(this.table.list[i])
  300. }
  301. if (listIndex > -1) {
  302. this.table.list.splice(listIndex, 1)
  303. return
  304. }
  305. }
  306. },
  307. handleUpdate(row) {
  308. for (let i = 0; i < this.table.list.length; i++) {
  309. if (this.table.list[i].Edit == true) {
  310. this.$message({ type: 'error', message: '当前内容未保存,请点击取消或保存继续进行操作', duration: 2000 })
  311. return false
  312. }
  313. }
  314. // 编辑true,不可编辑false
  315. row.Edit = true
  316. row.NoEdit = false
  317. // 新增false,编辑false,编辑保存true
  318. row.isCreate = false
  319. row.isUpdate = false
  320. row.isUpdateSave = true
  321. },
  322. updateData(row) {
  323. console.log('点击了编辑保存')
  324. this.table.temp.pastureId = Cookies.get('pastureid')
  325. this.table.temp.Code = row.Code
  326. this.table.temp.name = row.name
  327. this.table.temp.infoCode = row.infoCode
  328. this.table.temp.enable = row.enable
  329. this.table.temp.remark = row.remark
  330. this.table.temp.tclassid = row.tclassid
  331. this.table.temp.tclassname = row.tclassname
  332. this.table.temp.id = row.id
  333. if (this.table.temp.tclassid == '' && this.table.temp.Code == '' && this.table.temp.name == '' && this.table.temp.infoCode == '') {
  334. this.$message({ type: 'error', message: '设备类型/设备编号/设备名称/数据采集卡编号不能为空', duration: 2000 })
  335. return false
  336. } else if (this.table.temp.Code == '' && this.table.temp.name == '' && this.table.temp.infoCode == '') {
  337. this.$message({ type: 'error', message: '设备编号/设备名称/数据采集卡编号不能为空', duration: 2000 })
  338. return false
  339. } else if (this.table.temp.name == '' && this.table.temp.infoCode == '') {
  340. this.$message({ type: 'error', message: '设备名称/数据采集卡编号不能为空', duration: 2000 })
  341. return false
  342. } else if (this.table.temp.tclassid == '') {
  343. this.$message({ type: 'error', message: '设备类型不能为空', duration: 2000 })
  344. return false
  345. } else if (this.table.temp.name == '') {
  346. this.$message({ type: 'error', message: '设备名称不能为空', duration: 2000 })
  347. return false
  348. } else if (this.table.temp.Code == '') {
  349. this.$message({ type: 'error', message: '设备编号不能为空', duration: 2000 })
  350. return false
  351. } else if (this.table.temp.infoCode == '') {
  352. this.$message({ type: 'error', message: '数据采集卡编号不能为空', duration: 2000 })
  353. return false
  354. }
  355. const infoCode = /^([0-9]|(1[0-5]))$/
  356. if (!infoCode.test(parseInt(this.table.temp.infoCode))) {
  357. this.$message({ type: 'error', message: '数据采集卡请输入0-15之间整数', duration: 2000 })
  358. return false
  359. }
  360. const pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~!@#¥……&*()——|{}【】‘;:”“'。,、?]")
  361. console.log(this.table.temp.Code)
  362. if (pattern.test(this.table.temp.Code)) {
  363. this.$message({ type: 'error', message: '设备编号不可输入特殊字符', duration: 2000 })
  364. return false
  365. }
  366. if (pattern.test(this.table.temp.name)) {
  367. this.$message({ type: 'error', message: '设备名称不可输入特殊字符', duration: 2000 })
  368. return false
  369. }
  370. this.isokDisable = true
  371. setTimeout(() => {
  372. this.isokDisable = false
  373. }, 1000)
  374. this.requestParam.name = 'updateTmrEquipment'
  375. this.requestParam.parammaps = this.table.temp
  376. PostDataByName(this.requestParam).then(response => {
  377. console.log('新增保存发送参数', this.requestParam)
  378. if (response.msg !== 'fail') {
  379. this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
  380. this.getList()
  381. } else {
  382. const isRepeat = new RegExp('Duplicate entry :code')
  383. const isRepeat2 = new RegExp('Duplicate entry :infocode')
  384. if (isRepeat.test(response.data)) {
  385. this.$notify({ type: 'error', message: '设备编号不可重复,请重新录入', duration: 2000 })
  386. return false
  387. }
  388. if (isRepeat2.test(response.data)) {
  389. this.$notify({ type: 'error', message: '数据采集编号不可重复,请重新录入', duration: 2000 })
  390. return false
  391. }
  392. this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
  393. }
  394. })
  395. },
  396. updateCancel(row) {
  397. console.log('点击了编辑取消')
  398. // 编辑false,不可编辑true
  399. row.Edit = false
  400. row.NoEdit = true
  401. // 新增false,编辑true,编辑保存false
  402. row.isCreate = false
  403. row.isUpdate = true
  404. row.isUpdateSave = false
  405. this.getList()
  406. },
  407. handleRowDelete(row) {
  408. console.log('点击了行内删除')
  409. MessageBox.confirm('是否确认删除此信息?', {
  410. confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
  411. }).then(() => {
  412. this.selectList = []
  413. this.requestParam = {}
  414. this.requestParam.name = 'deleteTmrEquipment'
  415. this.requestParam.parammaps = {}
  416. this.requestParam.parammaps.id = row.id
  417. PostDataByName(this.requestParam).then(response => {
  418. if (response.msg === 'fail') {
  419. this.$notify({ title: '删除失败', message: response.data, type: 'warning', duration: 2000 })
  420. } else {
  421. this.$notify({ title: '成功', message: '删除成功', type: 'success', duration: 2000 })
  422. this.getList()
  423. }
  424. })
  425. }).catch(() => {
  426. this.$message({ type: 'info', message: '已取消删除' })
  427. })
  428. },
  429. handleSelectionChange(val) {
  430. console.log('勾选数据', val)
  431. this.selectList = val
  432. },
  433. handleDelete() {
  434. console.log('点击了删除')
  435. if (this.selectList.length == 0) {
  436. this.$message({ type: 'error', message: '请选择设备信息', duration: 2000 })
  437. } else {
  438. MessageBox.confirm('当前选中' + this.selectList.length + '条信息,是否删除?', {
  439. confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
  440. }).then(() => {
  441. console.log(this.selectList)
  442. this.requestParam = {}
  443. this.requestParam.common = { 'returnmap': '0' }
  444. this.requestParam.data = []
  445. this.requestParam.data[0] = { 'name': 'insertSpotList', 'resultmaps': { 'list': this.selectList }}
  446. this.requestParam.data[0].children = []
  447. this.requestParam.data[0].children[0] = { 'name': 'deleteTmrEquipment', 'type': 'e', 'parammaps': {
  448. id: '@insertSpotList.id'
  449. }}
  450. ExecDataByConfig(this.requestParam).then(response => {
  451. console.log('删除保存发送参数', this.requestParam)
  452. if (response.msg === 'fail') {
  453. this.$notify({ title: '删除失败', message: response.data, type: 'warning', duration: 2000 })
  454. } else {
  455. this.$notify({ title: '', message: '删除成功', type: 'success', duration: 2000 })
  456. this.getList()
  457. }
  458. })
  459. })
  460. }
  461. }
  462. }
  463. }
  464. </script>
  465. <style lang="scss" scoped>
  466. .search{margin-top:10px;}
  467. .table{margin-top:10px;}
  468. </style>