aa812ddf7c3ee4066765c76dd40ed6610007e45f.svn-base 30 KB

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