d216f438c45b9db31dde31c72abf7924e475016c.svn-base 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  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. console.log('table数据', response.data.list)
  171. if (response.data.list !== null) {
  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. // 检验用户名称/角色是否为空
  233. if (this.table.temp.tclassid == '' && this.table.temp.Code == '' && this.table.temp.name == '' && this.table.temp.infoCode == '') {
  234. this.$message({ type: 'error', message: '设备类型/设备编号/设备名称/数据采集卡编号不能为空', duration: 2000 })
  235. return false
  236. } else if (this.table.temp.Code == '' && this.table.temp.name == '' && this.table.temp.infoCode == '') {
  237. this.$message({ type: 'error', message: '设备编号/设备名称/数据采集卡编号不能为空', duration: 2000 })
  238. return false
  239. } else if (this.table.temp.name == '' && this.table.temp.infoCode == '') {
  240. this.$message({ type: 'error', message: '设备名称/数据采集卡编号不能为空', duration: 2000 })
  241. return false
  242. } else if (this.table.temp.tclassid == '') {
  243. this.$message({ type: 'error', message: '设备类型不能为空', duration: 2000 })
  244. return false
  245. } else if (this.table.temp.name == '') {
  246. this.$message({ type: 'error', message: '设备名称不能为空', duration: 2000 })
  247. return false
  248. } else if (this.table.temp.Code == '') {
  249. this.$message({ type: 'error', message: '设备编号不能为空', duration: 2000 })
  250. return false
  251. } else if (this.table.temp.infoCode == '') {
  252. this.$message({ type: 'error', message: '数据采集卡编号不能为空', duration: 2000 })
  253. return false
  254. }
  255. const infoCode = /^([0-9]|(1[0-5]))$/
  256. if (!infoCode.test(parseInt(this.table.temp.infoCode))) {
  257. this.$message({ type: 'error', message: '数据采集卡请输入0-15之间整数', duration: 2000 })
  258. return false
  259. }
  260. const pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~!@#¥……&*()——|{}【】‘;:”“'。,、?]")
  261. console.log(this.table.temp.Code)
  262. if (pattern.test(this.table.temp.Code)) {
  263. this.$message({ type: 'error', message: '设备编号不可输入特殊字符', duration: 2000 })
  264. return false
  265. }
  266. if (pattern.test(this.table.temp.name)) {
  267. this.$message({ type: 'error', message: '设备名称不可输入特殊字符', duration: 2000 })
  268. return false
  269. }
  270. this.isokDisable = true
  271. setTimeout(() => {
  272. this.isokDisable = false
  273. }, 1000)
  274. this.requestParam.name = 'insertTmrEquipment'
  275. this.requestParam.parammaps = this.table.temp
  276. PostDataByName(this.requestParam).then(response => {
  277. console.log('新增保存发送参数', this.requestParam)
  278. if (response.msg !== 'fail') {
  279. this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
  280. this.getList()
  281. } else {
  282. this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
  283. }
  284. })
  285. },
  286. createCancel(row) {
  287. console.log('点击了新增取消')
  288. for (let i = 0; i < this.table.list.length; i++) {
  289. if (row.myId === this.table.list[i].myId) {
  290. var listIndex = this.table.list.indexOf(this.table.list[i])
  291. }
  292. if (listIndex > -1) {
  293. this.table.list.splice(listIndex, 1)
  294. return
  295. }
  296. }
  297. },
  298. handleUpdate(row) {
  299. for (let i = 0; i < this.table.list.length; i++) {
  300. if (this.table.list[i].Edit == true) {
  301. this.$message({ type: 'error', message: '当前内容未保存,请点击取消或保存继续进行操作', duration: 2000 })
  302. return false
  303. }
  304. }
  305. // 编辑true,不可编辑false
  306. row.Edit = true
  307. row.NoEdit = false
  308. // 新增false,编辑false,编辑保存true
  309. row.isCreate = false
  310. row.isUpdate = false
  311. row.isUpdateSave = true
  312. },
  313. updateData(row) {
  314. console.log('点击了编辑保存')
  315. this.table.temp.pastureId = Cookies.get('pastureid')
  316. this.table.temp.Code = row.Code
  317. this.table.temp.name = row.name
  318. this.table.temp.infoCode = row.infoCode
  319. this.table.temp.enable = row.enable
  320. this.table.temp.remark = row.remark
  321. this.table.temp.tclassid = row.tclassid
  322. this.table.temp.tclassname = row.tclassname
  323. this.table.temp.id = row.id
  324. // 检验用户名称/角色是否为空
  325. if (this.table.temp.tclassid == '' && this.table.temp.Code == '' && this.table.temp.name == '' && this.table.temp.infoCode == '') {
  326. this.$message({ type: 'error', message: '设备类型/设备编号/设备名称/数据采集卡编号不能为空', duration: 2000 })
  327. return false
  328. } else if (this.table.temp.Code == '' && this.table.temp.name == '' && this.table.temp.infoCode == '') {
  329. this.$message({ type: 'error', message: '设备编号/设备名称/数据采集卡编号不能为空', duration: 2000 })
  330. return false
  331. } else if (this.table.temp.name == '' && this.table.temp.infoCode == '') {
  332. this.$message({ type: 'error', message: '设备名称/数据采集卡编号不能为空', duration: 2000 })
  333. return false
  334. } else if (this.table.temp.tclassid == '') {
  335. this.$message({ type: 'error', message: '设备类型不能为空', duration: 2000 })
  336. return false
  337. } else if (this.table.temp.name == '') {
  338. this.$message({ type: 'error', message: '设备名称不能为空', duration: 2000 })
  339. return false
  340. } else if (this.table.temp.Code == '') {
  341. this.$message({ type: 'error', message: '设备编号不能为空', duration: 2000 })
  342. return false
  343. } else if (this.table.temp.infoCode == '') {
  344. this.$message({ type: 'error', message: '数据采集卡编号不能为空', duration: 2000 })
  345. return false
  346. }
  347. const infoCode = /^([0-9]|(1[0-5]))$/
  348. if (!infoCode.test(parseInt(this.table.temp.infoCode))) {
  349. this.$message({ type: 'error', message: '数据采集卡请输入0-15之间整数', duration: 2000 })
  350. return false
  351. }
  352. const pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~!@#¥……&*()——|{}【】‘;:”“'。,、?]")
  353. console.log(this.table.temp.Code)
  354. if (pattern.test(this.table.temp.Code)) {
  355. this.$message({ type: 'error', message: '设备编号不可输入特殊字符', duration: 2000 })
  356. return false
  357. }
  358. if (pattern.test(this.table.temp.name)) {
  359. this.$message({ type: 'error', message: '设备名称不可输入特殊字符', duration: 2000 })
  360. return false
  361. }
  362. this.isokDisable = true
  363. setTimeout(() => {
  364. this.isokDisable = false
  365. }, 1000)
  366. this.requestParam.name = 'updateTmrEquipment'
  367. this.requestParam.parammaps = this.table.temp
  368. PostDataByName(this.requestParam).then(response => {
  369. console.log('新增保存发送参数', this.requestParam)
  370. if (response.msg !== 'fail') {
  371. this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
  372. this.getList()
  373. } else {
  374. this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
  375. }
  376. })
  377. },
  378. updateCancel(row) {
  379. console.log('点击了编辑取消')
  380. // 编辑false,不可编辑true
  381. row.Edit = false
  382. row.NoEdit = true
  383. // 新增false,编辑true,编辑保存false
  384. row.isCreate = false
  385. row.isUpdate = true
  386. row.isUpdateSave = false
  387. this.getList()
  388. },
  389. handleRowDelete(row) {
  390. console.log('点击了行内删除')
  391. MessageBox.confirm('是否确认删除此信息?', {
  392. confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
  393. }).then(() => {
  394. this.selectList = []
  395. this.requestParam = {}
  396. this.requestParam.name = 'deleteTmrEquipment'
  397. this.requestParam.parammaps = {}
  398. // this.requestParam.parammaps.pastureid = row.pastureid
  399. this.requestParam.parammaps.id = row.id
  400. PostDataByName(this.requestParam).then(response => {
  401. if (response.msg === 'fail') {
  402. this.$notify({ title: '删除失败', message: response.data, type: 'warning', duration: 2000 })
  403. } else {
  404. this.$notify({ title: '成功', message: '删除成功', type: 'success', duration: 2000 })
  405. this.getList()
  406. }
  407. })
  408. }).catch(() => {
  409. this.$message({ type: 'info', message: '已取消删除' })
  410. })
  411. },
  412. handleSelectionChange(val) {
  413. console.log('勾选数据', val)
  414. this.selectList = val
  415. },
  416. handleDelete() {
  417. console.log('点击了删除')
  418. if (this.selectList.length == 0) {
  419. this.$message({ type: 'error', message: '请选择设备信息', duration: 2000 })
  420. } else {
  421. MessageBox.confirm('当前选中' + this.selectList.length + '条信息,是否删除?', {
  422. confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
  423. }).then(() => {
  424. console.log(this.selectList)
  425. this.requestParam = {}
  426. this.requestParam.common = { 'returnmap': '0' }
  427. this.requestParam.data = []
  428. this.requestParam.data[0] = { 'name': 'insertSpotList', 'resultmaps': { 'list': this.selectList }}
  429. this.requestParam.data[0].children = []
  430. this.requestParam.data[0].children[0] = { 'name': 'deleteTmrEquipment', 'type': 'e', 'parammaps': {
  431. id: '@insertSpotList.id'
  432. // pastureid: '@insertSpotList.pastureid'
  433. }}
  434. ExecDataByConfig(this.requestParam).then(response => {
  435. console.log('删除保存发送参数', this.requestParam)
  436. if (response.msg === 'fail') {
  437. this.$notify({ title: '删除失败', message: response.data, type: 'warning', duration: 2000 })
  438. } else {
  439. this.$notify({ title: '', message: '删除成功', type: 'success', duration: 2000 })
  440. this.getList()
  441. }
  442. })
  443. })
  444. }
  445. }
  446. }
  447. }
  448. </script>
  449. <style lang="scss" scoped>
  450. .search{margin-top:10px;}
  451. .table{margin-top:10px;}
  452. </style>