16cd60d6bbffe02bd11023c758070d698ff06904.svn-base 35 KB

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