apply_form.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  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="orderId" min-width="180" 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="refundableQty" min-width="100" show-overflow-tooltip></el-table-column>
  147. <el-table-column align="center" label="总库存数量" prop="stockAdequate" min-width="100" show-overflow-tooltip>
  148. <template slot-scope="scope">
  149. {{scope.row.stockAdequate | stockFilter}}
  150. </template>
  151. </el-table-column>
  152. <el-table-column align="center" label="对应库存数量" prop="stockCorrespond" min-width="110" show-overflow-tooltip></el-table-column>
  153. </el-table>
  154. <div class="pagination clearfix" style="margin-top: 10px">
  155. <div class="fr">
  156. <el-pagination
  157. @current-change="handleTableCurrentChange"
  158. :current-page="currentPage"
  159. :page-size="10"
  160. background
  161. layout="prev, pager, next"
  162. :total="listTotal">
  163. </el-pagination>
  164. </div>
  165. </div>
  166. </div>
  167. <span slot="footer" class="dialog-footer">
  168. <el-button @click="closeDialog">取 消</el-button>
  169. <el-button type="primary" @click="submitAddGoods">确 定</el-button>
  170. </span>
  171. </el-dialog>
  172. </div>
  173. </template>
  174. <script>
  175. import { getApplyDetail, addApply, editApply, getGoodsList, getWarehouseList, getDealerList } from "@/api/supply/apply";
  176. import { getDictList } from '@/api/common'
  177. import { findElem } from '@/utils/util'
  178. import fileUpload from '@/components/Common/file-upload.vue'
  179. export default {
  180. components: {
  181. fileUpload
  182. },
  183. name: 'ApplyForm',
  184. componentName: 'ApplyForm',
  185. props: ['listItem'],
  186. filters: {
  187. stockFilter(val) {
  188. const MAP = {
  189. 0: '不充足',
  190. 1: '充足'
  191. }
  192. return MAP[val]
  193. }
  194. },
  195. data() {
  196. return {
  197. mainForm: {
  198. orderNum: '',
  199. date: '',
  200. jxsNum: '',
  201. jxsName: '',
  202. remark: '',
  203. createMan: '',
  204. },
  205. mainFormRules: {
  206. date: [
  207. { required: true, message: '请选择单据日期', trigger: 'change' }
  208. ],
  209. },
  210. dealerList: [],
  211. fileList: [],
  212. goodsList: [],
  213. warehouseList: [],
  214. isShowDialog: false,
  215. screenForm: {
  216. warehouse: '',
  217. type: '',
  218. orderNum: '',
  219. },
  220. currentPage: 1,
  221. listTotal: 0,
  222. typeList: [],
  223. tableGoodsList: [],
  224. tableSelection: [],
  225. }
  226. },
  227. computed: {
  228. sidebar() {
  229. return this.$store.state.app.sidebar
  230. },
  231. classObj() {
  232. return {
  233. hideSidebar: !this.sidebar.opened,
  234. openSidebar: this.sidebar.opened
  235. }
  236. },
  237. },
  238. created() {
  239. this.getDictList();
  240. this.getWarehouseList();
  241. this.getDealerList();
  242. if(this.listItem) {
  243. this.getDetail();
  244. }else {
  245. this.mainForm.jxsNum = JSON.parse(localStorage.getItem("supply_user")).customerId;
  246. this.mainForm.jxsName = JSON.parse(localStorage.getItem("supply_user")).customerName;
  247. this.mainForm.createMan = JSON.parse(localStorage.getItem("supply_user")).nickName;
  248. }
  249. },
  250. methods: {
  251. // 返回列表
  252. goBack() {
  253. this.$emit('backListFormDetail');
  254. },
  255. // 获取详情
  256. getDetail() {
  257. getApplyDetail({id: this.listItem.id}).then(res => {
  258. let data = res.data;
  259. this.mainForm.orderNum = data.id;
  260. this.mainForm.date = data.orderTime;
  261. this.mainForm.jxsNum = data.customerNumber;
  262. this.mainForm.jxsName = data.customerName;
  263. this.mainForm.createMan = data.createBy;
  264. this.mainForm.remark = data.remark;
  265. this.screenForm.warehouse = data.correspondId;
  266. this.fileList = data.fileUrl ? [{
  267. url: data.fileUrl,
  268. name: data.fileName
  269. }] : [];
  270. data.orders.forEach(item => {
  271. item.orderId = item.id;
  272. })
  273. this.goodsList = data.orders;
  274. })
  275. },
  276. // 获取仓库列表
  277. getWarehouseList() {
  278. getWarehouseList({
  279. pageNum: 1,
  280. pageSize: -1
  281. }).then((res) => {
  282. this.warehouseList = res.data.records;
  283. })
  284. },
  285. getDictList() {
  286. getDictList({sysDictEnum: 'PRODUCT_TYPE'}).then(res => {
  287. this.typeList = res.data;
  288. })
  289. },
  290. // 获取经销商列表
  291. getDealerList() {
  292. getDealerList({
  293. pageNum: 1,
  294. pageSize: -1,
  295. bindUser: false
  296. }).then(res => {
  297. this.dealerList = res.data.records;
  298. })
  299. },
  300. // 获取商品列表
  301. getGoodsList() {
  302. getGoodsList({
  303. pageNum: this.currentPage,
  304. pageSize: 10,
  305. correspondId: this.screenForm.warehouse,
  306. mainId: this.screenForm.type,
  307. id: this.screenForm.orderNum,
  308. }).then(res => {
  309. res.data.records.forEach(item => {
  310. item.mainOrderId = item.id;
  311. delete item.id;
  312. });
  313. let oldGoodsList = this.goodsList;
  314. let newGoodsList = res.data.records;
  315. for(let i = 0; i < oldGoodsList.length; i++) {
  316. let oldItem = oldGoodsList[i]
  317. for(let j = 0; j < newGoodsList.length; j++) {
  318. let newItem = newGoodsList[j]
  319. if(newItem.materialId === oldItem.materialId){
  320. newGoodsList[j].selected = true;
  321. break;
  322. }
  323. }
  324. }
  325. this.tableGoodsList = newGoodsList;
  326. this.listTotal = res.data.total;
  327. })
  328. },
  329. // 查询重复值并禁选
  330. checkboxSelect(row, rowIndex) {
  331. if (row.selected) {
  332. return false // 禁用
  333. }else{
  334. return true // 不禁用
  335. }
  336. },
  337. // 点击 选择商品
  338. openDialog() {
  339. if(!this.screenForm.warehouse) {
  340. return this.$errorMsg('请选择仓库');
  341. }
  342. this.isShowDialog = true;
  343. if(this.screenForm.warehouse && this.screenForm.type) {
  344. this.getGoodsList();
  345. }
  346. },
  347. // 提交筛选表单
  348. submitScreenForm() {
  349. if(!this.screenForm.warehouse || !this.screenForm.type) {
  350. return this.$errorMsg('请选择仓库和产品大类');
  351. }
  352. this.currentPage = 1;
  353. this.getGoodsList();
  354. },
  355. // 重置筛选表单
  356. resetScreenForm() {
  357. this.$refs.screenForm.resetFields();
  358. this.currentPage = 1;
  359. this.tableGoodsList = [];
  360. // this.getGoodsList();
  361. },
  362. // 更改列表当前页
  363. handleTableCurrentChange(val) {
  364. if(this.tableSelection.length > 0) {
  365. return this.$errorMsg('已选择产品不可切换');
  366. }
  367. this.currentPage = val;
  368. this.getGoodsList();
  369. },
  370. // 关闭 弹窗
  371. closeDialog() {
  372. this.isShowDialog = false;
  373. },
  374. // 列表选择
  375. tableSelectionChange(val) {
  376. this.tableSelection = val;
  377. },
  378. // 数组去重
  379. delRepeat(arr1, arr2) {
  380. let allArr = arr1.concat(arr2); // 两个数组对象合并
  381. let newArr = []; // 存放去重后数据的新数组
  382. for(let i=0; i<allArr.length; i++){ // 循环allArr数组对象的内容
  383. let flag = true; // 建立标记,判断数据是否重复,true为不重复
  384. for(let j=0; j<newArr.length; j++){ // 循环新数组的内容
  385. if(allArr[i].materialId == newArr[j].materialId){ // 让allArr数组对象的内容与新数组的内容作比较,相同的话,改变标记为false
  386. flag = false;
  387. }
  388. }
  389. if(flag){ // 判断是否重复
  390. newArr.push(allArr[i]); // 不重复的放入新数组。 新数组的内容会继续进行上边的循环。
  391. }
  392. }
  393. return newArr;
  394. },
  395. // 确定 添加产品
  396. submitAddGoods() {
  397. let allList = this.tableGoodsList;
  398. let selectList = this.tableSelection;
  399. let submitList = [];
  400. for(let i = 0; i < allList.length; i++) {
  401. for(let j = 0; j < selectList.length; j++) {
  402. if(selectList[j].orderId == allList[i].orderId){
  403. submitList.push(allList[i]);
  404. }
  405. }
  406. }
  407. // this.goodsList = this.goodsList.concat(submitList);
  408. this.goodsList = this.delRepeat(submitList, this.goodsList);
  409. this.isShowDialog = false;
  410. this.tableGoodsList = [];
  411. },
  412. // 删除产品
  413. deleteItem(index) {
  414. this.goodsList.splice(index, 1);
  415. // this.goodsList = this.goodsList.filter((item) => {
  416. // return item.orderId != id
  417. // })
  418. },
  419. // 保存
  420. clickSubmitForm(status) {
  421. this.$refs.mainForm.validate((valid) => {
  422. if (valid) {
  423. for(let i=0; i<this.goodsList.length; i++) {
  424. if(!this.goodsList[i].invoiceNum) {
  425. this.$errorMsg('请输入申请数量');
  426. return;
  427. }
  428. }
  429. for(let i=0; i<this.goodsList.length; i++) {
  430. if(this.goodsList[i].invoiceNum > this.goodsList[i].qty) {
  431. this.$errorMsg('申请数量不能大于总数量');
  432. return;
  433. }
  434. }
  435. if(!this.screenForm.warehouse) {
  436. return this.$errorMsg('请选择仓库');
  437. }
  438. let correspondName = this.warehouseList[findElem(this.warehouseList, 'id', this.screenForm.warehouse)].name;
  439. let params = {
  440. id: this.listItem ? this.listItem.id : '',
  441. orderTime: this.mainForm.date + ' 00:00:00',
  442. remark: this.mainForm.remark,
  443. fileUrl: this.fileList && this.fileList.length > 0 ? this.fileList[0].url : '',
  444. fileName: this.fileList && this.fileList.length > 0 ? this.fileList[0].name : '',
  445. // orderType: 1, // 1零售单 2家用工程 3商用工程
  446. correspondId: this.screenForm.warehouse,
  447. correspondName,
  448. orders: this.goodsList,
  449. examineStatus: status,
  450. }
  451. if(this.listItem) {
  452. editApply(params).then(res => {
  453. this.$successMsg('编辑成功');
  454. this.goBack();
  455. this.$parent.getList();
  456. })
  457. }else {
  458. addApply(params).then(res => {
  459. this.$successMsg('添加成功');
  460. this.goBack();
  461. this.$parent.getList();
  462. })
  463. }
  464. }
  465. })
  466. },
  467. }
  468. }
  469. </script>
  470. <style scoped lang="scss">
  471. .detail-container {
  472. width: 100%;
  473. height: 100%;
  474. }
  475. .main-title {
  476. display: flex;
  477. justify-content: space-between;
  478. align-items: center;
  479. margin-top: 20px;
  480. height: 60px;
  481. border-bottom: 1px solid #DCDFE6;
  482. margin-bottom: 20px;
  483. .title {
  484. font-size: 16px;
  485. font-weight: 600;
  486. padding-left: 10px;
  487. }
  488. }
  489. </style>