55151456fd05b78326ba21652cf57fbb92add81d.svn-base 34 KB

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