5627ce09c38e062537b6d0e2a097a712826006a5.svn-base 18 KB

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