apply_form.vue 20 KB

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