index.vue 31 KB

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