a49ffe25e888f8c58bde75ff3e54fd532b324472.svn-base 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  1. <template>
  2. <div class="app-container">
  3. <div class="operation">
  4. <el-button class="success" @click="handleCreate">新增</el-button>
  5. <el-button class="danger" @click="handleDelete">删除</el-button>
  6. </div>
  7. <div class="search">
  8. <el-input v-model="table.getdataListParm.parammaps.eqcode" placeholder="TMR设备编号" style="width: 180px;" class="filter-item" clearable />
  9. <el-select v-model="table.getdataListParm.parammaps.classname" filterable placeholder="TMR设备类型" class="filter-item" style="width: 140px;" clearable>
  10. <el-option v-for="item in typeList" :key="item.id" :label="item.label" :value="item.label" />
  11. </el-select>
  12. <el-select v-model="table.getdataListParm.parammaps.enable" filterable placeholder="是否启用" class="filter-item" style="width: 120px;" clearable>
  13. <el-option v-for="item in enableList" :key="item.id" :label="item.name" :value="item.id" />
  14. </el-select>
  15. <el-button class="successBorder" @click="handleSearch">查询</el-button>
  16. <el-button class="successBorder" @click="handleRefresh">重置</el-button>
  17. </div>
  18. <div class="table">
  19. <el-table
  20. :key="table.tableKey"
  21. v-loading="table.listLoading"
  22. element-loading-text="给我一点时间"
  23. :data="table.list"
  24. border
  25. fit
  26. highlight-current-row
  27. style="width: 100%;"
  28. :row-style="rowStyle"
  29. :cell-style="cellStyle"
  30. class="elTable table-fixed"
  31. @selection-change="handleSelectionChange"
  32. >
  33. <el-table-column type="selection" align="center" width="50" />
  34. <el-table-column label="序号" align="center" type="index" width="50px">
  35. <template slot-scope="scope">
  36. <span>{{ scope.$index + (table.pageNum-1) * table.pageSize + 1 }}</span>
  37. </template>
  38. </el-table-column>
  39. <el-table-column label="TMR设备编号" min-width="150px" align="center">
  40. <template slot-scope="scope">
  41. <span v-if="scope.row.NoEdit">{{ scope.row.eqcode }}</span>
  42. <el-input v-if="scope.row.Edit" v-model="scope.row.eqcode" type="textarea" :autosize="{ minRows: 1.3, maxRows: 4}" style="width:95%;padding:10px 0;" maxlength="32" />
  43. </template>
  44. </el-table-column>
  45. <el-table-column label="TMR设备名称" min-width="150px" align="center">
  46. <template slot-scope="scope">
  47. <span v-if="scope.row.NoEdit">{{ scope.row.tname }}</span>
  48. <el-input v-if="scope.row.Edit" v-model="scope.row.tname" type="textarea" :autosize="{ minRows: 1.3, maxRows: 4}" style="width:95%;padding:10px 0;" maxlength="32" />
  49. </template>
  50. </el-table-column>
  51. <el-table-column label="数据采集卡编号" min-width="150px" align="center">
  52. <template slot-scope="scope">
  53. <span v-if="scope.row.NoEdit">{{ scope.row.datacaptureno }}</span>
  54. <el-input v-if="scope.row.Edit" v-model="scope.row.datacaptureno" type="textarea" :autosize="{ minRows: 1.3, maxRows: 4}" style="width:95%;padding:10px 0;" />
  55. </template>
  56. </el-table-column>
  57. <el-table-column label="TMR设备类型" min-width="200px" align="center">
  58. <template slot-scope="scope">
  59. <span v-if="scope.row.NoEdit">{{ scope.row.tclassname }}</span>
  60. <el-select v-if="scope.row.Edit" v-model="scope.row.tclassid" filterable placeholder="TMR设备类型" class="filter-item" style="width:95%;padding:10px 0;" @change="changeType">
  61. <el-option v-for="item in typeList" :key="item.id" :label="item.label" :value="item.value" />
  62. </el-select>
  63. </template>
  64. </el-table-column>
  65. <el-table-column label="最大搅拌量(KG)" min-width="150px" align="center">
  66. <template slot-scope="scope">
  67. <span v-if="scope.row.NoEdit">{{ scope.row.maxstirfeed }}</span>
  68. <el-input v-if="scope.row.Edit" v-model="scope.row.maxstirfeed" style="width: 80%;" />
  69. </template>
  70. </el-table-column>
  71. <el-table-column label="备注" min-width="110px" align="center">
  72. <template slot-scope="scope">
  73. <span v-if="scope.row.NoEdit">{{ scope.row.remark }}</span>
  74. <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;" />
  75. </template>
  76. </el-table-column>
  77. <el-table-column label="是否启用" min-width="110px" align="center">
  78. <template slot-scope="scope">
  79. <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)" />
  80. </template>
  81. </el-table-column>
  82. <el-table-column label="操作" align="center" width="250" class-name="small-padding fixed-width" fixed="right">
  83. <template slot-scope="{row}">
  84. <!-- 新增 -->
  85. <el-button v-if="row.isCreate" :disabled="isokDisable" class="miniSuccess" @click="createData(row)">保存</el-button>
  86. <el-button v-if="row.isCreate" class="minCancel" @click="createCancel(row)">取消</el-button>
  87. <!-- 编辑 -->
  88. <el-button v-if="row.isUpdate" class="miniSuccess" @click="handleUpdate(row)">编辑</el-button>
  89. <el-button v-if="row.isUpdate" class="miniDanger" @click="handleRowDelete(row)">删除</el-button>
  90. <!-- 编辑保存 -->
  91. <el-button v-if="row.isUpdateSave" :disabled="isokDisable" class="miniSuccess" @click="updateData(row)">保存</el-button>
  92. <el-button v-if="row.isUpdateSave" class="minCancel" @click="updateCancel(row)">取消</el-button>
  93. </template>
  94. </el-table-column>
  95. </el-table>
  96. <pagination v-show="table.total>=0" :total="table.total" :page.sync="table.getdataListParm.offset" :limit.sync="table.getdataListParm.pagecount" @pagination="getList" />
  97. </div>
  98. </div>
  99. </template>
  100. <script>
  101. import { GetDataByName, PostDataByName, failproccess, ExecDataByConfig, GetDataByNames } from '@/api/common'
  102. import Cookies from 'js-cookie'
  103. import Pagination from '@/components/Pagination'
  104. import { MessageBox } from 'element-ui'
  105. export default {
  106. name: 'EquipmentTMR',
  107. components: { Pagination },
  108. data() {
  109. return {
  110. requestParams: [
  111. { name: 'getDictByName', offset: 0, pagecount: 0, params: ['TMR设备类型'] }
  112. ],
  113. typeList: [], // TMR设备类型
  114. enableList: [{ id: 1, name: '是' }, { id: 0, name: '否' }], // 是否启用
  115. table: {
  116. getdataListParm: {
  117. name: 'getTMRList',
  118. page: 1,
  119. offset: 1,
  120. pagecount: 10,
  121. returntype: 'Map',
  122. parammaps: {
  123. pastureid: Cookies.get('pastureid'),
  124. eqcode: '',
  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: 50 + 'px', height: 45 + 'px' },
  140. cellStyle: { padding: 0 + 'px' }
  141. }
  142. },
  143. created() {
  144. this.getList()
  145. this.getDownList()
  146. },
  147. methods: {
  148. getDownList() {
  149. GetDataByNames(this.requestParams).then(response => {
  150. this.typeList = response.data.getDictByName.list
  151. })
  152. },
  153. getList() {
  154. this.table.listLoading = true
  155. GetDataByName(this.table.getdataListParm).then(response => {
  156. console.log('table数据', response.data.list)
  157. if (response.data.list !== null) {
  158. for (let i = 0; i < response.data.list.length; i++) {
  159. this.$set(response.data.list[i], 'Edit', false) // 编辑
  160. this.$set(response.data.list[i], 'NoEdit', true) // 不可编辑/输入
  161. this.$set(response.data.list[i], 'isCreate', false) // 新增操作
  162. this.$set(response.data.list[i], 'isUpdate', true) // 编辑操作
  163. this.$set(response.data.list[i], 'isUpdateSave', false) // 编辑保存
  164. }
  165. this.table.list = response.data.list
  166. this.table.pageNum = response.data.pageNum
  167. this.table.pageSize = response.data.pageSize
  168. this.table.total = response.data.total
  169. } else {
  170. this.table.list = []
  171. }
  172. setTimeout(() => {
  173. this.table.listLoading = false
  174. }, 100)
  175. })
  176. },
  177. handleEnableChange() {
  178. console.log('点击了是否启用')
  179. },
  180. handleSearch() {
  181. console.log('点击了查询')
  182. this.table.getdataListParm.offset = 1
  183. this.getList()
  184. },
  185. handleRefresh() {
  186. console.log('点击了重置')
  187. this.table.getdataListParm.parammaps.eqcode = ''
  188. this.table.getdataListParm.parammaps.tclassname = ''
  189. this.table.getdataListParm.parammaps.enable = ''
  190. this.table.getdataListParm.parammaps.eqtype = '1'
  191. this.table.getdataListParm.offset = 1
  192. this.getList()
  193. },
  194. handleCreate() {
  195. console.log('点击了新增')
  196. // 编辑true/不可编辑false
  197. // 新增操true,编辑false,编辑保存false
  198. for (let i = 0; i < this.table.list.length; i++) {
  199. if (this.table.list[i].Edit == true) {
  200. this.$message({ type: 'error', message: '当前内容未保存,请点击取消或保存继续进行操作', duration: 2000 })
  201. return false
  202. }
  203. }
  204. this.table.list.unshift({ 'myId': (new Date()).valueOf(), 'Edit': true, 'NoEdit': false, 'isCreate': true, 'isUpdate': false, 'isUpdateSave': false, 'enable': 1, 'eqcode': '', 'tname': '', 'datacaptureno': '', 'tclassid': '', 'maxstirfeed': '' })
  205. },
  206. changeType(item) {
  207. this.table.temp.tclassname = this.typeList.find(obj => obj.value === item).label
  208. },
  209. createData(row) {
  210. console.log('点击了新增保存', row)
  211. this.table.temp.pastureid = Cookies.get('pastureid')
  212. this.table.temp.eqcode = row.eqcode
  213. this.table.temp.tname = row.tname
  214. this.table.temp.datacaptureno = row.datacaptureno
  215. this.table.temp.tclassid = row.tclassid
  216. this.table.temp.tclassname = this.table.temp.tclassname
  217. this.table.temp.maxstirfeed = row.maxstirfeed
  218. this.table.temp.enable = row.enable
  219. this.table.temp.remark = row.remark
  220. // 检验用户名称/角色是否为空
  221. if (this.table.temp.eqcode == '' && this.table.temp.tname == '' && this.table.temp.datacaptureno == '' && this.table.temp.tclassid == '' && this.table.temp.maxstirfeed == '') {
  222. this.$message({ type: 'error', message: 'TMR设备编号/TMR设备名称/数据采集卡编号/TMR设备类型/最大搅拌量不能为空', duration: 2000 })
  223. return false
  224. } else if (this.table.temp.tname == '' && this.table.temp.datacaptureno == '' && this.table.temp.tclassid == '' && this.table.temp.maxstirfeed == '') {
  225. this.$message({ type: 'error', message: 'TMR设备名称/数据采集卡编号/TMR设备类型/最大搅拌量不能为空', duration: 2000 })
  226. return false
  227. } else if (this.table.temp.datacaptureno == '' && this.table.temp.tclassid == '' && this.table.temp.maxstirfeed == '') {
  228. this.$message({ type: 'error', message: '数据采集卡编号/TMR设备类型/最大搅拌量不能为空', duration: 2000 })
  229. return false
  230. } else if (this.table.temp.tclassid == '' && this.table.temp.maxstirfeed == '') {
  231. this.$message({ type: 'error', message: 'TMR设备类型/最大搅拌量不能为空', duration: 2000 })
  232. return false
  233. } else if (this.table.temp.eqcode == '') {
  234. this.$message({ type: 'error', message: 'TMR设备编号不能为空', duration: 2000 })
  235. return false
  236. } else if (this.table.temp.tname == '') {
  237. this.$message({ type: 'error', message: 'TMR设备名称不能为空', duration: 2000 })
  238. return false
  239. } else if (this.table.temp.datacaptureno == '') {
  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.maxstirfeed == '') {
  246. this.$message({ type: 'error', message: '最大搅拌量不能为空', duration: 2000 })
  247. return false
  248. }
  249. const datacaptureno = /^([0-9]|(1[0-5]))$/
  250. if (!datacaptureno.test(parseFloat(this.table.temp.datacaptureno))) {
  251. this.$message({ type: 'error', message: '数据采集卡请输入0-15之间整数', duration: 2000 })
  252. return false
  253. }
  254. const maxstirfeed = /^[1-9]\d*$/
  255. if (!maxstirfeed.test(parseFloat(this.table.temp.maxstirfeed))) {
  256. this.$message({ type: 'error', message: '最大搅拌量请输入正整数', duration: 2000 })
  257. return false
  258. }
  259. const pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~!@#¥……&*()——|{}【】‘;:”“'。,、?]")
  260. if (pattern.test(this.table.temp.eqcode)) {
  261. this.$message({ type: 'error', message: 'TMR设备编号不可输入特殊字符', duration: 2000 })
  262. return false
  263. }
  264. if (pattern.test(this.table.temp.tname)) {
  265. this.$message({ type: 'error', message: 'TMR设备名称不可输入特殊字符', duration: 2000 })
  266. return false
  267. }
  268. this.isokDisable = true
  269. setTimeout(() => {
  270. this.isokDisable = false
  271. }, 1000)
  272. this.requestParam.name = 'insertTMR'
  273. this.requestParam.parammaps = this.table.temp
  274. PostDataByName(this.requestParam).then(response => {
  275. console.log('新增保存发送参数', this.requestParam)
  276. if (response.msg !== 'fail') {
  277. this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
  278. this.getList()
  279. } else {
  280. failproccess(response, this.$notify)
  281. }
  282. })
  283. },
  284. createCancel(row) {
  285. console.log('点击了新增取消')
  286. for (let i = 0; i < this.table.list.length; i++) {
  287. if (row.myId === this.table.list[i].myId) {
  288. var listIndex = this.table.list.indexOf(this.table.list[i])
  289. }
  290. if (listIndex > -1) {
  291. this.table.list.splice(listIndex, 1)
  292. return
  293. }
  294. }
  295. },
  296. handleUpdate(row) {
  297. for (let i = 0; i < this.table.list.length; i++) {
  298. if (this.table.list[i].Edit == true) {
  299. this.$message({ type: 'error', message: '当前内容未保存,请点击取消或保存继续进行操作', duration: 2000 })
  300. return false
  301. }
  302. }
  303. // 编辑true,不可编辑false
  304. row.Edit = true
  305. row.NoEdit = false
  306. // 新增false,编辑false,编辑保存true
  307. row.isCreate = false
  308. row.isUpdate = false
  309. row.isUpdateSave = true
  310. row.tclassid = String(row.tclassid)
  311. this.table.temp.tclassid = row.tclassid
  312. this.table.temp.tclassname = row.tclassname
  313. },
  314. updateData(row) {
  315. console.log('点击了编辑保存', row)
  316. this.table.temp.pastureid = Cookies.get('pastureid')
  317. this.table.temp.eqcode = row.eqcode
  318. this.table.temp.tname = row.tname
  319. this.table.temp.datacaptureno = row.datacaptureno
  320. this.table.temp.tclassid = row.tclassid
  321. this.table.temp.tclassname = this.table.temp.tclassname
  322. this.table.temp.maxstirfeed = row.maxstirfeed
  323. this.table.temp.enable = row.enable
  324. this.table.temp.remark = row.remark
  325. this.table.temp.id = row.id
  326. // 检验用户名称/角色是否为空
  327. if (this.table.temp.eqcode == '' && this.table.temp.tname == '' && this.table.temp.datacaptureno == '' && this.table.temp.tclassid == '' && this.table.temp.maxstirfeed == '') {
  328. this.$message({ type: 'error', message: 'TMR设备编号/TMR设备名称/数据采集卡编号/TMR设备类型/最大搅拌量不能为空', duration: 2000 })
  329. return false
  330. } else if (this.table.temp.tname == '' && this.table.temp.datacaptureno == '' && this.table.temp.tclassid == '' && this.table.temp.maxstirfeed == '') {
  331. this.$message({ type: 'error', message: 'TMR设备名称/数据采集卡编号/TMR设备类型/最大搅拌量不能为空', duration: 2000 })
  332. return false
  333. } else if (this.table.temp.datacaptureno == '' && this.table.temp.tclassid == '' && this.table.temp.maxstirfeed == '') {
  334. this.$message({ type: 'error', message: '数据采集卡编号/TMR设备类型/最大搅拌量不能为空', duration: 2000 })
  335. return false
  336. } else if (this.table.temp.tclassid == '' && this.table.temp.maxstirfeed == '') {
  337. this.$message({ type: 'error', message: 'TMR设备类型/最大搅拌量不能为空', duration: 2000 })
  338. return false
  339. } else if (this.table.temp.eqcode == '') {
  340. this.$message({ type: 'error', message: 'TMR设备编号不能为空', duration: 2000 })
  341. return false
  342. } else if (this.table.temp.tname == '') {
  343. this.$message({ type: 'error', message: '设备名称不能为空', duration: 2000 })
  344. return false
  345. } else if (this.table.temp.datacaptureno == '') {
  346. this.$message({ type: 'error', message: '数据采集卡编号不能为空', duration: 2000 })
  347. return false
  348. } else if (this.table.temp.tclassid == '') {
  349. this.$message({ type: 'error', message: '设备类型不能为空', duration: 2000 })
  350. return false
  351. } else if (this.table.temp.maxstirfeed == '') {
  352. this.$message({ type: 'error', message: '最大搅拌量不能为空', duration: 2000 })
  353. return false
  354. }
  355. const datacaptureno = /^([0-9]|(1[0-5]))$/
  356. if (!datacaptureno.test(parseInt(this.table.temp.datacaptureno))) {
  357. this.$message({ type: 'error', message: '数据采集卡请输入0-15之间整数', duration: 2000 })
  358. return false
  359. }
  360. const maxstirfeed = /^[1-9]\d*$/
  361. if (!maxstirfeed.test(parseInt(this.table.temp.maxstirfeed))) {
  362. this.$message({ type: 'error', message: '最大搅拌量请输入正整数', duration: 2000 })
  363. return false
  364. }
  365. const pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~!@#¥……&*()——|{}【】‘;:”“'。,、?]")
  366. if (pattern.test(this.table.temp.eqcode)) {
  367. this.$message({ type: 'error', message: 'TMR设备编号不可输入特殊字符', duration: 2000 })
  368. return false
  369. }
  370. if (pattern.test(this.table.temp.tname)) {
  371. this.$message({ type: 'error', message: 'TMR设备名称不可输入特殊字符', duration: 2000 })
  372. return false
  373. }
  374. this.isokDisable = true
  375. setTimeout(() => {
  376. this.isokDisable = false
  377. }, 1000)
  378. this.requestParam.name = 'updateTMR'
  379. this.requestParam.parammaps = this.table.temp
  380. PostDataByName(this.requestParam).then(response => {
  381. console.log('新增保存发送参数', this.requestParam)
  382. if (response.msg !== 'fail') {
  383. this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
  384. this.getList()
  385. } else {
  386. failproccess(response, this.$notify)
  387. }
  388. })
  389. },
  390. updateCancel(row) {
  391. console.log('点击了编辑取消')
  392. // 编辑false,不可编辑true
  393. row.Edit = false
  394. row.NoEdit = true
  395. // 新增false,编辑true,编辑保存false
  396. row.isCreate = false
  397. row.isUpdate = true
  398. row.isUpdateSave = false
  399. },
  400. // 删除
  401. handleRowDelete(row) {
  402. console.log('点击了行内删除')
  403. MessageBox.confirm('是否确认删除此信息?', {
  404. confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
  405. }).then(() => {
  406. this.selectList = []
  407. this.requestParam.name = 'deleteTMR'
  408. this.requestParam.parammaps = {}
  409. this.requestParam.parammaps.pastureid = row.pastureid
  410. this.requestParam.parammaps.id = row.id
  411. PostDataByName(this.requestParam).then(response => {
  412. if (response.msg === 'fail') {
  413. this.$notify({ title: '删除失败', message: response.data, type: 'warning', duration: 2000 })
  414. } else {
  415. this.$notify({ title: '成功', message: '删除成功', type: 'success', duration: 2000 })
  416. this.getList()
  417. }
  418. })
  419. }).catch(() => {
  420. this.$message({ type: 'info', message: '已取消删除' })
  421. })
  422. },
  423. handleSelectionChange(val) {
  424. console.log('勾选数据', val)
  425. this.selectList = val
  426. },
  427. handleDelete() {
  428. console.log('点击了删除')
  429. if (this.selectList.length == 0) {
  430. this.$message({ type: 'error', message: '请选择TMR设备信息', duration: 2000 })
  431. } else {
  432. MessageBox.confirm('是否确认删除此信息?', {
  433. confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
  434. }).then(() => {
  435. console.log(this.selectList)
  436. this.requestParam.common = { 'returnmap': '0' }
  437. this.requestParam.data = []
  438. this.requestParam.data[0] = { 'name': 'insertSpotList', 'resultmaps': { 'list': this.selectList }}
  439. this.requestParam.data[0].children = []
  440. this.requestParam.data[0].children[0] = { 'name': 'deleteTMR', 'type': 'e', 'parammaps': {
  441. id: '@insertSpotList.id',
  442. pastureid: '@insertSpotList.pastureid'
  443. }}
  444. ExecDataByConfig(this.requestParam).then(response => {
  445. console.log('删除保存发送参数', this.requestParam)
  446. if (response.msg === 'fail') {
  447. this.$notify({ title: '删除失败', message: response.data, type: 'warning', duration: 2000 })
  448. } else {
  449. this.$notify({ title: '', message: '删除成功', type: 'success', duration: 2000 })
  450. this.getList()
  451. }
  452. })
  453. })
  454. }
  455. }
  456. }
  457. }
  458. </script>
  459. <style lang="scss" scoped>
  460. .search{margin-top:10px;}
  461. .table{margin-top:10px;}
  462. </style>