apply_form.vue 21 KB

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