c7b33ff3cb6340338a22a99c4bb41687d686e94c.svn-base 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  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.usetype" placeholder="操作类型" class="filter-item" style="width: 120px;" clearable>
  8. <el-option v-for="item in operationTypeList" :key="item.id" :label="item.label" :value="item.value" />
  9. </el-select>
  10. <el-autocomplete v-model="table.getdataListParm.parammaps.feedname" value-key="feedname" class="inline-input filter-item" :fetch-suggestions="tableFeedNameSearch" placeholder="饲料名称" style="width:250px" @select="handleSelectTableFeedName">
  11. <template slot-scope="{ item }">
  12. <span>{{ item.feedname }}</span>
  13. </template>
  14. </el-autocomplete>
  15. <el-select v-model="table.getdataListParm.parammaps.cowclassid" filterable placeholder="请选择牲畜类别" class="filter-item" style="width: 150px;" clearable>
  16. <el-option v-for="item in livestockList" :key="item.id" :label="item.mixname" :value="item.id" />
  17. </el-select>
  18. <el-button class="successBorder" @click="handleSearch">查询</el-button>
  19. <el-button class="successBorder" @click="handleRefresh">重置</el-button>
  20. </div>
  21. <div class="operation">
  22. <el-button v-if="isRoleEdit" class="success" icon="el-icon-plus" @click="handleCreate">新增</el-button>
  23. <el-upload style="float: right;" :headers="headers" :data="uploadData" :action="uploadExcelUrl" :show-file-list="false" :before-upload="beforeImport" :on-success="handleImportSuccess">
  24. <el-button v-if="isRoleEdit" class="import" icon="el-icon-download" style="float: right;">导入</el-button>
  25. </el-upload>
  26. <el-dropdown style="float: right;margin-right: 10px;">
  27. <el-button class="export" icon="el-icon-upload2">导出</el-button>
  28. <el-dropdown-menu slot="dropdown">
  29. <el-dropdown-item @click.native="handleExport(1)">导出模板</el-dropdown-item>
  30. <el-dropdown-item @click.native="handleExport(2)">导出数据</el-dropdown-item>
  31. </el-dropdown-menu>
  32. </el-dropdown>
  33. </div>
  34. <div class="table">
  35. <el-table
  36. :key="table.tableKey"
  37. v-loading="table.listLoading"
  38. element-loading-text="给我一点时间"
  39. :data="table.list"
  40. border
  41. fit
  42. highlight-current-row
  43. style="width: 100%;"
  44. :row-style="rowStyle"
  45. :cell-style="cellStyle"
  46. class="elTable table-fixed"
  47. >
  48. <el-table-column label="序号" align="center" type="index" width="50px">
  49. <template slot-scope="scope">
  50. <span>{{ scope.$index + (table.pageNum-1) * table.pageSize + 1 }}</span>
  51. </template>
  52. </el-table-column>
  53. <el-table-column label="出库日期" min-width="130px" align="center">
  54. <template slot-scope="scope">
  55. <span>{{ scope.row.usedate }}</span>
  56. </template>
  57. </el-table-column>
  58. <el-table-column label="牲畜类别" min-width="130px" align="center">
  59. <template slot-scope="scope">
  60. <span>{{ scope.row.cowclass }}</span>
  61. </template>
  62. </el-table-column>
  63. <el-table-column label="饲料名称" min-width="110px" align="center">
  64. <template slot-scope="scope">
  65. <span>{{ scope.row.feedname }}</span>
  66. </template>
  67. </el-table-column>
  68. <el-table-column label="操作重量(kg)" min-width="110px" align="center">
  69. <template slot-scope="scope">
  70. <span>{{ scope.row.operateweight }}</span>
  71. </template>
  72. </el-table-column>
  73. <el-table-column label="操作类型" min-width="110px" align="center">
  74. <template slot-scope="scope">
  75. <span>{{ scope.row.usetype }}</span>
  76. </template>
  77. </el-table-column>
  78. <el-table-column label="备注" min-width="110px" align="center">
  79. <template slot-scope="scope">
  80. <span>{{ scope.row.remark }}</span>
  81. </template>
  82. </el-table-column>
  83. <el-table-column label="操作人" min-width="110px" align="center">
  84. <template slot-scope="scope">
  85. <span>{{ scope.row.createemp }}</span>
  86. </template>
  87. </el-table-column>
  88. <el-table-column label="操作" align="center" width="50" class-name="small-padding fixed-width" fixed="right">
  89. <template slot-scope="{row}">
  90. <el-button class="miniSuccess" icon="el-icon-search" @click="handleSee(row)" />
  91. </template>
  92. </el-table-column>
  93. </el-table>
  94. <pagination v-show="table.total>=0" :total="table.total" :page.sync="table.getdataListParm.offset" :limit.sync="table.getdataListParm.pagecount" @pagination="getList" />
  95. </div>
  96. <!-- 新增/编辑 -->
  97. <el-dialog :title="textMap[create.dialogStatus]" :visible.sync="create.dialogFormVisible" :close-on-click-modal="false" width="80%">
  98. <div class="app-add">
  99. <el-form ref="createTemp" :rules="create.rules" :model="create.createTemp" label-position="right" label-width="150px" style="width: 90%;height:300px;margin:0 auto 50px">
  100. <el-row>
  101. <el-col :span="12">
  102. <el-form-item label="操作类型:" prop="usetype">
  103. <el-select v-model="create.createTemp.usetype" placeholder="操作类型" class="filter-item" style="width: 100%;" :disabled="create.dialogStatus==='see'" @change="changeUsetype">
  104. <el-option v-for="item in operationTypeList" :key="item.id" :label="item.label" :value="item.value" />
  105. </el-select>
  106. </el-form-item>
  107. </el-col>
  108. <el-col :span="12">
  109. <el-form-item label="出库日期:" prop="usedate">
  110. <el-date-picker v-model="create.createTemp.usedate" :picker-options="create.pickerOptions1" :clearable="false" class="filter-item" format="yyyy-MM-dd" value-format="yyyy-MM-dd" style="width: 100%;" type="datetime" placeholder="出库日期" :disabled="create.dialogStatus==='see'" />
  111. </el-form-item>
  112. </el-col>
  113. </el-row>
  114. <el-row>
  115. <el-col :span="12">
  116. <el-form-item label="饲料名称:" prop="feedname">
  117. <el-autocomplete v-model="create.createTemp.feedname" :disabled="create.dialogStatus==='see'" value-key="feedname" class="inline-input" :fetch-suggestions="feedNameSearch" placeholder="请选择饲料名称" style="width:100%" @select="handleSelectFeedName" @blur="blurFeedName">
  118. <template slot-scope="{ item }">
  119. <span>{{ item.feedname }}</span>
  120. </template>
  121. </el-autocomplete>
  122. </el-form-item>
  123. </el-form-item>
  124. </el-col>
  125. <el-col :span="12">
  126. <el-form-item label="牲畜类别:" prop="cowclassid">
  127. <el-input v-if="create.dialogStatus==='see'" ref="cowclass" v-model="create.createTemp.cowclass" disabled class="filter-item" placeholder="请选择牲畜类别" type="text" disabled />
  128. <el-select v-else v-model="create.createTemp.cowclassid" filterable placeholder="请选择牲畜类别" class="filter-item" style="width: 100%;" :disabled="create.dialogStatus==='see' || create.createTemp.usetype=='损耗'" @change="changeLivestock">
  129. <el-option v-for="item in livestockList" :key="item.id" :label="item.mixname" :value="item.id" />
  130. </el-select>
  131. </el-form-item>
  132. </el-col>
  133. </el-row>
  134. <el-row>
  135. <el-col :span="12">
  136. <el-form-item label="库存重量(kg):" prop="repertoryweight">
  137. <el-input ref="repertoryweight" v-model="create.createTemp.repertoryweight" class="filter-item" placeholder="最多两位小数" type="text" disabled />
  138. </el-form-item>
  139. </el-col>
  140. <el-col :span="12">
  141. <el-form-item label="操作重量(kg):" prop="operateweight">
  142. <el-input ref="operateweight" v-model="create.createTemp.operateweight" class="filter-item" placeholder="最多两位小数" type="text" :disabled="create.dialogStatus==='see'" />
  143. </el-form-item>
  144. </el-col>
  145. </el-row>
  146. <el-row>
  147. <el-col :span="12">
  148. <el-form-item label="备注:" prop="remark">
  149. <el-input ref="remark" v-model="create.createTemp.remark" class="filter-item" placeholder="1-255字符" type="text" :disabled="create.dialogStatus==='see'" />
  150. </el-form-item>
  151. </el-col>
  152. <el-col :span="12">
  153. <el-form-item label="操作人:" prop="createemp">
  154. <el-input ref="createemp" v-model="create.createTemp.createemp" class="filter-item" placeholder="1-255字符" type="text" disabled />
  155. </el-form-item>
  156. </el-col>
  157. </el-row>
  158. </el-form>
  159. <div slot="footer" class="dialog-footer">
  160. <el-button v-if="create.dialogStatus==='see'" class="cancelClose cancelClose1" @click="create.dialogFormVisible = false;getList();">关闭</el-button>
  161. <el-button v-if="create.dialogStatus==='create'" class="cancelClose" @click="create.dialogFormVisible = false;getList();">关闭</el-button>
  162. <el-button v-if="create.dialogStatus==='create'" class="save" :disabled="isokDisable" @click="createData()">确认</el-button>
  163. </div>
  164. </div>
  165. </el-dialog>
  166. </div>
  167. </template>
  168. <script>
  169. import { GetDataByName, GetDataByNames, checkButtons, ExecDataByConfig, failproccess } from '@/api/common'
  170. import Pagination from '@/components/Pagination'
  171. import Cookies from 'js-cookie'
  172. import { parseTime, json2excel } from '@/utils/index.js'
  173. import axios from 'axios'
  174. import { getToken } from '@/utils/auth'
  175. export default {
  176. name: 'LaborConsumption',
  177. components: { Pagination },
  178. data() {
  179. return {
  180. isRoleEdit: [],
  181. requestParams: [
  182. { name: 'getDictByName', offset: 0, pagecount: 0, params: ['人工用量操作类型'] },
  183. { name: 'getCowclassListEnable', offset: 0, pagecount: 0, parammaps: { 'pastureid': Cookies.get('pastureid') }}
  184. ],
  185. operationTypeList: [], // 操作类型
  186. feedNameList: [], // 饲料名称
  187. livestockList: [], // 牲畜类别
  188. table: {
  189. getdataListParm: {
  190. name: 'getFeeduseList',
  191. page: 1,
  192. offset: 1,
  193. pagecount: parseInt(Cookies.get('pageCount')),
  194. returntype: 'Map',
  195. parammaps: {
  196. inputDatetime: '',
  197. pastureid: Cookies.get('pastureid'),
  198. startTime: '',
  199. stopTime: '',
  200. usetype: '',
  201. feedid: '',
  202. cowclassid: ''
  203. }
  204. },
  205. tableKey: 0,
  206. list: [],
  207. total: 0,
  208. listLoading: true
  209. },
  210. create: {
  211. pickerOptions1: {
  212. disabledDate(time) {
  213. return time.getTime() > Date.now()// 当天之前的时间可选
  214. }
  215. },
  216. dialogFormVisible: false,
  217. dialogStatus: '',
  218. createTemp: {
  219. pastureid: Cookies.get('pastureid'), usedate: parseTime(new Date(), '{y}-{m}-{d}'), feedid: '', feedname: '', cowclassid: '', cowclass: '', usetype: '', operateweight: '', repertoryweight: '', createemp: '', remark: '', price: '', operator: Cookies.get('employename')
  220. },
  221. getfeedNameParm: {
  222. name: 'getFeedstorageuse',
  223. offset: 0,
  224. pagecount: '',
  225. parammaps: { pastureid: Cookies.get('pastureid') }
  226. },
  227. rules: {
  228. usetype: [{ type: 'string', required: true, message: '必填', trigger: 'blur' }],
  229. usedate: [{ type: 'string', required: true, message: '必填', trigger: 'blur' }],
  230. feedname: [{ type: 'string', required: true, message: '必填', trigger: 'change' }],
  231. operateweight: [{ type: 'string', required: true, message: '必填', trigger: 'blur' }],
  232. cowclassid: [{ type: 'string', required: true, message: '必填', trigger: 'blur' }]
  233. }
  234. },
  235. textMap: {
  236. create: '新增',
  237. see: '查看'
  238. },
  239. requestParam: {},
  240. download: {
  241. getdataListParm: {
  242. name: 'getFeeduseList',
  243. page: 1,
  244. offset: 1,
  245. pagecount: 0,
  246. returntype: 'Map',
  247. parammaps: {
  248. inputDatetime: '',
  249. pastureid: Cookies.get('pastureid'),
  250. startTime: '',
  251. stopTime: '',
  252. usetype: '',
  253. feedid: '',
  254. cowclassid: ''
  255. }
  256. },
  257. list: []
  258. },
  259. isokDisable: false,
  260. rowStyle: { maxHeight: 30 + 'px', height: 30 + 'px' },
  261. cellStyle: { padding: 0 + 'px' }
  262. }
  263. },
  264. computed: {
  265. // 设置请求头
  266. headers() {
  267. return {
  268. token: getToken()
  269. }
  270. },
  271. uploadData() {
  272. return {
  273. name: 'checkFeed,checkclassname,checkfeedusetype,insertFeeduseUpload,insertFeedstorageUseUpload',
  274. importParams: '出库日期,操作类型,牲畜类别,饲料名称,操作重量(kg),备注,操作人',
  275. sheetname: 'Sheet1',
  276. // 登录牧场
  277. pastureid: Cookies.get('pastureid'),
  278. // 日期参数
  279. dateParams: '出库日期',
  280. // 必填参数
  281. requiredParams: '出库日期,操作类型,饲料名称,操作重量(kg)',
  282. // 为数值的参数
  283. numParams: '操作重量(kg)'
  284. }
  285. },
  286. // 设置上传地址
  287. uploadExcelUrl() {
  288. return process.env.VUE_APP_BASE_API + 'authdata/ImportExcel'
  289. }
  290. },
  291. created() {
  292. this.getList()
  293. this.getDownList()
  294. this.getButtons()
  295. },
  296. methods: {
  297. getButtons() {
  298. const Edit = 'SystemConsumption'
  299. const isRoleEdit = checkButtons(JSON.parse(sessionStorage.getItem('buttons')), Edit)
  300. this.isRoleEdit = isRoleEdit
  301. },
  302. getDownList() {
  303. GetDataByNames(this.requestParams).then(response => {
  304. this.operationTypeList = response.data.getDictByName.list
  305. this.livestockList = response.data.getCowclassListEnable.list
  306. })
  307. },
  308. handleBefore() {
  309. if (this.table.getdataListParm.parammaps.inputDatetime !== '' && this.table.getdataListParm.parammaps.inputDatetime !== null) {
  310. var start = new Date(this.table.getdataListParm.parammaps.inputDatetime[0].setDate(this.table.getdataListParm.parammaps.inputDatetime[0].getDate() - 1))
  311. var stop = new Date(this.table.getdataListParm.parammaps.inputDatetime[1].setDate(this.table.getdataListParm.parammaps.inputDatetime[1].getDate() - 1))
  312. this.table.getdataListParm.parammaps.inputDatetime.length = 0
  313. this.table.getdataListParm.parammaps.inputDatetime.push(start, stop)
  314. this.table.getdataListParm.parammaps.startTime = parseTime(start, '{y}-{m}-{d}')
  315. this.table.getdataListParm.parammaps.stopTime = parseTime(stop, '{y}-{m}-{d}')
  316. this.$forceUpdate()
  317. }
  318. },
  319. handleNext() {
  320. if (this.table.getdataListParm.parammaps.inputDatetime !== '' && this.table.getdataListParm.parammaps.inputDatetime !== null) {
  321. var start = new Date(this.table.getdataListParm.parammaps.inputDatetime[0].setDate(this.table.getdataListParm.parammaps.inputDatetime[0].getDate() + 1))
  322. var stop = new Date(this.table.getdataListParm.parammaps.inputDatetime[1].setDate(this.table.getdataListParm.parammaps.inputDatetime[1].getDate() + 1))
  323. this.table.getdataListParm.parammaps.inputDatetime.length = 0
  324. this.table.getdataListParm.parammaps.inputDatetime.push(start, stop)
  325. this.table.getdataListParm.parammaps.startTime = parseTime(start, '{y}-{m}-{d}')
  326. this.table.getdataListParm.parammaps.stopTime = parseTime(stop, '{y}-{m}-{d}')
  327. this.$forceUpdate()
  328. }
  329. },
  330. getList() {
  331. this.table.listLoading = true
  332. GetDataByName(this.table.getdataListParm).then(response => {
  333. console.log('table数据', response.data.list)
  334. if (response.data.list !== null) {
  335. this.table.list = response.data.list
  336. this.table.pageNum = response.data.pageNum
  337. this.table.pageSize = response.data.pageSize
  338. this.table.total = response.data.total
  339. } else {
  340. this.table.list = []
  341. }
  342. setTimeout(() => {
  343. this.table.listLoading = false
  344. }, 100)
  345. })
  346. },
  347. handleSearch() {
  348. console.log('点击了查询')
  349. if (this.table.getdataListParm.parammaps.inputDatetime !== '' && this.table.getdataListParm.parammaps.inputDatetime !== null) {
  350. this.table.getdataListParm.parammaps.startTime = parseTime(this.table.getdataListParm.parammaps.inputDatetime[0], '{y}-{m}-{d}')
  351. this.table.getdataListParm.parammaps.stopTime = parseTime(this.table.getdataListParm.parammaps.inputDatetime[1], '{y}-{m}-{d}')
  352. } else {
  353. this.table.getdataListParm.parammaps.inputDatetime = ''
  354. this.table.getdataListParm.parammaps.startTime = ''
  355. this.table.getdataListParm.parammaps.stopTime = ''
  356. }
  357. this.table.getdataListParm.offset = 1
  358. this.getList()
  359. },
  360. handleRefresh() {
  361. console.log('点击了重置')
  362. this.table.getdataListParm.parammaps.inputDatetime = ''
  363. this.table.getdataListParm.parammaps.startTime = ''
  364. this.table.getdataListParm.parammaps.stopTime = ''
  365. this.table.getdataListParm.parammaps.feedid = ''
  366. this.table.getdataListParm.parammaps.cowclassid = ''
  367. this.table.getdataListParm.parammaps.ischarge = ''
  368. this.table.getdataListParm.parammaps.usetype = ''
  369. this.table.getdataListParm.parammaps.feedname = ''
  370. this.table.getdataListParm.parammaps.cowclassid = ''
  371. this.getList()
  372. },
  373. // 操作类型
  374. changeUsetype(item) {
  375. console.log(item)
  376. if (item == '损耗') {
  377. console.log(item)
  378. this.create.createTemp.cowclassid = '/'
  379. this.create.createTemp.cowclass = '/'
  380. } else {
  381. this.create.createTemp.cowclassid = ''
  382. this.create.createTemp.cowclass = ''
  383. }
  384. },
  385. tableFeedNameSearch(queryString, cb) {
  386. this.create.getfeedNameParm.parammaps['feedname'] = queryString
  387. GetDataByName(this.create.getfeedNameParm).then(response => {
  388. console.log('模糊查询搜索data', response.data.list)
  389. if (response.data.list == null) {
  390. cb([])
  391. } else {
  392. cb(response.data.list)
  393. }
  394. })
  395. },
  396. handleSelectTableFeedName(item) {
  397. this.table.getdataListParm.parammaps.feedid = item.feedid
  398. },
  399. // 饲料名称
  400. feedNameSearch(queryString, cb) {
  401. this.create.getfeedNameParm.parammaps['feedname'] = queryString
  402. GetDataByName(this.create.getfeedNameParm).then(response => {
  403. console.log('模糊查询搜索data', response.data.list)
  404. if (response.data.list == null) {
  405. cb([])
  406. } else {
  407. cb(response.data.list)
  408. }
  409. })
  410. },
  411. handleSelectFeedName(item) {
  412. console.log(item)
  413. this.create.createTemp.feedname = item.feedname
  414. this.create.createTemp.feedid = item.feedid
  415. this.create.createTemp.price = item.price
  416. this.create.createTemp.pcpde = item.pcpde
  417. this.create.createTemp.repertoryweight = item.stockweight
  418. },
  419. blurFeedName() {
  420. this.create.createTemp.feedname = ''
  421. this.create.createTemp.feedid = ''
  422. this.create.createTemp.price = ''
  423. this.create.createTemp.pcpde = ''
  424. this.create.createTemp.repertoryweight = ''
  425. },
  426. // 牲畜类别
  427. changeLivestock(item) {
  428. this.create.createTemp.cowclass = this.livestockList.find(obj => obj.id == item).classname
  429. },
  430. resetCreateTemp() {
  431. this.create.createTemp = {
  432. cowclassid1: '-1', pastureid: Cookies.get('pastureid'), usedate: parseTime(new Date(), '{y}-{m}-{d}'), feedid: '', feedname: '', cowclassid: '', cowclass: '', usetype: '', operateweight: '', repertoryweight: '', createemp: Cookies.get('employename'), remark: '', price: '', operator: Cookies.get('employename')
  433. }
  434. },
  435. handleCreate() {
  436. console.log('点击了新增')
  437. this.create.dialogStatus = 'create'
  438. this.create.dialogFormVisible = true
  439. this.$nextTick(() => {
  440. this.resetCreateTemp()
  441. this.$refs.createTemp.resetFields()
  442. })
  443. },
  444. createData() {
  445. console.log('点击了新增保存')
  446. this.$refs['createTemp'].validate(valid => {
  447. if (valid) {
  448. this.isokDisable = true
  449. setTimeout(() => {
  450. this.isokDisable = false
  451. }, 1000)
  452. if (this.create.createTemp.usetype == '人工用料') {
  453. if (this.create.createTemp.cowclassid == '') {
  454. this.$message({ type: 'error', message: '请选择牲畜类别', duration: 2000 })
  455. return false
  456. }
  457. }
  458. const keepTwoNum = /^\d+(\.\d{1,2})?$/
  459. // 操作重量
  460. if (this.create.createTemp.operateweight == 0) {
  461. this.$message({ type: 'error', message: '操作重量请输入自然数并保留两位小数', duration: 2000 })
  462. return false
  463. } else {
  464. if (!keepTwoNum.test(parseFloat(this.create.createTemp.operateweight))) {
  465. this.$message({ type: 'error', message: '操作重量请输入自然数并保留两位小数', duration: 2000 })
  466. return false
  467. }
  468. }
  469. if (this.create.createTemp.cowclassid == '/' && this.create.createTemp.cowclass == '/') {
  470. this.create.createTemp.cowclassid = ''
  471. this.create.createTemp.cowclass = ''
  472. }
  473. this.requestParam.common = { 'returnmap': '0' }
  474. this.requestParam.data = []
  475. this.requestParam.data[0] = { 'name': 'insertFeeduse', 'type': 'e', 'parammaps': {
  476. 'pastureid': this.create.createTemp.pastureid,
  477. 'usedate': this.create.createTemp.usedate,
  478. 'feedid': this.create.createTemp.feedid,
  479. 'feedname': this.create.createTemp.feedname,
  480. 'cowclassid': this.create.createTemp.cowclassid,
  481. 'cowclass': this.create.createTemp.cowclass,
  482. 'usetype': this.create.createTemp.usetype,
  483. 'operateweight': this.create.createTemp.operateweight,
  484. 'repertoryweight': this.create.createTemp.repertoryweight,
  485. 'createemp': this.create.createTemp.createemp,
  486. 'remark': this.create.createTemp.remark,
  487. 'price': this.create.createTemp.price
  488. }}
  489. this.requestParam.data[1] = { 'name': 'insertFeedstorageUse', 'type': 'e', 'parammaps': {
  490. 'pastureid': this.create.createTemp.pastureid,
  491. 'feedid': this.create.createTemp.feedid,
  492. 'operateweight': this.create.createTemp.operateweight,
  493. 'fname': this.create.createTemp.feedname,
  494. 'pcpde': this.create.createTemp.pcpde,
  495. 'price': this.create.createTemp.price
  496. }}
  497. ExecDataByConfig(this.requestParam).then(response => {
  498. if (response.msg === 'fail') {
  499. this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
  500. } else {
  501. this.$notify({ title: '', message: '成功', type: 'success', duration: 2000 })
  502. this.create.dialogFormVisible = false
  503. this.getList()
  504. }
  505. })
  506. }
  507. })
  508. },
  509. handleSee(row) {
  510. this.$nextTick(() => {
  511. this.$refs.createTemp.resetFields()
  512. })
  513. this.create.dialogStatus = 'see'
  514. this.create.dialogFormVisible = true
  515. if (row.cowclassid == -1) {
  516. row.cowclassid = ''
  517. row.cowclass = ''
  518. }
  519. this.create.createTemp = Object.assign({}, row)
  520. },
  521. handleRowDelete(row) {
  522. console.log('点击了行内删除')
  523. },
  524. // 导出
  525. handleExport(item) {
  526. if (item == 1) {
  527. console.log('点击了导出模板')
  528. const requestParam = this.requestParam
  529. const url = process.env.VUE_APP_BASE_API + 'file/导入导出模板/库存管理/人工用量导入模板.xlsx' // 请求下载文件的地址
  530. console.log(url)
  531. axios({
  532. method: 'GET',
  533. url: url,
  534. data: requestParam,
  535. headers: { token: getToken(), optname: 'insertcustomdoc' },
  536. responseType: 'blob'
  537. }).then(res => {
  538. if (!res) return
  539. this.percentage = 99
  540. setTimeout(() => {
  541. this.isPercentage = false
  542. }, 2000)
  543. const blob = new Blob([res.data], {
  544. type: 'application/octet-stream;charset=utf-8'
  545. })
  546. const url = window.URL.createObjectURL(blob)
  547. const aLink = document.createElement('a')
  548. aLink.style.display = 'none'
  549. aLink.href = url
  550. const docname = '人工用量导入模板.xlsx'
  551. aLink.setAttribute('download', docname) // 下载的文件
  552. document.body.appendChild(aLink)
  553. aLink.click()
  554. document.body.removeChild(aLink)
  555. window.URL.revokeObjectURL(url)
  556. })
  557. } else {
  558. console.log('点击了导出数据')
  559. this.download.getdataListParm.parammaps = this.table.getdataListParm.parammaps
  560. if (this.download.getdataListParm.parammaps.inputDatetime !== '' && this.download.getdataListParm.parammaps.inputDatetime !== null) {
  561. this.download.getdataListParm.parammaps.startTime = parseTime(this.download.getdataListParm.parammaps.inputDatetime[0], '{y}-{m}-{d}')
  562. this.download.getdataListParm.parammaps.stopTime = parseTime(this.download.getdataListParm.parammaps.inputDatetime[1], '{y}-{m}-{d}')
  563. } else {
  564. this.download.getdataListParm.parammaps.inputDatetime = ''
  565. this.download.getdataListParm.parammaps.startTime = ''
  566. this.download.getdataListParm.parammaps.stopTime = ''
  567. }
  568. GetDataByName(this.download.getdataListParm).then(response => {
  569. if (response.data.list !== null) {
  570. this.download.list = response.data.list
  571. } else {
  572. this.download.list = []
  573. }
  574. var excelDatas = [
  575. {
  576. tHeader: ['出库日期', '操作类型', '牲畜类别', '饲料名称', '操作重量(kg)', '备注', '操作人'],
  577. filterVal: ['usedate', 'usetype', 'cowclass', 'feedname', 'operateweight', 'remark', 'createemp'],
  578. tableDatas: this.download.list,
  579. sheetName: 'Sheet1'
  580. }
  581. ]
  582. json2excel(excelDatas, '人工用量', true, 'xlsx')
  583. })
  584. }
  585. },
  586. beforeImport(file) {
  587. const isLt2M = file.size / 1024 / 1024 < 2
  588. if (!isLt2M) {
  589. this.$message.error('上传文件大小不能超过 2MB!')
  590. }
  591. return isLt2M
  592. },
  593. handleImportSuccess(res, file) {
  594. this.getList()
  595. if (res.msg === 'ok') {
  596. this.$message({ title: '成功', message: '导入成功:' + res.data.success + '条!', type: 'success', duration: 2000 })
  597. if (res.data.err_count > 0) {
  598. this.$notify({ title: '失败', message: '导入失败:' + res.data.err_count + '条!', type: 'danger', duration: 2000 })
  599. import('@/vendor/Export2Excel').then(excel => {
  600. const list1 = res.data.result
  601. const tHeader = [
  602. '出库日期', '操作类型', '牲畜类别', '饲料名称', '操作重量(kg)', '备注', '操作人', '错误信息'
  603. ]
  604. const filterVal = [
  605. '出库日期', '操作类型', '牲畜类别', '饲料名称', '操作重量(kg)', '备注', '操作人', 'error_msg'
  606. ]
  607. const data1 = this.formatJson(filterVal, list1)
  608. excel.export_json_to_excel({ header: tHeader, data: data1, filename: '人工用量导入报错信息', autoWidth: true, bookType: 'xlsx' })
  609. })
  610. }
  611. } else {
  612. this.$notify({ title: '失败', message: '上传失败', type: 'danger', duration: 2000 })
  613. }
  614. },
  615. formatJson(filterVal, jsonData) {
  616. return jsonData.map(v =>
  617. filterVal.map(j => {
  618. if (j === 'timestamp') {
  619. return parseTime(v[j])
  620. } else {
  621. return v[j]
  622. }
  623. })
  624. )
  625. }
  626. }
  627. }
  628. </script>
  629. <style lang="scss" scoped>
  630. .search{margin-top:10px;}
  631. .table{margin-top:10px;}
  632. </style>
  633. <style lang="scss">
  634. .typeSelect span .el-popover__reference .el-input--suffix {
  635. .el-input__inner{
  636. height:40px !important;
  637. }
  638. }
  639. </style>