d8131e52ed613c1bc907f1903f3dffd7ad1bb638.svn-base 38 KB

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