fe3fe39d7f7f3a7ef7b8e146effb8d469be42260.svn-base 30 KB

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