index改.vue 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273
  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.feedid" filterable placeholder="饲料名称" class="filter-item" style="width: 150px;" clearable>
  8. <el-option v-for="item in feedNameList" :key="item.id" :label="item.fname" :value="item.id" />
  9. </el-select>
  10. <el-select v-model="table.getdataListParm.parammaps.providerid" placeholder="供应商" class="filter-item" style="width: 150px;" clearable>
  11. <el-option v-for="item in supplierList" :key="item.id" :label="item.providerName" :value="item.id" />
  12. </el-select>
  13. <el-select v-model="table.getdataListParm.parammaps.islaid" placeholder="入库状态" class="filter-item" style="width: 150px;" clearable>
  14. <el-option v-for="item in islaidList" :key="item.id" :label="item.name" :value="item.name" />
  15. </el-select>
  16. <el-button class="successBorder" @click="handleSearch">查询</el-button>
  17. <el-button class="successBorder" @click="handleRefresh">重置</el-button>
  18. </div>
  19. <div class="operation">
  20. <el-button v-if="isRoleEdit" class="success" icon="el-icon-plus" @click="handleCreate">新增入库单</el-button>
  21. <el-upload style="float: right;" :headers="headers" :data="uploadData" :action="uploadExcelUrl" :show-file-list="false" :before-upload="beforeImport" :on-success="handleImportSuccess">
  22. <el-button v-if="isRoleEdit" class="import" icon="el-icon-download" style="float: right;">导入</el-button>
  23. </el-upload>
  24. <el-dropdown style="float: right;margin-right: 10px;">
  25. <el-button class="export" icon="el-icon-upload2">导出</el-button>
  26. <el-dropdown-menu slot="dropdown">
  27. <el-dropdown-item @click.native="handleExport(1)">导出模板</el-dropdown-item>
  28. <el-dropdown-item @click.native="handleExport(2)">导出数据</el-dropdown-item>
  29. </el-dropdown-menu>
  30. </el-dropdown>
  31. </div>
  32. <div class="table">
  33. <el-table
  34. :key="table.tableKey"
  35. v-loading="table.listLoading"
  36. element-loading-text="给我一点时间"
  37. :data="table.list"
  38. border
  39. fit
  40. highlight-current-row
  41. style="width: 100%;"
  42. :row-style="rowStyle"
  43. :cell-style="cellStyle"
  44. class="elTable table-fixed"
  45. :max-height="myHeight"
  46. >
  47. <el-table-column label="序号" align="center" type="index" width="50px">
  48. <template slot-scope="scope">
  49. <span>{{ scope.$index + (table.pageNum-1) * table.pageSize + 1 }}</span>
  50. </template>
  51. </el-table-column>
  52. <el-table-column label="入库日期" min-width="90px" align="center">
  53. <template slot-scope="scope">
  54. <span>{{ scope.row.laiddate }}</span>
  55. </template>
  56. </el-table-column>
  57. <el-table-column label="饲料名称" min-width="90px" align="center">
  58. <template slot-scope="scope">
  59. <span>{{ scope.row.feedname }}</span>
  60. </template>
  61. </el-table-column>
  62. <el-table-column label="供应商" min-width="90px" align="center">
  63. <template slot-scope="scope">
  64. <span>{{ scope.row.providername }}</span>
  65. </template>
  66. </el-table-column>
  67. <el-table-column label="入库重量(kg)" min-width="90px" align="center">
  68. <template slot-scope="scope">
  69. <span>{{ scope.row.operateweight }}</span>
  70. </template>
  71. </el-table-column>
  72. <el-table-column label="总价(元)" min-width="90px" align="center">
  73. <template slot-scope="scope">
  74. <span>{{ scope.row.sumprice }}</span>
  75. </template>
  76. </el-table-column>
  77. <el-table-column label="批号" min-width="90px" align="center">
  78. <template slot-scope="scope">
  79. <span>{{ scope.row.pcpde }}</span>
  80. </template>
  81. </el-table-column>
  82. <el-table-column label="备注" min-width="90px" align="center">
  83. <template slot-scope="scope">
  84. <span>{{ scope.row.remark }}</span>
  85. </template>
  86. </el-table-column>
  87. <el-table-column label="入库状态" min-width="90px" align="center">
  88. <template slot-scope="scope">
  89. <span>{{ scope.row.islaid }}</span>
  90. </template>
  91. </el-table-column>
  92. <el-table-column label="创建人" min-width="90px" align="center">
  93. <template slot-scope="scope">
  94. <span>{{ scope.row.createemp }}</span>
  95. </template>
  96. </el-table-column>
  97. <el-table-column label="创建日期" min-width="90px" align="center">
  98. <template slot-scope="scope">
  99. <span>{{ scope.row.createdate }}</span>
  100. </template>
  101. </el-table-column>
  102. <el-table-column label="操作" align="center" width="80" class-name="small-padding fixed-width" fixed="right">
  103. <template slot-scope="{row}">
  104. <el-button class="miniSuccess" icon="el-icon-search" @click="handleSee(row)" />
  105. <el-button v-if="row.islaid == '已入库'" class="miniSuccess" icon="el-icon-refresh-left" @click="handleRevoke(row)" />
  106. <el-button v-if="row.islaid == '未入库'" class="miniSuccess" icon="el-icon-edit-outline" @click="handleUpdate(row)" />
  107. </template>
  108. </el-table-column>
  109. </el-table>
  110. <pagination v-show="table.total>=0" :total="table.total" :page.sync="table.getdataListParm.offset" :limit.sync="table.getdataListParm.pagecount" @pagination="getList" />
  111. </div>
  112. <!-- 新增入库单 -->
  113. <el-dialog :fullscreen="dialogFull" :title="textMap[create.dialogStatus]" :visible.sync="create.dialogFormVisible" :close-on-click-modal="false" width="90%">
  114. <template slot="title">
  115. <div class="avue-crud__dialog__header">
  116. <span class="el-dialog__title">
  117. <span style="display:inline-block;width:3px;height:20px;margin-right:5px; float: left;margin-top:2px" />
  118. {{ textMap[create.dialogStatus] }}
  119. </span>
  120. <div class="avue-crud__dialog__menu" @click="dialogFull? dialogFull=false: dialogFull=true">
  121. <svg-icon v-if="dialogFull" icon-class="exit-fullscreen" />
  122. <svg-icon v-else icon-class="fullscreen" />
  123. </div>
  124. </div>
  125. </template>
  126. <div class="app-add">
  127. <el-form ref="createTemp" :rules="create.rules" :model="create.createTemp" label-position="right" label-width="160px" style="width: 100%;margin:0 auto">
  128. <el-row>
  129. <el-col :span="24">
  130. <h3 style="width: 160px;text-align: right;">基础信息</h3>
  131. </el-col>
  132. </el-row>
  133. <el-row>
  134. <el-col :span="8">
  135. <el-form-item label="入库日期:" prop="laiddate">
  136. <el-date-picker v-model="create.createTemp.laiddate" :disabled="create.dialogStatus=='see'" class="filter-item" type="date" placeholder="入库日期" :clearable="false" :picker-options="create.pickerOptions1" format="yyyy-MM-dd" value-format="yyyy-MM-dd" />
  137. </el-form-item>
  138. </el-col>
  139. <el-col :span="8">
  140. <el-form-item label="送货单编号:" prop="wagonnumber">
  141. <el-input ref="wagonnumber" v-model="create.createTemp.wagonnumber" :disabled="create.dialogStatus=='see'" class="filter-item" placeholder="送货单编号" type="text" />
  142. </el-form-item>
  143. </el-col>
  144. <el-col :span="8">
  145. <el-form-item label="饲料名称:" prop="feedname">
  146. <el-autocomplete
  147. v-model="create.createTemp.feedname"
  148. value-key="fname"
  149. class="inline-input"
  150. :fetch-suggestions="feedNameSearch"
  151. placeholder="请选择饲料名称"
  152. style="width:98%"
  153. :disabled="create.dialogStatus=='see' || create.dialogStatus=='update'"
  154. @select="handleSelectFeedName"
  155. @blur="blurFeedName"
  156. >
  157. <template slot-scope="{ item }">
  158. <span>{{ item.fname }}</span>
  159. </template>
  160. </el-autocomplete>
  161. </el-form-item>
  162. </el-col>
  163. </el-row>
  164. <el-row>
  165. <el-col :span="8">
  166. <el-form-item label="入库重量(kg):" prop="operateweight">
  167. <el-input ref="operateweight" v-model.trim="create.createTemp.operateweight" :disabled="create.dialogStatus=='see'" class="filter-item" placeholder="最多两位小数" type="number" :step="0.01" @blur="blurOperateweight" />
  168. </el-form-item>
  169. </el-col>
  170. <el-col :span="8">
  171. <el-form-item label="供应商:" prop="providerid">
  172. <el-input v-if="create.dialogStatus=='see'" ref="providername" v-model.trim="create.createTemp.providername" disabled class="filter-item" placeholder="请选择供应商" />
  173. <el-select v-else v-model="create.createTemp.providerid" clearable placeholder="请选择供应商" :disabled="create.dialogStatus=='see'" class="filter-item" style="width: 100%" @change="changeSupplier">
  174. <el-option v-for="item in supplierList" :key="item.id" :label="item.providerName" :value="item.id" />
  175. </el-select>
  176. </el-form-item>
  177. </el-col>
  178. <el-col :span="8">
  179. <el-form-item label="合同编号:" prop="contractcode">
  180. <el-select v-model="create.createTemp.contractcode" clearable placeholder="请选择合同编号" :disabled="create.dialogStatus=='see'" class="filter-item" style="width: 100%" @change="changeContractNo">
  181. <el-option v-for="item in contractNoList" :key="item.id" :label="item.contractcodeCat" :value="item.contractcode" />
  182. </el-select>
  183. </el-form-item>
  184. </el-col>
  185. </el-row>
  186. <el-row>
  187. <el-col :span="24">
  188. <h3 style="width: 160px;text-align: right;">价格信息</h3>
  189. </el-col>
  190. </el-row>
  191. <el-row>
  192. <el-col :span="8">
  193. <el-form-item label="单价(元):" prop="pricenew">
  194. <el-input ref="pricenew" v-model="create.createTemp.pricenew" :disabled="create.createTemp.contractcode !=='' || create.dialogStatus=='see'" class="filter-item" placeholder="最多两位小数" type="number" :step="0.01" @blur="blurPricenew" />
  195. </el-form-item>
  196. </el-col>
  197. <el-col :span="8">
  198. <el-form-item label="总价(元):" prop="sumprice">
  199. <el-input ref="sumprice" v-model="create.createTemp.sumprice" :disabled="create.dialogStatus=='see'" class="filter-item" placeholder="最多两位小数" type="number" :step="0.01" @blur="blurSumprice" />
  200. </el-form-item>
  201. </el-col>
  202. </el-row>
  203. <el-row>
  204. <el-col :span="24">
  205. <h3 style="width: 160px;text-align: right;">饲料信息</h3>
  206. </el-col>
  207. </el-row>
  208. <el-row>
  209. <el-col :span="8">
  210. <el-form-item label="毛重(kg):" prop="grossweight">
  211. <el-input ref="grossweight" v-model.trim="create.createTemp.grossweight" :disabled="create.dialogStatus=='see'" class="filter-item" placeholder="最多两位小数" type="number" :step="0.01" @blur="blurGrossweight" />
  212. </el-form-item>
  213. </el-col>
  214. <el-col :span="8">
  215. <el-form-item label="皮重(kg):" prop="tareweight">
  216. <el-input ref="tareweight" v-model.trim="create.createTemp.tareweight" :disabled="create.dialogStatus=='see'" class="filter-item" placeholder="最多两位小数" type="number" :step="0.01" @blur="blurTareweight" />
  217. </el-form-item>
  218. </el-col>
  219. <el-col :span="8">
  220. <el-form-item label="许可证号:" prop="licence">
  221. <el-input ref="licence" v-model="create.createTemp.licence" :disabled="create.dialogStatus=='see'" class="filter-item" placeholder="许可证号" type="text" />
  222. </el-form-item>
  223. </el-col>
  224. </el-row>
  225. <el-row>
  226. <el-col :span="8">
  227. <el-form-item label="批号:" prop="pcpde">
  228. <el-input ref="pcpde" v-model="create.createTemp.pcpde" :disabled="create.dialogStatus=='see'" class="filter-item" placeholder="批号" type="text" />
  229. </el-form-item>
  230. </el-col>
  231. </el-row>
  232. <el-row>
  233. <el-col :span="24">
  234. <h3 style="width: 160px;text-align: right;">操作信息</h3>
  235. </el-col>
  236. </el-row>
  237. <el-row>
  238. <el-col :span="8">
  239. <el-form-item label="创建人:" prop="createemp">
  240. <el-input ref="createemp" v-model="create.createTemp.createemp" class="filter-item" placeholder="创建人" type="text" disabled />
  241. </el-form-item>
  242. </el-col>
  243. <el-col :span="8">
  244. <el-form-item label="创建日期:" prop="createdate">
  245. <el-date-picker v-model="create.createTemp.createdate" class="filter-item" type="date" placeholder="创建日期" disabled />
  246. </el-form-item>
  247. </el-col>
  248. <el-col :span="8">
  249. <el-form-item label="备注:" prop="remark">
  250. <el-input ref="remark" v-model="create.createTemp.remark" :disabled="create.dialogStatus=='see'" class="filter-item" placeholder="1-255字符" type="text" />
  251. </el-form-item>
  252. </el-col>
  253. </el-row>
  254. </el-form>
  255. <div slot="footer" class="dialog-footer">
  256. <el-button v-if="create.dialogStatus == 'see' " class="cancelClose cancelClose1" @click="create.dialogFormVisible = false;getList(); ">关闭</el-button>
  257. <el-button v-if="create.dialogStatus !== 'see' " class="cancelClose" @click="create.dialogFormVisible = false;getList(); ">关闭</el-button>
  258. <el-button v-if="create.dialogStatus !== 'see' " class="save" :disabled="isokDisable" @click="create.dialogStatus==='create'?createData():updateData()">确认</el-button>
  259. </div>
  260. </div>
  261. </el-dialog>
  262. <!-- 初始化库存 -->
  263. <el-dialog :fullscreen="dialogFull" :visible.sync="initial.dialogFormVisible" :close-on-click-modal="false" width="80%" height="55%">
  264. <template slot="title">
  265. <div class="avue-crud__dialog__header">
  266. <span class="el-dialog__title">
  267. <span style="display:inline-block;width:3px;height:20px;margin-right:5px; float: left;margin-top:2px" />
  268. {{ textMap[initial.dialogStatus] }}
  269. </span>
  270. <div class="avue-crud__dialog__menu" @click="dialogFull? dialogFull=false: dialogFull=true">
  271. <svg-icon v-if="dialogFull" icon-class="exit-fullscreen" />
  272. <svg-icon v-else icon-class="fullscreen" />
  273. </div>
  274. </div>
  275. </template>
  276. <div class="app-add" style="height: 100%;margin: 0 auto 60px;">
  277. <div class="operation">
  278. <el-button style="float: left;margin-bottom:10px;" class="success" @click="handleInitialExport">模板下载</el-button>
  279. <el-upload style="float: left;margin-left: 10px;margin-bottom:10px;" action="" :auto-upload="false" accept=".xlsx, .xls" :show-file-list="false" :on-change="handleInitialImport">
  280. <el-button class="success" icon="el-icon-download">导入</el-button>
  281. </el-upload>
  282. </div>
  283. <div class="table">
  284. <el-table
  285. :key="initial.tableKey"
  286. v-loading="initial.listLoading"
  287. element-loading-text="给我一点时间"
  288. :data="initial.list"
  289. border
  290. fit
  291. highlight-current-row
  292. style="width: 100%;"
  293. :row-style="rowStyle"
  294. :cell-style="cellStyle"
  295. class="elTable table-fixed"
  296. >
  297. <el-table-column label="序号" align="center" type="index" width="50px" />
  298. <el-table-column label="饲料名称" min-width="130px" align="center">
  299. <template slot-scope="scope">
  300. <span>{{ scope.row.fname }}</span>
  301. </template>
  302. </el-table-column>
  303. <el-table-column label="库存重量" min-width="130px" align="center">
  304. <template slot-scope="scope">
  305. <el-input v-model="scope.row.stockweight" placeholder="最多两位小数" type="number" :step="0.01" style="width:95%;padding:10px 0;" />
  306. </template>
  307. </el-table-column>
  308. </el-table>
  309. <div slot="footer" class="dialog-footer">
  310. <el-button class="cancelClose" @click="initial.dialogFormVisible = false; ">关闭</el-button>
  311. <el-button class="save" :disabled="isokDisable" @click="initialData()">确认</el-button>
  312. </div>
  313. </div>
  314. </div>
  315. </el-dialog>
  316. </div>
  317. </template>
  318. <script>
  319. import { GetDataByName, GetDataByNames, checkButtons, ExecDataByConfig, failproccess, formatNum } from '@/api/common'
  320. import Pagination from '@/components/Pagination'
  321. import { MessageBox } from 'element-ui'
  322. import Cookies from 'js-cookie'
  323. import { json2excel, parseTime } from '@/utils/index.js'
  324. import axios from 'axios'
  325. import { getToken } from '@/utils/auth'
  326. import xlsx from 'xlsx'
  327. import { upload } from '@/utils/index.js'
  328. export default {
  329. name: 'Warehousing',
  330. components: { Pagination },
  331. data() {
  332. return {
  333. dialogFull: false,
  334. feedNameList: [], // 饲料名称
  335. feedNameAddList: [], // 饲料名称新增
  336. supplierList: [], // 供应商
  337. contractNoList: [], // 合同编号
  338. islaidList: [{ id: 0, name: '已入库' }, { id: 1, name: '未入库' }, { id: 2, name: '已撤销' }], // 是否入库
  339. requestParams: [
  340. { name: 'getFeedListEnable', offset: 0, pagecount: 0, parammaps: { pastureid: Cookies.get('pastureid') }},
  341. { name: 'getProviderListEnable', offset: 0, pagecount: 0, parammaps: { pastureid: Cookies.get('pastureid') }}
  342. ],
  343. table: {
  344. getdataListParm: {
  345. name: 'getFeedlaidList',
  346. page: 1,
  347. offset: 1,
  348. pagecount: parseInt(Cookies.get('pageCount')),
  349. returntype: 'Map',
  350. parammaps: {
  351. pastureid: Cookies.get('pastureid'),
  352. inputDatetime: '',
  353. startTime: '',
  354. stopTime: '',
  355. feedid: '',
  356. islaid: '',
  357. providerid: ''
  358. }
  359. },
  360. tableKey: 0,
  361. list: [],
  362. total: 0,
  363. listLoading: true
  364. },
  365. create: {
  366. dialogFormVisible: false,
  367. dialogStatus: '',
  368. pickerOptions1: {
  369. disabledDate(time) {
  370. return time.getTime() > Date.now()// 当天之前的时间可选
  371. }
  372. },
  373. createTemp: {
  374. laiddate: '', feedid: '', feedname: '', operateweight: '', providerid: '', providername: '', startweight: '', priceold: '', contractcode: '', pricenew: '', sumprice: '', grossweight: '', tareweight: '', licence: '', pcpde: '', createemp: '', createdate: '', remark: '', 'wagonnumber': ''
  375. },
  376. rules: {
  377. laiddate: [{ type: 'string', required: true, message: '必填', trigger: 'blur' }],
  378. feedname: [{ type: 'string', required: true, message: '必填', trigger: 'change' }],
  379. pricenew: [{ type: 'string', required: true, message: '必填', trigger: 'blur' }]
  380. },
  381. getdataListParm: {
  382. name: 'getBigContractListEnable',
  383. offset: 0,
  384. pagecount: '',
  385. parammaps: { pastureid: Cookies.get('pastureid') }
  386. },
  387. getfeedNameParm: {
  388. name: 'getFeedListEnableV2',
  389. offset: 0,
  390. pagecount: '',
  391. parammaps: { pastureid: Cookies.get('pastureid') }
  392. }
  393. },
  394. initial: {
  395. dialogFormVisible: false,
  396. dialogStatus: '',
  397. rules: {},
  398. getdataListParm: {
  399. name: 'getinitFeed',
  400. page: 1,
  401. offset: 1,
  402. pagecount: 6,
  403. returntype: 'Map',
  404. parammaps: {
  405. pastureid: Cookies.get('pastureid')
  406. }
  407. },
  408. tableKey: 0,
  409. list: [],
  410. total: 0,
  411. listLoading: true,
  412. character: {
  413. fname: {
  414. text: '饲料名称',
  415. type: String
  416. },
  417. stockweight: {
  418. text: '库存重量',
  419. type: String
  420. }
  421. }
  422. },
  423. textMap: {
  424. create: '新增入库单',
  425. update: '编辑入库单',
  426. see: '查看入库单',
  427. initial: '初始化库存'
  428. },
  429. requestParam: {},
  430. download: {
  431. getdataListParm: {
  432. name: 'getFeedlaidList',
  433. page: 1,
  434. offset: 1,
  435. pagecount: 0,
  436. returntype: 'Map',
  437. parammaps: {
  438. pastureid: Cookies.get('pastureid'),
  439. inputDatetime: '',
  440. startTime: '',
  441. stopTime: '',
  442. feedid: '',
  443. islaid: '',
  444. providerid: ''
  445. }
  446. },
  447. list: []
  448. },
  449. isokDisable: false,
  450. isRoleEdit: [],
  451. rowStyle: { maxHeight: 30 + 'px', height: 30 + 'px' },
  452. cellStyle: { padding: 0 + 'px' },
  453. myHeight:document.documentElement.clientHeight - 85- 150 - 45
  454. }
  455. },
  456. computed: {
  457. // 设置请求头
  458. headers() {
  459. return {
  460. token: getToken()
  461. }
  462. },
  463. uploadData() {
  464. return {
  465. name: 'checkFeed,checkProviderRK,checkcontractcode,checkcontractcodePrice,insertFeedlaidUpload,insertFeedstorageLaidUpload',
  466. importParams: '入库日期,送货单编号,饲料名称,供应商,合同编号,入库重量(kg),单价(元),总价(元),毛重(kg),皮重(kg),许可证号,批号,创建人,备注',
  467. sheetname: 'Sheet1',
  468. // 登录牧场
  469. pastureid: Cookies.get('pastureid'),
  470. // 日期参数
  471. dateParams: '入库日期',
  472. // 必填参数
  473. requiredParams: '入库日期,饲料名称,入库重量(kg),单价(元)',
  474. // 为数值的参数
  475. numParams: '入库重量(kg),单价(元),总价(元),毛重(kg),皮重(kg)'
  476. }
  477. },
  478. // 设置上传地址
  479. uploadExcelUrl() {
  480. return process.env.VUE_APP_BASE_API + 'authdata/ImportExcel'
  481. }
  482. },
  483. created() {
  484. this.getButtons()
  485. this.getDownList()
  486. this.getList()
  487. },
  488. methods: {
  489. getButtons() {
  490. const Edit = 'Warehousing'
  491. const isRoleEdit = checkButtons(JSON.parse(sessionStorage.getItem('buttons')), Edit)
  492. this.isRoleEdit = isRoleEdit
  493. },
  494. getDownList() {
  495. GetDataByNames(this.requestParams).then(response => {
  496. this.feedNameList = response.data.getFeedListEnable.list
  497. this.supplierList = response.data.getProviderListEnable.list
  498. })
  499. },
  500. handleBefore() {
  501. if (this.table.getdataListParm.parammaps.inputDatetime !== '' && this.table.getdataListParm.parammaps.inputDatetime !== null) {
  502. var start = new Date(this.table.getdataListParm.parammaps.inputDatetime[0].setDate(this.table.getdataListParm.parammaps.inputDatetime[0].getDate() - 1))
  503. var stop = new Date(this.table.getdataListParm.parammaps.inputDatetime[1].setDate(this.table.getdataListParm.parammaps.inputDatetime[1].getDate() - 1))
  504. this.table.getdataListParm.parammaps.inputDatetime.length = 0
  505. this.table.getdataListParm.parammaps.inputDatetime.push(start, stop)
  506. this.$forceUpdate()
  507. }
  508. },
  509. handleNext() {
  510. if (this.table.getdataListParm.parammaps.inputDatetime !== '' && this.table.getdataListParm.parammaps.inputDatetime !== null) {
  511. var start = new Date(this.table.getdataListParm.parammaps.inputDatetime[0].setDate(this.table.getdataListParm.parammaps.inputDatetime[0].getDate() + 1))
  512. var stop = new Date(this.table.getdataListParm.parammaps.inputDatetime[1].setDate(this.table.getdataListParm.parammaps.inputDatetime[1].getDate() + 1))
  513. this.table.getdataListParm.parammaps.inputDatetime.length = 0
  514. this.table.getdataListParm.parammaps.inputDatetime.push(start, stop)
  515. this.$forceUpdate()
  516. }
  517. },
  518. getList() {
  519. this.table.listLoading = true
  520. GetDataByName(this.table.getdataListParm).then(response => {
  521. console.log('table数据', response.data.list)
  522. if (response.data.list !== null) {
  523. this.table.list = response.data.list
  524. this.table.pageNum = response.data.pageNum
  525. this.table.pageSize = response.data.pageSize
  526. this.table.total = response.data.total
  527. } else {
  528. this.table.list = []
  529. }
  530. setTimeout(() => {
  531. this.table.listLoading = false
  532. }, 100)
  533. })
  534. },
  535. handleSearch() {
  536. // console.log('点击了查询')
  537. if (this.table.getdataListParm.parammaps.inputDatetime !== '' && this.table.getdataListParm.parammaps.inputDatetime !== null) {
  538. this.table.getdataListParm.parammaps.startTime = parseTime(this.table.getdataListParm.parammaps.inputDatetime[0], '{y}-{m}-{d}')
  539. this.table.getdataListParm.parammaps.stopTime = parseTime(this.table.getdataListParm.parammaps.inputDatetime[1], '{y}-{m}-{d}')
  540. } else {
  541. this.table.getdataListParm.parammaps.inputDatetime = ''
  542. this.table.getdataListParm.parammaps.startTime = ''
  543. this.table.getdataListParm.parammaps.stopTime = ''
  544. }
  545. this.table.getdataListParm.offset = 1
  546. this.getList()
  547. },
  548. handleRefresh() {
  549. console.log('点击了重置')
  550. this.table.getdataListParm.parammaps.inputDatetime = ''
  551. this.table.getdataListParm.parammaps.startTime = ''
  552. this.table.getdataListParm.parammaps.stopTime = ''
  553. this.table.getdataListParm.parammaps.feedid = ''
  554. this.table.getdataListParm.parammaps.islaid = ''
  555. this.table.getdataListParm.parammaps.providerid = ''
  556. this.table.getdataListParm.offset = 1
  557. this.getList()
  558. },
  559. resetCreateTemp() {
  560. this.create.createTemp = {
  561. pastureid: Cookies.get('pastureid'), laiddate: parseTime(new Date(), '{y}-{m}-{d}'), feedid: '', feedname: '', operateweight: '', providerid: '', providername: '', startweight: '', priceold: '', contractcode: '', pricenew: '', sumprice: '', grossweight: '', tareweight: '', licence: '', pcpde: '', createemp: Cookies.get('employename'), createdate: parseTime(new Date(), '{y}-{m}-{d}'), remark: '', 'wagonnumber': ''
  562. }
  563. this.contractNoList = []
  564. },
  565. // 供应商
  566. changeSupplier(item) {
  567. console.log(item)
  568. if (item !== '') {
  569. this.create.createTemp.providername = this.supplierList.find(obj => obj.id == item).providerName
  570. } else {
  571. this.create.createTemp.providername = ''
  572. this.create.createTemp.contractcode = ''
  573. this.create.createTemp.pricenew = ''
  574. this.create.createTemp.sumprice = ''
  575. this.contractNoList = []
  576. }
  577. if (this.create.createTemp.feedid !== '' && this.create.createTemp.providerid !== '') {
  578. this.getContractNoList()
  579. }
  580. },
  581. // 合同编号
  582. changeContractNo(item) {
  583. if (item !== '') {
  584. this.create.createTemp.pricenew = this.contractNoList.find(obj => obj.contractcode == item).price
  585. } else {
  586. this.create.createTemp.pricenew = ''
  587. }
  588. if (this.create.createTemp.operateweight !== '' && this.create.createTemp.pricenew !== '') {
  589. this.create.createTemp.sumprice = parseFloat(this.create.createTemp.operateweight) * parseFloat(this.create.createTemp.pricenew)
  590. this.create.createTemp.sumprice = formatNum(this.create.createTemp.sumprice, 2)
  591. }
  592. },
  593. getContractNoList() {
  594. this.create.getdataListParm.parammaps.feedid = this.create.createTemp.feedid
  595. this.create.getdataListParm.parammaps.providerid = this.create.createTemp.providerid
  596. GetDataByName(this.create.getdataListParm).then(response => {
  597. console.log('table数据', response.data.list)
  598. if (response.data.list !== null) {
  599. this.contractNoList = response.data.list
  600. this.create.createTemp.contractcode = ''
  601. this.create.createTemp.pricenew = ''
  602. this.create.createTemp.sumprice = ''
  603. } else {
  604. this.contractNoList = []
  605. this.create.createTemp.contractcode = ''
  606. this.create.createTemp.pricenew = ''
  607. this.create.createTemp.sumprice = ''
  608. }
  609. })
  610. },
  611. feedNameSearch(queryString, cb) {
  612. this.create.getfeedNameParm.parammaps['fname'] = queryString
  613. GetDataByName(this.create.getfeedNameParm).then(response => {
  614. console.log('模糊查询搜索data', response.data.list)
  615. if (response.data.list == null) {
  616. cb([])
  617. } else {
  618. cb(response.data.list)
  619. }
  620. })
  621. },
  622. handleSelectFeedName(item) {
  623. console.log('模糊查询选中值', item)
  624. this.create.createTemp.feedname = item.fname
  625. this.create.createTemp.feedid = item.id
  626. this.create.createTemp.startweight = item.stockweight
  627. this.create.createTemp.priceold = item.price
  628. this.create.createTemp.providerid = ''
  629. this.create.createTemp.providername = ''
  630. this.create.createTemp.contractcode = ''
  631. this.create.createTemp.pricenew = ''
  632. this.create.createTemp.sumprice = ''
  633. if (this.create.createTemp.feedid !== '' && this.create.createTemp.providerid !== '') {
  634. this.getContractNoList()
  635. }
  636. },
  637. blurFeedName() {
  638. this.create.createTemp.feedname = ''
  639. this.create.createTemp.feedid = ''
  640. this.create.createTemp.startweight = ''
  641. this.create.createTemp.priceold = ''
  642. this.create.createTemp.providerid = ''
  643. this.create.createTemp.providername = ''
  644. this.create.createTemp.contractcode = ''
  645. this.create.createTemp.pricenew = ''
  646. this.create.createTemp.sumprice = ''
  647. },
  648. // 入库重量
  649. blurOperateweight() {
  650. // 毛重grossweight皮重tareweight入库重量operateweight
  651. if (this.create.createTemp.grossweight !== '' && this.create.createTemp.operateweight !== '') {
  652. this.create.createTemp.tareweight = formatNum(parseFloat(this.create.createTemp.grossweight) - parseFloat(this.create.createTemp.operateweight), 2)
  653. }
  654. if (this.create.createTemp.grossweight !== '' && this.create.createTemp.operateweight !== '') {
  655. if (parseFloat(this.create.createTemp.operateweight) > parseFloat(this.create.createTemp.grossweight)) {
  656. this.create.createTemp.grossweight = formatNum(this.create.createTemp.operateweight, 2)
  657. this.create.createTemp.tareweight = formatNum(parseFloat(this.create.createTemp.operateweight) - parseFloat(this.create.createTemp.operateweight), 2)
  658. }
  659. }
  660. if (this.create.createTemp.tareweight !== '' && this.create.createTemp.grossweight !== '') {
  661. if (this.create.createTemp.operateweight == '') {
  662. this.create.createTemp.operateweight = formatNum(parseFloat(this.create.createTemp.grossweight) - parseFloat(this.create.createTemp.tareweight), 2)
  663. }
  664. if (parseFloat(this.create.createTemp.tareweight) > parseFloat(this.create.createTemp.grossweight)) {
  665. this.create.createTemp.tareweight = formatNum(this.create.createTemp.grossweight, 2)
  666. this.create.createTemp.operateweight = formatNum(parseFloat(this.create.createTemp.grossweight) - parseFloat(this.create.createTemp.tareweight), 2)
  667. }
  668. }
  669. if (this.create.createTemp.operateweight !== '' && this.create.createTemp.pricenew !== '') {
  670. this.create.createTemp.sumprice = parseFloat(this.create.createTemp.operateweight) * parseFloat(this.create.createTemp.pricenew)
  671. this.create.createTemp.sumprice = formatNum(this.create.createTemp.sumprice, 2)
  672. } else {
  673. this.create.createTemp.sumprice = ''
  674. }
  675. },
  676. // 毛重
  677. blurGrossweight() {
  678. // 毛重grossweight皮重tareweight入库重量operateweight
  679. if (this.create.createTemp.grossweight !== '' && this.create.createTemp.operateweight !== '') {
  680. this.create.createTemp.tareweight = formatNum(parseFloat(this.create.createTemp.grossweight) - parseFloat(this.create.createTemp.operateweight), 2)
  681. }
  682. if (this.create.createTemp.grossweight !== '' && this.create.createTemp.operateweight !== '') {
  683. if (parseFloat(this.create.createTemp.operateweight) > parseFloat(this.create.createTemp.grossweight)) {
  684. this.create.createTemp.grossweight = formatNum(this.create.createTemp.operateweight, 2)
  685. this.create.createTemp.tareweight = formatNum(parseFloat(this.create.createTemp.operateweight) - parseFloat(this.create.createTemp.operateweight), 2)
  686. }
  687. }
  688. if (this.create.createTemp.pricenew !== '' && this.create.createTemp.operateweight !== '') {
  689. this.create.createTemp.sumprice = parseFloat(this.create.createTemp.operateweight) * parseFloat(this.create.createTemp.pricenew)
  690. this.create.createTemp.sumprice = formatNum(this.create.createTemp.sumprice, 2)
  691. } else {
  692. this.create.createTemp.sumprice = ''
  693. }
  694. },
  695. // 皮重
  696. blurTareweight() {
  697. // 毛重grossweight皮重tareweight入库重量operateweight
  698. if (this.create.createTemp.operateweight !== '' && this.create.createTemp.tareweight !== '') {
  699. this.create.createTemp.grossweight = formatNum(parseFloat(this.create.createTemp.tareweight) + parseFloat(this.create.createTemp.operateweight), 2)
  700. }
  701. if (this.create.createTemp.grossweight !== '' && this.create.createTemp.operateweight !== '') {
  702. if (parseFloat(this.create.createTemp.operateweight) > parseFloat(this.create.createTemp.grossweight)) {
  703. this.create.createTemp.grossweight = formatNum(this.create.createTemp.operateweight, 2)
  704. this.create.createTemp.tareweight = formatNum(parseFloat(this.create.createTemp.operateweight) - parseFloat(this.create.createTemp.operateweight), 2)
  705. }
  706. }
  707. if (this.create.createTemp.tareweight !== '' && this.create.createTemp.grossweight !== '') {
  708. if (parseFloat(this.create.createTemp.tareweight) > parseFloat(this.create.createTemp.grossweight)) {
  709. this.create.createTemp.tareweight = formatNum(this.create.createTemp.grossweight, 2)
  710. this.create.createTemp.operateweight = formatNum(parseFloat(this.create.createTemp.grossweight) - parseFloat(this.create.createTemp.tareweight), 2)
  711. } else {
  712. this.create.createTemp.operateweight = formatNum(parseFloat(this.create.createTemp.grossweight) - parseFloat(this.create.createTemp.tareweight), 2)
  713. }
  714. }
  715. if (this.create.createTemp.pricenew !== '' && this.create.createTemp.operateweight !== '') {
  716. this.create.createTemp.sumprice = parseFloat(this.create.createTemp.operateweight) * parseFloat(this.create.createTemp.pricenew)
  717. this.create.createTemp.sumprice = formatNum(this.create.createTemp.sumprice, 2)
  718. } else {
  719. this.create.createTemp.sumprice = ''
  720. }
  721. },
  722. // 单价
  723. blurPricenew() {
  724. if (this.create.createTemp.operateweight !== '' && this.create.createTemp.pricenew !== '') {
  725. this.create.createTemp.sumprice = parseFloat(this.create.createTemp.operateweight) * parseFloat(this.create.createTemp.pricenew)
  726. this.create.createTemp.sumprice = formatNum(this.create.createTemp.sumprice, 2)
  727. } else {
  728. this.create.createTemp.sumprice = ''
  729. }
  730. },
  731. // 总价
  732. blurSumprice() {
  733. if (this.create.createTemp.sumprice !== '' && this.create.createTemp.pricenew !== '') {
  734. this.create.createTemp.operateweight = formatNum(parseFloat(this.create.createTemp.sumprice) / parseFloat(this.create.createTemp.pricenew), 2)
  735. } else {
  736. this.create.createTemp.operateweight = ''
  737. }
  738. },
  739. handleCreate() {
  740. console.log('点击了新增入库单')
  741. this.dialogFull = false
  742. this.create.dialogStatus = 'create'
  743. this.create.dialogFormVisible = true
  744. this.$nextTick(() => {
  745. this.resetCreateTemp()
  746. this.$refs.createTemp.resetFields()
  747. })
  748. },
  749. createData() {
  750. this.$refs['createTemp'].validate(valid => {
  751. if (valid) {
  752. if (this.create.createTemp.operateweight == '' && this.create.createTemp.grossweight == '') {
  753. this.$message({ type: 'error', message: '请输入入库重量或毛重', duration: 2000 })
  754. return false
  755. }
  756. if (this.create.createTemp.sumprice.length > 15) {
  757. this.$message({ type: 'error', message: '数值过大请重新输入', duration: 2000 })
  758. }
  759. const keepTwoNum = /^\d+(\.\d{1,2})?$/
  760. // 入库重量
  761. if (this.create.createTemp.operateweight !== '') {
  762. if (this.create.createTemp.operateweight == 0) {
  763. this.$message({ type: 'error', message: '入库重量请输入自然数并保留两位小数', duration: 2000 })
  764. return false
  765. } else {
  766. if (!keepTwoNum.test(parseFloat(this.create.createTemp.operateweight))) {
  767. this.$message({ type: 'error', message: '入库重量请输入自然数并保留两位小数', duration: 2000 })
  768. return false
  769. }
  770. }
  771. }
  772. // 单价
  773. if (this.create.createTemp.pricenew == 0) {
  774. this.$message({ type: 'error', message: '单价请输入自然数并保留两位小数', duration: 2000 })
  775. return false
  776. } else {
  777. if (!keepTwoNum.test(parseFloat(this.create.createTemp.pricenew))) {
  778. this.$message({ type: 'error', message: '单价请输入自然数并保留两位小数', duration: 2000 })
  779. return false
  780. }
  781. }
  782. // 总价
  783. if (this.create.createTemp.pricenew !== '' && this.create.createTemp.operateweight !== '') {
  784. if (this.create.createTemp.sumprice == 0) {
  785. this.$message({ type: 'error', message: '总价请输入自然数并保留两位小数', duration: 2000 })
  786. return false
  787. } else {
  788. if (!keepTwoNum.test(parseFloat(this.create.createTemp.sumprice))) {
  789. this.$message({ type: 'error', message: '总价请输入自然数并保留两位小数', duration: 2000 })
  790. return false
  791. }
  792. }
  793. }
  794. // 毛重
  795. if (this.create.createTemp.grossweight !== '') {
  796. if (this.create.createTemp.grossweight == 0) {
  797. this.$message({ type: 'error', message: '毛重请输入自然数并保留两位小数', duration: 2000 })
  798. return false
  799. } else {
  800. if (!keepTwoNum.test(parseFloat(this.create.createTemp.grossweight))) {
  801. this.$message({ type: 'error', message: '毛重请输入自然数并保留两位小数', duration: 2000 })
  802. return false
  803. }
  804. }
  805. }
  806. // 皮重
  807. if (this.create.createTemp.tareweight !== '') {
  808. if (this.create.createTemp.tareweight == 0) {
  809. this.$message({ type: 'error', message: '皮重请输入自然数并保留两位小数', duration: 2000 })
  810. return false
  811. } else {
  812. if (!keepTwoNum.test(parseFloat(this.create.createTemp.tareweight))) {
  813. this.$message({ type: 'error', message: '皮重请输入自然数并保留两位小数', duration: 2000 })
  814. return false
  815. }
  816. }
  817. }
  818. MessageBox.confirm('是否确认保存当前内容', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
  819. }).then(() => {
  820. this.isokDisable = true
  821. setTimeout(() => {
  822. this.isokDisable = false
  823. }, 1000)
  824. this.requestParam.common = { 'returnmap': '0' }
  825. this.requestParam.data = []
  826. this.requestParam.data[0] = { 'name': 'insertFeedlaid', 'type': 'e', 'parammaps': {
  827. 'pastureid': this.create.createTemp.pastureid,
  828. 'laiddate': this.create.createTemp.laiddate,
  829. 'feedid': this.create.createTemp.feedid,
  830. 'feedname': this.create.createTemp.feedname,
  831. 'providerid': this.create.createTemp.providerid,
  832. 'providername': this.create.createTemp.providername,
  833. 'contractcode': this.create.createTemp.contractcode,
  834. 'operateweight': this.create.createTemp.operateweight,
  835. 'grossweight': this.create.createTemp.grossweight,
  836. 'tareweight': this.create.createTemp.tareweight,
  837. 'sumprice': this.create.createTemp.sumprice,
  838. 'licence': this.create.createTemp.licence,
  839. 'pcpde': this.create.createTemp.pcpde,
  840. 'remark': this.create.createTemp.remark,
  841. 'createdate': this.create.createTemp.createdate,
  842. 'createemp': this.create.createTemp.createemp,
  843. 'startweight': this.create.createTemp.startweight,
  844. 'priceold': this.create.createTemp.priceold,
  845. 'pricenew': this.create.createTemp.pricenew,
  846. 'wagonnumber': this.create.createTemp.wagonnumber
  847. }}
  848. if (this.create.createTemp.operateweight !== '' && parseFloat(this.create.createTemp.operateweight) > 0) {
  849. this.requestParam.data[1] = { 'name': 'insertFeedstorageLaid', 'type': 'e', 'parammaps': {
  850. 'operateweight': this.create.createTemp.operateweight,
  851. 'pastureid': this.create.createTemp.pastureid,
  852. 'feedid': this.create.createTemp.feedid,
  853. 'fname': this.create.createTemp.fname,
  854. 'pcpde': this.create.createTemp.pcpde,
  855. 'stockweight': this.create.createTemp.startweight,
  856. 'price': this.create.createTemp.pricenew
  857. }}
  858. }
  859. console.log('点击了新增入库单保存', this.requestParam)
  860. ExecDataByConfig(this.requestParam).then(response => {
  861. if (response.msg === 'fail') {
  862. this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
  863. } else {
  864. this.$notify({ title: '', message: '成功', type: 'success', duration: 2000 })
  865. this.create.dialogFormVisible = false
  866. this.getList()
  867. }
  868. })
  869. })
  870. }
  871. })
  872. },
  873. handleUpdate(row) {
  874. console.log('点击了编辑')
  875. this.$nextTick(() => {
  876. this.$refs.createTemp.resetFields()
  877. })
  878. this.dialogFull = false
  879. this.create.dialogStatus = 'update'
  880. this.create.dialogFormVisible = true
  881. row.feedid = String(row.feedid)
  882. if (row.providerid == -1) {
  883. row.providerid = ''
  884. row.providername = ''
  885. }
  886. this.create.createTemp = Object.assign({}, row)
  887. },
  888. updateData() {
  889. this.$refs['createTemp'].validate(valid => {
  890. if (valid) {
  891. if (this.create.createTemp.operateweight == '' && this.create.createTemp.grossweight == '') {
  892. this.$message({ type: 'error', message: '请输入入库重量或毛重', duration: 2000 })
  893. return false
  894. }
  895. if (this.create.createTemp.sumprice.length > 15) {
  896. this.$message({ type: 'error', message: '数值过大请重新输入', duration: 2000 })
  897. }
  898. const keepTwoNum = /^\d+(\.\d{1,2})?$/
  899. // 入库重量
  900. if (this.create.createTemp.operateweight !== '') {
  901. if (this.create.createTemp.operateweight == 0) {
  902. this.$message({ type: 'error', message: '入库重量请输入自然数并保留两位小数', duration: 2000 })
  903. return false
  904. } else {
  905. if (!keepTwoNum.test(parseFloat(this.create.createTemp.operateweight))) {
  906. this.$message({ type: 'error', message: '入库重量请输入自然数并保留两位小数', duration: 2000 })
  907. return false
  908. }
  909. }
  910. }
  911. // 单价
  912. if (this.create.createTemp.pricenew == 0) {
  913. this.$message({ type: 'error', message: '单价请输入自然数并保留两位小数', duration: 2000 })
  914. return false
  915. } else {
  916. if (!keepTwoNum.test(parseFloat(this.create.createTemp.pricenew))) {
  917. this.$message({ type: 'error', message: '单价请输入自然数并保留两位小数', duration: 2000 })
  918. return false
  919. }
  920. }
  921. // 总价
  922. if (this.create.createTemp.pricenew !== '' && this.create.createTemp.operateweight !== '') {
  923. if (this.create.createTemp.sumprice == 0) {
  924. this.$message({ type: 'error', message: '总价请输入自然数并保留两位小数', duration: 2000 })
  925. return false
  926. } else {
  927. if (!keepTwoNum.test(parseFloat(this.create.createTemp.sumprice))) {
  928. this.$message({ type: 'error', message: '总价请输入自然数并保留两位小数', duration: 2000 })
  929. return false
  930. }
  931. }
  932. }
  933. // 毛重
  934. if (this.create.createTemp.grossweight !== '') {
  935. if (this.create.createTemp.grossweight == 0) {
  936. this.$message({ type: 'error', message: '毛重请输入自然数并保留两位小数', duration: 2000 })
  937. return false
  938. } else {
  939. if (!keepTwoNum.test(parseFloat(this.create.createTemp.grossweight))) {
  940. this.$message({ type: 'error', message: '毛重请输入自然数并保留两位小数', duration: 2000 })
  941. return false
  942. }
  943. }
  944. }
  945. // 皮重
  946. if (this.create.createTemp.tareweight !== '') {
  947. if (this.create.createTemp.tareweight == 0) {
  948. this.$message({ type: 'error', message: '皮重请输入自然数并保留两位小数', duration: 2000 })
  949. return false
  950. } else {
  951. if (!keepTwoNum.test(parseFloat(this.create.createTemp.tareweight))) {
  952. this.$message({ type: 'error', message: '皮重请输入自然数并保留两位小数', duration: 2000 })
  953. return false
  954. }
  955. }
  956. }
  957. MessageBox.confirm('是否确认保存当前内容', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
  958. }).then(() => {
  959. this.isokDisable = true
  960. setTimeout(() => {
  961. this.isokDisable = false
  962. }, 1000)
  963. this.requestParam.common = { 'returnmap': '0' }
  964. this.requestParam.data = []
  965. this.requestParam.data[0] = { 'name': 'updateFeedlaid', 'type': 'e', 'parammaps': {
  966. 'pastureid': this.create.createTemp.pastureid,
  967. 'id': this.create.createTemp.id,
  968. 'laiddate': this.create.createTemp.laiddate,
  969. 'feedid': this.create.createTemp.feedid,
  970. 'feedname': this.create.createTemp.feedname,
  971. 'providerid': this.create.createTemp.providerid,
  972. 'providername': this.create.createTemp.providername,
  973. 'contractcode': this.create.createTemp.contractcode,
  974. 'operateweight': this.create.createTemp.operateweight,
  975. 'grossweight': this.create.createTemp.grossweight,
  976. 'tareweight': this.create.createTemp.tareweight,
  977. 'sumprice': this.create.createTemp.sumprice,
  978. 'licence': this.create.createTemp.licence,
  979. 'pcpde': this.create.createTemp.pcpde,
  980. 'remark': this.create.createTemp.remark,
  981. 'createdate': this.create.createTemp.createdate,
  982. 'createemp': this.create.createTemp.createemp,
  983. 'startweight': this.create.createTemp.startweight,
  984. 'priceold': this.create.createTemp.priceold,
  985. 'pricenew': this.create.createTemp.pricenew,
  986. 'wagonnumber': this.create.createTemp.wagonnumber
  987. }}
  988. if (this.create.createTemp.operateweight !== '' && parseFloat(this.create.createTemp.operateweight) > 0) {
  989. this.requestParam.data[1] = { 'name': 'insertFeedstorageLaid', 'type': 'e', 'parammaps': {
  990. 'operateweight': this.create.createTemp.operateweight,
  991. 'pastureid': this.create.createTemp.pastureid,
  992. 'feedid': this.create.createTemp.feedid,
  993. 'fname': this.create.createTemp.fname,
  994. 'pcpde': this.create.createTemp.pcpde,
  995. 'stockweight': this.create.createTemp.startweight,
  996. 'price': this.create.createTemp.pricenew
  997. }}
  998. }
  999. console.log('点击了新增入库单保存', this.requestParam)
  1000. ExecDataByConfig(this.requestParam).then(response => {
  1001. if (response.msg === 'fail') {
  1002. this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
  1003. } else {
  1004. this.$notify({ title: '', message: '成功', type: 'success', duration: 2000 })
  1005. this.create.dialogFormVisible = false
  1006. this.getList()
  1007. }
  1008. })
  1009. })
  1010. }
  1011. })
  1012. },
  1013. handleRevoke(row){
  1014. console.log('点击了撤销')
  1015. },
  1016. handleSee(row) {
  1017. console.log('点击了查看')
  1018. this.$nextTick(() => {
  1019. this.$refs.createTemp.resetFields()
  1020. })
  1021. this.dialogFull = false
  1022. this.create.dialogStatus = 'see'
  1023. this.create.dialogFormVisible = true
  1024. if (row.providerid == -1) {
  1025. row.providerid = ''
  1026. row.providername = ''
  1027. }
  1028. this.create.createTemp = Object.assign({}, row)
  1029. },
  1030. handleInitial() {
  1031. console.log('点击了初始化库存')
  1032. this.dialogFull = false
  1033. this.initial.dialogStatus = 'initial'
  1034. this.initial.dialogFormVisible = true
  1035. this.getInitialList()
  1036. },
  1037. getInitialList() {
  1038. this.initial.listLoading = true
  1039. GetDataByName(this.initial.getdataListParm).then(response => {
  1040. console.log('table数据', response.data.list)
  1041. if (response.data.list !== null) {
  1042. this.initial.list = response.data.list
  1043. this.initial.pageNum = response.data.pageNum
  1044. this.initial.pageSize = response.data.pageSize
  1045. this.initial.total = response.data.total
  1046. } else {
  1047. this.initial.list = []
  1048. }
  1049. setTimeout(() => {
  1050. this.initial.listLoading = false
  1051. }, 100)
  1052. })
  1053. },
  1054. handleInitialExport() {
  1055. console.log('点击了初始化库存导出')
  1056. const ExcelDatas = [
  1057. {
  1058. tHeader: ['饲料名称', '库存重量'],
  1059. filterVal: ['fname', 'stockweight'],
  1060. tableDatas: this.initial.list,
  1061. sheetName: '初始化库存'
  1062. }
  1063. ]
  1064. json2excel(ExcelDatas, '初始化库存', true, 'xlsx')
  1065. },
  1066. async handleInitialImport(eve) {
  1067. const file = eve.raw
  1068. if (!file) return
  1069. let reader = await upload(file)
  1070. const worker = xlsx.read(reader, { type: 'binary' })
  1071. // 将返回的数据转换为json对象的数据
  1072. reader = xlsx.utils.sheet_to_json(worker.Sheets[worker.SheetNames[0]])
  1073. console.log(reader)
  1074. const arr = []
  1075. reader.forEach(item => {
  1076. const obj = {}
  1077. for (const key in this.initial.character) {
  1078. if (!this.initial.character.hasOwnProperty(key)) break
  1079. let v = this.initial.character[key]
  1080. const text = v.text
  1081. const type = v.type
  1082. v = item[text] || ''
  1083. type === 'string' ? (v = String(v)) : null
  1084. type === 'number' ? (v = Number(v)) : null
  1085. obj[key] = v
  1086. }
  1087. arr.push(obj)
  1088. })
  1089. console.log('导入处理后数据', arr)
  1090. var sum = 0
  1091. for (let i = 0; i < this.initial.list.length; i++) {
  1092. for (let j = 0; j < arr.length; j++) {
  1093. if (this.initial.list[i].fname == arr[j].fname) {
  1094. this.initial.list[i].stockweight = arr[j].stockweight
  1095. sum++
  1096. arr.splice(j, 1)
  1097. }
  1098. }
  1099. }
  1100. console.log(arr)
  1101. for (let i = 0; i < arr.length; i++) {
  1102. this.$set(arr[i], 'msg', '饲料名称与系统不匹配')
  1103. }
  1104. console.log(sum)
  1105. this.$message({ title: '成功', message: '导入成功:' + sum + '条!', type: 'success', duration: 2000 })
  1106. this.$notify({ title: '失败', message: '导入失败:' + arr.length + '条!', type: 'danger', duration: 2000 })
  1107. if (arr.length > 0) {
  1108. const ExcelDatas1 = [
  1109. {
  1110. tHeader: ['饲料名称', '库存重量', '报错信息'],
  1111. filterVal: ['fname', 'stockweight', 'msg'],
  1112. tableDatas: arr,
  1113. sheetName: 'ExcelDatas1'
  1114. }
  1115. ]
  1116. json2excel(ExcelDatas1, '初始化库存报错信息', true, 'xlsx')
  1117. }
  1118. },
  1119. initialData() {
  1120. console.log('点击了初始化库存保存')
  1121. this.isokDisable = true
  1122. setTimeout(() => {
  1123. this.isokDisable = false
  1124. }, 1000)
  1125. var rulesStockweight = /^\d+(\.\d{1,2})?$/
  1126. for (let i = 0; i < this.initial.list.length; i++) {
  1127. if (!rulesStockweight.test(parseFloat(this.initial.list[i].stockweight))) {
  1128. this.$message({ type: 'warning', message: '库存重量不可小于0,且保留俩位小数', duration: 2000 })
  1129. return false
  1130. }
  1131. }
  1132. this.requestParam.common = { 'returnmap': '0' }
  1133. this.requestParam.data = []
  1134. this.requestParam.data[0] = { 'name': 'clearFS', 'type': 'e', 'parammaps': {
  1135. 'pastureid': Cookies.get('pastureid')
  1136. }}
  1137. this.requestParam.data[1] = { 'name': 'insertSpotList', 'resultmaps': { 'list': this.initial.list }}
  1138. this.requestParam.data[1].children = []
  1139. this.requestParam.data[1].children[0] = { 'name': 'insertFeedstorage', 'type': 'e', 'parammaps': {
  1140. pastureid: '@insertSpotList.pastureid',
  1141. feedid: '@insertSpotList.feedid',
  1142. fname: '@insertSpotList.fname',
  1143. pcpde: '@insertSpotList.pcpde',
  1144. stockweight: '@insertSpotList.stockweight',
  1145. price: '@insertSpotList.price'
  1146. }}
  1147. ExecDataByConfig(this.requestParam).then(response => {
  1148. if (response.msg === 'fail') {
  1149. this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
  1150. } else {
  1151. this.$notify({ title: '', message: '成功', type: 'success', duration: 2000 })
  1152. this.create.dialogFormVisible = false
  1153. this.getList()
  1154. }
  1155. })
  1156. },
  1157. // 导出
  1158. handleExport(item) {
  1159. if (item == 1) {
  1160. console.log('点击了导出模板')
  1161. const requestParam = this.requestParam
  1162. const url = process.env.VUE_APP_BASE_API + 'file/导入导出模板/库存管理/入库导入模板.xlsx' // 请求下载文件的地址
  1163. console.log(url)
  1164. axios({
  1165. method: 'GET',
  1166. url: url,
  1167. data: requestParam,
  1168. headers: { token: getToken(), optname: 'insertcustomdoc' },
  1169. responseType: 'blob'
  1170. }).then(res => {
  1171. if (!res) return
  1172. this.percentage = 99
  1173. setTimeout(() => {
  1174. this.isPercentage = false
  1175. }, 2000)
  1176. const blob = new Blob([res.data], {
  1177. type: 'application/octet-stream;charset=utf-8'
  1178. })
  1179. const url = window.URL.createObjectURL(blob)
  1180. const aLink = document.createElement('a')
  1181. aLink.style.display = 'none'
  1182. aLink.href = url
  1183. const docname = '入库管理导入模板.xlsx'
  1184. aLink.setAttribute('download', docname) // 下载的文件
  1185. document.body.appendChild(aLink)
  1186. aLink.click()
  1187. document.body.removeChild(aLink)
  1188. window.URL.revokeObjectURL(url)
  1189. })
  1190. } else {
  1191. console.log('点击了导出数据')
  1192. this.download.getdataListParm.parammaps = this.table.getdataListParm.parammaps
  1193. if (this.download.getdataListParm.parammaps.inputDatetime !== '' && this.download.getdataListParm.parammaps.inputDatetime !== null) {
  1194. this.download.getdataListParm.parammaps.startTime = parseTime(this.download.getdataListParm.parammaps.inputDatetime[0], '{y}-{m}-{d}')
  1195. this.download.getdataListParm.parammaps.stopTime = parseTime(this.download.getdataListParm.parammaps.inputDatetime[1], '{y}-{m}-{d}')
  1196. } else {
  1197. this.download.getdataListParm.parammaps.inputDatetime = ''
  1198. this.download.getdataListParm.parammaps.startTime = ''
  1199. this.download.getdataListParm.parammaps.stopTime = ''
  1200. }
  1201. GetDataByName(this.download.getdataListParm).then(response => {
  1202. if (response.data.list !== null) {
  1203. this.download.list = response.data.list
  1204. } else {
  1205. this.download.list = []
  1206. }
  1207. var excelDatas = [
  1208. {
  1209. tHeader: ['入库日期', '送货单编号', '饲料名称', '供应商', '合同编号', '入库重量(kg)', '单价(元)', '总价', '毛重(kg)', '皮重(kg)', '许可证号', '批号', '创建人', '创建日期', '备注'],
  1210. filterVal: ['laiddate', 'wagonnumber', 'feedname', 'providername', 'contractcode', 'operateweight', 'pricenew', 'sumprice', 'grossweight', 'tareweight', 'licence', 'pcpde', 'createemp', 'createdate', 'remark'],
  1211. tableDatas: this.download.list,
  1212. sheetName: 'Sheet1'
  1213. }
  1214. ]
  1215. json2excel(excelDatas, '入库管理', true, 'xlsx')
  1216. })
  1217. }
  1218. },
  1219. beforeImport(file) {
  1220. const isLt2M = file.size / 1024 / 1024 < 2
  1221. if (!isLt2M) {
  1222. this.$message.error('上传文件大小不能超过 2MB!')
  1223. }
  1224. return isLt2M
  1225. },
  1226. handleImportSuccess(res, file) {
  1227. this.getList()
  1228. if (res.msg === 'ok') {
  1229. this.$message({ title: '成功', message: '导入成功:' + res.data.success + '条!', type: 'success', duration: 2000 })
  1230. if (res.data.err_count > 0) {
  1231. this.$notify({ title: '失败', message: '导入失败:' + res.data.err_count + '条!', type: 'danger', duration: 2000 })
  1232. import('@/vendor/Export2Excel').then(excel => {
  1233. const list1 = res.data.result
  1234. const tHeader = [
  1235. '入库日期', '送货单编号', '饲料名称', '供应商', '合同编号', '入库重量(kg)', '单价(元)', '总价(元)', '毛重(kg)', '皮重(kg)', '许可证号', '批号', '创建人', '创建日期', '备注', '错误信息'
  1236. ]
  1237. const filterVal = [
  1238. '入库日期', '送货单编号', '饲料名称', '供应商', '合同编号', '入库重量(kg)', '单价(元)', '总价(元)', '毛重(kg)', '皮重(kg)', '许可证号', '批号', '创建人', '创建日期', '备注', 'error_msg'
  1239. ]
  1240. const data1 = this.formatJson(filterVal, list1)
  1241. excel.export_json_to_excel({ header: tHeader, data: data1, filename: '入库管理导入报错信息', autoWidth: true, bookType: 'xlsx' })
  1242. })
  1243. }
  1244. } else {
  1245. this.$notify({ title: '失败', message: '上传失败', type: 'danger', duration: 2000 })
  1246. }
  1247. },
  1248. formatJson(filterVal, jsonData) {
  1249. return jsonData.map(v =>
  1250. filterVal.map(j => {
  1251. if (j === 'timestamp') {
  1252. return parseTime(v[j])
  1253. } else {
  1254. return v[j]
  1255. }
  1256. })
  1257. )
  1258. }
  1259. }
  1260. }
  1261. </script>