add.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. <template>
  2. <el-dialog
  3. top="5vh"
  4. :visible.sync="visible"
  5. :title="isView ? '查看收发明细表明细' : '选择收发明细表明细'"
  6. width="90vw"
  7. >
  8. <el-card shadow="never">
  9. <!-- 数据表格 -->
  10. <div>
  11. <el-form
  12. label-position="left"
  13. class="ele-form-search"
  14. :model="formData"
  15. :rules="rules"
  16. @keyup.enter.native="search"
  17. @submit.native.prevent
  18. >
  19. <el-row :gutter="15">
  20. <el-col :span="5">
  21. <el-form-item label-width="60px" label="编码:" prop="code">
  22. <el-input
  23. disabled
  24. v-model="formData.code"
  25. placeholder="请输入"
  26. ></el-input>
  27. </el-form-item>
  28. </el-col>
  29. <el-col :span="5">
  30. <el-form-item label-width="60px" label="名称:" prop="name">
  31. <el-input
  32. :disabled="isView"
  33. v-model="formData.name"
  34. placeholder="请输入"
  35. ></el-input>
  36. </el-form-item>
  37. </el-col>
  38. <el-col :span="7">
  39. <el-form-item label-width="90px" label="起止时间:" prop="time">
  40. <el-date-picker
  41. :disabled="isView"
  42. style="width: 100%"
  43. class="w100"
  44. size="small"
  45. v-model="formData.time"
  46. type="daterange"
  47. range-separator="至"
  48. start-placeholder="开始日期"
  49. end-placeholder="结束日期"
  50. value-format="yyyy-MM-dd"
  51. :picker-options="pickerOptions"
  52. ></el-date-picker>
  53. </el-form-item>
  54. </el-col>
  55. <el-col :span="4">
  56. <el-form-item label-width="60px" label="关键词:" prop="keyWord">
  57. <el-input
  58. :disabled="isView"
  59. v-model="formData.keyWord"
  60. placeholder="请输入关键词"
  61. ></el-input>
  62. </el-form-item>
  63. </el-col>
  64. <el-col v-if="!isView" :span="3">
  65. <div class="ele-form-actions">
  66. <el-button
  67. type="primary"
  68. icon="el-icon-search"
  69. class="ele-btn-icon"
  70. @click="search"
  71. size="small"
  72. >
  73. 查询
  74. </el-button>
  75. <el-button
  76. @click="reset"
  77. icon="el-icon-refresh-left"
  78. size="small"
  79. type="primary"
  80. >重置</el-button
  81. >
  82. </div>
  83. </el-col>
  84. </el-row>
  85. </el-form>
  86. </div>
  87. <ele-pro-table
  88. ref="table"
  89. class="table"
  90. :needPage="!isView"
  91. :columns="columns"
  92. :datasource="datasource"
  93. height="calc(100vh - 405px)"
  94. full-height="calc(100vh - 116px)"
  95. tool-class="ele-toolbar-form"
  96. >
  97. <!-- 状态 -->
  98. <!-- <template v-slot:verifyStatus="{ row }">
  99. <span :class="status[row.verifyStatus].class">
  100. {{ status[row.verifyStatus].label }}
  101. </span>
  102. </template> -->
  103. <template v-slot:bizType="{ row }">
  104. {{ handleBizType(row.bizType, row.type) }}
  105. </template>
  106. <template v-slot:assetType="{ row }">
  107. {{ handleAssetType(row.extInfo.assetType) }}
  108. </template>
  109. </ele-pro-table>
  110. </el-card>
  111. <div slot="footer" class="dialog-footer" style="margin-right: 2%">
  112. <el-button
  113. v-if="!isView"
  114. size="small"
  115. @click="downLoad"
  116. :loading="loading"
  117. type="primary"
  118. >提交并导出</el-button
  119. >
  120. <el-button v-else size="small" @click="visible = false" type="primary"
  121. >确定</el-button
  122. >
  123. <el-button size="small" @click="visible = false">关闭</el-button>
  124. </div>
  125. </el-dialog>
  126. </template>
  127. <script>
  128. import { getCode } from '@/api/codeManagement/index.js';
  129. import ItemSearch from './components/item-search.vue';
  130. import { sendReceiveExcel } from '@/api/warehouseManagement/statisticalReports';
  131. import storageApi from '@/api/warehouseManagement';
  132. import { allCategoryLevel } from '@/api/classifyManage';
  133. import {
  134. warehousingType,
  135. sceneState,
  136. outputSceneState,
  137. auditStatus,
  138. useDict
  139. } from '@/utils/dict/index';
  140. export default {
  141. components: { ItemSearch },
  142. data() {
  143. return {
  144. auditStatus,
  145. outputSceneState,
  146. warehousingType,
  147. sceneState,
  148. status: [
  149. { label: '未审核', class: 'ele-text-info' },
  150. { label: '审核中', class: 'ele-text-primary' },
  151. { label: '审核通过', class: 'ele-text-success' },
  152. { label: '驳回', class: 'ele-text-danger' }
  153. ],
  154. loading: false,
  155. isView: false,
  156. formData: {
  157. code: '',
  158. name: '',
  159. time: [],
  160. status: 2,
  161. keyWord: ''
  162. },
  163. // 表单验证规则
  164. rules: {
  165. name: [
  166. { required: true, message: '请输入库存余额名称', trigger: 'blur' }
  167. ],
  168. time: [
  169. { required: true, message: '请选择起止时间', trigger: 'change' }
  170. ]
  171. },
  172. pickerOptions: {
  173. shortcuts: [
  174. {
  175. text: '最近一周',
  176. onClick(picker) {
  177. const end = new Date();
  178. const start = new Date();
  179. start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
  180. picker.$emit('pick', [start, end]);
  181. }
  182. },
  183. {
  184. text: '最近一个月',
  185. onClick(picker) {
  186. const end = new Date();
  187. const start = new Date();
  188. start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
  189. picker.$emit('pick', [start, end]);
  190. }
  191. },
  192. {
  193. text: '最近三个月',
  194. onClick(picker) {
  195. const end = new Date();
  196. const start = new Date();
  197. start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
  198. picker.$emit('pick', [start, end]);
  199. }
  200. },
  201. {
  202. text: '最近一年',
  203. onClick(picker) {
  204. const end = new Date();
  205. const start = new Date();
  206. start.setTime(start.getTime() - 3600 * 1000 * 24 * 365);
  207. picker.$emit('pick', [start, end]);
  208. }
  209. }
  210. ]
  211. },
  212. visible: false
  213. };
  214. },
  215. computed: {
  216. // 表格列配置
  217. columns() {
  218. let arr = [
  219. {
  220. type: 'index',
  221. label: '序号',
  222. width: 50,
  223. align: 'center'
  224. },
  225. {
  226. prop: 'bizNo',
  227. label: '单号',
  228. align: 'center',
  229. slot: 'bizNo',
  230. showOverflowTooltip: true,
  231. width: 150
  232. },
  233. {
  234. prop: 'bizType',
  235. slot: 'bizType',
  236. label: '出入库类型',
  237. align: 'center',
  238. showOverflowTooltip: true,
  239. width: 150
  240. },
  241. {
  242. prop: 'assetType',
  243. slot: 'assetType',
  244. label: '物品类型',
  245. align: 'center',
  246. showOverflowTooltip: true,
  247. width: 150
  248. },
  249. {
  250. prop: 'categoryNames',
  251. label: '物品名称',
  252. align: 'center',
  253. showOverflowTooltip: true,
  254. width: 150
  255. },
  256. {
  257. prop: 'categoryCodes',
  258. label: '物品编码',
  259. align: 'center',
  260. showOverflowTooltip: true,
  261. width: 150
  262. },
  263. {
  264. prop: 'sourceBizNo',
  265. label: '来源单据',
  266. align: 'center',
  267. showOverflowTooltip: true
  268. },
  269. {
  270. prop: 'createUserName',
  271. label: '操作人',
  272. align: 'center',
  273. showOverflowTooltip: true
  274. },
  275. {
  276. width: 160,
  277. prop: 'storageTime',
  278. label: '出入库时间',
  279. align: 'center',
  280. showOverflowTooltip: true
  281. },
  282. {
  283. prop: 'verifyName',
  284. label: '审核人',
  285. align: 'center',
  286. showOverflowTooltip: true
  287. }
  288. // {
  289. // prop: 'verifyStatus',
  290. // label: '状态',
  291. // align: 'center',
  292. // slot: 'verifyStatus',
  293. // showOverflowTooltip: true,
  294. // width: 100
  295. // }
  296. ];
  297. return arr.filter((item) => item != '');
  298. },
  299. clientEnvironmentId() {
  300. return this.$store.state.user.info.clientEnvironmentId;
  301. }
  302. },
  303. created() {
  304. this.getTypeList();
  305. },
  306. methods: {
  307. async getTypeList() {
  308. const { data } = await allCategoryLevel();
  309. this.codeList = data.map((item) => {
  310. return { dictCode: item.id, dictValue: item.name };
  311. });
  312. },
  313. handleAssetType(r) {
  314. const code = this.codeList.find((item) => item.dictCode == r);
  315. return code?.dictValue;
  316. },
  317. handleBizType(code, type) {
  318. if (type == 1) {
  319. // 入库
  320. for (const key in this.sceneState) {
  321. if (this.sceneState[key].code == code) {
  322. return this.sceneState[key].label;
  323. }
  324. }
  325. } else {
  326. // 出库
  327. for (const key in this.outputSceneState) {
  328. if (this.outputSceneState[key].code == code) {
  329. return this.outputSceneState[key].label;
  330. }
  331. }
  332. }
  333. },
  334. // 获取时间函数
  335. getDate(date) {
  336. console.log(date);
  337. let obj = {
  338. year: date.getFullYear(), //获取完整的年份(4位)
  339. month: date.getMonth() + 1, //获取当前月份(0-11,0代表1月)
  340. strDate: date.getDate() // 获取当前日(1-31)
  341. };
  342. Object.keys(obj).forEach((key) => {
  343. if (obj[key] < 10) obj[key] = `0${obj[key]}`;
  344. });
  345. return `${obj.year}-${obj.month}-${obj.strDate}`;
  346. },
  347. downLoad() {
  348. if (!this.formData.name) {
  349. return this.$message.error('请输入名称');
  350. }
  351. if (this.formData.time.length <= 0) {
  352. return this.$message.error('请选择时间');
  353. }
  354. this.loading = true;
  355. const params = Object.assign({}, this.formData);
  356. if (params.time?.length) {
  357. params.startTime = params.time[0];
  358. params.endTime = params.time[1];
  359. }
  360. delete params.time;
  361. sendReceiveExcel(params).then((data) => {
  362. try {
  363. let objectUrl1 = window.URL.createObjectURL(new Blob([data]));
  364. let elink = document.createElement('a');
  365. elink.setAttribute(
  366. 'download',
  367. decodeURI(decodeURI('收发明细表.xlsx'))
  368. );
  369. elink.style.display = 'none';
  370. elink.href = objectUrl1;
  371. document.body.appendChild(elink);
  372. elink.click();
  373. document.body.removeChild(elink);
  374. window.URL.revokeObjectURL(elink.href);
  375. this.loading = false;
  376. this.visible = false;
  377. this.$emit('reload');
  378. } catch (err) {
  379. this.$message.error('导出失败,请联系管理员!');
  380. }
  381. });
  382. },
  383. async open(isView, row) {
  384. console.log(row);
  385. if (isView) {
  386. this.tableList = row.info.map((item) => {
  387. return {
  388. ...item,
  389. startTime: this.getDate(new Date(Number(item.startTime)))
  390. };
  391. });
  392. this.formData.code = row.code;
  393. this.formData.name = row.name;
  394. this.formData.status = 2;
  395. this.formData.time =
  396. row.startTime && row.endTime ? [row.startTime, row.endTime] : [];
  397. this.formData.keyWord = row.keyWord;
  398. } else {
  399. this.tableList = [];
  400. this.formData = {
  401. code: await getCode('statistics_log_code'),
  402. name: '',
  403. status: 2,
  404. time: [],
  405. keyWord: ''
  406. };
  407. }
  408. this.isView = isView;
  409. this.visible = true;
  410. this.$nextTick(() => {
  411. this.$refs.table.reload();
  412. });
  413. },
  414. /* 表格数据源 */
  415. async datasource({ page, limit, where, order }) {
  416. if (this.isView) {
  417. return this.tableList;
  418. } else {
  419. const params = Object.assign({}, this.formData);
  420. if (params.time?.length) {
  421. params.startTime = params.time[0];
  422. params.endTime = params.time[1];
  423. }
  424. delete params.time;
  425. const data = await storageApi.getInboundList({
  426. ...params,
  427. ...where,
  428. ...order,
  429. pageNum: page,
  430. size: limit
  431. });
  432. console.log(data);
  433. this.tableList = data;
  434. return data;
  435. }
  436. },
  437. search() {
  438. this.$refs.table.reload();
  439. },
  440. reset() {
  441. this.formData.time = [];
  442. this.formData.keyWord = '';
  443. this.search();
  444. }
  445. }
  446. };
  447. </script>
  448. <style lang="scss" scoped>
  449. #inventoryBalance {
  450. height: 100%;
  451. width: 100%;
  452. padding: 10px;
  453. box-sizing: border-box;
  454. .ele-form-actions {
  455. display: flex;
  456. justify-content: flex-end;
  457. }
  458. }
  459. </style>