c351ac510b29f88fa1a9c68691e33750678c6ab4.svn-base 20 KB

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