4a89c3d3c7e7244a1c12041fde9ada2ad6b88457.svn-base 31 KB

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