12bbf31aa552e48c08f10ef4ade1c4b423a42f8f.svn-base 36 KB

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