index.vue 39 KB

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