edit.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. <template>
  2. <view class="sales-edit-wrap">
  3. <!-- 基础信息 -->
  4. <view class="sales-info-con">
  5. <u-section @click="infoModal=true" title="基础信息" sub-title="查看更多" :line-color="$config('primaryColor')"></u-section>
  6. <view class="info-item-box">
  7. <text class="info-item-tit color_6">销售单号</text>
  8. <text>{{detailData && detailData.salesBillNo || '--'}}</text>
  9. </view>
  10. <view class="info-item-box">
  11. <text class="info-item-tit color_6">客户名称</text>
  12. <text>{{detailData && detailData.buyerName || '--'}}</text>
  13. </view>
  14. </view>
  15. <!-- 产品列表 -->
  16. <view class="sales-product-con">
  17. <!-- 标题 -->
  18. <view class="sales-product-header border-b flex align_center justify_between">
  19. <u-section title="产品列表" :right="pageData.type=='edit'" :line-color="$config('primaryColor')">
  20. <template slot="right" v-if="pageData.type=='edit'">
  21. <view class="sales-product-operation">
  22. <u-button @click="discountModal=true" size="mini" :hair-line="false" plain type="primary" hover-class="none">
  23. 打折
  24. <text v-if="detailData&&detailData.discountAmount">:¥{{detailData.discountAmount}}</text>
  25. </u-button>
  26. <u-button @click="handleProduct" size="mini" :hair-line="false" plain type="primary" hover-class="none">选择产品</u-button>
  27. </view>
  28. </template>
  29. </u-section>
  30. </view>
  31. <!-- 合计 -->
  32. <view ref="salesTotal" class="sales-total-box border-b font_13 flex justify_between">
  33. <view class="sales-total-con flex_1" :style="{height: toggle ? 'auto' : '44upx'}">
  34. <view>
  35. 总款数:<text class="sales-total-num" :style="{color: $config('warringColor')}">{{detailData && (detailData.totalCategory || detailData.totalCategory==0) ? toThousands(detailData.totalCategory) : '--'}}</text>;总数量:<text class="sales-total-num" :style="{color: $config('warringColor')}">{{detailData && (detailData.totalQty || detailData.totalQty==0) ? toThousands(detailData.totalQty) : '--'}}</text>;总售价:<text class="sales-total-num" :style="{color: $config('warringColor')}">¥{{detailData && (detailData.totalAmount || detailData.totalAmount==0) ? toThousands(detailData.totalAmount, 2) : '--'}}</text>;
  36. </view>
  37. <view>
  38. 折扣金额:<text class="sales-total-num" :style="{color: $config('warringColor')}">¥{{detailData && (detailData.discountAmount || detailData.discountAmount==0) ? toThousands(detailData.discountAmount, 2) : '--'}}</text>;折扣:<text class="sales-total-num" :style="{color: $config('warringColor')}">{{detailData && (detailData.discountRate || detailData.discountRate==0) ? detailData.discountRate+'%' : '--'}}</text>;折后总售价:<text class="sales-total-num" :style="{color: $config('warringColor')}">¥{{detailData && (detailData.discountedAmount || detailData.discountedAmount==0) ? toThousands(detailData.discountedAmount, 2) : '--'}}</text>;
  39. </view>
  40. <view>
  41. 急件总款数:<text class="sales-total-num" :style="{color: $config('warringColor')}">{{detailData && (detailData.oosCategory || detailData.oosCategory==0) ? toThousands(detailData.oosCategory) : '--'}}</text>;急件总数量:<text class="sales-total-num" :style="{color: $config('warringColor')}">{{detailData && (detailData.oosQty || detailData.oosQty==0) ? toThousands(detailData.oosQty) : '--'}}</text>;赠品总数量:<text class="sales-total-num" :style="{color: $config('warringColor')}">{{detailData && (detailData.giftQty || detailData.giftQty==0) ? toThousands(detailData.giftQty) : '--'}}</text>;
  42. </view>
  43. <view>
  44. 总成本:<text class="sales-total-num" :style="{color: $config('warringColor')}">¥{{detailData && (detailData.totalCost || detailData.totalCost==0) ? toThousands(detailData.totalCost, 2) : '--'}}</text>;总毛利:<text class="sales-total-num" :style="{color: $config('warringColor')}">¥{{detailData && (detailData.grossProfit || detailData.grossProfit==0) ? toThousands(detailData.grossProfit, 2) : '--'}}</text>;
  45. </view>
  46. </view>
  47. <text class="sales-total-btn" @click="toggle=!toggle" :style="{color: $config('primaryColor')}">{{ toggle ? '收起' : '展开' }}</text>
  48. </view>
  49. <!-- 产品列表 -->
  50. <view class="sales-list-box">
  51. <scroll-view class="sales-list-con" :style="{height: scrollH+'upx'}" scroll-y @scrolltolower="onreachBottom">
  52. <view class="sales-list-item border-b font_13 flex justify_between" v-for="(item, index) in listData" :key="item.id">
  53. <view class="pimgs">
  54. <u-image :src="item.productMainImage?item.productMainImage:`../../static/${theme}/def_img@2x.png`" width="128" height="128" border-radius="10"></u-image>
  55. <view v-if="item.oosFlag == 1" class="sign" :style="{backgroundColor: $config('errorColor')}">急</view>
  56. <view v-if="item.price < item.cost" class="sign" :style="{backgroundColor: $config('errorColor')}">亏</view>
  57. <view v-if="item.price == 0" class="sign" :style="{backgroundColor: $config('errorColor')}">赠</view>
  58. </view>
  59. <view class="sales-item-main flex_1">
  60. <view class="sales-item-name">{{item.productName || '--'}}</view>
  61. <view class="sales-item-txt flex align_center justify_between">
  62. <view>{{item.productCode || '--'}}</view>
  63. <u-icon v-if="pageData.type=='edit'" @click="handleDel(item)" name="trash-fill" :color="$config('errorColor')" size="34"></u-icon>
  64. </view>
  65. <view class="sales-item-txt color_6" style="font-size: 24upx;" v-if="item.warehouseEntity&&item.warehouseEntity.name || item.warehouseLocationEntity&&item.warehouseLocationEntity.name">{{item.warehouseEntity&&item.warehouseEntity.name}} > {{item.warehouseLocationEntity&&item.warehouseLocationEntity.name}}</view>
  66. <view class="sales-item-txt flex align_center justify_between">
  67. <view class="sales-item-priceInfo">
  68. <view :style="{color: $config('errorColor'), display: 'inline-block'}">¥<text style="font-size: 30upx;">{{toThousands(item.price||0, 2)}}</text></view>
  69. <text style="display: inline-block;margin: 0 10upx;">*</text>
  70. <text style="font-size: 30upx;">{{toThousands(item.qty||0)}}</text>
  71. {{item.productUnit}}
  72. </view>
  73. <view class="sales-item-price">¥{{toThousands(item.totalAmount||0, 2)}}</view>
  74. </view>
  75. <view class="sales-item-price" v-if="detailData&&detailData.discountAmount">折后¥{{toThousands(item.discountedAmount||0, 2)}}</view>
  76. </view>
  77. </view>
  78. <view v-if="listData && listData.length == 0">
  79. <u-empty :text="noDataText" mode="list" :img-width="200" :margin-top="30"></u-empty>
  80. </view>
  81. </scroll-view>
  82. </view>
  83. </view>
  84. <!-- 操作按钮 -->
  85. <view class="sales-btn-box">
  86. <view v-if="pageData.type=='edit'" class="flex align_center justify_between">
  87. <u-button class="handle-btn" size="medium" hover-class="none" @click="handleDel()">整单删除</u-button>
  88. <u-button class="handle-btn search-btn" @click="handleSubmit" size="medium" hover-class="none" :custom-style="customBtnStyle">提交</u-button>
  89. </view>
  90. <u-button v-if="pageData.type=='detail' && (detailData&&detailData.billStatus !== 'CANCEL' && detailData.billStatus !== 'FINISH' && detailData.billStatus != 'WAIT_OUT_WAREHOUSE')" class="edit-btn" @click="goPage" size="medium" hover-class="none" :custom-style="customBtnStyle">编辑</u-button>
  91. </view>
  92. <!-- 基础信息 -->
  93. <orderInfoModal :openModal="infoModal" :infoData="detailData" @close="infoModal=false" />
  94. <!-- 折扣 -->
  95. <discountModal :openModal="discountModal" :infoData="detailData" :amount="detailData&&detailData.discountAmount" @confirm="discountConfirm" @close="discountModal=false" />
  96. <!-- 删除产品/整单删除弹框 -->
  97. <common-modal :openModal="delModal" :content="delText" @confirm="handleConfirm" @close="delModal=false" />
  98. </view>
  99. </template>
  100. <script>
  101. import commonModal from '@/pages/common/commonModal.vue'
  102. import OrderInfoModal from './orderInfoModal.vue'
  103. import DiscountModal from './discountModal.vue'
  104. import { toThousands } from '@/libs/tools'
  105. import { salesDetailList, salesDetailDel, salesDel, salesDetail, salesSubmit, salesDiscount } from '@/api/sales'
  106. export default{
  107. components: { OrderInfoModal, DiscountModal, commonModal },
  108. data(){
  109. return{
  110. pageData: {
  111. type: 'edit',
  112. data: null
  113. },
  114. toggle: false,
  115. toThousands,
  116. customBtnStyle: { // 自定义按钮样式
  117. borderColor: this.$config('primaryColor'),
  118. backgroundColor: this.$config('primaryColor'),
  119. color: '#fff'
  120. },
  121. listData: [],
  122. pageNo: 1,
  123. pageSize: 6,
  124. totalNum: 0,
  125. noDataText: '暂无数据',
  126. theme: '',
  127. scrollH: 916,
  128. infoModal: false,
  129. discountModal: false,
  130. delModal: false,
  131. delText: '确认要删除吗?',
  132. dataInfo: null,
  133. detailData: null // 销售单详情
  134. }
  135. },
  136. onLoad(opt) {
  137. this.theme = getApp().globalData.theme
  138. if(opt){
  139. this.pageData = {
  140. type: opt.pageType || 'edit',
  141. data: opt.data ? JSON.parse(opt.data) : null
  142. }
  143. }
  144. this.init()
  145. // 监听整改完成后刷新事件
  146. uni.$on('refreshBL', this.init)
  147. },
  148. onUnload() {
  149. uni.$off('refreshBL')
  150. },
  151. methods: {
  152. init(){
  153. this.getList(1)
  154. this.getDetail()
  155. },
  156. // 列表
  157. getList(pageNo){
  158. const _this = this
  159. if (pageNo) {
  160. this.pageNo = pageNo
  161. }
  162. let params = {
  163. pageNo: this.pageNo,
  164. pageSize: this.pageSize,
  165. salesBillSn: this.pageData.data && this.pageData.data.salesBillSn
  166. }
  167. salesDetailList(params).then(res => {
  168. if (res.status == 200) {
  169. if(res.data && res.data.list){
  170. res.data.list.map(item => {
  171. item.productName = item.productEntity && item.productEntity.name || item.dealerProductEntity && item.dealerProductEntity.name
  172. item.productCode = item.productEntity && item.productEntity.code || item.dealerProductEntity && item.dealerProductEntity.code
  173. item.productUnit = item.productEntity && item.productEntity.unit || item.dealerProductEntity && item.dealerProductEntity.unit
  174. })
  175. if(this.pageNo>1){
  176. this.listData = this.listData.concat(res.data && res.data.list || [])
  177. }else{
  178. this.listData = res.data.list || []
  179. }
  180. }else{
  181. this.listData = []
  182. }
  183. this.totalNum = res.data && res.data.count || 0
  184. } else {
  185. this.listData = []
  186. this.totalNum = 0
  187. this.noDataText = res.message
  188. }
  189. })
  190. },
  191. // scroll-view到底部加载更多
  192. onreachBottom() {
  193. if(this.listData.length < this.totalNum){
  194. this.pageNo += 1
  195. this.getList()
  196. }
  197. },
  198. // 折扣金额
  199. discountConfirm(amount){
  200. let params = {
  201. discountAmount: amount,
  202. salesBillSn: this.detailData.salesBillSn,
  203. id: this.detailData.id
  204. }
  205. salesDiscount(params).then(res => {
  206. if(res.status == 200){
  207. this.init()
  208. this.discountModal = false
  209. }
  210. })
  211. },
  212. // 提交
  213. handleSubmit(){
  214. salesSubmit({ id: this.detailData.id }).then(res => {
  215. if(res.status == 200){
  216. this.toashMsg(res.message)
  217. uni.$emit('refreshBL')
  218. uni.navigateBack()
  219. }
  220. })
  221. },
  222. // 删除
  223. handleDel(item){
  224. if(item){ // 删除产品
  225. this.dataInfo = item
  226. this.delText = '确认要删除吗?'
  227. this.delModal = true
  228. }else{ // 整单删除
  229. this.dataInfo = null
  230. this.delText = '确认删除该销售单吗?'
  231. this.delModal = true
  232. }
  233. },
  234. // 删除
  235. handleConfirm(){
  236. let url = salesDetailDel
  237. let params = {}
  238. if(this.dataInfo){ // 删除产品
  239. url = salesDetailDel
  240. params = { id: this.dataInfo.id }
  241. }else{ // 整单删除
  242. url = salesDel
  243. params = { id: this.detailData && this.detailData.id }
  244. }
  245. url(params).then(res => {
  246. if (res.status == 200) {
  247. if(this.dataInfo){ // 删除产品
  248. this.toashMsg(res.message)
  249. this.init()
  250. }else{ // 整单删除
  251. this.toashMsg(res.message)
  252. uni.$emit('refreshBL')
  253. uni.navigateBack()
  254. }
  255. this.delModal = false
  256. } else {
  257. this.delModal = false
  258. }
  259. })
  260. },
  261. // 选择产品
  262. handleProduct(){
  263. uni.navigateTo({ url: '/pages/sales/chooseProduct?data='+JSON.stringify(this.detailData) })
  264. },
  265. // 编辑
  266. goPage(){
  267. uni.redirectTo({ url: '/pages/sales/edit?pageType=edit&data='+JSON.stringify(this.detailData) })
  268. },
  269. // 销售单详情
  270. getDetail(){
  271. salesDetail({ id: this.pageData.data.id }).then(res => {
  272. if(res.status == 200){
  273. this.detailData = res.data
  274. }else{
  275. this.detailData = null
  276. }
  277. })
  278. },
  279. changeScrollH(){
  280. const _this = this
  281. uni.getSystemInfo({
  282. success: function (res) {
  283. const winH = res.windowHeight * 2
  284. let totalH = _this.$refs.salesTotal && _this.$refs.salesTotal.$el && _this.$refs.salesTotal.$el.offsetHeight || 0
  285. if(_this.toggle){
  286. _this.scrollH = winH - 656 - totalH
  287. }else{
  288. _this.scrollH = winH - 522 - totalH
  289. }
  290. }
  291. })
  292. }
  293. },
  294. watch: {
  295. toggle (newValue, oldValue) {
  296. this.changeScrollH()
  297. }
  298. }
  299. }
  300. </script>
  301. <style lang="scss">
  302. .sales-edit-wrap{
  303. width: 100%;
  304. .color_6{
  305. color: #666;
  306. }
  307. .font_13{
  308. font-size: 26upx;
  309. }
  310. .border-b{
  311. border-bottom: 1px solid #e4e7ed;
  312. }
  313. .u-line{
  314. display: inline-block;
  315. width: 8upx;
  316. height: 40upx;
  317. background-color: red;
  318. vertical-align: bottom;
  319. margin: 0 20upx 0 0;
  320. }
  321. .sales-info-con{
  322. background-color: #fff;
  323. margin-bottom: 20upx;
  324. padding: 0 20upx;
  325. >view{
  326. padding: 14upx 0;
  327. border-bottom: 1px solid #e4e7ed;
  328. }
  329. >view:last-child{
  330. border-bottom: none;
  331. }
  332. .info-item-box{
  333. .info-item-tit{
  334. display: inline-block;
  335. width: 20%;
  336. }
  337. }
  338. }
  339. .sales-product-con{
  340. background-color: #fff;
  341. padding: 0 20upx;
  342. .sales-product-header{
  343. padding: 14upx 0;
  344. .sales-product-operation{
  345. button{
  346. margin: 0 0 0 10upx;
  347. }
  348. }
  349. }
  350. .sales-total-box{
  351. align-items: flex-end;
  352. padding: 16upx 0;
  353. .sales-total-con{
  354. color: #666;
  355. overflow: hidden;
  356. view{
  357. padding: 4upx 0;
  358. .sales-total-num{
  359. font-size: 24upx;
  360. color: rgb(48, 49, 51);
  361. }
  362. }
  363. }
  364. .sales-total-btn{
  365. display: inline-block;
  366. margin-bottom: 6upx;
  367. }
  368. }
  369. .sales-list-box{
  370. .sales-list-con{
  371. .sales-list-item{
  372. padding: 20upx 0;
  373. .pimgs{
  374. margin-right: 20upx;
  375. position: relative;
  376. .sign{
  377. position: absolute;
  378. right: -14upx;
  379. top: -14upx;
  380. color: #fff;
  381. border-radius: 50%;
  382. width: 40upx;
  383. height: 40upx;
  384. text-align: center;
  385. }
  386. }
  387. .sales-item-main{
  388. .sales-item-name{
  389. font-size: 28upx;
  390. color: rgb(48, 49, 51);
  391. font-weight: bold;
  392. overflow: hidden;
  393. text-overflow: ellipsis;
  394. display: -webkit-box;
  395. -webkit-box-orient: vertical;
  396. -webkit-line-clamp: 1;
  397. }
  398. .sales-item-txt{
  399. margin: 8upx 0;
  400. }
  401. .sales-item-price{
  402. text-align: right;
  403. }
  404. }
  405. }
  406. .sales-list-item:last-child{
  407. border: none;
  408. }
  409. }
  410. }
  411. }
  412. .sales-btn-box{
  413. background-color: #fff;
  414. padding: 16upx 20upx 12upx;
  415. .handle-btn{
  416. width: 47%;
  417. }
  418. .edit-btn{
  419. width: 100%;
  420. }
  421. }
  422. }
  423. </style>