salesReturnGrabEdit.vue 19 KB

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