4eb7643309910e2c8998443cbee994c49ab11071.svn-base 35 KB

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