4f6061b7a3e75bca520072b14360a260f058df52.svn-base 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. <template>
  2. <div class="app-container">
  3. <div class="search">
  4. <el-input v-model="table.getdataListParm.parammaps.gpsCode" placeholder="GPS编号" style="width: 180px;" class="filter-item" clearable />
  5. <el-input v-model="table.getdataListParm.parammaps.gpsName" 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.gpsCode }}</span>
  42. <el-input v-if="scope.row.Edit" v-model="scope.row.gpsCode" 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.gpsName }}</span>
  48. <el-input v-if="scope.row.Edit" v-model="scope.row.gpsName" 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.tname }}</span>
  54. <el-select v-if="scope.row.Edit" v-model="scope.row.tmrId" @change="(value)=> {handleAssociatedDevicesChange(value,scope.row)}">
  55. <el-option v-for="item in associatedDevicesList" :key="item.id" :label="`名称:${item.tname} 编号:${item.eqcode}类型:${item.tclassname}`" :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.remark }}</span>
  62. <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;" />
  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. getDownListParm: {
  106. name: 'getTMRList', page: 1, offset: 1, pagecount: '', returntype: 'Map',
  107. parammaps: { pastureid: Cookies.get('pastureid'), eqtype: '1' }
  108. },
  109. table: {
  110. rules: {
  111. name: { type: 'string', required: true, message: '必填字段', trigger: 'change' }
  112. },
  113. getdataListParm: {
  114. name: 'getGps',
  115. page: 1,
  116. offset: 1,
  117. pagecount: parseInt(Cookies.get('pageCount')),
  118. returntype: 'Map',
  119. parammaps: {
  120. pastureid: Cookies.get('pastureid'),
  121. gpsCode: '',
  122. tclassname: '',
  123. enable: '',
  124. eqtype: '1'
  125. }
  126. },
  127. tableKey: 0,
  128. list: [],
  129. total: 0,
  130. listLoading: true,
  131. temp: {}
  132. },
  133. requestParam: {},
  134. isokDisable: false,
  135. selectList: [],
  136. rowStyle: { maxHeight: 30 + 'px', height: 30 + 'px' },
  137. cellStyle: { padding: 0 + 'px' }
  138. }
  139. },
  140. created() {
  141. this.getDownList()
  142. this.getList()
  143. this.getButtons()
  144. },
  145. methods: {
  146. getButtons() {
  147. const Edit = 'ForkliftManagement'
  148. const isRoleEdit = checkButtons(JSON.parse(sessionStorage.getItem('buttons')), Edit)
  149. this.isRoleEdit = isRoleEdit
  150. },
  151. getDownList() {
  152. GetDataByName(this.getDownListParm).then(response => {
  153. if (response.data.list !== null) {
  154. this.associatedDevicesList = response.data.list
  155. } else {
  156. this.associatedDevicesList = []
  157. }
  158. })
  159. },
  160. getList() {
  161. this.table.listLoading = true
  162. GetDataByName(this.table.getdataListParm).then(response => {
  163. // console.log('table数据', response.data.list)
  164. if (response.data !== null && response.data.list !== null) {
  165. for (let i = 0; i < response.data.list.length; i++) {
  166. this.$set(response.data.list[i], 'Edit', false) // 编辑
  167. this.$set(response.data.list[i], 'NoEdit', true) // 不可编辑/输入
  168. this.$set(response.data.list[i], 'isCreate', false) // 新增操作
  169. this.$set(response.data.list[i], 'isUpdate', true) // 编辑操作
  170. this.$set(response.data.list[i], 'isUpdateSave', false) // 编辑保存
  171. }
  172. this.table.list = response.data.list
  173. this.table.pageNum = response.data.pageNum
  174. this.table.pageSize = response.data.pageSize
  175. this.table.total = response.data.total
  176. } else {
  177. this.table.list = []
  178. }
  179. this.table.total = this.table.list.length
  180. setTimeout(() => {
  181. this.table.listLoading = false
  182. }, 100)
  183. })
  184. },
  185. handleEnableChange() {
  186. console.log('点击了是否启用')
  187. },
  188. handleSearch() {
  189. console.log('点击了查询')
  190. this.table.getdataListParm.offset = 1
  191. this.getList()
  192. },
  193. handleRefresh() {
  194. console.log('点击了重置')
  195. this.table.getdataListParm.parammaps.gpsCode = ''
  196. this.table.getdataListParm.parammaps.gpsName = ''
  197. this.table.getdataListParm.parammaps.enable = ''
  198. this.table.getdataListParm.offset = 1
  199. this.getList()
  200. },
  201. handleAssociatedDevicesChange(item, row) {
  202. row.associatedDevices = this.associatedDevicesList.find(obj => obj.id === item).name
  203. },
  204. handleCreate() {
  205. console.log('点击了新增')
  206. // 编辑true/不可编辑false
  207. // 新增操true,编辑false,编辑保存false
  208. for (let i = 0; i < this.table.list.length; i++) {
  209. if (this.table.list[i].Edit == true) {
  210. this.$message({ type: 'error', message: '当前内容未保存,请点击取消或保存继续进行操作', duration: 2000 })
  211. return false
  212. }
  213. }
  214. this.table.list.unshift({ 'myId': (new Date()).valueOf(), 'Edit': true, 'NoEdit': false, 'isCreate': true, 'isUpdate': false, 'isUpdateSave': false, 'enable': 1, 'gpsCode': '', 'gpsName': '', 'tmrId': '', 'remark': '' })
  215. },
  216. createData(row) {
  217. console.log('点击了新增保存')
  218. this.table.temp.pastureid = Cookies.get('pastureid')
  219. this.table.temp.gpsCode = row.gpsCode
  220. this.table.temp.gpsName = row.gpsName
  221. this.table.temp.tmrId = row.tmrId
  222. this.table.temp.enable = row.enable
  223. this.table.temp.remark = row.remark
  224. // 检验GPS编号/GPS名称是否为空
  225. if (this.table.temp.gpsCode == '' && this.table.temp.gpsName == '') {
  226. this.$message({ type: 'error', message: 'GPS编号/GPS名称不能为空', duration: 2000 })
  227. return false
  228. } else if (this.table.temp.gpsCode == '' && this.table.temp.datacaptureno == '') {
  229. this.$message({ type: 'error', message: 'GPS编号不能为空', duration: 2000 })
  230. return false
  231. } else if (this.table.temp.gpsName == '') {
  232. this.$message({ type: 'error', message: 'GPS名称不能为空', duration: 2000 })
  233. return false
  234. }
  235. const pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~!@#¥……&*()——|{}【】‘;:”“'。,、?]")
  236. console.log(this.table.temp.gpsCode)
  237. if (pattern.test(this.table.temp.gpsCode)) {
  238. this.$message({ type: 'error', message: 'GPS编号不可输入特殊字符', duration: 2000 })
  239. return false
  240. }
  241. if (pattern.test(this.table.temp.tname)) {
  242. this.$message({ type: 'error', message: 'GPS名称不可输入特殊字符', duration: 2000 })
  243. return false
  244. }
  245. this.isokDisable = true
  246. setTimeout(() => {
  247. this.isokDisable = false
  248. }, 1000)
  249. this.requestParam.name = 'insertGps'
  250. this.requestParam.parammaps = this.table.temp
  251. PostDataByName(this.requestParam).then(response => {
  252. console.log('新增保存发送参数', this.requestParam)
  253. if (response.msg !== 'fail') {
  254. this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
  255. this.getList()
  256. } else {
  257. this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
  258. }
  259. })
  260. },
  261. createCancel(row) {
  262. console.log('点击了新增取消')
  263. for (let i = 0; i < this.table.list.length; i++) {
  264. if (row.myId === this.table.list[i].myId) {
  265. var listIndex = this.table.list.indexOf(this.table.list[i])
  266. }
  267. if (listIndex > -1) {
  268. this.table.list.splice(listIndex, 1)
  269. return
  270. }
  271. }
  272. },
  273. handleUpdate(row) {
  274. for (let i = 0; i < this.table.list.length; i++) {
  275. if (this.table.list[i].Edit == true) {
  276. this.$message({ type: 'error', message: '当前内容未保存,请点击取消或保存继续进行操作', duration: 2000 })
  277. return false
  278. }
  279. }
  280. // 编辑true,不可编辑false
  281. row.Edit = true
  282. row.NoEdit = false
  283. // 新增false,编辑false,编辑保存true
  284. row.isCreate = false
  285. row.isUpdate = false
  286. row.isUpdateSave = true
  287. },
  288. updateData(row) {
  289. console.log('点击了编辑保存')
  290. this.table.temp.gpsCode = row.gpsCode
  291. this.table.temp.gpsName = row.gpsName
  292. this.table.temp.tmrId = row.tmrId
  293. this.table.temp.enable = row.enable
  294. this.table.temp.remark = row.remark
  295. this.table.temp.id = row.id
  296. if (this.table.temp.gpsCode == '' && this.table.temp.gpsName == '') {
  297. this.$message({ type: 'error', message: 'GPS编号/GPS名称不能为空', duration: 2000 })
  298. return false
  299. } else if (this.table.temp.gpsCode == '' && this.table.temp.datacaptureno == '') {
  300. this.$message({ type: 'error', message: 'GPS编号不能为空', duration: 2000 })
  301. return false
  302. } else if (this.table.temp.gpsName == '') {
  303. this.$message({ type: 'error', message: 'GPS名称不能为空', duration: 2000 })
  304. return false
  305. }
  306. const pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~!@#¥……&*()——|{}【】‘;:”“'。,、?]")
  307. console.log(this.table.temp.gpsCode)
  308. if (pattern.test(this.table.temp.gpsCode)) {
  309. this.$message({ type: 'error', message: 'GPS编号不可输入特殊字符', duration: 2000 })
  310. return false
  311. }
  312. if (pattern.test(this.table.temp.tname)) {
  313. this.$message({ type: 'error', message: 'GPS名称不可输入特殊字符', duration: 2000 })
  314. return false
  315. }
  316. this.isokDisable = true
  317. setTimeout(() => {
  318. this.isokDisable = false
  319. }, 1000)
  320. this.requestParam.name = 'updateGps'
  321. this.requestParam.parammaps = this.table.temp
  322. PostDataByName(this.requestParam).then(response => {
  323. console.log('新增保存发送参数', this.requestParam)
  324. if (response.msg !== 'fail') {
  325. this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
  326. this.getList()
  327. } else {
  328. this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
  329. }
  330. })
  331. },
  332. updateCancel(row) {
  333. console.log('点击了编辑取消')
  334. // 编辑false,不可编辑true
  335. row.Edit = false
  336. row.NoEdit = true
  337. // 新增false,编辑true,编辑保存false
  338. row.isCreate = false
  339. row.isUpdate = true
  340. row.isUpdateSave = false
  341. this.getList()
  342. },
  343. handleRowDelete(row) {
  344. console.log('点击了行内删除')
  345. MessageBox.confirm('是否确认删除此信息?', {
  346. confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
  347. }).then(() => {
  348. this.selectList = []
  349. this.requestParam = {}
  350. this.requestParam.name = 'deleteGps'
  351. this.requestParam.parammaps = {}
  352. // this.requestParam.parammaps.pastureid = row.pastureid
  353. this.requestParam.parammaps.id = row.id
  354. PostDataByName(this.requestParam).then(response => {
  355. if (response.msg === 'fail') {
  356. this.$notify({ title: '删除失败', message: response.data, type: 'warning', duration: 2000 })
  357. } else {
  358. this.$notify({ title: '成功', message: '删除成功', type: 'success', duration: 2000 })
  359. this.getList()
  360. }
  361. })
  362. }).catch(() => {
  363. this.$message({ type: 'info', message: '已取消删除' })
  364. })
  365. },
  366. handleSelectionChange(val) {
  367. console.log('勾选数据', val)
  368. this.selectList = val
  369. },
  370. handleDelete() {
  371. console.log('点击了删除')
  372. if (this.selectList.length == 0) {
  373. this.$message({ type: 'error', message: '请选择信息', duration: 2000 })
  374. } else {
  375. MessageBox.confirm('当前选中' + this.selectList.length + '条信息,是否删除?', {
  376. confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
  377. }).then(() => {
  378. console.log(this.selectList)
  379. this.requestParam.common = { 'returnmap': '0' }
  380. this.requestParam.data = []
  381. this.requestParam.data[0] = { 'name': 'insertSpotList', 'resultmaps': { 'list': this.selectList }}
  382. this.requestParam.data[0].children = []
  383. this.requestParam.data[0].children[0] = { 'name': 'deleteGps', 'type': 'e', 'parammaps': {
  384. id: '@insertSpotList.id'
  385. // pastureid: '@insertSpotList.pastureid'
  386. }}
  387. ExecDataByConfig(this.requestParam).then(response => {
  388. console.log('删除保存发送参数', this.requestParam)
  389. if (response.msg === 'fail') {
  390. this.$notify({ title: '删除失败', message: response.data, type: 'warning', duration: 2000 })
  391. } else {
  392. this.$notify({ title: '', message: '删除成功', type: 'success', duration: 2000 })
  393. this.getList()
  394. }
  395. })
  396. })
  397. }
  398. }
  399. }
  400. }
  401. </script>
  402. <style lang="scss" scoped>
  403. .search{margin-top:10px;}
  404. .table{margin-top:10px;}
  405. </style>