edit.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  1. <template>
  2. <div class="purchaseReceiptEdit-wrap">
  3. <a-spin :spinning="spinning" tip="Loading...">
  4. <a-page-header :ghost="false" :backIcon="false" class="purchaseReceiptEdit-back">
  5. <!-- 自定义的二级文字标题 -->
  6. <template slot="subTitle">
  7. <a id="purchaseReceiptEdit-back-btn" href="javascript:;" @click="handleBack">
  8. <a-icon type="left" />
  9. 返回列表
  10. </a>
  11. <span style="margin: 0 15px;color: #666;font-weight: bold;">单号:{{ detailsData&&detailsData.sparePartsReturnNo }}</span>
  12. <span style="margin: 0 10px;color: #666;">供应商:{{ detailsData && detailsData.supplier && detailsData.supplier.supplierName }}</span>
  13. <a-button type="link" size="small" id="purchaseReceiptEdit-showDetail-btn" class="button-default" @click="showDetail=!showDetail">
  14. <a-icon :type="showDetail ? 'eye-invisible' : 'eye'"/> {{ showDetail?'隐藏':'查看' }}信息
  15. </a-button>
  16. </template>
  17. </a-page-header>
  18. <a-card size="small" :bordered="false" class="purchaseReceiptEdit-cont" v-show="showDetail">
  19. <div slot="title">
  20. <span>基础信息</span>
  21. <div style="cursor:pointer;color: #00aaff;float:right;" id="purchaseReceiptEdit-btn" @click.stop="handleEditBase" >
  22. <a-icon type="edit" /> 编辑基础信息
  23. </div>
  24. </div>
  25. <a-descriptions size="small" :column="4" style="margin-bottom: 10px;">
  26. <a-descriptions-item label="客户名称">{{ (detailsData && detailsData.sparePartsReturnNo) || '--' }}</a-descriptions-item>
  27. <a-descriptions-item label="收货地址">{{ (detailsData && detailsData.sparePartsReturnNo) || '--' }}</a-descriptions-item>
  28. <a-descriptions-item label="收货人">{{ (detailsData && detailsData.supplier && detailsData.supplier.supplierName) || '--' }}</a-descriptions-item>
  29. <a-descriptions-item label="收货电话">{{ (detailsData && detailsData.returnReasonDictValue) || '--' }}</a-descriptions-item>
  30. <a-descriptions-item label="业务状态">{{ detailsData&&detailsData.warehouseName || '--' }}</a-descriptions-item>
  31. <a-descriptions-item label="备注">{{ detailsData&&detailsData.grabFlag =='0'?'否':'是' }}</a-descriptions-item>
  32. <a-descriptions-item label="关联单号">{{ (detailsData && detailsData.explainInfo) || '--' }}</a-descriptions-item>
  33. <a-descriptions-item label="销售类型">{{ (detailsData && detailsData.explainInfo) || '--' }}</a-descriptions-item>
  34. </a-descriptions>
  35. </a-card>
  36. <a-card size="small" :bordered="false" class="purchaseReceiptEdit-cont">
  37. <div class="table-page-search-wrapper" style="display:flex;align-items: center;justify-content: space-between;">
  38. <div style="flex-grow:1;">
  39. <a-form layout="inline" id="purchaseReceiptEdit-form-btn" @keyup.enter.native="$refs.table.refresh(true)">
  40. <a-row :gutter="15">
  41. <a-col :md="6" :sm="24">
  42. <a-form-item label="产品编码"><a-input id="purchaseReceiptEdit-productCode" v-model.trim="productForm.productCode" allowClear placeholder="请输入产品编码" /></a-form-item>
  43. </a-col>
  44. <a-col :md="6" :sm="24">
  45. <a-form-item label="产品名称"><a-input id="purchaseReceiptEdit-productName" v-model.trim="productForm.productName" allowClear placeholder="请输入产品名称" /></a-form-item>
  46. </a-col>
  47. <a-col :md="6" :sm="24" style="margin-bottom: 10px;">
  48. <a-button type="primary" id="purchaseReceiptEdit-refresh" @click="$refs.table.refresh(true)">查询</a-button>
  49. <a-button style="margin-left: 5px" id="purchaseReceiptEdit-reset" @click="resetSearchForm">重置</a-button>
  50. </a-col>
  51. </a-row>
  52. </a-form>
  53. </div>
  54. </div>
  55. <div class="showBtn">
  56. <a-button id="purchaseReceiptEdit-add" type="primary" class="button-warning" @click="handleAdd">新增产品</a-button>
  57. <a-button id="purchaseReceiptEdit-ex" class="button-warning" @click="handleImport">导入产品</a-button>
  58. <a-button
  59. v-if="$hasPermissions('B_sparePartsBatchAudit')"
  60. id="purchaseReceiptEdit-queryQty"
  61. type="primary"
  62. class="button-warning"
  63. :loading="loading"
  64. @click="handleThirdQty">第三方库存</a-button>
  65. <a-alert type="info">
  66. <div slot="message" class="total-bar">
  67. <span>采购数量:{{ statisticsObj && (statisticsObj.qty || statisticsObj.qty == 0) ? statisticsObj.qty : '--' }};</span>
  68. <span v-if="$hasPermissions('B_purchaseReturnEdit_costPrice')">采购金额:{{ statisticsObj && statisticsObj.totalCost || statisticsObj.totalCost == 0 ? statisticsObj.totalCost : '--' }};</span>
  69. </div>
  70. </a-alert>
  71. </div>
  72. <s-table
  73. class="sTable"
  74. ref="table"
  75. size="small"
  76. :rowKey="(record) => record.id"
  77. :columns="columns"
  78. :data="loadData"
  79. :defaultLoadData="false"
  80. bordered>
  81. <!--申请退货数量 -->
  82. <template slot="qty" slot-scope="text, record">
  83. <a-input-number
  84. id="purchaseReceiptEdit-qty"
  85. size="small"
  86. v-model="record.qty"
  87. :precision="0"
  88. :min="1"
  89. :max="record.qty"
  90. placeholder="请输入"
  91. style="width: 100%;"
  92. @blur="e => onCellBlur(e.target.value, record)"
  93. />
  94. </template>
  95. <!-- 操作 -->
  96. <template slot="action" slot-scope="text, record">
  97. <a-button
  98. size="small"
  99. type="link"
  100. v-if="$hasPermissions('B_purchaseReturnEdit')"
  101. @click="handleEdit(record)"
  102. class="button-info"
  103. id="purchaseReceiptEdit-edit-btn">编辑</a-button>
  104. <a-button
  105. size="small"
  106. type="link"
  107. :loading="delLoading"
  108. class="button-error"
  109. @click="handleDel(record)"
  110. id="purchaseReceiptEdit-del-btn">删除</a-button>
  111. </template>
  112. </s-table>
  113. </a-card>
  114. </a-spin>
  115. <div class="affix-cont">
  116. <a-button
  117. size="large"
  118. style="padding: 0 60px;"
  119. :disabled="spinning"
  120. type="primary"
  121. class="button-primary"
  122. @click="handleSubmit"
  123. id="purchaseReceiptEdit-submit">提交</a-button>
  124. </div>
  125. <!-- 新增弹窗-->
  126. <add-modal v-drag :openModal="openAddModal" @ok="handleOk" @close="openAddModal=false" />
  127. <!-- 导入弹窗 -->
  128. <importGuideModal :openModal="openGuideModal" :params="{sparePartsSn: $route.params.sn}" @close="openGuideModal=false" @ok="hanldeOk" />
  129. <!-- 编辑基础信息弹窗 -->
  130. <basic-info-modal v-drag :openModal="openBasicInfoModal" :itemSn="sparePartsReturnSn" @ok="getBasicsData" @close="openBasicInfoModal = false" />
  131. </div>
  132. </template>
  133. <script>
  134. import { commonMixin } from '@/utils/mixin'
  135. // 组件
  136. import { STable, VSelect } from '@/components'
  137. import addModal from './addModal.vue'
  138. import basicInfoModal from './basicInfoModal.vue'
  139. import importGuideModal from './importGuideModal.vue'
  140. // 接口
  141. import {
  142. sparePartsReturnQueryPage,
  143. queryPageCount,
  144. sparePartsReturnDetailDelete,
  145. sparePartsReturnDetailSave,
  146. sparePartsReturnSubmit,
  147. sparePartsReturnInfo,
  148. sparePartsReturnDetailSaveBatch
  149. } from '@/api/sparePartsReturn'
  150. import { getThirdStockQty } from '@/api/salesNew'
  151. export default {
  152. name: 'PurchaseReturnEdit',
  153. mixins: [commonMixin],
  154. components: { STable, VSelect, basicInfoModal, addModal, importGuideModal },
  155. data () {
  156. return {
  157. spinning: false,
  158. showDetail: false, // 是否显示基础信息
  159. delLoading: false, // 删除loading
  160. openAddModal: false, // 打开新增产品弹窗
  161. openBasicInfoModal: false, // 打开编辑基础信息弹窗
  162. openGuideModal: false, // 导入产品弹窗
  163. detailsData: null, // 基础信息数据
  164. isInster: false, // 是否正在添加产品
  165. addMoreLoading: false, // 防止多次添加 加载状态
  166. // 查询参数
  167. productForm: {
  168. productCode: '', // 产品编码
  169. productName: '' // 产品名称
  170. },
  171. statisticsObj: null, // 统计明细
  172. sparePartsReturnSn: null,
  173. sparePartsReturnNo: null,
  174. chooseList: [],
  175. // 加载数据方法 必须为 Promise 对象
  176. loadData: parameter => {
  177. this.productForm.sparePartsReturnSn = this.sparePartsReturnSn
  178. // 获取列表数据 有分页
  179. return sparePartsReturnQueryPage(Object.assign(parameter, this.productForm)).then(res => {
  180. let data
  181. if (res.status == 200) {
  182. data = res.data
  183. // 计算表格序号
  184. const no = (data.pageNo - 1) * data.pageSize
  185. for (var i = 0; i < data.list.length; i++) {
  186. data.list[i].no = no + i + 1
  187. }
  188. }
  189. this.chooseList = data.list
  190. return data
  191. })
  192. },
  193. grabFlag: undefined // 备注
  194. }
  195. },
  196. computed: {
  197. // 列表表头配置
  198. columns () {
  199. const _this = this
  200. const arr = [
  201. { title: '序号', dataIndex: 'no', align: 'center', width: '4%' },
  202. {
  203. title: '产品编码',
  204. dataIndex: 'product.code',
  205. width: '18%',
  206. align: 'center',
  207. customRender: function (text) {
  208. return text || '--'
  209. }
  210. },
  211. {
  212. title: '产品名称',
  213. dataIndex: 'product.name',
  214. width: '25%',
  215. align: 'left',
  216. customRender: function (text) {
  217. return text || '--'
  218. },
  219. ellipsis: true
  220. },
  221. {
  222. title: '单位',
  223. dataIndex: 'product.unit',
  224. align: 'center',
  225. width: '6%',
  226. customRender: function (text) {
  227. return text || '--'
  228. }
  229. },
  230. { title: '采购数量', align: 'center', width: '13%', scopedSlots: { customRender: 'qty' } },
  231. {
  232. title: '库存数量',
  233. dataIndex: 'stockBatchNo',
  234. align: 'center',
  235. width: '10%',
  236. customRender: function (text) {
  237. return text || '--'
  238. }
  239. },
  240. {
  241. title: '采购单价',
  242. dataIndex: 'cost',
  243. width: '8%',
  244. align: 'right',
  245. customRender: function (text) {
  246. return text || text == 0 ? _this.toThousands(text, 2) : '--'
  247. }
  248. },
  249. {
  250. title: '采购金额',
  251. dataIndex: 'totalCost',
  252. width: '8%',
  253. align: 'right',
  254. customRender: function (text) {
  255. return text || text == 0 ? _this.toThousands(text, 2) : '--'
  256. }
  257. },
  258. { title: '操作', scopedSlots: { customRender: 'action' }, width: '10%', align: 'center' }
  259. ]
  260. if (this.$hasPermissions('B_purchaseReturnEdit_costPrice')) {
  261. arr.splice(6, 0, {
  262. title: '退货单价',
  263. dataIndex: 'cost',
  264. width: '8%',
  265. align: 'right',
  266. customRender: function (text) {
  267. return text || text == 0 ? _this.toThousands(text, 2) : '--'
  268. }
  269. })
  270. arr.splice(8, 0, {
  271. title: '采购金额',
  272. dataIndex: 'totalCost',
  273. width: '8%',
  274. align: 'right',
  275. customRender: function (text) {
  276. return text || text == 0 ? _this.toThousands(text, 2) : '--'
  277. }
  278. })
  279. }
  280. return arr
  281. }
  282. },
  283. methods: {
  284. // 第三方库存
  285. handleThirdQty () {
  286. const params = {
  287. sparePartsSn: this.sparePartsSn
  288. }
  289. getThirdStockQty(params).then(res => {
  290. if (res.status == 200) {
  291. }
  292. })
  293. },
  294. // 编辑基础信息
  295. handleEditBase () {
  296. this.openBasicInfoModal = true
  297. },
  298. // 返回
  299. handleBack () {
  300. this.$router.push({ name: 'purchaseReceiptList', query: { closeLastOldTab: true } })
  301. },
  302. // 新增产品
  303. handleAdd () {
  304. this.openAddModal = true
  305. },
  306. // 导入产品
  307. handleImport () {
  308. this.openGuideModal = true
  309. },
  310. // 查询库存
  311. handleQueryQty () {},
  312. // 删除所选产品
  313. handleDel (row) {
  314. const _this = this
  315. this.$confirm({
  316. title: '提示',
  317. content: '确认要删除吗?',
  318. centered: true,
  319. closable: true,
  320. onOk () {
  321. _this.delLoading = true
  322. _this.spinning = true
  323. sparePartsReturnDetailDelete({ detailSn: row.sparePartsReturnDetailSn })
  324. .then(res => {
  325. if (res.status == 200) {
  326. _this.resetTable(false)
  327. _this.getStatisticsData()
  328. _this.getChooseList()
  329. _this.$refs.partQuery.refreshLength()
  330. }
  331. _this.$message.info(res.message)
  332. _this.delLoading = false
  333. _this.spinning = false
  334. })
  335. .catch(err => {
  336. _this.delLoading = false
  337. })
  338. }
  339. })
  340. },
  341. // 获取产品列表
  342. resetTable (flag) {
  343. this.$refs.table.refresh(flag)
  344. },
  345. // 重置
  346. resetSearchForm (flag) {
  347. this.productForm.productName = ''
  348. this.productForm.productCode = ''
  349. this.$refs.table.refresh(!!flag)
  350. },
  351. saveMoreProduct (data) {
  352. if (this.addMoreLoading) {
  353. // 防止多次添加产品
  354. return
  355. }
  356. this.addMoreLoading = true
  357. var ajax_data = []
  358. data.forEach(item => {
  359. const obj = {
  360. sparePartsReturnSn: this.sparePartsReturnSn,
  361. sparePartsReturnNo: this.sparePartsReturnNo,
  362. sparePartsDetailSn: item.sparePartsDetailSn,
  363. productSn: item.productSn,
  364. stockDetailSn: item.stockDetailSn,
  365. productCode: item.productCode,
  366. putQty: item.productQty, // 入库数量
  367. returnedQty: item.returnedQty, // 已退数量
  368. qty: item.qty, // 申退数量
  369. cost: item.productCost, // 成本
  370. stockBatchNo: item.sparePartsBatchNo, // 批次号
  371. warehouseSn: item.warehouseSn, // 仓库sn
  372. warehouseLocationSn: item.warehouseLocationSn, // 仓位sn
  373. sparePartsNo: item.sparePartsNo,
  374. sparePartsSn: item.sparePartsSn
  375. }
  376. ajax_data.push(obj)
  377. })
  378. this.saveMore(ajax_data)
  379. },
  380. saveEdit (params) {
  381. this.spinning = true
  382. sparePartsReturnDetailSave(params).then(res => {
  383. if (res.status == 200) {
  384. this.getStatisticsData()
  385. this.$refs.table.refresh(true)
  386. this.getChooseList()
  387. }
  388. this.isInster = false
  389. this.spinning = false
  390. this.addMoreLoading = false
  391. }).catch(err => {
  392. this.isInster = false
  393. })
  394. },
  395. saveMore (params) {
  396. this.spinning = true
  397. sparePartsReturnDetailSaveBatch(params)
  398. .then(res => {
  399. if (res.status == 200) {
  400. this.getStatisticsData()
  401. this.getChooseList()
  402. this.$refs.table.refresh(true)
  403. this.$refs.partQuery.refreshLength()
  404. }
  405. this.isInster = false
  406. this.spinning = false
  407. this.addMoreLoading = false
  408. })
  409. .catch(err => {
  410. this.isInster = false
  411. this.addMoreLoading = false
  412. this.spinning = false
  413. })
  414. },
  415. beforeSubmit () {
  416. if (this.chooseList.length > 0) {
  417. this.openDepartUserModal = true
  418. } else {
  419. this.$message.warning('请先添加要退货的产品!')
  420. }
  421. },
  422. // 提交采购退货
  423. handleSubmit (data) {
  424. this.spinning = true
  425. sparePartsReturnSubmit({ sparePartsReturnSn: this.sparePartsReturnSn, ...data }).then(res => {
  426. if (res.status == 200) {
  427. this.handleBack()
  428. this.$message.success(res.message)
  429. }
  430. this.spinning = false
  431. })
  432. },
  433. // 初始化
  434. pageInit () {
  435. this.supplierSn = this.$route.query.sn
  436. this.sparePartsReturnSn = this.$route.query.returnSn
  437. this.sparePartsReturnNo = this.$route.query.no
  438. this.getStatisticsData()
  439. this.getBasicsData()
  440. this.resetSearchForm(true)
  441. },
  442. getChooseList () {
  443. this.$refs.partQuery.pageInit(this.supplierSn, this.sparePartsReturnSn, this.detailsData ? this.detailsData.warehouseSn : undefined, this.detailsData.grabFlag)
  444. },
  445. // 获取页面统计数据
  446. getStatisticsData () {
  447. this.getBasicsData(true)
  448. queryPageCount({ sparePartsReturnSn: this.sparePartsReturnSn }).then(res => {
  449. if (res.status == 200) {
  450. if (res.data) {
  451. res.data.totalCost = res.data && (res.data.totalCost || res.data.totalCost == 0) ? this.toThousands(res.data.totalCost, 2) : '--'
  452. this.statisticsObj = res.data
  453. } else {
  454. this.statisticsObj = null
  455. }
  456. } else {
  457. this.statisticsObj = null
  458. }
  459. })
  460. },
  461. // 获取基础信息
  462. getBasicsData (flag) {
  463. sparePartsReturnInfo({ sn: this.sparePartsReturnSn }).then(res => {
  464. if (res.status == 200) {
  465. this.detailsData = res.data
  466. } else {
  467. this.detailsData = null
  468. }
  469. const _this = this
  470. if (!flag) {
  471. this.$nextTick(() => {
  472. _this.getChooseList()
  473. })
  474. }
  475. })
  476. }
  477. },
  478. mounted () {
  479. if (!this.$store.state.app.isNewTab) {
  480. // 页签刷新时调用
  481. this.pageInit()
  482. }
  483. },
  484. activated () {
  485. // 如果是新页签打开或者进入新的子页(例:存在列表第2条数据编辑页页签时再打开第4条数据的编辑页),则重置当前页面
  486. if (this.$store.state.app.isNewTab || !this.$store.state.app.isNewSubTab) {
  487. this.pageInit()
  488. }
  489. },
  490. beforeRouteEnter (to, from, next) {
  491. next(vm => {})
  492. }
  493. }
  494. </script>
  495. <style lang="less">
  496. .purchaseReceiptEdit-wrap {
  497. position: relative;
  498. height: 100%;
  499. padding-bottom: 51px;
  500. box-sizing: border-box;
  501. > .ant-spin-nested-loading {
  502. overflow-y: scroll;
  503. height: 100%;
  504. }
  505. .showBtn{
  506. display:flex;
  507. align-items:center;
  508. margin-bottom:10px;
  509. }
  510. .purchaseReceiptEdit-cont {
  511. margin-top: 6px;
  512. .ant-divider-horizontal {
  513. margin: 10px 0 24px;
  514. }
  515. .total-bar {
  516. display: flex;
  517. align-items: center;
  518. justify-content: space-between;
  519. > div {
  520. &:last-child {
  521. display: flex;
  522. align-items: center;
  523. justify-content: space-between;
  524. > div {
  525. padding: 0 10px;
  526. }
  527. }
  528. }
  529. }
  530. }
  531. }
  532. </style>