index.vue 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858
  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="至" start-placeholder="开始日期" end-placeholder="结束日期" 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="record" filterable placeholder="记录" class="filter-item" style="width: 150px;" @change="changeRecord">
  11. <el-option v-for="item in recordList" :key="item.id" :label="item.name" :value="item.id" />
  12. </el-select>
  13. <el-select v-if="record== '1'" v-model="table.getdataListParm.parammaps.eqcode" filterable placeholder="TMR编号" class="filter-item" style="width: 120px;" clearable>
  14. <el-option v-for="item in TMRNumberList" :key="item.id" :label="item.tname" :value="item.eqcode" />
  15. </el-select>
  16. <el-button class="successBorder" @click="form_search">查询</el-button>
  17. <el-button class="successBorder" @click="handleRefresh">重置</el-button>
  18. </div>
  19. <div class="operation" v-if="record== '0'">
  20. <el-button v-if="isRoleEdit" icon="el-icon-plus" class="success" @click="handleCreate">新增</el-button>
  21. <el-button v-if="isRoleEdit" icon="el-icon-delete" class="danger" @click="form_delete">删除</el-button>
  22. <el-button v-if="isRoleEdit" icon="el-icon-copy-document" class="copy" @click="handleCopy">复制</el-button>
  23. <el-button v-if="dataSynchronization.isDataSynchronization && isRoleEdit" class="success" @click="handleDataUpload">数据上传</el-button>
  24. <el-upload v-if="isRoleEdit" style="float: right;" :headers="headers" :data="uploadData" :action="uploadExcelUrl" :show-file-list="false" :before-upload="beforeImport" :on-success="handleImportSuccess">
  25. <el-button class="import" icon="el-icon-download" style="float: right;">导入</el-button>
  26. </el-upload>
  27. <el-dropdown style="float: right;margin-right: 10px;">
  28. <el-button class="export" icon="el-icon-upload2">导出</el-button>
  29. <el-dropdown-menu slot="dropdown">
  30. <el-dropdown-item @click.native="handleExport(1)">导出模板</el-dropdown-item>
  31. <el-dropdown-item @click.native="handleExport(2)">导出数据</el-dropdown-item>
  32. </el-dropdown-menu>
  33. </el-dropdown>
  34. </div>
  35. <div class="operation" v-else>
  36. <el-button v-if="dataSynchronization.isDataSynchronization && isRoleEdit" class="success" @click="handleDataUpload">数据上传</el-button>
  37. <el-button style="float: right;margin-right: 10px;" class="export" icon="el-icon-upload2" @click="handleExport(3)">导出</el-button>
  38. </div>
  39. <!-- 手动记录 -->
  40. <div class="table" v-if="record== '0'">
  41. <el-table
  42. :key="table.tableKey"
  43. v-loading="table.listLoading"
  44. element-loading-text="给我一点时间"
  45. :data="table.list"
  46. border
  47. fit
  48. highlight-current-row
  49. style="width: 100%;"
  50. :row-style="rowStyle"
  51. :cell-style="cellStyle"
  52. class="elTable table-fixed"
  53. @selection-change="handleSelectionChange"
  54. :max-height="myHeight"
  55. >
  56. <el-table-column type="selection" align="center" width="50" />
  57. <el-table-column label="序号" align="center" type="index" width="50px">
  58. <template slot-scope="scope">
  59. <span>{{ scope.$index + (table.pageNum-1) * table.pageSize + 1 }}</span>
  60. </template>
  61. </el-table-column>
  62. <el-table-column label="栏舍名称" min-width="150px" align="center" prop="barname" />
  63. <el-table-column label="剩料量(kg)" min-width="150px" align="center" prop="remain" />
  64. <el-table-column label="干物质" min-width="150px" align="center" prop="dry" />
  65. <el-table-column label="班次" min-width="90px" align="center" prop="timesstr" />
  66. <el-table-column label="收集时间" min-width="100px" align="center" prop="operatetime" />
  67. <el-table-column label="操作人" min-width="90px" align="center" prop="emp" />
  68. <el-table-column label="操作" align="center" width="80" class-name="small-padding fixed-width" fixed="right">
  69. <template slot-scope="{row}">
  70. <el-button v-if="isRoleEdit" :disabled="row.emp == '设备采集'" class="miniSuccess" icon="el-icon-edit-outline" @click="handleUpdate(row)" />
  71. <span v-if="isRoleEdit" class="centerSpan">|</span>
  72. <el-button v-if="isRoleEdit" :disabled="row.emp == '设备采集'" class="miniDanger" icon="el-icon-delete" @click="handleRowDelete(row)" />
  73. </template>
  74. </el-table-column>
  75. </el-table>
  76. <pagination v-show="table.total>=0" :total="table.total" :page.sync="table.getdataListParm.offset" :limit.sync="table.getdataListParm.pagecount" @pagination="getList" />
  77. </div>
  78. <!-- TMR设备自动记录 -->
  79. <div class="table" v-else>
  80. <el-table
  81. :key="table.tableKey2"
  82. v-loading="table.listLoading2"
  83. element-loading-text="给我一点时间"
  84. :data="table.list"
  85. border
  86. fit
  87. highlight-current-row
  88. style="width: 98%;"
  89. :row-style="rowStyle"
  90. :cell-style="cellStyle"
  91. class="elTable table-fixed"
  92. :height="myHeight"
  93. >
  94. <el-table-column type="selection" align="center" width="50" />
  95. <el-table-column label="TMR设备编号" min-width="150px" align="center" prop="eqcode" />
  96. <el-table-column label="TMR设备名称" min-width="150px" align="center" prop="eqname" />
  97. <el-table-column label="TMR设备类型" min-width="150px" align="center" prop="tclassname" />
  98. <el-table-column label="栏舍名称" min-width="150px" align="center" prop="barname" />
  99. <el-table-column label="收集时间" min-width="150px" align="center" prop="createtime" />
  100. <el-table-column label="剩料重量(kg)" min-width="150px" align="center" prop="weight" />
  101. <el-table-column label="开始重量(kg)" min-width="150px" align="center" prop="beginweight" />
  102. <el-table-column label="结束重量(kg)" min-width="150px" align="center" prop="endweight" />
  103. <el-table-column label="驾驶员" min-width="150px" align="center" prop="driver" />
  104. </el-table>
  105. <pagination v-show="table.total>=0" :total="table.total" :page.sync="table.getdataListParm.offset" :limit.sync="table.getdataListParm.pagecount" @pagination="getList" />
  106. </div>
  107. <!-- 新增/编辑 -->
  108. <el-dialog :fullscreen="dialogFull" :visible.sync="create.dialogFormVisible" :close-on-click-modal="false" v-if='create.dialogFormVisible' width="40%">
  109. <template slot="title">
  110. <div class="avue-crud__dialog__header">
  111. <span class="el-dialog__title">
  112. <span style="display:inline-block;width:3px;height:20px;margin-right:5px; float: left;margin-top:2px" />
  113. {{ textMap[create.dialogStatus] }}
  114. </span>
  115. <div class="avue-crud__dialog__menu" @click="dialogFull? dialogFull=false: dialogFull=true">
  116. <svg-icon v-if="dialogFull" icon-class="exit-fullscreen" />
  117. <svg-icon v-else icon-class="fullscreen" />
  118. </div>
  119. </div>
  120. </template>
  121. <div class="app-add">
  122. <el-form ref="temp" :rules="create.rules" :model="create.temp" label-position="right" label-width="135px" style="width: 90%;margin:0 auto 50px">
  123. <el-row v-if="create.dialogStatus=='create'">
  124. <el-col :span="20">
  125. <el-form-item label="栏舍名称:" prop="barid">
  126. <el-select ref="barid" v-model="create.temp.barid" :disabled="create.dialogStatus=='update'" filterable placeholder="栏舍名称" class="filter-item" style="width: 100%;" @change="changeBar">
  127. <el-option v-for="item in houseNameList" :key="item.id" :label="item.bname" :value="item.id" />
  128. </el-select>
  129. </el-form-item>
  130. </el-col>
  131. </el-row>
  132. <el-row v-else>
  133. <el-col :span="20">
  134. <el-form-item label="栏舍名称:" prop="barname">
  135. <el-input ref="barname" v-model="create.temp.barname" disabled class="filter-item" placeholder="barname" />
  136. </el-form-item>
  137. </el-col>
  138. </el-row>
  139. <el-row>
  140. <el-col :span="20">
  141. <el-form-item label="剩料量:" prop="remain">
  142. <el-input ref="remain" v-model="create.temp.remain" class="filter-item" placeholder="剩料量" type="number" />
  143. </el-form-item>
  144. </el-col>
  145. </el-row>
  146. <el-row>
  147. <el-col :span="20">
  148. <el-form-item label="干物质:" prop="dry">
  149. <el-input ref="dry" v-model="create.temp.dry" class="filter-item" placeholder="干物质" type="number" />
  150. </el-form-item>
  151. </el-col>
  152. </el-row>
  153. <el-row>
  154. <el-col :span="20">
  155. <el-form-item label="班次:" prop="times">
  156. <el-select ref="times" v-model="create.temp.times" filterable placeholder="班次" :disabled="create.dialogStatus=='update'" class="filter-item" style="width: 100%;">
  157. <el-option v-for="item in frequencyList" :key="item.id" :label="item.name" :value="item.id" />
  158. </el-select>
  159. </el-form-item>
  160. </el-col>
  161. </el-row>
  162. <el-row>
  163. <el-col :span="20">
  164. <el-form-item label="处理时间:" prop="operatetime">
  165. <el-date-picker v-model="create.temp.operatetime" :disabled="create.dialogStatus=='update'" type="datetime" placeholder="选择处理时间" format="yyyy-MM-dd HH:mm" value-format="yyyy-MM-dd HH:mm" style="width: 100%;" :clearable="false" />
  166. </el-form-item>
  167. </el-col>
  168. </el-row>
  169. <el-row>
  170. <el-col :span="20">
  171. <el-form-item label="操作人:" prop="emp">
  172. <el-select ref="emp" v-model="create.temp.emp" filterable placeholder="操作人" :disabled="create.dialogStatus=='update'" class="filter-item" style="width: 100%;" @blur="blurEmp">
  173. <el-option v-for="item in create.noteTakerList" :key="item.myId" :label="item.emp" :value="item.emp" />
  174. </el-select>
  175. </el-form-item>
  176. </el-col>
  177. </el-row>
  178. </el-form>
  179. <div slot="footer" class="dialog-footer">
  180. <el-button class="cancelClose" @click="create.dialogFormVisible = false;getList()">关闭</el-button>
  181. <el-button v-if="create.dialogStatus==='create'" class="save" :disabled="isokDisable" @click="createDataAgain()">确认新增</el-button>
  182. <el-button v-if="create.dialogStatus==='create' || create.dialogStatus==='update'" class="save" :disabled="isokDisable" @click="create.dialogStatus==='create'?createData():updateData()">确认</el-button>
  183. </div>
  184. </div>
  185. </el-dialog>
  186. </div>
  187. </template>
  188. <script>
  189. import { GetDataByName, PostDataByName, failproccess, ExecDataByConfig, GetDataByNames, checkButtons,postJson2 } from '@/api/common'
  190. import Cookies from 'js-cookie'
  191. import { parseTime, json2excel } from '@/utils/index.js'
  192. import Pagination from '@/components/Pagination'
  193. import { MessageBox } from 'element-ui'
  194. import axios from 'axios'
  195. import { getToken } from '@/utils/auth'
  196. export default {
  197. name: 'MaterialRemainingRecord',
  198. components: { Pagination },
  199. data() {
  200. return {
  201. dialogFull: false,
  202. isRoleEdit: [],
  203. requestParams: [
  204. { name: 'getBarListEnable', offset: 0, pagecount: 0, parammaps: { 'pastureid': Cookies.get('pastureid') }},
  205. { name: 'getSysoptEnable', offset: 0, pagecount: 0, parammaps: { 'pastureid': Cookies.get('pastureid'), 'inforname': 'times' }},
  206. { name: 'getTMRListEnableType', offset: 0, pagecount: 0, parammaps: { 'pastureid': Cookies.get('pastureid'), 'eqtype': '1' }},
  207. ],
  208. houseNameList: [], // 栏舍名称
  209. frequencyList: [], // 班次
  210. recordList:[{id:'0',name:'手动记录'},{id:'1',name:'TMR设备自动记录'}],
  211. record:'0',
  212. table: {
  213. getdataListParm: {
  214. name: 'getBarfeedremainList',
  215. page: 1,
  216. offset: 1,
  217. pagecount: parseInt(Cookies.get('pageCount')),
  218. returntype: 'Map',
  219. parammaps: {
  220. pastureid: Cookies.get('pastureid'),
  221. barid: '',
  222. startTime: '',
  223. stopTime: '',
  224. inputDatetime: ''
  225. }
  226. },
  227. tableKey: 0,
  228. list: [],
  229. total: 0,
  230. listLoading: true,
  231. temp: {},
  232. tableKey2:0,
  233. listLoading2: false,
  234. list2:[]
  235. },
  236. // 新增/编辑
  237. create: {
  238. dialogFormVisible: false,
  239. dialogStatus: '',
  240. temp: { pastureid: Cookies.get('pastureid'), operatetime: parseTime(new Date(), '{y}-{m}-{d} {h}:{i}'), emp: Cookies.get('employename'), barid: '', barname: '', remain: '',dry:0, times: '' },
  241. rules: {
  242. barid: [{ type: 'string', required: true, message: '必填', trigger: 'blur' }],
  243. remain: [{ type: 'string', required: true, message: '必填', trigger: 'blur' }],
  244. times: [{ type: 'string', required: true, message: '必填', trigger: 'blur' }]
  245. },
  246. getdataListParm: {
  247. name: 'getBarfeedremainEmpHis',
  248. page: 1,
  249. offset: 1,
  250. pagecount: 10,
  251. returntype: 'Map',
  252. parammaps: {
  253. pastureid: Cookies.get('pastureid')
  254. }
  255. },
  256. noteTakerList: [] // 记录人
  257. },
  258. textMap: {
  259. create: '新增',
  260. update: '编辑'
  261. },
  262. requestParam: {},
  263. download: {
  264. getdataListParm: {
  265. name: 'getBarfeedremainList',
  266. page: 1,
  267. offset: 1,
  268. pagecount: 0,
  269. returntype: 'Map',
  270. parammaps: {
  271. pastureid: Cookies.get('pastureid'),
  272. barid: '',
  273. startTime: '',
  274. stopTime: '',
  275. inputDatetime: ''
  276. }
  277. },
  278. list: []
  279. },
  280. dataSynchronization: {
  281. dialogFormVisible: false,
  282. dialogStatus: '',
  283. getdataListParm: {
  284. name: 'getSysoptEnable',
  285. page: 1,
  286. offset: 1,
  287. pagecount: 1,
  288. returntype: 'Map',
  289. parammaps: {
  290. pastureid: Cookies.get('pastureid'),
  291. inforname: 'wgSap'
  292. }
  293. },
  294. isDataSynchronization: false
  295. },
  296. isokDisable: false,
  297. selectList: [],
  298. rowStyle: { maxHeight: 30 + 'px', height: 30 + 'px' },
  299. cellStyle: { padding: 0 + 'px' },
  300. myHeight:document.documentElement.clientHeight - 85- 150 - 45,
  301. url:'authdata/ImportExcel'
  302. }
  303. },
  304. computed: {
  305. // 设置请求头
  306. headers() {
  307. return {
  308. token: getToken()
  309. }
  310. },
  311. uploadData() {
  312. return {
  313. name: 'checkbarname,checktimes,insertBarfeedremainUpload',
  314. importParams: '栏舍名称,剩料量(kg),干物质,班次(第一班/第二班/第三班),收集时间,操作人',
  315. sheetname: 'Sheet1',
  316. // 登录牧场
  317. pastureid: Cookies.get('pastureid'),
  318. // 日期参数
  319. dateParams: '收集时间',
  320. // 必填参数
  321. requiredParams: '栏舍名称,剩料量(kg),剩料量(kg),班次(第一班/第二班/第三班)',
  322. // 为数值的参数
  323. numParams: '剩料量(kg)'
  324. }
  325. },
  326. // 设置上传地址
  327. uploadExcelUrl() {
  328. // return Cookies.get('url') + 'authdata/ImportExcel'
  329. return Cookies.get('url') + 'authdata/ImportExcel'
  330. }
  331. // let url = 'authdata/ImportExcel';
  332. },
  333. created() {
  334. console.log(document.querySelector("html").getAttribute("domain"),'7777')
  335. this.getDataSynchronization()
  336. this.getList()
  337. this.getDownList()
  338. this.getButtons()
  339. },
  340. methods: {
  341. getDataSynchronization() {
  342. GetDataByName(this.dataSynchronization.getdataListParm).then(response => {
  343. // console.log(response.data.list[0])
  344. if (response.data.list[0].inforvalue == 0) {
  345. this.dataSynchronization.isDataSynchronization = false
  346. } else {
  347. this.dataSynchronization.isDataSynchronization = true
  348. }
  349. })
  350. },
  351. getButtons() {
  352. const Edit = 'MaterialRemainingRecord'
  353. const isRoleEdit = checkButtons(JSON.parse(sessionStorage.getItem('buttons')), Edit)
  354. this.isRoleEdit = isRoleEdit
  355. },
  356. getDownList() {
  357. GetDataByNames(this.requestParams).then(response => {
  358. this.houseNameList = response.data.getBarListEnable.list
  359. this.TMRNumberList = response.data.getTMRListEnableType.list
  360. if (response.data.getSysoptEnable.list !== null) {
  361. for (let i = 1; i <= response.data.getSysoptEnable.list[0].inforvalue; i++) {
  362. const obj = {}
  363. obj.id = String(i)
  364. if (i == 1) { obj.name = '第一班' } else if (i == 2) { obj.name = '第二班' } else if (i == 3) { obj.name = '第三班' } else if (i == 4) { obj.name = '第四班' }else if (i == 5) { obj.name = '第五班' }else if (i == 6) { obj.name = '第六班' }
  365. this.frequencyList.push(obj)
  366. }
  367. } else {
  368. this.frequencyList = []
  369. }
  370. })
  371. },
  372. handleBefore() {
  373. if (this.table.getdataListParm.parammaps.inputDatetime !== '' && this.table.getdataListParm.parammaps.inputDatetime !== null) {
  374. var start = new Date(this.table.getdataListParm.parammaps.inputDatetime[0].setDate(this.table.getdataListParm.parammaps.inputDatetime[0].getDate() - 1))
  375. var stop = new Date(this.table.getdataListParm.parammaps.inputDatetime[1].setDate(this.table.getdataListParm.parammaps.inputDatetime[1].getDate() - 1))
  376. this.table.getdataListParm.parammaps.inputDatetime.length = 0
  377. this.table.getdataListParm.parammaps.inputDatetime.push(start, stop)
  378. this.$forceUpdate()
  379. }
  380. },
  381. handleNext() {
  382. if (this.table.getdataListParm.parammaps.inputDatetime !== '' && this.table.getdataListParm.parammaps.inputDatetime !== null) {
  383. var start = new Date(this.table.getdataListParm.parammaps.inputDatetime[0].setDate(this.table.getdataListParm.parammaps.inputDatetime[0].getDate() + 1))
  384. var stop = new Date(this.table.getdataListParm.parammaps.inputDatetime[1].setDate(this.table.getdataListParm.parammaps.inputDatetime[1].getDate() + 1))
  385. this.table.getdataListParm.parammaps.inputDatetime.length = 0
  386. this.table.getdataListParm.parammaps.inputDatetime.push(start, stop)
  387. this.$forceUpdate()
  388. }
  389. },
  390. getList() {
  391. this.table.listLoading = true
  392. if (this.table.getdataListParm.parammaps.inputDatetime !== '' && this.table.getdataListParm.parammaps.inputDatetime !== null) {
  393. this.table.getdataListParm.parammaps.startTime = parseTime(this.table.getdataListParm.parammaps.inputDatetime[0], '{y}-{m}-{d}')
  394. this.table.getdataListParm.parammaps.stopTime = parseTime(this.table.getdataListParm.parammaps.inputDatetime[1], '{y}-{m}-{d}')
  395. } else {
  396. this.table.getdataListParm.parammaps.inputDatetime = ''
  397. this.table.getdataListParm.parammaps.startTime = ''
  398. this.table.getdataListParm.parammaps.stopTime = ''
  399. }
  400. GetDataByName(this.table.getdataListParm).then(response => {
  401. console.log('table数据', response.data.list)
  402. if (response.data.list !== null) {
  403. this.table.list = response.data.list
  404. this.table.pageNum = response.data.pageNum
  405. this.table.pageSize = response.data.pageSize
  406. this.table.total = response.data.total
  407. } else {
  408. this.table.list = []
  409. }
  410. setTimeout(() => {
  411. this.table.listLoading = false
  412. }, 100)
  413. })
  414. },
  415. changeRecord(item){
  416. if(item == '0'){
  417. this.table.getdataListParm.name = 'getBarfeedremainList'
  418. }else{
  419. this.table.getdataListParm.name = 'getRemainplanrecord'
  420. }
  421. this.table.getdataListParm.offset = 1
  422. this.getList()
  423. },
  424. form_search() {
  425. console.log('点击了查询')
  426. this.table.getdataListParm.offset = 1
  427. this.getList()
  428. },
  429. handleRefresh() {
  430. console.log('点击了重置')
  431. this.table.getdataListParm.parammaps.barid = ''
  432. this.table.getdataListParm.parammaps.startTime = ''
  433. this.table.getdataListParm.parammaps.stopTime = ''
  434. this.table.getdataListParm.parammaps.inputDatetime = ''
  435. this.table.getdataListParm.offset = 1
  436. this.getList()
  437. },
  438. // 新增
  439. resetTemp() {
  440. this.create.temp = { pastureid: Cookies.get('pastureid'), operatetime: parseTime(new Date(), '{y}-{m}-{d} {h}:{i}'), emp: Cookies.get('employename'), barid: '', barname: '', remain: '',dry:0, times: '' }
  441. },
  442. blurEmp(item) {
  443. this.create.temp.emp = item.target.value
  444. },
  445. // 栏舍名称
  446. changeBar(item) {
  447. this.create.temp.barname = this.houseNameList.find(obj => obj.id === item).bname
  448. },
  449. getNoteTakerList() {
  450. GetDataByName(this.create.getdataListParm).then(response => {
  451. if (response.data.list !== null) {
  452. for (let i = 0; i < response.data.list.length; i++) {
  453. response.data.list[i].myId = i
  454. }
  455. this.create.noteTakerList = response.data.list
  456. console.log('记录人数据', response.data.list)
  457. console.log(this.create.noteTakerList)
  458. } else {
  459. this.create.noteTakerList = []
  460. }
  461. })
  462. },
  463. handleCreate() {
  464. console.log('点击了新增')
  465. this.dialogFull = false
  466. this.resetTemp()
  467. this.getNoteTakerList()
  468. this.create.dialogStatus = 'create'
  469. this.create.dialogFormVisible = true
  470. },
  471. createData() {
  472. console.log('点击了新增保存')
  473. this.isokDisable = true
  474. setTimeout(() => {
  475. this.isokDisable = false
  476. }, 1000)
  477. this.$refs['temp'].validate(valid => {
  478. if (valid) {
  479. this.isokDisable = true
  480. setTimeout(() => {
  481. this.isokDisable = false
  482. }, 1000)
  483. const remain = /^\d+(\.\d{1,2})?$/
  484. // 剩料量
  485. if (!remain.test(parseFloat(this.create.temp.remain))) {
  486. this.$message({ type: 'error', message: '剩料量请输入自然数并保留两位小数', duration: 2000 })
  487. return false
  488. }
  489. if(this.create.temp.dry){
  490. this.create.temp.dry = parseFloat(this.create.temp.dry)
  491. }else{
  492. this.create.temp.dry = 0
  493. }
  494. this.requestParam.name = 'insertBarfeedremain'
  495. this.requestParam.parammaps = this.create.temp
  496. if (this.create.temp.emp == '') { this.create.temp.emp = Cookies.get('employename') }
  497. PostDataByName(this.requestParam).then(response => {
  498. console.log('新增保存发送参数', this.requestParam)
  499. if (response.msg !== 'fail') {
  500. this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
  501. this.create.dialogFormVisible = false
  502. this.getList()
  503. } else {
  504. const barid = new RegExp("key 'barid'")
  505. if (barid.test(response.data)) {
  506. this.$message({ type: 'error', message: '该栏舍该班次今日剩料量已存在,不可重复生成', duration: 2000 })
  507. } else {
  508. this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
  509. }
  510. }
  511. })
  512. }
  513. })
  514. },
  515. createDataAgain() {
  516. console.log('点击了新增保存')
  517. this.isokDisable = true
  518. setTimeout(() => {
  519. this.isokDisable = false
  520. }, 1000)
  521. this.$refs['temp'].validate(valid => {
  522. if (valid) {
  523. this.isokDisable = true
  524. setTimeout(() => {
  525. this.isokDisable = false
  526. }, 1000)
  527. const remain = /^\d+(\.\d{1,2})?$/
  528. // 剩料量
  529. if (!remain.test(parseFloat(this.create.temp.remain))) {
  530. this.$message({ type: 'error', message: '剩料量请输入自然数并保留两位小数', duration: 2000 })
  531. return false
  532. }
  533. if(this.create.temp.dry){
  534. this.create.temp.dry = parseFloat(this.create.temp.dry)
  535. }else{
  536. this.create.temp.dry = 0
  537. }
  538. this.requestParam.name = 'insertBarfeedremain'
  539. this.requestParam.parammaps = this.create.temp
  540. if (this.create.temp.emp == '') { this.create.temp.emp = Cookies.get('employename') }
  541. PostDataByName(this.requestParam).then(response => {
  542. console.log('新增保存发送参数', this.requestParam)
  543. if (response.msg !== 'fail') {
  544. this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
  545. this.resetTemp()
  546. this.getList()
  547. this.getNoteTakerList()
  548. } else {
  549. const barid = new RegExp("key 'barid'")
  550. if (barid.test(response.data)) {
  551. this.$message({ type: 'error', message: '该栏舍该班次今日剩料量已存在,不可重复生成', duration: 2000 })
  552. } else {
  553. this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
  554. }
  555. }
  556. })
  557. }
  558. })
  559. },
  560. // 编辑
  561. handleUpdate(row) {
  562. console.log('点击了编辑', row)
  563. this.dialogFull = false
  564. row.barid = String(row.barid)
  565. this.create.temp = Object.assign({}, row)
  566. this.create.temp.id = row.id
  567. this.getNoteTakerList()
  568. this.create.dialogStatus = 'update'
  569. this.create.dialogFormVisible = true
  570. },
  571. updateData() {
  572. this.isokDisable = true
  573. setTimeout(() => {
  574. this.isokDisable = false
  575. }, 1000)
  576. this.$refs['temp'].validate(valid => {
  577. if (valid) {
  578. this.isokDisable = true
  579. setTimeout(() => {
  580. this.isokDisable = false
  581. }, 1000)
  582. const remain = /^\d+(\.\d{1,2})?$/
  583. // 剩料量
  584. if (!remain.test(parseFloat(this.create.temp.remain))) {
  585. this.$message({ type: 'error', message: '剩料量请输入自然数并保留两位小数', duration: 2000 })
  586. return false
  587. }
  588. this.requestParam.name = 'updateBarfeedremain'
  589. if(this.create.temp.dry){
  590. this.create.temp.dry = parseFloat(this.create.temp.dry)
  591. }else{
  592. this.create.temp.dry = 0
  593. }
  594. this.requestParam.parammaps = this.create.temp
  595. if (this.create.temp.emp == '') { this.create.temp.emp = Cookies.get('employename') }
  596. PostDataByName(this.requestParam).then(response => {
  597. console.log('新增保存发送参数', this.requestParam)
  598. if (response.msg !== 'fail') {
  599. this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
  600. this.create.dialogFormVisible = false
  601. this.getList()
  602. } else {
  603. this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
  604. }
  605. })
  606. }
  607. })
  608. },
  609. // 删除
  610. handleRowDelete(row) {
  611. console.log('点击了行内删除')
  612. MessageBox.confirm('是否确认删除此信息?', {
  613. confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
  614. }).then(() => {
  615. this.selectList = []
  616. this.requestParam.name = 'deleteBarfeedremain'
  617. this.requestParam.parammaps = {}
  618. this.requestParam.parammaps.pastureid = row.pastureid
  619. this.requestParam.parammaps.id = row.id
  620. PostDataByName(this.requestParam).then(response => {
  621. if (response.msg === 'fail') {
  622. this.$notify({ title: '删除失败', message: response.data, type: 'warning', duration: 2000 })
  623. } else {
  624. this.$notify({ title: '成功', message: '删除成功', type: 'success', duration: 2000 })
  625. this.getList()
  626. }
  627. })
  628. }).catch(() => {
  629. this.$message({ type: 'info', message: '已取消删除' })
  630. })
  631. },
  632. handleSelectionChange(val) {
  633. console.log('勾选数据', val)
  634. this.selectList = val
  635. },
  636. form_delete() {
  637. console.log('点击了删除')
  638. if (this.selectList.length == 0) {
  639. this.$message({ type: 'error', message: '请选择栏舍剩料记录', duration: 2000 })
  640. } else {
  641. MessageBox.confirm('当前选中' + this.selectList.length + '条信息,是否删除?', {
  642. confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
  643. }).then(() => {
  644. console.log(this.selectList)
  645. this.requestParam.common = { 'returnmap': '0' }
  646. this.requestParam.data = []
  647. this.requestParam.data[0] = { 'name': 'insertSpotList', 'resultmaps': { 'list': this.selectList }}
  648. this.requestParam.data[0].children = []
  649. this.requestParam.data[0].children[0] = { 'name': 'deleteBarfeedremain', 'type': 'e', 'parammaps': {
  650. id: '@insertSpotList.id',
  651. pastureid: '@insertSpotList.pastureid'
  652. }}
  653. ExecDataByConfig(this.requestParam).then(response => {
  654. console.log('删除保存发送参数', this.requestParam)
  655. if (response.msg === 'fail') {
  656. this.$notify({ title: '删除失败', message: response.data, type: 'warning', duration: 2000 })
  657. } else {
  658. this.$notify({ title: '', message: '删除成功', type: 'success', duration: 2000 })
  659. this.getList()
  660. }
  661. })
  662. })
  663. }
  664. },
  665. // 复制
  666. handleCopy() {
  667. console.log('点击了复制')
  668. if (this.selectList.length == 0) {
  669. this.$message({ type: 'error', message: '请选择栏舍剩料记录', duration: 2000 })
  670. } else if (this.selectList.length == 1) {
  671. MessageBox.confirm('是否确认复制此信息?', {
  672. confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
  673. }).then(() => {
  674. this.requestParam.name = 'copybarfeedremain'
  675. this.requestParam.parammaps = {}
  676. this.requestParam.parammaps.pastureid = this.selectList[0].pastureid
  677. this.requestParam.parammaps.id = this.selectList[0].id
  678. PostDataByName(this.requestParam).then(response => {
  679. if (response.msg === 'fail') {
  680. const barid = new RegExp("key 'barid'")
  681. if (barid.test(response.data)) {
  682. this.$notify({ type: 'warning', message: '该栏舍该班次今日剩料量已存在,不可重复生成', duration: 2000 })
  683. return
  684. }
  685. this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
  686. } else {
  687. this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
  688. this.getList()
  689. }
  690. })
  691. }).catch(() => {
  692. this.$message({ type: 'info', message: '已取消复制' })
  693. })
  694. } else {
  695. this.$message({ type: 'error', message: '请选择一条栏舍剩料记录', duration: 2000 })
  696. }
  697. },
  698. // 导出
  699. handleExport(item) {
  700. if (item == 1) {
  701. console.log('点击了导出模板')
  702. console.log('点击了导出模板')
  703. const requestParam = this.requestParam
  704. const url = Cookies.get('url') + 'authdata/barfeedremain/excel' // 请求下载文件的地址
  705. console.log(url)
  706. axios({
  707. method: 'POST',
  708. url: url,
  709. data: requestParam,
  710. headers: { token: getToken(), optname: 'insertcustomdoc' },
  711. responseType: 'blob'
  712. }).then(res => {
  713. if (!res) return
  714. this.percentage = 99
  715. setTimeout(() => {
  716. this.isPercentage = false
  717. }, 2000)
  718. const blob = new Blob([res.data], {
  719. type: 'application/octet-stream;charset=utf-8'
  720. })
  721. const url = window.URL.createObjectURL(blob)
  722. const aLink = document.createElement('a')
  723. aLink.style.display = 'none'
  724. aLink.href = url
  725. const docname = '栏舍剩料记录导入模板.xlsx'
  726. aLink.setAttribute('download', docname) // 下载的文件
  727. document.body.appendChild(aLink)
  728. aLink.click()
  729. document.body.removeChild(aLink)
  730. window.URL.revokeObjectURL(url)
  731. })
  732. } else {
  733. console.log('点击了导出数据',item,this.record)
  734. if(this.record == '0'){
  735. this.download.getdataListParm.name = 'getBarfeedremainList'
  736. }else{
  737. this.download.getdataListParm.name = 'getRemainplanrecord'
  738. }
  739. this.download.getdataListParm.parammaps = this.table.getdataListParm.parammaps
  740. if (this.download.getdataListParm.parammaps.inputDatetime !== '' && this.download.getdataListParm.parammaps.inputDatetime !== null) {
  741. this.download.getdataListParm.parammaps.startTime = parseTime(this.download.getdataListParm.parammaps.inputDatetime[0], '{y}-{m}-{d}')
  742. this.download.getdataListParm.parammaps.stopTime = parseTime(this.download.getdataListParm.parammaps.inputDatetime[1], '{y}-{m}-{d}')
  743. } else {
  744. this.download.getdataListParm.parammaps.inputDatetime = ''
  745. this.download.getdataListParm.parammaps.startTime = ''
  746. this.download.getdataListParm.parammaps.stopTime = ''
  747. }
  748. GetDataByName(this.download.getdataListParm).then(response => {
  749. if (response.data.list !== null) {
  750. this.download.list = response.data.list
  751. } else {
  752. this.download.list = []
  753. }
  754. if(item== 2){
  755. var excelDatas1 = [
  756. {
  757. tHeader: ['栏舍名称', '剩料量(kg)','干物质', '班次(第一班/第二班/第三班)', '收集时间', '操作人'],
  758. filterVal: ['barname', 'remain','dry', 'timesstr', 'operatetime', 'emp'],
  759. tableDatas: this.download.list,
  760. sheetName: 'Sheet1'
  761. }
  762. ]
  763. json2excel(excelDatas1, '栏舍剩料记录-手动记录', true, 'xlsx')
  764. }else{
  765. var excelDatas2 = [
  766. {
  767. tHeader: ['TMR设备编号','TMR设备名称','TMR设备类型','栏舍名称','收集时间','剩料重量(kg)','开始重量(kg)','结束重量(kg)','驾驶员'],
  768. filterVal: ['eqcode','eqname','tclassname','barname','createtime','weight','beginweight','endweight','driver'],
  769. tableDatas: this.download.list,
  770. sheetName: 'Sheet1'
  771. }
  772. ]
  773. json2excel(excelDatas2, '栏舍剩料记录-TMR设备自动记录', true, 'xlsx')
  774. }
  775. })
  776. }
  777. },
  778. beforeImport(file) {
  779. const isLt2M = file.size / 1024 / 1024 < 2
  780. if (!isLt2M) {
  781. this.$message.error('上传文件大小不能超过 2MB!')
  782. }
  783. return isLt2M
  784. },
  785. handleImportSuccess(res, file) {
  786. this.getList()
  787. if (res.msg === 'ok') {
  788. this.$message({ title: '成功', message: '导入成功:' + res.data.success + '条!', type: 'success', duration: 2000 })
  789. if (res.data.err_count > 0) {
  790. this.$notify({ title: '失败', message: '导入失败:' + res.data.err_count + '条!', type: 'danger', duration: 2000 })
  791. import('@/vendor/Export2Excel').then(excel => {
  792. const list1 = res.data.result
  793. const tHeader = ['栏舍名称', '剩料量(kg)', '班次', '收集时间', '操作人', '错误信息']
  794. const filterVal = ['栏舍名称', '剩料量(kg)', '班次', '收集时间', '操作人', 'error_msg']
  795. const data1 = this.formatJson(filterVal, list1)
  796. excel.export_json_to_excel({ header: tHeader, data: data1, filename: '栏舍剩料记录导入报错信息', autoWidth: true, bookType: 'xlsx' })
  797. })
  798. }
  799. } else {
  800. this.$notify({ title: '失败', message: '上传失败', type: 'danger', duration: 2000 })
  801. }
  802. },
  803. formatJson(filterVal, jsonData) {
  804. return jsonData.map(v =>
  805. filterVal.map(j => {
  806. if (j === 'timestamp') {
  807. return parseTime(v[j])
  808. } else {
  809. return v[j]
  810. }
  811. })
  812. )
  813. },
  814. handleDataUpload(){
  815. let a = Cookies.get('url')
  816. let b = a.search(8081)
  817. let c = a.substring(0,a.search(8081)) + '8082'
  818. let d = a.substring(0,a.lastIndexOf('/'))
  819. console.log(d)
  820. let url = ''
  821. if(b == -1){
  822. url = d + ':8082'
  823. }else{
  824. url = c
  825. }
  826. console.log(url,'url')
  827. let _url = url + '/authdata/surplus/push'
  828. let data = {
  829. date:parseTime(new Date(), '{y}-{m}-{d}'),
  830. pastureId:Cookies.get('pastureid')
  831. }
  832. console.log(_url,'_url')
  833. postJson2(_url, data).then(response => {
  834. if(response.msg == 'ok'){
  835. this.$notify({ title: '', message: response.data, type: 'success', duration: 2000 })
  836. }else{
  837. this.$notify({ title: '上传失败', message: response.data, type: 'warning', duration: 2000 })
  838. }
  839. })
  840. }
  841. }
  842. }
  843. </script>