edit.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  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="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="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. // 表头
  218. // columns: [
  219. // { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
  220. // { title: '产品编码', dataIndex: 'productEntity.code', scopedSlots: { customRender: 'productCode' }, width: '20%', align: 'center', sorter: true },
  221. // { title: '产品名称', dataIndex: 'productEntity.name', scopedSlots: { customRender: 'productName' }, width: '25%', align: 'left' },
  222. // { title: '售价', dataIndex: 'price', width: '8%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  223. // { title: '销售数量', scopedSlots: { customRender: 'salesNums' }, width: '8%', align: 'center' },
  224. // { title: '库存', dataIndex: 'stockQty', scopedSlots: { customRender: 'stockQty' }, width: '8%', align: 'center' },
  225. // { title: '单位', dataIndex: 'productEntity.unit', width: '6%', align: 'center', customRender: function (text) { return text || '--' } },
  226. // { title: '售价小计', dataIndex: 'totalAmount', width: '8%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  227. // { title: '操作', scopedSlots: { customRender: 'action' }, width: '13%', align: 'center' }
  228. // ],
  229. // 加载数据方法 必须为 Promise 对象
  230. loadData: parameter => {
  231. this.disabled = true
  232. this.productForm.salesBillSn = this.$route.params.sn
  233. return salesDetailStockList(Object.assign(parameter, this.productForm, this.queryParam)).then(res => {
  234. const data = res.data
  235. const no = (data.pageNo - 1) * data.pageSize
  236. for (var i = 0; i < data.list.length; i++) {
  237. data.list[i].no = no + i + 1
  238. data.list[i].qtyBackups = data.list[i].qty
  239. }
  240. this.disabled = false
  241. this.dataSource = data.list
  242. this.$refs.promotable.getData(this.salesBillSn)
  243. return data
  244. })
  245. },
  246. openGuideModal: false, // 导入产品引导
  247. queryParam: {
  248. productCode: '',
  249. productName: ''
  250. }
  251. }
  252. },
  253. computed: {
  254. columns () {
  255. const arr = [
  256. { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
  257. { title: '产品编码', dataIndex: 'productEntity.code', scopedSlots: { customRender: 'productCode' }, width: '20%', align: 'center', sorter: true },
  258. { title: '产品名称', dataIndex: 'productEntity.name', scopedSlots: { customRender: 'productName' }, width: '25%', align: 'left' },
  259. // { title: '售价', dataIndex: 'price', width: '8%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  260. { title: '销售数量', scopedSlots: { customRender: 'salesNums' }, width: '8%', align: 'center' },
  261. { title: '库存', dataIndex: 'stockQty', scopedSlots: { customRender: 'stockQty' }, width: '8%', align: 'center' },
  262. { title: '单位', dataIndex: 'productEntity.unit', width: '6%', align: 'center', customRender: function (text) { return text || '--' } },
  263. // { title: '售价小计', dataIndex: 'totalAmount', width: '8%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  264. { title: '操作', scopedSlots: { customRender: 'action' }, width: '13%', align: 'center' }
  265. ]
  266. if (this.$hasPermissions('B_isShowPrice')) {
  267. arr.splice(3, 0, { title: '售价', dataIndex: 'price', width: '8%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } })
  268. arr.splice(7, 0, { title: '售价小计', dataIndex: 'totalAmount', width: '8%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } })
  269. }
  270. return arr
  271. }
  272. },
  273. methods: {
  274. // 已选产品 blur
  275. onCellBlur (val, record) {
  276. const _this = this
  277. // 光标移出,值发生改变再调用编辑接口
  278. if (val && val != record.qtyBackups) {
  279. _this.spinning = true
  280. salesDetailUpdateQty({
  281. salesBillDetailSn: record.salesBillDetailSn,
  282. qty: record.qty,
  283. salesBillSn: _this.salesBillSn
  284. }).then(res => {
  285. _this.resetSearchForm(true)
  286. _this.$refs.promotable.resetCurForm()
  287. if (res.status == 200) {
  288. _this.$message.success(res.message)
  289. }
  290. _this.spinning = false
  291. })
  292. } else {
  293. record.qty = record.qtyBackups
  294. }
  295. },
  296. chooseResetSearchForm () {
  297. this.queryParam.productCode = ''
  298. this.queryParam.productName = ''
  299. this.$refs.table.refresh(true)
  300. },
  301. // 重置
  302. resetSearchForm (flag) {
  303. this.queryParam.productCode = ''
  304. this.queryParam.productName = ''
  305. this.$refs.table.refresh(!!flag)
  306. this.getPromoacActiveList()
  307. this.getOrderDetail(false)
  308. },
  309. // 返回
  310. handleBack () {
  311. this.$router.push({ path: '/salesManagement/salesQuery/list', query: { closeLastOldTab: true } })
  312. },
  313. // 整单删除
  314. delSalerDetailAll () {
  315. const _this = this
  316. this.$confirm({
  317. title: '提示',
  318. content: '确认要整单删除吗?',
  319. centered: true,
  320. closable: true,
  321. onOk () {
  322. _this.delLoading = true
  323. _this.spinning = true
  324. salesDetailDelAll({ salesBillSn: _this.salesBillSn }).then(res => {
  325. if (res.status == 200) {
  326. _this.resetSearchForm()
  327. _this.$refs.promotable.resetCurForm()
  328. _this.$message.success(res.message)
  329. }
  330. _this.delLoading = false
  331. _this.spinning = false
  332. })
  333. }
  334. })
  335. },
  336. // 删除产品
  337. handleDel (row) {
  338. const _this = this
  339. this.$confirm({
  340. title: '提示',
  341. content: '确认要删除吗?',
  342. centered: true,
  343. closable: true,
  344. onOk () {
  345. _this.delLoading = true
  346. _this.spinning = true
  347. salesDetailDel({ salesBillDetailSn: row.salesBillDetailSn, salesBillSn: _this.salesBillSn }).then(res => {
  348. if (res.status == 200) {
  349. _this.resetSearchForm(true)
  350. _this.$refs.promotable.resetCurForm()
  351. _this.$message.success(res.message)
  352. }
  353. _this.delLoading = false
  354. _this.spinning = false
  355. })
  356. }
  357. })
  358. },
  359. // 添加产品
  360. insterProduct (row, promotionFlag) {
  361. console.log(row)
  362. // 防止多次添加产品
  363. if (this.isInster) { return }
  364. const _this = this
  365. _this.saveNewProduct(row, promotionFlag)
  366. },
  367. // 保存添加的产品到销售列表
  368. saveNewProduct (row, promotionFlag) {
  369. this.$message.loading('正在添加产品...', 1)
  370. this.isInster = true
  371. this.spinning = true
  372. salesDetailInsert({
  373. packQty: row.productPackQty,
  374. productSn: row.productSn,
  375. showCost: row.lastStockCost,
  376. price: row.productPrice,
  377. origPrice: row.productPrice,
  378. promotionGiftsAmount: 0,
  379. usePromotionGiftsAmount: 0,
  380. qty: row.salesNums,
  381. salesBillSn: this.detailData.salesBillSn,
  382. salesBillNo: this.detailData.salesBillNo,
  383. purchaseBillSn: this.detailData.purchaseBillSn,
  384. purchaseBillNo: this.detailData.purchaseBillNo,
  385. stockSn: row.stockSn,
  386. promotableFlag: row.isJoinActivityProduct || 0, // 可促销标记 有活动的传1,没活动的传0
  387. promotionFlag: promotionFlag // 促销标记 正品传0,促销品传1
  388. }).then(res => {
  389. if (res.status == 200) {
  390. this.resetSearchForm()
  391. this.$message.success('产品添加成功', 2.5)
  392. this.spinning = false
  393. } else {
  394. this.spinning = false
  395. }
  396. this.isInster = false
  397. })
  398. },
  399. // 销售单详情
  400. getOrderDetail (flag) {
  401. salesDetailBySn({ salesBillSn: this.$route.params.sn }).then(res => {
  402. if (res.status == 200) {
  403. this.detailData = res.data
  404. if (flag) {
  405. this.$refs.partQuery.pageInit(this.detailData && this.detailData.buyerSn || '')
  406. }
  407. }
  408. })
  409. },
  410. // 提交销售单
  411. handleSubmit () {
  412. this.spinning = true
  413. salesWriteSubmit({ salesBillSn: this.salesBillSn }).then(res => {
  414. if (res.status == 200) {
  415. this.handleBack()
  416. this.$message.success(res.message)
  417. this.spinning = false
  418. } else {
  419. this.spinning = false
  420. }
  421. })
  422. },
  423. // 获取促销活动
  424. getPromoacActiveList () {
  425. const _this = this
  426. getPromoacActiveList({ salesBillSn: this.salesBillSn }).then(res => {
  427. if (res.status == 200) {
  428. _this.activeName = ''
  429. res.data.map(item => {
  430. _this.activeName += item.name + '、'
  431. })
  432. _this.activeName = _this.activeName.slice(0, _this.activeName.length - 1)
  433. }
  434. })
  435. },
  436. // 选择促销品
  437. handleSelCx (row) {
  438. // this.nowData = row
  439. this.newActive = true
  440. this.$refs.activeProduct.getData(row, this.detailData && this.detailData.buyerSn || '')
  441. },
  442. // 批量添加促销品
  443. addNewActive (list) {
  444. const temp = []
  445. list.map(item => {
  446. temp.push(Object.assign(item, {
  447. salesBillSn: this.detailData.salesBillSn,
  448. salesBillNo: this.detailData.salesBillNo,
  449. purchaseBillSn: this.detailData.purchaseBillSn,
  450. purchaseBillNo: this.detailData.purchaseBillNo
  451. }))
  452. })
  453. this.isInster == true
  454. this.spinning = true
  455. addPromoGoods(temp).then(res => {
  456. if (res.status == 200) {
  457. this.$refs.promotable.getData(this.salesBillSn)
  458. this.getOrderDetail(false)
  459. this.newActive = false
  460. this.isInster == false
  461. this.spinning = false
  462. } else {
  463. this.spinning = false
  464. }
  465. })
  466. },
  467. closeActive () {
  468. this.nowData = null
  469. this.newActive = false
  470. },
  471. closeGuideModel () {
  472. this.openGuideModal = false
  473. },
  474. // 导入产品
  475. hanldeOk (obj) {
  476. salesBatchInsert(obj).then(res => {
  477. if (res.status == 200) {
  478. this.$refs.table.refresh(true)
  479. this.getOrderDetail(false)
  480. }
  481. })
  482. },
  483. pageInit () {
  484. this.getOrderDetail(true)
  485. this.$refs.table.refresh(true)
  486. this.salesBillSn = this.$route.params.sn
  487. // 获取促销活动
  488. this.getPromoacActiveList()
  489. }
  490. },
  491. mounted () {
  492. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  493. this.pageInit()
  494. }
  495. },
  496. activated () {
  497. // 如果是新页签打开或者进入新的子页(例:存在列表第2条数据编辑页页签时再打开第4条数据的编辑页),则重置当前页面
  498. if (this.$store.state.app.isNewTab || !this.$store.state.app.isNewSubTab) {
  499. this.pageInit()
  500. }
  501. },
  502. beforeRouteEnter (to, from, next) {
  503. next(vm => {})
  504. }
  505. }
  506. </script>
  507. <style lang="less">
  508. .salesEdit-wrap{
  509. position: relative;
  510. height: 100%;
  511. padding-bottom: 51px;
  512. box-sizing: border-box;
  513. >.ant-spin-nested-loading{
  514. overflow-y: scroll;
  515. height: 100%;
  516. }
  517. .salesEdit-cont{
  518. margin-top: 10px;
  519. }
  520. .p-title{
  521. font-weight: bold;
  522. font-size: 16px;
  523. }
  524. .p-notes{
  525. font-size: 14px;
  526. span{
  527. color: #FF9900;
  528. }
  529. }
  530. .redStyle{
  531. font-weight: bold;
  532. color: red;
  533. }
  534. .ellipsisCon{
  535. display: flex;
  536. justify-content: space-between;
  537. align-items: center;
  538. .ellipsisText{
  539. width: 100%;
  540. overflow: hidden;
  541. text-overflow: ellipsis;
  542. display: box;
  543. display: -webkit-box;
  544. -webkit-line-clamp: 1;
  545. -webkit-box-orient: vertical;
  546. }
  547. }
  548. .total-bar{
  549. display: flex;
  550. align-items: center;
  551. justify-content: space-between;
  552. > div{
  553. &:last-child{
  554. display: flex;
  555. align-items: center;
  556. justify-content: space-between;
  557. > div{
  558. padding: 0 10px;
  559. }
  560. }
  561. }
  562. }
  563. .redBg-row{
  564. background-color: #f5cdc8;
  565. }
  566. }
  567. </style>