salesReturnEdit.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  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"><a-icon type="left" /> 返回列表</a>
  8. <span style="margin: 0 15px;color: #666;">客户名称:{{ (ordeDetail&&ordeDetail.buyerName) || '--' }}</span>
  9. </template>
  10. <!-- 操作区,位于 title 行的行尾 -->
  11. <template slot="extra" v-if="$hasPermissions('B_salesReturnPrint')">
  12. <a-radio-group key="4" v-model="printerType">
  13. <a-radio value="NEEDLE">针式</a-radio>
  14. <a-radio value="INK">喷墨</a-radio>
  15. </a-radio-group>
  16. <a-button key="3" id="salesReturnEdit-preview-btn" :disabled="chooseLoadData.length==0" @click="handlePrint('preview')">打印预览</a-button>
  17. <a-button key="2" type="primary" id="salesReturnEdit-print-btn" :disabled="chooseLoadData.length==0" @click="handlePrint('print')">快捷打印</a-button>
  18. <a-button
  19. key="1"
  20. type="primary"
  21. class="button-warning"
  22. id="salesReturnEdit-export-btn"
  23. :disabled="chooseLoadData.length==0"
  24. @click="handlePrint('export')">导出Excel</a-button>
  25. </template>
  26. </a-page-header>
  27. <a-card size="small" :bordered="false" class="pages-wrap">
  28. <!-- 查询配件列表 -->
  29. <queryPart :buyerSn="$route.params.buyerSn" :priceType="ordeDetail&&ordeDetail.priceType||''" grabFlag="0" :newLoading="isInster" @add="saveProduct"></queryPart>
  30. </a-card>
  31. <a-card size="small" :bordered="false" class="pages-wrap">
  32. <!-- alert -->
  33. <a-alert style="margin-bottom: 10px;" type="info">
  34. <div slot="message" class="total-bar">
  35. <div v-if="countData">
  36. <span>退货总金额:{{ countData&&(countData.totalAmount || countData.totalAmount==0) ? countData.totalAmount : '--' }}元;</span>
  37. <span>总款数:{{ countData&&(countData.totalCategory || countData.totalCategory==0) ? countData.totalCategory : '--' }};</span>
  38. <span>总数量:{{ countData&&(countData.totalQty || countData.totalQty==0) ? countData.totalQty : '--' }};</span>
  39. <span>废品总数量:{{ countData&&(countData.totalCelQty || countData.totalCelQty==0) ? countData.totalCelQty : '--' }};</span>
  40. </div>
  41. <div v-if="ordeDetail">
  42. <div>
  43. 折扣金额:
  44. <a-input-number id="discount" v-model="ordeDetail.discountAmount" :min="0" :precision="2" :max="999999"/>
  45. <a-button type="primary" @click="salesReturnDiscount" class="button-info">打折</a-button>
  46. </div>
  47. <div>
  48. 折扣:<strong>{{ ordeDetail&&(ordeDetail.discountRate || ordeDetail.discountRate==0) ? ordeDetail.discountRate+'%' : '--' }}</strong>;
  49. 折后总售价:<strong>{{ ordeDetail&&(ordeDetail.discountedAmount || ordeDetail.discountedAmount==0) ? '¥'+ordeDetail.discountedAmount : '--' }}</strong>;
  50. </div>
  51. </div>
  52. </div>
  53. </a-alert>
  54. <!-- 搜索条件 -->
  55. <div class="table-page-search-wrapper">
  56. <a-row :gutter="15">
  57. <a-col :span="18">
  58. <a-form-model layout="inline" :model="productForm" @keyup.enter.native="$refs.table.refresh(true)">
  59. <a-row :gutter="15">
  60. <a-col :md="8" :sm="24">
  61. <a-form-model-item label="产品编码">
  62. <a-input v-model="productForm.productCode" allowClear placeholder="输入产品编码" />
  63. </a-form-model-item>
  64. </a-col>
  65. <a-col :md="8" :sm="24">
  66. <a-form-model-item label="产品名称">
  67. <a-input v-model="productForm.productName" allowClear placeholder="输入产品名称" />
  68. </a-form-model-item>
  69. </a-col>
  70. <a-col :md="8" :sm="24">
  71. <a-form-model-item>
  72. <a-button type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="salesReturn-refresh">查询</a-button>
  73. <a-button style="margin-left: 5px" @click="resetForm" id="salesReturn-reset">重置</a-button>
  74. </a-form-model-item>
  75. </a-col>
  76. </a-row>
  77. </a-form-model>
  78. </a-col>
  79. <a-col :span="6">
  80. <div style="float:right;overflow: hidden;">
  81. <!-- <a-button id="salesReturn-dru">导入明细</a-button> -->
  82. <a-button
  83. size="small"
  84. type="primary"
  85. @click="salesReturnDelAll"
  86. :loading="delLoading"
  87. style="margin-left: 10px"
  88. id="salesReturn-del-all">整单删除</a-button>
  89. </div>
  90. </a-col>
  91. </a-row>
  92. </div>
  93. <!-- 已选配件列表 -->
  94. <s-table
  95. class="sTable"
  96. ref="table"
  97. size="small"
  98. :rowKey="(record) => record.id"
  99. :columns="columns"
  100. :data="loadData"
  101. :scroll="{ x: 1620, y: 300 }"
  102. bordered>
  103. <!-- 本次退货数量 -->
  104. <template slot="qty" slot-scope="text, record">
  105. <a-input-number
  106. id="salesReturn-qty"
  107. size="small"
  108. v-model="record.qty"
  109. :precision="0"
  110. :min="0"
  111. :max="999999"
  112. placeholder="请输入"
  113. @blur="e => onCellBlur(e.target.value, record, 'qty')"
  114. style="width: 100%;" />
  115. </template>
  116. <!-- 废品数量 -->
  117. <template slot="celQty" slot-scope="text, record">
  118. <a-input-number
  119. id="salesReturn-celQty"
  120. size="small"
  121. v-model="record.celQty"
  122. :precision="0"
  123. :min="0"
  124. :max="999999"
  125. placeholder="请输入"
  126. @blur="e => onCellBlur(e.target.value, record, 'celQty')"
  127. style="width: 100%;" />
  128. </template>
  129. <!-- 价格 -->
  130. <template slot="price" slot-scope="text, record">
  131. <a-input-number
  132. id="salesReturn-price"
  133. size="small"
  134. v-model="record.price"
  135. :precision="2"
  136. :min="0"
  137. :max="999999"
  138. placeholder="请输入"
  139. @blur="e => onCellBlur(e.target.value, record, 'price')"
  140. style="width: 100%;" />
  141. </template>
  142. <!-- 退货金额小计 -->
  143. <template slot="returnAmount" slot-scope="text, record">
  144. ¥{{ (record.price * record.qty).toFixed(2) }}
  145. </template>
  146. <!-- 仓库仓位 -->
  147. <template slot="warehouse" slot-scope="text, record, index">
  148. <a-cascader
  149. size="small"
  150. @change="e => changeWarehouseCascade(e, record, index)"
  151. v-model="record.warehouseCascade"
  152. expand-trigger="hover"
  153. :options="warehouseCascadeData"
  154. :fieldNames="{ label: 'name', value: 'sn', children: 'warehouseLocationList' }"
  155. id="bulkWarehousingOrderEdit-warehouseCascade"
  156. placeholder="请选择仓库仓位"
  157. style="width: 100%;" />
  158. </template>
  159. <!-- 操作 -->
  160. <template slot="action" slot-scope="text, record">
  161. <a-button
  162. size="small"
  163. type="primary"
  164. :loading="delLoading"
  165. class="button-error"
  166. @click="handleDel(record)"
  167. id="salesReturn-Del">删除</a-button>
  168. </template>
  169. </s-table>
  170. </a-card>
  171. </a-spin>
  172. <div class="affix-cont">
  173. <a-button
  174. size="large"
  175. style="padding: 0 60px;"
  176. type="primary"
  177. :disabled="spinning"
  178. class="button-primary"
  179. @click="handleSubmit()"
  180. id="salesReturn-handleSubmit">提交</a-button>
  181. </div>
  182. <!-- 选择客户弹框 -->
  183. <choose-custom-modal :show="openModal" @ok="chooseCustomOk" @cancel="openModal=false"></choose-custom-modal>
  184. <!-- 打印 -->
  185. <div id="print"></div>
  186. </div>
  187. </template>
  188. <script>
  189. import moment from 'moment'
  190. import { STable, VSelect } from '@/components'
  191. import queryPart from './queryPart.vue'
  192. import chooseCustomModal from './chooseCustomModal.vue'
  193. import { warehouseCascadeList } from '@/api/warehouse'
  194. import { salesReturnDetail, salesReturnQueryCount, salesReturnDetailList, salesReturnDiscount, salesReturnDelAll, salesReturnDetailDel, salesReturnSaveProduct, salesReturnSubmit, salesReturnDetailPrint, salesDetailExport } from '@/api/salesReturn'
  195. export default {
  196. name: 'SalesDetail',
  197. components: {
  198. STable,
  199. VSelect,
  200. queryPart,
  201. chooseCustomModal
  202. },
  203. data () {
  204. return {
  205. spinning: false,
  206. orderId: null,
  207. orderSn: null,
  208. buyerSn: null,
  209. disabled: false,
  210. openModal: false,
  211. isInster: false, // 是否正在添加产品
  212. ordeDetail: { discountAmount: 0 },
  213. delLoading: false,
  214. warehouseCascadeData: [], // 仓库仓位
  215. // 已选产品
  216. dataSource: [],
  217. productForm: {
  218. productCode: '',
  219. productName: ''
  220. },
  221. countData: null,
  222. // 表头
  223. columns: [
  224. { title: '序号', dataIndex: 'no', align: 'center', width: 80 },
  225. { title: '产品编码', dataIndex: 'dealerProductEntity.code', align: 'center', width: 220, customRender: function (text) { return text || '--' } },
  226. { title: '产品名称', dataIndex: 'dealerProductEntity.name', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  227. { title: '原厂编码', dataIndex: 'dealerProductEntity.origCode', align: 'center', width: 220, customRender: function (text) { return text || '--' } },
  228. { title: '售价', dataIndex: 'price', align: 'center', width: 100, scopedSlots: { customRender: 'price' } },
  229. { title: '单位', dataIndex: 'dealerProductEntity.unit', align: 'center', width: 60, customRender: function (text) { return text || '--' } },
  230. { title: '仓库仓位', scopedSlots: { customRender: 'warehouse' }, width: 200, align: 'center' },
  231. { title: '退货数量', dataIndex: 'qty', align: 'center', width: 100, scopedSlots: { customRender: 'qty' } },
  232. { title: '废品数量', dataIndex: 'celQty', align: 'center', width: 100, scopedSlots: { customRender: 'celQty' } },
  233. { title: '退货金额小计', align: 'center', scopedSlots: { customRender: 'returnAmount' }, width: 120 },
  234. { title: '折后金额小计', dataIndex: 'discountedAmount', align: 'center', width: 120, customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  235. { title: '操作', scopedSlots: { customRender: 'action' }, width: 80, align: 'center', fixed: 'right' }
  236. ],
  237. chooseLoadData: [],
  238. // 加载数据方法 必须为 Promise 对象
  239. loadData: parameter => {
  240. this.disabled = true
  241. // 查询总计
  242. this.productForm.salesReturnBillSn = this.$route.params.sn
  243. this.getQueryCount(Object.assign(parameter, this.productForm))
  244. return salesReturnDetailList(Object.assign(parameter, this.productForm)).then(res => {
  245. const data = res.data
  246. const no = (data.pageNo - 1) * data.pageSize
  247. for (var i = 0; i < data.list.length; i++) {
  248. data.list[i].no = no + i + 1
  249. data.list[i].qtyBackups = data.list[i].qty
  250. data.list[i].celQtyBackups = data.list[i].celQty
  251. data.list[i].priceBackups = data.list[i].price
  252. const warehouseSn = data.list[i].warehouseSn || undefined
  253. const warehouseLocationSn = data.list[i].warehouseLocationSn || undefined
  254. if (warehouseSn || warehouseLocationSn) {
  255. data.list[i].warehouseSnBackups = warehouseSn
  256. data.list[i].warehouseLocationSnBackups = warehouseLocationSn
  257. data.list[i].warehouseCascade = [warehouseSn, warehouseLocationSn]
  258. } else {
  259. data.list[i].warehouseCascade = undefined
  260. }
  261. }
  262. this.disabled = false
  263. this.chooseLoadData = data.list
  264. return data
  265. })
  266. },
  267. printerType: 'NEEDLE' // 打印机类型
  268. }
  269. },
  270. methods: {
  271. // 返回
  272. handleBack () {
  273. this.$router.push({ path: '/salesManagement/salesReturn/list', query: { closeLastOldTab: true } })
  274. },
  275. // 选择客户成功
  276. chooseCustomOk (data) {},
  277. handleEditCustom () {
  278. this.openModal = true
  279. },
  280. // 已选产品 blur
  281. onCellBlur (val, record, type) {
  282. let valBackups
  283. if (type == 'qty') {
  284. valBackups = record.qtyBackups
  285. } else if (type == 'celQty') {
  286. valBackups = record.celQtyBackups
  287. } else if (type == 'price') {
  288. valBackups = record.priceBackups
  289. }
  290. // 光标移出,值发生改变再调用编辑接口
  291. if (val && val != valBackups) {
  292. if (Number(record.celQty) > Number(record.qty)) {
  293. this.$message.info('废品数量不可大于本次退货数量')
  294. this.reductionVal(record, type, valBackups)
  295. } else {
  296. this.saveProduct(record, 'edit')
  297. }
  298. } else {
  299. this.reductionVal(record, type, valBackups)
  300. }
  301. },
  302. reductionVal (record, type, valBackups) {
  303. if (type == 'qty') {
  304. record.qty = valBackups
  305. } else if (type == 'celQty') {
  306. record.celQty = valBackups
  307. } else if (type == 'price') {
  308. record.price = valBackups
  309. }
  310. },
  311. // 仓库仓位 级联 列表
  312. getWarehouseCascade () {
  313. warehouseCascadeList({}).then(res => {
  314. if (res.status == 200) {
  315. res.data.map(item => {
  316. item.sn = item.warehouseSn
  317. if (item.warehouseLocationList) {
  318. item.warehouseLocationList.map(subItem => {
  319. subItem.sn = subItem.warehouseLocationSn
  320. })
  321. }
  322. })
  323. this.warehouseCascadeData = res.data
  324. } else {
  325. this.warehouseCascadeData = []
  326. }
  327. })
  328. },
  329. // 修改仓库仓位
  330. changeWarehouseCascade (val, opt, ind) {
  331. let loadData = this.chooseLoadData[ind]
  332. if (val.length < 2) {
  333. this.$message.warning('当前仓库无仓位,请选择其他仓库')
  334. const warehouseSnBackups = loadData.warehouseSnBackups || undefined
  335. const warehouseLocationSnBackups = loadData.warehouseLocationSnBackups || undefined
  336. loadData.warehouseSn = warehouseSnBackups
  337. loadData.warehouseLocationSn = warehouseLocationSnBackups
  338. if (warehouseSnBackups || warehouseLocationSnBackups) {
  339. loadData.warehouseCascade = [warehouseSnBackups, warehouseLocationSnBackups]
  340. } else {
  341. loadData.warehouseCascade = undefined
  342. }
  343. } else {
  344. loadData.warehouseSn = val[0] ? val[0] : ''
  345. loadData.warehouseLocationSn = val[1] ? val[1] : ''
  346. loadData.warehouseSnBackups = val[0] ? val[0] : ''
  347. loadData.warehouseLocationSnBackups = val[1] ? val[1] : ''
  348. loadData = this.chooseLoadData[ind]
  349. this.saveProduct(loadData, 'edit')
  350. }
  351. },
  352. // 重置列表
  353. resetForm () {
  354. this.productForm = {
  355. productName: '',
  356. productCode: ''
  357. }
  358. this.$refs.table.refresh(true)
  359. },
  360. // 明细统计
  361. getQueryCount (params) {
  362. salesReturnQueryCount(params).then(res => {
  363. this.countData = res.data || null
  364. })
  365. },
  366. // 获取单据详细
  367. getOrderDetail () {
  368. salesReturnDetail({ sn: this.orderSn }).then(res => {
  369. this.ordeDetail = res.data || null
  370. })
  371. },
  372. // 打折
  373. salesReturnDiscount () {
  374. if (this.ordeDetail.discountAmount < 0) {
  375. return
  376. }
  377. this.spinning = true
  378. salesReturnDiscount({
  379. discountAmount: this.ordeDetail.discountAmount,
  380. salesReturnSn: this.ordeDetail.salesReturnSn,
  381. id: this.ordeDetail.id
  382. }).then(res => {
  383. if (res.status == 200) {
  384. this.resetSearchForm()
  385. this.spinning = false
  386. } else {
  387. this.spinning = false
  388. }
  389. })
  390. },
  391. // 整单删除
  392. salesReturnDelAll () {
  393. const _this = this
  394. this.$confirm({
  395. title: '提示',
  396. content: '确认要整单删除吗?',
  397. centered: true,
  398. closable: true,
  399. onOk () {
  400. _this.delLoading = true
  401. _this.spinning = true
  402. salesReturnDelAll({ sn: _this.ordeDetail.salesReturnSn }).then(res => {
  403. if (res.status == 200) {
  404. _this.resetSearchForm()
  405. }
  406. _this.$message.info(res.message)
  407. _this.delLoading = false
  408. _this.spinning = false
  409. })
  410. }
  411. })
  412. },
  413. // 删除产品
  414. handleDel (row) {
  415. const _this = this
  416. this.$confirm({
  417. title: '提示',
  418. content: '确认要删除吗?',
  419. centered: true,
  420. closable: true,
  421. onOk () {
  422. _this.delLoading = true
  423. _this.spinning = true
  424. salesReturnDetailDel({ id: row.id }).then(res => {
  425. if (res.status == 200) {
  426. _this.resetSearchForm(true)
  427. }
  428. _this.$message.info(res.message)
  429. _this.delLoading = false
  430. _this.spinning = false
  431. })
  432. }
  433. })
  434. },
  435. // 重置
  436. resetSearchForm (flag) {
  437. this.$refs.table.refresh(!!flag)
  438. this.getOrderDetail()
  439. },
  440. // 添加或修改产品
  441. saveProduct (row, type) {
  442. console.log(row)
  443. // 防止多次添加产品
  444. if (this.isInster) {
  445. return
  446. }
  447. this.isInster = true
  448. const params = {
  449. 'salesReturnBillSn': this.orderSn,
  450. 'salesReturnBillNo': this.ordeDetail.salesReturnNo,
  451. 'salesBillSn': row.salesBillSn,
  452. 'salesBillNo': row.salesBillNo,
  453. 'salesBillDetailSn': row.salesBillDetailSn,
  454. 'price': type == 'edit' ? row.price : row.salePrice,
  455. 'cost': row.putCost,
  456. 'productSn': row.productSn,
  457. 'celQty': row.celQty,
  458. 'hasReturnQty': row.hasReturnQty,
  459. 'warehouseLocationSn': row.warehouseLocationSn,
  460. 'warehouseSn': row.warehouseSn
  461. }
  462. // 编辑
  463. if (type == 'edit') {
  464. params.id = row.id
  465. params.qty = row.qty
  466. } else {
  467. params.salesQty = row.qty
  468. }
  469. this.spinning = true
  470. salesReturnSaveProduct(params).then(res => {
  471. this.resetSearchForm(true)
  472. this.isInster = false
  473. this.spinning = false
  474. })
  475. },
  476. // 提交销售单
  477. handleSubmit () {
  478. this.spinning = true
  479. salesReturnSubmit({ sn: this.orderSn }).then(res => {
  480. if (res.status == 200) {
  481. this.handleBack()
  482. this.$message.success(res.message)
  483. this.spinning = false
  484. } else {
  485. this.spinning = false
  486. }
  487. })
  488. },
  489. // 打印预览/快捷打印
  490. handlePrint (type) {
  491. const _this = this
  492. _this.spinning = true
  493. let url = salesReturnDetailPrint
  494. let params = { sn: this.$route.params.sn, type: this.printerType }
  495. if (type == 'export') { // 导出
  496. url = salesDetailExport
  497. params = { sn: this.$route.params.sn }
  498. }
  499. url(params).then(res => {
  500. _this.spinning = false
  501. if (res.type == 'application/json') {
  502. var reader = new FileReader()
  503. reader.addEventListener('loadend', function () {
  504. const obj = JSON.parse(reader.result)
  505. _this.$notification.error({
  506. message: '提示',
  507. description: obj.message
  508. })
  509. })
  510. reader.readAsText(res)
  511. } else {
  512. if (type == 'export') { // 导出
  513. this.download(res)
  514. } else {
  515. this.print(res, type)
  516. }
  517. }
  518. })
  519. },
  520. print (data, type) {
  521. if (!data) {
  522. return
  523. }
  524. const url = window.URL.createObjectURL(new Blob([data], { type: 'application/pdf' }))
  525. document.getElementById('print').innerHTML = '<iframe id="printf" name="printf" src="' + url + '" hidden></iframe>'
  526. if (type == 'preview') { // 预览
  527. window.open(url)
  528. } else if (type == 'print') { // 打印
  529. window.frames['printf'].focus()
  530. window.frames['printf'].print()
  531. }
  532. },
  533. download (data) {
  534. if (!data) { return }
  535. const url = window.URL.createObjectURL(new Blob([data]))
  536. const link = document.createElement('a')
  537. link.style.display = 'none'
  538. link.href = url
  539. const a = moment().format('YYYYMMDDHHmmss')
  540. const fname = '销售退货' + a
  541. link.setAttribute('download', fname + '.xlsx')
  542. document.body.appendChild(link)
  543. link.click()
  544. }
  545. },
  546. mounted () {
  547. this.orderId = this.$route.params.id
  548. this.orderSn = this.$route.params.sn
  549. this.buyerSn = this.$route.params.buyerSn
  550. this.getOrderDetail()
  551. this.getWarehouseCascade()
  552. },
  553. beforeRouteEnter (to, from, next) {
  554. next(vm => {})
  555. }
  556. }
  557. </script>
  558. <style lang="less">
  559. .salesReturnEdit-wrap{
  560. position: relative;
  561. height: 100%;
  562. padding-bottom: 51px;
  563. box-sizing: border-box;
  564. >.ant-spin-nested-loading{
  565. overflow-y: scroll;
  566. height: 100%;
  567. }
  568. .pages-wrap{
  569. margin-top: 10px;
  570. .total-bar{
  571. display: flex;
  572. align-items: center;
  573. justify-content: space-between;
  574. > div{
  575. &:last-child{
  576. display: flex;
  577. align-items: center;
  578. justify-content: space-between;
  579. > div{
  580. padding: 0 10px;
  581. }
  582. }
  583. }
  584. }
  585. }
  586. }
  587. </style>