pbpedigree.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. <template>
  2. <div class="mod-role">
  3. <el-container>
  4. <!-- form表单 -->
  5. <el-header>
  6. <div class="rect rect-form">
  7. <el-form :inline="true" :model="form" @keyup.enter.native="getDataList()" size="mini" ref="form">
  8. <el-form-item>
  9. <el-input v-model="form.eartag" placeholder="耳标" clearable></el-input>
  10. </el-form-item>
  11. <el-form-item style="width: 140px">
  12. <el-select placeholder="性别" v-model="form.sex">
  13. <el-option
  14. v-for="item in gender"
  15. :key="item.value"
  16. :label="item.label"
  17. :value="item.value">
  18. </el-option>
  19. </el-select>
  20. </el-form-item>
  21. <el-form-item style="width: 140px">
  22. <el-select placeholder="品种" v-model="form.breed">
  23. <el-option
  24. v-for="item in breed"
  25. :key="item.value"
  26. :label="item.label"
  27. :value="item.value">
  28. </el-option>
  29. </el-select>
  30. </el-form-item>
  31. <el-form-item style="width: 140px">
  32. <el-select placeholder="健康状态" v-model="form.healthStatus">
  33. <el-option
  34. v-for="item in healthStatus"
  35. :key="item.value"
  36. :label="item.label"
  37. :value="item.value">
  38. </el-option>
  39. </el-select>
  40. </el-form-item>
  41. <el-form-item style="width: 140px">
  42. <el-select placeholder="养殖状态" v-model="form.outFenceStatus">
  43. <el-option
  44. v-for="item in outFenceStatus"
  45. :key="item.value"
  46. :label="item.label"
  47. :value="item.value">
  48. </el-option>
  49. </el-select>
  50. </el-form-item>
  51. <el-form-item style="width: 140px">
  52. <el-select placeholder="猪舍" v-model="form.pigstyId" @change="pigstyChange">
  53. <el-option
  54. v-for="item in pigstyList"
  55. :key="item.value"
  56. :label="item.label"
  57. :value="item.value">
  58. </el-option>
  59. </el-select>
  60. </el-form-item>
  61. <el-form-item style="width: 140px">
  62. <el-select placeholder="单元" v-model="form.unitId" @change="ifPigsty('unitId')">
  63. <el-option
  64. v-for="item in unitSelectedList"
  65. :key="item.value"
  66. :label="item.label"
  67. :value="item.value">
  68. </el-option>
  69. </el-select>
  70. </el-form-item>
  71. <el-form-item style="width: 140px">
  72. <el-select placeholder="栏期" v-model="form.periodId" @change="ifPigsty('periodId')">
  73. <el-option
  74. v-for="item in periodSelectedList"
  75. :key="item.value"
  76. :label="item.label"
  77. :value="item.value">
  78. </el-option>
  79. </el-select>
  80. </el-form-item>
  81. <el-form-item>
  82. <el-button @click="getDataList()" icon="el-icon-search">查 询</el-button>
  83. </el-form-item>
  84. <el-form-item>
  85. <el-button
  86. icon="el-icon-circle-close"
  87. @click="clearAll">清 空</el-button>
  88. </el-form-item>
  89. </el-form>
  90. </div>
  91. </el-header>
  92. <!-- role表格 -->
  93. <el-main>
  94. <div class="rect rect-table">
  95. <!-- 新增 删除按钮 -->
  96. <el-form inline size="mini">
  97. <el-form-item>
  98. <el-button
  99. icon="el-icon-plus"
  100. @click="addOrUpdateHandle()">
  101. 新 增
  102. </el-button>
  103. </el-form-item>
  104. <el-form-item>
  105. <el-button
  106. icon="el-icon-delete"
  107. type="danger"
  108. @click="deleteHandle()"
  109. :disabled="dataListSelections.length <= 0">
  110. 删 除
  111. </el-button>
  112. </el-form-item>
  113. <el-form-item>
  114. <el-button
  115. icon="el-icon-edit"
  116. type="danger"
  117. @click="addOrUpdateHandle()"
  118. :disabled="dataListSelections.length <= 0">
  119. 批量修改
  120. </el-button>
  121. </el-form-item>
  122. </el-form>
  123. <el-table
  124. :data="dataList"
  125. border
  126. stripe
  127. v-loading="dataListLoading"
  128. @selection-change="selectionChangeHandle"
  129. style="width: 100%;"
  130. size="mini"
  131. height="540"
  132. :header-cell-style="{background:'rgb(245,245,245)',color:'#000',height: '45px',fontSize: '13px',fontWeight: 'normal',borderBottom: '1px solid #ccc'}"
  133. :cell-style="{color: '#888',fontSize: '13px'}">
  134. <el-table-column
  135. type="selection"
  136. header-align="center"
  137. align="center"
  138. width="50">
  139. </el-table-column>
  140. <el-table-column
  141. prop="id"
  142. header-align="center"
  143. align="center"
  144. label="id">
  145. </el-table-column>
  146. <el-table-column
  147. prop="eartag"
  148. header-align="center"
  149. align="center"
  150. label="耳标">
  151. </el-table-column>
  152. <el-table-column
  153. prop="sex"
  154. header-align="center"
  155. align="center"
  156. label="性别">
  157. </el-table-column>
  158. <!-- <el-table-column
  159. prop="birthday"
  160. header-align="center"
  161. align="center"
  162. label="出生日期">
  163. </el-table-column>
  164. <el-table-column
  165. header-align="center"
  166. align="center"
  167. label="健康状态">
  168. <template slot-scope="scope">
  169. <span>{{scope.row.healthStatus? '健康': '不健康'}}</span>
  170. </template>
  171. </el-table-column>
  172. <el-table-column
  173. header-align="center"
  174. align="center"
  175. label="养殖状态">
  176. <template slot-scope="scope">
  177. <span>{{scope.row.outFenceStatus? '出栏': '育肥'}}</span>
  178. </template>
  179. </el-table-column>
  180. <el-table-column
  181. prop="breed"
  182. header-align="center"
  183. align="center"
  184. label="品种">
  185. </el-table-column> -->
  186. <el-table-column
  187. prop="pigstyName"
  188. header-align="center"
  189. align="center"
  190. label="猪舍">
  191. </el-table-column>
  192. <el-table-column
  193. prop="unitName"
  194. header-align="center"
  195. align="center"
  196. label="单元">
  197. </el-table-column>
  198. <el-table-column
  199. prop="periodName"
  200. header-align="center"
  201. align="center"
  202. label="栏期">
  203. </el-table-column>
  204. <el-table-column
  205. fixed="right"
  206. header-align="center"
  207. align="center"
  208. label="操作">
  209. <template slot-scope="scope">
  210. <el-button
  211. type="text"
  212. size="medium"
  213. style="color: rgb(24,144,255)"
  214. @click="detailsHandle(scope.row)">
  215. 查看谱系
  216. </el-button>
  217. <!-- <el-button
  218. type="text"
  219. size="medium"
  220. @click="addOrUpdateHandle(scope.row)"
  221. style="color: rgb(24,144,255)">
  222. 编辑
  223. </el-button> -->
  224. </template>
  225. </el-table-column>
  226. </el-table>
  227. <el-pagination
  228. @size-change="sizeChangeHandle"
  229. @current-change="currentChangeHandle"
  230. :current-page="pageIndex"
  231. :page-sizes="[10, 20, 50, 100]"
  232. :page-size="pageSize"
  233. :total="totalPage"
  234. layout="total, sizes, prev, pager, next, jumper">
  235. </el-pagination>
  236. <!-- 弹窗, 新增 / 修改 -->
  237. <Details v-if="detailsVisible" ref="details" @refreshDataList="getDataList"></Details>
  238. </div>
  239. </el-main>
  240. </el-container>
  241. </div>
  242. </template>
  243. <script>
  244. import Details from './pbped-details.vue'
  245. export default {
  246. data () {
  247. return {
  248. form: {
  249. eartag: '',
  250. sex: '',
  251. breed: '',
  252. healthStatus: '',
  253. outFenceStatus: '',
  254. periodId: '',
  255. pigstyId: '',
  256. unitId: ''
  257. },
  258. dataList: [],
  259. pageIndex: 1,
  260. pageSize: 10,
  261. totalPage: 0,
  262. dataListLoading: false,
  263. dataListSelections: [],
  264. detailsVisible: false,
  265. farmId: undefined,
  266. gender: [
  267. {
  268. value: '公',
  269. label: '公'
  270. },
  271. {
  272. value: '母',
  273. label: '母'
  274. }
  275. ],
  276. breed: [
  277. {
  278. value: 1,
  279. label: '杜巴嘉'
  280. },
  281. {
  282. value: 2,
  283. label: '长白'
  284. }
  285. ],
  286. healthStatus: [
  287. {
  288. value: true,
  289. label: '健康'
  290. },
  291. {
  292. value: false,
  293. label: '不健康'
  294. }
  295. ],
  296. outFenceStatus: [
  297. {
  298. value: 0,
  299. label: '育肥'
  300. },
  301. {
  302. value: 1,
  303. label: '出栏'
  304. }
  305. ],
  306. periodList: [], // 所有栏期
  307. periodSelectedList: [], // 根据栋舍限制的栏期
  308. pigstyList: [], // 所有栋舍
  309. unitList: [], // 所有单元
  310. unitSelectedList: [], // 根据栋舍限制的单元
  311. labelPosition: 'right'
  312. }
  313. },
  314. components: {
  315. Details
  316. },
  317. activated () {
  318. this.getDataList()
  319. },
  320. methods: {
  321. // 获取数据列表
  322. getDataList () {
  323. this.dataListLoading = true
  324. this.$http({
  325. url: this.$http.adornUrl('/management/yearpigbase/list'),
  326. method: 'get',
  327. params: this.$http.adornParams({
  328. 'page': this.pageIndex,
  329. 'limit': this.pageSize,
  330. 'eartag': this.form.eartag || undefined,
  331. 'sex': this.form.sex || undefined,
  332. 'breed': this.form.breed || undefined,
  333. 'healthStatus': this.form.healthStatus || (this.form.healthStatus === 0?this.form.healthStatus: undefined),
  334. 'outFenceStatus': this.form.outFenceStatus || (this.form.outFenceStatus === 0?this.form.outFenceStatus: undefined),
  335. 'periodId': this.form.periodId || undefined,
  336. 'pigstyId': this.form.pigstyId || undefined,
  337. 'unitId': this.form.unitId || undefined
  338. })
  339. }).then(async({data}) => {
  340. // // 获取所有牧场
  341. // let pastureList = []
  342. // let pastureResult = await this.$http({
  343. // url: this.$http.adornUrl("/management/farm/findAll"),
  344. // method: "post",
  345. // })
  346. // pastureResult.data.all && (pastureList = pastureResult.data.all)
  347. // 栋舍List
  348. this.pigstyList = []
  349. let pigstyList = []
  350. let pigstyR = await this.$http({
  351. url: this.$http.adornUrl("/management/pigsty/findAll"),
  352. method: "get",
  353. params: this.$http.adornParams({})
  354. })
  355. pigstyR.data.all && (pigstyList = pigstyR.data.all)
  356. pigstyList.forEach(pigsty => {
  357. let item = {
  358. value: pigsty.id,
  359. label: pigsty.number
  360. }
  361. this.pigstyList.push(item)
  362. })
  363. // 单元List
  364. this.unitList = []
  365. let unitList = []
  366. let unitR = await this.$http({
  367. url: this.$http.adornUrl("/management/unit/findAll"),
  368. method: "get",
  369. params: this.$http.adornParams({})
  370. })
  371. unitR.data.all && (unitList = unitR.data.all)
  372. unitList.forEach(unit => {
  373. let item = {
  374. value: unit.id,
  375. label: unit.number,
  376. pigstyId: unit.pigstyId,
  377. farmId: unit.farmId
  378. }
  379. this.unitList.push(item)
  380. })
  381. this.unitSelectedList = this.unitList
  382. // 栏期List
  383. this.periodList = []
  384. let periodList = []
  385. let periodR = await this.$http({
  386. url: this.$http.adornUrl("/management/period/findAll"),
  387. method: "get",
  388. params: this.$http.adornParams({})
  389. })
  390. periodR.data.all && (periodList = periodR.data.all)
  391. periodList.forEach(period => {
  392. let item = {
  393. value: period.id,
  394. label: period.number,
  395. pigstyId: period.pigstyId
  396. }
  397. this.periodList.push(item)
  398. })
  399. this.periodSelectedList = this.periodList
  400. this.form.pigstyId? this.periodSelectedList = this.periodList.filter(item => item.pigstyId === this.form.pigstyId): this.periodSelectedList = this.periodList
  401. this.form.pigstyId? this.unitSelectedList = this.unitList.filter(item => item.pigstyId === this.form.pigstyId): this.unitSelectedList = this.unitList
  402. // 获取猪只List
  403. if (data && data.code === 0) {
  404. this.dataList = data.page.list
  405. this.totalPage = data.page.totalCount
  406. } else {
  407. this.dataList = []
  408. this.totalPage = 0
  409. this.$message.error(data.msg)
  410. }
  411. // // 猪只信息与单元、牧场、栏期、栋舍对应
  412. // this.dataList.forEach((item) => {
  413. // // 单元对应
  414. // for (let unit of this.unitList) {
  415. // if (item.unitId === unit.value) {
  416. // item.unitNumber = unit.label;
  417. // item.farmId = unit.farmId;
  418. // item.pigstyId = unit.pigstyId;
  419. // break;
  420. // }
  421. // }
  422. // // // 牧场对应
  423. // // for (let pasture of pastureList) {
  424. // // if (item.farmId === pasture.id) {
  425. // // item.name = pasture.name;
  426. // // break;
  427. // // }
  428. // // }
  429. // // 栋舍对应
  430. // for (let pighouse of this.pigstyList) {
  431. // if (item.pigstyId === pighouse.value) {
  432. // item.phNumber = pighouse.label;
  433. // break;
  434. // }
  435. // }
  436. // // 栏期对应
  437. // for (let period of this.periodList) {
  438. // if (item.periodId === period.value) {
  439. // item.periodNumber = period.label;
  440. // break;
  441. // }
  442. // }
  443. // })
  444. this.dataListLoading = false
  445. })
  446. },
  447. // 根据栋舍选择限制单元和栏期
  448. pigstyChange (val) {
  449. this.unitSelectedList = this.unitList.filter(item => item.pigstyId === val)
  450. this.periodSelectedList = this.periodList.filter(item => item.pigstyId === val)
  451. },
  452. // 需要先选择猪舍,才能选择单元或栏期
  453. ifPigsty (val) {
  454. if (!this.form.pigstyId) {
  455. this.$message.error('请先选择猪舍')
  456. this.form[val] = ''
  457. }
  458. },
  459. // form表单清空,单元SelectedList 和 栏期SelectedList重置
  460. clearAll () {
  461. for (let i in this.form) {
  462. this.form[i] = ''
  463. }
  464. this.unitSelectedList = this.unitList
  465. this.periodSelectedList = this.periodList
  466. },
  467. // 每页数
  468. sizeChangeHandle (val) {
  469. this.pageSize = val
  470. this.pageIndex = 1
  471. this.getDataList()
  472. },
  473. // 当前页
  474. currentChangeHandle (val) {
  475. this.pageIndex = val
  476. this.getDataList()
  477. },
  478. // 多选
  479. selectionChangeHandle (val) {
  480. this.dataListSelections = val
  481. },
  482. // 查看谱系
  483. detailsHandle (pig) {
  484. this.detailsVisible = true
  485. // var ids = id ? [id] : this.dataListSelections.map(item => {
  486. // return {
  487. // id: item.id,
  488. // eartag: item.eartag
  489. // }
  490. // })
  491. this.$nextTick(() => {
  492. this.$refs.details.init(pig.eartag)
  493. })
  494. },
  495. // 删除
  496. deleteHandle (id) {
  497. var ids = id ? [id] : this.dataListSelections.map(item => {
  498. return item.id
  499. })
  500. this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
  501. confirmButtonText: '确定',
  502. cancelButtonText: '取消',
  503. type: 'warning'
  504. }).then(() => {
  505. this.$http({
  506. url: this.$http.adornUrl('/management/yearpigbase/delete'),
  507. method: 'post',
  508. data: this.$http.adornData(ids, false)
  509. }).then(({data}) => {
  510. if (data && data.code === 0) {
  511. this.$message({
  512. message: '操作成功',
  513. type: 'success',
  514. duration: 1500,
  515. onClose: () => {
  516. this.getDataList()
  517. }
  518. })
  519. } else {
  520. this.$message.error(data.msg)
  521. }
  522. })
  523. }).catch(() => {})
  524. }
  525. },
  526. watch: {
  527. 'form.pigstyId': {
  528. handler(newValue, oldValue) {
  529. if (oldValue) {
  530. this.form.unitId = ''
  531. this.form.periodId = ''
  532. }
  533. }
  534. }
  535. }
  536. }
  537. </script>
  538. <style scoped>
  539. .rect {
  540. background-color: #fff;
  541. padding: 30px 15px;
  542. border-radius: 5px;
  543. border: 1px solid #e8e8e8;
  544. }
  545. .rect-form {
  546. padding-bottom: 10px;
  547. }
  548. .rect-table {
  549. margin-top: 20px;
  550. }
  551. .demo-table-expand {
  552. font-size: 0;
  553. margin-left: 40px;
  554. }
  555. .demo-table-expand label {
  556. width: 90px;
  557. color: #99a9bf;
  558. }
  559. .demo-table-expand .el-form-item {
  560. margin-right: 0;
  561. margin-bottom: 0;
  562. width: 80%;
  563. }
  564. .el-table .height {
  565. background: rgba(254, 254, 254, 0.5);
  566. }
  567. /deep/ .el-table--mini td, .el-table--mini th {
  568. padding: 3px 0 !important;
  569. height: 20px !important;
  570. }
  571. /deep/ .el-checkbox__input.is-checked+.el-checkbox__label {
  572. color: rgb(24,144,255);
  573. background-color: rgb(24,144,255);
  574. border-color: rgb(24,144,255);
  575. }
  576. /deep/.el-table .el-checkbox__input.is-checked .el-checkbox__inner, .el-checkbox__input.is-indeterminate .el-checkbox__inner {
  577. background-color: rgb(24,144,255);
  578. border-color: rgb(24,144,255);
  579. }
  580. /deep/.el-table .el-checkbox__inner:hover {
  581. border-color: rgb(24,144,255);
  582. }
  583. /deep/.el-table .el-checkbox__input.is-focus .el-checkbox__inner {
  584. border-color: rgb(24,144,255);
  585. }
  586. /deep/.el-table #select .cell .el-checkbox__input.is-checked .el-checkbox__inner, .el-checkbox__input.is-indeterminate .el-checkbox__inner {
  587. background-color: rgb(24,144,255);
  588. border-color: rgb(24,144,255);
  589. }
  590. </style>