apply_form.vue 21 KB

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