apply_form.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  1. <template>
  2. <div class="detail-container">
  3. <el-page-header @back="goBack" :content="listItem ? '编辑':'新增'"></el-page-header>
  4. <div class="main-title">
  5. <div class="title">发货申请单信息</div>
  6. </div>
  7. <el-form ref="mainForm" :model="mainForm" :rules="mainFormRules" label-width="90px" size="small" label-position="right">
  8. <el-row :gutter="20">
  9. <el-col :xs="24" :sm="12" :lg="8">
  10. <el-form-item label="订单号" prop="id">
  11. <el-input v-model="mainForm.orderNum" placeholder="系统自动生成" readonly></el-input>
  12. </el-form-item>
  13. </el-col>
  14. <el-col :xs="24" :sm="12" :lg="8" style="height: 51px;">
  15. <el-form-item label="单据日期" prop="date">
  16. <el-date-picker
  17. v-model="mainForm.date"
  18. type="date"
  19. value-format="yyyy-MM-dd"
  20. style="width: 100%;"
  21. placeholder="选择日期">
  22. </el-date-picker>
  23. </el-form-item>
  24. </el-col>
  25. <el-col :xs="24" :sm="12" :lg="8">
  26. <el-form-item label="制单人" prop="createMan">
  27. <el-input v-model="mainForm.createMan" readonly></el-input>
  28. </el-form-item>
  29. </el-col>
  30. <el-col :xs="24" :sm="24" :lg="16">
  31. <el-form-item label="备注" prop="remark">
  32. <el-input v-model="mainForm.remark" placeholder="请输入备注"></el-input>
  33. </el-form-item>
  34. </el-col>
  35. <el-col :xs="24" :sm="12" :lg="8">
  36. <el-form-item label="经销商" prop="jxsNum">
  37. <el-select v-model="mainForm.jxsNum" placeholder="请选择经销商" style="width: 100%;" disabled>
  38. <el-option :label="item.name" :value="item.id" v-for="(item, index) in dealerList" :key="index"></el-option>
  39. </el-select>
  40. </el-form-item>
  41. </el-col>
  42. <el-col :xs="24" :sm="8" :lg="8">
  43. <el-form-item label="附件" prop="fileUrl">
  44. <fileUpload :fileList="fileList" />
  45. </el-form-item>
  46. </el-col>
  47. </el-row>
  48. </el-form>
  49. <div class="main-title">
  50. <div class="title">货品信息</div>
  51. <div>
  52. <span style="font-size: 14px; margin-right: 10px">仓库</span>
  53. <el-select v-model="screenForm.warehouse" placeholder="请选择发货仓库" size="small" filterable clearable :disabled="goodsList.length > 0">
  54. <el-option :label="item.name" :value="item.id" v-for="(item, index) in warehouseList" :key="index"></el-option>
  55. </el-select>
  56. <el-divider direction="vertical"></el-divider>
  57. <el-button type="primary" size="small" icon="el-icon-plus" @click="openDialog">添加引用</el-button>
  58. </div>
  59. </div>
  60. <div class="table" style="margin-top: 20px">
  61. <el-table :data="goodsList" element-loading-text="Loading" border fit highlight-current-row stripe max-height="400">
  62. <el-table-column align="center" label="序号" type="index" width="50"></el-table-column>
  63. <el-table-column align="center" label="引用单号" prop="orderId" min-width="180" show-overflow-tooltip></el-table-column>
  64. <el-table-column align="center" label="销售类型" prop="saleTypeName" min-width="100" show-overflow-tooltip></el-table-column>
  65. <el-table-column align="center" label="产品名称" prop="materialName" min-width="160" show-overflow-tooltip></el-table-column>
  66. <el-table-column align="center" label="规格型号" prop="specification" min-width="160" show-overflow-tooltip></el-table-column>
  67. <el-table-column align="center" label="单位" prop="unit" min-width="100" show-overflow-tooltip></el-table-column>
  68. <el-table-column align="center" label="数量" prop="qty" min-width="80" show-overflow-tooltip></el-table-column>
  69. <el-table-column align="center" label="申请数量" prop="invoiceNum" min-width="110" show-overflow-tooltip>
  70. <template slot-scope="scope">
  71. <el-input v-model="scope.row.invoiceNum" size="small"></el-input>
  72. </template>
  73. </el-table-column>
  74. <el-table-column align="center" label="已申请数量" prop="alreadyInvoiceNum" min-width="100" show-overflow-tooltip></el-table-column>
  75. <el-table-column align="center" label="未申请数量" prop="refundableQty" min-width="100" show-overflow-tooltip> </el-table-column>
  76. <el-table-column align="center" label="备注" prop="remark" min-width="160" show-overflow-tooltip>
  77. <template slot-scope="scope">
  78. <el-input v-model="scope.row.remark" size="small"></el-input>
  79. </template>
  80. </el-table-column>
  81. <el-table-column align="center" label="操作" width="100" fixed="right">
  82. <template slot-scope="scope">
  83. <el-button type="text" @click="deleteItem(scope.$index)">删除</el-button>
  84. </template>
  85. </el-table-column>
  86. </el-table>
  87. </div>
  88. <div class="page-footer">
  89. <div class="footer" :class="classObj">
  90. <el-button type="primary" @click="clickSubmitForm('SAVE')">保 存</el-button>
  91. <el-button type="primary" @click="clickSubmitForm('WAIT')">提交审核</el-button>
  92. <el-popconfirm title="确定关闭吗?" @onConfirm="goBack" style="margin-left: 10px;">
  93. <el-button slot="reference">关 闭</el-button>
  94. </el-popconfirm>
  95. </div>
  96. </div>
  97. <el-dialog title="添加产品" :visible.sync="isShowDialog" width="80%">
  98. <el-form ref="screenForm" :model="screenForm" size="small" label-position="left" label-width="70px">
  99. <el-row :gutter="20">
  100. <el-col :xs="12" :sm="6" :lg="6">
  101. <el-form-item prop="warehouse" label="选择仓库">
  102. <el-select v-model="screenForm.warehouse" placeholder="请选择仓库" size="small" filterable clearable :disabled="goodsList.length > 0 || tableSelection.length > 0">
  103. <el-option :label="item.name" :value="item.id" v-for="(item, index) in warehouseList" :key="index"></el-option>
  104. </el-select>
  105. </el-form-item>
  106. </el-col>
  107. <el-col :xs="12" :sm="6" :lg="6">
  108. <el-form-item prop="type" label="产品大类">
  109. <el-select v-model="screenForm.type" placeholder="选择产品大类" style="width: 100%" :disabled="goodsList.length > 0 || tableSelection.length > 0">
  110. <el-option v-for="item in typeList" :key="item.dictCode" :label="item.dictValue" :value="item.dictCode"></el-option>
  111. </el-select>
  112. </el-form-item>
  113. </el-col>
  114. <el-col :xs="12" :sm="6" :lg="6">
  115. <el-form-item prop="orderNum" label="订单号">
  116. <el-input v-model="screenForm.orderNum" placeholder="请输入订单号"></el-input>
  117. </el-form-item>
  118. </el-col>
  119. <el-col :xs="12" :sm="6" :lg="6" class="tr">
  120. <el-form-item label="">
  121. <el-button size="small" @click="resetScreenForm">清空</el-button>
  122. <el-button size="small" type="primary" @click="submitScreenForm">搜索</el-button>
  123. </el-form-item>
  124. </el-col>
  125. </el-row>
  126. </el-form>
  127. <div class="table">
  128. <el-table :data="tableGoodsList" element-loading-text="Loading" border fit highlight-current-row stripe height="400" @selection-change="tableSelectionChange">
  129. <el-table-column align="center" type="selection" width="55" :selectable='checkboxSelect'></el-table-column>
  130. <el-table-column align="center" label="订单号" prop="orderId" min-width="180" show-overflow-tooltip></el-table-column>
  131. <el-table-column align="center" label="销售类型" prop="saleTypeName" min-width="100" show-overflow-tooltip></el-table-column>
  132. <el-table-column align="center" label="产品名称" prop="materialName" min-width="160" show-overflow-tooltip></el-table-column>
  133. <el-table-column align="center" label="规格型号" prop="specification" min-width="160" show-overflow-tooltip></el-table-column>
  134. <el-table-column align="center" label="单位" prop="unit" min-width="80" show-overflow-tooltip></el-table-column>
  135. <el-table-column align="center" label="数量" prop="qty" min-width="80" show-overflow-tooltip></el-table-column>
  136. <el-table-column align="center" label="本次申请数量" prop="invoiceNum" min-width="110" show-overflow-tooltip>
  137. <template slot-scope="scope">
  138. <el-input v-model="scope.row.invoiceNum" size="small"></el-input>
  139. </template>
  140. </el-table-column>
  141. <el-table-column align="center" label="已申请数量" prop="alreadyInvoiceNum" min-width="100" show-overflow-tooltip></el-table-column>
  142. <el-table-column align="center" label="未申请数量" prop="refundableQty" min-width="100" show-overflow-tooltip></el-table-column>
  143. <el-table-column align="center" label="总库存数量" prop="stockAdequate" min-width="100" show-overflow-tooltip>
  144. <template slot-scope="scope">
  145. {{scope.row.stockAdequate | stockFilter}}
  146. </template>
  147. </el-table-column>
  148. <el-table-column align="center" label="对应库存数量" prop="stockCorrespond" min-width="110" show-overflow-tooltip></el-table-column>
  149. </el-table>
  150. <div class="pagination clearfix" style="margin-top: 10px">
  151. <div class="fr">
  152. <el-pagination
  153. @current-change="handleTableCurrentChange"
  154. :current-page="currentPage"
  155. :page-size="10"
  156. background
  157. layout="prev, pager, next"
  158. :total="listTotal">
  159. </el-pagination>
  160. </div>
  161. </div>
  162. </div>
  163. <span slot="footer" class="dialog-footer">
  164. <el-button @click="closeDialog">取 消</el-button>
  165. <el-button type="primary" @click="submitAddGoods">确 定</el-button>
  166. </span>
  167. </el-dialog>
  168. </div>
  169. </template>
  170. <script>
  171. import { getApplyDetail, addApply, editApply, getGoodsList, getWarehouseList, getDealerList } from "@/api/supply/apply";
  172. import { getDictList } from '@/api/common'
  173. import { findElem } from '@/utils/util'
  174. import fileUpload from '@/components/Common/file-upload.vue'
  175. export default {
  176. components: {
  177. fileUpload
  178. },
  179. name: 'ApplyForm',
  180. componentName: 'ApplyForm',
  181. props: ['listItem'],
  182. filters: {
  183. stockFilter(val) {
  184. const MAP = {
  185. 0: '不充足',
  186. 1: '充足'
  187. }
  188. return MAP[val]
  189. }
  190. },
  191. data() {
  192. return {
  193. mainForm: {
  194. orderNum: '',
  195. date: '',
  196. jxsNum: '',
  197. remark: '',
  198. createMan: '',
  199. },
  200. mainFormRules: {
  201. date: [
  202. { required: true, message: '请选择单据日期', trigger: 'change' }
  203. ],
  204. },
  205. dealerList: [],
  206. fileList: [],
  207. goodsList: [],
  208. warehouseList: [],
  209. isShowDialog: false,
  210. screenForm: {
  211. warehouse: '',
  212. type: '',
  213. orderNum: '',
  214. },
  215. currentPage: 1,
  216. listTotal: 0,
  217. typeList: [],
  218. tableGoodsList: [],
  219. tableSelection: [],
  220. }
  221. },
  222. computed: {
  223. sidebar() {
  224. return this.$store.state.app.sidebar
  225. },
  226. classObj() {
  227. return {
  228. hideSidebar: !this.sidebar.opened,
  229. openSidebar: this.sidebar.opened
  230. }
  231. },
  232. },
  233. created() {
  234. this.getDictList();
  235. this.getWarehouseList();
  236. this.getDealerList();
  237. if(this.listItem) {
  238. this.getDetail();
  239. }else {
  240. this.mainForm.jxsNum = JSON.parse(localStorage.getItem("supply_user")).customerId;
  241. this.mainForm.createMan = JSON.parse(localStorage.getItem("supply_user")).nickName;
  242. }
  243. },
  244. methods: {
  245. // 返回列表
  246. goBack() {
  247. this.$emit('backListFormDetail');
  248. },
  249. // 获取详情
  250. getDetail() {
  251. getApplyDetail({id: this.listItem.id}).then(res => {
  252. let data = res.data;
  253. this.mainForm.orderNum = data.id;
  254. this.mainForm.date = data.orderTime;
  255. this.mainForm.jxsNum = data.customerNumber;
  256. this.mainForm.createMan = data.createBy;
  257. this.mainForm.remark = data.remark;
  258. this.screenForm.warehouse = data.correspondId;
  259. this.fileList = data.fileUrl ? [{
  260. url: data.fileUrl,
  261. name: data.fileName
  262. }] : [];
  263. data.orders.forEach(item => {
  264. item.orderId = item.id;
  265. })
  266. this.goodsList = data.orders;
  267. })
  268. },
  269. // 获取仓库列表
  270. getWarehouseList() {
  271. getWarehouseList({
  272. pageNum: 1,
  273. pageSize: -1
  274. }).then((res) => {
  275. this.warehouseList = res.data.records;
  276. })
  277. },
  278. getDictList() {
  279. getDictList({sysDictEnum: 'PRODUCT_TYPE'}).then(res => {
  280. this.typeList = res.data;
  281. })
  282. },
  283. // 获取经销商列表
  284. getDealerList() {
  285. getDealerList({
  286. pageNum: 1,
  287. pageSize: -1,
  288. bindUser: false
  289. }).then(res => {
  290. this.dealerList = res.data.records;
  291. })
  292. },
  293. // 获取商品列表
  294. getGoodsList() {
  295. getGoodsList({
  296. pageNum: this.currentPage,
  297. pageSize: 10,
  298. stockId: this.screenForm.warehouse,
  299. mainId: this.screenForm.type,
  300. id: this.screenForm.orderNum,
  301. examineStatus: 'OK',
  302. type: 1,
  303. }).then(res => {
  304. let goodsList = [];
  305. res.data.records.forEach(item => {
  306. goodsList.push({
  307. orderId: item.id,
  308. retailId: item.retailId,
  309. saleTypeName: item.saleTypeName,
  310. materialId: item.materialId,
  311. materialCode: item.materialCode,
  312. materialName: item.materialName,
  313. specification: item.specification,
  314. unit: item.unit,
  315. qty: item.qty,
  316. invoiceNum: item.invoiceNum,
  317. alreadyInvoiceNum: item.alreadyInvoiceNum,
  318. refundableQty: item.refundableQty,
  319. stockAdequate: item.stockAdequate,
  320. stockCorrespond: item.stockCorrespond,
  321. })
  322. });
  323. let oldGoodsList = this.goodsList;
  324. let newGoodsList = goodsList;
  325. for(let i = 0; i < oldGoodsList.length; i++) {
  326. let oldItem = oldGoodsList[i]
  327. for(let j = 0; j < newGoodsList.length; j++) {
  328. let newItem = newGoodsList[j]
  329. if(newItem.materialId === oldItem.materialId){
  330. newGoodsList[j].selected = true;
  331. break;
  332. }
  333. }
  334. }
  335. this.tableGoodsList = newGoodsList;
  336. this.listTotal = res.data.total;
  337. })
  338. },
  339. // 查询重复值并禁选
  340. checkboxSelect(row, rowIndex) {
  341. if (row.selected) {
  342. return false // 禁用
  343. }else{
  344. return true // 不禁用
  345. }
  346. },
  347. // 点击 选择商品
  348. openDialog() {
  349. if(!this.screenForm.warehouse) {
  350. return this.$errorMsg('请选择仓库');
  351. }
  352. this.isShowDialog = true;
  353. if(this.screenForm.warehouse && this.screenForm.type) {
  354. this.getGoodsList();
  355. }
  356. },
  357. // 提交筛选表单
  358. submitScreenForm() {
  359. if(!this.screenForm.warehouse || !this.screenForm.type) {
  360. return this.$errorMsg('请选择仓库和产品大类');
  361. }
  362. this.currentPage = 1;
  363. this.getGoodsList();
  364. },
  365. // 重置筛选表单
  366. resetScreenForm() {
  367. this.$refs.screenForm.resetFields();
  368. this.currentPage = 1;
  369. this.tableGoodsList = [];
  370. // this.getGoodsList();
  371. },
  372. // 更改列表当前页
  373. handleTableCurrentChange(val) {
  374. if(this.tableSelection.length > 0) {
  375. return this.$errorMsg('已选择产品不可切换');
  376. }
  377. this.currentPage = val;
  378. this.getGoodsList();
  379. },
  380. // 关闭 弹窗
  381. closeDialog() {
  382. this.isShowDialog = false;
  383. },
  384. // 列表选择
  385. tableSelectionChange(val) {
  386. this.tableSelection = val;
  387. },
  388. // 数组去重
  389. delRepeat(arr1, arr2) {
  390. let allArr = arr1.concat(arr2); // 两个数组对象合并
  391. let newArr = []; // 存放去重后数据的新数组
  392. for(let i=0; i<allArr.length; i++){ // 循环allArr数组对象的内容
  393. let flag = true; // 建立标记,判断数据是否重复,true为不重复
  394. for(let j=0; j<newArr.length; j++){ // 循环新数组的内容
  395. if(allArr[i].materialId == newArr[j].materialId){ // 让allArr数组对象的内容与新数组的内容作比较,相同的话,改变标记为false
  396. flag = false;
  397. }
  398. }
  399. if(flag){ // 判断是否重复
  400. newArr.push(allArr[i]); // 不重复的放入新数组。 新数组的内容会继续进行上边的循环。
  401. }
  402. }
  403. return newArr;
  404. },
  405. // 确定 添加产品
  406. submitAddGoods() {
  407. let allList = this.tableGoodsList;
  408. let selectList = this.tableSelection;
  409. let submitList = [];
  410. for(let i = 0; i < allList.length; i++) {
  411. for(let j = 0; j < selectList.length; j++) {
  412. if(selectList[j].orderId == allList[i].orderId){
  413. submitList.push(allList[i]);
  414. }
  415. }
  416. }
  417. // this.goodsList = this.goodsList.concat(submitList);
  418. this.goodsList = this.delRepeat(submitList, this.goodsList);
  419. this.isShowDialog = false;
  420. this.tableGoodsList = [];
  421. },
  422. // 删除产品
  423. deleteItem(index) {
  424. this.goodsList.splice(index, 1);
  425. // this.goodsList = this.goodsList.filter((item) => {
  426. // return item.orderId != id
  427. // })
  428. },
  429. // 保存
  430. clickSubmitForm(status) {
  431. this.$refs.mainForm.validate((valid) => {
  432. if (valid) {
  433. for(let i=0; i<this.goodsList.length; i++) {
  434. if(!this.goodsList[i].invoiceNum) {
  435. this.$errorMsg('请输入申请数量');
  436. return;
  437. }
  438. }
  439. for(let i=0; i<this.goodsList.length; i++) {
  440. if(this.goodsList[i].invoiceNum > this.goodsList[i].qty) {
  441. this.$errorMsg('申请数量不能大于总数量');
  442. return;
  443. }
  444. }
  445. let correspondName = this.warehouseList[findElem(this.warehouseList, 'id', this.screenForm.warehouse)].name;
  446. let params = {
  447. id: this.listItem ? this.listItem.id : '',
  448. orderTime: this.mainForm.date + ' 00:00:00',
  449. remark: this.mainForm.remark,
  450. fileUrl: this.fileList && this.fileList.length > 0 ? this.fileList[0].url : '',
  451. fileName: this.fileList && this.fileList.length > 0 ? this.fileList[0].name : '',
  452. orderType: 1, // 1零售单 2家用工程 3商用工程
  453. correspondId: this.screenForm.warehouse,
  454. correspondName,
  455. orders: this.goodsList,
  456. examineStatus: status,
  457. }
  458. if(this.listItem) {
  459. editApply(params).then(res => {
  460. this.$successMsg('编辑成功');
  461. this.goBack();
  462. this.$parent.getList();
  463. })
  464. }else {
  465. addApply(params).then(res => {
  466. this.$successMsg('添加成功');
  467. this.goBack();
  468. this.$parent.getList();
  469. })
  470. }
  471. }
  472. })
  473. },
  474. }
  475. }
  476. </script>
  477. <style scoped lang="scss">
  478. .detail-container {
  479. width: 100%;
  480. height: 100%;
  481. }
  482. .main-title {
  483. display: flex;
  484. justify-content: space-between;
  485. align-items: center;
  486. margin-top: 20px;
  487. height: 60px;
  488. border-bottom: 1px solid #DCDFE6;
  489. margin-bottom: 20px;
  490. .title {
  491. font-size: 16px;
  492. font-weight: 600;
  493. padding-left: 10px;
  494. }
  495. }
  496. </style>