67b168bcf33bc4f55c37109c9bf231be1577a370.svn-base 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141
  1. <template>
  2. <div class="app-container">
  3. <div class="operation">
  4. <el-button v-if="isRoleEdit" class="success" style="float: left;margin-right:10px;" @click="handleCreate">新增</el-button>
  5. <el-button v-if="isRoleEdit" class="danger" style="float: left;margin-right:10px;" @click="handleDelete">删除</el-button>
  6. <el-button v-if="isRoleEdit" class="warning" style="float: left;margin-right:10px;" @click="handleCopy">复制</el-button>
  7. <el-upload v-if="isRoleEdit" style="float: right;" :headers="headers" :data="uploadData" :action="uploadExcelUrl" :show-file-list="false" :before-upload="beforeImport" :on-success="handleImportSuccess">
  8. <el-button class="import" style="float: right;">导入</el-button>
  9. </el-upload>
  10. <el-dropdown style="float: right;margin-right: 10px;">
  11. <el-button class="export">导出</el-button>
  12. <el-dropdown-menu slot="dropdown">
  13. <el-dropdown-item @click.native="handleExport(1)">导出模板</el-dropdown-item>
  14. <el-dropdown-item @click.native="handleExport(2)">导出数据</el-dropdown-item>
  15. </el-dropdown-menu>
  16. </el-dropdown>
  17. </div>
  18. <div class="search">
  19. <el-date-picker v-model="table.getdataListParm.parammaps.inputDatetime" class="inputDatetime filter-item" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" style="width: 250px;" />
  20. <el-button class="el-icon-arrow-left elIconArrowLeft" @click="handleBefore" />
  21. <el-button class="el-icon-arrow-right elIconArrowRight" @click="handleNext" />
  22. <el-select v-model="table.getdataListParm.parammaps.barid" filterable placeholder="栏舍名称" class="filter-item" style="width: 120px;" clearable>
  23. <el-option v-for="item in houseNameList" :key="item.id" :label="item.bname" :value="item.id" />
  24. </el-select>
  25. <el-select v-model="table.getdataListParm.parammaps.cowclass" filterable placeholder="牲畜类别" class="filter-item" style="width: 120px;" clearable>
  26. <el-option v-for="item in livestockList" :key="item.id" :label="item.mixname" :value="item.classname" />
  27. </el-select>
  28. <el-button class="successBorder" @click="handleSearch">查询</el-button>
  29. <el-button class="successBorder" @click="handleRefresh">重置</el-button>
  30. </div>
  31. <div class="table">
  32. <el-table
  33. :key="table.tableKey"
  34. v-loading="table.listLoading"
  35. element-loading-text="给我一点时间"
  36. :data="table.list"
  37. border
  38. fit
  39. highlight-current-row
  40. style="width: 100%;"
  41. :row-style="rowStyle"
  42. :cell-style="cellStyle"
  43. class="elTable table-fixed"
  44. @selection-change="handleSelectionChange"
  45. >
  46. <el-table-column type="selection" align="center" width="50" />
  47. <el-table-column label="序号" align="center" type="index" width="50px">
  48. <template slot-scope="scope">
  49. <span>{{ scope.$index + (table.pageNum-1) * table.pageSize + 1 }}</span>
  50. </template>
  51. </el-table-column>
  52. <el-table-column label="栏舍名称" min-width="150px" align="center">
  53. <template slot-scope="scope">
  54. <span>{{ scope.row.barname }}</span>
  55. </template>
  56. </el-table-column>
  57. <el-table-column label="牲畜类别" min-width="150px" align="center">
  58. <template slot-scope="scope">
  59. <span>{{ scope.row.cowclass }}</span>
  60. </template>
  61. </el-table-column>
  62. <el-table-column label="牛头数" min-width="90px" align="center">
  63. <template slot-scope="scope">
  64. <span>{{ scope.row.cowsum }}</span>
  65. </template>
  66. </el-table-column>
  67. <el-table-column label="月龄" min-width="90px" align="center">
  68. <template slot-scope="scope">
  69. <span>{{ scope.row.avgmonthage }}</span>
  70. </template>
  71. </el-table-column>
  72. <el-table-column label="体重(kg)" min-width="90px" align="center">
  73. <template slot-scope="scope">
  74. <span>{{ scope.row.bw }}</span>
  75. </template>
  76. </el-table-column>
  77. <el-table-column label="日增重(kg)" min-width="90px" align="center">
  78. <template slot-scope="scope">
  79. <span>{{ scope.row.dayw }}</span>
  80. </template>
  81. </el-table-column>
  82. <el-table-column label="胎次" min-width="80px" align="center">
  83. <template slot-scope="scope">
  84. <span>{{ scope.row.fetal }}</span>
  85. </template>
  86. </el-table-column>
  87. <el-table-column label="平均泌乳天数" min-width="110px" align="center">
  88. <template slot-scope="scope">
  89. <span>{{ scope.row.avgdim }}</span>
  90. </template>
  91. </el-table-column>
  92. <el-table-column label="怀孕天数" min-width="90px" align="center">
  93. <template slot-scope="scope">
  94. <span>{{ scope.row.dayspre }}</span>
  95. </template>
  96. </el-table-column>
  97. <el-table-column label="产奶量(kg/头)" min-width="110px" align="center">
  98. <template slot-scope="scope">
  99. <span>{{ scope.row.product }}</span>
  100. </template>
  101. </el-table-column>
  102. <el-table-column label="乳脂率(%)" min-width="90px" align="center">
  103. <template slot-scope="scope">
  104. <span>{{ scope.row.fat }}</span>
  105. </template>
  106. </el-table-column>
  107. <el-table-column label="乳蛋白率(%)" min-width="100px" align="center">
  108. <template slot-scope="scope">
  109. <span>{{ scope.row.pro }}</span>
  110. </template>
  111. </el-table-column>
  112. <el-table-column label="乳糖率(%)" min-width="90px" align="center">
  113. <template slot-scope="scope">
  114. <span>{{ scope.row.lactose }}</span>
  115. </template>
  116. </el-table-column>
  117. <el-table-column label="温度(℃)" min-width="110px" align="center">
  118. <template slot-scope="scope">
  119. <span>{{ scope.row.tem }}</span>
  120. </template>
  121. </el-table-column>
  122. <el-table-column label="记录人" min-width="90px" align="center">
  123. <template slot-scope="scope">
  124. <span>{{ scope.row.emp }}</span>
  125. </template>
  126. </el-table-column>
  127. <el-table-column label="生效时间" min-width="110px" align="center">
  128. <template slot-scope="scope">
  129. <span>{{ scope.row.productdate }}</span>
  130. </template>
  131. </el-table-column>
  132. <el-table-column label="操作" align="center" width="250" class-name="small-padding fixed-width" fixed="right">
  133. <template slot-scope="{row}">
  134. <el-button v-if="isRoleEdit" class="miniSuccess" @click="handleUpdate(row)">编辑</el-button>
  135. <el-button v-if="isRoleEdit" class="miniDanger" @click="handleRowDelete(row)">删除</el-button>
  136. </template>
  137. </el-table-column>
  138. </el-table>
  139. <pagination v-show="table.total>=0" :total="table.total" :page.sync="table.getdataListParm.offset" :limit.sync="table.getdataListParm.pagecount" @pagination="getList" />
  140. </div>
  141. <el-dialog :title="textMap[create.dialogStatus]" :visible.sync="create.dialogFormVisible" :close-on-click-modal="false" width="90%">
  142. <div class="app-add">
  143. <el-form ref="temp" :rules="create.rules" :model="create.temp" label-position="right" label-width="135px" style="width: 100%;margin:0 auto 50px">
  144. <el-row>
  145. <el-col :span="6">
  146. <el-form-item label="生效日期:" prop="productdate">
  147. <el-date-picker v-model="create.temp.productdate" type="date" placeholder="选择日期" format="yyyy-MM-dd" value-format="yyyy-MM-dd" style="width: 100%;" :clearable="false" :disabled="create.dialogStatus=='update'" />
  148. </el-form-item>
  149. </el-col>
  150. <el-col :span="6">
  151. <el-form-item label="记录人:" prop="emp">
  152. <el-select ref="emp" v-model="create.temp.emp" :disabled="create.dialogStatus=='update'" filterable placeholder="记录人" class="filter-item" style="width: 100%;" @blur="blurEmp">
  153. <el-option v-for="item in create.noteTakerList" :key="item.myId" :label="item.emp" :value="item.emp" />
  154. </el-select>
  155. </el-form-item>
  156. </el-col>
  157. </el-row>
  158. <el-row>
  159. <el-col :span="24">
  160. <h3 style="width: 160px;text-align: right;">栏舍信息</h3>
  161. </el-col>
  162. </el-row>
  163. <el-row>
  164. <el-col v-if="create.dialogStatus=='create'" :span="6">
  165. <el-form-item label="栏舍名称:" prop="barid">
  166. <el-select v-model="create.temp.barid" filterable placeholder="栏舍名称" class="filter-item" style="width: 100%;" @change="changeBar">
  167. <el-option v-for="item in houseNameList" :key="item.id" :label="item.bname" :value="item.id" />
  168. </el-select>
  169. </el-form-item>
  170. </el-col>
  171. <el-col v-else :span="6">
  172. <el-form-item label="栏舍名称:" prop="barname">
  173. <el-input ref="barname" v-model="create.temp.barname" disabled class="filter-item" placeholder="barname" />
  174. </el-form-item>
  175. </el-col>
  176. <el-col :span="6">
  177. <el-form-item label="牲畜类别:" prop="cowclassid">
  178. <el-select v-model="create.temp.cowclassid" :disabled="create.dialogStatus=='update'" filterable placeholder="牲畜类别" class="filter-item" style="width: 100%;" @change="changeCowclass">
  179. <el-option v-for="item in livestockList" :key="item.id" :label="item.mixname" :value="item.id" />
  180. </el-select>
  181. </el-form-item>
  182. </el-col>
  183. <el-col :span="6">
  184. <el-form-item label="牛头数:" prop="cowsum">
  185. <el-input ref="cowsum" v-model="create.temp.cowsum" class="filter-item" placeholder="正整数" type="number" step="0.01" />
  186. </el-form-item>
  187. </el-col>
  188. <el-col :span="6">
  189. <el-form-item label="环境温度(℃):" prop="tem">
  190. <el-input v-model="create.temp.tem" class="filter-item" placeholder="最多两位小数" type="number" step="0.01" />
  191. </el-form-item>
  192. </el-col>
  193. </el-row>
  194. <el-row>
  195. <el-col :span="24">
  196. <h3 style="width: 160px;text-align: right;">牛只基础信息</h3>
  197. </el-col>
  198. </el-row>
  199. <el-row>
  200. <el-col :span="6">
  201. <el-form-item label="平均月龄:" prop="avgmonthage">
  202. <el-input ref="avgmonthage" v-model="create.temp.avgmonthage" class="filter-item" placeholder="最多两位小数" type="number" step="0.01" />
  203. </el-form-item>
  204. </el-col>
  205. <el-col :span="6">
  206. <el-form-item label="体重(kg):" prop="bw">
  207. <el-input ref="bw" v-model="create.temp.bw" class="filter-item" placeholder="最多两位小数" type="number" step="0.01" />
  208. </el-form-item>
  209. </el-col>
  210. <el-col :span="6">
  211. <el-form-item label="日增重(kg):" prop="dayw">
  212. <el-input ref="dayw" v-model="create.temp.dayw" class="filter-item" placeholder="最多两位小数" type="number" step="0.01" />
  213. </el-form-item>
  214. </el-col>
  215. <el-col :span="6">
  216. <el-form-item label="怀孕天数:" prop="dayspre">
  217. <el-input ref="dayspre" v-model="create.temp.dayspre" class="filter-item" placeholder="0-280整数" type="number" />
  218. </el-form-item>
  219. </el-col>
  220. </el-row>
  221. <el-row>
  222. <el-col :span="6">
  223. <el-form-item label="胎次:" prop="fetal">
  224. <el-input ref="fetal" v-model="create.temp.fetal" :disabled="create.temp.bigcowclass=='后备牛' " class="filter-item" placeholder="0-20整数" type="number" />
  225. </el-form-item>
  226. </el-col>
  227. <el-col :span="6">
  228. <el-form-item label="平均泌乳天数:" prop="avgdim">
  229. <el-input ref="avgdim" v-model="create.temp.avgdim" :disabled="create.temp.bigcowclass=='后备牛' || create.temp.bigcowclass=='干奶牛'" class="filter-item" placeholder="正整数" type="number" />
  230. </el-form-item>
  231. </el-col>
  232. <el-col :span="6">
  233. <el-form-item label="产奶量(kg/头):" prop="product">
  234. <el-input ref="product" v-model="create.temp.product" :disabled="create.temp.bigcowclass=='后备牛' || create.temp.bigcowclass=='干奶牛'" class="filter-item" placeholder="最多两位小数" type="number" />
  235. </el-form-item>
  236. </el-col>
  237. <el-col :span="6">
  238. <el-form-item label="乳脂率(%)" prop="fat">
  239. <el-input ref="fat" v-model="create.temp.fat" :disabled="create.temp.bigcowclass=='后备牛' || create.temp.bigcowclass=='干奶牛'" class="filter-item" placeholder="最多两位小数" type="number" />
  240. </el-form-item>
  241. </el-col>
  242. </el-row>
  243. <el-row>
  244. <el-col :span="6">
  245. <el-form-item label="乳蛋白率(%):" prop="pro">
  246. <el-input ref="pro" v-model="create.temp.pro" :disabled="create.temp.bigcowclass=='后备牛' || create.temp.bigcowclass=='干奶牛'" class="filter-item" placeholder="最多两位小数" type="number" />
  247. </el-form-item>
  248. </el-col>
  249. <el-col :span="6">
  250. <el-form-item label="乳糖率(%):" prop="lactose">
  251. <el-input ref="lactose" v-model="create.temp.lactose" :disabled="create.temp.bigcowclass=='后备牛' || create.temp.bigcowclass=='干奶牛'" class="filter-item" placeholder="最多两位小数" type="number" />
  252. </el-form-item>
  253. </el-col>
  254. </el-row>
  255. </el-form>
  256. <div slot="footer" class="dialog-footer">
  257. <el-button class="cancelClose" @click="create.dialogFormVisible = false;getList()">关闭</el-button>
  258. <el-button v-if="create.dialogStatus==='create'" class="success" :disabled="isokDisable" @click="createDataAgain()">确认新增</el-button>
  259. <el-button v-if="create.dialogStatus==='create' || create.dialogStatus==='update'" class="success" :disabled="isokDisable" @click="create.dialogStatus==='create'?createData():updateData()">确认</el-button>
  260. </div>
  261. </div>
  262. </el-dialog>
  263. </div>
  264. </template>
  265. <script>
  266. import { GetDataByName, PostDataByName, failproccess, ExecDataByConfig, GetDataByNames, checkButtons } from '@/api/common'
  267. import Cookies from 'js-cookie'
  268. import { parseTime, json2excel } from '@/utils/index.js'
  269. import Pagination from '@/components/Pagination'
  270. import { MessageBox } from 'element-ui'
  271. import axios from 'axios'
  272. import { getToken } from '@/utils/auth'
  273. export default {
  274. name: 'Performance',
  275. components: { Pagination },
  276. data() {
  277. return {
  278. isRoleEdit: [],
  279. requestParams: [
  280. { name: 'getBarListEnable', offset: 0, pagecount: 0, parammaps: { 'pastureid': Cookies.get('pastureid') }},
  281. { name: 'getCowclassListEnable', offset: 0, pagecount: 0, parammaps: { 'pastureid': Cookies.get('pastureid') }}
  282. ],
  283. houseNameList: [], // 栏舍名称
  284. livestockList: [], // 牲畜类别
  285. table: {
  286. getdataListParm: {
  287. name: 'getBarmilkList',
  288. page: 1,
  289. offset: 1,
  290. pagecount: 10,
  291. returntype: 'Map',
  292. parammaps: {
  293. pastureid: Cookies.get('pastureid'),
  294. barid: '',
  295. cowclass: '',
  296. startTime: '',
  297. stopTime: '',
  298. inputDatetime: ''
  299. }
  300. },
  301. tableKey: 0,
  302. list: [],
  303. total: 0,
  304. listLoading: true,
  305. temp: {}
  306. },
  307. // 新增/编辑
  308. create: {
  309. dialogFormVisible: false,
  310. dialogStatus: '',
  311. temp: { pastureid: Cookies.get('pastureid'), productdate: parseTime(new Date(), '{y}-{m}-{d}'), emp: Cookies.get('employename'), barid: '', barname: '', cowclassid: '', cowclass: '', bigcowclass: '', cowsum: '', tem: '', avgmonthage: '', bw: '', dayw: '', dayspre: '', fetal: '', avgdim: '', product: '', fat: '', pro: '', lactose: '' },
  312. rules: {
  313. barid: [{ type: 'string', required: true, message: '必填', trigger: 'blur' }],
  314. cowclassid: [{ type: 'string', required: true, message: '必填', trigger: 'blur' }]
  315. },
  316. getdataListParm: {
  317. name: 'getBarmilkEmpHis',
  318. page: 1,
  319. offset: 1,
  320. pagecount: 10,
  321. returntype: 'Map',
  322. parammaps: {
  323. pastureid: Cookies.get('pastureid')
  324. }
  325. },
  326. noteTakerList: [] // 记录人
  327. },
  328. textMap: {
  329. create: '新增',
  330. update: '编辑'
  331. },
  332. requestParam: {},
  333. download: {
  334. getdataListParm: {
  335. name: 'getBarmilkList',
  336. page: 1,
  337. offset: 1,
  338. pagecount: 0,
  339. returntype: 'Map',
  340. parammaps: {
  341. pastureid: Cookies.get('pastureid'),
  342. barid: '',
  343. cowclass: '',
  344. startTime: '',
  345. stopTime: '',
  346. inputDatetime: ''
  347. }
  348. },
  349. list: []
  350. },
  351. isokDisable: false,
  352. selectList: [],
  353. rowStyle: { maxHeight: 50 + 'px', height: 45 + 'px' },
  354. cellStyle: { padding: 0 + 'px' }
  355. }
  356. },
  357. computed: {
  358. // 设置请求头
  359. headers() {
  360. return {
  361. token: getToken()
  362. }
  363. },
  364. uploadData() {
  365. return {
  366. name: 'checkbarname,checkclassname,insertBarmilkUpload',
  367. importParams: '栏舍名称,牲畜类别,牛头数,环境温度(℃),平均月龄,体重(kg),日增重(kg),怀孕天数,胎次,平均泌乳天数,产奶量(kg/头),乳脂率(%),乳蛋白率(%),乳糖率(%),记录人,生效日期',
  368. sheetname: 'Sheet1',
  369. // 登录牧场
  370. pastureid: Cookies.get('pastureid'),
  371. // 日期参数
  372. dateParams: '生效日期',
  373. // 必填参数
  374. requiredParams: '栏舍名称',
  375. // 为数值的参数
  376. numParams: '牛头数,环境温度(℃),平均月龄,体重(kg),日增重(kg),怀孕天数,胎次,平均泌乳天数,产奶量(kg/头),乳脂率(%),乳蛋白率(%),乳糖率(%)'
  377. }
  378. },
  379. // 设置上传地址
  380. uploadExcelUrl() {
  381. return process.env.VUE_APP_BASE_API + 'authdata/ImportExcel'
  382. }
  383. },
  384. created() {
  385. this.getList()
  386. this.getDownList()
  387. this.getButtons()
  388. },
  389. methods: {
  390. getButtons() {
  391. const Edit = 'Performance'
  392. const isRoleEdit = checkButtons(JSON.parse(sessionStorage.getItem('buttons')), Edit)
  393. this.isRoleEdit = isRoleEdit
  394. },
  395. getDownList() {
  396. GetDataByNames(this.requestParams).then(response => {
  397. this.houseNameList = response.data.getBarListEnable.list
  398. this.livestockList = response.data.getCowclassListEnable.list
  399. })
  400. },
  401. handleBefore() {
  402. if (this.table.getdataListParm.parammaps.inputDatetime !== '' && this.table.getdataListParm.parammaps.inputDatetime !== null) {
  403. var start = new Date(this.table.getdataListParm.parammaps.inputDatetime[0].setDate(this.table.getdataListParm.parammaps.inputDatetime[0].getDate() - 1))
  404. var stop = new Date(this.table.getdataListParm.parammaps.inputDatetime[1].setDate(this.table.getdataListParm.parammaps.inputDatetime[1].getDate() - 1))
  405. this.table.getdataListParm.parammaps.inputDatetime.length = 0
  406. this.table.getdataListParm.parammaps.inputDatetime.push(start, stop)
  407. this.$forceUpdate()
  408. }
  409. },
  410. handleNext() {
  411. if (this.table.getdataListParm.parammaps.inputDatetime !== '' && this.table.getdataListParm.parammaps.inputDatetime !== null) {
  412. var start = new Date(this.table.getdataListParm.parammaps.inputDatetime[0].setDate(this.table.getdataListParm.parammaps.inputDatetime[0].getDate() + 1))
  413. var stop = new Date(this.table.getdataListParm.parammaps.inputDatetime[1].setDate(this.table.getdataListParm.parammaps.inputDatetime[1].getDate() + 1))
  414. this.table.getdataListParm.parammaps.inputDatetime.length = 0
  415. this.table.getdataListParm.parammaps.inputDatetime.push(start, stop)
  416. this.$forceUpdate()
  417. }
  418. },
  419. getList() {
  420. this.table.listLoading = true
  421. GetDataByName(this.table.getdataListParm).then(response => {
  422. console.log('table数据', response.data.list)
  423. if (response.data.list !== null) {
  424. this.table.list = response.data.list
  425. this.table.pageNum = response.data.pageNum
  426. this.table.pageSize = response.data.pageSize
  427. this.table.total = response.data.total
  428. } else {
  429. this.table.list = []
  430. }
  431. setTimeout(() => {
  432. this.table.listLoading = false
  433. }, 100)
  434. })
  435. },
  436. handleSearch() {
  437. console.log('点击了查询')
  438. if (this.table.getdataListParm.parammaps.inputDatetime !== '' && this.table.getdataListParm.parammaps.inputDatetime !== null) {
  439. this.table.getdataListParm.parammaps.startTime = parseTime(this.table.getdataListParm.parammaps.inputDatetime[0], '{y}-{m}-{d}')
  440. this.table.getdataListParm.parammaps.stopTime = parseTime(this.table.getdataListParm.parammaps.inputDatetime[1], '{y}-{m}-{d}')
  441. } else {
  442. this.table.getdataListParm.parammaps.inputDatetime = ''
  443. this.table.getdataListParm.parammaps.startTime = ''
  444. this.table.getdataListParm.parammaps.stopTime = ''
  445. }
  446. this.table.getdataListParm.offset = 1
  447. this.getList()
  448. },
  449. handleRefresh() {
  450. console.log('点击了重置')
  451. this.table.getdataListParm.parammaps.barid = ''
  452. this.table.getdataListParm.parammaps.cowclass = ''
  453. this.table.getdataListParm.parammaps.startTime = ''
  454. this.table.getdataListParm.parammaps.stopTime = ''
  455. this.table.getdataListParm.parammaps.inputDatetime = ''
  456. this.table.getdataListParm.offset = 1
  457. this.getList()
  458. },
  459. // 新增
  460. resetTemp() {
  461. this.create.temp = { pastureid: Cookies.get('pastureid'), productdate: parseTime(new Date(), '{y}-{m}-{d}'), emp: Cookies.get('employename'), barid: '', barname: '', cowclassid: '', cowclass: '', bigcowclass: '', cowsum: '', tem: '', avgmonthage: '', bw: '', dayw: '', dayspre: '', fetal: '', avgdim: '', product: '', fat: '', pro: '', lactose: '' }
  462. },
  463. blurEmp(item) {
  464. this.create.temp.emp = item.target.value
  465. },
  466. // 栏舍名称
  467. changeBar(item) {
  468. this.create.temp.barname = this.houseNameList.find(obj => obj.id === item).bname
  469. },
  470. // 牲畜类别
  471. changeCowclass(item) {
  472. this.create.temp.cowclass = this.livestockList.find(obj => obj.id === item).classname
  473. this.create.temp.bigcowclass = this.livestockList.find(obj => obj.id === item).parentname
  474. },
  475. getNoteTakerList() {
  476. GetDataByName(this.create.getdataListParm).then(response => {
  477. if (response.data.list !== null) {
  478. for (let i = 0; i < response.data.list.length; i++) {
  479. response.data.list[i].myId = i
  480. }
  481. this.create.noteTakerList = response.data.list
  482. console.log('记录人数据', response.data.list)
  483. console.log(this.create.noteTakerList)
  484. } else {
  485. this.create.noteTakerList = []
  486. }
  487. })
  488. },
  489. handleCreate() {
  490. console.log('点击了新增')
  491. this.resetTemp()
  492. this.getNoteTakerList()
  493. this.create.dialogStatus = 'create'
  494. this.create.dialogFormVisible = true
  495. },
  496. createData() {
  497. console.log('点击了新增保存')
  498. this.isokDisable = true
  499. setTimeout(() => {
  500. this.isokDisable = false
  501. }, 1000)
  502. this.$refs['temp'].validate(valid => {
  503. if (valid) {
  504. this.isokDisable = true
  505. setTimeout(() => {
  506. this.isokDisable = false
  507. }, 1000)
  508. const positiveInteger = /^[1-9]\d*$/
  509. // 牛头数
  510. if (this.create.temp.cowsum !== '') {
  511. if (!positiveInteger.test(parseFloat(this.create.temp.cowsum))) {
  512. this.$message({ type: 'error', message: '牛头数请输入正整数', duration: 2000 })
  513. return false
  514. }
  515. }
  516. const twoDecimalPlaces = /^\d+(\.\d{1,2})?$/
  517. // 温度环境
  518. if (this.create.temp.tem !== '') {
  519. if (!twoDecimalPlaces.test(parseFloat(this.create.temp.tem))) {
  520. this.$message({ type: 'error', message: '温度环境请保留两位小数', duration: 2000 })
  521. return false
  522. }
  523. }
  524. // 平均月龄
  525. if (this.create.temp.avgmonthage !== '') {
  526. if (!twoDecimalPlaces.test(parseFloat(this.create.temp.avgmonthage))) {
  527. this.$message({ type: 'error', message: '平均月龄请保留两位小数', duration: 2000 })
  528. return false
  529. }
  530. }
  531. // 体重
  532. if (this.create.temp.bw !== '') {
  533. if (!twoDecimalPlaces.test(parseFloat(this.create.temp.bw))) {
  534. this.$message({ type: 'error', message: '体重请保留两位小数', duration: 2000 })
  535. return false
  536. }
  537. }
  538. // 日增重
  539. if (this.create.temp.dayw !== '') {
  540. if (!twoDecimalPlaces.test(parseFloat(this.create.temp.dayw))) {
  541. this.$message({ type: 'error', message: '日增重请保留两位小数', duration: 2000 })
  542. return false
  543. }
  544. }
  545. const dayspre = /^(([1-9]|([1-9]\d)|(1\d\d)|(2([0-7]\d|7[0-9]))))$/
  546. // 怀孕天数
  547. if (this.create.temp.dayspre !== '') {
  548. if (!dayspre.test(parseFloat(this.create.temp.dayspre))) {
  549. this.$message({ type: 'error', message: '怀孕天数请输入大于0小于280整数', duration: 2000 })
  550. return false
  551. }
  552. }
  553. const fetal = /^(?:[1-9]|1[0-9])$/
  554. // 胎次
  555. if (this.create.temp.fetal !== '') {
  556. if (!fetal.test(parseFloat(this.create.temp.fetal))) {
  557. this.$message({ type: 'error', message: '胎次请输入大于0小于20整数', duration: 2000 })
  558. return false
  559. }
  560. }
  561. // 平均泌乳
  562. if (this.create.temp.avgdim !== '') {
  563. if (!positiveInteger.test(parseFloat(this.create.temp.avgdim))) {
  564. this.$message({ type: 'error', message: '平均泌乳天数请输入正整数', duration: 2000 })
  565. return false
  566. }
  567. }
  568. // 产奶量
  569. if (this.create.temp.product !== '') {
  570. if (!twoDecimalPlaces.test(parseFloat(this.create.temp.product))) {
  571. this.$message({ type: 'error', message: '产奶量请保留两位小数', duration: 2000 })
  572. return false
  573. }
  574. }
  575. // 乳脂率
  576. if (this.create.temp.fat !== '') {
  577. if (!twoDecimalPlaces.test(parseFloat(this.create.temp.fat))) {
  578. this.$message({ type: 'error', message: '乳脂率请保留两位小数', duration: 2000 })
  579. return false
  580. }
  581. }
  582. // 乳蛋白率
  583. if (this.create.temp.pro !== '') {
  584. if (!twoDecimalPlaces.test(parseFloat(this.create.temp.pro))) {
  585. this.$message({ type: 'error', message: '乳蛋白率请保留两位小数', duration: 2000 })
  586. return false
  587. }
  588. }
  589. // 乳糖率
  590. if (this.create.temp.lactose !== '') {
  591. if (!twoDecimalPlaces.test(parseFloat(this.create.temp.lactose))) {
  592. this.$message({ type: 'error', message: '乳糖率请保留两位小数', duration: 2000 })
  593. return false
  594. }
  595. }
  596. this.requestParam.name = 'insertBarmilk'
  597. this.requestParam.parammaps = this.create.temp
  598. if (this.create.temp.cowsum == '') { this.create.temp.cowsum = '0' }
  599. if (this.create.temp.tem == '') { this.create.temp.tem = '0' }
  600. if (this.create.temp.avgmonthage == '') { this.create.temp.avgmonthage = '0' }
  601. if (this.create.temp.bw == '') { this.create.temp.bw = '0' }
  602. if (this.create.temp.dayw == '') { this.create.temp.dayw = '0' }
  603. if (this.create.temp.dayspre == '') { this.create.temp.dayspre = '0' }
  604. if (this.create.temp.fetal == '') { this.create.temp.fetal = '0' }
  605. if (this.create.temp.avgdim == '') { this.create.temp.avgdim = '0' }
  606. if (this.create.temp.product == '') { this.create.temp.product = '0' }
  607. if (this.create.temp.fat == '') { this.create.temp.fat = '0' }
  608. if (this.create.temp.pro == '') { this.create.temp.pro = '0' }
  609. if (this.create.temp.lactose == '') { this.create.temp.lactose = '0' }
  610. PostDataByName(this.requestParam).then(response => {
  611. console.log('新增保存发送参数', this.requestParam)
  612. if (response.msg !== 'fail') {
  613. this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
  614. this.create.dialogFormVisible = false
  615. this.getList()
  616. } else {
  617. const barid = new RegExp("key 'barid'")
  618. if (barid.test(response.data)) {
  619. this.$message({ type: 'error', message: '该栏舍今日生产性能已存在,不可重复生成', duration: 2000 })
  620. } else {
  621. this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
  622. }
  623. if (this.create.temp.cowsum == '0') { this.create.temp.cowsum = '' }
  624. if (this.create.temp.tem == '0') { this.create.temp.tem = '' }
  625. if (this.create.temp.avgmonthage == '0') { this.create.temp.avgmonthage = '' }
  626. if (this.create.temp.bw == '0') { this.create.temp.bw = '' }
  627. if (this.create.temp.dayw == '0') { this.create.temp.dayw = '' }
  628. if (this.create.temp.dayspre == '0') { this.create.temp.dayspre = '' }
  629. if (this.create.temp.fetal == '0') { this.create.temp.fetal = '' }
  630. if (this.create.temp.avgdim == '0') { this.create.temp.avgdim = '' }
  631. if (this.create.temp.product == '0') { this.create.temp.product = '' }
  632. if (this.create.temp.fat == '0') { this.create.temp.fat = '' }
  633. if (this.create.temp.pro == '0') { this.create.temp.pro = '' }
  634. if (this.create.temp.lactose == '0') { this.create.temp.lactose = '' }
  635. }
  636. })
  637. }
  638. })
  639. },
  640. createDataAgain() {
  641. console.log('点击了新增保存')
  642. this.isokDisable = true
  643. setTimeout(() => {
  644. this.isokDisable = false
  645. }, 1000)
  646. this.$refs['temp'].validate(valid => {
  647. if (valid) {
  648. this.isokDisable = true
  649. setTimeout(() => {
  650. this.isokDisable = false
  651. }, 1000)
  652. const positiveInteger = /^[1-9]\d*$/
  653. // 牛头数
  654. if (this.create.temp.cowsum !== '') {
  655. if (!positiveInteger.test(parseFloat(this.create.temp.cowsum))) {
  656. this.$message({ type: 'error', message: '牛头数请输入正整数', duration: 2000 })
  657. return false
  658. }
  659. }
  660. const twoDecimalPlaces = /^\d+(\.\d{1,2})?$/
  661. // 温度环境
  662. if (this.create.temp.tem !== '') {
  663. if (!twoDecimalPlaces.test(parseFloat(this.create.temp.tem))) {
  664. this.$message({ type: 'error', message: '温度环境请保留两位小数', duration: 2000 })
  665. return false
  666. }
  667. }
  668. // 平均月龄
  669. if (this.create.temp.avgmonthage !== '') {
  670. if (!twoDecimalPlaces.test(parseFloat(this.create.temp.avgmonthage))) {
  671. this.$message({ type: 'error', message: '平均月龄请保留两位小数', duration: 2000 })
  672. return false
  673. }
  674. }
  675. // 体重
  676. if (this.create.temp.bw !== '') {
  677. if (!twoDecimalPlaces.test(parseFloat(this.create.temp.bw))) {
  678. this.$message({ type: 'error', message: '体重请保留两位小数', duration: 2000 })
  679. return false
  680. }
  681. }
  682. // 日增重
  683. if (this.create.temp.dayw !== '') {
  684. if (!twoDecimalPlaces.test(parseFloat(this.create.temp.dayw))) {
  685. this.$message({ type: 'error', message: '日增重请保留两位小数', duration: 2000 })
  686. return false
  687. }
  688. }
  689. const dayspre = /^(([1-9]|([1-9]\d)|(1\d\d)|(2([0-7]\d|7[0-9]))))$/
  690. // 怀孕天数
  691. if (this.create.temp.dayspre !== '') {
  692. if (!dayspre.test(parseFloat(this.create.temp.dayspre))) {
  693. this.$message({ type: 'error', message: '怀孕天数请输入大于0小于280整数', duration: 2000 })
  694. return false
  695. }
  696. }
  697. const fetal = /^(?:[1-9]|1[0-9])$/
  698. // 胎次
  699. if (this.create.temp.fetal !== '') {
  700. if (!fetal.test(parseFloat(this.create.temp.fetal))) {
  701. this.$message({ type: 'error', message: '胎次请输入大于0小于20整数', duration: 2000 })
  702. return false
  703. }
  704. }
  705. // 平均泌乳
  706. if (this.create.temp.avgdim !== '') {
  707. if (!positiveInteger.test(parseFloat(this.create.temp.avgdim))) {
  708. this.$message({ type: 'error', message: '平均泌乳天数请输入正整数', duration: 2000 })
  709. return false
  710. }
  711. }
  712. // 产奶量
  713. if (this.create.temp.product !== '') {
  714. if (!twoDecimalPlaces.test(parseFloat(this.create.temp.product))) {
  715. this.$message({ type: 'error', message: '产奶量请保留两位小数', duration: 2000 })
  716. return false
  717. }
  718. }
  719. // 乳脂率
  720. if (this.create.temp.fat !== '') {
  721. if (!twoDecimalPlaces.test(parseFloat(this.create.temp.fat))) {
  722. this.$message({ type: 'error', message: '乳脂率请保留两位小数', duration: 2000 })
  723. return false
  724. }
  725. }
  726. // 乳蛋白率
  727. if (this.create.temp.pro !== '') {
  728. if (!twoDecimalPlaces.test(parseFloat(this.create.temp.pro))) {
  729. this.$message({ type: 'error', message: '乳蛋白率请保留两位小数', duration: 2000 })
  730. return false
  731. }
  732. }
  733. // 乳糖率
  734. if (this.create.temp.lactose !== '') {
  735. if (!twoDecimalPlaces.test(parseFloat(this.create.temp.lactose))) {
  736. this.$message({ type: 'error', message: '乳糖率请保留两位小数', duration: 2000 })
  737. return false
  738. }
  739. }
  740. this.requestParam.name = 'insertBarmilk'
  741. this.requestParam.parammaps = this.create.temp
  742. if (this.create.temp.cowsum == '') { this.create.temp.cowsum = '0' }
  743. if (this.create.temp.tem == '') { this.create.temp.tem = '0' }
  744. if (this.create.temp.avgmonthage == '') { this.create.temp.avgmonthage = '0' }
  745. if (this.create.temp.bw == '') { this.create.temp.bw = '0' }
  746. if (this.create.temp.dayw == '') { this.create.temp.dayw = '0' }
  747. if (this.create.temp.dayspre == '') { this.create.temp.dayspre = '0' }
  748. if (this.create.temp.fetal == '') { this.create.temp.fetal = '0' }
  749. if (this.create.temp.avgdim == '') { this.create.temp.avgdim = '0' }
  750. if (this.create.temp.product == '') { this.create.temp.product = '0' }
  751. if (this.create.temp.fat == '') { this.create.temp.fat = '0' }
  752. if (this.create.temp.pro == '') { this.create.temp.pro = '0' }
  753. if (this.create.temp.lactose == '') { this.create.temp.lactose = '0' }
  754. PostDataByName(this.requestParam).then(response => {
  755. console.log('新增保存发送参数', this.requestParam)
  756. if (response.msg !== 'fail') {
  757. this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
  758. this.resetTemp()
  759. this.create.noteTakerList = []
  760. this.getNoteTakerList()
  761. } else {
  762. const barid = new RegExp("key 'barid'")
  763. if (barid.test(response.data)) {
  764. this.$message({ type: 'error', message: '该栏舍今日生产性能已存在,不可重复生成', duration: 2000 })
  765. } else {
  766. this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
  767. }
  768. if (this.create.temp.cowsum == '0') { this.create.temp.cowsum = '' }
  769. if (this.create.temp.tem == '0') { this.create.temp.tem = '' }
  770. if (this.create.temp.avgmonthage == '0') { this.create.temp.avgmonthage = '' }
  771. if (this.create.temp.bw == '0') { this.create.temp.bw = '' }
  772. if (this.create.temp.dayw == '0') { this.create.temp.dayw = '' }
  773. if (this.create.temp.dayspre == '0') { this.create.temp.dayspre = '' }
  774. if (this.create.temp.fetal == '0') { this.create.temp.fetal = '' }
  775. if (this.create.temp.avgdim == '0') { this.create.temp.avgdim = '' }
  776. if (this.create.temp.product == '0') { this.create.temp.product = '' }
  777. if (this.create.temp.fat == '0') { this.create.temp.fat = '' }
  778. if (this.create.temp.pro == '0') { this.create.temp.pro = '' }
  779. if (this.create.temp.lactose == '0') { this.create.temp.lactose = '' }
  780. }
  781. })
  782. }
  783. })
  784. },
  785. // 编辑
  786. handleUpdate(row) {
  787. console.log('点击了编辑', row)
  788. row.barid = String(row.barid)
  789. row.cowclassid = String(row.cowclassid)
  790. this.create.temp = Object.assign({}, row)
  791. this.create.temp.id = row.id
  792. if (this.create.temp.cowsum == '0') { this.create.temp.cowsum = '' }
  793. if (this.create.temp.avgdim == '0') { this.create.temp.avgdim = '' }
  794. if (this.create.temp.dayspre == '0') { this.create.temp.dayspre = '' }
  795. if (this.create.temp.fetal == '0') { this.create.temp.fetal = '' }
  796. this.getNoteTakerList()
  797. this.create.dialogStatus = 'update'
  798. this.create.dialogFormVisible = true
  799. },
  800. updateData() {
  801. this.isokDisable = true
  802. setTimeout(() => {
  803. this.isokDisable = false
  804. }, 1000)
  805. this.$refs['temp'].validate(valid => {
  806. if (valid) {
  807. this.isokDisable = true
  808. setTimeout(() => {
  809. this.isokDisable = false
  810. }, 1000)
  811. const positiveInteger = /^[1-9]\d*$/
  812. // 牛头数
  813. if (this.create.temp.cowsum !== '') {
  814. if (!positiveInteger.test(parseFloat(this.create.temp.cowsum))) {
  815. this.$message({ type: 'error', message: '牛头数请输入正整数', duration: 2000 })
  816. return false
  817. }
  818. }
  819. const twoDecimalPlaces = /^\d+(\.\d{1,2})?$/
  820. // 温度环境
  821. if (this.create.temp.tem !== '') {
  822. if (!twoDecimalPlaces.test(parseFloat(this.create.temp.tem))) {
  823. this.$message({ type: 'error', message: '温度环境请保留两位小数', duration: 2000 })
  824. return false
  825. }
  826. }
  827. // 平均月龄
  828. if (this.create.temp.avgmonthage !== '') {
  829. if (!twoDecimalPlaces.test(parseFloat(this.create.temp.avgmonthage))) {
  830. this.$message({ type: 'error', message: '平均月龄请保留两位小数', duration: 2000 })
  831. return false
  832. }
  833. }
  834. // 体重
  835. if (this.create.temp.bw !== '') {
  836. if (!twoDecimalPlaces.test(parseFloat(this.create.temp.bw))) {
  837. this.$message({ type: 'error', message: '体重请保留两位小数', duration: 2000 })
  838. return false
  839. }
  840. }
  841. // 日增重
  842. if (this.create.temp.dayw !== '') {
  843. if (!twoDecimalPlaces.test(parseFloat(this.create.temp.dayw))) {
  844. this.$message({ type: 'error', message: '日增重请保留两位小数', duration: 2000 })
  845. return false
  846. }
  847. }
  848. const dayspre = /^(([1-9]|([1-9]\d)|(1\d\d)|(2([0-7]\d|7[0-9]))))$/
  849. // 怀孕天数
  850. if (this.create.temp.dayspre !== '') {
  851. if (!dayspre.test(parseFloat(this.create.temp.dayspre))) {
  852. this.$message({ type: 'error', message: '怀孕天数请输入大于0小于280整数', duration: 2000 })
  853. return false
  854. }
  855. }
  856. const fetal = /^(?:[1-9]|1[0-9])$/
  857. // 胎次
  858. if (this.create.temp.fetal !== '') {
  859. if (!fetal.test(parseFloat(this.create.temp.fetal))) {
  860. this.$message({ type: 'error', message: '胎次请输入大于0小于20整数', duration: 2000 })
  861. return false
  862. }
  863. }
  864. // 平均泌乳
  865. if (this.create.temp.avgdim !== '') {
  866. if (!positiveInteger.test(parseFloat(this.create.temp.avgdim))) {
  867. this.$message({ type: 'error', message: '平均泌乳天数请输入正整数', duration: 2000 })
  868. return false
  869. }
  870. }
  871. // 产奶量
  872. if (this.create.temp.product !== '') {
  873. if (!twoDecimalPlaces.test(parseFloat(this.create.temp.product))) {
  874. this.$message({ type: 'error', message: '产奶量请保留两位小数', duration: 2000 })
  875. return false
  876. }
  877. }
  878. // 乳脂率
  879. if (this.create.temp.fat !== '') {
  880. if (!twoDecimalPlaces.test(parseFloat(this.create.temp.fat))) {
  881. this.$message({ type: 'error', message: '乳脂率请保留两位小数', duration: 2000 })
  882. return false
  883. }
  884. }
  885. // 乳蛋白率
  886. if (this.create.temp.pro !== '') {
  887. if (!twoDecimalPlaces.test(parseFloat(this.create.temp.pro))) {
  888. this.$message({ type: 'error', message: '乳蛋白率请保留两位小数', duration: 2000 })
  889. return false
  890. }
  891. }
  892. // 乳糖率
  893. if (this.create.temp.lactose !== '') {
  894. if (!twoDecimalPlaces.test(parseFloat(this.create.temp.lactose))) {
  895. this.$message({ type: 'error', message: '乳糖率请保留两位小数', duration: 2000 })
  896. return false
  897. }
  898. }
  899. this.requestParam.name = 'updateBarmilk'
  900. this.requestParam.parammaps = this.create.temp
  901. if (this.create.temp.cowsum == '') { this.create.temp.cowsum = '0' }
  902. if (this.create.temp.tem == '') { this.create.temp.tem = '0' }
  903. if (this.create.temp.avgmonthage == '') { this.create.temp.avgmonthage = '0' }
  904. if (this.create.temp.bw == '') { this.create.temp.bw = '0' }
  905. if (this.create.temp.dayw == '') { this.create.temp.dayw = '0' }
  906. if (this.create.temp.dayspre == '') { this.create.temp.dayspre = '0' }
  907. if (this.create.temp.fetal == '') { this.create.temp.fetal = '0' }
  908. if (this.create.temp.avgdim == '') { this.create.temp.avgdim = '0' }
  909. if (this.create.temp.product == '') { this.create.temp.product = '0' }
  910. if (this.create.temp.fat == '') { this.create.temp.fat = '0' }
  911. if (this.create.temp.pro == '') { this.create.temp.pro = '0' }
  912. if (this.create.temp.lactose == '') { this.create.temp.lactose = '0' }
  913. PostDataByName(this.requestParam).then(response => {
  914. console.log('新增保存发送参数', this.requestParam)
  915. if (response.msg !== 'fail') {
  916. this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
  917. this.create.dialogFormVisible = false
  918. this.getList()
  919. } else {
  920. this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
  921. if (this.create.temp.dayspre == '0') { this.create.temp.dayspre = '' }
  922. if (this.create.temp.fetal == '0') { this.create.temp.fetal = '' }
  923. if (this.create.temp.cowsum == '0') { this.create.temp.cowsum = '' }
  924. if (this.create.temp.avgdim == '0') { this.create.temp.avgdim = '' }
  925. }
  926. })
  927. }
  928. })
  929. },
  930. // 删除
  931. handleRowDelete(row) {
  932. console.log('点击了行内删除')
  933. MessageBox.confirm('是否确认删除此信息?', {
  934. confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
  935. }).then(() => {
  936. this.selectList = []
  937. this.requestParam.name = 'deleteBarmilk'
  938. this.requestParam.parammaps = {}
  939. this.requestParam.parammaps.pastureid = row.pastureid
  940. this.requestParam.parammaps.id = row.id
  941. PostDataByName(this.requestParam).then(response => {
  942. if (response.msg === 'fail') {
  943. this.$notify({ title: '删除失败', message: response.data, type: 'warning', duration: 2000 })
  944. } else {
  945. this.$notify({ title: '成功', message: '删除成功', type: 'success', duration: 2000 })
  946. this.getList()
  947. }
  948. })
  949. }).catch(() => {
  950. this.$message({ type: 'info', message: '已取消删除' })
  951. })
  952. },
  953. handleSelectionChange(val) {
  954. console.log('勾选数据', val)
  955. this.selectList = val
  956. },
  957. handleDelete() {
  958. console.log('点击了删除')
  959. if (this.selectList.length == 0) {
  960. this.$message({ type: 'error', message: '请选择栏舍生产性能', duration: 2000 })
  961. } else {
  962. MessageBox.confirm('当前选中' + this.selectList.length + '条信息,是否删除?', {
  963. confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
  964. }).then(() => {
  965. console.log(this.selectList)
  966. this.requestParam.common = { 'returnmap': '0' }
  967. this.requestParam.data = []
  968. this.requestParam.data[0] = { 'name': 'insertSpotList', 'resultmaps': { 'list': this.selectList }}
  969. this.requestParam.data[0].children = []
  970. this.requestParam.data[0].children[0] = { 'name': 'deleteBarmilk', 'type': 'e', 'parammaps': {
  971. id: '@insertSpotList.id',
  972. pastureid: '@insertSpotList.pastureid'
  973. }}
  974. ExecDataByConfig(this.requestParam).then(response => {
  975. console.log('删除保存发送参数', this.requestParam)
  976. if (response.msg === 'fail') {
  977. this.$notify({ title: '删除失败', message: response.data, type: 'warning', duration: 2000 })
  978. } else {
  979. this.$notify({ title: '', message: '删除成功', type: 'success', duration: 2000 })
  980. this.getList()
  981. }
  982. })
  983. })
  984. }
  985. },
  986. // 复制
  987. handleCopy() {
  988. console.log('点击了复制')
  989. if (this.selectList.length == 0) {
  990. this.$message({ type: 'error', message: '请选择栏舍生产性能', duration: 2000 })
  991. } else if (this.selectList.length == 1) {
  992. MessageBox.confirm('是否确认复制此信息?', {
  993. confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
  994. }).then(() => {
  995. this.requestParam.name = 'copybarmilk'
  996. this.requestParam.parammaps = {}
  997. this.requestParam.parammaps.pastureid = this.selectList[0].pastureid
  998. this.requestParam.parammaps.id = this.selectList[0].id
  999. PostDataByName(this.requestParam).then(response => {
  1000. if (response.msg === 'fail') {
  1001. const barid = new RegExp("key 'barid'")
  1002. if (barid.test(response.data)) {
  1003. this.$message({ type: 'error', message: '该栏舍今日生产性能已存在,不可重复生成', duration: 2000 })
  1004. } else {
  1005. this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
  1006. }
  1007. } else {
  1008. this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
  1009. this.getList()
  1010. }
  1011. })
  1012. }).catch(() => {
  1013. this.$message({ type: 'info', message: '已取消删除' })
  1014. })
  1015. } else {
  1016. this.$message({ type: 'error', message: '请选择一条栏舍生产性能', duration: 2000 })
  1017. }
  1018. },
  1019. // 导出
  1020. handleExport(item) {
  1021. if (item == 1) {
  1022. console.log('点击了导出模板')
  1023. // https://kptyun.cn:8081/file/导入导出模板/栏舍生产/栏舍生产性能导入模板.xlsx
  1024. const requestParam = this.requestParam
  1025. const url = process.env.VUE_APP_BASE_API + 'file/导入导出模板/栏舍生产/栏舍生产性能导入模板.xlsx' // 请求下载文件的地址
  1026. console.log(url)
  1027. axios({
  1028. method: 'GET',
  1029. url: url,
  1030. data: requestParam,
  1031. headers: { token: getToken(), optname: 'insertcustomdoc' },
  1032. responseType: 'blob'
  1033. }).then(res => {
  1034. if (!res) return
  1035. this.percentage = 99
  1036. setTimeout(() => {
  1037. this.isPercentage = false
  1038. }, 2000)
  1039. const blob = new Blob([res.data], {
  1040. type: 'application/octet-stream;charset=utf-8'
  1041. })
  1042. const url = window.URL.createObjectURL(blob)
  1043. const aLink = document.createElement('a')
  1044. aLink.style.display = 'none'
  1045. aLink.href = url
  1046. const docname = '栏舍生产性能导入模板.xlsx'
  1047. aLink.setAttribute('download', docname) // 下载的文件
  1048. document.body.appendChild(aLink)
  1049. aLink.click()
  1050. document.body.removeChild(aLink)
  1051. window.URL.revokeObjectURL(url)
  1052. })
  1053. } else {
  1054. console.log('点击了导出数据')
  1055. this.download.getdataListParm.parammaps = this.table.getdataListParm.parammaps
  1056. if (this.download.getdataListParm.parammaps.inputDatetime !== '' && this.download.getdataListParm.parammaps.inputDatetime !== null) {
  1057. this.download.getdataListParm.parammaps.startTime = parseTime(this.download.getdataListParm.parammaps.inputDatetime[0], '{y}-{m}-{d}')
  1058. this.download.getdataListParm.parammaps.stopTime = parseTime(this.download.getdataListParm.parammaps.inputDatetime[1], '{y}-{m}-{d}')
  1059. } else {
  1060. this.download.getdataListParm.parammaps.inputDatetime = ''
  1061. this.download.getdataListParm.parammaps.startTime = ''
  1062. this.download.getdataListParm.parammaps.stopTime = ''
  1063. }
  1064. GetDataByName(this.download.getdataListParm).then(response => {
  1065. if (response.data.list !== null) {
  1066. this.download.list = response.data.list
  1067. } else {
  1068. this.download.list = []
  1069. }
  1070. var excelDatas = [
  1071. {
  1072. tHeader: ['栏舍名称', '牲畜类别', '牛头数', '环境温度(℃)', '平均月龄', '体重(kg)', '日增重(kg)', '怀孕天数', '胎次', '平均泌乳天数', '产奶量(kg/头)', '乳脂率(%)', '乳蛋白率(%)', '乳糖率(%)', '记录人', '生效日期'],
  1073. filterVal: ['barname', 'cowclass', 'cowsum', 'tem', 'avgmonthage', 'bw', 'dayw', 'dayspre', 'fetal', 'avgdim', 'product', 'fat', 'pro', 'lactose', 'emp', 'productdate'],
  1074. tableDatas: this.download.list,
  1075. sheetName: 'Sheet1'
  1076. }
  1077. ]
  1078. json2excel(excelDatas, '栏舍生产性能', true, 'xlsx')
  1079. })
  1080. }
  1081. },
  1082. beforeImport(file) {
  1083. const isLt2M = file.size / 1024 / 1024 < 2
  1084. if (!isLt2M) {
  1085. this.$message.error('上传文件大小不能超过 2MB!')
  1086. }
  1087. return isLt2M
  1088. },
  1089. handleImportSuccess(res, file) {
  1090. this.getList()
  1091. if (res.msg === 'ok') {
  1092. this.$message({ title: '成功', message: '导入成功:' + res.data.success + '条!', type: 'success', duration: 2000 })
  1093. if (res.data.err_count > 0) {
  1094. this.$notify({ title: '失败', message: '导入失败:' + res.data.err_count + '条!', type: 'danger', duration: 2000 })
  1095. import('@/vendor/Export2Excel').then(excel => {
  1096. const list1 = res.data.result
  1097. const tHeader = [
  1098. '栏舍名称', '牲畜类别', '牛头数', '环境温度(℃)', '平均月龄', '体重(kg)', '日增重(kg)', '怀孕天数', '胎次', '平均泌乳天数', '产奶量(kg/头)', '乳脂率(%)', '乳蛋白率(%)', '乳糖率(%)', '记录人', '生效日期', '错误信息'
  1099. ]
  1100. const filterVal = [
  1101. '栏舍名称', '牲畜类别', '牛头数', '环境温度(℃)', '平均月龄', '体重(kg)', '日增重(kg)', '怀孕天数', '胎次', '平均泌乳天数', '产奶量(kg/头)', '乳脂率(%)', '乳蛋白率(%)', '乳糖率(%)', '记录人', '生效日期', 'error_msg'
  1102. ]
  1103. const data1 = this.formatJson(filterVal, list1)
  1104. excel.export_json_to_excel({ header: tHeader, data: data1, filename: '栏舍生产性能导入报错信息', autoWidth: true, bookType: 'xlsx' })
  1105. })
  1106. }
  1107. } else {
  1108. this.$notify({ title: '失败', message: '上传失败', type: 'danger', duration: 2000 })
  1109. }
  1110. },
  1111. formatJson(filterVal, jsonData) {
  1112. return jsonData.map(v =>
  1113. filterVal.map(j => {
  1114. if (j === 'timestamp') {
  1115. return parseTime(v[j])
  1116. } else {
  1117. return v[j]
  1118. }
  1119. })
  1120. )
  1121. }
  1122. }
  1123. }
  1124. </script>
  1125. <style lang="scss" scoped>
  1126. .search{padding-top:10px;clear: both;}
  1127. .table{margin-top:10px;}
  1128. </style>