02f546e3633c4846f972900ea99913abc18a286d.svn-base 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  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 axios from 'axios'
  152. import { getToken } from '@/utils/auth'
  153. export default {
  154. name: 'MaterialRemainingRecord',
  155. components: { Pagination },
  156. data() {
  157. return {
  158. isRoleEdit: [],
  159. requestParams: [
  160. { name: 'getBarListEnable', offset: 0, pagecount: 0, parammaps: { 'pastureid': Cookies.get('pastureid') }},
  161. { name: 'getSysoptEnable', offset: 0, pagecount: 0, parammaps: { 'pastureid': Cookies.get('pastureid'), 'inforname': 'times' }}
  162. ],
  163. houseNameList: [], // 栏舍名称
  164. frequencyList: [], // 班次
  165. table: {
  166. getdataListParm: {
  167. name: 'getBarfeedremainList',
  168. page: 1,
  169. offset: 1,
  170. pagecount: 10,
  171. returntype: 'Map',
  172. parammaps: {
  173. pastureid: Cookies.get('pastureid'),
  174. barid: '',
  175. startTime: '',
  176. stopTime: '',
  177. inputDatetime: ''
  178. }
  179. },
  180. tableKey: 0,
  181. list: [],
  182. total: 0,
  183. listLoading: true,
  184. temp: {}
  185. },
  186. // 新增/编辑
  187. create: {
  188. dialogFormVisible: false,
  189. dialogStatus: '',
  190. temp: { pastureid: Cookies.get('pastureid'), operatetime: parseTime(new Date(), '{y}-{m}-{d} {h}:{i}'), emp: Cookies.get('employename'), barid: '', barname: '', remain: '', times: '' },
  191. rules: {
  192. barid: [{ type: 'string', required: true, message: '必填', trigger: 'blur' }],
  193. remain: [{ type: 'string', required: true, message: '必填', trigger: 'blur' }],
  194. times: [{ type: 'string', required: true, message: '必填', trigger: 'blur' }]
  195. },
  196. getdataListParm: {
  197. name: 'getBarfeedremainEmpHis',
  198. page: 1,
  199. offset: 1,
  200. pagecount: 10,
  201. returntype: 'Map',
  202. parammaps: {
  203. pastureid: Cookies.get('pastureid')
  204. }
  205. },
  206. noteTakerList: [] // 记录人
  207. },
  208. textMap: {
  209. create: '新增',
  210. update: '编辑'
  211. },
  212. requestParam: {},
  213. download: {
  214. getdataListParm: {
  215. name: 'getBarfeedremainList',
  216. page: 1,
  217. offset: 1,
  218. pagecount: 0,
  219. returntype: 'Map',
  220. parammaps: {
  221. pastureid: Cookies.get('pastureid'),
  222. barid: '',
  223. startTime: '',
  224. stopTime: '',
  225. inputDatetime: ''
  226. }
  227. },
  228. list: []
  229. },
  230. isokDisable: false,
  231. selectList: [],
  232. rowStyle: { maxHeight: 50 + 'px', height: 45 + 'px' },
  233. cellStyle: { padding: 0 + 'px' }
  234. }
  235. },
  236. computed: {
  237. // 设置请求头
  238. headers() {
  239. return {
  240. token: getToken()
  241. }
  242. },
  243. uploadData() {
  244. return {
  245. name: '颛孙洋洋-栏舍剩料记录',
  246. importParams: '栏舍名称,剩料量(kg),应用班次,处理时间 ,操作人',
  247. sheetname: 'SheetJS'
  248. }
  249. },
  250. // 设置上传地址
  251. uploadExcelUrl() {
  252. return process.env.VUE_APP_BASE_API + 'authdata/ImportExcel'
  253. }
  254. },
  255. created() {
  256. this.getList()
  257. this.getDownList()
  258. this.getButtons()
  259. },
  260. methods: {
  261. getButtons() {
  262. const Edit = 'MaterialRemainingRecord'
  263. const isRoleEdit = checkButtons(JSON.parse(sessionStorage.getItem('buttons')), Edit)
  264. this.isRoleEdit = isRoleEdit
  265. },
  266. getDownList() {
  267. GetDataByNames(this.requestParams).then(response => {
  268. this.houseNameList = response.data.getBarListEnable.list
  269. if (response.data.getSysoptEnable.list !== null) {
  270. for (let i = 1; i <= response.data.getSysoptEnable.list[0].inforvalue; i++) {
  271. const obj = {}
  272. obj.id = String(i)
  273. if (i == 1) { obj.name = '第一班' } else if (i == 2) { obj.name = '第二班' } else if (i == 3) { obj.name = '第三班' } else if (i == 4) { obj.name = '第四班' }
  274. this.frequencyList.push(obj)
  275. }
  276. } else {
  277. this.frequencyList = []
  278. }
  279. })
  280. },
  281. handleBefore() {
  282. if (this.table.getdataListParm.parammaps.inputDatetime !== '' && this.table.getdataListParm.parammaps.inputDatetime !== null) {
  283. var start = new Date(this.table.getdataListParm.parammaps.inputDatetime[0].setDate(this.table.getdataListParm.parammaps.inputDatetime[0].getDate() - 1))
  284. var stop = new Date(this.table.getdataListParm.parammaps.inputDatetime[1].setDate(this.table.getdataListParm.parammaps.inputDatetime[1].getDate() - 1))
  285. this.table.getdataListParm.parammaps.inputDatetime.length = 0
  286. this.table.getdataListParm.parammaps.inputDatetime.push(start, stop)
  287. this.$forceUpdate()
  288. }
  289. },
  290. handleNext() {
  291. if (this.table.getdataListParm.parammaps.inputDatetime !== '' && this.table.getdataListParm.parammaps.inputDatetime !== null) {
  292. var start = new Date(this.table.getdataListParm.parammaps.inputDatetime[0].setDate(this.table.getdataListParm.parammaps.inputDatetime[0].getDate() + 1))
  293. var stop = new Date(this.table.getdataListParm.parammaps.inputDatetime[1].setDate(this.table.getdataListParm.parammaps.inputDatetime[1].getDate() + 1))
  294. this.table.getdataListParm.parammaps.inputDatetime.length = 0
  295. this.table.getdataListParm.parammaps.inputDatetime.push(start, stop)
  296. this.$forceUpdate()
  297. }
  298. },
  299. getList() {
  300. this.table.listLoading = true
  301. GetDataByName(this.table.getdataListParm).then(response => {
  302. console.log('table数据', response.data.list)
  303. if (response.data.list !== null) {
  304. this.table.list = response.data.list
  305. this.table.pageNum = response.data.pageNum
  306. this.table.pageSize = response.data.pageSize
  307. this.table.total = response.data.total
  308. } else {
  309. this.table.list = []
  310. }
  311. setTimeout(() => {
  312. this.table.listLoading = false
  313. }, 100)
  314. })
  315. },
  316. handleSearch() {
  317. console.log('点击了查询')
  318. if (this.table.getdataListParm.parammaps.inputDatetime !== '' && this.table.getdataListParm.parammaps.inputDatetime !== null) {
  319. this.table.getdataListParm.parammaps.startTime = parseTime(this.table.getdataListParm.parammaps.inputDatetime[0], '{y}-{m}-{d}')
  320. this.table.getdataListParm.parammaps.stopTime = parseTime(this.table.getdataListParm.parammaps.inputDatetime[1], '{y}-{m}-{d}')
  321. } else {
  322. this.table.getdataListParm.parammaps.inputDatetime = ''
  323. this.table.getdataListParm.parammaps.startTime = ''
  324. this.table.getdataListParm.parammaps.stopTime = ''
  325. }
  326. this.table.getdataListParm.offset = 1
  327. this.getList()
  328. },
  329. handleRefresh() {
  330. console.log('点击了重置')
  331. this.table.getdataListParm.parammaps.barid = ''
  332. this.table.getdataListParm.parammaps.startTime = ''
  333. this.table.getdataListParm.parammaps.stopTime = ''
  334. this.table.getdataListParm.parammaps.inputDatetime = ''
  335. this.table.getdataListParm.offset = 1
  336. this.getList()
  337. },
  338. // 新增
  339. resetTemp() {
  340. this.create.temp = { pastureid: Cookies.get('pastureid'), operatetime: parseTime(new Date(), '{y}-{m}-{d} {h}:{i}'), emp: Cookies.get('employename'), barid: '', barname: '', remain: '', times: '' }
  341. },
  342. blurEmp(item) {
  343. this.create.temp.emp = item.target.value
  344. },
  345. // 栏舍名称
  346. changeBar(item) {
  347. this.create.temp.barname = this.houseNameList.find(obj => obj.id === item).bname
  348. },
  349. getNoteTakerList() {
  350. GetDataByName(this.create.getdataListParm).then(response => {
  351. if (response.data.list !== null) {
  352. for (let i = 0; i < response.data.list.length; i++) {
  353. response.data.list[i].myId = i
  354. }
  355. this.create.noteTakerList = response.data.list
  356. console.log('记录人数据', response.data.list)
  357. console.log(this.create.noteTakerList)
  358. } else {
  359. this.create.noteTakerList = []
  360. }
  361. })
  362. },
  363. handleCreate() {
  364. console.log('点击了新增')
  365. this.resetTemp()
  366. this.getNoteTakerList()
  367. this.create.dialogStatus = 'create'
  368. this.create.dialogFormVisible = true
  369. },
  370. createData() {
  371. console.log('点击了新增保存')
  372. this.isokDisable = true
  373. setTimeout(() => {
  374. this.isokDisable = false
  375. }, 1000)
  376. this.$refs['temp'].validate(valid => {
  377. if (valid) {
  378. this.isokDisable = true
  379. setTimeout(() => {
  380. this.isokDisable = false
  381. }, 1000)
  382. const remain = /^\d+(\.\d{1,2})?$/
  383. // 剩料量
  384. if (!remain.test(parseFloat(this.create.temp.remain))) {
  385. this.$message({ type: 'error', message: '剩料量请输入自然数并保留两位小数', duration: 2000 })
  386. return false
  387. }
  388. this.requestParam.name = 'insertBarfeedremain'
  389. this.requestParam.parammaps = this.create.temp
  390. if (this.create.temp.emp == '') { this.create.temp.emp = Cookies.get('employename') }
  391. PostDataByName(this.requestParam).then(response => {
  392. console.log('新增保存发送参数', this.requestParam)
  393. if (response.msg !== 'fail') {
  394. this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
  395. this.create.dialogFormVisible = false
  396. this.getList()
  397. } else {
  398. const barid = new RegExp("key 'barid'")
  399. if (barid.test(response.data)) {
  400. this.$message({ type: 'error', message: '该栏舍该班次今日剩料量已存在,不可重复生成', duration: 2000 })
  401. } else {
  402. this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
  403. }
  404. }
  405. })
  406. }
  407. })
  408. },
  409. createDataAgain() {
  410. console.log('点击了新增保存')
  411. this.isokDisable = true
  412. setTimeout(() => {
  413. this.isokDisable = false
  414. }, 1000)
  415. this.$refs['temp'].validate(valid => {
  416. if (valid) {
  417. this.isokDisable = true
  418. setTimeout(() => {
  419. this.isokDisable = false
  420. }, 1000)
  421. const remain = /^\d+(\.\d{1,2})?$/
  422. // 剩料量
  423. if (!remain.test(parseFloat(this.create.temp.remain))) {
  424. this.$message({ type: 'error', message: '剩料量请输入自然数并保留两位小数', duration: 2000 })
  425. return false
  426. }
  427. this.requestParam.name = 'insertBarfeedremain'
  428. this.requestParam.parammaps = this.create.temp
  429. if (this.create.temp.emp == '') { this.create.temp.emp = Cookies.get('employename') }
  430. PostDataByName(this.requestParam).then(response => {
  431. console.log('新增保存发送参数', this.requestParam)
  432. if (response.msg !== 'fail') {
  433. this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
  434. this.resetTemp()
  435. this.getList()
  436. this.getNoteTakerList()
  437. } else {
  438. const barid = new RegExp("key 'barid'")
  439. if (barid.test(response.data)) {
  440. this.$message({ type: 'error', message: '该栏舍该班次今日剩料量已存在,不可重复生成', duration: 2000 })
  441. } else {
  442. this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
  443. }
  444. }
  445. })
  446. }
  447. })
  448. },
  449. // 编辑
  450. handleUpdate(row) {
  451. console.log('点击了编辑', row)
  452. row.barid = String(row.barid)
  453. this.create.temp = Object.assign({}, row)
  454. this.create.temp.id = row.id
  455. this.getNoteTakerList()
  456. this.create.dialogStatus = 'update'
  457. this.create.dialogFormVisible = true
  458. },
  459. updateData() {
  460. this.isokDisable = true
  461. setTimeout(() => {
  462. this.isokDisable = false
  463. }, 1000)
  464. this.$refs['temp'].validate(valid => {
  465. if (valid) {
  466. this.isokDisable = true
  467. setTimeout(() => {
  468. this.isokDisable = false
  469. }, 1000)
  470. const remain = /^\d+(\.\d{1,2})?$/
  471. // 剩料量
  472. if (!remain.test(parseFloat(this.create.temp.remain))) {
  473. this.$message({ type: 'error', message: '剩料量请输入自然数并保留两位小数', duration: 2000 })
  474. return false
  475. }
  476. this.requestParam.name = 'updateBarfeedremain'
  477. this.requestParam.parammaps = this.create.temp
  478. if (this.create.temp.emp == '') { this.create.temp.emp = Cookies.get('employename') }
  479. PostDataByName(this.requestParam).then(response => {
  480. console.log('新增保存发送参数', this.requestParam)
  481. if (response.msg !== 'fail') {
  482. this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
  483. this.create.dialogFormVisible = false
  484. this.getList()
  485. } else {
  486. this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
  487. }
  488. })
  489. }
  490. })
  491. },
  492. // 删除
  493. handleRowDelete(row) {
  494. console.log('点击了行内删除')
  495. MessageBox.confirm('是否确认删除此信息?', {
  496. confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
  497. }).then(() => {
  498. this.selectList = []
  499. this.requestParam.name = 'deleteBarfeedremain'
  500. this.requestParam.parammaps = {}
  501. this.requestParam.parammaps.pastureid = row.pastureid
  502. this.requestParam.parammaps.id = row.id
  503. PostDataByName(this.requestParam).then(response => {
  504. if (response.msg === 'fail') {
  505. this.$notify({ title: '删除失败', message: response.data, type: 'warning', duration: 2000 })
  506. } else {
  507. this.$notify({ title: '成功', message: '删除成功', type: 'success', duration: 2000 })
  508. this.getList()
  509. }
  510. })
  511. }).catch(() => {
  512. this.$message({ type: 'info', message: '已取消删除' })
  513. })
  514. },
  515. handleSelectionChange(val) {
  516. console.log('勾选数据', val)
  517. this.selectList = val
  518. },
  519. handleDelete() {
  520. console.log('点击了删除')
  521. if (this.selectList.length == 0) {
  522. this.$message({ type: 'error', message: '请选择栏舍剩料记录', duration: 2000 })
  523. } else {
  524. MessageBox.confirm('当前选中' + this.selectList.length + '条信息,是否删除?', {
  525. confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
  526. }).then(() => {
  527. console.log(this.selectList)
  528. this.requestParam.common = { 'returnmap': '0' }
  529. this.requestParam.data = []
  530. this.requestParam.data[0] = { 'name': 'insertSpotList', 'resultmaps': { 'list': this.selectList }}
  531. this.requestParam.data[0].children = []
  532. this.requestParam.data[0].children[0] = { 'name': 'deleteBarfeedremain', 'type': 'e', 'parammaps': {
  533. id: '@insertSpotList.id',
  534. pastureid: '@insertSpotList.pastureid'
  535. }}
  536. ExecDataByConfig(this.requestParam).then(response => {
  537. console.log('删除保存发送参数', this.requestParam)
  538. if (response.msg === 'fail') {
  539. this.$notify({ title: '删除失败', message: response.data, type: 'warning', duration: 2000 })
  540. } else {
  541. this.$notify({ title: '', message: '删除成功', type: 'success', duration: 2000 })
  542. this.getList()
  543. }
  544. })
  545. })
  546. }
  547. },
  548. // 复制
  549. handleCopy() {
  550. console.log('点击了复制')
  551. if (this.selectList.length == 0) {
  552. this.$message({ type: 'error', message: '请选择栏舍剩料记录', duration: 2000 })
  553. } else if (this.selectList.length == 1) {
  554. MessageBox.confirm('是否确认复制此信息?', {
  555. confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
  556. }).then(() => {
  557. this.requestParam.name = 'copybarfeedremain'
  558. this.requestParam.parammaps = {}
  559. this.requestParam.parammaps.pastureid = this.selectList[0].pastureid
  560. this.requestParam.parammaps.id = this.selectList[0].id
  561. PostDataByName(this.requestParam).then(response => {
  562. if (response.msg === 'fail') {
  563. const barid = new RegExp("key 'barid'")
  564. if (barid.test(response.data)) {
  565. this.$message({ type: 'error', message: '该栏舍该班次今日剩料量已存在,不可重复生成', duration: 2000 })
  566. } else {
  567. this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
  568. }
  569. } else {
  570. this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
  571. this.getList()
  572. }
  573. })
  574. }).catch(() => {
  575. this.$message({ type: 'info', message: '已取消删除' })
  576. })
  577. } else {
  578. this.$message({ type: 'error', message: '请选择一条栏舍剩料记录', duration: 2000 })
  579. }
  580. },
  581. // 导出
  582. handleExport(item) {
  583. if (item == 1) {
  584. console.log('点击了导出模板')
  585. console.log('点击了导出模板')
  586. const requestParam = this.requestParam
  587. const url = process.env.VUE_APP_BASE_API + 'file/导入导出模板/栏舍生产/栏舍剩料记录导入模板.xlsx' // 请求下载文件的地址
  588. console.log(url)
  589. axios({
  590. method: 'GET',
  591. url: url,
  592. data: requestParam,
  593. headers: { token: getToken(), optname: 'insertcustomdoc' },
  594. responseType: 'blob'
  595. }).then(res => {
  596. if (!res) return
  597. this.percentage = 99
  598. setTimeout(() => {
  599. this.isPercentage = false
  600. }, 2000)
  601. const blob = new Blob([res.data], {
  602. type: 'application/octet-stream;charset=utf-8'
  603. })
  604. const url = window.URL.createObjectURL(blob)
  605. const aLink = document.createElement('a')
  606. aLink.style.display = 'none'
  607. aLink.href = url
  608. const docname = '栏舍剩料记录导入模板.xlsx'
  609. aLink.setAttribute('download', docname) // 下载的文件
  610. document.body.appendChild(aLink)
  611. aLink.click()
  612. document.body.removeChild(aLink)
  613. window.URL.revokeObjectURL(url)
  614. })
  615. } else {
  616. console.log('点击了导出数据')
  617. this.download.getdataListParm.parammaps = this.table.getdataListParm.parammaps
  618. if (this.download.getdataListParm.parammaps.inputDatetime !== '' && this.download.getdataListParm.parammaps.inputDatetime !== null) {
  619. this.download.getdataListParm.parammaps.startTime = parseTime(this.download.getdataListParm.parammaps.inputDatetime[0], '{y}-{m}-{d}')
  620. this.download.getdataListParm.parammaps.stopTime = parseTime(this.download.getdataListParm.parammaps.inputDatetime[1], '{y}-{m}-{d}')
  621. } else {
  622. this.download.getdataListParm.parammaps.inputDatetime = ''
  623. this.download.getdataListParm.parammaps.startTime = ''
  624. this.download.getdataListParm.parammaps.stopTime = ''
  625. }
  626. GetDataByName(this.download.getdataListParm).then(response => {
  627. if (response.data.list !== null) {
  628. this.download.list = response.data.list
  629. } else {
  630. this.download.list = []
  631. }
  632. var excelDatas = [
  633. {
  634. tHeader: ['栏舍名称', '剩料量(kg)', '应用班次', '处理时间', '操作人'],
  635. filterVal: ['barname', 'remain', 'timesstr', 'operatetime', 'emp'],
  636. tableDatas: this.download.list,
  637. sheetName: 'Sheet1'
  638. }
  639. ]
  640. json2excel(excelDatas, '栏舍剩料记录', true, 'xlsx')
  641. })
  642. }
  643. },
  644. beforeImport(file) {
  645. const isLt2M = file.size / 1024 / 1024 < 2
  646. if (!isLt2M) {
  647. this.$message.error('上传文件大小不能超过 2MB!')
  648. }
  649. return isLt2M
  650. },
  651. handleImportSuccess(res, file) {
  652. this.getList()
  653. if (res.msg === 'ok') {
  654. this.$message({ title: '成功', message: '导入成功:' + res.data.success + '条!', type: 'success', duration: 2000 })
  655. if (res.data.err_count > 0) {
  656. this.$notify({ title: '失败', message: '导入失败:' + res.data.err_count + '条!', type: 'danger', duration: 2000 })
  657. import('@/vendor/Export2Excel').then(excel => {
  658. const list1 = res.data.result
  659. const tHeader = ['栏舍名称', '剩料量(kg)', '应用班次', '处理时间', '操作人', '错误信息']
  660. const filterVal = ['栏舍名称', '剩料量(kg)', '应用班次', '处理时间', '操作人', 'error_msg']
  661. const data1 = this.formatJson(filterVal, list1)
  662. excel.export_json_to_excel({ header: tHeader, data: data1, filename: '栏舍剩料记录导入报错信息', autoWidth: true, bookType: 'xlsx' })
  663. })
  664. }
  665. } else {
  666. this.$notify({ title: '失败', message: '上传失败', type: 'danger', duration: 2000 })
  667. }
  668. },
  669. formatJson(filterVal, jsonData) {
  670. return jsonData.map(v =>
  671. filterVal.map(j => {
  672. if (j === 'timestamp') {
  673. return parseTime(v[j])
  674. } else {
  675. return v[j]
  676. }
  677. })
  678. )
  679. }
  680. }
  681. }
  682. </script>
  683. <style lang="scss" scoped>
  684. .search{padding-top:10px;clear: both;}
  685. .table{margin-top:10px;}
  686. </style>