salesReturnEdit.vue 19 KB

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