salesReturnEdit.vue 16 KB

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