index.vue 56 KB

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