index.vue 30 KB

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