index.vue 39 KB

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