edit.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  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. </template>
  10. </a-page-header>
  11. <a-card size="small" :bordered="false" class="salesEdit-cont">
  12. <div slot="title">
  13. <div class="p-title">
  14. 选择产品
  15. </div>
  16. </div>
  17. <!-- 查询配件列表 -->
  18. <queryPart ref="partQuery" :newLoading="isInster" @add="insterProduct"></queryPart>
  19. </a-card>
  20. <a-card size="small" :bordered="false" class="salesEdit-cont">
  21. <div slot="title">
  22. <a-row :gutter="15" type="flex">
  23. <a-col :span="2">
  24. <div class="p-title">
  25. 已选产品
  26. </div>
  27. </a-col>
  28. <a-col :span="16" v-if="activeName">
  29. <div class="p-notes">
  30. <a-icon style="color: #FF9900;" type="bell" /> 已选产品可参加<span>{{ activeName }}</span>的促销活动,促销产品为指定产品
  31. </div>
  32. </a-col>
  33. </a-row>
  34. </div>
  35. <!-- 总计 -->
  36. <a-alert type="info" style="margin-bottom: 10px;">
  37. <div slot="message" class="total-bar">
  38. <div style="position: relative;width: 100%;">
  39. <div>
  40. <span v-if="$hasPermissions('B_isShowPrice')">总售价:<strong>{{ detailData&&(detailData.totalCommonAmount || detailData.totalCommonAmount==0) ? '¥'+detailData.totalCommonAmount : '--' }}</strong>;</span>
  41. 总款数:<strong>{{ detailData&&(detailData.totalCommonCategory || detailData.totalCommonCategory==0) ? detailData.totalCommonCategory : '--' }}</strong>;
  42. 总数量:<strong>{{ detailData&&(detailData.totalCommonQty || detailData.totalCommonQty==0) ? detailData.totalCommonQty : '--' }}</strong>;
  43. </div>
  44. <div style="position: absolute;right: 0;top: -3px;">
  45. <a-button size="small" type="primary" class="button-info" id="salesEdit-import-btn" @click="openGuideModal=true">导入产品</a-button>
  46. </div>
  47. </div>
  48. </div>
  49. </a-alert>
  50. <!-- 筛选条件 -->
  51. <a-row :gutter="15">
  52. <a-col :span="24">
  53. <div class="table-page-search-wrapper">
  54. <a-form layout="inline" @keyup.enter.native="$refs.table.refresh(true)">
  55. <a-row :gutter="15">
  56. <a-col :md="6" :sm="24">
  57. <a-form-item label="产品编码" prop="productCode">
  58. <a-input id="salesEdit-productCode" v-model.trim="queryParam.productCode" placeholder="请输入产品编码" allowClear />
  59. </a-form-item>
  60. </a-col>
  61. <a-col :md="6" :sm="24">
  62. <a-form-item label="产品名称" prop="productName">
  63. <a-input id="salesEdit-productName" v-model.trim="queryParam.productName" placeholder="请输入产品名称" allowClear />
  64. </a-form-item>
  65. </a-col>
  66. <a-col :md="6" :sm="24" style="margin-bottom: 10px;">
  67. <a-button type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="salesEdit-refresh">查询</a-button>
  68. <a-button style="margin-left: 5px" @click="resetSearchForm" :disabled="disabled" id="salesEdit-reset">重置</a-button>
  69. </a-col>
  70. </a-row>
  71. </a-form>
  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. :defaultLoadData="false"
  84. :scroll="{ y: 300 }"
  85. bordered>
  86. <!-- 产品编码 -->
  87. <template slot="productCode" slot-scope="text, record">
  88. <a-badge count="缺" v-if="Number(record.stockQty) < Number(record.unpushedQty)">
  89. <div style="padding-right: 15px;">{{ text }}</div>
  90. </a-badge>
  91. <span v-if="!(Number(record.stockQty) < Number(record.unpushedQty))">{{ text }}</span>
  92. </template>
  93. <!-- 产品名称 -->
  94. <template slot="productName" slot-scope="text, record">
  95. <div class="ellipsisCon">
  96. <a-tooltip placement="rightBottom">
  97. <template slot="title">
  98. <span>{{ text }}</span>
  99. </template>
  100. <span class="ellipsisText">{{ text }}</span>
  101. </a-tooltip>
  102. <a-badge :number-style="{ backgroundColor: '#52c41a' }" count="活动" v-if="record.promotableFlag == 1"></a-badge>
  103. </div>
  104. </template>
  105. <!-- 销售数量 -->
  106. <template slot="salesNums" slot-scope="text, record">
  107. <a-input-number
  108. id="salesEdit-qty"
  109. size="small"
  110. v-model="record.qty"
  111. :precision="0"
  112. :min="1"
  113. :max="999999"
  114. placeholder="请输入"
  115. @blur="e => onCellBlur(e.target.value, record)"
  116. style="width: 100%;" />
  117. </template>
  118. <!-- 当前库存 -->
  119. <template slot="stockQty" slot-scope="text, record">
  120. <div v-if="record.stockQty || record.stockQty==0">
  121. <p style="margin: 0;" v-if="Number(record.stockQty) < Number(record.unpushedQty)">{{ record.stockQty }}(<span class="redStyle">缺{{ Number(record.unpushedQty) - Number(record.stockQty) }}</span>)</p>
  122. <p style="margin: 0;" v-else>{{ record.stockQty }}</p>
  123. </div>
  124. <span v-else>--</span>
  125. </template>
  126. <!-- 操作 -->
  127. <template slot="action" slot-scope="text, record">
  128. <a-button
  129. size="small"
  130. type="link"
  131. :loading="delLoading"
  132. class="button-error"
  133. @click="handleDel(record)"
  134. >删除</a-button>
  135. <a-button
  136. size="small"
  137. type="link"
  138. :loading="delLoading"
  139. class="button-warning"
  140. @click="handleSelCx(record)"
  141. v-if="record.promotableFlag == 1"
  142. >选择促销品</a-button>
  143. </template>
  144. </s-table>
  145. </a-card>
  146. <a-card size="small" :bordered="false" class="salesEdit-cont">
  147. <div slot="title">
  148. <div class="p-title">
  149. 已选促销品
  150. </div>
  151. </div>
  152. <!-- 总计 -->
  153. <a-alert type="info" style="margin-bottom: 10px;">
  154. <div slot="message" class="total-bar">
  155. <div>
  156. <span v-if="$hasPermissions('B_isShowCost')">总成本:<strong>{{ detailData&&(detailData.totalPromoCost || detailData.totalPromoCost==0) ? '¥'+detailData.totalPromoCost : '--' }}</strong>;</span>
  157. 总款数:<strong>{{ detailData&&(detailData.totalPromoCategory || detailData.totalPromoCategory==0) ? detailData.totalPromoCategory : '--' }}</strong>;
  158. 总数量:<strong>{{ detailData&&(detailData.totalPromoQty || detailData.totalPromoQty==0) ? detailData.totalPromoQty : '--' }}</strong>;
  159. </div>
  160. <div>
  161. </div>
  162. </div>
  163. </a-alert>
  164. <!-- 已选促销品列表 -->
  165. <queryPromotable ref="promotable" :delLoading="delLoading" @onCellBlur="onCellBlur" @del="handleDel"></queryPromotable>
  166. </a-card>
  167. </a-spin>
  168. <div class="affix-cont">
  169. <a-button
  170. size="large"
  171. style="padding: 0 60px;"
  172. :disabled="spinning"
  173. type="primary"
  174. class="button-primary"
  175. @click="handleSubmit()"
  176. id="productInfoList-handleSubmit">提交</a-button>
  177. </div>
  178. <!-- 添加产品 -->
  179. <ChooseActive
  180. ref="activeProduct"
  181. :openModal="newActive"
  182. @ok="addNewActive"
  183. :newLoading="isInster"
  184. @close="closeActive"></ChooseActive>
  185. <!-- 导入产品 -->
  186. <importGuideModal :openModal="openGuideModal" :params="{salesBillSn: $route.params.sn}" @close="closeGuideModel" @ok="hanldeOk" />
  187. </div>
  188. </template>
  189. <script>
  190. import { STable, VSelect } from '@/components'
  191. import queryPart from './queryPart.vue'
  192. import queryPromotable from './queryPromotable.vue'
  193. import ChooseActive from './chooseActive.vue'
  194. import ImportGuideModal from './importGuideModal.vue'
  195. import { salesDetailBySn, salesWriteSubmit, getPromoacActiveList } from '@/api/sales'
  196. import { salesDetailStockList, salesDetailInsert, salesDetailUpdateQty, salesDetailDel, salesDetailDelAll, addPromoGoods, salesBatchInsert } from '@/api/salesDetail'
  197. export default {
  198. name: 'SalesDetail',
  199. components: { STable, VSelect, queryPart, queryPromotable, ChooseActive, ImportGuideModal },
  200. data () {
  201. return {
  202. spinning: false,
  203. salesBillSn: null, // 销售单sn
  204. disabled: false, // 查询、重置按钮是否可操作
  205. chooseDisabled: false,
  206. isInster: false, // 是否正在添加产品
  207. delLoading: false,
  208. newActive: false, // 选择促销品
  209. detailData: { discountAmount: 0, id: null, salesBillSn: '' }, // 订单基础数据
  210. dataSource: [],
  211. productForm: {
  212. salesBillSn: '',
  213. promotionFlag: 0
  214. },
  215. activeName: '', // 促销活动
  216. nowData: null,
  217. // 加载数据方法 必须为 Promise 对象
  218. loadData: parameter => {
  219. this.disabled = true
  220. this.productForm.salesBillSn = this.$route.params.sn
  221. return salesDetailStockList(Object.assign(parameter, this.productForm, this.queryParam)).then(res => {
  222. let data
  223. if (res.status == 200) {
  224. data = res.data
  225. const no = (data.pageNo - 1) * data.pageSize
  226. for (var i = 0; i < data.list.length; i++) {
  227. data.list[i].no = no + i + 1
  228. data.list[i].qtyBackups = data.list[i].qty
  229. }
  230. this.disabled = false
  231. this.dataSource = data.list
  232. this.$refs.promotable.getData(this.salesBillSn)
  233. }
  234. return data
  235. })
  236. },
  237. openGuideModal: false, // 导入产品引导
  238. queryParam: {
  239. productCode: '',
  240. productName: ''
  241. }
  242. }
  243. },
  244. computed: {
  245. columns () {
  246. const arr = [
  247. { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
  248. { title: '产品编码', dataIndex: 'productEntity.code', scopedSlots: { customRender: 'productCode' }, width: '20%', align: 'center', sorter: true },
  249. { title: '产品名称', dataIndex: 'productEntity.name', scopedSlots: { customRender: 'productName' }, width: '25%', align: 'left' },
  250. // { title: '售价', dataIndex: 'price', width: '8%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  251. { title: '销售数量', scopedSlots: { customRender: 'salesNums' }, width: '8%', align: 'center' },
  252. { title: '库存', dataIndex: 'stockQty', scopedSlots: { customRender: 'stockQty' }, width: '8%', align: 'center' },
  253. { title: '单位', dataIndex: 'productEntity.unit', width: '6%', align: 'center', customRender: function (text) { return text || '--' } },
  254. // { title: '售价小计', dataIndex: 'totalAmount', width: '8%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  255. { title: '操作', scopedSlots: { customRender: 'action' }, width: '13%', align: 'center' }
  256. ]
  257. if (this.$hasPermissions('B_isShowPrice')) { // 售价权限
  258. arr.splice(3, 0, { title: '售价', dataIndex: 'price', width: '8%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } })
  259. arr.splice(7, 0, { title: '售价小计', dataIndex: 'totalAmount', width: '8%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } })
  260. }
  261. return arr
  262. }
  263. },
  264. methods: {
  265. // 已选产品 blur
  266. onCellBlur (val, record) {
  267. const _this = this
  268. // 光标移出,值发生改变再调用编辑接口
  269. if (val && val != record.qtyBackups) {
  270. _this.spinning = true
  271. salesDetailUpdateQty({
  272. salesBillDetailSn: record.salesBillDetailSn,
  273. qty: record.qty,
  274. salesBillSn: _this.salesBillSn
  275. }).then(res => {
  276. _this.resetSearchForm(true)
  277. _this.$refs.promotable.resetCurForm()
  278. if (res.status == 200) {
  279. _this.$message.success(res.message)
  280. }
  281. _this.spinning = false
  282. })
  283. } else {
  284. record.qty = record.qtyBackups
  285. }
  286. },
  287. chooseResetSearchForm () {
  288. this.queryParam.productCode = ''
  289. this.queryParam.productName = ''
  290. this.$refs.table.refresh(true)
  291. },
  292. // 重置
  293. resetSearchForm (flag) {
  294. this.queryParam.productCode = ''
  295. this.queryParam.productName = ''
  296. this.$refs.table.refresh(!!flag)
  297. this.getPromoacActiveList()
  298. this.getOrderDetail(false)
  299. },
  300. // 返回
  301. handleBack () {
  302. this.$router.push({ path: '/salesManagement/salesQuery/list', query: { closeLastOldTab: true } })
  303. },
  304. // 整单删除
  305. delSalerDetailAll () {
  306. const _this = this
  307. this.$confirm({
  308. title: '提示',
  309. content: '确认要整单删除吗?',
  310. centered: true,
  311. closable: true,
  312. onOk () {
  313. _this.delLoading = true
  314. _this.spinning = true
  315. salesDetailDelAll({ salesBillSn: _this.salesBillSn }).then(res => {
  316. if (res.status == 200) {
  317. _this.resetSearchForm()
  318. _this.$refs.promotable.resetCurForm()
  319. _this.$message.success(res.message)
  320. }
  321. _this.delLoading = false
  322. _this.spinning = false
  323. })
  324. }
  325. })
  326. },
  327. // 删除产品
  328. handleDel (row) {
  329. const _this = this
  330. this.$confirm({
  331. title: '提示',
  332. content: '确认要删除吗?',
  333. centered: true,
  334. closable: true,
  335. onOk () {
  336. _this.delLoading = true
  337. _this.spinning = true
  338. salesDetailDel({ salesBillDetailSn: row.salesBillDetailSn, salesBillSn: _this.salesBillSn }).then(res => {
  339. if (res.status == 200) {
  340. _this.resetSearchForm(true)
  341. _this.$refs.promotable.resetCurForm()
  342. _this.$message.success(res.message)
  343. }
  344. _this.delLoading = false
  345. _this.spinning = false
  346. })
  347. }
  348. })
  349. },
  350. // 添加产品
  351. insterProduct (row, promotionFlag) {
  352. console.log(row)
  353. // 防止多次添加产品
  354. if (this.isInster) { return }
  355. const _this = this
  356. _this.saveNewProduct(row, promotionFlag)
  357. },
  358. // 保存添加的产品到销售列表
  359. saveNewProduct (row, promotionFlag) {
  360. this.$message.loading('正在添加产品...', 1)
  361. this.isInster = true
  362. this.spinning = true
  363. salesDetailInsert({
  364. packQty: row.productPackQty,
  365. productSn: row.productSn,
  366. showCost: row.lastStockCost,
  367. price: row.productPrice,
  368. origPrice: row.productPrice,
  369. promotionGiftsAmount: 0,
  370. usePromotionGiftsAmount: 0,
  371. qty: row.salesNums,
  372. salesBillSn: this.detailData.salesBillSn,
  373. salesBillNo: this.detailData.salesBillNo,
  374. purchaseBillSn: this.detailData.purchaseBillSn,
  375. purchaseBillNo: this.detailData.purchaseBillNo,
  376. stockSn: row.stockSn,
  377. promotableFlag: row.isJoinActivityProduct || 0, // 可促销标记 有活动的传1,没活动的传0
  378. promotionFlag: promotionFlag // 促销标记 正品传0,促销品传1
  379. }).then(res => {
  380. if (res.status == 200) {
  381. this.resetSearchForm()
  382. this.$message.success('产品添加成功', 2.5)
  383. this.spinning = false
  384. } else {
  385. this.spinning = false
  386. }
  387. this.isInster = false
  388. })
  389. },
  390. // 销售单详情
  391. getOrderDetail (flag) {
  392. salesDetailBySn({ salesBillSn: this.$route.params.sn }).then(res => {
  393. if (res.status == 200) {
  394. this.detailData = res.data
  395. if (flag) {
  396. this.$refs.partQuery.pageInit(this.detailData && this.detailData.buyerSn || '')
  397. }
  398. }
  399. })
  400. },
  401. // 提交销售单
  402. handleSubmit () {
  403. this.spinning = true
  404. salesWriteSubmit({ salesBillSn: this.salesBillSn }).then(res => {
  405. if (res.status == 200) {
  406. this.handleBack()
  407. this.$message.success(res.message)
  408. this.spinning = false
  409. } else {
  410. this.spinning = false
  411. }
  412. })
  413. },
  414. // 获取促销活动
  415. getPromoacActiveList () {
  416. const _this = this
  417. getPromoacActiveList({ salesBillSn: this.salesBillSn }).then(res => {
  418. if (res.status == 200) {
  419. _this.activeName = ''
  420. res.data.map(item => {
  421. _this.activeName += item.name + '、'
  422. })
  423. _this.activeName = _this.activeName.slice(0, _this.activeName.length - 1)
  424. }
  425. })
  426. },
  427. // 选择促销品
  428. handleSelCx (row) {
  429. // this.nowData = row
  430. this.newActive = true
  431. this.$refs.activeProduct.getData(row, this.detailData && this.detailData.buyerSn || '')
  432. },
  433. // 批量添加促销品
  434. addNewActive (list) {
  435. const temp = []
  436. list.map(item => {
  437. temp.push(Object.assign(item, {
  438. salesBillSn: this.detailData.salesBillSn,
  439. salesBillNo: this.detailData.salesBillNo,
  440. purchaseBillSn: this.detailData.purchaseBillSn,
  441. purchaseBillNo: this.detailData.purchaseBillNo
  442. }))
  443. })
  444. this.isInster == true
  445. this.spinning = true
  446. addPromoGoods(temp).then(res => {
  447. if (res.status == 200) {
  448. this.$refs.promotable.getData(this.salesBillSn)
  449. this.getOrderDetail(false)
  450. this.newActive = false
  451. this.isInster == false
  452. this.spinning = false
  453. } else {
  454. this.spinning = false
  455. }
  456. })
  457. },
  458. closeActive () {
  459. this.nowData = null
  460. this.newActive = false
  461. },
  462. closeGuideModel () {
  463. this.openGuideModal = false
  464. },
  465. // 导入产品
  466. hanldeOk (obj) {
  467. salesBatchInsert(obj).then(res => {
  468. if (res.status == 200) {
  469. this.$refs.table.refresh(true)
  470. this.getOrderDetail(false)
  471. }
  472. })
  473. },
  474. pageInit () {
  475. this.getOrderDetail(true)
  476. this.$refs.table.refresh(true)
  477. this.salesBillSn = this.$route.params.sn
  478. // 获取促销活动
  479. this.getPromoacActiveList()
  480. }
  481. },
  482. mounted () {
  483. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  484. this.pageInit()
  485. }
  486. },
  487. activated () {
  488. // 如果是新页签打开或者进入新的子页(例:存在列表第2条数据编辑页页签时再打开第4条数据的编辑页),则重置当前页面
  489. if (this.$store.state.app.isNewTab || !this.$store.state.app.isNewSubTab) {
  490. this.pageInit()
  491. }
  492. },
  493. beforeRouteEnter (to, from, next) {
  494. next(vm => {})
  495. }
  496. }
  497. </script>
  498. <style lang="less">
  499. .salesEdit-wrap{
  500. position: relative;
  501. height: 100%;
  502. padding-bottom: 51px;
  503. box-sizing: border-box;
  504. >.ant-spin-nested-loading{
  505. overflow-y: scroll;
  506. height: 100%;
  507. }
  508. .salesEdit-cont{
  509. margin-top: 10px;
  510. }
  511. .p-title{
  512. font-weight: bold;
  513. font-size: 16px;
  514. }
  515. .p-notes{
  516. font-size: 14px;
  517. span{
  518. color: #FF9900;
  519. }
  520. }
  521. .redStyle{
  522. font-weight: bold;
  523. color: red;
  524. }
  525. .ellipsisCon{
  526. display: flex;
  527. justify-content: space-between;
  528. align-items: center;
  529. .ellipsisText{
  530. width: 100%;
  531. overflow: hidden;
  532. text-overflow: ellipsis;
  533. display: box;
  534. display: -webkit-box;
  535. -webkit-line-clamp: 1;
  536. -webkit-box-orient: vertical;
  537. }
  538. }
  539. .total-bar{
  540. display: flex;
  541. align-items: center;
  542. justify-content: space-between;
  543. > div{
  544. &:last-child{
  545. display: flex;
  546. align-items: center;
  547. justify-content: space-between;
  548. > div{
  549. padding: 0 10px;
  550. }
  551. }
  552. }
  553. }
  554. .redBg-row{
  555. background-color: #f5cdc8;
  556. }
  557. }
  558. </style>