bd0e8d02cdc14c60552fdc49a102f94d77d432cc.svn-base 31 KB

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