index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. <template>
  2. <div class="app-container">
  3. <div class="filter-container">
  4. <el-select v-model="getdataListParm.parammaps.pastureName" placeholder="牧场" class="filter-item" style="width: 120px;">
  5. <el-option
  6. v-for="item in findAllPasture"
  7. :key="item.id"
  8. :label="item.name"
  9. :value="item.name"
  10. />
  11. </el-select>
  12. <el-input v-model="getdataListParm.parammaps.partCode" placeholder="备件编号" style="width: 160px;" class="filter-item" />
  13. <el-input v-model="getdataListParm.parammaps.partName" placeholder="备件名称" style="width: 160px;" class="filter-item" />
  14. <tree-select
  15. class="typeSelect"
  16. :height="150"
  17. :width="250"
  18. size="small"
  19. clearable
  20. :data="parentDept"
  21. :disabled="disabled"
  22. :placeholder="placeholder"
  23. style="display:inline-block;"
  24. :default-props="defaultProps"
  25. :node-key="nodeKey"
  26. :checked-keys="defaultCheckedKeys"
  27. @popoverHide="popoverHide"
  28. />
  29. <el-autocomplete v-model="getdataListParm.parammaps.providerName" clearable value-key="providerName" class="inline-input" :fetch-suggestions="providerSearch" placeholder="供应商" style="width:150px;top:-3px;" @select="handleSelectProvider" />
  30. <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="form_search">搜索</el-button>
  31. </div>
  32. <div class="app-btn" style="height:50px">
  33. <el-button class="filter-item" type="primary" @click="form_add">库存预警设置</el-button>
  34. <!-- <el-button v-waves class="filter-item" type="info" icon="el-icon-download" @click="handleDownloadTemp"> 模板 </el-button>
  35. <el-upload style="display: inline-block;" :headers="headers" :data="uploadData" :action="uploadExcelUrl" :show-file-list="false" :before-upload="beforeImportExcel" :on-success="handleImportExcelSuccess">
  36. <el-button v-waves class="filter-item" type="warning" icon="el-icon-upload2">导入</el-button>
  37. </el-upload>
  38. <el-button class="filter-item" style="margin-left: 10px;" type="success" icon="el-icon-edit" @click="handleDownload">导出</el-button> -->
  39. </div>
  40. <el-table
  41. :key="tableKey"
  42. v-loading="listLoading"
  43. element-loading-text="给我一点时间"
  44. :data="list"
  45. border
  46. fit
  47. highlight-current-row
  48. style="width: 100%;"
  49. :row-style="rowStyle"
  50. :cell-style="cellStyle"
  51. class="elTable"
  52. @selection-change="handleSelectionChange"
  53. @sort-change="tableSort"
  54. >
  55. <el-table-column type="selection" width="55" />
  56. <el-table-column label="序号" align="center" type="index" width="50px">
  57. <template slot-scope="scope">
  58. <span>{{ scope.$index + (pageNum-1) * pageSize + 1 }}</span>
  59. </template>
  60. </el-table-column>
  61. <el-table-column label="备件编号" min-width="140px" align="center">
  62. <template slot-scope="scope">
  63. <span>{{ scope.row.partCode }}</span>
  64. </template>
  65. </el-table-column>
  66. <el-table-column label="备件名称" min-width="140px" align="center">
  67. <template slot-scope="scope">
  68. <span>{{ scope.row.partName }}</span>
  69. </template>
  70. </el-table-column>
  71. <el-table-column label="备件规格" min-width="140px" align="center">
  72. <template slot-scope="scope">
  73. <span>{{ scope.row.specification }}</span>
  74. </template>
  75. </el-table-column>
  76. <el-table-column label="备件类别" min-width="140px" align="center">
  77. <template slot-scope="scope">
  78. <span>{{ scope.row.category }}</span>
  79. </template>
  80. </el-table-column>
  81. <el-table-column label="供应商" min-width="90px" align="center">
  82. <template slot-scope="scope">
  83. <span>{{ scope.row.providerName }}</span>
  84. </template>
  85. </el-table-column>
  86. <el-table-column label="最高库存" sortable prop="maxRepertory" min-width="90px" align="center">
  87. <template slot-scope="scope">
  88. <span>{{ scope.row.maxRepertory }}</span>
  89. </template>
  90. </el-table-column>
  91. <el-table-column label="最低库存" sortable prop="minRepertory" min-width="100px" align="center">
  92. <template slot-scope="scope">
  93. <span>{{ scope.row.minRepertory }}</span>
  94. </template>
  95. </el-table-column>
  96. </el-table>
  97. <pagination
  98. v-show="total>0"
  99. :total="total"
  100. :page.sync="getdataListParm.offset"
  101. :limit.sync="getdataListParm.pagecount"
  102. @pagination="getList"
  103. />
  104. <el-dialog
  105. :title="textMap[dialogStatus]"
  106. :visible.sync="dialogFormVisible"
  107. :close-on-click-modal="false"
  108. width="30%"
  109. >
  110. <div class="app-add">
  111. <b>当前设置条数:{{ number }}条</b>
  112. <el-form
  113. ref="createTemp"
  114. :rules="rules"
  115. :model="createTemp"
  116. label-position="right"
  117. label-width="100px"
  118. style="width: 90%;margin:10px auto 0"
  119. >
  120. <el-row>
  121. <el-col :span="20">
  122. <el-form-item label="最高库存:" prop="maxRepertory">
  123. <el-input ref="maxRepertory" v-model="createTemp.maxRepertory" />
  124. </el-form-item>
  125. </el-col>
  126. </el-row>
  127. <el-row>
  128. <el-col :span="20">
  129. <el-form-item label="最低库存:" prop="minRepertory">
  130. <el-input ref="minRepertory" v-model="createTemp.minRepertory" />
  131. </el-form-item>
  132. </el-col>
  133. </el-row>
  134. </el-form>
  135. <div slot="footer" class="dialog-footer">
  136. <el-button type="primary" :disabled="isokDisable" @click="dialogStatus==='create'?add_dialog_save():add_dialog_save()">保存并关闭</el-button>
  137. <el-button @click="dialogFormVisible = false;">取消并关闭</el-button>
  138. </div>
  139. </div>
  140. </el-dialog>
  141. </div>
  142. </template>
  143. <script>
  144. import waves from '@/directive/waves' // waves directive
  145. import Pagination from '@/components/Pagination' // secondary package based on el-pagination
  146. import { GetDataByName, GetDataByNames, transData, ExecDataByConfig } from '@/api/common'
  147. import TreeSelect from '@/components/TreeSelect'
  148. import Cookies from 'js-cookie'
  149. import { getToken } from '@/utils/auth'
  150. import { parseTime, sortChange } from '@/utils/index.js'
  151. export default {
  152. name: 'SafetyStock',
  153. components: { Pagination, TreeSelect },
  154. directives: { waves },
  155. data() {
  156. return {
  157. rules: {
  158. maxRepertory: [{ type: 'number', required: true, validator: (rule, value, callback) => {
  159. if (!value) {
  160. callback(new Error('不能为空'))
  161. }
  162. setTimeout(() => {
  163. const re = /^[0-9]*[1-9][0-9]*$/ // /^[0-9]*[1-9][0-9]*$/
  164. const rsCheck = re.test(value)
  165. if (!rsCheck) {
  166. callback(new Error('请输入正整数'))
  167. } else {
  168. callback()
  169. }
  170. }, 0)
  171. }, trigger: 'blur' }],
  172. minRepertory: [{ type: 'number', required: true, validator: (rule, value, callback) => {
  173. if (!value) {
  174. callback(new Error('不能为空'))
  175. }
  176. setTimeout(() => {
  177. const re = /^[0-9]*[1-9][0-9]*$/ // /^[0-9]*[1-9][0-9]*$/
  178. const rsCheck = re.test(value)
  179. if (!rsCheck) {
  180. callback(new Error('请输入正整数'))
  181. } else {
  182. callback()
  183. }
  184. }, 0)
  185. }, trigger: 'blur' }]
  186. },
  187. isokDisable: false,
  188. rowStyle: { maxHeight: 50 + 'px', height: 45 + 'px' },
  189. cellStyle: { padding: 0 + 'px' },
  190. findAllPasture: [],
  191. requestParams: [{ name: 'findAllPasture', offset: 0, pagecount: 0, returntype: 'Map', parammaps: { 'id': Cookies.get('pastureid') }}],
  192. parentDept: [],
  193. defaultProps: {
  194. children: 'children',
  195. label: 'partClassNameCode'
  196. },
  197. disabled: false,
  198. placeholder: '请选择备件类别',
  199. nodeKey: 'id',
  200. defaultCheckedKeys: [],
  201. listType: [],
  202. tableKey: 0,
  203. getDeptListParm: { name: 'getpart_classList' },
  204. list: [],
  205. total: 0,
  206. listLoading: true,
  207. getdataListParm: {
  208. name: 'getPRlist',
  209. page: 1,
  210. offset: 1,
  211. pagecount: 50,
  212. returntype: 'Map',
  213. parammaps: {
  214. pastureName: Cookies.get('pasturename'),
  215. partCode: '',
  216. partName: '',
  217. classCode: ''
  218. }
  219. },
  220. textMap: {
  221. create: '库存预警设置'
  222. },
  223. dialogStatus: '',
  224. dialogFormVisible: false,
  225. selectionList: [],
  226. number: 0,
  227. createTemp: {
  228. maxRepertory: '',
  229. minRepertory: ''
  230. },
  231. postDataPramas: {},
  232. requestProvider: {
  233. name: 'getProviderList',
  234. page: 1,
  235. offset: 1,
  236. pagecount: 10,
  237. returntype: 'Map',
  238. parammaps: {}
  239. }
  240. }
  241. },
  242. computed: {
  243. // 设置请求头
  244. headers() {
  245. return {
  246. // 设置token
  247. // eslint-disable-next-line no-undef
  248. token: getToken()
  249. }
  250. },
  251. uploadData() {
  252. return {
  253. name: 'importStockUse',
  254. importParams: '牧场,领用单编号,领用日期,物料编码,品名,规格型号,品牌,计量单位,实发数量,单价,总价,库位,供应商,名称,牧场设备编号,具体用处,领用类型,领用部门,领用人,SignColumn',
  255. sheetname: 'SheetJS'
  256. }
  257. },
  258. // 设置上传地址
  259. uploadExcelUrl() {
  260. // process.env.VUE_APP_BASE_API是服务器的路径,也是axios的基本路径
  261. return process.env.VUE_APP_BASE_API + 'authdata/ImportExcel'
  262. }
  263. },
  264. created() {
  265. this.get_select_list()
  266. this.getList()
  267. this.getTypeList()
  268. },
  269. methods: {
  270. tableSort(column) {
  271. sortChange(column, this.list)
  272. },
  273. providerSearch(queryString, cb) {
  274. console.log('供应商模糊查询输入值', queryString)
  275. this.requestProvider.parammaps['providerName'] = queryString
  276. GetDataByName(this.requestProvider).then(response => {
  277. console.log('供应商模糊查询搜索data', response.data.list)
  278. if (response.data.list !== null) {
  279. cb(response.data.list)
  280. } else {
  281. cb([])
  282. }
  283. })
  284. },
  285. handleSelectProvider(item) {
  286. console.log('供应商模糊查询选中值', item)
  287. },
  288. get_select_list() {
  289. GetDataByNames(this.requestParams).then(response => {
  290. this.findAllPasture = response.data.findAllPasture.list
  291. })
  292. },
  293. getTypeList() {
  294. GetDataByName(this.getDeptListParm).then(response => {
  295. this.listType = response.data
  296. if (response.data.list !== null) {
  297. this.listType = transData(response.data.list, 'id', 'pid', 'children')
  298. console.log(this.listType)
  299. }
  300. this.parentDept = this.listType
  301. })
  302. },
  303. popoverHide(checkedIds, checkedData) {
  304. if (checkedIds !== null) {
  305. console.log(checkedData)
  306. console.log(checkedData.childrens)
  307. if (checkedData.childrens == 0) {
  308. if (checkedIds !== null) {
  309. this.getdataListParm.parammaps.classCode = checkedData.partClassCode
  310. }
  311. } else {
  312. this.defaultCheckedKeys = []
  313. this.getdataListParm.parammaps.classCode = ''
  314. this.$message({
  315. type: 'warning',
  316. message: '请选择详细备件类别'
  317. })
  318. }
  319. } else {
  320. this.defaultCheckedKeys = []
  321. this.getdataListParm.parammaps.classCode = ''
  322. }
  323. },
  324. getList() {
  325. GetDataByName(this.getdataListParm).then(response => {
  326. console.log('table数据', response.data.list)
  327. this.list = response.data.list
  328. this.pageNum = response.data.pageNum
  329. this.pageSize = response.data.pageSize
  330. this.total = response.data.total
  331. setTimeout(() => {
  332. this.listLoading = false
  333. }, 100)
  334. })
  335. },
  336. form_search() {
  337. this.listLoading = true
  338. this.getdataListParm.offset = 1
  339. this.getList()
  340. },
  341. handleSelectionChange(val) {
  342. console.log('选中值', val)
  343. this.selectionList = val
  344. },
  345. resetCreateTemp() {
  346. this.createTemp.maxRepertory = ''
  347. this.createTemp.minRepertory = ''
  348. },
  349. form_add() {
  350. if (this.selectionList.length > 0) {
  351. this.resetCreateTemp()
  352. this.dialogStatus = 'create'
  353. this.dialogFormVisible = true
  354. this.number = this.selectionList.length
  355. } else {
  356. this.$message({
  357. type: 'warning',
  358. message: '请选择备件'
  359. })
  360. }
  361. },
  362. add_dialog_save() {
  363. this.$refs['createTemp'].validate(valid => {
  364. if (valid) {
  365. this.postDataPramas.common = { 'returnmap': '0' }
  366. this.postDataPramas.data = []
  367. this.postDataPramas.data[0] = { 'name': 'insertSpotList', 'resultmaps': { 'list': this.selectionList }}
  368. this.postDataPramas.data[0].children = []
  369. this.postDataPramas.data[0].children[0] = { 'name': 'updatePRMaxMin', 'type': 'e', 'parammaps': {
  370. id: '@insertSpotList.id',
  371. maxRepertory: this.createTemp.maxRepertory,
  372. minRepertory: this.createTemp.minRepertory
  373. }}
  374. ExecDataByConfig(this.postDataPramas).then(response => {
  375. console.log('新增保存发送参数', this.postDataPramas)
  376. if (response.msg === 'fail') {
  377. this.$notify({
  378. title: '保存失败',
  379. message: response.data,
  380. type: 'warning',
  381. duration: 2000
  382. })
  383. } else {
  384. this.dialogFormVisible = false
  385. this.getList()
  386. this.$notify({
  387. title: '',
  388. message: '保存成功',
  389. type: 'success',
  390. duration: 2000
  391. })
  392. }
  393. })
  394. }
  395. })
  396. },
  397. handleDownloadTemp() {
  398. console.log('点击了模板')
  399. },
  400. beforeImportExcel(file) {
  401. const isLt2M = file.size / 1024 / 1024 < 10
  402. if (!isLt2M) {
  403. this.$message.error('上传文件大小不能超过 10MB!')
  404. }
  405. return isLt2M
  406. },
  407. handleImportExcelSuccess(res, file) {
  408. if (res.msg === 'ok') {
  409. this.$message({
  410. title: '成功',
  411. message: '导入成功:' + res.data.success + '条!',
  412. type: 'success',
  413. duration: 2000
  414. })
  415. if (res.data.err_count > 0) {
  416. this.$notify({
  417. title: '失败',
  418. message: '导入失败:' + res.data.err_count + '条!',
  419. type: 'danger',
  420. duration: 2000
  421. })
  422. import('@/vendor/Export2Excel').then(excel => {
  423. const list1 = res.data.result
  424. const tHeader = [
  425. '牧场', '领用单编号', '领用日期', '物料编码', '品名', '规格型号', '品牌', '计量单位', '实发数量', '单价', '总价', '库位', '供应商', '名称', '牧场设备编号', '具体用处', '领用类型', '领用部门', '领用人', 'SignColumn', '报错信息'
  426. ]
  427. const filterVal = [
  428. '牧场', '领用单编号', '领用日期', '物料编码', '品名', '规格型号', '品牌', '计量单位', '实发数量', '单价', '总价', '库位', '供应商', '名称', '牧场设备编号', '具体用处', '领用类型', '领用部门', '领用人', 'SignColumn', 'error_msg'
  429. ]
  430. const data1 = this.formatJson(filterVal, list1)
  431. excel.export_json_to_excel({
  432. header: tHeader,
  433. data: data1,
  434. filename: this.requestParam.parammaps.formType,
  435. autoWidth: true,
  436. bookType: 'xlsx'
  437. })
  438. })
  439. }
  440. } else {
  441. this.$notify({
  442. title: '失败',
  443. message: '上传失败',
  444. type: 'danger',
  445. duration: 2000
  446. })
  447. }
  448. },
  449. formatJsonTemp(filterVal, jsonData) {
  450. return jsonData.map(v =>
  451. filterVal.map(j => {
  452. if (j === 'timestamp') {
  453. return parseTime(v[j])
  454. } else {
  455. return v[j]
  456. }
  457. })
  458. )
  459. },
  460. handleDownload() {
  461. console.log('点击了导出')
  462. }
  463. }
  464. }
  465. </script>