cd0041b4b5b330a13e578d1b6fff2f3f7355d7f6.svn-base 36 KB

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