apply_form.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  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 || tableSelection.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-input v-model="screenForm.type" placeholder="请输入存货类别"></el-input>
  127. </el-form-item>
  128. </el-col>
  129. <el-col :xs="12" :sm="6" :lg="6" class="tr">
  130. <el-form-item label="">
  131. <el-button size="small" @click="resetScreenForm">清空</el-button>
  132. <el-button size="small" type="primary" @click="submitScreenForm">搜索</el-button>
  133. </el-form-item>
  134. </el-col>
  135. </el-row>
  136. </el-form>
  137. <div class="table">
  138. <el-table :data="tableGoodsList" element-loading-text="Loading" border fit highlight-current-row stripe height="400" @selection-change="tableSelectionChange">
  139. <el-table-column align="center" type="selection" width="55" :selectable='checkboxSelect'></el-table-column>
  140. <el-table-column align="center" label="订单号" prop="mainOrderId" min-width="200" show-overflow-tooltip></el-table-column>
  141. <el-table-column align="center" label="销售类型" prop="saleTypeName" min-width="100" show-overflow-tooltip></el-table-column>
  142. <el-table-column align="center" label="产品名称" prop="materialName" min-width="160" show-overflow-tooltip></el-table-column>
  143. <el-table-column align="center" label="规格型号" prop="specification" min-width="160" show-overflow-tooltip></el-table-column>
  144. <el-table-column align="center" label="单位" prop="unit" min-width="80" show-overflow-tooltip></el-table-column>
  145. <el-table-column align="center" label="数量" prop="qty" min-width="80" show-overflow-tooltip></el-table-column>
  146. <el-table-column align="center" label="本次申请数量" prop="invoiceNum" min-width="110" show-overflow-tooltip>
  147. <template slot-scope="scope">
  148. <el-input v-model="scope.row.invoiceNum" size="small"></el-input>
  149. </template>
  150. </el-table-column>
  151. <el-table-column align="center" label="已申请数量" prop="alreadyInvoiceNum" min-width="100" show-overflow-tooltip></el-table-column>
  152. <el-table-column align="center" label="已申请未出货数量" prop="sendQty" min-width="100" show-overflow-tooltip></el-table-column>
  153. <el-table-column align="center" label="未申请数量" prop="refundableQty" min-width="100" show-overflow-tooltip></el-table-column>
  154. <el-table-column align="center" label="总库存数量" prop="stockAdequate" min-width="100" show-overflow-tooltip>
  155. <template slot-scope="scope">
  156. {{stockFilter(scope.row, 1)}}
  157. </template>
  158. </el-table-column>
  159. <el-table-column align="center" label="对应库存数量" prop="stockCorrespond" min-width="110" show-overflow-tooltip>
  160. <template slot-scope="scope">
  161. {{stockFilter(scope.row, 2)}}
  162. </template>
  163. </el-table-column>
  164. </el-table>
  165. <div class="pagination clearfix" style="margin-top: 10px">
  166. <div class="fr">
  167. <el-pagination
  168. @current-change="handleTableCurrentChange"
  169. :current-page="currentPage"
  170. :page-size="10"
  171. background
  172. layout="prev, pager, next"
  173. :total="listTotal">
  174. </el-pagination>
  175. </div>
  176. </div>
  177. </div>
  178. <span slot="footer" class="dialog-footer">
  179. <el-button @click="closeDialog">取 消</el-button>
  180. <el-button type="primary" @click="submitAddGoods">确 定</el-button>
  181. </span>
  182. </el-dialog>
  183. </div>
  184. </template>
  185. <script>
  186. import { getApplyDetail, addApply, editApply, getGoodsList, getWarehouseList, getDealerList } from "@/api/supply/apply";
  187. import { getDictList } from '@/api/common'
  188. import { findElem } from '@/utils/util'
  189. import fileUpload from '@/components/Common/file-upload.vue'
  190. export default {
  191. components: {
  192. fileUpload
  193. },
  194. name: 'ApplyForm',
  195. componentName: 'ApplyForm',
  196. props: ['listItem'],
  197. data() {
  198. return {
  199. mainForm: {
  200. orderNum: '',
  201. date: '',
  202. jxsNum: '',
  203. jxsName: '',
  204. remark: '',
  205. createMan: '',
  206. },
  207. mainFormRules: {
  208. // date: [{ required: true, message: '请选择单据日期', trigger: 'change' }],
  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. stockList: [],
  224. tableGoodsList: [],
  225. tableSelection: [],
  226. }
  227. },
  228. created() {
  229. this.getDictList();
  230. this.getWarehouseList();
  231. this.getDealerList();
  232. if(this.listItem) {
  233. this.getDetail();
  234. }else {
  235. this.mainForm.jxsNum = JSON.parse(localStorage.getItem("supply_user")).customerId;
  236. this.mainForm.jxsName = JSON.parse(localStorage.getItem("supply_user")).customerName;
  237. this.mainForm.createMan = JSON.parse(localStorage.getItem("supply_user")).nickName;
  238. }
  239. },
  240. methods: {
  241. // 返回列表
  242. goBack() {
  243. this.$emit('backListFormDetail');
  244. },
  245. // 获取详情
  246. getDetail() {
  247. getApplyDetail({id: this.listItem.id}).then(res => {
  248. let data = res.data;
  249. this.mainForm.orderNum = data.id;
  250. this.mainForm.date = data.orderTime;
  251. this.mainForm.jxsNum = data.customerNumber;
  252. this.mainForm.jxsName = data.customerName;
  253. this.mainForm.createMan = data.createBy;
  254. this.mainForm.remark = data.remark;
  255. this.screenForm.warehouse = data.correspondId;
  256. this.fileList = data.fileUrl ? [{
  257. url: data.fileUrl,
  258. name: data.fileName
  259. }] : [];
  260. // data.orders.forEach(item => {
  261. // item.orderId = item.id;
  262. // })
  263. this.goodsList = data.orders;
  264. // this.screenForm.type = data.mainId;
  265. })
  266. },
  267. // 获取仓库列表
  268. getWarehouseList() {
  269. getWarehouseList({
  270. pageNum: 1,
  271. pageSize: -1
  272. }).then((res) => {
  273. this.warehouseList = res.data.records;
  274. })
  275. },
  276. getDictList() {
  277. // getDictList({sysDictEnum: 'PRODUCT_TYPE'}).then(res => {
  278. // this.typeList = res.data;
  279. // })
  280. getDictList({sysDictEnum: 'STOCK_ORDER'}).then(res => {
  281. this.stockList = res.data;
  282. })
  283. },
  284. // 获取经销商列表
  285. getDealerList() {
  286. getDealerList({
  287. pageNum: 1,
  288. pageSize: -1,
  289. bindUser: false
  290. }).then(res => {
  291. this.dealerList = res.data.records;
  292. })
  293. },
  294. // 库存字段
  295. stockFilter(item, type) {
  296. let STOCK_ORDER_INVOICE = this.stockList.find(o => o.dictCode == 'STOCK_ORDER_INVOICE').dictValue;
  297. if(type === 1) {
  298. return item.stockAdequate > STOCK_ORDER_INVOICE ? '充足' : item.stockAdequate;
  299. }
  300. if(type === 2) {
  301. return item.stockCorrespond > STOCK_ORDER_INVOICE ? '充足' : item.stockCorrespond;
  302. }
  303. },
  304. // 获取商品列表
  305. getGoodsList() {
  306. getGoodsList({
  307. pageNum: this.currentPage,
  308. pageSize: 10,
  309. correspondId: this.screenForm.warehouse,
  310. categoryName: this.screenForm.type,
  311. id: this.screenForm.orderNum,
  312. }).then(res => {
  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.orderId === oldItem.orderId){
  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) {
  344. this.getGoodsList();
  345. }
  346. },
  347. // 提交筛选表单
  348. submitScreenForm() {
  349. if(!this.screenForm.warehouse) {
  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].orderId == newArr[j].orderId){ // 让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. for(let i=0; i<this.tableSelection.length; i++) {
  398. if(!this.tableSelection[i].invoiceNum) {
  399. this.$errorMsg('请输入申请数量');
  400. return;
  401. }
  402. if(this.tableSelection[i].invoiceNum > this.tableSelection[i].refundableQty) {
  403. this.$errorMsg('申请数量不能大于未申请数量');
  404. return;
  405. }
  406. }
  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. this.goodsList = this.goodsList.concat(this.tableSelection);
  422. },
  423. // 删除产品
  424. deleteItem(index) {
  425. this.goodsList.splice(index, 1);
  426. // this.goodsList = this.goodsList.filter((item) => {
  427. // return item.orderId != id
  428. // })
  429. },
  430. // 保存
  431. clickSubmitForm(status) {
  432. this.$refs.mainForm.validate((valid) => {
  433. if (valid) {
  434. if(this.goodsList.length < 1) {
  435. return this.$errorMsg('请添加引用');
  436. }
  437. for(let i=0; i<this.goodsList.length; i++) {
  438. if(!this.goodsList[i].invoiceNum) {
  439. this.$errorMsg('请输入申请数量');
  440. return;
  441. }
  442. if(this.goodsList[i].invoiceNum > this.goodsList[i].refundableQty) {
  443. this.$errorMsg('申请数量不能大于未申请数量');
  444. return;
  445. }
  446. }
  447. if(!this.screenForm.warehouse) {
  448. return this.$errorMsg('请选择仓库');
  449. }
  450. let correspondName = this.warehouseList[findElem(this.warehouseList, 'id', this.screenForm.warehouse)].name;
  451. let params = {
  452. id: this.listItem ? this.listItem.id : '',
  453. // orderTime: this.mainForm.date + ' 00:00:00',
  454. remark: this.mainForm.remark,
  455. fileUrl: this.fileList && this.fileList.length > 0 ? this.fileList[0].url : '',
  456. fileName: this.fileList && this.fileList.length > 0 ? this.fileList[0].name : '',
  457. // orderType: 1, // 1零售单 2家用工程 3商用工程
  458. correspondId: this.screenForm.warehouse,
  459. correspondName,
  460. orders: this.goodsList,
  461. examineStatus: status,
  462. }
  463. if(this.listItem) {
  464. editApply(params).then(res => {
  465. this.$successMsg('编辑成功');
  466. this.goBack();
  467. this.$parent.getList();
  468. })
  469. }else {
  470. addApply(params).then(res => {
  471. this.$successMsg('添加成功');
  472. this.goBack();
  473. this.$parent.getList();
  474. })
  475. }
  476. }
  477. })
  478. },
  479. }
  480. }
  481. </script>
  482. <style scoped lang="scss">
  483. .detail-container {
  484. width: 100%;
  485. height: 100%;
  486. }
  487. .main-title {
  488. display: flex;
  489. justify-content: space-between;
  490. align-items: center;
  491. margin-top: 20px;
  492. height: 60px;
  493. border-bottom: 1px solid #DCDFE6;
  494. margin-bottom: 20px;
  495. .title {
  496. font-size: 16px;
  497. font-weight: 600;
  498. padding-left: 10px;
  499. }
  500. }
  501. </style>