da2ba3cc9bc5a14b373ac17d1874ad2c34c2946f.svn-base 18 KB

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