e4b54f6ee9075c8ef441e6f65972e1ad3bf8980c.svn-base 28 KB

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