f790f20deb553f68bf2d34d87773b436409c51e9.svn-base 29 KB

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