edit.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  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. :disabled="spinning"
  140. type="primary"
  141. class="button-primary"
  142. @click="handleSubmit()"
  143. id="productInfoList-handleSubmit">提交</a-button>
  144. </div>
  145. <!-- 选择客户弹框 -->
  146. <choose-custom-modal ref="custModal" :show="openModal" @cancel="openModal=false" />
  147. <!-- 添加产品 -->
  148. <ChooseActive
  149. ref="activeProduct"
  150. :buyerSn="detailData&&detailData.buyerSn"
  151. :openModal="newActive"
  152. @ok="addNewActive"
  153. :newLoading="isInster"
  154. @close="newActive=false"></ChooseActive>
  155. </div>
  156. </template>
  157. <script>
  158. import { STable, VSelect } from '@/components'
  159. import queryPart from './queryPart.vue'
  160. import queryPromotable from './queryPromotable.vue'
  161. import chooseCustomModal from './chooseCustomModal.vue'
  162. import ChooseActive from './chooseActive.vue'
  163. import { salesDetailBySn, salesWriteSubmit, getPromoacActiveList } from '@/api/sales'
  164. import { salesDetailList, salesDetailInsert, salesDetailUpdateQty, salesDetailDel, salesDetailDelAll, addPromoGoods } from '@/api/salesDetail'
  165. export default {
  166. name: 'SalesDetail',
  167. components: { STable, VSelect, queryPart, queryPromotable, chooseCustomModal, ChooseActive },
  168. data () {
  169. return {
  170. spinning: false,
  171. salesBillSn: null, // 销售单sn
  172. disabled: false, // 查询、重置按钮是否可操作
  173. isInster: false, // 是否正在添加产品
  174. openModal: false, // 客户弹框
  175. delLoading: false,
  176. newActive: false, // 选择促销品
  177. detailData: { discountAmount: 0, id: null, salesBillSn: '' }, // 订单基础数据
  178. dataSource: [],
  179. productForm: {
  180. salesBillSn: '',
  181. promotionFlag: 0
  182. },
  183. activeName: '', // 促销活动
  184. // 表头
  185. columns: [
  186. { title: '序号', dataIndex: 'no', width: 70, align: 'center' },
  187. { title: '产品编码', dataIndex: 'productEntity.code', width: 120, align: 'center', customRender: function (text) { return text || '--' }, sorter: true },
  188. { title: '产品名称', dataIndex: 'productEntity.name', scopedSlots: { customRender: 'productName' }, align: 'center' },
  189. { title: '售价', dataIndex: 'price', width: 80, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  190. { title: '销售数量', scopedSlots: { customRender: 'salesNums' }, width: 100, align: 'center' },
  191. { title: '单位', dataIndex: 'productEntity.unit', width: 60, align: 'center', customRender: function (text) { return text || '--' } },
  192. { title: '售价小计', dataIndex: 'totalAmount', width: 80, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  193. { title: '操作', scopedSlots: { customRender: 'action' }, width: 170, align: 'center', fixed: 'right' }
  194. ],
  195. // 加载数据方法 必须为 Promise 对象
  196. loadData: parameter => {
  197. this.disabled = true
  198. this.productForm.salesBillSn = this.$route.params.sn
  199. return salesDetailList(Object.assign(parameter, this.productForm)).then(res => {
  200. const data = res.data
  201. const no = (data.pageNo - 1) * data.pageSize
  202. for (var i = 0; i < data.list.length; i++) {
  203. data.list[i].no = no + i + 1
  204. data.list[i].qtyBackups = data.list[i].qty
  205. }
  206. this.disabled = false
  207. this.dataSource = data.list
  208. return data
  209. })
  210. }
  211. }
  212. },
  213. methods: {
  214. // 已选产品 blur
  215. onCellBlur (val, record) {
  216. const _this = this
  217. // 光标移出,值发生改变再调用编辑接口
  218. if (val && val != record.qtyBackups) {
  219. _this.spinning = true
  220. salesDetailUpdateQty({
  221. salesBillDetailSn: record.salesBillDetailSn,
  222. qty: record.qty,
  223. salesBillSn: _this.salesBillSn
  224. }).then(res => {
  225. _this.resetSearchForm(true)
  226. _this.$refs.promotable.resetCurForm()
  227. if (res.status == 200) {
  228. _this.$message.success(res.message)
  229. }
  230. _this.spinning = false
  231. })
  232. } else {
  233. record.qty = record.qtyBackups
  234. }
  235. },
  236. // 编辑客户信息
  237. handleEdit () {
  238. this.openModal = true
  239. setTimeout(() => {
  240. this.$refs.custModal.editCust(this.detailData)
  241. }, 500)
  242. },
  243. // 重置
  244. resetSearchForm (flag) {
  245. this.$refs.table.refresh(!!flag)
  246. this.getPromoacActiveList()
  247. this.getOrderDetail()
  248. },
  249. // 重置列表
  250. resetForm () {
  251. this.$refs.table.refresh()
  252. },
  253. // 返回
  254. handleBack () {
  255. this.$router.push({ path: '/salesManagement/salesQuery/list', query: { closeLastOldTab: true } })
  256. },
  257. // 整单删除
  258. delSalerDetailAll () {
  259. const _this = this
  260. this.$confirm({
  261. title: '提示',
  262. content: '确认要整单删除吗?',
  263. centered: true,
  264. closable: true,
  265. onOk () {
  266. _this.delLoading = true
  267. _this.spinning = true
  268. salesDetailDelAll({ salesBillSn: _this.salesBillSn }).then(res => {
  269. if (res.status == 200) {
  270. _this.resetSearchForm()
  271. _this.$refs.promotable.resetCurForm()
  272. _this.$message.success(res.message)
  273. }
  274. _this.delLoading = false
  275. _this.spinning = false
  276. })
  277. }
  278. })
  279. },
  280. // 删除产品
  281. handleDel (row) {
  282. const _this = this
  283. this.$confirm({
  284. title: '提示',
  285. content: '确认要删除吗?',
  286. centered: true,
  287. closable: true,
  288. onOk () {
  289. _this.delLoading = true
  290. _this.spinning = true
  291. salesDetailDel({ salesBillDetailSn: row.salesBillDetailSn, salesBillSn: _this.salesBillSn }).then(res => {
  292. if (res.status == 200) {
  293. _this.resetSearchForm(true)
  294. _this.$refs.promotable.resetCurForm()
  295. _this.$message.success(res.message)
  296. }
  297. _this.delLoading = false
  298. _this.spinning = false
  299. })
  300. }
  301. })
  302. },
  303. // 添加产品
  304. insterProduct (row, promotionFlag) {
  305. console.log(row)
  306. // 防止多次添加产品
  307. if (this.isInster) { return }
  308. const _this = this
  309. _this.saveNewProduct(row, promotionFlag)
  310. },
  311. // 保存添加的产品到销售列表
  312. saveNewProduct (row, promotionFlag) {
  313. this.$message.loading('正在添加产品...', 1)
  314. this.isInster = true
  315. this.spinning = true
  316. salesDetailInsert({
  317. packQty: row.productPackQty,
  318. productSn: row.productSn,
  319. showCost: row.lastStockCost,
  320. price: row.productPrice,
  321. origPrice: row.productPrice,
  322. promotionGiftsAmount: 0,
  323. usePromotionGiftsAmount: 0,
  324. qty: row.salesNums,
  325. salesBillSn: this.detailData.salesBillSn,
  326. salesBillNo: this.detailData.salesBillNo,
  327. purchaseBillSn: this.detailData.purchaseBillSn,
  328. purchaseBillNo: this.detailData.purchaseBillNo,
  329. stockSn: row.stockSn,
  330. promotableFlag: row.isJoinActivityProduct || 0, // 可促销标记 有活动的传1,没活动的传0
  331. promotionFlag: promotionFlag // 促销标记 正品传0,促销品传1
  332. }).then(res => {
  333. if (res.status == 200) {
  334. this.resetSearchForm()
  335. this.$message.success('产品添加成功', 2.5)
  336. this.spinning = false
  337. } else {
  338. this.spinning = false
  339. }
  340. this.isInster = false
  341. })
  342. },
  343. // 销售单详情
  344. getOrderDetail () {
  345. salesDetailBySn({ salesBillSn: this.$route.params.sn }).then(res => {
  346. console.log('getOrderDetail')
  347. if (res.status == 200) {
  348. this.detailData = res.data
  349. console.log(this.detailData)
  350. }
  351. })
  352. },
  353. // 提交销售单
  354. handleSubmit () {
  355. this.spinning = true
  356. salesWriteSubmit({ salesBillSn: this.salesBillSn }).then(res => {
  357. if (res.status == 200) {
  358. this.handleBack()
  359. this.$message.success(res.message)
  360. this.spinning = false
  361. } else {
  362. this.spinning = false
  363. }
  364. })
  365. },
  366. // 获取促销活动
  367. getPromoacActiveList () {
  368. const _this = this
  369. getPromoacActiveList({ salesBillSn: this.salesBillSn }).then(res => {
  370. if (res.status == 200) {
  371. _this.activeName = ''
  372. res.data.map(item => {
  373. _this.activeName += item.name + '、'
  374. })
  375. _this.activeName = _this.activeName.slice(0, _this.activeName.length - 1)
  376. }
  377. })
  378. },
  379. // 选择促销品
  380. handleSelCx (row) {
  381. this.newActive = true
  382. this.$refs.activeProduct.getData(row)
  383. },
  384. // 批量添加促销品
  385. addNewActive (list) {
  386. const temp = []
  387. list.map(item => {
  388. temp.push(Object.assign(item, {
  389. salesBillSn: this.detailData.salesBillSn,
  390. salesBillNo: this.detailData.salesBillNo,
  391. purchaseBillSn: this.detailData.purchaseBillSn,
  392. purchaseBillNo: this.detailData.purchaseBillNo
  393. }))
  394. })
  395. this.isInster == true
  396. this.spinning = true
  397. addPromoGoods(temp).then(res => {
  398. if (res.status == 200) {
  399. this.$refs.promotable.getData()
  400. this.getOrderDetail()
  401. this.newActive = false
  402. this.isInster == false
  403. this.spinning = false
  404. } else {
  405. this.spinning = false
  406. }
  407. })
  408. }
  409. },
  410. mounted () {
  411. this.getOrderDetail()
  412. },
  413. beforeRouteEnter (to, from, next) {
  414. next(vm => {
  415. vm.salesBillSn = vm.$route.params.sn
  416. // 获取促销活动
  417. vm.getPromoacActiveList()
  418. // 查询已选促销品
  419. vm.$refs.promotable.getData()
  420. })
  421. }
  422. }
  423. </script>
  424. <style lang="less">
  425. .salesEdit-wrap{
  426. position: relative;
  427. height: 100%;
  428. padding-bottom: 51px;
  429. box-sizing: border-box;
  430. >.ant-spin-nested-loading{
  431. overflow-y: scroll;
  432. height: 100%;
  433. }
  434. .salesEdit-cont{
  435. margin-top: 10px;
  436. }
  437. .p-title{
  438. font-weight: bold;
  439. font-size: 16px;
  440. }
  441. .p-notes{
  442. font-size: 14px;
  443. span{
  444. color: #FF9900;
  445. }
  446. }
  447. .total-bar{
  448. display: flex;
  449. align-items: center;
  450. justify-content: space-between;
  451. > div{
  452. &:last-child{
  453. display: flex;
  454. align-items: center;
  455. justify-content: space-between;
  456. > div{
  457. padding: 0 10px;
  458. }
  459. }
  460. }
  461. }
  462. .redBg-row{
  463. background-color: #f5cdc8;
  464. }
  465. }
  466. </style>