salesReturnEdit.vue 18 KB

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