edit.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  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="handleQueryQty">查询库存</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. export default {
  151. name: 'PurchaseReturnEdit',
  152. mixins: [commonMixin],
  153. components: { STable, VSelect, basicInfoModal, addModal, importGuideModal },
  154. data () {
  155. return {
  156. spinning: false,
  157. showDetail: false, // 是否显示基础信息
  158. delLoading: false, // 删除loading
  159. openAddModal: false, // 打开新增产品弹窗
  160. openBasicInfoModal: false, // 打开编辑基础信息弹窗
  161. openGuideModal: false, // 导入产品弹窗
  162. detailsData: null, // 基础信息数据
  163. isInster: false, // 是否正在添加产品
  164. addMoreLoading: false, // 防止多次添加 加载状态
  165. // 查询参数
  166. productForm: {
  167. productCode: '', // 产品编码
  168. productName: '' // 产品名称
  169. },
  170. statisticsObj: null, // 统计明细
  171. sparePartsReturnSn: null,
  172. sparePartsReturnNo: null,
  173. chooseList: [],
  174. // 加载数据方法 必须为 Promise 对象
  175. loadData: parameter => {
  176. this.productForm.sparePartsReturnSn = this.sparePartsReturnSn
  177. // 获取列表数据 有分页
  178. return sparePartsReturnQueryPage(Object.assign(parameter, this.productForm)).then(res => {
  179. let data
  180. if (res.status == 200) {
  181. data = res.data
  182. // 计算表格序号
  183. const no = (data.pageNo - 1) * data.pageSize
  184. for (var i = 0; i < data.list.length; i++) {
  185. data.list[i].no = no + i + 1
  186. }
  187. }
  188. this.chooseList = data.list
  189. return data
  190. })
  191. },
  192. grabFlag: undefined // 备注
  193. }
  194. },
  195. computed: {
  196. // 列表表头配置
  197. columns () {
  198. const _this = this
  199. const arr = [
  200. { title: '序号', dataIndex: 'no', align: 'center', width: '4%' },
  201. {
  202. title: '产品编码',
  203. dataIndex: 'product.code',
  204. width: '18%',
  205. align: 'center',
  206. customRender: function (text) {
  207. return text || '--'
  208. }
  209. },
  210. {
  211. title: '产品名称',
  212. dataIndex: 'product.name',
  213. width: '25%',
  214. align: 'left',
  215. customRender: function (text) {
  216. return text || '--'
  217. },
  218. ellipsis: true
  219. },
  220. {
  221. title: '单位',
  222. dataIndex: 'product.unit',
  223. align: 'center',
  224. width: '6%',
  225. customRender: function (text) {
  226. return text || '--'
  227. }
  228. },
  229. { title: '采购数量', align: 'center', width: '13%', scopedSlots: { customRender: 'qty' } },
  230. {
  231. title: '库存数量',
  232. dataIndex: 'stockBatchNo',
  233. align: 'center',
  234. width: '10%',
  235. customRender: function (text) {
  236. return text || '--'
  237. }
  238. },
  239. {
  240. title: '采购单价',
  241. dataIndex: 'cost',
  242. width: '8%',
  243. align: 'right',
  244. customRender: function (text) {
  245. return text || text == 0 ? _this.toThousands(text, 2) : '--'
  246. }
  247. },
  248. {
  249. title: '采购金额',
  250. dataIndex: 'totalCost',
  251. width: '8%',
  252. align: 'right',
  253. customRender: function (text) {
  254. return text || text == 0 ? _this.toThousands(text, 2) : '--'
  255. }
  256. },
  257. { title: '操作', scopedSlots: { customRender: 'action' }, width: '10%', align: 'center' }
  258. ]
  259. if (this.$hasPermissions('B_purchaseReturnEdit_costPrice')) {
  260. arr.splice(6, 0, {
  261. title: '退货单价',
  262. dataIndex: 'cost',
  263. width: '8%',
  264. align: 'right',
  265. customRender: function (text) {
  266. return text || text == 0 ? _this.toThousands(text, 2) : '--'
  267. }
  268. })
  269. arr.splice(8, 0, {
  270. title: '采购金额',
  271. dataIndex: 'totalCost',
  272. width: '8%',
  273. align: 'right',
  274. customRender: function (text) {
  275. return text || text == 0 ? _this.toThousands(text, 2) : '--'
  276. }
  277. })
  278. }
  279. return arr
  280. }
  281. },
  282. methods: {
  283. // 编辑基础信息
  284. handleEditBase () {
  285. this.openBasicInfoModal = true
  286. },
  287. // 返回
  288. handleBack () {
  289. this.$router.push({ name: 'purchaseReceiptList', query: { closeLastOldTab: true } })
  290. },
  291. // 新增产品
  292. handleAdd () {
  293. this.openAddModal = true
  294. },
  295. // 导入产品
  296. handleImport () {
  297. this.openGuideModal = true
  298. },
  299. // 查询库存
  300. handleQueryQty () {},
  301. // 删除所选产品
  302. handleDel (row) {
  303. const _this = this
  304. this.$confirm({
  305. title: '提示',
  306. content: '确认要删除吗?',
  307. centered: true,
  308. closable: true,
  309. onOk () {
  310. _this.delLoading = true
  311. _this.spinning = true
  312. sparePartsReturnDetailDelete({ detailSn: row.sparePartsReturnDetailSn })
  313. .then(res => {
  314. if (res.status == 200) {
  315. _this.resetTable(false)
  316. _this.getStatisticsData()
  317. _this.getChooseList()
  318. _this.$refs.partQuery.refreshLength()
  319. }
  320. _this.$message.info(res.message)
  321. _this.delLoading = false
  322. _this.spinning = false
  323. })
  324. .catch(err => {
  325. _this.delLoading = false
  326. })
  327. }
  328. })
  329. },
  330. // 获取产品列表
  331. resetTable (flag) {
  332. this.$refs.table.refresh(flag)
  333. },
  334. // 重置
  335. resetSearchForm (flag) {
  336. this.productForm.productName = ''
  337. this.productForm.productCode = ''
  338. this.$refs.table.refresh(!!flag)
  339. },
  340. saveMoreProduct (data) {
  341. if (this.addMoreLoading) {
  342. // 防止多次添加产品
  343. return
  344. }
  345. this.addMoreLoading = true
  346. var ajax_data = []
  347. data.forEach(item => {
  348. const obj = {
  349. sparePartsReturnSn: this.sparePartsReturnSn,
  350. sparePartsReturnNo: this.sparePartsReturnNo,
  351. sparePartsDetailSn: item.sparePartsDetailSn,
  352. productSn: item.productSn,
  353. stockDetailSn: item.stockDetailSn,
  354. productCode: item.productCode,
  355. putQty: item.productQty, // 入库数量
  356. returnedQty: item.returnedQty, // 已退数量
  357. qty: item.qty, // 申退数量
  358. cost: item.productCost, // 成本
  359. stockBatchNo: item.sparePartsBatchNo, // 批次号
  360. warehouseSn: item.warehouseSn, // 仓库sn
  361. warehouseLocationSn: item.warehouseLocationSn, // 仓位sn
  362. sparePartsNo: item.sparePartsNo,
  363. sparePartsSn: item.sparePartsSn
  364. }
  365. ajax_data.push(obj)
  366. })
  367. this.saveMore(ajax_data)
  368. },
  369. saveEdit (params) {
  370. this.spinning = true
  371. sparePartsReturnDetailSave(params).then(res => {
  372. if (res.status == 200) {
  373. this.getStatisticsData()
  374. this.$refs.table.refresh(true)
  375. this.getChooseList()
  376. }
  377. this.isInster = false
  378. this.spinning = false
  379. this.addMoreLoading = false
  380. }).catch(err => {
  381. this.isInster = false
  382. })
  383. },
  384. saveMore (params) {
  385. this.spinning = true
  386. sparePartsReturnDetailSaveBatch(params)
  387. .then(res => {
  388. if (res.status == 200) {
  389. this.getStatisticsData()
  390. this.getChooseList()
  391. this.$refs.table.refresh(true)
  392. this.$refs.partQuery.refreshLength()
  393. }
  394. this.isInster = false
  395. this.spinning = false
  396. this.addMoreLoading = false
  397. })
  398. .catch(err => {
  399. this.isInster = false
  400. this.addMoreLoading = false
  401. this.spinning = false
  402. })
  403. },
  404. beforeSubmit () {
  405. if (this.chooseList.length > 0) {
  406. this.openDepartUserModal = true
  407. } else {
  408. this.$message.warning('请先添加要退货的产品!')
  409. }
  410. },
  411. // 提交采购退货
  412. handleSubmit (data) {
  413. this.spinning = true
  414. sparePartsReturnSubmit({ sparePartsReturnSn: this.sparePartsReturnSn, ...data }).then(res => {
  415. if (res.status == 200) {
  416. this.handleBack()
  417. this.$message.success(res.message)
  418. }
  419. this.spinning = false
  420. })
  421. },
  422. // 初始化
  423. pageInit () {
  424. this.supplierSn = this.$route.query.sn
  425. this.sparePartsReturnSn = this.$route.query.returnSn
  426. this.sparePartsReturnNo = this.$route.query.no
  427. this.getStatisticsData()
  428. this.getBasicsData()
  429. this.resetSearchForm(true)
  430. },
  431. getChooseList () {
  432. this.$refs.partQuery.pageInit(this.supplierSn, this.sparePartsReturnSn, this.detailsData ? this.detailsData.warehouseSn : undefined, this.detailsData.grabFlag)
  433. },
  434. // 获取页面统计数据
  435. getStatisticsData () {
  436. this.getBasicsData(true)
  437. queryPageCount({ sparePartsReturnSn: this.sparePartsReturnSn }).then(res => {
  438. if (res.status == 200) {
  439. if (res.data) {
  440. res.data.totalCost = res.data && (res.data.totalCost || res.data.totalCost == 0) ? this.toThousands(res.data.totalCost, 2) : '--'
  441. this.statisticsObj = res.data
  442. } else {
  443. this.statisticsObj = null
  444. }
  445. } else {
  446. this.statisticsObj = null
  447. }
  448. })
  449. },
  450. // 获取基础信息
  451. getBasicsData (flag) {
  452. sparePartsReturnInfo({ sn: this.sparePartsReturnSn }).then(res => {
  453. if (res.status == 200) {
  454. this.detailsData = res.data
  455. } else {
  456. this.detailsData = null
  457. }
  458. const _this = this
  459. if (!flag) {
  460. this.$nextTick(() => {
  461. _this.getChooseList()
  462. })
  463. }
  464. })
  465. }
  466. },
  467. mounted () {
  468. if (!this.$store.state.app.isNewTab) {
  469. // 页签刷新时调用
  470. this.pageInit()
  471. }
  472. },
  473. activated () {
  474. // 如果是新页签打开或者进入新的子页(例:存在列表第2条数据编辑页页签时再打开第4条数据的编辑页),则重置当前页面
  475. if (this.$store.state.app.isNewTab || !this.$store.state.app.isNewSubTab) {
  476. this.pageInit()
  477. }
  478. },
  479. beforeRouteEnter (to, from, next) {
  480. next(vm => {})
  481. }
  482. }
  483. </script>
  484. <style lang="less">
  485. .purchaseReceiptEdit-wrap {
  486. position: relative;
  487. height: 100%;
  488. padding-bottom: 51px;
  489. box-sizing: border-box;
  490. > .ant-spin-nested-loading {
  491. overflow-y: scroll;
  492. height: 100%;
  493. }
  494. .showBtn{
  495. display:flex;
  496. align-items:center;
  497. margin-bottom:10px;
  498. }
  499. .purchaseReceiptEdit-cont {
  500. margin-top: 6px;
  501. .ant-divider-horizontal {
  502. margin: 10px 0 24px;
  503. }
  504. .total-bar {
  505. display: flex;
  506. align-items: center;
  507. justify-content: space-between;
  508. > div {
  509. &:last-child {
  510. display: flex;
  511. align-items: center;
  512. justify-content: space-between;
  513. > div {
  514. padding: 0 10px;
  515. }
  516. }
  517. }
  518. }
  519. }
  520. }
  521. </style>