pbbasic.vue 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259
  1. <template>
  2. <div class="pbbasic">
  3. <el-container>
  4. <el-header>
  5. <div class="rect rect-form">
  6. <el-form
  7. :inline="true"
  8. :model="searchForm"
  9. size="mini"
  10. style="height: 47px">
  11. <el-form-item style="width: 200px">
  12. <el-input placeholder="耳标" style="width: 200px" v-model="searchForm.eartag"></el-input>
  13. </el-form-item>
  14. <el-form-item style="width: 140px">
  15. <el-select placeholder="性别" style="width: 140px" v-model="searchForm.sex">
  16. <el-option
  17. v-for="item in gender"
  18. :key="item.label"
  19. :label="item.label"
  20. :value="item.value">
  21. </el-option>
  22. </el-select>
  23. </el-form-item>
  24. <el-form-item style="width: 140px">
  25. <el-select placeholder="品种" style="width: 140px" v-model="searchForm.breed">
  26. <el-option
  27. v-for="item in breedList"
  28. :key="item.label"
  29. :label="item.label"
  30. :value="item.value">
  31. </el-option>
  32. </el-select>
  33. </el-form-item>
  34. <el-form-item style="width: 140px">
  35. <el-select placeholder="健康状况" style="width: 140px" v-model="searchForm.healthStatus">
  36. <el-option
  37. v-for="item in healthStatus"
  38. :key="item.label"
  39. :label="item.label"
  40. :value="item.value">
  41. </el-option>
  42. </el-select>
  43. </el-form-item>
  44. <el-form-item style="width: 140px">
  45. <el-select placeholder="养殖状态" style="width: 140px" v-model="searchForm.outFenceStatus">
  46. <el-option
  47. v-for="item in outFenceStatus"
  48. :key="item.label"
  49. :label="item.label"
  50. :value="item.value">
  51. </el-option></el-select>
  52. </el-form-item>
  53. <el-form-item style="width: 140px">
  54. <el-select placeholder="猪舍"
  55. style="width: 140px"
  56. v-model="searchForm.pigstyId">
  57. <el-option
  58. v-for="item in pigstyList"
  59. :key="item.value"
  60. :label="item.label"
  61. :value="item.value">
  62. </el-option>
  63. </el-select>
  64. </el-form-item>
  65. <el-form-item style="width: 140px">
  66. <el-select
  67. placeholder="单元"
  68. style="width: 140px"
  69. ref="unit"
  70. v-model="searchForm.unitId"
  71. @focus="selectFocus('unit')">
  72. <el-option
  73. v-for="item in unitSelectedList"
  74. :key="item.value"
  75. :label="item.label"
  76. :value="item.value">
  77. </el-option>
  78. </el-select>
  79. </el-form-item>
  80. <el-form-item>
  81. <el-form-item style="width: 140px">
  82. <el-select
  83. placeholder="栏期"
  84. style="width: 140px"
  85. ref="period"
  86. v-model="searchForm.periodId"
  87. @focus="selectFocus('period')">
  88. <el-option
  89. v-for="item in periodSelectedList"
  90. :key="item.label"
  91. :label="item.label"
  92. :value="item.value">
  93. </el-option>
  94. </el-select>
  95. </el-form-item>
  96. <el-button @click="getDataList()" icon="el-icon-search">查 询</el-button>
  97. </el-form-item>
  98. <el-form-item>
  99. <el-button icon="el-icon-circle-close" @click="clearAll">清 空</el-button>
  100. </el-form-item>
  101. </el-form>
  102. </div>
  103. </el-header>
  104. <!-- 表格 -->
  105. <el-main>
  106. <div class="rect rect-table">
  107. <el-form size="mini" :inline="true">
  108. <el-form-item>
  109. <!-- <el-button
  110. icon="el-icon-plus">
  111. 新 增
  112. </el-button> -->
  113. <el-button
  114. icon="el-icon-delete"
  115. type="danger"
  116. @click="deleteHandle()"
  117. :disabled="selectionDataList.length <= 0">
  118. 删 除
  119. </el-button>
  120. </el-form-item>
  121. </el-form>
  122. <el-table
  123. id="select"
  124. height="530"
  125. :data="dataList"
  126. @selection-change="selectionChangeHandle"
  127. v-loading="dataListLoading"
  128. style="width: 100%"
  129. @expand-change="expandChange"
  130. ref="table"
  131. stripe
  132. border
  133. :header-cell-style="{background:'rgb(245,245,245)',color:'#000',height: '45px',fontSize: '13px',fontWeight: 'normal',borderBottom: '1px solid #ccc'}"
  134. :cell-style="{color: '#888',fontSize: '13px'}"
  135. size="mini">
  136. <el-table-column
  137. type="selection"
  138. header-align="center"
  139. align="center"
  140. width="50">
  141. </el-table-column>
  142. <el-table-column
  143. prop="id"
  144. header-align="center"
  145. align="center"
  146. label="id">
  147. </el-table-column>
  148. <el-table-column
  149. prop="eartag"
  150. header-align="center"
  151. align="center"
  152. label="耳标">
  153. </el-table-column>
  154. <el-table-column
  155. prop="sex"
  156. header-align="center"
  157. align="center"
  158. label="性别">
  159. </el-table-column>
  160. <el-table-column
  161. prop="birthday"
  162. header-align="center"
  163. align="center"
  164. label="出生日期">
  165. </el-table-column>
  166. <el-table-column
  167. header-align="center"
  168. align="center"
  169. label="健康状态">
  170. <template slot-scope="scope">
  171. <span>{{scope.row.healthStatus? '健康': '不健康'}}</span>
  172. </template>
  173. </el-table-column>
  174. <el-table-column
  175. header-align="center"
  176. align="center"
  177. label="养殖状态">
  178. <template slot-scope="scope">
  179. <span>{{ outFenceStatus[scope.row.outFenceStatus].label }}</span>
  180. </template>
  181. </el-table-column>
  182. <el-table-column
  183. prop="breed"
  184. header-align="center"
  185. align="center"
  186. label="品种">
  187. </el-table-column>
  188. <el-table-column
  189. prop="pigstyName"
  190. header-align="center"
  191. align="center"
  192. label="栋舍">
  193. </el-table-column>
  194. <el-table-column
  195. prop="unitName"
  196. header-align="center"
  197. align="center"
  198. label="单元">
  199. </el-table-column>
  200. <el-table-column
  201. prop="periodName"
  202. header-align="center"
  203. align="center"
  204. label="栏期">
  205. </el-table-column>
  206. <el-table-column
  207. header-align="center"
  208. align="center"
  209. label="操作">
  210. <template slot-scope="scope">
  211. <el-button
  212. v-if="isAuth('sys:user:update')"
  213. type="text"
  214. size="medium"
  215. @click="addOrUpdateHandle(scope.row)"
  216. style="color: rgb(24,144,255)">
  217. 修改
  218. </el-button>
  219. <el-button
  220. v-if="isAuth('sys:user:delete')"
  221. type="text"
  222. size="medium"
  223. @click="deleteHandle(scope.row.id)"
  224. style="color: rgb(24,144,255)">
  225. 删除
  226. </el-button>
  227. </template>
  228. </el-table-column>
  229. </el-table>
  230. <div class="block">
  231. <el-pagination
  232. @size-change="sizeChangeHandle"
  233. @current-change="currentChangeHandle"
  234. :current-page="pageIndex"
  235. :page-sizes="[10, 20, 30, 50, 100]"
  236. :page-size="pageSize"
  237. layout="total, sizes, prev, pager, next, jumper"
  238. :total="totalPage">
  239. </el-pagination>
  240. </div>
  241. <el-dialog
  242. :title="!form.id ? '新增' : '修改'"
  243. :close-on-click-modal="false"
  244. :visible.sync="visible"
  245. @close="cancel"
  246. style="width: 50%; margin: auto">
  247. <el-form
  248. :model="form"
  249. :rules="dataRule"
  250. ref="form"
  251. @keyup.enter.native="formSubmit()"
  252. label-width="80px"
  253. size="mini"
  254. style="padding: 0 60px 0 40px">
  255. <el-form-item label="所属猪舍" prop="pigstyId">
  256. <el-select
  257. v-model="form.pigstyId"
  258. placeholder="请选择所属猪舍"
  259. style="width: 100%">
  260. <el-option
  261. v-for="item in pigstyList"
  262. :key="item.label"
  263. :label="item.label"
  264. :value="item.value">
  265. </el-option>
  266. </el-select>
  267. </el-form-item>
  268. <el-form-item label="单元编号" prop="unitId">
  269. <el-select
  270. v-model="form.unitId"
  271. placeholder="请选择所属单元"
  272. style="width: 100%">
  273. <el-option
  274. v-for="item in unitSelectedList"
  275. :key="item.label"
  276. :label="item.label"
  277. :value="item.value">
  278. </el-option>
  279. </el-select>
  280. </el-form-item>
  281. <!-- <el-form-item label="栏期编号" prop="periodId">
  282. <el-select
  283. v-model="form.periodId"
  284. placeholder="请选择所属栏期"
  285. @change="ifPigsty('periodId')"
  286. style="width: 100%">
  287. <el-option
  288. v-for="item in periodSelectedList"
  289. :key="item.label"
  290. :label="item.label"
  291. :value="item.value">
  292. </el-option>
  293. </el-select>
  294. </el-form-item> -->
  295. <el-form-item label="耳标" prop="eartag">
  296. <el-input
  297. v-model="form.eartag"
  298. placeholder="请输入耳标"
  299. style="width: 100%">
  300. </el-input>
  301. </el-form-item>
  302. <el-form-item label="性别" prop="sex">
  303. <el-select
  304. v-model="form.sex"
  305. placeholder="请选择性别"
  306. style="width: 100%">
  307. <el-option
  308. v-for="item in gender"
  309. :key="item.label"
  310. :label="item.label"
  311. :value="item.value">
  312. </el-option>
  313. </el-select>
  314. </el-form-item>
  315. <el-form-item label="出生日期" prop="birthday">
  316. <el-date-picker
  317. v-model="form.birthday"
  318. type="date"
  319. value-format="yyyy-MM-dd"
  320. placeholder="请选择出生日期"
  321. @change="changeBirth"
  322. style="width: 100%">
  323. </el-date-picker>
  324. </el-form-item>
  325. <el-form-item label="健康状况" prop="healthStatus">
  326. <el-select
  327. v-model="form.healthStatus"
  328. placeholder="请选择健康状况"
  329. style="width: 100%">
  330. <el-option
  331. v-for="item in healthStatus"
  332. :key="item.label"
  333. :label="item.label"
  334. :value="item.value">
  335. </el-option>
  336. </el-select>
  337. </el-form-item>
  338. <el-form-item label="体重" prop="weight">
  339. <el-input-number
  340. v-model="form.weight"
  341. :step="0.01"
  342. :max="1000000"
  343. :min="0"
  344. style="width: 85%">
  345. </el-input-number>
  346. 千克
  347. </el-form-item>
  348. <el-form-item label="品种" prop="breed">
  349. <el-input
  350. v-model="form.breed"
  351. placeholder="请输入品种"
  352. style="width: 100%">
  353. </el-input>
  354. </el-form-item>
  355. </el-form>
  356. <span slot="footer" class="dialog-footer">
  357. <el-button @click="cancel" style="background-color: rgb(24,144,255);color: #fff;border-color: rgb(24,144,255)">关闭</el-button>
  358. <el-button type="primary" @click="formSubmit()" style="background-color: rgb(24,144,255);color: #fff;border-color: rgb(24,144,255)">确定</el-button>
  359. </span>
  360. </el-dialog>
  361. </div>
  362. </el-main>
  363. </el-container>
  364. </div>
  365. </template>
  366. <script>
  367. export default {
  368. data() {
  369. return {
  370. searchForm: {
  371. eartag: '',
  372. sex: '',
  373. breed: '',
  374. healthStatus: '',
  375. outFenceStatus: '',
  376. // periodId: '',
  377. pigstyId: '',
  378. unitId: ''
  379. },
  380. dataList: [],
  381. pageIndex: 1,
  382. pageSize: 10,
  383. totalPage: 0,
  384. dataListLoading: false,
  385. selectionDataList: [],
  386. visible: false,
  387. form: {
  388. id: "",
  389. unitId: "",
  390. weight: "",
  391. whereDidYouGo: "",
  392. dayAge: "",
  393. eartag: "",
  394. healthStatus: "",
  395. breed: "",
  396. birthday: "",
  397. sex: "",
  398. pigstyId: "",
  399. // periodId: "",
  400. farmId: "",
  401. },
  402. // pastureList: [], // 牧场list
  403. pigstyList: [], // 猪舍list
  404. unitList: [], // 单元list
  405. unitSelectedList: [], // 选择过后的单元list
  406. periodList: [], // 栏期list
  407. periodSelectedList: [], // 选择过后的栏期list
  408. health: [
  409. {
  410. value: true,
  411. label: "健康",
  412. },
  413. {
  414. value: false,
  415. label: "不健康",
  416. },
  417. ],
  418. gender: [
  419. {
  420. value: "公",
  421. label: "公",
  422. },
  423. {
  424. value: "母",
  425. label: "母",
  426. },
  427. ],
  428. breedList: [],
  429. healthStatus: [
  430. {
  431. value: 1,
  432. label: '健康'
  433. },
  434. {
  435. value: 0,
  436. label: '不健康'
  437. }
  438. ],
  439. outFenceStatus: [
  440. {
  441. value: 0,
  442. label: '育肥'
  443. },
  444. {
  445. value: 1,
  446. label: '出栏'
  447. }
  448. ],
  449. row: {},
  450. dataRule: {
  451. farmId: [
  452. { required: true, message: "牧场不能为空", trigger: "blur" },
  453. ],
  454. pigstyId: [
  455. { required: true, message: "猪舍不能为空", trigger: "blur" },
  456. ],
  457. unitId: [{ required: true, message: "单元不能为空", trigger: "blur" }],
  458. // periodId: [
  459. // { required: true, message: "栏期不能为空", trigger: "blur" },
  460. // ],
  461. eartag: [{ required: true, message: "耳标不能为空", trigger: "blur" }],
  462. sex: [{ required: true, message: "性别不能为空", trigger: "blur" }],
  463. birthday: [
  464. { required: true, message: "出生日期不能为空", trigger: "blur" },
  465. ],
  466. healthStatus: [],
  467. weight: [],
  468. breed: [{ required: true, message: "品种不能为空", trigger: "blur" }],
  469. },
  470. labelPosition: 'right',
  471. searchForm: {
  472. eartag: '',
  473. sex: '',
  474. breed: '',
  475. healthStatus: '',
  476. outFenceStatus: '',
  477. periodId: '',
  478. pigstyId: '',
  479. unitId: ''
  480. },
  481. eartags: [] // 被删除的猪只耳标
  482. }
  483. },
  484. activated() {
  485. this.getDataList();
  486. },
  487. methods: {
  488. // 左侧树形控件调用getDataList
  489. getPigs (val) {
  490. console.log(val);
  491. },
  492. // 获取数据列表
  493. getDataList() {
  494. this.dataListLoading = true;
  495. // 获取所有猪只信息
  496. this.$http({
  497. url: this.$http.adornUrl("/management/yearpigbase/list"),
  498. method: "get",
  499. params: this.$http.adornParams({
  500. page: this.pageIndex,
  501. limit: this.pageSize,
  502. 'eartag': this.searchForm.eartag || undefined,
  503. 'sex': this.searchForm.sex || undefined,
  504. 'breed': this.searchForm.breed || undefined,
  505. 'healthStatus': this.searchForm.healthStatus || (this.searchForm.healthStatus === 0?this.searchForm.healthStatus: undefined),
  506. 'outFenceStatus': this.searchForm.outFenceStatus || (this.searchForm.outFenceStatus === 0?this.searchForm.outFenceStatus: undefined),
  507. 'periodId': this.searchForm.periodId || undefined,
  508. 'pigstyId': this.searchForm.pigstyId || undefined,
  509. 'unitId': this.searchForm.unitId || undefined
  510. })
  511. }).then(async ({ data }) => {
  512. // 猪舍List
  513. this.pigstyList = []
  514. let pigstyList = []
  515. let pigstyR = await this.$http({
  516. url: this.$http.adornUrl("/management/pigsty/findAll"),
  517. method: "get",
  518. params: this.$http.adornParams({})
  519. })
  520. pigstyR.data.all && (pigstyList = pigstyR.data.all)
  521. pigstyList.forEach(pigsty => {
  522. let item = {
  523. value: pigsty.id,
  524. label: pigsty.number
  525. }
  526. this.pigstyList.push(item)
  527. })
  528. console.log(this.pigstyList);
  529. // 单元List
  530. this.unitList = []
  531. let unitList = []
  532. let unitR = await this.$http({
  533. url: this.$http.adornUrl("/management/unit/findAll"),
  534. method: "get",
  535. params: this.$http.adornParams({})
  536. })
  537. unitR.data.all && (unitList = unitR.data.all)
  538. unitList.forEach(unit => {
  539. let item = {
  540. value: unit.id,
  541. label: unit.number,
  542. pigstyId: unit.pigstyId
  543. }
  544. this.unitList.push(item)
  545. })
  546. // 栏期List
  547. this.periodList = []
  548. let periodList = []
  549. let periodR = await this.$http({
  550. url: this.$http.adornUrl("/management/period/findAll"),
  551. method: "get",
  552. params: this.$http.adornParams({})
  553. })
  554. periodR.data.all && (periodList = periodR.data.all)
  555. periodList.forEach(period => {
  556. let item = {
  557. value: period.id,
  558. label: period.number,
  559. pigstyId: period.pigstyId
  560. }
  561. this.periodList.push(item)
  562. })
  563. this.periodSelectedList = this.searchForm.pigstyId? this.periodList.filter(item => item.pigstyId === this.searchForm.pigstyId): this.periodList
  564. this.unitSelectedList = this.searchForm.pigstyId? this.unitList.filter(item => item.pigstyId === this.searchForm.pigstyId): this.unitList
  565. // 品种list
  566. this.breedList = []
  567. let breedList = []
  568. let breedR = await this.$http({
  569. url: this.$http.adornUrl("/management/basebloodline/findAll"),
  570. method: "get",
  571. params: this.$http.adornParams({})
  572. })
  573. breedR.data.all && (breedList = breedR.data.all)
  574. breedList.forEach(breed => {
  575. let item = {
  576. value: breed.name,
  577. label: breed.name
  578. }
  579. this.breedList.push(item)
  580. })
  581. if (data && data.code === 0) {
  582. this.dataList = data.page.list;
  583. this.totalPage = data.page.totalCount;
  584. // console.log(data.page.list);
  585. // // 单元对应
  586. // this.dataList.forEach((item) => {
  587. // for (let unit of this.unitList) {
  588. // if (item.unitId === unit.id) {
  589. // item.unitNumber = unit.number;
  590. // item.farmId = unit.farmId;
  591. // item.pigstyId = unit.pigstyId;
  592. // break;
  593. // }
  594. // }
  595. // });
  596. // // // 牧场对应
  597. // // this.dataList.forEach((item) => {
  598. // // for (let pasture of this.pastureList) {
  599. // // if (item.farmId === pasture.id) {
  600. // // item.name = pasture.name;
  601. // // break;
  602. // // }
  603. // // }
  604. // // });
  605. // // 猪舍对应
  606. // this.dataList.forEach((item) => {
  607. // for (let pighouse of this.pighouseList) {
  608. // if (item.pigstyId === pighouse.id) {
  609. // item.phNumber = pighouse.number;
  610. // break;
  611. // }
  612. // }
  613. // });
  614. // // 栏期对应
  615. // this.dataList.forEach((item) => {
  616. // for (let period of this.periodList) {
  617. // if (item.periodId === period.id) {
  618. // item.periodNumber = period.number;
  619. // break;
  620. // }
  621. // }
  622. // });
  623. // 初始化时,选择后的与未选择的list相同
  624. // this.phSelectedList = this.pighouseList;
  625. // this.unSelectedList = this.unitList;
  626. // this.peSelectedList = this.periodList;
  627. } else {
  628. this.dataList = [];
  629. this.totalPage = 0;
  630. }
  631. this.dataListLoading = false;
  632. });
  633. },
  634. // // 根据栋舍选择限制单元和栏期
  635. // pigstyChange (val) {
  636. // this.unitSelectedList = this.unitList.filter(item => item.pigstyId === val)
  637. // this.periodSelectedList = this.periodList.filter(item => item.pigstyId === val)
  638. // },
  639. // 点击 单元or栏期的选择框
  640. selectFocus (val) {
  641. if (!this.searchForm.pigstyId) {
  642. this.$message.error('请先选择猪舍')
  643. this.searchForm[val + 'Id'] = ''
  644. setTimeout(() => {
  645. this.$refs[val].blur()
  646. }, 10)
  647. }
  648. },
  649. // 每页数
  650. sizeChangeHandle(val) {
  651. this.pageSize = val;
  652. this.pageIndex = 1;
  653. this.getDataList();
  654. },
  655. // 当前页
  656. currentChangeHandle(val) {
  657. this.pageIndex = val;
  658. this.getDataList();
  659. },
  660. // 展开年猪具体信息,关闭另外的具体信息
  661. expandChange(val) {
  662. if (val !== this.row) {
  663. this.$refs.table.toggleRowExpansion(this.row, false);
  664. this.row = val;
  665. }
  666. console.log(val);
  667. },
  668. // 获取出生日期
  669. changeBirth(val) {
  670. let birth = new Date(val);
  671. let now = new Date();
  672. let days = now.getTime() - birth.getTime();
  673. if (days < 0) {
  674. this.$confirm(`出生日期有误`, "提示", {
  675. confirmButtonText: "确定",
  676. cancelButtonText: "取消",
  677. type: "warning",
  678. })
  679. .then(() => {
  680. console.log("还没出生呢...");
  681. })
  682. .catch(() => {});
  683. }
  684. this.form.dayAge = parseInt(days / (1000 * 60 * 60 * 24));
  685. },
  686. // 搜索表单清空
  687. clearAll () {
  688. for (let i in this.searchForm) {
  689. this.searchForm[i] = ''
  690. }
  691. this.unitSelectedList = this.unitList
  692. this.periodSelectedList = this.periodList
  693. },
  694. // 获取dayAge
  695. changeDay(val) {
  696. let now = new Date();
  697. let birth = new Date(now.setDate(now.getDate() - val));
  698. let month =
  699. birth.getMonth() < 9
  700. ? "0" + (birth.getMonth() + 1)
  701. : birth.getMonth() + 1;
  702. let date = birth.getDate() < 10 ? "0" + birth.getDate() : birth.getDate();
  703. this.form.birthday = `${birth.getFullYear()}-${month}-${date}`;
  704. },
  705. // // 获取到了牧场 → 猪舍 + 单元 + 栏期处理
  706. // getPasture(val) {
  707. // /** 关于猪舍 */
  708. // // → 限制猪舍
  709. // this.phSelectedList = [];
  710. // this.pighouseList.forEach((item) => {
  711. // if (item.farmId === val) {
  712. // this.phSelectedList.push(item);
  713. // }
  714. // });
  715. // // 判断当前 猪舍 是否需要清除
  716. // let pigsty = this.pigstyByYid(this.form.pigstyId);
  717. // if (pigsty && pigsty.farmId !== val) {
  718. // this.form.pigstyId = "";
  719. // }
  720. // /** 关于单元 */
  721. // // → 限制单元
  722. // this.unSelectedList = [];
  723. // this.unitList.forEach((item) => {
  724. // if (item.farmId === val) {
  725. // this.unSelectedList.push(item);
  726. // }
  727. // });
  728. // // 判断当前 单元 是否需要清除
  729. // let unit = this.UnitByIid(this.form.unitId);
  730. // if (unit && unit.farmId !== val) {
  731. // this.form.unitId = "";
  732. // }
  733. // /** 关于栏期 */
  734. // // → 限制栏期
  735. // this.peSelectedList = [];
  736. // this.periodList.forEach((item) => {
  737. // if (item.farmId === val) {
  738. // this.peSelectedList.push(item);
  739. // }
  740. // });
  741. // // 判断当前 栏期 是否需要清除
  742. // let period = this.periodByJid(this.form.periodId);
  743. // if (period && period.farmId !== val) {
  744. // this.form.periodId = "";
  745. // }
  746. // },
  747. // // 获取到猪舍 → 牧场 + 猪舍自身 + 单元 + 栏期处理
  748. // getPigsty(val) {
  749. // // → 反向确定牧场
  750. // let pigsty = this.pigstyByYid(this.form.pigstyId);
  751. // this.form.farmId = pigsty.farmId;
  752. // // → 先获取猪舍,没有确定牧场的情况下,限制猪舍自身
  753. // this.phSelectedList = this.xidYlist(pigsty.farmId);
  754. // /** 关于单元 */
  755. // // → 限制单元
  756. // this.unSelectedList = [];
  757. // this.unitList.forEach((item) => {
  758. // if (item.pigstyId === val) {
  759. // this.unSelectedList.push(item);
  760. // }
  761. // });
  762. // // 判断当前 单元 是否需要清除
  763. // let unit = this.UnitByIid(this.form.unitId);
  764. // if (unit && unit.pigstyId !== val) {
  765. // this.form.unitId = "";
  766. // }
  767. // /** 关于栏期 */
  768. // // → 限制栏期
  769. // this.peSelectedList = [];
  770. // this.periodList.forEach((item) => {
  771. // if (item.pigstyId === val) {
  772. // this.peSelectedList.push(item);
  773. // }
  774. // });
  775. // // 判断当前 栏期 是否需要清除
  776. // let period = this.periodByJid(this.form.periodId);
  777. // if (period && period.pigstyId !== val) {
  778. // this.form.periodId = "";
  779. // }
  780. // },
  781. // // 获取到了单元 → 牧场 + 猪舍 + 单元自身处理
  782. // getUnit(val) {
  783. // let unit = this.UnitByIid(val);
  784. // // 反向确定 牧场 + 猪舍
  785. // this.form.farmId = unit.farmId;
  786. // this.form.pigstyId = unit.pigstyId;
  787. // // 反向确定 猪舍selectedList + 单元selectedList + 栏期selectedList
  788. // this.phSelectedList = this.xidYlist(unit.farmId);
  789. // this.unSelectedList = this.yidIlist(unit.pigstyId);
  790. // this.peSelectedList = this.yidJlist(unit.pigstyId);
  791. // // 判断当前栏期是否需要清除
  792. // let period = this.periodByJid(this.form.periodId);
  793. // if (period && period.pigstyId !== unit.pigstyId) {
  794. // this.form.periodId = "";
  795. // }
  796. // },
  797. // // 根据牧场id → 限制猪舍selectedList
  798. // xidYlist(farmId) {
  799. // let phSelectedList = [];
  800. // this.pighouseList.forEach((item) => {
  801. // if (item.farmId === farmId) {
  802. // phSelectedList.push(item);
  803. // }
  804. // });
  805. // return phSelectedList;
  806. // },
  807. // // 根据猪舍id → 限制栏期selectedList
  808. // yidJlist(pigstyId) {
  809. // let peSelectedList = [];
  810. // this.periodList.forEach((item) => {
  811. // if (item.pigstyId === pigstyId) {
  812. // peSelectedList.push(item);
  813. // }
  814. // });
  815. // return peSelectedList;
  816. // },
  817. // // 根据猪舍id → 限制单元selectedList
  818. // yidIlist(pigstyId) {
  819. // let unSelectedList = [];
  820. // this.unitList.forEach((item) => {
  821. // if (item.pigstyId === pigstyId) {
  822. // unSelectedList.push(item);
  823. // }
  824. // });
  825. // return unSelectedList;
  826. // },
  827. // // 根据猪舍id → 返回猪舍信息
  828. // pigstyByYid(pigstyId) {
  829. // for (let item of this.pighouseList) {
  830. // if (item.id === pigstyId) {
  831. // return item;
  832. // }
  833. // }
  834. // return null;
  835. // },
  836. // // 根据栏期id → 返回栏期信息
  837. // periodByJid(periodId) {
  838. // for (let item of this.periodList) {
  839. // if (item.id === periodId) {
  840. // return item;
  841. // }
  842. // }
  843. // return null;
  844. // },
  845. // // 根据单元id → 返回单元信息
  846. // UnitByIid(unitId) {
  847. // for (let item of this.unitList) {
  848. // if (item.id === unitId) {
  849. // return item;
  850. // }
  851. // }
  852. // return null;
  853. // },
  854. // // 获取到栏期 → 牧场 + 猪舍 + 单元自身处理
  855. // getPeriod(val) {
  856. // let period = this.periodByJid(val);
  857. // // 反向确定牧场 + 猪舍
  858. // this.form.farmId = period.farmId;
  859. // this.form.pigstyId = period.pigstyId;
  860. // // 反向确定 猪舍selectedList + 单元selectedList + 栏期selectedList
  861. // this.phSelectedList = this.xidYlist(period.farmId);
  862. // this.unSelectedList = this.yidIlist(period.pigstyId);
  863. // this.peSelectedList = this.yidJlist(period.pigstyId);
  864. // // 判断当前 单元 是否需要清除
  865. // let unit = this.UnitByIid(this.form.unitId);
  866. // if (unit && unit.pigstyId !== period.pigstyId) {
  867. // this.form.unitId = "";
  868. // }
  869. // },
  870. // 新增 or 修改单元
  871. addOrUpdateHandle(row) {
  872. // 显示牧场新增 or 修改面板
  873. this.visible = true;
  874. console.log(row);
  875. if (row) {
  876. // this.form = row;
  877. this.form.id = row.id
  878. this.form.unitId = row.unitId
  879. this.form.pigstyId = row.pigstyId
  880. this.form.dayAge = row.dayAge
  881. this.form.eartag = row.eartag
  882. this.form.healthStatus = row.healthStatus
  883. this.form.weight = row.weight
  884. this.form.whereDidYouGo = row.whereDidYouGo
  885. this.form.breed = row.breed
  886. this.form.birthday = row.birthday
  887. this.form.sex = row.sex
  888. this.unitSelectedList = this.unitList.filter(item => item.pigstyId === this.form.pigstyId)
  889. // this.form.periodId = row.periodId
  890. }
  891. },
  892. // 选择n个牧场
  893. selectionChangeHandle(val) {
  894. this.selectionDataList = [];
  895. val.forEach((item) => {
  896. this.selectionDataList.push(item.id);
  897. });
  898. this.eartags = val.map(pig => pig.eartag)
  899. },
  900. // 删除n个猪
  901. deleteHandle(id) {
  902. this.eartags = id? [this.dataList.filter(pig => pig.id === id)[0].eartag]: this.eartags
  903. this.$confirm(`确定删除耳标号${this.eartags.join()}的猪只?`, "提示", {
  904. showCancelButton: true,
  905. showConfirmButton: true,
  906. cancelButtonClass: 'cancelButton',
  907. confirmButtonClass: 'confirmButton',
  908. confirmButtonText: "确定",
  909. cancelButtonText: "取消",
  910. type: "warning"
  911. })
  912. .then(() => {
  913. // 删除操作
  914. if (id) {
  915. this.selectionDataList.push(id);
  916. }
  917. if (this.selectionDataList.length <= 0) {
  918. return;
  919. }
  920. this.$http({
  921. url: this.$http.adornUrl("/management/yearpigbase/delete"),
  922. method: "post",
  923. data: this.$http.adornData(this.selectionDataList, false),
  924. }).then((result) => {
  925. if (result.data.code === 0) {
  926. // this.getDataList();
  927. // this.resetForm();
  928. this.$message({
  929. message: "成功删除年猪",
  930. type: "success",
  931. duration: 1000,
  932. });
  933. this.getDataList()
  934. // pageIndex修正
  935. // this.totalPage -= this.selectionDataList.length;
  936. // let pages = Math.ceil(this.totalPage / this.pageSize);
  937. // this.pageIndex = this.pageIndex > pages ? pages : this.pageIndex;
  938. // this.pageIndex = this.pageIndex < 1 ? pages : this.pageIndex;
  939. } else {
  940. this.$message.error("删除年猪失败");
  941. }
  942. this.selectionDataList = [];
  943. this.eartags = []
  944. });
  945. })
  946. .catch(() => {});
  947. },
  948. formSubmit() {
  949. if (this.form.id) {
  950. // 修改
  951. // // 输入是否完整
  952. // if (!this.confirmComplete()) {
  953. // return
  954. // }
  955. // 输入是否合法
  956. if (!this.confirmInput()) {
  957. return;
  958. }
  959. // 进行修改操作
  960. this.$http({
  961. url: this.$http.adornUrl("/management/yearpigbase/update"),
  962. method: "post",
  963. data: this.$http.adornData({
  964. id: this.form.id,
  965. unitId: this.form.unitId,
  966. dayAge: parseInt(this.form.dayAge),
  967. eartag: this.form.eartag,
  968. healthStatus: this.form.healthStatus,
  969. weight: parseFloat(this.form.weight),
  970. whereDidYouGo: this.form.whereDidYouGo,
  971. breed: this.form.breed,
  972. birthday: this.form.birthday,
  973. sex: this.form.sex,
  974. // periodId: this.form.periodId,
  975. pigstyId: this.form.pigstyId,
  976. farmId: parseInt(this.$cookie.get('formFarmId'))
  977. }),
  978. }).then((result) => {
  979. if (result.data.code === 0) {
  980. // this.resetForm();
  981. // console.log(result);
  982. // console.log(this.form);
  983. this.visible = false;
  984. this.$message({
  985. message: "成功修改年猪信息",
  986. type: "success",
  987. duration: 1000,
  988. })
  989. // this.getDataList()
  990. } else {
  991. // TODO: 年猪耳标重复
  992. if (result.data.code === 600) {
  993. // this.$message.error('牧场名称 ' + result.data.msg)
  994. // let msg = result.data.msg.split(' ')
  995. // this.$message({
  996. // message: `牧场名称 <p style="color:#333; display:inline">${msg[0]}</p> 已经存在!`,
  997. // type: "error",
  998. // duration: 1000,
  999. // dangerouslyUseHTMLString: true
  1000. // })
  1001. this.$message.error(result.data.msg);
  1002. return;
  1003. }
  1004. this.$message.error("修改年猪信息失败");
  1005. }
  1006. });
  1007. } else {
  1008. // 新增
  1009. console.log(this.form);
  1010. // 输入是否完整
  1011. // if (!this.confirmComplete(1)) {
  1012. // return
  1013. // }
  1014. // 输入是否合法
  1015. if (!this.confirmInput()) {
  1016. return;
  1017. }
  1018. // 进行新增操作
  1019. console.log("进行新增操作");
  1020. this.$http({
  1021. url: this.$http.adornUrl("/management/yearpigbase/save"),
  1022. method: "post",
  1023. data: this.$http.adornData({
  1024. unitId: this.form.unitId,
  1025. dayAge: parseInt(this.form.dayAge),
  1026. eartag: this.form.eartag,
  1027. healthStatus: this.form.healthStatus,
  1028. weight: parseInt(this.form.weight),
  1029. whereDidYouGo: this.form.whereDidYouGo,
  1030. breed: this.form.breed,
  1031. birthday: this.form.birthday,
  1032. sex: this.form.sex,
  1033. // periodId: this.form.periodId,
  1034. pigstyId: this.form.pigstyId,
  1035. farmId: parseInt(this.$cookie.get('formFarmId'))
  1036. }),
  1037. }).then((result) => {
  1038. if (result.data.code === 0) {
  1039. // 新增pageIndex的修正
  1040. // this.totalPage++;
  1041. // let pages = Math.ceil(this.totalPage / this.pageSize);
  1042. // this.pageIndex = this.pageIndex < pages ? pages : this.pageIndex;
  1043. // this.resetForm();
  1044. // this.visible = false;
  1045. this.$message({
  1046. message: "成功添加年猪",
  1047. type: "success",
  1048. duration: 1000,
  1049. })
  1050. // this.getDataList()
  1051. } else {
  1052. // TODO: 年猪耳标重复
  1053. if (result.data.code === 600) {
  1054. // this.$message.error('牧场名称 ' + result.data.msg)
  1055. // let msg = result.data.msg.split(' ')
  1056. // this.$message({
  1057. // message: `牧场名称 <p style="color:#333; display:inline">${msg[0]}</p> 已经存在!`,
  1058. // type: "error",
  1059. // duration: 1000,
  1060. // dangerouslyUseHTMLString: true
  1061. // })
  1062. this.$message.error(result.data.msg);
  1063. return;
  1064. }
  1065. this.$message.error("添加年猪失败");
  1066. }
  1067. });
  1068. }
  1069. this.getDataList()
  1070. },
  1071. // 校验输入是否完整
  1072. validComplete(val) {
  1073. val &&
  1074. (delete this.form.id,
  1075. delete this.form.deleted,
  1076. delete this.form.fosterStatus,
  1077. delete this.form.gmtCreate,
  1078. delete this.form.gmtModified,
  1079. // delete this.form.periodNumber,
  1080. delete this.form.phNumber,
  1081. delete this.form.unitNumber,
  1082. delete this.form.name);
  1083. for (let i in this.form) {
  1084. if (!this.form[i].toString()) {
  1085. return false;
  1086. }
  1087. }
  1088. return true;
  1089. },
  1090. // 如不完整,则提示
  1091. confirmComplete(val) {
  1092. if (this.validComplete(val)) {
  1093. return true;
  1094. }
  1095. this.$confirm(`请输入完整`, "提示", {
  1096. confirmButtonText: "确定",
  1097. cancelButtonText: "取消",
  1098. type: "warning",
  1099. })
  1100. .then(() => {
  1101. console.log("输入不完整");
  1102. })
  1103. .catch(() => {});
  1104. return false;
  1105. },
  1106. // 校验输入是否合法
  1107. validInput() {
  1108. // 出生日期是否有误
  1109. let birth = new Date(this.form.birthday);
  1110. let now = new Date();
  1111. let days = now.getTime() - birth.getTime();
  1112. if (days < 0) {
  1113. return false;
  1114. }
  1115. if (this.form.weight <= 0) {
  1116. return false;
  1117. }
  1118. // 只允许中文、英文、数字、-、_的输入,取反
  1119. const reg = /[^\a-\z\A-\Z0-9\u4E00-\u9FA5\_\-]/g;
  1120. if (reg.test(this.form.eartag)) {
  1121. return false;
  1122. }
  1123. if (reg.test(this.form.breed)) {
  1124. return false;
  1125. }
  1126. if (reg.test(this.form.whereDidYouGo)) {
  1127. return false;
  1128. }
  1129. return true;
  1130. },
  1131. // 如不合法,则提示
  1132. confirmInput() {
  1133. if (this.validInput()) {
  1134. return true;
  1135. }
  1136. this.$confirm(`请检查输入项是否合法`, "提示", {
  1137. confirmButtonText: "确定",
  1138. cancelButtonText: "取消",
  1139. type: "warning",
  1140. })
  1141. .then(() => {
  1142. console.log("输入不合法");
  1143. })
  1144. .catch(() => {});
  1145. return false;
  1146. },
  1147. // // 清空form
  1148. // resetForm() {
  1149. // // for (let i in this.form) {
  1150. // // this.form[i] = ''
  1151. // // }
  1152. // this.form.eartag = "";
  1153. // this.getDataList();
  1154. // },
  1155. // 取消
  1156. cancel() {
  1157. this.visible = false;
  1158. // this.resetForm();
  1159. },
  1160. },
  1161. watch: {
  1162. 'searchForm.pigstyId': {
  1163. handler(newValue, oldValue) {
  1164. if (oldValue) {
  1165. this.searchForm.unitId = ''
  1166. this.searchForm.periodId = ''
  1167. }
  1168. this.unitSelectedList = this.unitList.filter(item => item.pigstyId === newValue)
  1169. this.periodSelectedList = this.periodList.filter(item => item.pigstyId === newValue)
  1170. }
  1171. },
  1172. 'form.pigstyId': {
  1173. handler(newValue, oldValue) {
  1174. if (oldValue) {
  1175. this.form.unitId = ''
  1176. // this.form.periodId = ''
  1177. }
  1178. this.unitSelectedList = this.unitList.filter(item => item.pigstyId === newValue)
  1179. // this.periodSelectedList = this.periodList.filter(item => item.pigstyId === newValue)
  1180. }
  1181. }
  1182. }
  1183. }
  1184. </script>
  1185. <style scoped>
  1186. .rect {
  1187. background-color: #fff;
  1188. padding: 30px 15px;
  1189. border-radius: 5px;
  1190. border: 1px solid #e8e8e8;
  1191. }
  1192. .rect-form {
  1193. padding-bottom: 10px;
  1194. }
  1195. .rect-table {
  1196. margin-top: 20px;
  1197. }
  1198. .demo-table-expand {
  1199. font-size: 0;
  1200. margin-left: 40px;
  1201. }
  1202. .demo-table-expand label {
  1203. width: 90px;
  1204. color: #99a9bf;
  1205. }
  1206. .demo-table-expand .el-form-item {
  1207. margin-right: 0;
  1208. margin-bottom: 0;
  1209. width: 80%;
  1210. }
  1211. .el-table .height {
  1212. background: rgba(254, 254, 254, 0.5);
  1213. }
  1214. /* .cancelButton {
  1215. background-color: rgb(24,144,255) !important;
  1216. border-color: rgb(24,144,255) !important;
  1217. }
  1218. .confirmButton {
  1219. background-color: rgb(24,144,255) !important;
  1220. border-color: rgb(24,144,255) !important;
  1221. } */
  1222. /deep/ .el-table--mini td, .el-table--mini th {
  1223. padding: 3px 0 !important;
  1224. height: 20px !important;
  1225. }
  1226. /deep/ .el-checkbox__input.is-checked+.el-checkbox__label {
  1227. color: rgb(24,144,255);
  1228. background-color: rgb(24,144,255);
  1229. border-color: rgb(24,144,255);
  1230. }
  1231. /deep/.el-table .el-checkbox__input.is-checked .el-checkbox__inner, .el-checkbox__input.is-indeterminate .el-checkbox__inner {
  1232. background-color: rgb(24,144,255);
  1233. border-color: rgb(24,144,255);
  1234. }
  1235. /deep/.el-table .el-checkbox__inner:hover {
  1236. border-color: rgb(24,144,255);
  1237. }
  1238. /deep/.el-table .el-checkbox__input.is-focus .el-checkbox__inner {
  1239. border-color: rgb(24,144,255);
  1240. }
  1241. /deep/.el-table #select .cell .el-checkbox__input.is-checked .el-checkbox__inner, .el-checkbox__input.is-indeterminate .el-checkbox__inner {
  1242. background-color: rgb(24,144,255);
  1243. border-color: rgb(24,144,255);
  1244. }
  1245. /* /deep/.el-button--primary {
  1246. background-color: rgb(24,144,255);
  1247. border-color: rgb(24,144,255);
  1248. }
  1249. /deep/ .el-button--primary:focus, .el-button--primary:hover {
  1250. background-color: rgb(24,144,255);
  1251. border-color: rgb(24,144,255);
  1252. } */
  1253. /* .el-message-box__btns button:focus,.el-message-box__btns button:active {
  1254. background-color: rgb(24,144,255) !important;
  1255. border-color: rgb(24,144,255) !important;
  1256. } */
  1257. </style>