8a0ab27efba7ea10b725335c87f2cd0b395bc0d5.svn-base 35 KB

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