0286c29fd9d50d9a905157b0c57b929467e11bab.svn-base 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. <template>
  2. <div class="app-container">
  3. <div class="search">
  4. <el-select v-model="table.getdataListParm.parammaps.bigfeedclassname" filterable placeholder="饲料大类" class="filter-item" style="width: 120px;" clearable>
  5. <el-option v-for="item in feedCategoryList" :key="item.value" :label="item.label" :value="item.label" />
  6. </el-select>
  7. <el-input v-model="table.getdataListParm.parammaps.fcname" placeholder="饲料分类名称" style="width: 180px;" class="filter-item" clearable />
  8. <el-input v-model="table.getdataListParm.parammaps.fccode" placeholder="饲料分类编号" style="width: 180px;" class="filter-item" clearable />
  9. <el-select v-model="table.getdataListParm.parammaps.enable" filterable placeholder="是否启用" class="filter-item" style="width: 120px;" clearable>
  10. <el-option v-for="item in enableList" :key="item.id" :label="item.name" :value="item.id" />
  11. </el-select>
  12. <el-button class="successBorder" @click="handleSearch">查询</el-button>
  13. <el-button class="successBorder" @click="handleRefresh">重置</el-button>
  14. </div>
  15. <div class="operation">
  16. <el-button v-if="isRoleEdit" class="success" icon="el-icon-plus" @click="handleCreate">新增</el-button>
  17. <el-button v-if="isRoleEdit" class="danger" icon="el-icon-delete" @click="handleDelete">删除</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="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. <pagination v-show="table.total>=0" :total="table.total" :page.sync="table.getdataListParm.offset" :limit.sync="table.getdataListParm.pagecount" @pagination="getList" />
  84. </div>
  85. </div>
  86. </template>
  87. <script>
  88. import { GetDataByName, PostDataByName, failproccess, ExecDataByConfig, GetDataByNames, checkButtons } from '@/api/common'
  89. import Cookies from 'js-cookie'
  90. import Pagination from '@/components/Pagination'
  91. import { MessageBox } from 'element-ui'
  92. export default {
  93. name: 'FeedClassification',
  94. components: { Pagination },
  95. data() {
  96. return {
  97. isRoleEdit: [],
  98. requestParams: [
  99. { name: 'getDictByName', offset: 0, pagecount: 0, params: ['饲料大类'] }
  100. ],
  101. enableList: [{ id: 1, name: '是' }, { id: 0, name: '否' }],
  102. feedCategoryList: [],
  103. table: {
  104. getdataListParm: {
  105. name: 'getFeedclassList',
  106. page: 1,
  107. offset: 1,
  108. pagecount: parseInt(Cookies.get('pageCount')),
  109. returntype: 'Map',
  110. parammaps: {
  111. pastureid: Cookies.get('pastureid'),
  112. fccode: '',
  113. fcname: '',
  114. bigfeedclassname: '',
  115. enable: ''
  116. }
  117. },
  118. tableKey: 0,
  119. list: [],
  120. total: 0,
  121. listLoading: true,
  122. temp: {}
  123. },
  124. requestParam: {},
  125. isokDisable: false,
  126. selectList: [],
  127. rowStyle: { maxHeight: 30 + 'px', height: 30 + 'px' },
  128. cellStyle: { padding: 0 + 'px' }
  129. }
  130. },
  131. created() {
  132. this.getList()
  133. this.getDownList()
  134. this.getButtons()
  135. },
  136. methods: {
  137. getButtons() {
  138. const Edit = 'FeedClassification'
  139. const isRoleEdit = checkButtons(JSON.parse(sessionStorage.getItem('buttons')), Edit)
  140. this.isRoleEdit = isRoleEdit
  141. },
  142. getDownList() {
  143. GetDataByNames(this.requestParams).then(response => {
  144. this.feedCategoryList = response.data.getDictByName.list
  145. })
  146. },
  147. getList() {
  148. this.table.listLoading = true
  149. GetDataByName(this.table.getdataListParm).then(response => {
  150. console.log('table数据', response.data.list)
  151. if (response.data.list !== null) {
  152. for (let i = 0; i < response.data.list.length; i++) {
  153. this.$set(response.data.list[i], 'Edit', false) // 编辑
  154. this.$set(response.data.list[i], 'NoEdit', true) // 不可编辑/输入
  155. this.$set(response.data.list[i], 'isCreate', false) // 新增操作
  156. this.$set(response.data.list[i], 'isUpdate', true) // 编辑操作
  157. this.$set(response.data.list[i], 'isUpdateSave', false) // 编辑保存
  158. }
  159. this.table.list = response.data.list
  160. this.table.pageNum = response.data.pageNum
  161. this.table.pageSize = response.data.pageSize
  162. this.table.total = response.data.total
  163. } else {
  164. this.table.list = []
  165. }
  166. setTimeout(() => {
  167. this.table.listLoading = false
  168. }, 100)
  169. })
  170. },
  171. handleEnableChange() {
  172. console.log('点击了是否启用')
  173. },
  174. handleSearch() {
  175. console.log('点击了查询')
  176. this.table.getdataListParm.offset = 1
  177. this.getList()
  178. },
  179. handleRefresh() {
  180. console.log('点击了重置')
  181. this.table.getdataListParm.parammaps.bigfeedclassname = ''
  182. this.table.getdataListParm.parammaps.fccode = ''
  183. this.table.getdataListParm.parammaps.fcname = ''
  184. this.table.getdataListParm.parammaps.enable = ''
  185. this.table.getdataListParm.offset = 1
  186. this.getList()
  187. },
  188. changeBigfeedclass(item) {
  189. this.table.temp.bigfeedclassname = this.feedCategoryList.find(obj => obj.value === item).label
  190. },
  191. handleCreate() {
  192. // 编辑true/不可编辑false
  193. // 新增操true,编辑false,编辑保存false
  194. for (let i = 0; i < this.table.list.length; i++) {
  195. if (this.table.list[i].Edit === true) {
  196. this.$message({ type: 'error', message: '当前内容未保存,请点击取消或保存继续进行操作', duration: 2000 })
  197. return false
  198. }
  199. }
  200. this.table.list.unshift({ 'myId': (new Date()).valueOf(), 'Edit': true, 'NoEdit': false, 'isCreate': true, 'isUpdate': false, 'isUpdateSave': false, 'enable': 1, 'bigfeedclassid': '', 'fcname': '', 'fccode': '' })
  201. },
  202. createData(row) {
  203. console.log('点击了新增保存', row)
  204. this.table.temp.pastureid = Cookies.get('pastureid')
  205. this.table.temp.fccode = row.fccode
  206. this.table.temp.fcname = row.fcname
  207. this.table.temp.bigfeedclassname = this.table.temp.bigfeedclassname
  208. this.table.temp.bigfeedclassid = row.bigfeedclassid
  209. this.table.temp.enable = row.enable
  210. // 饲料大类/饲料分类/饲料分类编号是否为空
  211. if (this.table.temp.bigfeedclassid == '' && 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.fcname == '' && this.table.temp.fccode == '') {
  215. this.$message({ type: 'error', message: '饲料分类/饲料分类编号不能为空', duration: 2000 })
  216. return false
  217. } else if (this.table.temp.bigfeedclassid == '') {
  218. this.$message({ type: 'error', message: '饲料大类不能为空', duration: 2000 })
  219. return false
  220. } else if (this.table.temp.fcname == '') {
  221. this.$message({ type: 'error', message: '饲料分类不能为空', duration: 2000 })
  222. return false
  223. } else if (this.table.temp.fccode == '') {
  224. this.$message({ type: 'error', message: '饲料分类编号不能为空', duration: 2000 })
  225. return false
  226. }
  227. const pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~!@#¥……&*()——|{}【】‘;:”“'。,、?]")
  228. if (pattern.test(this.table.temp.fccode)) {
  229. this.$message({ type: 'error', message: '饲料分类编号不可输入特殊字符', duration: 2000 })
  230. return false
  231. }
  232. if (pattern.test(this.table.temp.fcname)) {
  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 = 'insertFeedclass'
  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. this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
  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. for (let i = 0; i < this.table.list.length; i++) {
  266. if (this.table.list[i].Edit == true) {
  267. this.$message({ type: 'error', message: '当前内容未保存,请点击取消或保存继续进行操作', duration: 2000 })
  268. return false
  269. }
  270. }
  271. // 编辑true,不可编辑false
  272. row.Edit = true
  273. row.NoEdit = false
  274. // 新增false,编辑false,编辑保存true
  275. row.isCreate = false
  276. row.isUpdate = false
  277. row.isUpdateSave = true
  278. row.bigfeedclassid = String(row.bigfeedclassid)
  279. this.table.temp.bigfeedclassid = row.bigfeedclassid
  280. this.table.temp.bigfeedclassname = row.bigfeedclassname
  281. },
  282. updateData(row) {
  283. console.log('点击了编辑保存', row)
  284. console.log('点击了新增保存', row)
  285. this.table.temp.pastureid = Cookies.get('pastureid')
  286. this.table.temp.fccode = row.fccode
  287. this.table.temp.fcname = row.fcname
  288. this.table.temp.bigfeedclassname = this.table.temp.bigfeedclassname
  289. this.table.temp.bigfeedclassid = row.bigfeedclassid
  290. this.table.temp.enable = row.enable
  291. this.table.temp.id = row.id
  292. // 饲料大类/饲料分类/饲料分类编号是否为空
  293. if (this.table.temp.bigfeedclassid == '' && 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.fcname == '' && this.table.temp.fccode == '') {
  297. this.$message({ type: 'error', message: '饲料分类/饲料分类编号不能为空', duration: 2000 })
  298. return false
  299. } else if (this.table.temp.bigfeedclassid == '') {
  300. this.$message({ type: 'error', message: '饲料大类不能为空', duration: 2000 })
  301. return false
  302. } else if (this.table.temp.fcname == '') {
  303. this.$message({ type: 'error', message: '饲料分类不能为空', duration: 2000 })
  304. return false
  305. } else if (this.table.temp.fccode == '') {
  306. this.$message({ type: 'error', message: '饲料分类编号不能为空', duration: 2000 })
  307. return false
  308. }
  309. const pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~!@#¥……&*()——|{}【】‘;:”“'。,、?]")
  310. if (pattern.test(this.table.temp.fccode)) {
  311. this.$message({ type: 'error', message: '饲料分类编号不可输入特殊字符', duration: 2000 })
  312. return false
  313. }
  314. if (pattern.test(this.table.temp.fcname)) {
  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 = 'updateFeedclass'
  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. this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
  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 = {}
  352. this.requestParam.common = { 'returnmap': '0' }
  353. this.requestParam.data = []
  354. this.requestParam.data[0] = { 'name': 'checkDeleteFC', 'type': 'v', 'parammaps': {
  355. 'pastureid': row.pastureid,
  356. 'id': row.id
  357. }}
  358. this.requestParam.data[1] = { 'name': 'deleteFeedclass', 'type': 'e', 'parammaps': {
  359. 'pastureid': row.pastureid,
  360. 'id': row.id
  361. }}
  362. ExecDataByConfig(this.requestParam).then(response => {
  363. console.log('删除保存发送参数', this.requestParam)
  364. if (response.msg === 'fail') {
  365. this.$notify({ title: '删除失败', message: response.data, type: 'warning', duration: 2000 })
  366. } else {
  367. this.$notify({ title: '', message: '删除成功', type: 'success', duration: 2000 })
  368. this.getList()
  369. }
  370. })
  371. }).catch(() => {
  372. this.$message({ type: 'info', message: '已取消删除' })
  373. })
  374. },
  375. handleSelectionChange(val) {
  376. console.log('勾选数据', val)
  377. this.selectList = val
  378. },
  379. handleDelete() {
  380. console.log('点击了删除')
  381. if (this.selectList.length == 0) {
  382. this.$message({ type: 'error', message: '请选择饲料分类信息', duration: 2000 })
  383. } else {
  384. MessageBox.confirm('当前选中' + this.selectList.length + '条信息,是否删除?', {
  385. confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
  386. }).then(() => {
  387. console.log(this.selectList)
  388. this.requestParam = {}
  389. this.requestParam.common = { 'returnmap': '0' }
  390. this.requestParam.data = []
  391. this.requestParam.data[0] = { 'name': 'insertSpotList', 'resultmaps': { 'list': this.selectList }}
  392. this.requestParam.data[0].children = []
  393. this.requestParam.data[0].children[0] = { 'name': 'checkDeleteFC', 'type': 'v', 'parammaps': {
  394. id: '@insertSpotList.id',
  395. pastureid: '@insertSpotList.pastureid'
  396. }}
  397. this.requestParam.data[0].children[1] = { 'name': 'deleteFeedclass', 'type': 'e', 'parammaps': {
  398. id: '@insertSpotList.id',
  399. pastureid: '@insertSpotList.pastureid'
  400. }}
  401. ExecDataByConfig(this.requestParam).then(response => {
  402. console.log('删除保存发送参数', this.requestParam)
  403. if (response.msg === 'fail') {
  404. this.$notify({ title: '删除失败', message: response.data, type: 'warning', duration: 2000 })
  405. } else {
  406. this.$notify({ title: '', message: '删除成功', type: 'success', duration: 2000 })
  407. this.getList()
  408. }
  409. })
  410. })
  411. }
  412. }
  413. }
  414. }
  415. </script>
  416. <style lang="scss" scoped>
  417. .search{margin-top:10px;}
  418. .table{margin-top:10px;}
  419. </style>