salesReturnEdit.vue 21 KB

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