7d06b094111113e727a2f35d313a2d13b371aedb.svn-base 31 KB

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