aecf0e4d0ee5731408bfd9d57f192b90000e08dd.svn-base 30 KB

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