edit.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  1. <template>
  2. <div class="salesReturnEdit-wrap">
  3. <a-spin :spinning="spinning" tip="Loading...">
  4. <a-page-header :ghost="false" :backIcon="false" class="salesReturnEdit-back">
  5. <!-- 自定义的二级文字标题 -->
  6. <template slot="subTitle">
  7. <a id="salesReturnEdit-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" class="button-default" @click.stop="handleEditBase" >
  14. <a-icon type="edit" /> 编辑备注
  15. </a-button>
  16. </template>
  17. </a-page-header>
  18. <a-card size="small" :bordered="false" class="salesReturnEdit-cont">
  19. <queryPart
  20. ref="partQuery"
  21. :newLoading="isInster"
  22. :addMoreLoading="addMoreLoading"
  23. @add="saveProduct"
  24. @bachAdd="saveMoreProduct"></queryPart>
  25. </a-card>
  26. <a-card size="small" :bordered="false" class="salesReturnEdit-cont">
  27. <a-alert style="margin-bottom: 10px;" type="info">
  28. <div slot="message" class="total-bar">
  29. <div v-if="detailData">
  30. <span>余额:{{ detailData && (detailData.qty || detailData.qty == 0) ? detailData.qty : '--' }};</span>
  31. <span>借方:{{ detailData && (detailData.qty || detailData.qty == 0) ? detailData.qty : '--' }};</span>
  32. <span>贷方:{{ detailData && (detailData.qty || detailData.qty == 0) ? detailData.qty : '--' }};</span>
  33. </div>
  34. </div>
  35. </a-alert>
  36. <div class="table-page-search-wrapper" style="display:flex;align-items: center;justify-content: space-between;">
  37. <div style="flex-grow:1;">
  38. <a-form layout="inline" @keyup.enter.native="$refs.table.refresh(true)">
  39. <a-row :gutter="15">
  40. <a-col :md="6" :sm="24">
  41. <a-form-item label="时间">
  42. <rangeDate id="accountStatement-rangeDate" ref="rangeDate" :value="creatDate" @change="dateChange" />
  43. </a-form-item>
  44. </a-col>
  45. <a-col :md="4" :sm="24">
  46. <a-form-item label="订单单号"><a-input id="accountStatement-orderNO" v-model.trim="productForm.sparePartsNo" allowClear placeholder="请输入入库单号" /></a-form-item>
  47. </a-col>
  48. <a-col :md="4" :sm="24">
  49. <a-form-item label="借贷类型">
  50. <v-select
  51. v-model="productForm.status"
  52. ref="status"
  53. id="accountStatement-status"
  54. code="FINANCE_BOOK_STATE"
  55. placeholder="请选择借贷类型"
  56. allowClear></v-select>
  57. </a-form-item>
  58. </a-col>
  59. <a-col :md="4" :sm="24">
  60. <a-form-item label="单据类型">
  61. <v-select
  62. v-model="productForm.status"
  63. ref="status"
  64. id="accountStatement-status"
  65. code="FINANCE_BOOK_STATE"
  66. placeholder="请选择单据类型"
  67. allowClear></v-select>
  68. </a-form-item>
  69. </a-col>
  70. <a-col :md="4" :sm="24" style="margin-bottom: 10px;">
  71. <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
  72. <a-button style="margin-left: 5px" @click="resetSearchForm">重置</a-button>
  73. </a-col>
  74. </a-row>
  75. </a-form>
  76. </div>
  77. </div>
  78. <!-- 已选配件列表 -->
  79. <s-table
  80. class="sTable"
  81. ref="table"
  82. size="small"
  83. :rowKey="(record) => record.id"
  84. :columns="columns"
  85. :data="loadData"
  86. :defaultLoadData="false"
  87. :scroll="{ y: 300 }"
  88. bordered>
  89. <!-- 备注 -->
  90. <template slot="remark" slot-scope="text, record">
  91. <div @dblclick.stop>
  92. <a-input
  93. size="small"
  94. v-model="record.remarks"
  95. style="width: 100%;"
  96. placeholder="请输入备注"/>
  97. </div>
  98. </template>
  99. <!-- 操作 -->
  100. <template slot="action" slot-scope="text, record">
  101. <a-button
  102. size="small"
  103. type="link"
  104. :loading="delLoading"
  105. class="button-error"
  106. @click="handleDel(record)"
  107. id="salesReturn-Del">删除</a-button>
  108. </template>
  109. </s-table>
  110. </a-card>
  111. </a-spin>
  112. <div class="affix-cont">
  113. <a-button
  114. size="large"
  115. style="padding: 0 60px;"
  116. :disabled="spinning"
  117. type="primary"
  118. class="button-primary"
  119. @click="handleSubmit"
  120. id="salesReturn-handleSubmit">提交</a-button>
  121. </div>
  122. <!-- 编辑基础信息弹窗 -->
  123. <baseModal v-drag :show="openModal" @cancel="openModal=false" @refashData="getBasicsData"></baseModal>
  124. </div>
  125. </template>
  126. <script>
  127. import { commonMixin } from '@/utils/mixin'
  128. import { STable, VSelect } from '@/components'
  129. import queryPart from './queryPart.vue'
  130. import baseModal from './baseModal.vue'
  131. import {
  132. sparePartsReturnQueryPage,
  133. queryPageCount,
  134. sparePartsReturnDetailDelete,
  135. sparePartsReturnDetailSave,
  136. sparePartsReturnSubmit,
  137. sparePartsReturnInfo,
  138. sparePartsReturnDetailSaveBatch
  139. } from '@/api/sparePartsReturn'
  140. import rangeDate from '@/views/common/rangeDate.vue'
  141. export default {
  142. name: 'AccountStatementEdit',
  143. mixins: [commonMixin],
  144. components: {
  145. STable,
  146. VSelect,
  147. queryPart,
  148. baseModal,
  149. rangeDate
  150. },
  151. data () {
  152. return {
  153. spinning: false,
  154. isInster: false, // 是否正在添加产品
  155. delLoading: false,
  156. productForm: {
  157. productName: '',
  158. productCode: '',
  159. sparePartsNo: '',
  160. orderBy: 'sprd.CREATE_DATE DESC'
  161. },
  162. creatDate: [],
  163. bookSn: null,
  164. sparePartsReturnNo: null,
  165. chooseList: [],
  166. // 加载数据方法 必须为 Promise 对象
  167. loadData: parameter => {
  168. this.productForm.bookSn = this.bookSn
  169. return sparePartsReturnQueryPage(Object.assign(parameter, this.productForm)).then(res => {
  170. let data
  171. if (res.status == 200) {
  172. data = res.data
  173. const no = (data.pageNo - 1) * data.pageSize
  174. for (var i = 0; i < data.list.length; i++) {
  175. data.list[i].no = no + i + 1
  176. }
  177. }
  178. this.chooseList = data.list
  179. return data
  180. })
  181. },
  182. openModal: false, // 修改信息弹窗
  183. detailData: null, // 统计明细
  184. detailsData: null, // 基础信息数据
  185. addMoreLoading: false, // 批量添加动画
  186. grabFlag: undefined
  187. }
  188. },
  189. computed: {
  190. columns () {
  191. const _this = this
  192. const arr = [
  193. { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
  194. { title: '年', dataIndex: 'sparePartsNo', width: '4%', align: 'center', customRender: function (text) { return text || '--' } },
  195. { title: '月', dataIndex: 'sparePartsNo', width: '4%', align: 'center', customRender: function (text) { return text || '--' } },
  196. { title: '日', dataIndex: 'sparePartsNo', width: '4%', align: 'center', customRender: function (text) { return text || '--' } },
  197. { title: '业务单号', dataIndex: 'sparePartsNo', width: '8%', align: 'center', customRender: function (text) { return text || '--' } },
  198. { title: '单据类型', dataIndex: 'product.code', width: '8%', align: 'center', customRender: function (text) { return text || '--' } },
  199. { title: '业务状态', dataIndex: 'product.name', width: '8%', align: 'left', customRender: function (text) { return text || '--' }, ellipsis: true },
  200. { title: '费用/调拨类型', dataIndex: 'product.unit', width: '8%', align: 'center', customRender: function (text) { return text || '--' } },
  201. { title: '摘要', dataIndex: 'sparePartsBatchNo', width: '10%', align: 'center', customRender: function (text) { return text || '--' } },
  202. { title: '客诉索赔编码', dataIndex: 'currentStockQty', width: '8%', align: 'center', customRender: function (text) { return (text || text == 0) ? text : '--' } },
  203. { title: '借方', dataIndex: 'productCost', width: '6%', align: 'right', customRender: function (text) { return ((text || text == 0) ? toThousands(text, 2) : '--') } },
  204. { title: '贷方', dataIndex: 'productCost', width: '6%', align: 'right', customRender: function (text) { return ((text || text == 0) ? toThousands(text, 2) : '--') } },
  205. { title: '备注', scopedSlots: { customRender: 'remark' }, width: '15%', align: 'center' },
  206. { title: '操作', scopedSlots: { customRender: 'action' }, width: '10%', align: 'center' }
  207. ]
  208. return arr
  209. }
  210. },
  211. methods: {
  212. // 编辑基础信息
  213. handleEditBase () {
  214. this.openModal = true
  215. },
  216. // 返回列表
  217. handleBack () {
  218. this.$router.push({ name: `accountStatementList` })
  219. },
  220. // 创建时间 change
  221. dateChange (date) {
  222. this.queryParam.beginDate = date[0] ? date[0] : ''
  223. this.queryParam.endDate = date[1] ? date[1] : ''
  224. },
  225. // 删除所选产品
  226. handleDel (row) {
  227. const _this = this
  228. this.$confirm({
  229. title: '提示',
  230. content: '确认要删除吗?',
  231. centered: true,
  232. closable: true,
  233. onOk () {
  234. _this.delLoading = true
  235. _this.spinning = true
  236. sparePartsReturnDetailDelete({ detailSn: row.sparePartsReturnDetailSn })
  237. .then(res => {
  238. if (res.status == 200) {
  239. _this.resetTable(false)
  240. _this.getStatisticsData()
  241. _this.getChooseList()
  242. _this.$refs.partQuery.refreshLength()
  243. }
  244. _this.$message.info(res.message)
  245. _this.delLoading = false
  246. _this.spinning = false
  247. })
  248. .catch(err => {
  249. _this.delLoading = false
  250. })
  251. }
  252. })
  253. },
  254. // 刷新已选表格
  255. resetTable (flag) {
  256. this.$refs.table.refresh(flag)
  257. },
  258. // 重置
  259. resetSearchForm (flag) {
  260. this.productForm.productName = ''
  261. this.productForm.productCode = ''
  262. this.productForm.sparePartsNo = ''
  263. this.creatDate = []
  264. this.$refs.rangeDate.resetDate(this.creatDate)
  265. this.$refs.table.refresh(!!flag)
  266. },
  267. // 已选产品 blur
  268. onCellBlur (val, record) {
  269. if (val * 1 > record.putQty * 1) {
  270. this.$message.warning('申请退货数量不能大于入库数量!')
  271. this.$refs.table.refresh(true)
  272. return
  273. }
  274. const ajax_data = {
  275. bookSn: this.bookSn,
  276. sparePartsReturnNo: this.sparePartsReturnNo,
  277. sparePartsDetailSn: record.sparePartsDetailSn,
  278. productSn: record.productSn,
  279. sparePartsReturnDetailSn: record.sparePartsReturnDetailSn,
  280. stockDetailSn: record.stockDetailSn,
  281. productCode: record.productCode,
  282. putQty: record.putQty, // 入库数量
  283. returnedQty: record.returnedQty, // 已退数量
  284. qty: val, // 申退数量
  285. cost: record.cost, // 成本
  286. stockBatchNo: record.stockBatchNo, // 批次号
  287. warehouseSn: record.warehouseSn, // 仓库sn
  288. warehouseLocationSn: record.warehouseLocationSn, // 仓位sn
  289. sparePartsNo: record.sparePartsNo,
  290. sparePartsSn: record.sparePartsSn
  291. }
  292. this.saveEdit(ajax_data)
  293. },
  294. // 添加或修改产品
  295. saveProduct (row) {
  296. if (this.isInster) {
  297. // 防止多次添加产品
  298. return
  299. }
  300. this.isInster = true
  301. const paramsData = {
  302. bookSn: this.bookSn,
  303. sparePartsReturnNo: this.sparePartsReturnNo,
  304. sparePartsDetailSn: row.sparePartsDetailSn,
  305. productSn: row.productSn,
  306. stockDetailSn: row.stockDetailSn,
  307. productCode: row.productCode,
  308. putQty: row.productQty, // 入库数量
  309. returnedQty: row.returnedQty, // 已退数量
  310. qty: row.qty, // 申退数量
  311. cost: row.productCost, // 成本
  312. stockBatchNo: row.sparePartsBatchNo, // 批次号
  313. warehouseSn: row.warehouseSn, // 仓库sn
  314. warehouseLocationSn: row.warehouseLocationSn, // 仓位sn
  315. sparePartsNo: row.sparePartsNo,
  316. sparePartsSn: row.sparePartsSn
  317. }
  318. this.saveEdit(paramsData)
  319. },
  320. saveMoreProduct (data) {
  321. if (this.addMoreLoading) {
  322. // 防止多次添加产品
  323. return
  324. }
  325. this.addMoreLoading = true
  326. var ajax_data = []
  327. data.forEach(item => {
  328. const obj = {
  329. bookSn: this.bookSn,
  330. sparePartsReturnNo: this.sparePartsReturnNo,
  331. sparePartsDetailSn: item.sparePartsDetailSn,
  332. productSn: item.productSn,
  333. stockDetailSn: item.stockDetailSn,
  334. productCode: item.productCode,
  335. putQty: item.productQty, // 入库数量
  336. returnedQty: item.returnedQty, // 已退数量
  337. qty: item.qty, // 申退数量
  338. cost: item.productCost, // 成本
  339. stockBatchNo: item.sparePartsBatchNo, // 批次号
  340. warehouseSn: item.warehouseSn, // 仓库sn
  341. warehouseLocationSn: item.warehouseLocationSn, // 仓位sn
  342. sparePartsNo: item.sparePartsNo,
  343. sparePartsSn: item.sparePartsSn
  344. }
  345. ajax_data.push(obj)
  346. })
  347. this.saveMore(ajax_data)
  348. },
  349. saveEdit (params) {
  350. this.spinning = true
  351. sparePartsReturnDetailSave(params).then(res => {
  352. if (res.status == 200) {
  353. this.getStatisticsData()
  354. this.$refs.table.refresh(true)
  355. this.getChooseList()
  356. }
  357. this.isInster = false
  358. this.spinning = false
  359. this.addMoreLoading = false
  360. }).catch(err => {
  361. this.isInster = false
  362. })
  363. },
  364. saveMore (params) {
  365. this.spinning = true
  366. sparePartsReturnDetailSaveBatch(params)
  367. .then(res => {
  368. if (res.status == 200) {
  369. this.getStatisticsData()
  370. this.getChooseList()
  371. this.$refs.table.refresh(true)
  372. this.$refs.partQuery.refreshLength()
  373. }
  374. this.isInster = false
  375. this.spinning = false
  376. this.addMoreLoading = false
  377. })
  378. .catch(err => {
  379. this.isInster = false
  380. this.addMoreLoading = false
  381. this.spinning = false
  382. })
  383. },
  384. // 提交采购退货
  385. handleSubmit (data) {
  386. this.spinning = true
  387. sparePartsReturnSubmit({ bookSn: this.bookSn, ...data }).then(res => {
  388. if (res.status == 200) {
  389. this.handleBack()
  390. this.$message.success(res.message)
  391. }
  392. this.spinning = false
  393. })
  394. },
  395. pageInit () {
  396. this.bookSn = this.$route.query.sn
  397. this.getStatisticsData()
  398. this.getBasicsData()
  399. this.resetSearchForm(true)
  400. },
  401. getChooseList () {
  402. this.$refs.partQuery.pageInit(this.supplierSn, this.bookSn, this.detailsData ? this.detailsData.warehouseSn : undefined, this.detailsData.grabFlag)
  403. },
  404. // 获取页面统计数据
  405. getStatisticsData () {
  406. this.getBasicsData(true)
  407. queryPageCount({ bookSn: this.bookSn }).then(res => {
  408. if (res.status == 200) {
  409. if (res.data) {
  410. res.data.totalCost = res.data && (res.data.totalCost || res.data.totalCost == 0) ? this.toThousands(res.data.totalCost, 2) : '--'
  411. this.detailData = res.data
  412. } else {
  413. this.detailData = null
  414. }
  415. } else {
  416. this.detailData = null
  417. }
  418. })
  419. },
  420. // 获取基础信息
  421. getBasicsData (flag) {
  422. sparePartsReturnInfo({ sn: this.bookSn }).then(res => {
  423. if (res.status == 200) {
  424. this.detailsData = res.data
  425. } else {
  426. this.detailsData = null
  427. }
  428. const _this = this
  429. if (!flag) {
  430. this.$nextTick(() => {
  431. _this.getChooseList()
  432. })
  433. }
  434. })
  435. }
  436. },
  437. mounted () {
  438. if (!this.$store.state.app.isNewTab) {
  439. // 页签刷新时调用
  440. this.pageInit()
  441. }
  442. },
  443. activated () {
  444. // 如果是新页签打开或者进入新的子页(例:存在列表第2条数据编辑页页签时再打开第4条数据的编辑页),则重置当前页面
  445. if (this.$store.state.app.isNewTab || !this.$store.state.app.isNewSubTab) {
  446. this.pageInit()
  447. }
  448. },
  449. beforeRouteEnter (to, from, next) {
  450. next(vm => {})
  451. }
  452. }
  453. </script>
  454. <style lang="less">
  455. .salesReturnEdit-wrap {
  456. position: relative;
  457. height: 100%;
  458. padding-bottom: 51px;
  459. box-sizing: border-box;
  460. > .ant-spin-nested-loading {
  461. overflow-y: scroll;
  462. height: 100%;
  463. }
  464. .salesReturnEdit-cont {
  465. margin-top: 6px;
  466. .ant-divider-horizontal {
  467. margin: 10px 0 24px;
  468. }
  469. .total-bar {
  470. display: flex;
  471. align-items: center;
  472. justify-content: space-between;
  473. > div {
  474. &:last-child {
  475. display: flex;
  476. align-items: center;
  477. justify-content: space-between;
  478. > div {
  479. padding: 0 10px;
  480. }
  481. }
  482. }
  483. }
  484. }
  485. }
  486. </style>