index.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. <template>
  2. <div class="app-container">
  3. <div class="search">
  4. <el-input v-model="table.getdataListParm.parammaps.Code" :placeholder="$t('driver.sbcode')" style="width: 180px;" class="filter-item" clearable />
  5. <el-input v-model="table.getdataListParm.parammaps.name" :placeholder="$t('driver.sbname')" 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="$t('driver.sbtype')" 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="$t('driver.sbcode')" 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"
  51. :placeholder="$t('supplier.zf1')" type="textarea" :autosize="{ minRows: 1.3, maxRows: 4}" maxlength="32" style="width:80%;padding:10px 0;" />
  52. </template>
  53. </el-table-column>
  54. <el-table-column :label="$t('driver.sbname')" min-width="110px" align="center">
  55. <template slot-scope="scope">
  56. <span v-if="scope.row.NoEdit">{{ scope.row.name }}</span>
  57. <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" />
  58. </template>
  59. </el-table-column>
  60. <el-table-column :label="$t('driver.sjcjkbh')" min-width="110px" align="center">
  61. <template slot-scope="scope">
  62. <span v-if="scope.row.NoEdit">{{ scope.row.infoCode }}</span>
  63. <el-input v-if="scope.row.Edit" v-model="scope.row.infoCode" type="number" step="0.01" style="width:80%;padding:10px 0;" />
  64. </template>
  65. </el-table-column>
  66. <el-table-column :label="$t('formulationEvaluation.remark')" min-width="110px" align="center">
  67. <template slot-scope="scope">
  68. <span v-if="scope.row.NoEdit">{{ scope.row.remark }}</span>
  69. <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;" />
  70. </template>
  71. </el-table-column>
  72. <el-table-column :label="$t('formulationEvaluation.sfqy')" min-width="110px" align="center">
  73. <template slot-scope="scope">
  74. <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)" />
  75. </template>
  76. </el-table-column>
  77. <el-table-column :label="$t('errorAnalysis.cz')" align="center" width="80" class-name="small-padding fixed-width" fixed="right">
  78. <template slot-scope="{row}">
  79. <!-- 新增 -->
  80. <el-button v-if="row.isCreate" :disabled="isokDisable" icon="el-icon-folder-checked" class="miniSuccess" @click="createData(row)" />
  81. <span v-if="row.isCreate" class="centerSpan">|</span>
  82. <el-button v-if="row.isCreate" class="minCancel" icon="el-icon-close" @click="createCancel(row)" />
  83. <!-- 编辑 -->
  84. <el-button v-if="row.isUpdate && isRoleEdit" class="miniSuccess" icon="el-icon-edit-outline" @click="handleUpdate(row)" />
  85. <span v-if="row.isUpdate && isRoleEdit" class="centerSpan">|</span>
  86. <el-button v-if="row.isUpdate && isRoleEdit" class="miniDanger" icon="el-icon-delete" @click="handleRowDelete(row)" />
  87. <!-- 编辑保存 -->
  88. <el-button v-if="row.isUpdateSave" :disabled="isokDisable" icon="el-icon-folder-checked" class="miniSuccess" @click="updateData(row)" />
  89. <span v-if="row.isUpdateSave" class="centerSpan">|</span>
  90. <el-button v-if="row.isUpdateSave" class="minCancel" icon="el-icon-close" @click="updateCancel(row)" />
  91. </template>
  92. </el-table-column>
  93. </el-table>
  94. </el-form>
  95. <pagination v-show="table.total>=0" :total="table.total" :page.sync="table.getdataListParm.offset" :limit.sync="table.getdataListParm.pagecount" @pagination="getList" />
  96. </div>
  97. </div>
  98. </template>
  99. <script>
  100. import { GetDataByName, PostDataByName, failproccess, ExecDataByConfig, checkButtons } from '@/api/common'
  101. import Cookies from 'js-cookie'
  102. import Pagination from '@/components/Pagination'
  103. import { MessageBox } from 'element-ui'
  104. export default {
  105. name: 'ForkliftManagement',
  106. components: { Pagination },
  107. data() {
  108. return {
  109. isRoleEdit: [],
  110. enableList: this.$t('driver.enableList'),
  111. equipmentTypeList: this.$t('driver.equipmentTypeList'),
  112. getdownListParm: {
  113. name: 'getDictByName',
  114. page: 1,
  115. offset: 1,
  116. pagecount: '',
  117. returntype: 'Map',
  118. parammaps: {
  119. dictname: '其他设备管理'
  120. }
  121. },
  122. table: {
  123. rules: {
  124. name: { type: 'string', required: true, message: '必填字段', trigger: 'change' }
  125. },
  126. getdataListParm: {
  127. name: 'getTmrEquipment',
  128. page: 1,
  129. offset: 1,
  130. pagecount: parseInt(Cookies.get('pageCount')),
  131. returntype: 'Map',
  132. parammaps: {
  133. pastureId: Cookies.get('pastureid'),
  134. Code: '',
  135. tclassname: '',
  136. enable: ''
  137. }
  138. },
  139. tableKey: 0,
  140. list: [],
  141. total: 0,
  142. listLoading: true,
  143. temp: {}
  144. },
  145. requestParam: {},
  146. isokDisable: false,
  147. selectList: [],
  148. rowStyle: { maxHeight: 30 + 'px', height: 30 + 'px' },
  149. cellStyle: { padding: 0 + 'px' }
  150. }
  151. },
  152. created() {
  153. this.getList()
  154. this.getButtons()
  155. this.getDownList()
  156. },
  157. methods: {
  158. getDownList() {
  159. GetDataByName(this.getdownListParm).then(response => {
  160. this.equipmentTypeList = response.data.list
  161. })
  162. },
  163. getButtons() {
  164. const Edit = 'ForkliftManagement'
  165. const isRoleEdit = checkButtons(JSON.parse(sessionStorage.getItem('buttons')), Edit)
  166. this.isRoleEdit = isRoleEdit
  167. },
  168. getList() {
  169. this.table.listLoading = true
  170. GetDataByName(this.table.getdataListParm).then(response => {
  171. if (response.data && 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. } else {
  183. this.table.list = []
  184. }
  185. this.table.total = response.data.total
  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. form_search() {
  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: this.$t('driver.messageNote'), 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: this.$t('common.succes'), message: this.$t('driver.saveSuccess'), 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: this.$t('driver.saveFail'), 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: this.$t('driver.messageNote'), 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: this.$t('common.succes'), message: this.$t('driver.saveSuccess'), 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: this.$t('driver.saveFail'), 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( this.$t('common.delMsg'), {
  410. confirmButtonText: this.$t('common.confirm'), confirmButtonText: this.$t('common.cancel'), 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: this.$t('common.delfail'), message: response.data, type: 'warning', duration: 2000 })
  420. } else {
  421. this.$notify({ title: this.$t('common.succes'),message: this.$t('common.delSuccess'), type: 'success', duration: 2000 })
  422. this.getList()
  423. }
  424. })
  425. }).catch(() => {
  426. this.$message({ type: 'info', message: this.$t('common.cancelMsg') })
  427. })
  428. },
  429. handleSelectionChange(val) {
  430. console.log('勾选数据', val)
  431. this.selectList = val
  432. },
  433. form_delete() {
  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: this.$t('common.confirm'), confirmButtonText: this.$t('common.cancel'), 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: this.$t('common.delfail'), message: response.data, type: 'warning', duration: 2000 })
  454. } else {
  455. this.$notify({ title: '',message: this.$t('common.delSuccess'), 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. </style>