edit.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. <template>
  2. <div class="salesNewEdit-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;font-weight: bold;">单号:{{ detailData&&detailData.salesBillNo }}</span>
  9. <span v-if="detailData&&detailData.salesBillNoSource">(原:{{ detailData&&detailData.salesBillNoSource || '--' }})</span>
  10. <a-button type="link" class="button-default" @click="showDetail=!showDetail">
  11. <a-icon :type="showDetail ? 'eye-invisible' : 'eye'"/> {{ showDetail?'隐藏':'查看' }}信息
  12. </a-button>
  13. </template>
  14. </a-page-header>
  15. <!-- 单据详情 -->
  16. <a-card size="small" :bordered="false" class="salesEdit-cont" v-show="showDetail">
  17. <div style="padding: 10px;">
  18. <a-descriptions size="small" :column="3">
  19. <a-descriptions-item label="客户名称">{{ detailData&&detailData.buyerName || '--' }}</a-descriptions-item>
  20. <a-descriptions-item label="收货地址" :span="2">{{ shippingAddress||'--' }}</a-descriptions-item>
  21. <a-descriptions-item label="收货人">{{ detailData&&detailData.salesBillExtEntity&&detailData.salesBillExtEntity.consigneeName || '--' }}</a-descriptions-item>
  22. <a-descriptions-item label="收货电话">{{ detailData&&detailData.salesBillExtEntity&&detailData.salesBillExtEntity.consigneeTel || '--' }}</a-descriptions-item>
  23. <a-descriptions-item label="收款方式">{{ detailData&&detailData.settleStyleSnDictValue || '--' }}</a-descriptions-item>
  24. <a-descriptions-item label="审核时间">{{ detailData&&detailData.auditDate || '--' }}</a-descriptions-item>
  25. <a-descriptions-item label="业务状态">{{ detailData&&detailData.billStatusDictValue || '--' }}</a-descriptions-item>
  26. <a-descriptions-item label="财务状态">{{ detailData&&detailData.financialStatusDictValue || '--' }}</a-descriptions-item>
  27. <a-descriptions-item label="备注" :span="3">{{ detailData&&detailData.remarks || '--' }}</a-descriptions-item>
  28. </a-descriptions>
  29. </div>
  30. </a-card>
  31. <!-- 正常产品 -->
  32. <a-card size="small" :bordered="false" class="salesEdit-cont" v-if="salesBillSn">
  33. <div style="padding: 10px;">
  34. <productNormalList
  35. ref="productNormalList"
  36. @insterOk="insterActiveOk"
  37. @openCpModal="openProductModal"
  38. :showTotal="activeList.length>0"
  39. :detailData="detailData"
  40. :warehouseSn="warehouseSn"
  41. :salesBillSn="salesBillSn"></productNormalList>
  42. </div>
  43. </a-card>
  44. <!-- 活动产品 -->
  45. <a-card
  46. size="small"
  47. :bordered="false"
  48. class="salesEdit-cont"
  49. v-for="item in activeList"
  50. :key="item.promoRuleSn"
  51. v-if="activeList.length"
  52. >
  53. <div slot="title" style="display: inline-block;width:100%;">
  54. <strong style="margin-right:10px;font-size:14px;">{{item.promotion.description}}</strong> ({{item.promotionRule.description}})
  55. <span style="margin-left:20px;color:#00aaff;cursor: pointer;" @click="(event) => {showDesc(event, item)}">
  56. <a-icon :type="item.showDesc ? 'eye-invisible' : 'eye'"/> 活动详情
  57. </span>
  58. <span :style="{margin:'0 20px',color:item.disabled?'#14b900':'#ff0800',cursor: 'pointer'}" @click="(event) => {disabledActive(event, item)}">
  59. <a-icon title="禁用规则" type="disconnect"/> {{item.disabled ? '启用规则' : '禁用规则'}}
  60. </span>
  61. </div>
  62. <div slot="extra" @click="tooglePanel(item)" style="cursor: pointer;">{{ item.isActive ? '收起' : '展开' }} <a-icon type="caret-right" :rotate="item.isActive ? 90 : 0"/> </div>
  63. <div v-show="item.isActive" style="padding: 10px;">
  64. <productList
  65. :ref="'productList-'+item.promoRuleSn"
  66. :id="item.promoRuleSn"
  67. @openCpModal="openProductModal"
  68. @insterOk="insterActiveOk"
  69. @showDesc="v => showDescOk(v,item)"
  70. @upActive="upActive"
  71. :promo="item"
  72. :detailData="detailData"
  73. :warehouseSn="warehouseSn"
  74. :salesBillSn="salesBillSn"></productList>
  75. </div>
  76. </a-card>
  77. </a-spin>
  78. <div class="affix-cont">
  79. <div class="footer-price">
  80. <div></div>
  81. <div v-if="detailData">
  82. <div class="totalPrice">总售价:¥<span>{{ toThousands(detailData.totalAmount) }}</span></div>
  83. <div>
  84. 产品总款数:<strong style="margin-right: 10px;"> {{ detailData.totalCategory }} </strong>
  85. 总数量:<strong> {{ detailData.totalQty }} </strong>
  86. <span style="margin:0 0 0 10px;" v-if="detailData.totalLossAmount">优惠金额:¥<strong>{{ toThousands(detailData.totalLossAmount) }}</strong></span>
  87. <a-popover title="优惠明细" @visibleChange="(visible)=>{visible&&getPromYhDetail()}">
  88. <a-button shape="round" size="small" v-if="detailData.totalLossAmount">优惠明细</a-button>
  89. <div slot="content">
  90. <div v-if="yhDetail">
  91. <div
  92. class="yhdetail"
  93. style="min-width:300px;margin-bottom: 5px;"
  94. v-for="(item,index) in yhDetail.promoMapList"
  95. :key="index">
  96. <div class="yhdetail-h" style="font-weight: bold;font-size:14px;">{{ item.title }}</div>
  97. <div style="padding-left:10px;"
  98. v-for="(sitem,sindex) in item.promoRuleMapList"
  99. :key="sindex"
  100. v-if="sitem.lossAmount"
  101. >
  102. <div style="display: flex;justify-content: space-between;">
  103. <span>{{sitem.promotionRuleTypeDictValue}}:</span>
  104. <strong>¥{{ toThousands(sitem.lossAmount) }}</strong>
  105. </div>
  106. <div class="yhdetail-d" style="color:#999;">{{ sitem.description }}</div>
  107. </div>
  108. </div>
  109. <div class="yhdetail" style="display: flex;justify-content: space-between;">
  110. <span style="font-weight: bold;font-size:14px;">优惠金额:</span>
  111. <span style="font-weight: bold;font-size:18px;">¥{{ toThousands(yhDetail.totalLossAmount) }}</span>
  112. </div>
  113. </div>
  114. <div style="text-align: center;padding: 20px;" v-else>
  115. 正在加载...
  116. </div>
  117. </div>
  118. </a-popover>
  119. </div>
  120. </div>
  121. </div>
  122. <div>
  123. <a-button
  124. size="large"
  125. style="padding: 0 60px;"
  126. :disabled="spinning"
  127. type="primary"
  128. class="button-primary"
  129. @click="handleSubmit()"
  130. id="productInfoList-handleSubmit">提交</a-button>
  131. </div>
  132. </div>
  133. <!-- 添加产品 -->
  134. <chooseProduct
  135. ref="chooseProduct"
  136. :openModal="showCpModal"
  137. @close="closeProductModal"
  138. @addProduct="insterProduct"></chooseProduct>
  139. <!-- 价格更新弹窗 -->
  140. <setPriceModal
  141. :show="priceUpdateModal"
  142. :totalRealAmount="updataData.totalRealAmount"
  143. :totalAmount="updataData.totalAmount"
  144. @ok="updatePrice"
  145. @cancel="priceUpdateModal=false"></setPriceModal>
  146. <!-- 新活动窗口 -->
  147. <newPromoModal
  148. :show="showNewActiveModal"
  149. :salesBillSn="salesBillSn"
  150. :newActiveList="newActiveList"
  151. @ok="showNewActiveOk"
  152. ></newPromoModal>
  153. </div>
  154. </template>
  155. <script>
  156. import { commonMixin } from '@/utils/mixin'
  157. import productList from './comps/productList.vue'
  158. import productNormalList from './comps/productNormalList.vue'
  159. import chooseProduct from './comps/chooseProduct.vue'
  160. import setPriceModal from './setPriceModal.vue'
  161. import newPromoModal from './newPromoModal.vue'
  162. import { salesDisablePromo, salesChangePromo } from '@/api/salesDetailNew'
  163. import { salesDetailBySn,salesPromoQueryCount, salesWriteSubmit, submitCheck, updateBatch, salesPromoQueryList, salesQueryUnPartPromo,salesPromoValidaSubmit } from '@/api/salesNew'
  164. export default {
  165. name: 'SalesNewEdit',
  166. mixins: [commonMixin],
  167. components:{
  168. setPriceModal,
  169. productList,
  170. chooseProduct,
  171. productNormalList,
  172. newPromoModal
  173. },
  174. data () {
  175. return {
  176. spinning: false,
  177. activeList:[], // 活动列表
  178. newActiveList: [], // 新活动列表
  179. activeDesKey: {},
  180. salesBillSn: null, // 销售单sn
  181. detailData: { discountAmount: 0, id: null, salesBillSn: '' }, // 订单基础数据
  182. warehouseSn: undefined,
  183. updataData: {
  184. totalRealAmount: '',
  185. totalAmount: ''
  186. },
  187. priceUpdateModal: false, // 价格更新弹窗
  188. showDetail: false,
  189. showCpModal: false,
  190. cpCurRefId: '',
  191. disabledActiveOption: null,
  192. yhDetail: null,
  193. showNewActiveModal: false
  194. }
  195. },
  196. computed: {
  197. shippingAddress () {
  198. const shippingAddrProvinceName = this.detailData && this.detailData.salesBillExtEntity && this.detailData.salesBillExtEntity.shippingAddrProvinceName ? this.detailData.salesBillExtEntity.shippingAddrProvinceName : ''
  199. const shippingAddrCityName = this.detailData && this.detailData.salesBillExtEntity && this.detailData.salesBillExtEntity.shippingAddrCityName ? this.detailData.salesBillExtEntity.shippingAddrCityName : ''
  200. const shippingAddrCountyName = this.detailData && this.detailData.salesBillExtEntity && this.detailData.salesBillExtEntity.shippingAddrCountyName ? this.detailData.salesBillExtEntity.shippingAddrCountyName : ''
  201. const shippingAddr = this.detailData && this.detailData.salesBillExtEntity && this.detailData.salesBillExtEntity.shippingAddr ? this.detailData.salesBillExtEntity.shippingAddr : ''
  202. if (!shippingAddrProvinceName && !shippingAddrCityName && !shippingAddrCountyName && !shippingAddr) {
  203. return '--'
  204. } else {
  205. return shippingAddrProvinceName + shippingAddrCityName + shippingAddrCountyName + shippingAddr
  206. }
  207. }
  208. },
  209. methods: {
  210. // 返回
  211. handleBack () {
  212. this.$router.push({ name: 'salesQueryNewList', query: { closeLastOldTab: true } })
  213. },
  214. tooglePanel(item){
  215. item.isActive=!item.isActive
  216. this.activeList.splice()
  217. },
  218. // 销售单详情
  219. getOrderDetail (flag) {
  220. salesDetailBySn({ salesBillSn: this.$route.params.sn }).then(res => {
  221. if (res.status == 200) {
  222. this.detailData = res.data
  223. }
  224. if(flag){
  225. this.getActiveList()
  226. }
  227. })
  228. },
  229. // 优惠明细查看
  230. getPromYhDetail(){
  231. salesPromoQueryCount({salesBillSn: this.$route.params.sn }).then(res => {
  232. if (res.status == 200) {
  233. this.yhDetail = res.data
  234. }
  235. })
  236. },
  237. // 获取销售单参与的活动列表
  238. async getActiveList(){
  239. // 已参与活动列表
  240. this.activeList = await salesPromoQueryList({ salesBillSn: this.$route.params.sn }).then(res => res.data || [])
  241. this.activeList.map(item => {
  242. item.isActive = true
  243. item.showDesc = false
  244. item.disabled = item.enabledFlag == 0
  245. this.activeDesKey['search-'+item.promoRuleSn] = false
  246. })
  247. },
  248. // 获取是否有新活动
  249. async getNewActive(){
  250. const hasNewActive = await salesQueryUnPartPromo({ salesBillSn: this.$route.params.sn, enabledFlag: "1" }).then(res => res.data)
  251. if(hasNewActive.length){
  252. this.newActiveList = hasNewActive
  253. this.showNewActiveModal=true
  254. }
  255. },
  256. showNewActiveOk(){
  257. this.showNewActiveModal = false
  258. this.pageInit()
  259. },
  260. // 添加产品,包括正常和活动的产品
  261. closeProductModal(){
  262. this.cpCurRefId = ''
  263. this.showCpModal = false
  264. },
  265. // 打开选择产品弹框
  266. openProductModal(type, refId){
  267. console.log(type, refId)
  268. const promo = this.activeList.find(item => item.promoRuleSn == refId)
  269. this.$refs.chooseProduct.pageInit(this.detailData, promo, type)
  270. this.cpCurRefId = 'productList-' + refId
  271. this.showCpModal = true
  272. },
  273. // 添加活动产品成功的回调
  274. insterActiveOk(type){
  275. if(type == 'promo'){
  276. // 刷新正常产品列表
  277. this.$refs.productNormalList.resetSearchForm()
  278. }
  279. if(type == 'normal'){
  280. // 刷新活动产品列表
  281. this.activeList.map(item => {
  282. this.$refs['productList-' + item.promoRuleSn][0].resetSearchForm()
  283. })
  284. }
  285. this.getOrderDetail()
  286. },
  287. // 新增产品
  288. insterProduct(row, promotionFlag, type){
  289. // 正常产品
  290. if(type == 0){
  291. this.$refs.productNormalList.insterProduct(row, promotionFlag)
  292. }else{
  293. // 活动产品
  294. this.$refs[this.cpCurRefId][0].insterProduct(row, promotionFlag, type)
  295. }
  296. },
  297. // 更换活动
  298. upActive(oldPromo,data,params){
  299. const promo = data.split('-')
  300. const newSn = this.activeList.find(item => item.promoRuleSn == promo[1])
  301. const newSalesPromoSn = newSn && newSn.salesPromoSn || ''
  302. salesChangePromo({
  303. salesPromoSn: data != 0 ? newSalesPromoSn : '',
  304. promoRuleSn: promo[1],
  305. promotionFlag: promo[2]||'',
  306. ...params
  307. }).then(res => {
  308. if(res.status == 200){
  309. // 刷新新参与活动
  310. if(data != 0){
  311. this.$refs['productList-'+promo[1]][0].resetSearchForm()
  312. }
  313. // 刷新正常活动
  314. this.$refs.productNormalList.resetSearchForm()
  315. // 刷新当前活动
  316. this.$refs['productList-'+oldPromo.promoRuleSn][0].upAcitveSuccess()
  317. }
  318. })
  319. },
  320. // 选择价格类型 并更新
  321. updatePrice (type) {
  322. const _this = this
  323. if (type == 0) {
  324. const ajax_data = {
  325. salesBillSn: _this.salesBillSn,
  326. productPriceChangeFlag: type
  327. }
  328. _this.submitResult(ajax_data)
  329. } else {
  330. updateBatch(_this.updataData.detailList).then(res => {
  331. if (res.status == 200) {
  332. const ajax_data = {
  333. salesBillSn: _this.salesBillSn,
  334. productPriceChangeFlag: type
  335. }
  336. _this.submitResult(ajax_data)
  337. }
  338. })
  339. }
  340. },
  341. // 提交销售单
  342. handleSubmit () {
  343. // 先不提交,先判断是否有价格更新 (下级创建时判断)
  344. if (this.detailData && this.detailData.salesBillSource && this.detailData.salesBillSource == 'PURCHASE') {
  345. submitCheck({ salesBillSn: this.salesBillSn }).then(res => {
  346. if (res.status == 200) {
  347. if (res.data.detailList.length > 0) {
  348. this.updataData = res.data
  349. const _this = this
  350. this.$nextTick(() => {
  351. _this.priceUpdateModal = true
  352. })
  353. } else {
  354. this.submitResult({ salesBillSn: this.salesBillSn })
  355. }
  356. }
  357. })
  358. } else {
  359. this.submitResult({ salesBillSn: this.salesBillSn })
  360. }
  361. },
  362. // 提交销售单
  363. async submitResult (data) {
  364. const _this = this
  365. // 校验活动规则
  366. const vaildActive = await salesPromoValidaSubmit({salesBillSn: this.salesBillSn}).then(res => res.data)
  367. // console.log(vaildActive)
  368. const a = vaildActive.filter(item => item.type == 1) // 不可提交
  369. const b = vaildActive.filter(item => item.type == 0) // 可跳过继续提交
  370. // 弹出不符合规则弹框,不可提交
  371. if(a.length){
  372. this.$info({
  373. title: '提示',
  374. centered: true,
  375. class:'confirm-center',
  376. okText:'关闭',
  377. width: 600,
  378. content: <div style="padding-top:15px;">
  379. <ol>
  380. {a.map(item => (
  381. <li style="padding:3px 0;">{item.message}</li>
  382. ))}
  383. </ol>
  384. <div style="padding:10px 0;text-align:center"><strong>请按照以上提示修改后再提交</strong></div>
  385. </div>
  386. });
  387. }else{
  388. // 弹出确认提示信息,可跳过继续提交
  389. if(b.length){
  390. this.$confirm({
  391. title: '提示',
  392. centered: true,
  393. class:'confirm-center',
  394. okText:'提交',
  395. width: 600,
  396. content: <div style="padding-top:15px;">
  397. <ol>
  398. {b.map(item => (
  399. <li style="padding:3px 0;">{item.message}</li>
  400. ))}
  401. </ol>
  402. <div style="padding:10px 0;text-align:center"><strong>继续提交将无法享受优惠</strong></div>
  403. </div>,
  404. onOk() {
  405. _this.submitOrder(data)
  406. }
  407. });
  408. }else{
  409. _this.submitOrder(data)
  410. }
  411. }
  412. },
  413. async submitOrder(data){
  414. this.spinning = true
  415. const res = await salesWriteSubmit(data)
  416. if (res.status == 200) {
  417. this.handleBack()
  418. this.$message.success(res.message)
  419. }
  420. this.spinning = false
  421. },
  422. // 展开收缩活动详情
  423. showDesc(e,item){
  424. e.stopPropagation()
  425. const row = this.$refs['productList-'+item.promoRuleSn][0]
  426. row&&row.showDesc(item.promotionRule)
  427. },
  428. showDescOk(v,item){
  429. item.showDesc = v
  430. this.activeList.splice()
  431. },
  432. // 禁用活动
  433. disabledActive(e,item){
  434. const _this = this
  435. if(item.disabled){
  436. this.$message.info("规则已经禁用!")
  437. return
  438. }
  439. this.$confirm({
  440. title: '确定禁用规则?',
  441. centered: true,
  442. class:'confirm-center',
  443. content: <div>
  444. <div style="padding:10px 0;text-align:center;">禁用规则后,将无法享受该活动规则优惠</div>
  445. <div style="padding:0 0 10px 0;text-align:center;">
  446. <aRadioGroup onChange={_this.changeDaOpt}>
  447. <aRadio style="display:block;height: '30px';lineHeight: '30px';padding:5px 0;" value="DELETE">
  448. 删除规则中相关产品
  449. </aRadio>
  450. <aRadio style="display:block;height: '30px';lineHeight: '30px';padding:5px 0;" value="REMOVE">
  451. 移出规则中相关产品
  452. </aRadio>
  453. </aRadioGroup>
  454. </div>
  455. </div>,
  456. onOk() {
  457. if(_this.disabledActiveOption){
  458. salesDisablePromo({
  459. salesBillSn: _this.salesBillSn,
  460. salesPromoSn: item.salesPromoSn,
  461. promoRuleSn: item.promoRuleSn,
  462. salesDisableType: _this.disabledActiveOption
  463. }).then(res => {
  464. if(res.status == 200){
  465. _this.$refs['productList-'+item.promoRuleSn][0].disableActive(true)
  466. _this.disabledActiveOption = null
  467. item.disabled = true
  468. _this.activeList.splice()
  469. }
  470. })
  471. }else{
  472. _this.$message.info("请选择禁用方式!")
  473. return true
  474. }
  475. },
  476. onCancel() {
  477. _this.disabledActiveOption = null
  478. },
  479. });
  480. },
  481. changeDaOpt(e){
  482. console.log(e)
  483. this.disabledActiveOption = e.target.value
  484. },
  485. pageInit () {
  486. this.salesBillSn = this.$route.params.sn
  487. this.warehouseSn = this.$route.params.sn ? this.$route.params.wSn : ''
  488. this.getOrderDetail(true)
  489. this.getNewActive()
  490. }
  491. },
  492. mounted () {
  493. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  494. this.pageInit()
  495. }
  496. },
  497. activated () {
  498. // 如果是新页签打开或者进入新的子页(例:存在列表第2条数据编辑页页签时再打开第4条数据的编辑页),则重置当前页面
  499. if (this.$store.state.app.isNewTab || !this.$store.state.app.isNewSubTab) {
  500. this.pageInit()
  501. }
  502. },
  503. beforeRouteEnter (to, from, next) {
  504. next(vm => {})
  505. }
  506. }
  507. </script>
  508. <style lang="less">
  509. .salesNewEdit-wrap{
  510. position: relative;
  511. height: 100%;
  512. padding-bottom: 75px;
  513. box-sizing: border-box;
  514. >.ant-spin-nested-loading{
  515. overflow-y: auto;
  516. height: 100%;
  517. }
  518. .salesEdit-cont{
  519. margin: 10px 0;
  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. .ant-card-small > .ant-card-body {
  540. padding: 0!important;
  541. }
  542. .affix-cont{
  543. padding: 10px 15px;
  544. text-align: right;
  545. display: flex;
  546. justify-content: space-between;
  547. align-items: center;
  548. .footer-price{
  549. flex-grow:1;
  550. display: flex;
  551. justify-content: flex-end;
  552. align-items: center;
  553. > div{
  554. padding: 0 15px;
  555. }
  556. .totalPrice{
  557. span{
  558. font-weight: bold;
  559. color: red;
  560. font-size: 20px;
  561. }
  562. }
  563. }
  564. }
  565. }
  566. </style>