index.vue 18 KB

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