chooseProduct.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. <template>
  2. <view class="chooseProduct-wrap">
  3. <!-- 标题 -->
  4. <u-navbar title="选择产品" :safeAreaInsetTop="false" :border-bottom="true">
  5. <view class="u-nav-slot" slot="right" style="padding-right: 40rpx;">
  6. <u-icon name="search" color="#999" size="28" @click="openModal=true"></u-icon>查询
  7. </view>
  8. </u-navbar>
  9. <!-- 产品列表 -->
  10. <view class="product-list-box">
  11. <scroll-view class="product-list-con" :style="{height: scrollH+'upx'}" scroll-y @scrolltolower="onreachBottom">
  12. <view class="product-list-item font_13" v-for="(item, index) in listData" :key="item.id">
  13. <view class="list-item-tit">
  14. <view class="item-tit ellipsis-one" :style="{borderColor: $config('primaryColor')}">{{item.productName}}</view>
  15. </view>
  16. <view class="list-item-con flex align_center justify_between">
  17. <view class="pimgs">
  18. <u-image :src="item.productMainPic&&item.productMainPic.imageUrl?item.productMainPic.imageUrl:`../../static/${theme}/def_img@2x.png`" width="128" height="128" border-radius="10"></u-image>
  19. </view>
  20. <view class="flex_1">
  21. <view>产品编码:{{item.productCode || '--'}}</view>
  22. <view class="padding_3 flex align_center justify_between">
  23. <view>原厂编码:{{item.productOrigCode || '--'}}</view>
  24. <u-icon name="plus-circle" :color="$config('primaryColor')" size="40" class="close-circle" @click="handleAdd(item, 'add')"></u-icon>
  25. </view>
  26. <view v-if="item.warehouseName || item.warehouseLocationName">仓库仓位:{{item.warehouseName}} > {{item.warehouseLocationName}}</view>
  27. </view>
  28. </view>
  29. <view class="list-item-footer flex align_center justify_between">
  30. <view class="footer-item">
  31. <view>{{toThousands(item.currentQty||0)}}{{item.unit}}</view>
  32. <view class="color_6">库存数量</view>
  33. </view>
  34. <view class="footer-item">
  35. <view>
  36. <text :style="{color: $config('errorColor')}">{{toThousands(item.price||0, 2)}}</text>
  37. <text v-if="item.origSalePriceFlag == 1">(原)</text>
  38. </view>
  39. <view class="color_6">参考售价</view>
  40. </view>
  41. </view>
  42. </view>
  43. <view v-if="listData && listData.length == 0">
  44. <u-empty :text="noDataText" mode="list" :img-width="200" :margin-top="30"></u-empty>
  45. </view>
  46. </scroll-view>
  47. </view>
  48. <!-- 合计 -->
  49. <view ref="productTotal" class="selected-box flex align_center justify_between">
  50. <view class="choose-info flex_1 flex align_center justify_between" @click="lookProduct">
  51. <text>已选 {{detailData && (detailData.totalCategory || detailData.totalCategory==0) ? toThousands(detailData.totalCategory) : '--'}} 款,合计 ¥{{detailData && (detailData.totalAmount || detailData.totalAmount==0) ? toThousands(detailData.totalAmount, 2) : '--'}}</text>
  52. <u-icon name="arrow-up" :color="$config('primaryColor')" size="34" class="close-circle"></u-icon>
  53. </view>
  54. <view class="choose-btn" @click="handleChoose" :style="{backgroundColor: $config('primaryColor')}">选好了</view>
  55. </view>
  56. <!-- 查询右侧弹框 -->
  57. <productSearch :openModal="openModal" :defaultParams="searchParams" @refresh="refresh" @close="openModal=false" />
  58. <!-- 添加/编辑产品 -->
  59. <productModal :openModal="openProductModal" :infoData="productData" @confirm="productConfirm" @close="openProductModal=false" />
  60. <!-- 已选产品 -->
  61. <selectedProductsModal :openModal="openSelectedModal" :nowData="detailData" @confirm="handleChoose" @refreshTotal="selectedProductTotal" @close="openSelectedModal=false" />
  62. <!-- 弹框 -->
  63. <common-modal :openModal="commonModal" :content="modalText" @confirm="handleCommon" @close="commonModal=false" />
  64. </view>
  65. </template>
  66. <script>
  67. import ProductSearch from './productSearch.vue'
  68. import ProductModal from './productModal.vue'
  69. import SelectedProductsModal from './selectedProductsModal.vue'
  70. import commonModal from '@/pages/common/commonModal.vue'
  71. import { toThousands } from '@/libs/tools'
  72. import { querySumByProductLocation } from '@/api/stock'
  73. import { salesDetail, supperCodeByVin } from '@/api/sales'
  74. export default{
  75. components: { ProductSearch, ProductModal, SelectedProductsModal, commonModal },
  76. data(){
  77. return{
  78. toThousands,
  79. listData: [],
  80. pageNo: 1,
  81. pageSize: 6,
  82. totalNum: 0,
  83. noDataText: '暂无数据',
  84. searchParams: {},
  85. openModal: false,
  86. theme: '',
  87. salesInfo: null, // 销售单信息
  88. scrollH: 0,
  89. openProductModal: false, // 编辑产品信息弹框是否显示
  90. productData: null, // 当前操作的产品信息
  91. chooseType: 'add', // 添加产品add,编辑产品edit
  92. commonModal: false, // 公共弹框是否显示
  93. modalText: '', // 公共弹框提示语
  94. commonType: 1, // 公共弹框类型 1为添加产品时库存不足,2为编辑产品时库存不足,
  95. openSelectedModal: false, // 已选产品弹框是否显示
  96. detailData: null // 销售单详情数据
  97. }
  98. },
  99. onNavigationBarButtonTap(e){ // 标题栏 按钮操作
  100. this.openModal = true
  101. },
  102. onLoad(opt) {
  103. this.theme = getApp().globalData.theme
  104. if(opt){
  105. this.salesInfo = opt.data ? JSON.parse(opt.data) : null
  106. }
  107. this.init()
  108. const _this = this
  109. uni.getSystemInfo({
  110. success: function (res) {
  111. const winH = res.windowHeight * 2
  112. _this.scrollH = winH - 180
  113. }
  114. })
  115. },
  116. methods: {
  117. init(){
  118. this.getList(1) // 产品列表
  119. this.selectedProductTotal() // 已选产品合计
  120. },
  121. // 获取查询参数 刷新列表
  122. refresh(params){
  123. console.log('查询', params)
  124. const _this = this
  125. if(params.vinCode && params.vinCode.length == 17){
  126. // 查询vin码
  127. supperCodeByVin({ vin: params.vinCode }).then(res => {
  128. if(res.status == 200){
  129. params.productCodeList = res.data.partCodeList || []
  130. this.searchParams = params
  131. this.getList(1)
  132. }
  133. })
  134. }else{
  135. this.searchParams = params
  136. this.getList(1)
  137. }
  138. },
  139. // 列表
  140. getList(pageNo){
  141. const _this = this
  142. if (pageNo) {
  143. this.pageNo = pageNo
  144. }
  145. let params = {
  146. pageNo: this.pageNo,
  147. pageSize: this.pageSize
  148. }
  149. let searchParams = JSON.parse(JSON.stringify(this.searchParams))
  150. searchParams.brandName = undefined
  151. searchParams.nowData = undefined
  152. searchParams.warehouseName = undefined
  153. querySumByProductLocation(Object.assign(params, searchParams, { customerSn: this.salesInfo.buyerSn })).then(res => {
  154. if (res.status == 200) {
  155. if(res.data && res.data.list){
  156. res.data.list.map(item => {
  157. item.salesNums = 1
  158. item.currentQty = item.currentQty || 0
  159. item.price = item.lastSalePrice ? item.lastSalePrice : item.salePrice
  160. })
  161. }
  162. if(this.pageNo>1){
  163. this.listData = this.listData.concat(res.data.list || [])
  164. }else{
  165. this.listData = res.data.list || []
  166. }
  167. this.totalNum = res.data.count || 0
  168. } else {
  169. this.listData = []
  170. this.totalNum = 0
  171. this.noDataText = res.message
  172. }
  173. })
  174. },
  175. // scroll-view到底部加载更多
  176. onreachBottom() {
  177. if(this.listData.length < this.totalNum){
  178. this.pageNo += 1
  179. this.getList()
  180. }
  181. },
  182. // 添加/编辑产品
  183. handleAdd(data, type){
  184. this.openProductModal = true
  185. this.chooseType = type
  186. this.productData = data
  187. },
  188. // 选好了
  189. handleChoose(){
  190. uni.redirectTo({ url: '/pages/sales/edit?pageType=edit&data='+JSON.stringify(this.detailData) })
  191. },
  192. // 查看已选产品
  193. lookProduct(){
  194. this.openSelectedModal = true
  195. },
  196. // 确认产品信息
  197. productConfirm(data){
  198. console.log('form',data)
  199. console.log('info',this.productData)
  200. if (this.productData.lastSalePrice && (this.productData.price < this.productData.salePrice)) { // 售价低于定价
  201. }
  202. if(this.chooseType == 'add'){
  203. // 库存不足时
  204. if (this.productData.currentQty < data.qty) {
  205. this.commonType = 1
  206. this.modalText = '库存不足,将产生急件,确认要添加吗?'
  207. this.commonModal = true
  208. }else{
  209. }
  210. }else if(this.chooseType == 'edit'){
  211. // 库存不足时
  212. if (this.productData.currentQty < this.productData.salesNums) {
  213. this.commonType = 2
  214. this.modalText = '库存不足,将产生急件,确认修改吗?'
  215. this.commonModal = true
  216. }else{
  217. }
  218. }
  219. // this.openProductModal = false
  220. },
  221. addProduct(data){
  222. },
  223. // 公共弹框
  224. handleCommon(){
  225. if(this.commonType == 1){ // 添加产品时库存不足
  226. }else if(this.commonType == 2){ // 编辑产品时库存不足
  227. }
  228. },
  229. // 已选产品 提交
  230. selectedConfirm(){},
  231. // 已选产品合计
  232. selectedProductTotal(){
  233. salesDetail({ id: this.salesInfo.id }).then(res => {
  234. if(res.status == 200){
  235. this.detailData = res.data
  236. }else{
  237. this.detailData = null
  238. }
  239. })
  240. },
  241. }
  242. }
  243. </script>
  244. <style lang="scss">
  245. .chooseProduct-wrap{
  246. width: 100%;
  247. position: relative;
  248. .padding_3{
  249. padding: 6upx 0;
  250. }
  251. .color_6{
  252. color: #666;
  253. }
  254. .product-list-box{
  255. padding: 20upx 20upx;
  256. .product-list-con{
  257. .product-list-item{
  258. background: #ffffff;
  259. padding: 20upx 20upx 0;
  260. margin-bottom: 25upx;
  261. border-radius: 25upx;
  262. box-shadow: 1px 1px 3px #EEEEEE;
  263. .list-item-tit{
  264. padding-bottom: 12upx;
  265. border-bottom: 1px solid #e4e7ed;
  266. .item-tit{
  267. font-weight: bold;
  268. color: rgb(48, 49, 51);
  269. font-size: 28upx;
  270. padding-left: 10upx;
  271. border-left: 6upx solid #000;
  272. line-height: 1;
  273. }
  274. }
  275. .list-item-con{
  276. padding: 14upx 14upx 16upx;
  277. font-size: 26upx;
  278. .pimgs{
  279. margin-right: 16upx;
  280. }
  281. }
  282. .list-item-footer{
  283. border-top: 1px solid #e4e7ed;
  284. .footer-item{
  285. width: 50%;
  286. text-align: center;
  287. border-right: 1px solid #e4e7ed;
  288. font-size: 26upx;
  289. padding: 8upx 0 12upx;
  290. }
  291. .footer-item:last-child{
  292. border: none;
  293. }
  294. }
  295. }
  296. }
  297. }
  298. .selected-box{
  299. background-color: #fff;
  300. box-shadow: 1px -1px 3px #EEEEEE;
  301. .choose-info{
  302. padding: 0 30upx;
  303. }
  304. .choose-btn{
  305. color: #fff;
  306. width: 28%;
  307. padding: 26upx 0;
  308. text-align: center;
  309. }
  310. }
  311. }
  312. </style>