hvaccine.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. <template>
  2. <div class="hvaccine">
  3. <el-container>
  4. <el-header>
  5. <div class="rect" style="padding-bottom: 10px">
  6. <el-form
  7. :inline="true"
  8. :model="searchForm"
  9. size="mini">
  10. <el-form-item style="width: 200px">
  11. <el-input placeholder="耳标" style="width: 200px" v-model="searchForm.earTag"></el-input>
  12. </el-form-item>
  13. <el-form-item>
  14. <el-button icon="el-icon-search" @click="init">查 询</el-button>
  15. </el-form-item>
  16. <el-form-item>
  17. <el-button icon="el-icon-circle-close" @click="clearAll">清 空</el-button>
  18. </el-form-item>
  19. </el-form>
  20. </div>
  21. </el-header>
  22. <el-main>
  23. <div class="rect" style="margin-top: 20px">
  24. <el-form size="mini" :inline="true">
  25. <el-form-item>
  26. <el-button
  27. icon="el-icon-plus"
  28. @click="visible = true">
  29. 新 增
  30. </el-button>
  31. <el-button
  32. icon="el-icon-delete"
  33. @click="delAll"
  34. type="danger"
  35. :disabled="selectList.length <= 0">
  36. 删 除
  37. </el-button>
  38. </el-form-item>
  39. </el-form>
  40. <el-table
  41. id="select"
  42. height="530"
  43. :data="tableData"
  44. @selection-change="selectionChangeHandle"
  45. v-loading="dataListLoading"
  46. style="width: 100%"
  47. ref="table"
  48. stripe
  49. border
  50. :header-cell-style="{background:'rgb(245,245,245)',color:'#000',height: '45px',fontSize: '13px',fontWeight: 'normal',borderBottom: '1px solid #ccc'}"
  51. :cell-style="{color: '#888',fontSize: '13px'}"
  52. size="mini">
  53. <el-table-column
  54. type="selection"
  55. header-align="center"
  56. align="center"
  57. width="50">
  58. </el-table-column>
  59. <el-table-column
  60. prop="id"
  61. header-align="center"
  62. align="center"
  63. label="id">
  64. </el-table-column>
  65. <el-table-column
  66. prop="pigId"
  67. header-align="center"
  68. align="center"
  69. label="猪只耳标">
  70. </el-table-column>
  71. <el-table-column
  72. prop="vaccineName"
  73. header-align="center"
  74. align="center"
  75. label="疫苗名称">
  76. </el-table-column>
  77. <el-table-column
  78. prop="createTime"
  79. header-align="center"
  80. align="center"
  81. label="创建时间">
  82. </el-table-column>
  83. <el-table-column
  84. prop="manName"
  85. header-align="center"
  86. align="center"
  87. label="操作人">
  88. </el-table-column>
  89. <el-table-column
  90. header-align="center"
  91. align="center"
  92. label="操作">
  93. <template slot-scope="scope">
  94. <el-button
  95. v-if="isAuth('sys:user:update')"
  96. type="text"
  97. size="medium"
  98. @click="addOrUpdateHandle(scope.row)"
  99. style="color: rgb(24,144,255)">
  100. 修改
  101. </el-button>
  102. <el-button
  103. v-if="isAuth('sys:user:delete')"
  104. type="text"
  105. size="medium"
  106. @click="deleteHandle(scope.row.id)"
  107. style="color: rgb(24,144,255)">
  108. 删除
  109. </el-button>
  110. </template>
  111. </el-table-column>
  112. </el-table>
  113. <el-pagination
  114. @size-change="sizeChange"
  115. @current-change="pageChange"
  116. :current-page="page"
  117. :page-sizes="[10, 20, 50, 100]"
  118. :page-size="limit"
  119. :total="total"
  120. layout="total, sizes, prev, pager, next, jumper">
  121. </el-pagination>
  122. </div>
  123. <!-- 弹框 -->
  124. <el-dialog
  125. :title="!dataForm.id ? '新增' : '修改'"
  126. :close-on-click-modal="false"
  127. :visible.sync="visible"
  128. width="600px">
  129. <el-form
  130. :model="dataForm"
  131. :rules="dataRule"
  132. ref="dataForm"
  133. @keyup.enter.native="dataFormSubmit()"
  134. label-width="80px"
  135. size="mini"
  136. style="margin-left: 20px;width: 500px">
  137. <el-form-item label="猪只耳标" prop="pigId">
  138. <el-input
  139. type="textarea"
  140. :rows="2"
  141. placeholder="每个耳标之间用英文逗号隔开,最多可以添加50头猪"
  142. v-model="dataForm.pigId"
  143. :disabled="dataForm.id? true: false">
  144. </el-input>
  145. </el-form-item>
  146. <el-form-item label="疫苗名称" prop="vaccineName">
  147. <el-input v-model="dataForm.vaccineName" placeholder="请输入疫苗名称"></el-input>
  148. </el-form-item>
  149. <el-form-item label="操作人" prop="manId">
  150. <el-select
  151. ref="slelctRef"
  152. @change="onChangeMan($event)"
  153. v-model="dataForm.manId"
  154. style="width: 100%">
  155. <el-option
  156. v-for="item in manList"
  157. :key="item.id"
  158. :label="item.name"
  159. :value="item.id">
  160. </el-option>
  161. </el-select>
  162. </el-form-item>
  163. </el-form>
  164. <span slot="footer" class="dialog-footer">
  165. <el-button size="mini" @click="onCancel">关闭</el-button>
  166. <el-button size="mini" type="primary" @click="dataFormSubmit()">确定</el-button>
  167. </span>
  168. </el-dialog>
  169. </el-main>
  170. </el-container>
  171. </div>
  172. </template>
  173. <script>
  174. import TableFooter from '../../../components/TableFooter'
  175. import {mapState, mapActions} from 'vuex'
  176. export default {
  177. name: 'hvaccine',
  178. components: {
  179. TableFooter
  180. },
  181. data () {
  182. return {
  183. searchForm: {
  184. earTag: ''
  185. },
  186. tableData: [],
  187. dataListLoading: false,
  188. page: 1,
  189. limit: 20,
  190. total: 0,
  191. dataForm: {
  192. id: '',
  193. pigId: '',
  194. vaccineName: '',
  195. manId: '',
  196. manName: ''
  197. },
  198. visible: false,
  199. dataRule: {
  200. pigId: [
  201. {required: true, message: '猪只耳标不能为空', trigger: 'blur'}
  202. ],
  203. vaccineName: [
  204. {required: true, message: '疫苗名称不能为空', trigger: 'blur'}
  205. ],
  206. manId: [
  207. {required: true, message: '操作人不能为空', trigger: 'change'}
  208. ]
  209. },
  210. selectList: []
  211. }
  212. },
  213. computed: {
  214. ...mapState(['manList'])
  215. },
  216. methods: {
  217. ...mapActions(['getManList']),
  218. // 修改size
  219. sizeChange (val) {
  220. this.limit = val
  221. this.init()
  222. },
  223. // 修改页数
  224. pageChange (val) {
  225. this.page = val
  226. this.init()
  227. },
  228. init () {
  229. this.dataListLoading = true
  230. let params = {
  231. page: this.page,
  232. limit: this.limit,
  233. eartag: this.searchForm.earTag
  234. }
  235. this.$http({
  236. url: this.$http.adornUrl('/management/healthimmunerecord/list'),
  237. method: 'get',
  238. params: this.$http.adornParams(params)
  239. })
  240. .then(res => {
  241. if (res.data.code === 0) {
  242. this.tableData = res.data.page.list
  243. this.total = res.data.page.totalCount
  244. }
  245. }).finally(() => {
  246. this.dataListLoading = false
  247. })
  248. },
  249. selectionChangeHandle (val) {
  250. this.selectList = []
  251. val.forEach(item => {
  252. this.selectList.push(item.id)
  253. })
  254. },
  255. // 修改
  256. addOrUpdateHandle (row) {
  257. this.dataForm = {
  258. id: row.id,
  259. pigId: row.pigId,
  260. vaccineName: row.vaccineName,
  261. manId: row.manId
  262. }
  263. this.visible = true
  264. },
  265. deleteHandle (id) {
  266. let ids = [id]
  267. this.$http({
  268. url: this.$http.adornUrl('/management/healthimmunerecord/delete'),
  269. method: 'post',
  270. data: this.$http.adornData(ids, false)
  271. })
  272. .then(res => {
  273. if (res.data.code === 0) {
  274. this.$message.success('删除成功!')
  275. this.init()
  276. } else {
  277. this.$message.error(res.data.msg)
  278. }
  279. })
  280. },
  281. onChangeMan (id) {
  282. let man = {}
  283. man = this.manList.find(item => {
  284. return item.id === id
  285. })
  286. this.dataForm.manName = man.name
  287. },
  288. dataFormSubmit () {
  289. this.$refs['dataForm'].validate((valid) => {
  290. if (valid) {
  291. let params = {
  292. id: this.dataForm.id == '' ? undefined : this.dataForm.id,
  293. eartags: this.dataForm.pigId,
  294. vaccineName: this.dataForm.vaccineName,
  295. manId: this.dataForm.manId,
  296. manName: this.dataForm.manName
  297. }
  298. this.$http({
  299. url: this.$http.adornUrl(`${!this.dataForm.id ? '/management/healthimmunerecord/saveAll' : '/management/healthimmunerecord/update'}`),
  300. method: 'post',
  301. data: this.$http.adornData(params, true)
  302. }).then(({data}) => {
  303. if (data && data.code === 0) {
  304. this.visible = false
  305. this.$message({
  306. message: '操作成功',
  307. type: 'success',
  308. duration: 1500
  309. })
  310. this.init()
  311. } else {
  312. this.$message.error(data.msg)
  313. }
  314. })
  315. }
  316. })
  317. },
  318. clearAll () {
  319. this.searchForm.earTag = ''
  320. },
  321. delAll () {
  322. this.$http({
  323. url: this.$http.adornUrl('/management/healthimmunerecord/delete'),
  324. method: 'post',
  325. data: this.$http.adornData(this.selectList, false)
  326. })
  327. .then(res => {
  328. if (res.data.code === 0) {
  329. this.$message.success('删除成功')
  330. this.init()
  331. } else {
  332. this.$message.error(res.data.msg)
  333. }
  334. })
  335. },
  336. // 关闭模态框
  337. onCancel () {
  338. this.visible = false
  339. this.reset()
  340. },
  341. reset () {
  342. this.dataForm = {
  343. id: '',
  344. pigId: '',
  345. vaccine: '',
  346. manId: '',
  347. manName: ''
  348. }
  349. }
  350. },
  351. created () {
  352. this.getManList()
  353. },
  354. activated () {
  355. this.init()
  356. }
  357. }
  358. </script>
  359. <style scoped>
  360. .hvaccine {
  361. }
  362. .rect {
  363. background-color: #fff;
  364. padding: 30px 15px;
  365. border-radius: 5px;
  366. border: 1px solid #e8e8e8;
  367. }
  368. /deep/ .el-table--mini td, .el-table--mini th {
  369. padding: 3px 0 !important;
  370. height: 20px !important;
  371. }
  372. /deep/ .el-checkbox__input.is-checked+.el-checkbox__label {
  373. color: rgb(24,144,255);
  374. background-color: rgb(24,144,255);
  375. border-color: rgb(24,144,255);
  376. }
  377. /deep/.el-table .el-checkbox__input.is-checked .el-checkbox__inner, .el-checkbox__input.is-indeterminate .el-checkbox__inner {
  378. background-color: rgb(24,144,255);
  379. border-color: rgb(24,144,255);
  380. }
  381. /deep/.el-table .el-checkbox__inner:hover {
  382. border-color: rgb(24,144,255);
  383. }
  384. /deep/.el-table .el-checkbox__input.is-focus .el-checkbox__inner {
  385. border-color: rgb(24,144,255);
  386. }
  387. /deep/.el-table #select .cell .el-checkbox__input.is-checked .el-checkbox__inner, .el-checkbox__input.is-indeterminate .el-checkbox__inner {
  388. background-color: rgb(24,144,255);
  389. border-color: rgb(24,144,255);
  390. }
  391. </style>