receive.vue 26 KB

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