7c364c9c42385a04e2df9253a762a19a7d1afce9.svn-base 32 KB

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