receive.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" size="mini" :inline="true">
  4. <el-form-item label="物料名称" prop="materialName">
  5. <el-input
  6. v-model="queryParams.materialName"
  7. placeholder="请输入物料名称"
  8. clearable
  9. style="width: 240px"
  10. @keyup.enter.native="handleQuery"
  11. />
  12. </el-form-item>
  13. <el-form-item label="只看自己" prop="self">
  14. <el-switch v-model="queryParams.self"></el-switch>
  15. </el-form-item>
  16. <el-form-item label="月/周数据" prop="monthOrWeek">
  17. <el-radio-group v-model="queryParams.monthOrWeek" @change="getList">
  18. <el-radio-button label="1">月</el-radio-button>
  19. <el-radio-button label="2">周</el-radio-button>
  20. </el-radio-group>
  21. </el-form-item>
  22. <el-form-item label="周期" prop="recordDate">
  23. <div v-if="queryParams.monthOrWeek==='1'">
  24. <el-date-picker
  25. v-model="queryParams.date"
  26. type="month"
  27. value-format="yyyy-MM"
  28. placeholder="选择月份"
  29. @change="handleQuery"
  30. clearable>
  31. </el-date-picker>
  32. </div>
  33. <div v-if="queryParams.monthOrWeek==='2'">
  34. <el-date-picker
  35. v-model="queryParams.date"
  36. type="week"
  37. format="yyyy 第 WW 周"
  38. placeholder="选择周"
  39. @change="handleQuery"
  40. clearable>
  41. </el-date-picker>
  42. </div>
  43. </el-form-item>
  44. <el-form-item>
  45. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  46. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  47. </el-form-item>
  48. </el-form>
  49. <el-row :gutter="10" style="margin-bottom: 8px">
  50. <el-col :span="1.5" v-if="queryParams.monthOrWeek==='1'">
  51. <el-button
  52. type="primary"
  53. plain
  54. icon="el-icon-plus"
  55. size="mini"
  56. @click="handleAdd"
  57. v-hasPermi="['material:receive:add']"
  58. >新增
  59. </el-button>
  60. </el-col>
  61. <el-col :span="1.5" v-if="queryParams.monthOrWeek==='1'">
  62. <el-button
  63. type="primary"
  64. plain
  65. icon="el-icon-plus"
  66. size="mini"
  67. :disabled="addList.length===0"
  68. @click="handleSplit"
  69. v-hasPermi="['material:receive:add']"
  70. >周数据
  71. </el-button>
  72. </el-col>
  73. <el-col :span="1.5">
  74. <el-button
  75. plain
  76. icon="el-icon-download"
  77. size="mini"
  78. @click="handleExport"
  79. v-hasPermi="['material:receive:export']"
  80. >导出
  81. </el-button>
  82. </el-col>
  83. </el-row>
  84. <el-table :data="materialList"
  85. ref="materialList"
  86. stripe
  87. border
  88. size="mini"
  89. @selection-change="handleSelectionChange">
  90. <el-table-column type="selection" width="40" v-if="queryParams.monthOrWeek==='1'"/>
  91. <el-table-column label="编号" prop="id" width="80"/>
  92. <el-table-column label="物料名称" prop="materialName" :show-overflow-tooltip="true"/>
  93. <el-table-column label="规格" prop="specification" :show-overflow-tooltip="true"/>
  94. <el-table-column label="品牌/货号" prop="articleNo" :show-overflow-tooltip="true"/>
  95. <el-table-column label="厂商" prop="factory"/>
  96. <el-table-column label="领取量" prop="num" mini-width="80"/>
  97. <el-table-column label="单位" prop="unit" mini-width="80"/>
  98. <el-table-column label="物料类型" mini-width="80">
  99. <template slot-scope="scope">
  100. <el-tag v-if="scope.row.materialType==='1'" type="warning" size="mini">生产</el-tag>
  101. <el-tag v-else type="info" size="mini">非生产</el-tag>
  102. </template>
  103. </el-table-column>
  104. <el-table-column label="领用人" prop="receiveUserName" width="100"/>
  105. <el-table-column label="周期" prop="recordDate" :width="queryParams.monthOrWeek==='1'?100:160"/>
  106. <el-table-column label="操作" align="center" width="130">
  107. <template slot-scope="scope">
  108. <el-button
  109. size="mini"
  110. type="text"
  111. icon="el-icon-edit"
  112. v-if="showEditBtn(scope.row)"
  113. @click="handleUpdate(scope.row)"
  114. v-hasPermi="['material:receive:edit']"
  115. >修改
  116. </el-button>
  117. <el-button
  118. size="mini"
  119. type="text"
  120. icon="el-icon-delete"
  121. @click="handleDelete(scope.row)"
  122. v-hasPermi="['material:receive:delete']"
  123. >删除
  124. </el-button>
  125. </template>
  126. </el-table-column>
  127. </el-table>
  128. <div style="margin-top: 10px;text-align: center">
  129. <el-pagination
  130. background
  131. @size-change="handleSizeChange"
  132. @current-change="handleCurrentChange"
  133. :current-page="queryParams.pageNum"
  134. :page-sizes="[10, 20, 50]"
  135. :page-size="queryParams.pageSize"
  136. layout="total, sizes, prev, pager, next, jumper"
  137. :total="total">
  138. </el-pagination>
  139. </div>
  140. <!-- 添加物料配置对话框 -->
  141. <el-dialog :title="title" :visible.sync="open" @close="dialogClose" width="80%" append-to-body
  142. :close-on-click-modal="false">
  143. <el-form ref="addForm" :model="addForm" :rules="rules" size="mini" inline>
  144. <el-row>
  145. <el-col :span="22">
  146. <el-form-item label="数据周期">
  147. <div v-if="addForm.monthOrWeek==='1'">
  148. <el-date-picker
  149. v-model="addForm.date"
  150. type="month"
  151. value-format="yyyy-MM"
  152. placeholder="选择月份"
  153. :picker-options="getPickerOptions('month')"
  154. clearable>
  155. </el-date-picker>
  156. </div>
  157. <div v-else>
  158. <el-date-picker
  159. v-model="addForm.date"
  160. type="week"
  161. format="yyyy 第 WW 周"
  162. placeholder="选择周"
  163. :picker-options="getPickerOptions('week')"
  164. clearable>
  165. </el-date-picker>
  166. </div>
  167. </el-form-item>
  168. </el-col>
  169. <el-col :span="2">
  170. <el-form-item>
  171. <el-button icon="el-icon-plus" @click="addRow">添加</el-button>
  172. </el-form-item>
  173. </el-col>
  174. </el-row>
  175. </el-form>
  176. <el-table :data="addList" class="add-table" border size="mini">
  177. <el-table-column label="物料名称" prop="materialName">
  178. <template slot-scope="scope">
  179. <el-input v-model="scope.row.materialName" size="mini" placeholder="请输入物料名称"
  180. :disabled="addForm.monthOrWeek==='2'"/>
  181. </template>
  182. </el-table-column>
  183. <el-table-column label="规格" prop="specification">
  184. <template slot-scope="scope">
  185. <el-input v-model="scope.row.specification" size="mini" placeholder="请输入物料规格"
  186. :disabled="addForm.monthOrWeek==='2'"/>
  187. </template>
  188. </el-table-column>
  189. <el-table-column label="品牌/货号" prop="articleNo">
  190. <template slot-scope="scope">
  191. <el-input v-model="scope.row.articleNo" size="mini" placeholder="请输入品牌/货号"
  192. :disabled="addForm.monthOrWeek==='2'"/>
  193. </template>
  194. </el-table-column>
  195. <el-table-column label="厂商" prop="factory">
  196. <template slot-scope="scope">
  197. <el-input v-model="scope.row.factory" size="mini" placeholder="请输入厂商"
  198. :disabled="addForm.monthOrWeek==='2'"/>
  199. </template>
  200. </el-table-column>
  201. <el-table-column label="单位" prop="unit" width="120px">
  202. <template slot-scope="scope">
  203. <el-input v-model="scope.row.unit" size="mini" placeholder="请输入单位" :disabled="addForm.monthOrWeek==='2'"
  204. style="width: 100%"/>
  205. </template>
  206. </el-table-column>
  207. <el-table-column label="价格" prop="price" width="120px">
  208. <template slot-scope="scope">
  209. <el-input v-model="scope.row.price" size="mini" placeholder="请输入单价" :disabled="addForm.monthOrWeek==='2'"
  210. style="width: 100%"/>
  211. </template>
  212. </el-table-column>
  213. <el-table-column label="领取量" prop="num" width="100px">
  214. <template slot-scope="scope">
  215. <el-input-number v-model="scope.row.num" size="mini" controls-position="right" :min="0"
  216. placeholder="请输入领取量" style="width: 100%"/>
  217. </template>
  218. </el-table-column>
  219. <el-table-column label="物料类型" prop="materialType" width="100px">
  220. <template slot-scope="scope">
  221. <el-select v-model="scope.row.materialType" size="mini" :disabled="addForm.monthOrWeek==='2'"
  222. style="width: 100%">
  223. <el-option label="生产" value="1"></el-option>
  224. <el-option label="非生产" value="2"></el-option>
  225. </el-select>
  226. </template>
  227. </el-table-column>
  228. <el-table-column label="用于项目" prop="projectId" width="120px">
  229. <template slot-scope="scope">
  230. <el-select v-model="scope.row.projectId" size="mini" :disabled="addForm.monthOrWeek==='2'"
  231. style="width: 100%">
  232. <el-option label="项目1" value="1"></el-option>
  233. <el-option label="项目2" value="2"></el-option>
  234. <el-option label="其他" value="0"></el-option>
  235. </el-select>
  236. </template>
  237. </el-table-column>
  238. <el-table-column label="备注">
  239. <template slot-scope="scope">
  240. <el-input v-model="scope.row.remark" size="mini" type="textarea" autosize/>
  241. </template>
  242. </el-table-column>
  243. <el-table-column width="50">
  244. <template slot-scope="scope">
  245. <el-button
  246. size="mini"
  247. icon="el-icon-delete"
  248. @click="deleteRow(scope.row)"
  249. >
  250. </el-button>
  251. </template>
  252. </el-table-column>
  253. </el-table>
  254. <div slot="footer" class="dialog-footer">
  255. <el-button type="primary" @click="submitForm" size="mini">确 定</el-button>
  256. <el-button @click="cancel" size="mini">取 消</el-button>
  257. </div>
  258. </el-dialog>
  259. <!-- 修改物料配置对话框 -->
  260. <el-dialog title="修改" :visible.sync="editOpen" @close="dialogClose" width="500px" append-to-body
  261. :close-on-click-modal="false">
  262. <el-form ref="editForm" :model="editForm" :rules="rules" size="mini" label-width="100px">
  263. <el-form-item label="物料名称" prop="materialName">
  264. <el-input v-model="editForm.materialName" placeholder="请输入物料名称" :disabled="editForm.monthOrWeek==='2'"/>
  265. </el-form-item>
  266. <el-form-item label="物料规格" prop="specification">
  267. <el-input v-model="editForm.specification" placeholder="请输入物料规格" :disabled="editForm.monthOrWeek==='2'"/>
  268. </el-form-item>
  269. <el-form-item label="品牌/货号" prop="articleNo">
  270. <el-input v-model="editForm.articleNo" placeholder="请输入品牌/货号" :disabled="editForm.monthOrWeek==='2'"/>
  271. </el-form-item>
  272. <el-form-item label="厂商" prop="factory">
  273. <el-input v-model="editForm.factory" placeholder="请输入厂商" :disabled="editForm.monthOrWeek==='2'"/>
  274. </el-form-item>
  275. <el-form-item label="单位" prop="unit">
  276. <el-input v-model="editForm.unit" placeholder="请输入单位" :disabled="editForm.monthOrWeek==='2'"/>
  277. </el-form-item>
  278. <el-form-item label="领取量" prop="num">
  279. <el-input-number v-model="editForm.num" controls-position="right" :min="0" placeholder="请输入领取量"/>
  280. </el-form-item>
  281. <el-form-item label="物料类型" prop="materialType">
  282. <el-radio-group v-model="editForm.materialType" :disabled="editForm.monthOrWeek==='2'">
  283. <el-radio label="1">生产</el-radio>
  284. <el-radio label="2">非生产</el-radio>
  285. </el-radio-group>
  286. </el-form-item>
  287. <el-form-item label="备注">
  288. <el-input v-model="editForm.remark" type="textarea"/>
  289. </el-form-item>
  290. </el-form>
  291. <div slot="footer" class="dialog-footer">
  292. <el-button type="primary" @click="submitEditForm">确 定</el-button>
  293. <el-button @click="cancel">取 消</el-button>
  294. </div>
  295. </el-dialog>
  296. </div>
  297. </template>
  298. <script>
  299. import {
  300. listMaterial,
  301. getMaterial,
  302. delMaterial,
  303. addMaterial,
  304. updateMaterial,
  305. exportMaterial
  306. } from "@/api/material/material";
  307. import DateUtil from "@/utils/date"
  308. export default {
  309. name: "Receive",
  310. data() {
  311. return {
  312. // 总条数
  313. total: 0,
  314. // 物料表格数据
  315. materialList: [],
  316. // 弹出层标题
  317. title: "",
  318. // 是否显示弹出层
  319. open: false,
  320. // 查询参数
  321. queryParams: {
  322. pageNum: 1,
  323. pageSize: 10,
  324. materialName: undefined,
  325. factory: undefined,
  326. self: false,
  327. monthOrWeek: "1",
  328. date: undefined
  329. },
  330. // 表单参数
  331. addForm: {
  332. date: undefined,
  333. monthOrWeek: undefined,
  334. },
  335. addList: [],
  336. editOpen: false,
  337. editForm: {
  338. id: undefined,
  339. parentId: undefined,
  340. materialName: undefined,
  341. specification: undefined,
  342. articleNo: undefined,
  343. factory: undefined,
  344. unit: undefined,
  345. num: 0,
  346. materialType: undefined,
  347. monthOrWeek: undefined,
  348. remark: undefined
  349. },
  350. // 表单校验
  351. rules: {
  352. materialName: [
  353. {required: true, message: "物料名称不能为空", trigger: "blur"}
  354. ],
  355. specification: [
  356. {required: true, message: "物料规格不能为空", trigger: "blur"}
  357. ],
  358. articleNo: [
  359. {required: true, message: "品牌/货号不能为空", trigger: "blur"}
  360. ],
  361. factory: [
  362. {required: true, message: "厂商不能为空", trigger: "blur"}
  363. ],
  364. unit: [
  365. {required: true, message: "单位不能为空", trigger: "blur"}
  366. ],
  367. num: [
  368. {required: true, message: "领取量不能为空", trigger: "blur"}
  369. ],
  370. materialType: [
  371. {required: true, message: "物料类型不能为空", trigger: "change"}
  372. ],
  373. monthOrWeek: [
  374. {required: true, message: "月/周数据不能为空", trigger: "change"}
  375. ]
  376. }
  377. };
  378. },
  379. created() {
  380. this.getList();
  381. },
  382. methods: {
  383. /** 查询物料列表 */
  384. getList() {
  385. listMaterial(this.queryParams).then(res => {
  386. this.materialList = res.data.records;
  387. this.total = res.data.total;
  388. })
  389. },
  390. // 取消按钮
  391. cancel() {
  392. this.open = false;
  393. this.editOpen = false;
  394. this.reset();
  395. },
  396. // 对话框关闭回调
  397. dialogClose() {
  398. this.open = false;
  399. this.editOpen = false;
  400. this.reset();
  401. },
  402. // 表单重置
  403. reset() {
  404. this.addForm = {
  405. date: undefined,
  406. monthOrWeek: undefined,
  407. };
  408. this.addList = []
  409. this.$refs.materialList.clearSelection();
  410. this.resetForm("addForm");
  411. this.editForm = {
  412. id: undefined,
  413. parentId: undefined,
  414. materialName: undefined,
  415. specification: undefined,
  416. articleNo: undefined,
  417. factory: undefined,
  418. unit: undefined,
  419. num: 0,
  420. materialType: undefined,
  421. monthOrWeek: undefined,
  422. remark: undefined
  423. }
  424. this.resetForm("editForm");
  425. },
  426. /** 搜索按钮操作 */
  427. handleQuery() {
  428. this.queryParams.pageNum = 1;
  429. this.queryParams.pageSize = 10;
  430. this.getList();
  431. },
  432. /** 重置按钮操作 */
  433. resetQuery() {
  434. this.$refs.queryForm.resetFields();
  435. this.handleQuery();
  436. },
  437. handleSelectionChange(val) {
  438. let temp = _.cloneDeep(val)
  439. this.addList = temp.map(item => {
  440. item.parentId = item.id
  441. item.num = undefined
  442. item.id = undefined
  443. return item
  444. })
  445. },
  446. handleSizeChange(val) {
  447. this.pageSize = val;
  448. this.getList();
  449. },
  450. handleCurrentChange(val) {
  451. this.pageNum = val;
  452. this.getList();
  453. },
  454. getPickerOptions(type) {
  455. if (type === 'month') {
  456. return {
  457. disabledDate: time => time.getTime() < DateUtil.unix(DateUtil.afterMonth()) * 1000
  458. }
  459. }
  460. if (type === 'week') {
  461. let time1 = DateUtil.unix(this.addForm.date) * 1000
  462. let time2 = DateUtil.unix(DateUtil.afterWeek()) * 1000
  463. let limitTime = time1 > time2 ? time1 : time2;
  464. return {
  465. disabledDate: time => time.getTime() < limitTime
  466. }
  467. }
  468. },
  469. showEditBtn(row) {
  470. if (row.monthOrWeek === '1') {
  471. if (DateUtil.getMinutes() < DateUtil.getMinutes(DateUtil.day(DateUtil.month() + '25'))) {
  472. return DateUtil.unix(row.recordDate) >= DateUtil.unix(DateUtil.afterMonth())
  473. } else {
  474. return DateUtil.unix(row.recordDate) >= DateUtil.unix(DateUtil.afterMonth())
  475. }
  476. } else {
  477. let split = row.recordDate.split("~");
  478. let date = split[0];
  479. let minutes = DateUtil.unix(date);
  480. let minutes1 = DateUtil.unix(DateUtil.afterWeek());
  481. return minutes >= minutes1
  482. }
  483. },
  484. /** 新增按钮操作 */
  485. handleAdd() {
  486. this.reset();
  487. this.addForm.monthOrWeek = '1'
  488. this.title = "添加月物料计划";
  489. this.addList.push({
  490. id: undefined,
  491. materialName: undefined,
  492. specification: undefined,
  493. articleNo: undefined,
  494. factory: undefined,
  495. unit: undefined,
  496. num: 0,
  497. materialType: undefined,
  498. monthOrWeek: '1',
  499. remark: undefined
  500. })
  501. this.open = true;
  502. },
  503. addRow() {
  504. this.addList.push({
  505. id: undefined,
  506. materialName: undefined,
  507. specification: undefined,
  508. articleNo: undefined,
  509. factory: undefined,
  510. unit: undefined,
  511. num: 0,
  512. price: 0,
  513. projectId: undefined,
  514. materialType: undefined,
  515. monthOrWeek: '1',
  516. remark: undefined
  517. })
  518. },
  519. deleteRow(row) {
  520. if (this.addList.length === 1) {
  521. this.addList = [
  522. {
  523. id: undefined,
  524. materialName: undefined,
  525. specification: undefined,
  526. articleNo: undefined,
  527. factory: undefined,
  528. unit: undefined,
  529. num: 0,
  530. materialType: undefined,
  531. monthOrWeek: '1',
  532. remark: undefined
  533. }
  534. ]
  535. return
  536. }
  537. let index = this.addList.indexOf(row);
  538. this.addList.splice(index, 1)
  539. },
  540. handleExport() {
  541. exportMaterial(this.queryParams)
  542. },
  543. /** 周数据填报操作 */
  544. handleSplit() {
  545. this.addForm.id = undefined;
  546. this.addForm.monthOrWeek = '2'
  547. this.title = "添加周物料计划";
  548. this.open = true;
  549. },
  550. /** 修改按钮操作 */
  551. handleUpdate(row) {
  552. this.editForm = row
  553. this.editOpen = true
  554. },
  555. /** 提交按钮 */
  556. submitForm() {
  557. this.$refs["addForm"].validate(valid => {
  558. if (valid) {
  559. let data = {
  560. date: this.addForm.date,
  561. monthOrWeek: this.addForm.monthOrWeek,
  562. addList: this.addList
  563. }
  564. addMaterial(data).then(res => {
  565. this.$message.success("添加成功");
  566. this.open = false;
  567. this.getList();
  568. });
  569. }
  570. });
  571. },
  572. submitEditForm() {
  573. this.$refs["editForm"].validate(valid => {
  574. if (valid) {
  575. updateMaterial(this.editForm).then(res => {
  576. this.$message.success("修改成功");
  577. this.editOpen = false;
  578. this.getList();
  579. });
  580. }
  581. });
  582. },
  583. /** 删除按钮操作 */
  584. handleDelete(row) {
  585. this.$confirm('是否确认删除编号为"' + row.id + '"的数据项?').then(() => {
  586. return delMaterial(row.id);
  587. }).then(() => {
  588. this.getList();
  589. this.$message.success("删除成功");
  590. }).catch(() => {
  591. });
  592. },
  593. }
  594. };
  595. </script>
  596. <style scoped lang="scss">
  597. .add-table::v-deep.el-table .cell {
  598. padding-left: 2px;
  599. padding-right: 2px;
  600. }
  601. .add-table::v-deep.el-table th.el-table__cell > .cell {
  602. padding-left: 5px;
  603. padding-right: 5px;
  604. }
  605. </style>