d7c4bf37086ae8c6ec0bb22147ac395aee5ff145.svn-base 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. <template>
  2. <div class="app-container">
  3. <div class="search">
  4. <el-input v-model="table.getdataListParm.parammaps.eqcode" placeholder="GPS编号" style="width: 180px;" class="filter-item" clearable />
  5. <el-input v-model="table.getdataListParm.parammaps.tname" placeholder="GPS名称" 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="GPS编号" min-width="110px" align="center">
  40. <template slot-scope="scope">
  41. <span v-if="scope.row.NoEdit">{{ scope.row.field1 }}</span>
  42. <el-input v-if="scope.row.Edit" v-model="scope.row.field1" placeholder="1-32个字符" type="textarea" :autosize="{ minRows: 1.3, maxRows: 4}" maxlength="32" style="width:80%;padding:10px 0;" />
  43. </template>
  44. </el-table-column>
  45. <el-table-column label="GPS名称" min-width="110px" align="center">
  46. <template slot-scope="scope">
  47. <span v-if="scope.row.NoEdit">{{ scope.row.field2 }}</span>
  48. <el-input v-if="scope.row.Edit" v-model="scope.row.field2" type="textarea" :autosize="{ minRows: 1.3, maxRows: 4}" style="width:80%;padding:10px 0;" maxlength="32" />
  49. </template>
  50. </el-table-column>
  51. <el-table-column label="关联设备" min-width="110px" align="center">
  52. <template slot-scope="scope">
  53. <span v-if="scope.row.NoEdit">{{ scope.row.field3 }}</span>
  54. <el-select v-if="scope.row.Edit" v-model="scope.row.field3" @change="(value)=> {handleAssociatedDevicesChange(value,scope.row)}">
  55. <el-option v-for="item in associatedDevicesList" :key="item.id" :label="`名称:${item.name} 编号:${item.name2}类型:${item.name3}`" :value="item.id" />
  56. </el-select>
  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.field4 }}</span>
  62. <el-input v-if="scope.row.Edit" v-model="scope.row.field4" type="textarea" :autosize="{ minRows: 1.3, maxRows: 4}" style="width:95%;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. <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)" />
  68. </template>
  69. </el-table-column>
  70. <el-table-column label="操作" align="center" width="80" class-name="small-padding fixed-width" fixed="right">
  71. <template slot-scope="{row}">
  72. <!-- 新增 -->
  73. <el-button v-if="row.isCreate" :disabled="isokDisable" icon="el-icon-folder-checked" class="miniSuccess" @click="createData(row)" />
  74. <span v-if="row.isCreate" class="centerSpan">|</span>
  75. <el-button v-if="row.isCreate" class="minCancel" icon="el-icon-close" @click="createCancel(row)" />
  76. <!-- 编辑 -->
  77. <el-button v-if="row.isUpdate && isRoleEdit" class="miniSuccess" icon="el-icon-edit-outline" @click="handleUpdate(row)" />
  78. <span v-if="row.isUpdate && isRoleEdit" class="centerSpan">|</span>
  79. <el-button v-if="row.isUpdate && isRoleEdit" class="miniDanger" icon="el-icon-delete" @click="handleRowDelete(row)" />
  80. <!-- 编辑保存 -->
  81. <el-button v-if="row.isUpdateSave" :disabled="isokDisable" icon="el-icon-folder-checked" class="miniSuccess" @click="updateData(row)" />
  82. <span v-if="row.isUpdateSave" class="centerSpan">|</span>
  83. <el-button v-if="row.isUpdateSave" class="minCancel" icon="el-icon-close" @click="updateCancel(row)" />
  84. </template>
  85. </el-table-column>
  86. </el-table>
  87. </el-form>
  88. <pagination v-show="table.total>=0" :total="table.total" :page.sync="table.getdataListParm.offset" :limit.sync="table.getdataListParm.pagecount" @pagination="getList" />
  89. </div>
  90. </div>
  91. </template>
  92. <script>
  93. import { GetDataByName, PostDataByName, failproccess, ExecDataByConfig, checkButtons } from '@/api/common'
  94. import Cookies from 'js-cookie'
  95. import Pagination from '@/components/Pagination'
  96. import { MessageBox } from 'element-ui'
  97. export default {
  98. name: 'ManagementGPS',
  99. components: { Pagination },
  100. data() {
  101. return {
  102. isRoleEdit: [],
  103. enableList: [{ id: 1, name: '是' }, { id: 0, name: '否' }],
  104. associatedDevicesList: [{ id: 0, name: '设备001', name2: '00123', name3: '铲车' }, { id: 1, name: '设备002', name2: '00124', name3: '铲车' }, { id: 2, name: '设备003', name2: '00125', name3: '铲车' }],
  105. table: {
  106. rules: {
  107. name: { type: 'string', required: true, message: '必填字段', trigger: 'change' }
  108. },
  109. getdataListParm: {
  110. name: 'getTMRList',
  111. page: 1,
  112. offset: 1,
  113. pagecount: parseInt(Cookies.get('pageCount')),
  114. returntype: 'Map',
  115. parammaps: {
  116. pastureid: Cookies.get('pastureid'),
  117. eqcode: '',
  118. tclassname: '',
  119. enable: '',
  120. eqtype: '0'
  121. }
  122. },
  123. tableKey: 0,
  124. list: [],
  125. total: 0,
  126. listLoading: true,
  127. temp: {}
  128. },
  129. requestParam: {},
  130. isokDisable: false,
  131. selectList: [],
  132. rowStyle: { maxHeight: 30 + 'px', height: 30 + 'px' },
  133. cellStyle: { padding: 0 + 'px' }
  134. }
  135. },
  136. created() {
  137. this.getList()
  138. this.getButtons()
  139. },
  140. methods: {
  141. getButtons() {
  142. const Edit = 'ForkliftManagement'
  143. const isRoleEdit = checkButtons(JSON.parse(sessionStorage.getItem('buttons')), Edit)
  144. this.isRoleEdit = isRoleEdit
  145. },
  146. getList() {
  147. this.table.listLoading = true
  148. GetDataByName(this.table.getdataListParm).then(response => {
  149. // console.log('table数据', response.data.list)
  150. if (response.data.list !== null) {
  151. // for (let i = 0; i < response.data.list.length; i++) {
  152. // this.$set(response.data.list[i], 'Edit', false) // 编辑
  153. // this.$set(response.data.list[i], 'NoEdit', true) // 不可编辑/输入
  154. // this.$set(response.data.list[i], 'isCreate', false) // 新增操作
  155. // this.$set(response.data.list[i], 'isUpdate', true) // 编辑操作
  156. // this.$set(response.data.list[i], 'isUpdateSave', false) // 编辑保存
  157. // }
  158. // this.table.list = response.data.list
  159. this.table.pageNum = response.data.pageNum
  160. this.table.pageSize = response.data.pageSize
  161. this.table.total = response.data.total
  162. } else {
  163. // this.table.list = []
  164. }
  165. this.table.list = [
  166. { 'field1': 'GPS01', 'field2': '自走式GPS', 'field3': '1', 'field4': '1号自走式tmr', 'id': '1', 'myId': (new Date()).valueOf(), 'Edit': false, 'NoEdit': true, 'isCreate': false, 'isUpdate': true, 'isUpdateSave': false, 'enable': 1 },
  167. { 'field1': 'GPS02', 'field2': '铲车GPS', 'field3': '1号铲车', 'field4': '', 'id': '1', 'myId': (new Date()).valueOf(), 'Edit': false, 'NoEdit': true, 'isCreate': false, 'isUpdate': true, 'isUpdateSave': false, 'enable': 1 },
  168. { 'field1': 'GPS03', 'field2': '推料车GPS', 'field3': '1号推料车', 'field4': '', 'id': '1', 'myId': (new Date()).valueOf(), 'Edit': false, 'NoEdit': true, 'isCreate': false, 'isUpdate': true, 'isUpdateSave': false, 'enable': 1 }
  169. ]
  170. this.table.total = this.table.list.length
  171. setTimeout(() => {
  172. this.table.listLoading = false
  173. }, 100)
  174. })
  175. },
  176. handleEnableChange() {
  177. console.log('点击了是否启用')
  178. },
  179. handleSearch() {
  180. console.log('点击了查询')
  181. this.table.getdataListParm.offset = 1
  182. this.getList()
  183. },
  184. handleRefresh() {
  185. console.log('点击了重置')
  186. this.table.getdataListParm.parammaps.eqcode = ''
  187. this.table.getdataListParm.parammaps.tname = ''
  188. this.table.getdataListParm.parammaps.enable = ''
  189. this.table.getdataListParm.parammaps.eqtype = '0'
  190. this.table.getdataListParm.offset = 1
  191. this.getList()
  192. },
  193. handleAssociatedDevicesChange(item, row) {
  194. row.associatedDevices = this.associatedDevicesList.find(obj => obj.id === item).name
  195. },
  196. handleCreate() {
  197. console.log('点击了新增')
  198. // 编辑true/不可编辑false
  199. // 新增操true,编辑false,编辑保存false
  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. this.table.list.unshift({ 'myId': (new Date()).valueOf(), 'Edit': true, 'NoEdit': false, 'isCreate': true, 'isUpdate': false, 'isUpdateSave': false, 'enable': 1, 'eqcode': '', 'tname': '', 'datacaptureno': '' })
  207. },
  208. createData(row) {
  209. console.log('点击了新增保存')
  210. this.table.temp.pastureid = Cookies.get('pastureid')
  211. this.table.temp.eqcode = row.eqcode
  212. this.table.temp.tname = row.tname
  213. this.table.temp.datacaptureno = row.datacaptureno
  214. this.table.temp.enable = row.enable
  215. this.table.temp.remark = row.remark
  216. this.table.temp.tclassid = '0'
  217. this.table.temp.maxstirfeed = '0'
  218. // 检验用户名称/角色是否为空
  219. if (this.table.temp.eqcode == '' && this.table.temp.tname == '' && this.table.temp.datacaptureno == '') {
  220. this.$message({ type: 'error', message: '铲车编号/铲车名称/数据采集卡编号不能为空', duration: 2000 })
  221. return false
  222. } else if (this.table.temp.tname == '' && this.table.temp.datacaptureno == '') {
  223. this.$message({ type: 'error', message: '铲车名称/数据采集卡编号不能为空', duration: 2000 })
  224. return false
  225. } else if (this.table.temp.eqcode == '') {
  226. this.$message({ type: 'error', message: '铲车编号不能为空', duration: 2000 })
  227. return false
  228. } else if (this.table.temp.tname == '') {
  229. this.$message({ type: 'error', message: '铲车名称不能为空', duration: 2000 })
  230. return false
  231. } else if (this.table.temp.datacaptureno == '') {
  232. this.$message({ type: 'error', message: '数据采集卡编号不能为空', duration: 2000 })
  233. return false
  234. }
  235. const datacaptureno = /^([0-9]|(1[0-5]))$/
  236. if (!datacaptureno.test(parseInt(this.table.temp.datacaptureno))) {
  237. this.$message({ type: 'error', message: '数据采集卡请输入0-15之间整数', duration: 2000 })
  238. return false
  239. }
  240. const pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~!@#¥……&*()——|{}【】‘;:”“'。,、?]")
  241. console.log(this.table.temp.eqcode)
  242. if (pattern.test(this.table.temp.eqcode)) {
  243. this.$message({ type: 'error', message: '铲车编号不可输入特殊字符', duration: 2000 })
  244. return false
  245. }
  246. if (pattern.test(this.table.temp.tname)) {
  247. this.$message({ type: 'error', message: '铲车名称不可输入特殊字符', duration: 2000 })
  248. return false
  249. }
  250. this.isokDisable = true
  251. setTimeout(() => {
  252. this.isokDisable = false
  253. }, 1000)
  254. this.requestParam.name = 'insertTMR'
  255. this.requestParam.parammaps = this.table.temp
  256. PostDataByName(this.requestParam).then(response => {
  257. console.log('新增保存发送参数', this.requestParam)
  258. if (response.msg !== 'fail') {
  259. this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
  260. this.getList()
  261. } else {
  262. this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
  263. }
  264. })
  265. },
  266. createCancel(row) {
  267. console.log('点击了新增取消')
  268. for (let i = 0; i < this.table.list.length; i++) {
  269. if (row.myId === this.table.list[i].myId) {
  270. var listIndex = this.table.list.indexOf(this.table.list[i])
  271. }
  272. if (listIndex > -1) {
  273. this.table.list.splice(listIndex, 1)
  274. return
  275. }
  276. }
  277. },
  278. handleUpdate(row) {
  279. for (let i = 0; i < this.table.list.length; i++) {
  280. if (this.table.list[i].Edit == true) {
  281. this.$message({ type: 'error', message: '当前内容未保存,请点击取消或保存继续进行操作', duration: 2000 })
  282. return false
  283. }
  284. }
  285. // 编辑true,不可编辑false
  286. row.Edit = true
  287. row.NoEdit = false
  288. // 新增false,编辑false,编辑保存true
  289. row.isCreate = false
  290. row.isUpdate = false
  291. row.isUpdateSave = true
  292. },
  293. updateData(row) {
  294. console.log('点击了编辑保存')
  295. this.table.temp.pastureid = Cookies.get('pastureid')
  296. this.table.temp.eqcode = row.eqcode
  297. this.table.temp.tname = row.tname
  298. this.table.temp.datacaptureno = row.datacaptureno
  299. this.table.temp.enable = row.enable
  300. this.table.temp.remark = row.remark
  301. this.table.temp.tclassid = '0'
  302. this.table.temp.maxstirfeed = '0'
  303. this.table.temp.id = row.id
  304. // 检验用户名称/角色是否为空
  305. if (this.table.temp.eqcode == '' && this.table.temp.tname == '' && this.table.temp.datacaptureno == '') {
  306. this.$message({ type: 'error', message: '铲车编号/铲车名称/数据采集卡编号不能为空', duration: 2000 })
  307. return false
  308. } else if (this.table.temp.tname == '' && this.table.temp.datacaptureno == '') {
  309. this.$message({ type: 'error', message: '铲车名称/数据采集卡编号不能为空', duration: 2000 })
  310. return false
  311. } else if (this.table.temp.eqcode == '') {
  312. this.$message({ type: 'error', message: '铲车编号不能为空', duration: 2000 })
  313. return false
  314. } else if (this.table.temp.tname == '') {
  315. this.$message({ type: 'error', message: '铲车名称不能为空', duration: 2000 })
  316. return false
  317. } else if (this.table.temp.datacaptureno == '') {
  318. this.$message({ type: 'error', message: '数据采集卡编号不能为空', duration: 2000 })
  319. return false
  320. }
  321. const datacaptureno = /^([0-9]|(1[0-5]))$/
  322. if (!datacaptureno.test(parseInt(this.table.temp.datacaptureno))) {
  323. this.$message({ type: 'error', message: '数据采集卡请输入0-15之间整数', duration: 2000 })
  324. return false
  325. }
  326. const pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~!@#¥……&*()——|{}【】‘;:”“'。,、?]")
  327. console.log(this.table.temp.eqcode)
  328. if (pattern.test(this.table.temp.eqcode)) {
  329. this.$message({ type: 'error', message: '铲车编号不可输入特殊字符', duration: 2000 })
  330. return false
  331. }
  332. if (pattern.test(this.table.temp.tname)) {
  333. this.$message({ type: 'error', message: '铲车名称不可输入特殊字符', duration: 2000 })
  334. return false
  335. }
  336. this.isokDisable = true
  337. setTimeout(() => {
  338. this.isokDisable = false
  339. }, 1000)
  340. this.requestParam.name = 'updateTMR'
  341. this.requestParam.parammaps = this.table.temp
  342. PostDataByName(this.requestParam).then(response => {
  343. console.log('新增保存发送参数', this.requestParam)
  344. if (response.msg !== 'fail') {
  345. this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
  346. this.getList()
  347. } else {
  348. this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
  349. }
  350. })
  351. },
  352. updateCancel(row) {
  353. console.log('点击了编辑取消')
  354. // 编辑false,不可编辑true
  355. row.Edit = false
  356. row.NoEdit = true
  357. // 新增false,编辑true,编辑保存false
  358. row.isCreate = false
  359. row.isUpdate = true
  360. row.isUpdateSave = false
  361. this.getList()
  362. },
  363. handleRowDelete(row) {
  364. console.log('点击了行内删除')
  365. MessageBox.confirm('是否确认删除此信息?', {
  366. confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
  367. }).then(() => {
  368. this.selectList = []
  369. this.requestParam.data = []
  370. this.requestParam.data[0] = { 'name': 'checkDeleteTmr', 'type': 'v', 'parammaps': {
  371. 'pastureid': row.pastureid,
  372. 'id': row.id
  373. }}
  374. this.requestParam.data[1] = { 'name': 'deleteTMR', 'type': 'e', 'parammaps': {
  375. 'pastureid': row.pastureid,
  376. 'id': row.id
  377. }}
  378. ExecDataByConfig(this.requestParam).then(response => {
  379. console.log('删除保存发送参数', this.requestParam)
  380. if (response.msg === 'fail') {
  381. this.$notify({ title: '删除失败', message: response.data, type: 'warning', duration: 2000 })
  382. } else {
  383. this.$notify({ title: '', message: '删除成功', type: 'success', duration: 2000 })
  384. this.getList()
  385. }
  386. })
  387. }).catch(() => {
  388. this.$message({ type: 'info', message: '已取消删除' })
  389. })
  390. },
  391. handleSelectionChange(val) {
  392. console.log('勾选数据', val)
  393. this.selectList = val
  394. },
  395. handleDelete() {
  396. console.log('点击了删除')
  397. if (this.selectList.length == 0) {
  398. this.$message({ type: 'error', message: '请选择铲车信息', duration: 2000 })
  399. } else {
  400. MessageBox.confirm('当前选中' + this.selectList.length + '条信息,是否删除?', {
  401. confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
  402. }).then(() => {
  403. console.log(this.selectList)
  404. this.requestParam = {}
  405. this.requestParam.common = { 'returnmap': '0' }
  406. this.requestParam.data = []
  407. this.requestParam.data[0] = { 'name': 'insertSpotList', 'resultmaps': { 'list': this.selectList }}
  408. this.requestParam.data[0].children = []
  409. this.requestParam.data[0].children[0] = { 'name': 'checkDeleteTmr', 'type': 'v', 'parammaps': {
  410. id: '@insertSpotList.id',
  411. pastureid: '@insertSpotList.pastureid'
  412. }}
  413. this.requestParam.data[0].children[1] = { 'name': 'deleteTMR', 'type': 'e', 'parammaps': {
  414. id: '@insertSpotList.id',
  415. pastureid: '@insertSpotList.pastureid'
  416. }}
  417. ExecDataByConfig(this.requestParam).then(response => {
  418. console.log('删除保存发送参数', this.requestParam)
  419. if (response.msg === 'fail') {
  420. this.$notify({ title: '删除失败', message: response.data, type: 'warning', duration: 2000 })
  421. } else {
  422. this.$notify({ title: '', message: '删除成功', type: 'success', duration: 2000 })
  423. this.getList()
  424. }
  425. })
  426. })
  427. }
  428. }
  429. }
  430. }
  431. </script>
  432. <style lang="scss" scoped>
  433. .search{margin-top:10px;}
  434. .table{margin-top:10px;}
  435. </style>