edit.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. <template>
  2. <div class="salesEdit-wrap">
  3. <a-spin :spinning="spinning" tip="Loading...">
  4. <a-page-header :ghost="false" :backIcon="false" @back="handleBack" >
  5. <!-- 自定义的二级文字标题 -->
  6. <template slot="subTitle">
  7. <a id="salesEdit-back-btn" href="javascript:;" @click="handleBack"><a-icon type="left" /> 返回列表</a>
  8. <span style="margin: 0 15px;color: #666;">客户名称:{{ detailData&&detailData.buyerName }}</span>
  9. <!-- <a-button id="salesEdit-edit-btn" size="small" @click="handleEdit" style="margin-left:10px" key="0">编辑</a-button> -->
  10. </template>
  11. <!-- 操作区,位于 title 行的行尾 -->
  12. <!-- <template slot="extra">
  13. <a-button key="2" id="salesEdit-preview-btn">打印预览</a-button>
  14. <a-button key="1" type="primary" id="salesEdit-print-btn">快速打印</a-button>
  15. </template> -->
  16. </a-page-header>
  17. <a-card size="small" :bordered="false" class="salesEdit-cont">
  18. <div slot="title">
  19. <div class="p-title">
  20. 选择产品
  21. </div>
  22. </div>
  23. <!-- 查询配件列表 -->
  24. <queryPart ref="partQuery" :buyerSn="detailData&&detailData.buyerSn" :newLoading="isInster" @add="insterProduct"></queryPart>
  25. </a-card>
  26. <a-card size="small" :bordered="false" class="salesEdit-cont">
  27. <div slot="title">
  28. <a-row :gutter="15" type="flex">
  29. <a-col :span="2">
  30. <div class="p-title">
  31. 已选产品
  32. </div>
  33. </a-col>
  34. <a-col :span="16" v-if="activeName">
  35. <div class="p-notes">
  36. <a-icon style="color: #FF9900;" type="bell" /> 已选产品可参加<span>{{ activeName }}</span>的促销活动,促销产品为指定产品
  37. </div>
  38. </a-col>
  39. <!-- <a-col :span="6">
  40. <div style="float:right;overflow: hidden;">
  41. <a-button size="small" id="salesEdit-dru">导入明细</a-button>
  42. <a-button
  43. size="small"
  44. type="primary"
  45. @click="delSalerDetailAll"
  46. :loading="delLoading"
  47. style="margin-left: 10px"
  48. id="salesEdit-del-all">整单删除</a-button>
  49. </div>
  50. </a-col> -->
  51. </a-row>
  52. </div>
  53. <!-- 总计 -->
  54. <a-alert type="info" style="margin-bottom: 10px;">
  55. <div slot="message" class="total-bar">
  56. <div>
  57. 总售价:<strong>¥{{ detailData&&(detailData.totalCommonAmount || detailData.totalCommonAmount==0) ? detailData.totalCommonAmount : '--' }}</strong>;
  58. 总款数:<strong>{{ detailData&&(detailData.totalCommonCategory || detailData.totalCommonCategory==0) ? detailData.totalCommonCategory : '--' }}</strong>;
  59. 总数量:<strong>{{ detailData&&(detailData.totalCommonQty || detailData.totalCommonQty==0) ? detailData.totalCommonQty : '--' }}</strong>;
  60. </div>
  61. <div>
  62. </div>
  63. </div>
  64. </a-alert>
  65. <!-- 已选配件列表 -->
  66. <s-table
  67. class="sTable"
  68. ref="table"
  69. size="small"
  70. :rowKey="(record) => record.id"
  71. :columns="columns"
  72. :data="loadData"
  73. :scroll="{ x:840, y: 300 }"
  74. bordered>
  75. <!-- 产品名称 -->
  76. <template slot="productName" slot-scope="text, record">
  77. <span>{{ text }}</span>
  78. <a-badge :number-style="{ backgroundColor: '#52c41a' }" count="活动" v-if="record.promotableFlag == 1"></a-badge>
  79. </template>
  80. <!-- 销售数量 -->
  81. <template slot="salesNums" slot-scope="text, record">
  82. <a-input-number
  83. id="salesEdit-qty"
  84. size="small"
  85. v-model="record.qty"
  86. :precision="0"
  87. :min="1"
  88. :max="999999"
  89. placeholder="请输入"
  90. @blur="e => onCellBlur(e.target.value, record)"
  91. style="width: 100%;" />
  92. </template>
  93. <!-- 操作 -->
  94. <template slot="action" slot-scope="text, record">
  95. <a-button
  96. size="small"
  97. type="primary"
  98. :loading="delLoading"
  99. class="button-error"
  100. @click="handleDel(record)"
  101. >删除</a-button>
  102. <a-button
  103. size="small"
  104. type="primary"
  105. :loading="delLoading"
  106. class="button-warning"
  107. @click="handleSelCx(record)"
  108. v-if="record.promotableFlag == 1"
  109. >选择促销品</a-button>
  110. </template>
  111. </s-table>
  112. </a-card>
  113. <a-card size="small" :bordered="false" class="salesEdit-cont">
  114. <div slot="title">
  115. <div class="p-title">
  116. 已选促销品
  117. </div>
  118. </div>
  119. <!-- 总计 -->
  120. <a-alert type="info" style="margin-bottom: 10px;">
  121. <div slot="message" class="total-bar">
  122. <div>
  123. 总成本:<strong>¥{{ detailData&&(detailData.totalPromoCost || detailData.totalPromoCost==0) ? detailData.totalPromoCost : '--' }}</strong>;
  124. 总款数:<strong>{{ detailData&&(detailData.totalPromoCategory || detailData.totalPromoCategory==0) ? detailData.totalPromoCategory : '--' }}</strong>;
  125. 总数量:<strong>{{ detailData&&(detailData.totalPromoQty || detailData.totalPromoQty==0) ? detailData.totalPromoQty : '--' }}</strong>;
  126. </div>
  127. <div>
  128. </div>
  129. </div>
  130. </a-alert>
  131. <!-- 已选促销品列表 -->
  132. <queryPromotable ref="promotable" :salesBillSn="$route.params.sn" :delLoading="delLoading" @onCellBlur="onCellBlur" @del="handleDel"></queryPromotable>
  133. </a-card>
  134. </a-spin>
  135. <div class="affix-cont">
  136. <a-button
  137. size="large"
  138. style="padding: 0 60px;"
  139. type="primary"
  140. class="button-primary"
  141. @click="handleSubmit()"
  142. id="productInfoList-handleSubmit">提交</a-button>
  143. </div>
  144. <!-- 选择客户弹框 -->
  145. <choose-custom-modal ref="custModal" :show="openModal" @cancel="openModal=false" />
  146. <!-- 添加产品 -->
  147. <ChooseActive
  148. ref="activeProduct"
  149. :buyerSn="detailData&&detailData.buyerSn"
  150. :openModal="newActive"
  151. @ok="addNewActive"
  152. :newLoading="isInster"
  153. @close="newActive=false"></ChooseActive>
  154. </div>
  155. </template>
  156. <script>
  157. import { STable, VSelect } from '@/components'
  158. import queryPart from './queryPart.vue'
  159. import queryPromotable from './queryPromotable.vue'
  160. import chooseCustomModal from './chooseCustomModal.vue'
  161. import ChooseActive from './chooseActive.vue'
  162. import { salesDetailBySn, salesWriteSubmit, getPromoacActiveList } from '@/api/sales'
  163. import { salesDetailList, salesDetailInsert, salesDetailUpdateQty, salesDetailDel, salesDetailDelAll, addPromoGoods } from '@/api/salesDetail'
  164. export default {
  165. name: 'SalesDetail',
  166. components: { STable, VSelect, queryPart, queryPromotable, chooseCustomModal, ChooseActive },
  167. data () {
  168. return {
  169. spinning: false,
  170. salesBillSn: null, // 销售单sn
  171. disabled: false, // 查询、重置按钮是否可操作
  172. isInster: false, // 是否正在添加产品
  173. openModal: false, // 客户弹框
  174. delLoading: false,
  175. newActive: false, // 选择促销品
  176. detailData: { discountAmount: 0, id: null, salesBillSn: '' }, // 订单基础数据
  177. dataSource: [],
  178. productForm: {
  179. salesBillSn: '',
  180. promotionFlag: 0
  181. },
  182. activeName: '', // 促销活动
  183. // 表头
  184. columns: [
  185. { title: '序号', dataIndex: 'no', width: 70, align: 'center' },
  186. { title: '产品编码', dataIndex: 'productEntity.code', width: 120, align: 'center', customRender: function (text) { return text || '--' }, sorter: true },
  187. { title: '产品名称', dataIndex: 'productEntity.name', scopedSlots: { customRender: 'productName' }, align: 'center' },
  188. { title: '售价', dataIndex: 'price', width: 80, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  189. { title: '销售数量', scopedSlots: { customRender: 'salesNums' }, width: 100, align: 'center' },
  190. { title: '单位', dataIndex: 'productEntity.unit', width: 60, align: 'center', customRender: function (text) { return text || '--' } },
  191. { title: '售价小计', dataIndex: 'totalAmount', width: 80, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  192. { title: '操作', scopedSlots: { customRender: 'action' }, width: 170, align: 'center', fixed: 'right' }
  193. ],
  194. // 加载数据方法 必须为 Promise 对象
  195. loadData: parameter => {
  196. this.disabled = true
  197. this.productForm.salesBillSn = this.$route.params.sn
  198. return salesDetailList(Object.assign(parameter, this.productForm)).then(res => {
  199. const data = res.data
  200. const no = (data.pageNo - 1) * data.pageSize
  201. for (var i = 0; i < data.list.length; i++) {
  202. data.list[i].no = no + i + 1
  203. data.list[i].qtyBackups = data.list[i].qty
  204. }
  205. this.disabled = false
  206. this.dataSource = data.list
  207. return data
  208. })
  209. }
  210. }
  211. },
  212. methods: {
  213. // 已选产品 blur
  214. onCellBlur (val, record) {
  215. const _this = this
  216. // 光标移出,值发生改变再调用编辑接口
  217. if (val && val != record.qtyBackups) {
  218. _this.spinning = true
  219. salesDetailUpdateQty({
  220. salesBillDetailSn: record.salesBillDetailSn,
  221. qty: record.qty,
  222. salesBillSn: _this.salesBillSn
  223. }).then(res => {
  224. _this.resetSearchForm(true)
  225. _this.$refs.promotable.resetCurForm()
  226. if (res.status == 200) {
  227. _this.$message.success(res.message)
  228. }
  229. _this.spinning = false
  230. })
  231. } else {
  232. record.qty = record.qtyBackups
  233. }
  234. },
  235. // 编辑客户信息
  236. handleEdit () {
  237. this.openModal = true
  238. setTimeout(() => {
  239. this.$refs.custModal.editCust(this.detailData)
  240. }, 500)
  241. },
  242. // 重置
  243. resetSearchForm (flag) {
  244. this.$refs.table.refresh(!!flag)
  245. this.getPromoacActiveList()
  246. this.getOrderDetail()
  247. },
  248. // 重置列表
  249. resetForm () {
  250. this.$refs.table.refresh()
  251. },
  252. // 返回
  253. handleBack () {
  254. this.$router.push({ path: '/salesManagement/salesQuery/list', query: { closeLastOldTab: true } })
  255. },
  256. // 整单删除
  257. delSalerDetailAll () {
  258. const _this = this
  259. this.$confirm({
  260. title: '提示',
  261. content: '确认要整单删除吗?',
  262. centered: true,
  263. closable: true,
  264. onOk () {
  265. _this.delLoading = true
  266. _this.spinning = true
  267. salesDetailDelAll({ salesBillSn: _this.salesBillSn }).then(res => {
  268. if (res.status == 200) {
  269. _this.resetSearchForm()
  270. _this.$refs.promotable.resetCurForm()
  271. _this.$message.success(res.message)
  272. }
  273. _this.delLoading = false
  274. _this.spinning = false
  275. })
  276. }
  277. })
  278. },
  279. // 删除产品
  280. handleDel (row) {
  281. const _this = this
  282. this.$confirm({
  283. title: '提示',
  284. content: '确认要删除吗?',
  285. centered: true,
  286. closable: true,
  287. onOk () {
  288. _this.delLoading = true
  289. _this.spinning = true
  290. salesDetailDel({ salesBillDetailSn: row.salesBillDetailSn, salesBillSn: _this.salesBillSn }).then(res => {
  291. if (res.status == 200) {
  292. _this.resetSearchForm(true)
  293. _this.$refs.promotable.resetCurForm()
  294. _this.$message.success(res.message)
  295. }
  296. _this.delLoading = false
  297. _this.spinning = false
  298. })
  299. }
  300. })
  301. },
  302. // 添加产品
  303. insterProduct (row, promotionFlag) {
  304. console.log(row)
  305. // 防止多次添加产品
  306. if (this.isInster) { return }
  307. const _this = this
  308. _this.saveNewProduct(row, promotionFlag)
  309. },
  310. // 保存添加的产品到销售列表
  311. saveNewProduct (row, promotionFlag) {
  312. this.$message.loading('正在添加产品...', 1)
  313. this.isInster = true
  314. this.spinning = true
  315. salesDetailInsert({
  316. packQty: row.productPackQty,
  317. productSn: row.productSn,
  318. showCost: row.lastStockCost,
  319. price: row.productPrice,
  320. origPrice: row.productPrice,
  321. promotionGiftsAmount: 0,
  322. usePromotionGiftsAmount: 0,
  323. qty: row.salesNums,
  324. salesBillSn: this.detailData.salesBillSn,
  325. salesBillNo: this.detailData.salesBillNo,
  326. purchaseBillSn: this.detailData.purchaseBillSn,
  327. purchaseBillNo: this.detailData.purchaseBillNo,
  328. stockSn: row.stockSn,
  329. promotableFlag: row.isJoinActivityProduct || 0, // 可促销标记 有活动的传1,没活动的传0
  330. promotionFlag: promotionFlag // 促销标记 正品传0,促销品传1
  331. }).then(res => {
  332. if (res.status == 200) {
  333. this.resetSearchForm()
  334. this.$message.success('产品添加成功', 2.5)
  335. this.spinning = false
  336. } else {
  337. this.spinning = false
  338. }
  339. this.isInster = false
  340. })
  341. },
  342. // 销售单详情
  343. getOrderDetail () {
  344. salesDetailBySn({ salesBillSn: this.$route.params.sn }).then(res => {
  345. console.log('getOrderDetail')
  346. if (res.status == 200) {
  347. this.detailData = res.data
  348. console.log(this.detailData)
  349. }
  350. })
  351. },
  352. // 提交销售单
  353. handleSubmit () {
  354. this.spinning = true
  355. salesWriteSubmit({ salesBillSn: this.salesBillSn }).then(res => {
  356. if (res.status == 200) {
  357. this.handleBack()
  358. this.$message.success(res.message)
  359. this.spinning = false
  360. } else {
  361. this.spinning = false
  362. }
  363. })
  364. },
  365. // 获取促销活动
  366. getPromoacActiveList () {
  367. const _this = this
  368. getPromoacActiveList({ salesBillSn: this.salesBillSn }).then(res => {
  369. if (res.status == 200) {
  370. _this.activeName = ''
  371. res.data.map(item => {
  372. _this.activeName += item.name + '、'
  373. })
  374. _this.activeName = _this.activeName.slice(0, _this.activeName.length - 1)
  375. }
  376. })
  377. },
  378. // 选择促销品
  379. handleSelCx (row) {
  380. this.newActive = true
  381. this.$refs.activeProduct.getData(row)
  382. },
  383. // 批量添加促销品
  384. addNewActive (list) {
  385. const temp = []
  386. list.map(item => {
  387. temp.push(Object.assign(item, {
  388. salesBillSn: this.detailData.salesBillSn,
  389. salesBillNo: this.detailData.salesBillNo,
  390. purchaseBillSn: this.detailData.purchaseBillSn,
  391. purchaseBillNo: this.detailData.purchaseBillNo
  392. }))
  393. })
  394. this.isInster == true
  395. this.spinning = true
  396. addPromoGoods(temp).then(res => {
  397. if (res.status == 200) {
  398. this.$refs.promotable.getData()
  399. this.getOrderDetail()
  400. this.newActive = false
  401. this.isInster == false
  402. this.spinning = false
  403. } else {
  404. this.spinning = false
  405. }
  406. })
  407. }
  408. },
  409. mounted () {
  410. this.getOrderDetail()
  411. },
  412. beforeRouteEnter (to, from, next) {
  413. next(vm => {
  414. vm.salesBillSn = vm.$route.params.sn
  415. // 获取促销活动
  416. vm.getPromoacActiveList()
  417. // 查询已选促销品
  418. vm.$refs.promotable.getData()
  419. })
  420. }
  421. }
  422. </script>
  423. <style lang="less">
  424. .salesEdit-wrap{
  425. position: relative;
  426. height: 100%;
  427. padding-bottom: 51px;
  428. box-sizing: border-box;
  429. >.ant-spin-nested-loading{
  430. overflow-y: scroll;
  431. height: 100%;
  432. }
  433. .salesEdit-cont{
  434. margin-top: 10px;
  435. }
  436. .p-title{
  437. font-weight: bold;
  438. font-size: 16px;
  439. }
  440. .p-notes{
  441. font-size: 14px;
  442. span{
  443. color: #FF9900;
  444. }
  445. }
  446. .total-bar{
  447. display: flex;
  448. align-items: center;
  449. justify-content: space-between;
  450. > div{
  451. &:last-child{
  452. display: flex;
  453. align-items: center;
  454. justify-content: space-between;
  455. > div{
  456. padding: 0 10px;
  457. }
  458. }
  459. }
  460. }
  461. .redBg-row{
  462. background-color: #f5cdc8;
  463. }
  464. }
  465. </style>