0b64e3e0f8ce59bfd456f28b6e6999978115fe7b.svn-base 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  1. <template>
  2. <div class="app-container">
  3. <div class="operation">
  4. <el-button class="success" @click="handleCreate">新增合同</el-button>
  5. <el-upload style="float: right;" :headers="headers" :data="uploadData" :action="uploadExcelUrl" :show-file-list="false" :before-upload="beforeImport" :on-success="handleImportSuccess">
  6. <el-button class="import" style="float: right;">导入</el-button>
  7. </el-upload>
  8. <el-dropdown style="float: right;margin-right: 10px;">
  9. <el-button class="export">导出</el-button>
  10. <el-dropdown-menu slot="dropdown">
  11. <el-dropdown-item @click.native="handleExport(1)">导出模板</el-dropdown-item>
  12. <el-dropdown-item @click.native="handleExport(2)">导出数据</el-dropdown-item>
  13. </el-dropdown-menu>
  14. </el-dropdown>
  15. </div>
  16. <div class="search">
  17. <el-date-picker v-model="table.getdataListParm.parammaps.inputDatetime" class="inputDatetime filter-item" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" style="width: 250px;" />
  18. <el-button class="el-icon-arrow-left elIconArrowLeft" @click="handleBefore" />
  19. <el-button class="el-icon-arrow-right elIconArrowRight" @click="handleNext" />
  20. <el-select v-model="table.getdataListParm.parammaps.providerid" filterable placeholder="请选择供应商" class="filter-item" style="width: 150px;" clearable>
  21. <el-option v-for="item in supplierList" :key="item.id" :label="item.providerName" :value="item.id" />
  22. </el-select>
  23. <el-button class="successBorder" @click="handleSearch">查询</el-button>
  24. <el-button class="successBorder" @click="handleRefresh">重置</el-button>
  25. </div>
  26. <div class="table">
  27. <el-table
  28. :key="table.tableKey"
  29. v-loading="table.listLoading"
  30. element-loading-text="给我一点时间"
  31. :data="table.list"
  32. border
  33. fit
  34. highlight-current-row
  35. style="width: 100%;"
  36. :row-style="rowStyle"
  37. :cell-style="cellStyle"
  38. class="elTable table-fixed"
  39. >
  40. <el-table-column label="序号" align="center" type="index" width="50px">
  41. <template slot-scope="scope">
  42. <span>{{ scope.$index + (table.pageNum-1) * table.pageSize + 1 }}</span>
  43. </template>
  44. </el-table-column>
  45. <el-table-column label="合同编号" min-width="130px" align="center">
  46. <template slot-scope="scope">
  47. <span>{{ scope.row.contractcode }}</span>
  48. </template>
  49. </el-table-column>
  50. <el-table-column label="供应商" min-width="130px" align="center">
  51. <template slot-scope="scope">
  52. <span>{{ scope.row.providername }}</span>
  53. </template>
  54. </el-table-column>
  55. <el-table-column label="录入日期" min-width="110px" align="center">
  56. <template slot-scope="scope">
  57. <span>{{ scope.row.operatetime }}</span>
  58. </template>
  59. </el-table-column>
  60. <el-table-column label="启用" min-width="110px" align="center">
  61. <template slot-scope="scope">
  62. <el-switch v-model="scope.row.enable" disabled active-color="#13ce66" inactive-color="#ff4949" :active-value="1" :inactive-value="0" />
  63. </template>
  64. </el-table-column>
  65. <el-table-column label="操作" align="center" width="320" class-name="small-padding fixed-width" fixed="right">
  66. <template slot-scope="{row}">
  67. <el-button class="miniPrimary" @click="handleSee(row)">查看</el-button>
  68. <el-button class="miniSuccess" @click="handleUpdate(row)">编辑</el-button>
  69. <el-button class="miniDanger" @click="handleRowDelete(row)">删除</el-button>
  70. </template>
  71. </el-table-column>
  72. </el-table>
  73. <pagination v-show="table.total>=0" :total="table.total" :page.sync="table.getdataListParm.offset" :limit.sync="table.getdataListParm.pagecount" @pagination="getList" />
  74. </div>
  75. <!-- 新增 -->
  76. <el-dialog :title="textMap[create.dialogStatus]" :visible.sync="create.dialogFormVisible" :close-on-click-modal="false" width="90%">
  77. <div class="app-add">
  78. <el-form ref="createTemp" :rules="create.rules" :model="create.createTemp" label-position="right" label-width="160px" style="width: 90%;margin:0 auto">
  79. <el-row>
  80. <el-col :span="8">
  81. <el-form-item label="合同编号:" prop="contractcode">
  82. <el-input ref="contractcode" v-model="create.createTemp.contractcode" class="filter-item" placeholder="合同编号" type="text" :disabled="create.dialogStatus !== 'create'" />
  83. </el-form-item>
  84. </el-col>
  85. <el-col :span="8">
  86. <el-form-item label="供应商:" prop="providerid">
  87. <el-select v-model="create.createTemp.providerid" filterable placeholder="请选择供应商" class="filter-item" style="width: 100%;" :disabled="create.dialogStatus !== 'create'" @change="changeSupplier">
  88. <el-option v-for="item in supplierList" :key="item.id" :label="item.providerName" :value="item.id" />
  89. </el-select>
  90. </el-form-item>
  91. </el-col>
  92. <el-col :span="8">
  93. <el-form-item label="录入日期:" prop="operatetime">
  94. <el-date-picker v-model="create.createTemp.operatetime" class="filter-item" type="date" placeholder="录入日期" :disabled="create.dialogStatus==='see'" :clearable="false" />
  95. </el-form-item>
  96. </el-col>
  97. </el-row>
  98. <el-row>
  99. <el-col :span="8">
  100. <el-form-item label="添加饲料:" prop="feedid">
  101. <el-select v-model="create.createTemp.feedid" filterable placeholder="请选择饲料" class="filter-item" style="width: 100%;" :disabled="create.dialogStatus==='see'" @change="changeFeedNameAdd">
  102. <el-option v-for="item in feedNameAddList" :key="item.id" :label="item.fname" :value="item.id" />
  103. </el-select>
  104. </el-form-item>
  105. </el-col>
  106. <el-col :span="8">
  107. <el-form-item label="是否启用:" prop="enable">
  108. <el-switch v-model="create.createTemp.enable" :disabled="create.dialogStatus==='see'" active-color="#13ce66" inactive-color="#ff4949" :active-value="1" :inactive-value="0" />
  109. </el-form-item>
  110. </el-col>
  111. </el-row>
  112. </el-form>
  113. <el-table
  114. :key="create.tableKey"
  115. v-loading="create.listLoading"
  116. element-loading-text="给我一点时间"
  117. :data="create.list"
  118. border
  119. fit
  120. highlight-current-row
  121. style="width: 100%;margin-bottom: 50px;"
  122. :row-style="rowStyle"
  123. :cell-style="cellStyle"
  124. class="elTable table-fixed"
  125. >
  126. <el-table-column label="饲料名称" min-width="130px" align="center">
  127. <template slot-scope="scope">
  128. <span>{{ scope.row.feedname }}</span>
  129. </template>
  130. </el-table-column>
  131. <el-table-column label="饲料价格" min-width="130px" align="center">
  132. <template slot-scope="scope">
  133. <el-input v-if="create.dialogStatus !=='see'" ref="input" v-model="scope.row.price" type="number" :step="0.01" placeholder="最多两位小数" style="width:80%;padding:10px 0;" />
  134. <span v-else> {{ scope.row.price }}</span>
  135. </template>
  136. </el-table-column>
  137. <el-table-column v-if="create.dialogStatus !=='see'" label="操作" align="center" width="120" class-name="small-padding fixed-width" fixed="right">
  138. <template slot-scope="{row}">
  139. <a class="smallDanger" @click="handleFeedDelete(row)">删除</a>
  140. </template>
  141. </el-table-column>
  142. </el-table>
  143. <div slot="footer" class="dialog-footer">
  144. <el-button class="cancelClose" @click="create.dialogFormVisible = false; ">关闭</el-button>
  145. <el-button v-if="create.dialogStatus !== 'see'" class="success" :disabled="isokDisable" @click="create.dialogStatus==='create'?createData():updateData()">确认</el-button>
  146. </div>
  147. </div>
  148. </el-dialog>
  149. </div>
  150. </template>
  151. <script>
  152. import { GetDataByName, GetDataByNames, checkButtons, ExecDataByConfig, failproccess } from '@/api/common'
  153. import Pagination from '@/components/Pagination'
  154. import { parseTime, json2excel } from '@/utils/index.js'
  155. import { MessageBox } from 'element-ui'
  156. import Cookies from 'js-cookie'
  157. import { getToken } from '@/utils/auth'
  158. export default {
  159. name: 'FeedContract',
  160. components: { Pagination },
  161. data() {
  162. return {
  163. isRoleEdit: [],
  164. requestParams: [
  165. { name: 'getProviderListEnable', offset: 0, pagecount: 0, parammaps: { pastureid: Cookies.get('pastureid') }},
  166. { name: 'getFeedListEnable', offset: 0, pagecount: 0, parammaps: { pastureid: Cookies.get('pastureid') }}
  167. ],
  168. supplierList: [], // 供应商
  169. feedNameAddList: [], // 饲料名称
  170. table: {
  171. getdataListParm: {
  172. name: 'getBigContractList',
  173. page: 1,
  174. offset: 1,
  175. pagecount: 10,
  176. returntype: 'Map',
  177. parammaps: {
  178. pastureid: Cookies.get('pastureid'),
  179. inputDatetime: '',
  180. startTime: '',
  181. stopTime: ''
  182. }
  183. },
  184. tableKey: 0,
  185. list: [],
  186. total: 0,
  187. listLoading: true
  188. },
  189. textMap: {
  190. create: '新增合同',
  191. update: '编辑合同',
  192. see: '查看合同'
  193. },
  194. create: {
  195. dialogFormVisible: false,
  196. dialogStatus: '',
  197. createTemp: {
  198. pastureid: Cookies.get('pastureid'), 'providerid': '', 'providername': '', 'emp': Cookies.get('employename'), 'enable': 1, 'operatetime': parseTime(new Date(), '{y}-{m}-{d}')
  199. },
  200. rules: {
  201. contractcode: [{ type: 'string', required: true, message: '必填', trigger: 'blur' }],
  202. providerid: [{ type: 'string', required: true, message: '必填', trigger: 'blur' }]
  203. },
  204. getdataListParm: {
  205. name: 'getContractList',
  206. page: 1,
  207. offset: 1,
  208. pagecount: 10,
  209. returntype: 'Map',
  210. parammaps: {}
  211. },
  212. listLoading: false,
  213. tableKey: 0,
  214. list: []
  215. },
  216. requestParam: {},
  217. download: {
  218. getdataListParm: {
  219. name: 'getBigContractList',
  220. page: 1,
  221. offset: 1,
  222. pagecount: 0,
  223. returntype: 'Map',
  224. parammaps: {
  225. pastureid: Cookies.get('pastureid'),
  226. inputDatetime: '',
  227. startTime: '',
  228. stopTime: ''
  229. }
  230. },
  231. list: []
  232. },
  233. isokDisable: false,
  234. rowStyle: { maxHeight: 50 + 'px', height: 45 + 'px' },
  235. cellStyle: { padding: 0 + 'px' }
  236. }
  237. },
  238. computed: {
  239. // 设置请求头
  240. headers() {
  241. return {
  242. token: getToken()
  243. }
  244. },
  245. uploadData() {
  246. return {
  247. name: '颛孙洋洋-饲料合同',
  248. importParams: '合同编号, 供应商, 饲料名称, 饲料价格(元), 录入日期',
  249. sheetname: 'SheetJS'
  250. }
  251. },
  252. // 设置上传地址
  253. uploadExcelUrl() {
  254. return process.env.VUE_APP_BASE_API + 'authdata/ImportExcel'
  255. }
  256. },
  257. created() {
  258. this.getButtons()
  259. this.getDownList()
  260. this.getList()
  261. },
  262. methods: {
  263. getButtons() {
  264. const Edit = 'FeedContract'
  265. const isRoleEdit = checkButtons(JSON.parse(sessionStorage.getItem('buttons')), Edit)
  266. this.isRoleEdit = isRoleEdit
  267. },
  268. getDownList() {
  269. GetDataByNames(this.requestParams).then(response => {
  270. this.supplierList = response.data.getProviderListEnable.list
  271. this.feedNameAddList = response.data.getFeedListEnable.list
  272. })
  273. },
  274. handleBefore() {
  275. if (this.table.getdataListParm.parammaps.inputDatetime !== '' && this.table.getdataListParm.parammaps.inputDatetime !== null) {
  276. var start = new Date(this.table.getdataListParm.parammaps.inputDatetime[0].setDate(this.table.getdataListParm.parammaps.inputDatetime[0].getDate() - 1))
  277. var stop = new Date(this.table.getdataListParm.parammaps.inputDatetime[1].setDate(this.table.getdataListParm.parammaps.inputDatetime[1].getDate() - 1))
  278. this.table.getdataListParm.parammaps.inputDatetime.length = 0
  279. this.table.getdataListParm.parammaps.inputDatetime.push(start, stop)
  280. this.table.getdataListParm.parammaps.startTime = parseTime(start, '{y}-{m}-{d}')
  281. this.table.getdataListParm.parammaps.stopTime = parseTime(stop, '{y}-{m}-{d}')
  282. this.$forceUpdate()
  283. this.getList()
  284. }
  285. },
  286. handleNext() {
  287. if (this.table.getdataListParm.parammaps.inputDatetime !== '' && this.table.getdataListParm.parammaps.inputDatetime !== null) {
  288. var start = new Date(this.table.getdataListParm.parammaps.inputDatetime[0].setDate(this.table.getdataListParm.parammaps.inputDatetime[0].getDate() + 1))
  289. var stop = new Date(this.table.getdataListParm.parammaps.inputDatetime[1].setDate(this.table.getdataListParm.parammaps.inputDatetime[1].getDate() + 1))
  290. this.table.getdataListParm.parammaps.inputDatetime.length = 0
  291. this.table.getdataListParm.parammaps.inputDatetime.push(start, stop)
  292. this.table.getdataListParm.parammaps.startTime = parseTime(start, '{y}-{m}-{d}')
  293. this.table.getdataListParm.parammaps.stopTime = parseTime(stop, '{y}-{m}-{d}')
  294. this.$forceUpdate()
  295. }
  296. },
  297. getList() {
  298. this.table.listLoading = true
  299. GetDataByName(this.table.getdataListParm).then(response => {
  300. console.log('table数据', response.data.list)
  301. if (response.data.list !== null) {
  302. this.table.list = response.data.list
  303. this.table.pageNum = response.data.pageNum
  304. this.table.pageSize = response.data.pageSize
  305. this.table.total = response.data.total
  306. } else {
  307. this.table.list = []
  308. }
  309. setTimeout(() => {
  310. this.table.listLoading = false
  311. }, 100)
  312. })
  313. },
  314. handleSearch() {
  315. if (this.table.getdataListParm.parammaps.inputDatetime !== '' && this.table.getdataListParm.parammaps.inputDatetime !== null) {
  316. this.table.getdataListParm.parammaps.startTime = parseTime(this.table.getdataListParm.parammaps.inputDatetime[0], '{y}-{m}-{d}')
  317. this.table.getdataListParm.parammaps.stopTime = parseTime(this.table.getdataListParm.parammaps.inputDatetime[1], '{y}-{m}-{d}')
  318. } else {
  319. this.table.getdataListParm.parammaps.inputDatetime = ''
  320. this.table.getdataListParm.parammaps.startTime = ''
  321. this.table.getdataListParm.parammaps.stopTime = ''
  322. }
  323. this.table.getdataListParm.offset = 1
  324. this.getList()
  325. },
  326. handleRefresh() {
  327. this.table.getdataListParm.parammaps.inputDatetime = ''
  328. this.table.getdataListParm.parammaps.startTime = ''
  329. this.table.getdataListParm.parammaps.stopTime = ''
  330. this.table.getdataListParm.parammaps.providerid = ''
  331. },
  332. resetCreateTemp() {
  333. this.create.createTemp = {
  334. pastureid: Cookies.get('pastureid'), 'providerid': '', 'providername': '', 'emp': Cookies.get('employename'), 'enable': 1, 'operatetime': parseTime(new Date(), '{y}-{m}-{d}')
  335. }
  336. this.create.list = []
  337. },
  338. handleCreate() {
  339. console.log('点击了新增')
  340. this.resetCreateTemp()
  341. this.create.dialogStatus = 'create'
  342. this.create.dialogFormVisible = true
  343. },
  344. // 供应商
  345. changeSupplier(item) {
  346. this.create.createTemp.providername = this.supplierList.find(obj => obj.id == item).providerName
  347. },
  348. // 新增饲料
  349. changeFeedNameAdd(item) {
  350. var obj = {}
  351. obj.feedid = item
  352. obj.feedname = this.feedNameAddList.find(obj => obj.id == item).fname
  353. obj.pastureid = this.feedNameAddList.find(obj => obj.id == item).pastureid
  354. obj.price = ''
  355. obj.myId = (new Date()).valueOf()
  356. for (let i = 0; i < this.create.list.length; i++) {
  357. if (this.create.list[i].feedid == item) {
  358. this.$message({ type: 'warning', message: '添加饲料不可重复', duration: 2000 })
  359. return false
  360. }
  361. }
  362. this.create.list.push(obj)
  363. },
  364. handleFeedDelete(row) {
  365. for (let i = 0; i < this.create.list.length; i++) {
  366. console.log(this.create.list[i])
  367. if (this.create.list[i].myId === row.myId) {
  368. var listAddIndex = this.create.list.indexOf(this.create.list[i])
  369. }
  370. if (listAddIndex > -1) {
  371. this.create.list.splice(listAddIndex, 1)
  372. return
  373. }
  374. }
  375. },
  376. createData() {
  377. console.log('点击了新增保存')
  378. this.$refs['createTemp'].validate(valid => {
  379. if (valid) {
  380. this.isokDisable = true
  381. setTimeout(() => {
  382. this.isokDisable = false
  383. }, 1000)
  384. console.log(this.create.list.length)
  385. if (this.create.list.length == 0) {
  386. this.$message({ type: 'warning', message: '请添加饲料', duration: 2000 })
  387. return false
  388. }
  389. const rulesPrice = /^\d+(\.\d{1,2})?$/
  390. for (let i = 0; i < this.create.list.length; i++) {
  391. if (this.create.list[i].price == '') {
  392. this.$message({ type: 'warning', message: '饲料价格不可为空', duration: 2000 })
  393. return false
  394. }
  395. if (!rulesPrice.test(parseFloat(this.create.list[i].price))) {
  396. this.$message({ type: 'warning', message: '饲料价格最多保留两位小数', duration: 2000 })
  397. return false
  398. }
  399. }
  400. this.create.createTemp.operatetime = parseTime(this.create.createTemp.operatetime, '{y}-{m}-{d}')
  401. this.requestParam.common = { 'returnmap': '0' }
  402. this.requestParam.data = []
  403. this.requestParam.data[0] = { 'name': 'insertBigContract', 'type': 'e', 'parammaps': {
  404. 'pastureid': this.create.createTemp.pastureid,
  405. 'contractcode': this.create.createTemp.contractcode,
  406. 'providerid': this.create.createTemp.providerid,
  407. 'providername': this.create.createTemp.providername,
  408. 'emp': this.create.createTemp.emp,
  409. 'enable': this.create.createTemp.enable,
  410. 'operatetime': this.create.createTemp.operatetime
  411. }}
  412. this.requestParam.data[1] = { 'name': 'insertSpotList', 'resultmaps': { 'list': this.create.list }}
  413. this.requestParam.data[1].children = []
  414. this.requestParam.data[1].children[0] = { 'name': 'insertContract', 'type': 'e', 'parammaps': {
  415. pastureid: '@insertSpotList.pastureid',
  416. bigid: '@insertBigContract.LastInsertId',
  417. feedid: '@insertSpotList.feedid',
  418. feedname: '@insertSpotList.feedname',
  419. price: '@insertSpotList.price'
  420. }}
  421. ExecDataByConfig(this.requestParam).then(response => {
  422. if (response.msg === 'fail') {
  423. failproccess(response, this.$notify)
  424. } else {
  425. this.$notify({ title: '', message: '成功', type: 'success', duration: 2000 })
  426. this.create.dialogFormVisible = false
  427. this.getList()
  428. }
  429. })
  430. }
  431. })
  432. },
  433. handleUpdate(row) {
  434. console.log('点击了编辑')
  435. this.create.dialogStatus = 'update'
  436. this.create.dialogFormVisible = true
  437. this.create.createTemp = Object.assign({}, row)
  438. this.create.getdataListParm.parammaps.pastureid = row.pastureid
  439. this.create.getdataListParm.parammaps.id = row.id
  440. this.getSeeList()
  441. },
  442. updateData() {
  443. console.log('点击了编辑保存')
  444. this.$refs['createTemp'].validate(valid => {
  445. if (valid) {
  446. this.isokDisable = true
  447. setTimeout(() => {
  448. this.isokDisable = false
  449. }, 1000)
  450. console.log(this.create.list.length)
  451. if (this.create.list.length == 0) {
  452. this.$message({ type: 'warning', message: '请添加饲料', duration: 2000 })
  453. return false
  454. }
  455. const rulesPrice = /^\d+(\.\d{1,2})?$/
  456. for (let i = 0; i < this.create.list.length; i++) {
  457. if (this.create.list[i].price == '') {
  458. this.$message({ type: 'warning', message: '饲料价格不可为空', duration: 2000 })
  459. return false
  460. }
  461. if (!rulesPrice.test(parseFloat(this.create.list[i].price))) {
  462. this.$message({ type: 'warning', message: '饲料价格最多保留两位小数', duration: 2000 })
  463. return false
  464. }
  465. }
  466. this.create.createTemp.operatetime = parseTime(this.create.createTemp.operatetime, '{y}-{m}-{d}')
  467. this.requestParam.common = { 'returnmap': '0' }
  468. this.requestParam.data = []
  469. this.requestParam.data[0] = { 'name': 'updateBigContract', 'type': 'e', 'parammaps': {
  470. 'pastureid': this.create.createTemp.pastureid,
  471. 'id': this.create.createTemp.id,
  472. 'operatetime': this.create.createTemp.operatetime,
  473. 'enable': this.create.createTemp.enable
  474. }}
  475. this.requestParam.data[1] = { 'name': 'deleteContract', 'type': 'e', 'parammaps': {
  476. 'pastureid': this.create.createTemp.pastureid,
  477. 'id': this.create.createTemp.id
  478. }}
  479. this.requestParam.data[2] = { 'name': 'insertSpotList', 'resultmaps': { 'list': this.create.list }}
  480. this.requestParam.data[2].children = []
  481. this.requestParam.data[2].children[0] = { 'name': 'insertContract', 'type': 'e', 'parammaps': {
  482. pastureid: '@insertSpotList.pastureid',
  483. bigid: this.create.createTemp.id,
  484. feedid: '@insertSpotList.feedid',
  485. feedname: '@insertSpotList.feedname',
  486. price: '@insertSpotList.price'
  487. }}
  488. ExecDataByConfig(this.requestParam).then(response => {
  489. if (response.msg === 'fail') {
  490. failproccess(response, this.$notify)
  491. } else {
  492. this.$notify({ title: '', message: '成功', type: 'success', duration: 2000 })
  493. this.create.dialogFormVisible = false
  494. this.getList()
  495. }
  496. })
  497. }
  498. })
  499. },
  500. handleSee(row) {
  501. console.log('点击了查看')
  502. this.create.dialogStatus = 'see'
  503. this.create.dialogFormVisible = true
  504. this.create.createTemp = Object.assign({}, row)
  505. this.create.getdataListParm.parammaps.pastureid = row.pastureid
  506. this.create.getdataListParm.parammaps.id = row.id
  507. this.getSeeList()
  508. },
  509. getSeeList() {
  510. this.create.listLoading = true
  511. GetDataByName(this.create.getdataListParm).then(response => {
  512. console.log('查看table数据', response.data.list)
  513. if (response.data.list !== null) {
  514. this.create.list = response.data.list
  515. } else {
  516. this.create.list = []
  517. }
  518. setTimeout(() => {
  519. this.create.listLoading = false
  520. }, 100)
  521. })
  522. },
  523. handleRowDelete(row) {
  524. MessageBox.confirm('是否确认删除此信息?', {
  525. confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
  526. }).then(() => {
  527. console.log('点击了删除')
  528. this.requestParam.common = { 'returnmap': '0' }
  529. this.requestParam.data = []
  530. this.requestParam.data[0] = { 'name': 'deleteBigContract', 'type': 'e', 'parammaps': {
  531. 'pastureid': row.pastureid,
  532. 'id': row.id
  533. }}
  534. this.requestParam.data[1] = { 'name': 'deleteContract', 'type': 'e', 'parammaps': {
  535. 'pastureid': row.pastureid,
  536. 'id': row.id
  537. }}
  538. ExecDataByConfig(this.requestParam).then(response => {
  539. if (response.msg === 'fail') {
  540. failproccess(response, this.$notify)
  541. } else {
  542. this.$notify({ title: '', message: '成功', type: 'success', duration: 2000 })
  543. this.getList()
  544. }
  545. })
  546. }).catch(() => {
  547. this.$message({ type: 'info', message: '已取消删除' })
  548. })
  549. },
  550. handleExport(item) {
  551. if (item == 1) {
  552. console.log('点击了导出模板')
  553. var excelDatas = [
  554. {
  555. tHeader: ['合同编号', '供应商', '饲料名称', '饲料价格(元)', '录入日期'],
  556. filterVal: ['合同编号', '供应商', '饲料名称', '饲料价格(元)', '录入日期'],
  557. tableDatas: this.download.list,
  558. sheetName: 'Sheet1'
  559. }
  560. ]
  561. json2excel(excelDatas, '饲料合同模板', true, 'xlsx')
  562. } else {
  563. console.log('点击了导出数据')
  564. this.download.getdataListParm.parammaps = this.table.getdataListParm.parammaps
  565. if (this.download.getdataListParm.parammaps.inputDatetime !== '' && this.download.getdataListParm.parammaps.inputDatetime !== null) {
  566. this.download.getdataListParm.parammaps.startTime = parseTime(this.download.getdataListParm.parammaps.inputDatetime[0], '{y}-{m}-{d}')
  567. this.download.getdataListParm.parammaps.stopTime = parseTime(this.download.getdataListParm.parammaps.inputDatetime[1], '{y}-{m}-{d}')
  568. } else {
  569. this.download.getdataListParm.parammaps.inputDatetime = ''
  570. this.download.getdataListParm.parammaps.startTime = ''
  571. this.download.getdataListParm.parammaps.stopTime = ''
  572. }
  573. GetDataByName(this.download.getdataListParm).then(response => {
  574. if (response.data.list !== null) {
  575. this.download.list = response.data.list
  576. } else {
  577. this.download.list = []
  578. }
  579. var excelDatas = [
  580. {
  581. tHeader: ['合同编号', '供应商', '饲料名称', '饲料价格(元)', '录入日期'],
  582. filterVal: ['contractcode', 'providername', 'feedname', 'price', 'operatetime'],
  583. tableDatas: this.download.list,
  584. sheetName: 'Sheet1'
  585. }
  586. ]
  587. json2excel(excelDatas, '饲料合同', true, 'xlsx')
  588. })
  589. }
  590. },
  591. beforeImport(file) {
  592. const isLt2M = file.size / 1024 / 1024 < 2
  593. if (!isLt2M) {
  594. this.$message.error('上传文件大小不能超过 2MB!')
  595. }
  596. return isLt2M
  597. },
  598. handleImportSuccess(res, file) {
  599. this.getList()
  600. if (res.msg === 'ok') {
  601. this.$message({ title: '成功', message: '导入成功:' + res.data.success + '条!', type: 'success', duration: 2000 })
  602. if (res.data.err_count > 0) {
  603. this.$notify({ title: '失败', message: '导入失败:' + res.data.err_count + '条!', type: 'danger', duration: 2000 })
  604. import('@/vendor/Export2Excel').then(excel => {
  605. const list1 = res.data.result
  606. const tHeader = [
  607. '合同编号', '供应商', '饲料名称', '饲料价格(元)', '录入日期', '错误信息'
  608. ]
  609. const filterVal = [
  610. '合同编号', '供应商', '饲料名称', '饲料价格(元)', '录入日期', 'error_msg'
  611. ]
  612. const data1 = this.formatJson(filterVal, list1)
  613. excel.export_json_to_excel({ header: tHeader, data: data1, filename: '入库管理导入报错信息', autoWidth: true, bookType: 'xlsx' })
  614. })
  615. }
  616. } else {
  617. this.$notify({ title: '失败', message: '上传失败', type: 'danger', duration: 2000 })
  618. }
  619. },
  620. formatJson(filterVal, jsonData) {
  621. return jsonData.map(v =>
  622. filterVal.map(j => {
  623. if (j === 'timestamp') {
  624. return parseTime(v[j])
  625. } else {
  626. return v[j]
  627. }
  628. })
  629. )
  630. }
  631. }
  632. }
  633. </script>
  634. <style lang="scss" scoped>
  635. .search{margin-top:10px;}
  636. .table{margin-top:10px;}
  637. </style>
  638. <style>
  639. .inputDatetime .el-range-separator{ padding: 0; margin: 0 10px; }
  640. </style>