42e2c8e8042ec5a8451ca54299fdf2d02beff90e.svn-base 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  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 axios from 'axios'
  158. import { getToken } from '@/utils/auth'
  159. export default {
  160. name: 'FeedContract',
  161. components: { Pagination },
  162. data() {
  163. return {
  164. isRoleEdit: [],
  165. requestParams: [
  166. { name: 'getProviderListEnable', offset: 0, pagecount: 0, parammaps: { pastureid: Cookies.get('pastureid') }},
  167. { name: 'getFeedListEnable', offset: 0, pagecount: 0, parammaps: { pastureid: Cookies.get('pastureid') }}
  168. ],
  169. supplierList: [], // 供应商
  170. feedNameAddList: [], // 饲料名称
  171. table: {
  172. getdataListParm: {
  173. name: 'getBigContractList',
  174. page: 1,
  175. offset: 1,
  176. pagecount: 10,
  177. returntype: 'Map',
  178. parammaps: {
  179. pastureid: Cookies.get('pastureid'),
  180. inputDatetime: '',
  181. startTime: '',
  182. stopTime: ''
  183. }
  184. },
  185. tableKey: 0,
  186. list: [],
  187. total: 0,
  188. listLoading: true
  189. },
  190. textMap: {
  191. create: '新增合同',
  192. update: '编辑合同',
  193. see: '查看合同'
  194. },
  195. create: {
  196. dialogFormVisible: false,
  197. dialogStatus: '',
  198. createTemp: {
  199. pastureid: Cookies.get('pastureid'), 'providerid': '', 'providername': '', 'emp': Cookies.get('employename'), 'enable': 1, 'operatetime': parseTime(new Date(), '{y}-{m}-{d}')
  200. },
  201. rules: {
  202. contractcode: [{ type: 'string', required: true, message: '必填', trigger: 'blur' }],
  203. providerid: [{ type: 'string', required: true, message: '必填', trigger: 'blur' }]
  204. },
  205. getdataListParm: {
  206. name: 'getContractList',
  207. page: 1,
  208. offset: 1,
  209. pagecount: 10,
  210. returntype: 'Map',
  211. parammaps: {}
  212. },
  213. listLoading: false,
  214. tableKey: 0,
  215. list: []
  216. },
  217. requestParam: {},
  218. download: {
  219. getdataListParm: {
  220. name: 'getBigContractList',
  221. page: 1,
  222. offset: 1,
  223. pagecount: 0,
  224. returntype: 'Map',
  225. parammaps: {
  226. pastureid: Cookies.get('pastureid'),
  227. inputDatetime: '',
  228. startTime: '',
  229. stopTime: ''
  230. }
  231. },
  232. list: []
  233. },
  234. isokDisable: false,
  235. rowStyle: { maxHeight: 50 + 'px', height: 45 + 'px' },
  236. cellStyle: { padding: 0 + 'px' }
  237. }
  238. },
  239. computed: {
  240. // 设置请求头
  241. headers() {
  242. return {
  243. token: getToken()
  244. }
  245. },
  246. uploadData() {
  247. return {
  248. name: '颛孙洋洋-饲料合同',
  249. importParams: '合同编号, 供应商, 饲料名称, 饲料价格(元), 录入日期',
  250. sheetname: 'SheetJS'
  251. }
  252. },
  253. // 设置上传地址
  254. uploadExcelUrl() {
  255. return process.env.VUE_APP_BASE_API + 'authdata/ImportExcel'
  256. }
  257. },
  258. created() {
  259. this.getButtons()
  260. this.getDownList()
  261. this.getList()
  262. },
  263. methods: {
  264. getButtons() {
  265. const Edit = 'FeedContract'
  266. const isRoleEdit = checkButtons(JSON.parse(sessionStorage.getItem('buttons')), Edit)
  267. this.isRoleEdit = isRoleEdit
  268. },
  269. getDownList() {
  270. GetDataByNames(this.requestParams).then(response => {
  271. this.supplierList = response.data.getProviderListEnable.list
  272. this.feedNameAddList = response.data.getFeedListEnable.list
  273. })
  274. },
  275. handleBefore() {
  276. if (this.table.getdataListParm.parammaps.inputDatetime !== '' && this.table.getdataListParm.parammaps.inputDatetime !== null) {
  277. var start = new Date(this.table.getdataListParm.parammaps.inputDatetime[0].setDate(this.table.getdataListParm.parammaps.inputDatetime[0].getDate() - 1))
  278. var stop = new Date(this.table.getdataListParm.parammaps.inputDatetime[1].setDate(this.table.getdataListParm.parammaps.inputDatetime[1].getDate() - 1))
  279. this.table.getdataListParm.parammaps.inputDatetime.length = 0
  280. this.table.getdataListParm.parammaps.inputDatetime.push(start, stop)
  281. this.table.getdataListParm.parammaps.startTime = parseTime(start, '{y}-{m}-{d}')
  282. this.table.getdataListParm.parammaps.stopTime = parseTime(stop, '{y}-{m}-{d}')
  283. this.$forceUpdate()
  284. this.getList()
  285. }
  286. },
  287. handleNext() {
  288. if (this.table.getdataListParm.parammaps.inputDatetime !== '' && this.table.getdataListParm.parammaps.inputDatetime !== null) {
  289. var start = new Date(this.table.getdataListParm.parammaps.inputDatetime[0].setDate(this.table.getdataListParm.parammaps.inputDatetime[0].getDate() + 1))
  290. var stop = new Date(this.table.getdataListParm.parammaps.inputDatetime[1].setDate(this.table.getdataListParm.parammaps.inputDatetime[1].getDate() + 1))
  291. this.table.getdataListParm.parammaps.inputDatetime.length = 0
  292. this.table.getdataListParm.parammaps.inputDatetime.push(start, stop)
  293. this.table.getdataListParm.parammaps.startTime = parseTime(start, '{y}-{m}-{d}')
  294. this.table.getdataListParm.parammaps.stopTime = parseTime(stop, '{y}-{m}-{d}')
  295. this.$forceUpdate()
  296. }
  297. },
  298. getList() {
  299. this.table.listLoading = true
  300. GetDataByName(this.table.getdataListParm).then(response => {
  301. console.log('table数据', response.data.list)
  302. if (response.data.list !== null) {
  303. this.table.list = response.data.list
  304. this.table.pageNum = response.data.pageNum
  305. this.table.pageSize = response.data.pageSize
  306. this.table.total = response.data.total
  307. } else {
  308. this.table.list = []
  309. }
  310. setTimeout(() => {
  311. this.table.listLoading = false
  312. }, 100)
  313. })
  314. },
  315. handleSearch() {
  316. if (this.table.getdataListParm.parammaps.inputDatetime !== '' && this.table.getdataListParm.parammaps.inputDatetime !== null) {
  317. this.table.getdataListParm.parammaps.startTime = parseTime(this.table.getdataListParm.parammaps.inputDatetime[0], '{y}-{m}-{d}')
  318. this.table.getdataListParm.parammaps.stopTime = parseTime(this.table.getdataListParm.parammaps.inputDatetime[1], '{y}-{m}-{d}')
  319. } else {
  320. this.table.getdataListParm.parammaps.inputDatetime = ''
  321. this.table.getdataListParm.parammaps.startTime = ''
  322. this.table.getdataListParm.parammaps.stopTime = ''
  323. }
  324. this.table.getdataListParm.offset = 1
  325. this.getList()
  326. },
  327. handleRefresh() {
  328. this.table.getdataListParm.parammaps.inputDatetime = ''
  329. this.table.getdataListParm.parammaps.startTime = ''
  330. this.table.getdataListParm.parammaps.stopTime = ''
  331. this.table.getdataListParm.parammaps.providerid = ''
  332. },
  333. resetCreateTemp() {
  334. this.create.createTemp = {
  335. pastureid: Cookies.get('pastureid'), 'providerid': '', 'providername': '', 'emp': Cookies.get('employename'), 'enable': 1, 'operatetime': parseTime(new Date(), '{y}-{m}-{d}')
  336. }
  337. this.create.list = []
  338. },
  339. handleCreate() {
  340. console.log('点击了新增')
  341. this.resetCreateTemp()
  342. this.create.dialogStatus = 'create'
  343. this.create.dialogFormVisible = true
  344. },
  345. // 供应商
  346. changeSupplier(item) {
  347. this.create.createTemp.providername = this.supplierList.find(obj => obj.id == item).providerName
  348. },
  349. // 新增饲料
  350. changeFeedNameAdd(item) {
  351. var obj = {}
  352. obj.feedid = item
  353. obj.feedname = this.feedNameAddList.find(obj => obj.id == item).fname
  354. obj.pastureid = this.feedNameAddList.find(obj => obj.id == item).pastureid
  355. obj.price = ''
  356. obj.myId = (new Date()).valueOf()
  357. for (let i = 0; i < this.create.list.length; i++) {
  358. if (this.create.list[i].feedid == item) {
  359. this.$message({ type: 'warning', message: '添加饲料不可重复', duration: 2000 })
  360. return false
  361. }
  362. }
  363. this.create.list.push(obj)
  364. },
  365. handleFeedDelete(row) {
  366. for (let i = 0; i < this.create.list.length; i++) {
  367. console.log(this.create.list[i])
  368. if (this.create.list[i].myId === row.myId) {
  369. var listAddIndex = this.create.list.indexOf(this.create.list[i])
  370. }
  371. if (listAddIndex > -1) {
  372. this.create.list.splice(listAddIndex, 1)
  373. return
  374. }
  375. }
  376. },
  377. createData() {
  378. console.log('点击了新增保存')
  379. this.$refs['createTemp'].validate(valid => {
  380. if (valid) {
  381. this.isokDisable = true
  382. setTimeout(() => {
  383. this.isokDisable = false
  384. }, 1000)
  385. console.log(this.create.list.length)
  386. if (this.create.list.length == 0) {
  387. this.$message({ type: 'warning', message: '请添加饲料', duration: 2000 })
  388. return false
  389. }
  390. const rulesPrice = /^\d+(\.\d{1,2})?$/
  391. for (let i = 0; i < this.create.list.length; i++) {
  392. if (this.create.list[i].price == '') {
  393. this.$message({ type: 'warning', message: '饲料价格不可为空', duration: 2000 })
  394. return false
  395. }
  396. if (!rulesPrice.test(parseFloat(this.create.list[i].price))) {
  397. this.$message({ type: 'warning', message: '饲料价格最多保留两位小数', duration: 2000 })
  398. return false
  399. }
  400. }
  401. this.create.createTemp.operatetime = parseTime(this.create.createTemp.operatetime, '{y}-{m}-{d}')
  402. this.requestParam.common = { 'returnmap': '0' }
  403. this.requestParam.data = []
  404. this.requestParam.data[0] = { 'name': 'insertBigContract', 'type': 'e', 'parammaps': {
  405. 'pastureid': this.create.createTemp.pastureid,
  406. 'contractcode': this.create.createTemp.contractcode,
  407. 'providerid': this.create.createTemp.providerid,
  408. 'providername': this.create.createTemp.providername,
  409. 'emp': this.create.createTemp.emp,
  410. 'enable': this.create.createTemp.enable,
  411. 'operatetime': this.create.createTemp.operatetime
  412. }}
  413. this.requestParam.data[1] = { 'name': 'insertSpotList', 'resultmaps': { 'list': this.create.list }}
  414. this.requestParam.data[1].children = []
  415. this.requestParam.data[1].children[0] = { 'name': 'insertContract', 'type': 'e', 'parammaps': {
  416. pastureid: '@insertSpotList.pastureid',
  417. bigid: '@insertBigContract.LastInsertId',
  418. feedid: '@insertSpotList.feedid',
  419. feedname: '@insertSpotList.feedname',
  420. price: '@insertSpotList.price'
  421. }}
  422. ExecDataByConfig(this.requestParam).then(response => {
  423. if (response.msg == 'fail') {
  424. const contractcode = new RegExp("key 'contractcode'")
  425. if (contractcode.test(response.data)) {
  426. this.$message({ type: 'error', message: '该合同已存在,不可重复生成', duration: 2000 })
  427. } else {
  428. this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
  429. }
  430. } else {
  431. this.$notify({ title: '', message: '成功', type: 'success', duration: 2000 })
  432. this.create.dialogFormVisible = false
  433. this.getList()
  434. }
  435. })
  436. }
  437. })
  438. },
  439. handleUpdate(row) {
  440. console.log('点击了编辑')
  441. this.create.dialogStatus = 'update'
  442. this.create.dialogFormVisible = true
  443. this.create.createTemp = Object.assign({}, row)
  444. this.create.getdataListParm.parammaps.pastureid = row.pastureid
  445. this.create.getdataListParm.parammaps.id = row.id
  446. this.getSeeList()
  447. },
  448. updateData() {
  449. console.log('点击了编辑保存')
  450. this.$refs['createTemp'].validate(valid => {
  451. if (valid) {
  452. this.isokDisable = true
  453. setTimeout(() => {
  454. this.isokDisable = false
  455. }, 1000)
  456. console.log(this.create.list.length)
  457. if (this.create.list.length == 0) {
  458. this.$message({ type: 'warning', message: '请添加饲料', duration: 2000 })
  459. return false
  460. }
  461. const rulesPrice = /^\d+(\.\d{1,2})?$/
  462. for (let i = 0; i < this.create.list.length; i++) {
  463. if (this.create.list[i].price == '') {
  464. this.$message({ type: 'warning', message: '饲料价格不可为空', duration: 2000 })
  465. return false
  466. }
  467. if (!rulesPrice.test(parseFloat(this.create.list[i].price))) {
  468. this.$message({ type: 'warning', message: '饲料价格最多保留两位小数', duration: 2000 })
  469. return false
  470. }
  471. }
  472. this.create.createTemp.operatetime = parseTime(this.create.createTemp.operatetime, '{y}-{m}-{d}')
  473. this.requestParam.common = { 'returnmap': '0' }
  474. this.requestParam.data = []
  475. this.requestParam.data[0] = { 'name': 'updateBigContract', 'type': 'e', 'parammaps': {
  476. 'pastureid': this.create.createTemp.pastureid,
  477. 'id': this.create.createTemp.id,
  478. 'operatetime': this.create.createTemp.operatetime,
  479. 'enable': this.create.createTemp.enable
  480. }}
  481. this.requestParam.data[1] = { 'name': 'deleteContract', 'type': 'e', 'parammaps': {
  482. 'pastureid': this.create.createTemp.pastureid,
  483. 'id': this.create.createTemp.id
  484. }}
  485. this.requestParam.data[2] = { 'name': 'insertSpotList', 'resultmaps': { 'list': this.create.list }}
  486. this.requestParam.data[2].children = []
  487. this.requestParam.data[2].children[0] = { 'name': 'insertContract', 'type': 'e', 'parammaps': {
  488. pastureid: '@insertSpotList.pastureid',
  489. bigid: this.create.createTemp.id,
  490. feedid: '@insertSpotList.feedid',
  491. feedname: '@insertSpotList.feedname',
  492. price: '@insertSpotList.price'
  493. }}
  494. ExecDataByConfig(this.requestParam).then(response => {
  495. if (response.msg === 'fail') {
  496. this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
  497. } else {
  498. this.$notify({ title: '', message: '成功', type: 'success', duration: 2000 })
  499. this.create.dialogFormVisible = false
  500. this.getList()
  501. }
  502. })
  503. }
  504. })
  505. },
  506. handleSee(row) {
  507. console.log('点击了查看')
  508. this.create.dialogStatus = 'see'
  509. this.create.dialogFormVisible = true
  510. this.create.createTemp = Object.assign({}, row)
  511. this.create.getdataListParm.parammaps.pastureid = row.pastureid
  512. this.create.getdataListParm.parammaps.id = row.id
  513. this.getSeeList()
  514. },
  515. getSeeList() {
  516. this.create.listLoading = true
  517. GetDataByName(this.create.getdataListParm).then(response => {
  518. console.log('查看table数据', response.data.list)
  519. if (response.data.list !== null) {
  520. this.create.list = response.data.list
  521. } else {
  522. this.create.list = []
  523. }
  524. setTimeout(() => {
  525. this.create.listLoading = false
  526. }, 100)
  527. })
  528. },
  529. handleRowDelete(row) {
  530. MessageBox.confirm('是否确认删除此信息?', {
  531. confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
  532. }).then(() => {
  533. console.log('点击了删除')
  534. this.requestParam.common = { 'returnmap': '0' }
  535. this.requestParam.data = []
  536. this.requestParam.data[0] = { 'name': 'deleteBigContract', 'type': 'e', 'parammaps': {
  537. 'pastureid': row.pastureid,
  538. 'id': row.id
  539. }}
  540. this.requestParam.data[1] = { 'name': 'deleteContract', 'type': 'e', 'parammaps': {
  541. 'pastureid': row.pastureid,
  542. 'id': row.id
  543. }}
  544. ExecDataByConfig(this.requestParam).then(response => {
  545. if (response.msg === 'fail') {
  546. this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
  547. } else {
  548. this.$notify({ title: '', message: '成功', type: 'success', duration: 2000 })
  549. this.getList()
  550. }
  551. })
  552. }).catch(() => {
  553. this.$message({ type: 'info', message: '已取消删除' })
  554. })
  555. },
  556. handleExport(item) {
  557. if (item == 1) {
  558. console.log('点击了导出模板')
  559. const requestParam = this.requestParam
  560. const url = process.env.VUE_APP_BASE_API + 'file/导入导出模板/库存管理/饲料合同导入模板.xlsx' // 请求下载文件的地址
  561. console.log(url)
  562. axios({
  563. method: 'GET',
  564. url: url,
  565. data: requestParam,
  566. headers: { token: getToken(), optname: 'insertcustomdoc' },
  567. responseType: 'blob'
  568. }).then(res => {
  569. if (!res) return
  570. this.percentage = 99
  571. setTimeout(() => {
  572. this.isPercentage = false
  573. }, 2000)
  574. const blob = new Blob([res.data], {
  575. type: 'application/octet-stream;charset=utf-8'
  576. })
  577. const url = window.URL.createObjectURL(blob)
  578. const aLink = document.createElement('a')
  579. aLink.style.display = 'none'
  580. aLink.href = url
  581. const docname = '饲料合同导入模板.xlsx'
  582. aLink.setAttribute('download', docname) // 下载的文件
  583. document.body.appendChild(aLink)
  584. aLink.click()
  585. document.body.removeChild(aLink)
  586. window.URL.revokeObjectURL(url)
  587. })
  588. } else {
  589. console.log('点击了导出数据')
  590. this.download.getdataListParm.parammaps = this.table.getdataListParm.parammaps
  591. if (this.download.getdataListParm.parammaps.inputDatetime !== '' && this.download.getdataListParm.parammaps.inputDatetime !== null) {
  592. this.download.getdataListParm.parammaps.startTime = parseTime(this.download.getdataListParm.parammaps.inputDatetime[0], '{y}-{m}-{d}')
  593. this.download.getdataListParm.parammaps.stopTime = parseTime(this.download.getdataListParm.parammaps.inputDatetime[1], '{y}-{m}-{d}')
  594. } else {
  595. this.download.getdataListParm.parammaps.inputDatetime = ''
  596. this.download.getdataListParm.parammaps.startTime = ''
  597. this.download.getdataListParm.parammaps.stopTime = ''
  598. }
  599. GetDataByName(this.download.getdataListParm).then(response => {
  600. if (response.data.list !== null) {
  601. this.download.list = response.data.list
  602. } else {
  603. this.download.list = []
  604. }
  605. var excelDatas = [
  606. {
  607. tHeader: ['合同编号', '供应商', '饲料名称', '饲料价格(元)', '录入日期'],
  608. filterVal: ['contractcode', 'providername', 'feedname', 'price', 'operatetime'],
  609. tableDatas: this.download.list,
  610. sheetName: 'Sheet1'
  611. }
  612. ]
  613. json2excel(excelDatas, '饲料合同', true, 'xlsx')
  614. })
  615. }
  616. },
  617. beforeImport(file) {
  618. const isLt2M = file.size / 1024 / 1024 < 2
  619. if (!isLt2M) {
  620. this.$message.error('上传文件大小不能超过 2MB!')
  621. }
  622. return isLt2M
  623. },
  624. handleImportSuccess(res, file) {
  625. this.getList()
  626. if (res.msg === 'ok') {
  627. this.$message({ title: '成功', message: '导入成功:' + res.data.success + '条!', type: 'success', duration: 2000 })
  628. if (res.data.err_count > 0) {
  629. this.$notify({ title: '失败', message: '导入失败:' + res.data.err_count + '条!', type: 'danger', duration: 2000 })
  630. import('@/vendor/Export2Excel').then(excel => {
  631. const list1 = res.data.result
  632. const tHeader = [
  633. '合同编号', '供应商', '饲料名称', '饲料价格(元)', '录入日期', '错误信息'
  634. ]
  635. const filterVal = [
  636. '合同编号', '供应商', '饲料名称', '饲料价格(元)', '录入日期', 'error_msg'
  637. ]
  638. const data1 = this.formatJson(filterVal, list1)
  639. excel.export_json_to_excel({ header: tHeader, data: data1, filename: '入库管理导入报错信息', autoWidth: true, bookType: 'xlsx' })
  640. })
  641. }
  642. } else {
  643. this.$notify({ title: '失败', message: '上传失败', type: 'danger', duration: 2000 })
  644. }
  645. },
  646. formatJson(filterVal, jsonData) {
  647. return jsonData.map(v =>
  648. filterVal.map(j => {
  649. if (j === 'timestamp') {
  650. return parseTime(v[j])
  651. } else {
  652. return v[j]
  653. }
  654. })
  655. )
  656. }
  657. }
  658. }
  659. </script>
  660. <style lang="scss" scoped>
  661. .search{margin-top:10px;}
  662. .table{margin-top:10px;}
  663. </style>
  664. <style>
  665. .inputDatetime .el-range-separator{ padding: 0; margin: 0 10px; }
  666. </style>