index.vue 40 KB

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