5ab9b4e57b780bacf76d65bd756051463e410b7d.svn-base 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793
  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-select v-model="table.getdataListParm.parammaps.times" filterable placeholder="班次" class="filter-item" style="width: 120px;" clearable>
  26. <el-option v-for="item in frequencyList" :key="item.id" :label="item.name" :value="item.id" />
  27. </el-select>
  28. <el-button class="successBorder" @click="handleSearch">查询</el-button>
  29. <el-button class="successBorder" @click="handleRefresh">重置</el-button>
  30. </div>
  31. <div class="table">
  32. <el-table
  33. :key="table.tableKey"
  34. v-loading="table.listLoading"
  35. element-loading-text="给我一点时间"
  36. :data="table.list"
  37. border
  38. fit
  39. highlight-current-row
  40. style="width: 100%;"
  41. :row-style="rowStyle"
  42. :cell-style="cellStyle"
  43. class="elTable table-fixed"
  44. @selection-change="handleSelectionChange"
  45. >
  46. <el-table-column type="selection" align="center" width="50" />
  47. <el-table-column label="序号" align="center" type="index" width="50px">
  48. <template slot-scope="scope">
  49. <span>{{ scope.$index + (table.pageNum-1) * table.pageSize + 1 }}</span>
  50. </template>
  51. </el-table-column>
  52. <el-table-column label="栏舍名称" min-width="150px" align="center">
  53. <template slot-scope="scope">
  54. <span>{{ scope.row.barname }}</span>
  55. </template>
  56. </el-table-column>
  57. <el-table-column label="班次" min-width="90px" align="center">
  58. <template slot-scope="scope">
  59. <span>{{ scope.row.timesstr }}</span>
  60. </template>
  61. </el-table-column>
  62. <el-table-column label="鲜样重量(g)" min-width="100px" align="center">
  63. <template slot-scope="scope">
  64. <span>{{ scope.row.freshweight }}</span>
  65. </template>
  66. </el-table-column>
  67. <el-table-column label="烘干重量(g)" min-width="100px" align="center">
  68. <template slot-scope="scope">
  69. <span>{{ scope.row.dryweight }}</span>
  70. </template>
  71. </el-table-column>
  72. <el-table-column label="理论干物质" min-width="100px" align="center">
  73. <template slot-scope="scope">
  74. <span>{{ scope.row.thoweight }}</span>
  75. </template>
  76. </el-table-column>
  77. <el-table-column label="实际干物质" min-width="100px" align="center">
  78. <template slot-scope="scope">
  79. <span>{{ scope.row.actweight }}</span>
  80. </template>
  81. </el-table-column>
  82. <el-table-column label="操作人" min-width="90px" align="center">
  83. <template slot-scope="scope">
  84. <span>{{ scope.row.emp }}</span>
  85. </template>
  86. </el-table-column>
  87. <el-table-column label="操作日期" min-width="100px" align="center">
  88. <template slot-scope="scope">
  89. <span>{{ scope.row.operatetime }}</span>
  90. </template>
  91. </el-table-column>
  92. <el-table-column label="操作" align="center" width="250" class-name="small-padding fixed-width" fixed="right">
  93. <template slot-scope="{row}">
  94. <el-button v-if="isRoleEdit" class="miniSuccess" @click="handleUpdate(row)">编辑</el-button>
  95. <el-button v-if="isRoleEdit" class="miniDanger" @click="handleRowDelete(row)">删除</el-button>
  96. </template>
  97. </el-table-column>
  98. </el-table>
  99. <pagination v-show="table.total>=0" :total="table.total" :page.sync="table.getdataListParm.offset" :limit.sync="table.getdataListParm.pagecount" @pagination="getList" />
  100. </div>
  101. <!-- 新增/编辑 -->
  102. <el-dialog :title="textMap[create.dialogStatus]" :visible.sync="create.dialogFormVisible" :close-on-click-modal="false" width="70%">
  103. <div class="app-add">
  104. <el-form ref="temp" :rules="create.rules" :model="create.temp" label-position="right" label-width="135px" style="width: 90%;margin:0 auto 50px">
  105. <el-row>
  106. <el-col v-if="create.dialogStatus=='create'" :span="12">
  107. <el-form-item label="栏舍名称:" prop="barid">
  108. <el-select ref="barid" v-model="create.temp.barid" filterable placeholder="栏舍名称" class="filter-item" style="width: 100%;" @change="changeBar">
  109. <el-option v-for="item in houseNameList" :key="item.id" :label="item.bname" :value="item.id" />
  110. </el-select>
  111. </el-form-item>
  112. </el-col>
  113. <el-col v-else :span="12">
  114. <el-form-item label="栏舍名称:" prop="barname">
  115. <el-input ref="barname" v-model="create.temp.barname" disabled class="filter-item" placeholder="barname" />
  116. </el-form-item>
  117. </el-col>
  118. <el-col :span="12">
  119. <el-form-item label="班次:" prop="times">
  120. <el-select ref="times" v-model="create.temp.times" :disabled="create.dialogStatus=='update'" filterable placeholder="班次" class="filter-item" style="width: 100%;">
  121. <el-option v-for="item in frequencyList" :key="item.id" :label="item.name" :value="item.id" />
  122. </el-select>
  123. </el-form-item>
  124. </el-col>
  125. </el-row>
  126. <el-row>
  127. <el-col :span="12">
  128. <el-form-item label="鲜样重量(g):" prop="freshweight">
  129. <el-input ref="freshweight" v-model="create.temp.freshweight" class="filter-item" placeholder="最多两位小数" type="number" @blur="blurFreshweight" />
  130. </el-form-item>
  131. </el-col>
  132. <el-col :span="12">
  133. <el-form-item label="烘干重量(g):" prop="dryweight">
  134. <el-input ref="dryweight" v-model="create.temp.dryweight" class="filter-item" placeholder="最多两位小数" type="number" @blur="blurDryweight" />
  135. </el-form-item>
  136. </el-col>
  137. </el-row>
  138. <el-row>
  139. <el-col :span="12">
  140. <el-form-item label="理论干物质:" prop="thoweight">
  141. <span>{{ create.temp.thoweight }}</span>
  142. </el-form-item>
  143. </el-col>
  144. <el-col :span="12">
  145. <el-form-item label="实际干物质:" prop="actweight">
  146. <span>{{ create.temp.actweight }}</span>
  147. </el-form-item>
  148. </el-col>
  149. </el-row>
  150. <el-row>
  151. <el-col :span="12">
  152. <el-form-item label="操作人:" prop="emp">
  153. <el-select ref="emp" v-model="create.temp.emp" filterable placeholder="操作人" class="filter-item" style="width: 100%;" @blur="blurEmp">
  154. <el-option v-for="item in create.noteTakerList" :key="item.myId" :label="item.emp" :value="item.emp" />
  155. </el-select>
  156. </el-form-item>
  157. </el-col>
  158. <el-col :span="12">
  159. <el-form-item label="操作日期:" prop="operatetime">
  160. <el-date-picker v-model="create.temp.operatetime" :disabled="create.dialogStatus=='update'" type="date" placeholder="选择日期" format="yyyy-MM-dd" value-format="yyyy-MM-dd" style="width: 100%;" :clearable="false" @change="changeOperatetime" />
  161. </el-form-item>
  162. </el-col>
  163. </el-row>
  164. </el-form>
  165. <div slot="footer" class="dialog-footer">
  166. <el-button class="cancelClose" @click="create.dialogFormVisible = false;getList()">关闭</el-button>
  167. <el-button v-if="create.dialogStatus==='create'" class="success" :disabled="isokDisable" @click="createDataAgain()">确认新增</el-button>
  168. <el-button v-if="create.dialogStatus==='create' || create.dialogStatus==='update'" class="success" :disabled="isokDisable" @click="create.dialogStatus==='create'?createData():updateData()">确认</el-button>
  169. </div>
  170. </div>
  171. </el-dialog>
  172. </div>
  173. </template>
  174. <script>
  175. import { GetDataByName, PostDataByName, failproccess, ExecDataByConfig, GetDataByNames, checkButtons } from '@/api/common'
  176. import Cookies from 'js-cookie'
  177. import { parseTime, json2excel } from '@/utils/index.js'
  178. import Pagination from '@/components/Pagination'
  179. import { MessageBox } from 'element-ui'
  180. import axios from 'axios'
  181. import { getToken } from '@/utils/auth'
  182. export default {
  183. name: 'FormulaDryMatter',
  184. components: { Pagination },
  185. data() {
  186. return {
  187. isRoleEdit: [],
  188. requestParams: [
  189. { name: 'getBarListEnable', offset: 0, pagecount: 0, parammaps: { 'pastureid': Cookies.get('pastureid') }},
  190. { name: 'getSysoptEnable', offset: 0, pagecount: 0, parammaps: { 'pastureid': Cookies.get('pastureid'), 'inforname': 'times' }}
  191. ],
  192. houseNameList: [], // 栏舍名称
  193. frequencyList: [], // 班次
  194. table: {
  195. getdataListParm: {
  196. name: 'getFtdryList',
  197. page: 1,
  198. offset: 1,
  199. pagecount: 10,
  200. returntype: 'Map',
  201. parammaps: {
  202. pastureid: Cookies.get('pastureid'),
  203. barid: '',
  204. times: '',
  205. startTime: '',
  206. stopTime: '',
  207. inputDatetime: ''
  208. }
  209. },
  210. tableKey: 0,
  211. list: [],
  212. total: 0,
  213. listLoading: true,
  214. temp: {}
  215. },
  216. // 新增/编辑
  217. create: {
  218. dialogFormVisible: false,
  219. dialogStatus: '',
  220. temp: { pastureid: Cookies.get('pastureid'), operatetime: parseTime(new Date(), '{y}-{m}-{d}'), emp: Cookies.get('employename'), barid: '', barname: '', freshweight: '', dryweight: '', thoweight: '', actweight: '', times: '' },
  221. rules: {
  222. barid: [{ type: 'string', required: true, message: '必填', trigger: 'blur' }],
  223. times: [{ type: 'string', required: true, message: '必填', trigger: 'blur' }],
  224. freshweight: [{ type: 'string', required: true, message: '必填', trigger: 'blur' }],
  225. dryweight: [{ type: 'string', required: true, message: '必填', trigger: 'blur' }]
  226. },
  227. // 操作人
  228. getdataListParm: {
  229. name: 'getFtdryEmpHis',
  230. page: 1,
  231. offset: 1,
  232. pagecount: 10,
  233. returntype: 'Map',
  234. parammaps: {
  235. pastureid: Cookies.get('pastureid')
  236. }
  237. },
  238. // 理论干物质
  239. getdataListParm2: {
  240. name: 'getFtdrytweight',
  241. page: 1,
  242. offset: 1,
  243. pagecount: 10,
  244. returntype: 'Map',
  245. parammaps: {
  246. pastureid: Cookies.get('pastureid'),
  247. barid: '',
  248. date: ''
  249. }
  250. },
  251. noteTakerList: [] // 记录人
  252. },
  253. textMap: {
  254. create: '新增',
  255. update: '编辑'
  256. },
  257. requestParam: {},
  258. download: {
  259. getdataListParm: {
  260. name: 'getFtdryList',
  261. page: 1,
  262. offset: 1,
  263. pagecount: 0,
  264. returntype: 'Map',
  265. parammaps: {
  266. pastureid: Cookies.get('pastureid'),
  267. barid: '',
  268. times: '',
  269. startTime: '',
  270. stopTime: '',
  271. inputDatetime: ''
  272. }
  273. },
  274. list: []
  275. },
  276. isokDisable: false,
  277. selectList: [],
  278. rowStyle: { maxHeight: 50 + 'px', height: 45 + 'px' },
  279. cellStyle: { padding: 0 + 'px' }
  280. }
  281. },
  282. computed: {
  283. // 设置请求头
  284. headers() {
  285. return {
  286. token: getToken()
  287. }
  288. },
  289. uploadData() {
  290. return {
  291. name: '颛孙洋洋-配方干物质',
  292. importParams: '栏舍名称, 班次, 鲜样重量(g), 烘干重量(g), 操作人, 操作日期',
  293. sheetname: 'SheetJS'
  294. }
  295. },
  296. // 设置上传地址
  297. uploadExcelUrl() {
  298. return process.env.VUE_APP_BASE_API + 'authdata/ImportExcel'
  299. }
  300. },
  301. created() {
  302. this.getList()
  303. this.getDownList()
  304. this.getButtons()
  305. },
  306. methods: {
  307. getButtons() {
  308. const Edit = 'FormulaDryMatter'
  309. const isRoleEdit = checkButtons(JSON.parse(sessionStorage.getItem('buttons')), Edit)
  310. this.isRoleEdit = isRoleEdit
  311. },
  312. getDownList() {
  313. GetDataByNames(this.requestParams).then(response => {
  314. this.houseNameList = response.data.getBarListEnable.list
  315. if (response.data.getSysoptEnable.list !== null) {
  316. for (let i = 1; i <= response.data.getSysoptEnable.list[0].inforvalue; i++) {
  317. const obj = {}
  318. obj.id = String(i)
  319. if (i == 1) { obj.name = '第一班' } else if (i == 2) { obj.name = '第二班' } else if (i == 3) { obj.name = '第三班' } else if (i == 4) { obj.name = '第四班' }
  320. this.frequencyList.push(obj)
  321. }
  322. } else {
  323. this.frequencyList = []
  324. }
  325. })
  326. },
  327. handleBefore() {
  328. if (this.table.getdataListParm.parammaps.inputDatetime !== '' && this.table.getdataListParm.parammaps.inputDatetime !== null) {
  329. var start = new Date(this.table.getdataListParm.parammaps.inputDatetime[0].setDate(this.table.getdataListParm.parammaps.inputDatetime[0].getDate() - 1))
  330. var stop = new Date(this.table.getdataListParm.parammaps.inputDatetime[1].setDate(this.table.getdataListParm.parammaps.inputDatetime[1].getDate() - 1))
  331. this.table.getdataListParm.parammaps.inputDatetime.length = 0
  332. this.table.getdataListParm.parammaps.inputDatetime.push(start, stop)
  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.$forceUpdate()
  343. }
  344. },
  345. getList() {
  346. this.table.listLoading = true
  347. GetDataByName(this.table.getdataListParm).then(response => {
  348. console.log('table数据', response.data.list)
  349. if (response.data.list !== null) {
  350. this.table.list = response.data.list
  351. this.table.pageNum = response.data.pageNum
  352. this.table.pageSize = response.data.pageSize
  353. this.table.total = response.data.total
  354. } else {
  355. this.table.list = []
  356. }
  357. setTimeout(() => {
  358. this.table.listLoading = false
  359. }, 100)
  360. })
  361. },
  362. handleSearch() {
  363. console.log('点击了查询')
  364. if (this.table.getdataListParm.parammaps.inputDatetime !== '' && this.table.getdataListParm.parammaps.inputDatetime !== null) {
  365. this.table.getdataListParm.parammaps.startTime = parseTime(this.table.getdataListParm.parammaps.inputDatetime[0], '{y}-{m}-{d}')
  366. this.table.getdataListParm.parammaps.stopTime = parseTime(this.table.getdataListParm.parammaps.inputDatetime[1], '{y}-{m}-{d}')
  367. } else {
  368. this.table.getdataListParm.parammaps.inputDatetime = ''
  369. this.table.getdataListParm.parammaps.startTime = ''
  370. this.table.getdataListParm.parammaps.stopTime = ''
  371. }
  372. this.table.getdataListParm.offset = 1
  373. this.getList()
  374. },
  375. handleRefresh() {
  376. console.log('点击了重置')
  377. this.table.getdataListParm.parammaps.barid = ''
  378. this.table.getdataListParm.parammaps.times = ''
  379. this.table.getdataListParm.parammaps.startTime = ''
  380. this.table.getdataListParm.parammaps.stopTime = ''
  381. this.table.getdataListParm.parammaps.inputDatetime = ''
  382. this.table.getdataListParm.offset = 1
  383. this.getList()
  384. },
  385. // 新增
  386. resetTemp() {
  387. this.create.temp = { pastureid: Cookies.get('pastureid'), operatetime: parseTime(new Date(), '{y}-{m}-{d}'), emp: Cookies.get('employename'), barid: '', barname: '', freshweight: '', dryweight: '', thoweight: '', actweight: '', times: '' }
  388. },
  389. blurEmp(item) {
  390. this.create.temp.emp = item.target.value
  391. },
  392. // 栏舍名称
  393. changeBar(item) {
  394. this.create.temp.barname = this.houseNameList.find(obj => obj.id === item).bname
  395. this.getThoweight()
  396. },
  397. changeOperatetime() {
  398. this.getThoweight()
  399. },
  400. // 理论干物质
  401. getThoweight() {
  402. this.create.getdataListParm2.parammaps.date = this.create.temp.operatetime
  403. this.create.getdataListParm2.parammaps.barid = this.create.temp.barid
  404. GetDataByName(this.create.getdataListParm2).then(response => {
  405. if (response.data.list !== null) {
  406. this.create.temp.thoweight = response.data.list[0].thoweight
  407. } else {
  408. this.create.temp.thoweight = 0
  409. }
  410. })
  411. },
  412. // 操作人
  413. getNoteTakerList() {
  414. GetDataByName(this.create.getdataListParm).then(response => {
  415. if (response.data.list !== null) {
  416. for (let i = 0; i < response.data.list.length; i++) {
  417. response.data.list[i].myId = i
  418. }
  419. this.create.noteTakerList = response.data.list
  420. console.log('记录人数据', response.data.list)
  421. console.log(this.create.noteTakerList)
  422. } else {
  423. this.create.noteTakerList = []
  424. }
  425. })
  426. },
  427. blurFreshweight() {
  428. if (this.create.temp.dryweight !== '' && this.create.temp.freshweight !== '') {
  429. this.create.temp.actweight = parseFloat(this.create.temp.dryweight) / parseFloat(this.create.temp.freshweight)
  430. this.create.temp.actweight = this.create.temp.actweight.toFixed(2)
  431. }
  432. },
  433. blurDryweight() {
  434. if (this.create.temp.freshweight !== '' && this.create.temp.dryweight !== '') {
  435. this.create.temp.actweight = parseFloat(this.create.temp.dryweight) / parseFloat(this.create.temp.freshweight)
  436. this.create.temp.actweight = this.create.temp.actweight.toFixed(2)
  437. }
  438. },
  439. handleCreate() {
  440. console.log('点击了新增')
  441. this.resetTemp()
  442. this.getNoteTakerList()
  443. this.create.dialogStatus = 'create'
  444. this.create.dialogFormVisible = true
  445. },
  446. createData() {
  447. console.log('点击了新增保存')
  448. this.isokDisable = true
  449. setTimeout(() => {
  450. this.isokDisable = false
  451. }, 1000)
  452. this.$refs['temp'].validate(valid => {
  453. if (valid) {
  454. this.isokDisable = true
  455. setTimeout(() => {
  456. this.isokDisable = false
  457. }, 1000)
  458. const weight = /^\d+(\.\d{1,2})?$/
  459. // 鲜样重量/烘干重量
  460. if (!weight.test(parseFloat(this.create.temp.freshweight)) || !weight.test(parseFloat(this.create.temp.dryweight))) {
  461. this.$message({ type: 'error', message: '重量不可小于0,最多保留俩位小数', duration: 2000 })
  462. return false
  463. }
  464. if (this.create.temp.freshweight !== '' && this.create.temp.dryweight) {
  465. if (parseFloat(this.create.temp.dryweight) > parseFloat(this.create.temp.freshweight)) {
  466. this.$message({ type: 'error', message: '烘干重量不可大于鲜样重量', duration: 2000 })
  467. return false
  468. }
  469. }
  470. this.requestParam.name = 'insertFtdry'
  471. this.requestParam.parammaps = this.create.temp
  472. if (this.create.temp.emp == '') { this.create.temp.emp = Cookies.get('employename') }
  473. PostDataByName(this.requestParam).then(response => {
  474. console.log('新增保存发送参数', this.requestParam)
  475. if (response.msg !== 'fail') {
  476. this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
  477. this.create.dialogFormVisible = false
  478. this.getList()
  479. } else {
  480. const barid = new RegExp("key 'barid'")
  481. if (barid.test(response.data)) {
  482. this.$message({ type: 'error', message: '该栏舍该班次今日配方干物质已存在,不可重复生成', duration: 2000 })
  483. } else {
  484. this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
  485. }
  486. }
  487. })
  488. }
  489. })
  490. },
  491. createDataAgain() {
  492. console.log('点击了新增保存')
  493. this.isokDisable = true
  494. setTimeout(() => {
  495. this.isokDisable = false
  496. }, 1000)
  497. this.$refs['temp'].validate(valid => {
  498. if (valid) {
  499. this.isokDisable = true
  500. setTimeout(() => {
  501. this.isokDisable = false
  502. }, 1000)
  503. const weight = /^\d+(\.\d{1,2})?$/
  504. // 鲜样重量/烘干重量
  505. if (!weight.test(parseFloat(this.create.temp.freshweight)) || !weight.test(parseFloat(this.create.temp.dryweight))) {
  506. this.$message({ type: 'error', message: '重量不可小于0,最多保留俩位小数', duration: 2000 })
  507. return false
  508. }
  509. if (this.create.temp.freshweight !== '' && this.create.temp.dryweight) {
  510. if (parseFloat(this.create.temp.dryweight) > parseFloat(this.create.temp.freshweight)) {
  511. this.$message({ type: 'error', message: '烘干重量不可大于鲜样重量', duration: 2000 })
  512. return false
  513. }
  514. }
  515. this.requestParam.name = 'insertFtdry'
  516. this.requestParam.parammaps = this.create.temp
  517. if (this.create.temp.emp == '') { this.create.temp.emp = Cookies.get('employename') }
  518. PostDataByName(this.requestParam).then(response => {
  519. console.log('新增保存发送参数', this.requestParam)
  520. if (response.msg !== 'fail') {
  521. this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
  522. this.resetTemp()
  523. this.getList()
  524. this.getNoteTakerList()
  525. } else {
  526. const barid = new RegExp("key 'barid'")
  527. if (barid.test(response.data)) {
  528. this.$message({ type: 'error', message: '该栏舍该班次今日配方干物质已存在,不可重复生成', duration: 2000 })
  529. } else {
  530. this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
  531. }
  532. }
  533. })
  534. }
  535. })
  536. },
  537. // 编辑
  538. handleUpdate(row) {
  539. console.log('点击了编辑', row)
  540. row.barid = String(row.barid)
  541. this.create.temp = Object.assign({}, row)
  542. this.create.temp.id = row.id
  543. this.getNoteTakerList()
  544. this.create.dialogStatus = 'update'
  545. this.create.dialogFormVisible = true
  546. },
  547. updateData() {
  548. this.isokDisable = true
  549. setTimeout(() => {
  550. this.isokDisable = false
  551. }, 1000)
  552. this.$refs['temp'].validate(valid => {
  553. if (valid) {
  554. this.isokDisable = true
  555. setTimeout(() => {
  556. this.isokDisable = false
  557. }, 1000)
  558. const weight = /^\d+(\.\d{1,2})?$/
  559. // 鲜样重量/烘干重量
  560. if (!weight.test(parseFloat(this.create.temp.freshweight)) || !weight.test(parseFloat(this.create.temp.dryweight))) {
  561. this.$message({ type: 'error', message: '重量不可小于0,最多保留俩位小数', duration: 2000 })
  562. return false
  563. }
  564. if (this.create.temp.freshweight !== '' && this.create.temp.dryweight) {
  565. if (parseFloat(this.create.temp.dryweight) > parseFloat(this.create.temp.freshweight)) {
  566. this.$message({ type: 'error', message: '烘干重量不可大于鲜样重量', duration: 2000 })
  567. return false
  568. }
  569. }
  570. this.requestParam.name = 'updateFtdry'
  571. this.requestParam.parammaps = this.create.temp
  572. if (this.create.temp.emp == '') { this.create.temp.emp = Cookies.get('employename') }
  573. PostDataByName(this.requestParam).then(response => {
  574. console.log('新增保存发送参数', this.requestParam)
  575. if (response.msg !== 'fail') {
  576. this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
  577. this.create.dialogFormVisible = false
  578. this.getList()
  579. } else {
  580. this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
  581. }
  582. })
  583. }
  584. })
  585. },
  586. // 删除
  587. handleRowDelete(row) {
  588. console.log('点击了行内删除')
  589. MessageBox.confirm('是否确认删除此信息?', {
  590. confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
  591. }).then(() => {
  592. this.selectList = []
  593. this.requestParam.name = 'deleteFtdry'
  594. this.requestParam.parammaps = {}
  595. this.requestParam.parammaps.pastureid = row.pastureid
  596. this.requestParam.parammaps.id = row.id
  597. PostDataByName(this.requestParam).then(response => {
  598. if (response.msg === 'fail') {
  599. this.$notify({ title: '删除失败', message: response.data, type: 'warning', duration: 2000 })
  600. } else {
  601. this.$notify({ title: '成功', message: '删除成功', type: 'success', duration: 2000 })
  602. this.getList()
  603. }
  604. })
  605. }).catch(() => {
  606. this.$message({ type: 'info', message: '已取消删除' })
  607. })
  608. },
  609. handleSelectionChange(val) {
  610. console.log('勾选数据', val)
  611. this.selectList = val
  612. },
  613. handleDelete() {
  614. console.log('点击了删除')
  615. if (this.selectList.length == 0) {
  616. this.$message({ type: 'error', message: '请选择配方干物质', duration: 2000 })
  617. } else {
  618. MessageBox.confirm('当前选中' + this.selectList.length + '条信息,是否删除?', {
  619. confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
  620. }).then(() => {
  621. console.log(this.selectList)
  622. this.requestParam.common = { 'returnmap': '0' }
  623. this.requestParam.data = []
  624. this.requestParam.data[0] = { 'name': 'insertSpotList', 'resultmaps': { 'list': this.selectList }}
  625. this.requestParam.data[0].children = []
  626. this.requestParam.data[0].children[0] = { 'name': 'deleteFtdry', 'type': 'e', 'parammaps': {
  627. id: '@insertSpotList.id',
  628. pastureid: '@insertSpotList.pastureid'
  629. }}
  630. ExecDataByConfig(this.requestParam).then(response => {
  631. console.log('删除保存发送参数', this.requestParam)
  632. if (response.msg === 'fail') {
  633. this.$notify({ title: '删除失败', message: response.data, type: 'warning', duration: 2000 })
  634. } else {
  635. this.$notify({ title: '', message: '删除成功', type: 'success', duration: 2000 })
  636. this.getList()
  637. }
  638. })
  639. })
  640. }
  641. },
  642. // 复制
  643. handleCopy() {
  644. console.log('点击了复制')
  645. if (this.selectList.length == 0) {
  646. this.$message({ type: 'error', message: '请选择配方干物质', duration: 2000 })
  647. } else if (this.selectList.length == 1) {
  648. MessageBox.confirm('是否确认复制此信息?', {
  649. confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
  650. }).then(() => {
  651. this.requestParam.name = 'copyFtdry'
  652. this.requestParam.parammaps = {}
  653. this.requestParam.parammaps.pastureid = this.selectList[0].pastureid
  654. this.requestParam.parammaps.id = this.selectList[0].id
  655. PostDataByName(this.requestParam).then(response => {
  656. if (response.msg === 'fail') {
  657. const barid = new RegExp("key 'barid'")
  658. if (barid.test(response.data)) {
  659. this.$message({ type: 'error', message: '该栏舍该班次今日配方干物质已存在,不可重复生成', duration: 2000 })
  660. } else {
  661. this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
  662. }
  663. } else {
  664. this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
  665. this.getList()
  666. }
  667. })
  668. }).catch(() => {
  669. this.$message({ type: 'info', message: '已取消删除' })
  670. })
  671. } else {
  672. this.$message({ type: 'error', message: '请选择一条配方干物质', duration: 2000 })
  673. }
  674. },
  675. // 导出
  676. handleExport(item) {
  677. if (item == 1) {
  678. console.log('点击了导出模板')
  679. const requestParam = this.requestParam
  680. const url = process.env.VUE_APP_BASE_API + 'file/导入导出模板/栏舍生产/配方干物质导入模板.xlsx' // 请求下载文件的地址
  681. console.log(url)
  682. axios({
  683. method: 'GET',
  684. url: url,
  685. data: requestParam,
  686. headers: { token: getToken(), optname: 'insertcustomdoc' },
  687. responseType: 'blob'
  688. }).then(res => {
  689. if (!res) return
  690. this.percentage = 99
  691. setTimeout(() => {
  692. this.isPercentage = false
  693. }, 2000)
  694. const blob = new Blob([res.data], {
  695. type: 'application/octet-stream;charset=utf-8'
  696. })
  697. const url = window.URL.createObjectURL(blob)
  698. const aLink = document.createElement('a')
  699. aLink.style.display = 'none'
  700. aLink.href = url
  701. const docname = '配方干物质导入模板.xlsx'
  702. aLink.setAttribute('download', docname) // 下载的文件
  703. document.body.appendChild(aLink)
  704. aLink.click()
  705. document.body.removeChild(aLink)
  706. window.URL.revokeObjectURL(url)
  707. })
  708. } else {
  709. console.log('点击了导出数据')
  710. this.download.getdataListParm.parammaps = this.table.getdataListParm.parammaps
  711. if (this.download.getdataListParm.parammaps.inputDatetime !== '' && this.download.getdataListParm.parammaps.inputDatetime !== null) {
  712. this.download.getdataListParm.parammaps.startTime = parseTime(this.download.getdataListParm.parammaps.inputDatetime[0], '{y}-{m}-{d}')
  713. this.download.getdataListParm.parammaps.stopTime = parseTime(this.download.getdataListParm.parammaps.inputDatetime[1], '{y}-{m}-{d}')
  714. } else {
  715. this.download.getdataListParm.parammaps.inputDatetime = ''
  716. this.download.getdataListParm.parammaps.startTime = ''
  717. this.download.getdataListParm.parammaps.stopTime = ''
  718. }
  719. GetDataByName(this.download.getdataListParm).then(response => {
  720. if (response.data.list !== null) {
  721. this.download.list = response.data.list
  722. } else {
  723. this.download.list = []
  724. }
  725. var excelDatas = [
  726. {
  727. tHeader: ['栏舍名称', '班次', '鲜样重量(g)', '烘干重量(g)', '理论干物质', '实际干物质', '操作人', '操作日期'],
  728. filterVal: ['barname', 'timesstr', 'freshweight', 'dryweight', 'thoweight', 'actweight', 'emp', 'operatetime'],
  729. tableDatas: this.download.list,
  730. sheetName: 'Sheet1'
  731. }
  732. ]
  733. json2excel(excelDatas, '配方干物质', true, 'xlsx')
  734. })
  735. }
  736. },
  737. beforeImport(file) {
  738. const isLt2M = file.size / 1024 / 1024 < 2
  739. if (!isLt2M) {
  740. this.$message.error('上传文件大小不能超过 2MB!')
  741. }
  742. return isLt2M
  743. },
  744. handleImportSuccess(res, file) {
  745. this.getList()
  746. if (res.msg === 'ok') {
  747. this.$message({ title: '成功', message: '导入成功:' + res.data.success + '条!', type: 'success', duration: 2000 })
  748. if (res.data.err_count > 0) {
  749. this.$notify({ title: '失败', message: '导入失败:' + res.data.err_count + '条!', type: 'danger', duration: 2000 })
  750. import('@/vendor/Export2Excel').then(excel => {
  751. const list1 = res.data.result
  752. const tHeader = ['栏舍名称', '班次', '鲜样重量(g)', '烘干重量(g)', '操作人', '操作日期', '错误信息']
  753. const filterVal = ['栏舍名称', '班次', '鲜样重量(g)', '烘干重量(g)', '操作人', '操作日期', 'error_msg']
  754. const data1 = this.formatJson(filterVal, list1)
  755. excel.export_json_to_excel({ header: tHeader, data: data1, filename: '配方干物质导入报错信息', autoWidth: true, bookType: 'xlsx' })
  756. })
  757. }
  758. } else {
  759. this.$notify({ title: '失败', message: '上传失败', type: 'danger', duration: 2000 })
  760. }
  761. },
  762. formatJson(filterVal, jsonData) {
  763. return jsonData.map(v =>
  764. filterVal.map(j => {
  765. if (j === 'timestamp') {
  766. return parseTime(v[j])
  767. } else {
  768. return v[j]
  769. }
  770. })
  771. )
  772. }
  773. }
  774. }
  775. </script>
  776. <style lang="scss" scoped>
  777. .search{padding-top:10px;clear: both;}
  778. .table{margin-top:10px;}
  779. </style>