6281f20f92bbc702a14701d55a0edbf8471e35d4.svn-base 19 KB

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