e0dbe48364d931845981354d76688cf5b93d8e2c.svn-base 30 KB

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