3ff352302cd9244cc04bd0017f32a302d47fc97b.svn-base 32 KB

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