47f3ae909173cd788459070f34352e26c9d79092.svn-base 19 KB

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