index.vue 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420
  1. <template>
  2. <div class="app-container">
  3. <el-row :gutter="20" class="retail-container">
  4. <!-- 左侧会员信息和购物车 -->
  5. <el-col :span="8" class="left-panel">
  6. <el-card class="member-card">
  7. <!-- 会员搜索 -->
  8. <div class="member-search">
  9. <el-input
  10. v-model="queryParams.phoneNumber"
  11. placeholder="请输入会员手机号"
  12. clearable
  13. prefix-icon="el-icon-user"
  14. @clear="clearAppUserInfo"
  15. maxlength="11"
  16. @keyup.enter.native="searchUser"
  17. >
  18. <el-button slot="append" icon="el-icon-search" @click="searchUser"></el-button>
  19. </el-input>
  20. </div>
  21. <!-- 会员信息展示 -->
  22. <div class="member-info" v-if="appUserInfo">
  23. <div class="member-header">
  24. <div class="avatar">
  25. <i class="el-icon-user-solid"></i>
  26. </div>
  27. <div class="basic-info">
  28. <div class="name">{{appUserInfo.realName || '未设置姓名'}}</div>
  29. <div class="level">{{appUserInfo.level || '普通会员'}}</div>
  30. </div>
  31. </div>
  32. <div class="balance-info">
  33. <div class="balance-item">
  34. <div class="label">账户余额</div>
  35. <div class="value">¥{{formatMoney(appUserInfo.rechargeBalance + appUserInfo.giveBalance)}}</div>
  36. </div>
  37. <div class="balance-item">
  38. <div class="label">现金余额</div>
  39. <div class="value">¥{{formatMoney(appUserInfo.rechargeBalance)}}</div>
  40. </div>
  41. <div class="balance-item">
  42. <div class="label">赠送余额</div>
  43. <div class="value">¥{{formatMoney(appUserInfo.giveBalance)}}</div>
  44. </div>
  45. </div>
  46. </div>
  47. <!-- 购物车列表 -->
  48. <div class="cart-container">
  49. <div class="cart-header">
  50. <div class="title">
  51. <i class="el-icon-shopping-cart-2"></i>
  52. <span>购物车</span>
  53. <span class="count" v-if="addGoodsList.length">({{addGoodsList.length}})</span>
  54. </div>
  55. <el-button type="text" @click="clearCart" v-if="addGoodsList.length">
  56. <i class="el-icon-delete"></i>
  57. 清空
  58. </el-button>
  59. </div>
  60. <div class="cart-list" :class="{'empty': !addGoodsList.length}">
  61. <el-table
  62. v-if="addGoodsList.length"
  63. :data="addGoodsList"
  64. size="midium"
  65. :header-cell-style="{background:'#f5f7fa'}"
  66. :cell-style="{padding: '5px 0'}"
  67. >
  68. <el-table-column label="商品信息" min-width="200">
  69. <template slot-scope="scope">
  70. <div class="goods-info">
  71. <div class="goods-name">{{scope.row.goodsName}}</div>
  72. <div class="goods-spec">{{formatSpec(scope.row.specValLists)}}</div>
  73. </div>
  74. </template>
  75. </el-table-column>
  76. <el-table-column label="数量" width="180" align="center">
  77. <template slot-scope="scope">
  78. <el-input-number
  79. v-model="getPurchaseCount(scope.row).count"
  80. :min="1"
  81. :max="scope.row.stock"
  82. size="mini"
  83. @change="countPrice"
  84. ></el-input-number>
  85. </template>
  86. </el-table-column>
  87. <el-table-column label="小计" width="100" align="right">
  88. <template slot-scope="scope">
  89. <span class="subtotal">¥{{formatMoney(scope.row.salePrice * getPurchaseCount(scope.row).count)}}</span>
  90. </template>
  91. </el-table-column>
  92. <el-table-column width="80" align="center">
  93. <template slot-scope="scope">
  94. <el-button type="text" class="delete-btn" @click="deleteGoods(scope.row)">
  95. <i class="el-icon-delete"></i>
  96. </el-button>
  97. </template>
  98. </el-table-column>
  99. </el-table>
  100. <div v-else class="empty-cart">
  101. <img
  102. :src="noGoodsImage"
  103. :onerror="defaultImageError"
  104. alt="商品图片"
  105. >
  106. <p>购物车是空的</p>
  107. </div>
  108. </div>
  109. <!-- 结算区域 -->
  110. <div class="settlement-panel">
  111. <div class="amount-info">
  112. <div class="total-row">
  113. <span>商品数量:</span>
  114. <span class="number">{{calculateTotalCount}}件</span>
  115. </div>
  116. <div class="total-row">
  117. <span>商品总额:</span>
  118. <span class="amount">¥{{formatMoney(calculateTotalPrice)}}</span>
  119. </div>
  120. </div>
  121. <el-button
  122. type="primary"
  123. class="settle-btn"
  124. @click="submitCash"
  125. :disabled="!appUserInfo || !addGoodsList.length"
  126. >
  127. <i class="el-icon-wallet"></i>
  128. 收银结算
  129. </el-button>
  130. </div>
  131. </div>
  132. </el-card>
  133. </el-col>
  134. <!-- 右侧商品选择区域 -->
  135. <el-col :span="16" class="right-panel">
  136. <el-card>
  137. <!-- 搜索栏 -->
  138. <div class="search-bar">
  139. <el-input
  140. v-model="searchQuery"
  141. placeholder="请输入商品条码/名称"
  142. clearable
  143. @clear="handleSearchClear"
  144. @keyup.enter.native="handleSearch"
  145. >
  146. <el-button slot="append" icon="el-icon-search" @click="handleSearch"></el-button>
  147. </el-input>
  148. </div>
  149. <!-- 商品分类标签页 -->
  150. <el-tabs
  151. v-model="activeCategory"
  152. @tab-click="handleCategoryChange"
  153. class="goods-tabs"
  154. >
  155. <el-tab-pane
  156. v-for="category in categoryList"
  157. :key="category.id"
  158. :label="category.categoryName"
  159. :name="category.id.toString()"
  160. >
  161. <!-- 商品列表 -->
  162. <div class="goods-container">
  163. <div class="goods-grid">
  164. <el-card
  165. v-for="goods in goodsList"
  166. :key="goods.goodsCode"
  167. shadow="hover"
  168. class="goods-item"
  169. :class="{'out-of-stock': goods.stock <= 0}"
  170. @click.native="goods.stock > 0 && selectSpec(goods)"
  171. >
  172. <img
  173. :src="goods.goodsImg || defaultImage"
  174. :onerror="defaultImageError"
  175. class="goods-img"
  176. alt="商品图片"
  177. >
  178. <div class="goods-info">
  179. <div class="goods-name" :title="goods.goodsName">{{goods.goodsName}}</div>
  180. <div class="goods-price">¥{{formatMoney(goods.salePrice)}}</div>
  181. <div class="goods-stock" :class="{'low-stock': goods.stock <= 5 && goods.stock > 0}">
  182. 库存: {{goods.stock}}
  183. </div>
  184. </div>
  185. <div class="stock-overlay" v-if="goods.stock <= 0">
  186. <i class="el-icon-warning"></i>
  187. <span>无库存</span>
  188. </div>
  189. </el-card>
  190. </div>
  191. <!-- 分页器 -->
  192. <div class="pagination-container">
  193. <el-pagination
  194. @size-change="handleSizeChange"
  195. @current-change="handleCurrentChange"
  196. :current-page="queryParamsGoods.pageNum"
  197. :page-sizes="[20, 40, 60, 80]"
  198. :page-size="queryParamsGoods.pageSize"
  199. layout="total, sizes, prev, pager, next, jumper"
  200. :total="total"
  201. background
  202. >
  203. </el-pagination>
  204. </div>
  205. </div>
  206. </el-tab-pane>
  207. </el-tabs>
  208. </el-card>
  209. </el-col>
  210. </el-row>
  211. <!-- 选择规格弹窗 -->
  212. <el-dialog title="选择规格" :visible.sync="skuOpen" width="500px">
  213. <el-table :data="goodsSkuList" v-loading="skuLoading">
  214. <el-table-column label="规格" prop="specVoList">
  215. <template slot-scope="scope">
  216. {{formatSpec(scope.row.specValLists)}}
  217. </template>
  218. </el-table-column>
  219. <el-table-column label="价格" prop="salePrice" width="100" align="right">
  220. <template slot-scope="scope">
  221. ¥{{formatMoney(scope.row.salePrice)}}
  222. </template>
  223. </el-table-column>
  224. <el-table-column label="库存" prop="stock" width="80" align="center"/>
  225. <el-table-column label="操作" width="80" align="center">
  226. <template slot-scope="scope">
  227. <el-button type="text" @click="addGoods(scope.row)" :disabled="scope.row.stock <= 0">
  228. 选择
  229. </el-button>
  230. </template>
  231. </el-table-column>
  232. </el-table>
  233. </el-dialog>
  234. <!-- 收银结算弹窗 -->
  235. <el-dialog
  236. title="收银结算"
  237. :visible.sync="payOpen"
  238. width="600px"
  239. :close-on-click-modal="false"
  240. custom-class="settlement-dialog"
  241. >
  242. <!-- 订单信息概览 -->
  243. <div class="order-summary">
  244. <div class="summary-row">
  245. <div class="summary-item">
  246. <div class="label">商品总数</div>
  247. <div class="value highlight-blue">{{calculateTotalCount}}件</div>
  248. </div>
  249. <div class="summary-item">
  250. <div class="label">商品总额</div>
  251. <div class="value highlight-red">¥{{formatMoney(calculateTotalPrice)}}</div>
  252. </div>
  253. <div class="summary-item">
  254. <div class="label">会员余额</div>
  255. <div class="value highlight-green">¥{{formatMoney(appUserInfo ? appUserInfo.rechargeBalance + appUserInfo.giveBalance : 0)}}</div>
  256. </div>
  257. </div>
  258. </div>
  259. <el-form ref="payFrom" :model="payFrom" label-width="100px" class="settlement-form">
  260. <!-- 优惠信息 -->
  261. <div class="section-card">
  262. <div class="section-title">
  263. <i class="el-icon-ticket"></i>
  264. 优惠信息
  265. </div>
  266. <el-form-item label="抵扣金额" prop="deductAmount">
  267. <el-input-number
  268. v-model="payFrom.deductAmount"
  269. :min="0"
  270. :max="calculateTotalPrice"
  271. :precision="2"
  272. :step="1"
  273. :controls="true"
  274. style="width: 200px"
  275. placeholder="请输入抵扣金额"
  276. ></el-input-number>
  277. <span class="form-tip">最大可抵扣: ¥{{formatMoney(calculateTotalPrice)}}</span>
  278. </el-form-item>
  279. <div class="amount-display">
  280. <span>折后应付:</span>
  281. <span class="highlight-amount">¥{{formatMoney(calculatePayMoney)}}</span>
  282. </div>
  283. </div>
  284. <!-- 支付方式 -->
  285. <div class="section-card">
  286. <div class="section-title">
  287. <i class="el-icon-wallet"></i>
  288. 支付方式
  289. </div>
  290. <div class="payment-methods">
  291. <el-radio-group v-model="payFrom.payType" @change="changePayType" size="large">
  292. <el-radio-button label="3">
  293. <i class="el-icon-money"></i>
  294. 余额支付
  295. </el-radio-button>
  296. <el-radio-button label="2">
  297. <i class="el-icon-coin"></i>
  298. 现金支付
  299. </el-radio-button>
  300. <el-radio-button label="0">
  301. <i class="el-icon-chat-dot-square"></i>
  302. 微信支付
  303. </el-radio-button>
  304. <el-radio-button label="1">
  305. <i class="el-icon-chat-line-square"></i>
  306. 支付宝
  307. </el-radio-button>
  308. </el-radio-group>
  309. </div>
  310. <!-- 根据支付方式显示不同的输入项 -->
  311. <div class="payment-details" v-if="payFrom.payType">
  312. <!-- 余额支付 -->
  313. <template v-if="payFrom.payType === '3'">
  314. <div class="balance-info" v-if="appUserInfo">
  315. <div class="info-item">
  316. <span class="label">会员姓名:</span>
  317. <span class="value">{{appUserInfo.realName || '- -'}}</span>
  318. </div>
  319. <div class="info-item">
  320. <span class="label">可用余额:</span>
  321. <span class="value highlight-green">¥{{formatMoney(appUserInfo.rechargeBalance + appUserInfo.giveBalance)}}</span>
  322. </div>
  323. </div>
  324. </template>
  325. <!-- 现金支付 -->
  326. <template v-if="payFrom.payType === '2'">
  327. <el-form-item label="收款金额" prop="thisPayMoney" class="cash-payment">
  328. <el-input-number
  329. v-model="payFrom.thisPayMoney"
  330. :min="calculatePayMoney"
  331. :precision="2"
  332. :step="10"
  333. :controls="true"
  334. style="width: 200px"
  335. placeholder="请输入收款金额"
  336. ></el-input-number>
  337. <div class="change-amount" v-if="payFrom.thisPayMoney >= calculatePayMoney">
  338. <span class="label">找零:</span>
  339. <span class="value highlight-blue">¥{{formatMoney(payFrom.thisPayMoney - calculatePayMoney)}}</span>
  340. </div>
  341. </el-form-item>
  342. </template>
  343. <!-- 微信支付 -->
  344. <template v-if="payFrom.payType === '0'">
  345. <el-form-item label="付款码" prop="wxBarcode">
  346. <el-input
  347. v-model="payFrom.wxBarcode"
  348. style="width: 300px"
  349. placeholder="请扫描微信付款码"
  350. prefix-icon="el-icon-scan"
  351. autofocus
  352. ></el-input>
  353. </el-form-item>
  354. </template>
  355. <!-- 支付宝支付 -->
  356. <template v-if="payFrom.payType === '1'">
  357. <el-form-item label="付款码" prop="aliPayBarcode">
  358. <el-input
  359. v-model="payFrom.aliPayBarcode"
  360. style="width: 300px"
  361. placeholder="请扫描支付宝付款码"
  362. prefix-icon="el-icon-scan"
  363. autofocus
  364. ></el-input>
  365. </el-form-item>
  366. </template>
  367. </div>
  368. </div>
  369. </el-form>
  370. <!-- 结算按钮 -->
  371. <div slot="footer" class="dialog-footer">
  372. <el-button @click="payOpen = false">取 消</el-button>
  373. <el-button type="primary" @click="submitSettlement" :loading="submitting">
  374. 确认结算
  375. </el-button>
  376. </div>
  377. </el-dialog>
  378. </div>
  379. </template>
  380. <script>
  381. import { getGoodsListToGoodsRetail, getGoodsSkuListToGoodsRetail, purchaseListSku } from '@/api/core/sku'
  382. import { listCategory } from '@/api/core/category'
  383. import { findUserByPhoneNumber } from '@/api/app/user'
  384. import { listBrand } from '@/api/core/brand'
  385. import { insertRetailOrderGoods, getGoods } from '@/api/order/goods'
  386. import { getLodop } from "@/utils/lodopUtils";
  387. export default {
  388. name: "goodsRetail",
  389. dicts: ['sys_yes_no'],
  390. data() {
  391. return {
  392. // 客户信息
  393. appUserInfo: null,
  394. // 商品列表等待
  395. goodsLoading: false,
  396. // 物料列表等待
  397. skuLoading: false,
  398. // 总条数
  399. total: 0,
  400. // 弹出层标题
  401. title: "",
  402. // 是否显示弹出层 物料页面弹框
  403. skuOpen: false,
  404. // 收银支付页面弹框
  405. payOpen: false,
  406. // 查询参数
  407. queryParams: {
  408. pageNum: 1,
  409. pageSize: 10,
  410. },
  411. // 查询分类+品牌的查询参数
  412. queryParams2: {
  413. pageNum: 1,
  414. pageSize: 9999,
  415. status: '0',
  416. goodsType: null,
  417. },
  418. // 查询参数
  419. queryParamsGoods: {
  420. pageNum: 1,
  421. pageSize: 20,
  422. goodsCategoryId: null,
  423. keywords: ''
  424. },
  425. // 支付表单参数
  426. payFrom: {
  427. },
  428. // 表单校验
  429. rules: {
  430. },
  431. goodsType: null,
  432. // 分类id
  433. goodsCategoryId: null,
  434. // 可选商品集合
  435. goodsList: null,
  436. // 可选商品物料集合
  437. goodsSkuList: null,
  438. // 已选商品集合
  439. addGoodsList: [],
  440. // 左侧分类集合
  441. categoryList: null,
  442. // 品牌list
  443. brandList: {},
  444. // 自定义一个计算数量的临时对象集合
  445. purchaseCountVOList: [],
  446. // 总金额
  447. totalPrice: 0,
  448. // 总件数
  449. totalCount: 0,
  450. // 提交的参数对象
  451. submitGoodsOrderDTO: {},
  452. // 需要支付的金额
  453. payMoney: null,
  454. LODOP: null,
  455. number: 1,
  456. pointerList: [],
  457. userInfoVO: null,
  458. activeCategory: '', // 当前选中的分类
  459. noGoodsImage: require("@/assets/images/nogoods.png"), // 添加默认图片
  460. defaultImage: require("@/assets/images/profile.jpg"), // 添加默认图片
  461. defaultImageError: 'this.src="' + require("@/assets/images/profile.jpg") + '"' , // 图片加载失败时的处理
  462. searchQuery: '', // 搜索关键词
  463. searchType: 'name', // 搜索类型
  464. submitting: false,
  465. };
  466. },
  467. created() {
  468. this.handleUser();
  469. this.goodsType = this.getUrlParam('goodsType');
  470. this.getCategoryList().then(() => {
  471. if (this.categoryList && this.categoryList.length > 0) {
  472. this.activeCategory = this.categoryList[0].id.toString();
  473. this.goodsCategoryId = this.categoryList[0].id;
  474. this.getGoodsList();
  475. }
  476. });
  477. this.getBrandList();
  478. },
  479. mounted() {
  480. this.number = 1;
  481. const printerTime = setInterval(() => {
  482. this.LODOP = getLodop();
  483. this.number++
  484. if (this.number == 25) {
  485. clearInterval(printerTime);
  486. }
  487. if (this.LODOP) {
  488. clearInterval(printerTime);
  489. }
  490. }, 200)
  491. this.pointerList = JSON.parse(this.$cache.local.get("printerSeting"));
  492. },
  493. computed: {
  494. calculateTotalCount() {
  495. this.totalCount = 0;
  496. this.addGoodsList.forEach(vo => {
  497. let number = this.purchaseCountVOList.find(item => item.goodsSkuStoreId == vo.goodsSkuStoreId).count;
  498. this.totalCount = this.totalCount + number;
  499. });
  500. return this.totalCount;
  501. },
  502. calculateTotalPrice() {
  503. this.totalPrice = 0;
  504. this.addGoodsList.forEach(vo => {
  505. let number = this.purchaseCountVOList.find(item => item.goodsSkuStoreId == vo.goodsSkuStoreId).count;
  506. this.totalPrice = this.totalPrice + (number * vo.salePrice);
  507. });
  508. return this.totalPrice;
  509. },
  510. calculatePayMoney() {
  511. this.payMoney = this.payFrom.deductAmount ? this.totalPrice - this.payFrom.deductAmount : this.totalPrice;
  512. return this.payMoney;
  513. }
  514. },
  515. methods: {
  516. handleUser() {
  517. this.userInfoVO = this.getUserInfo();
  518. },
  519. // 切换支付方式
  520. changePayType() {
  521. delete this.payFrom.thisPayMoney
  522. },
  523. // 收银
  524. submitCash() {
  525. if (this.appUserInfo == null) {
  526. this.$message.error("请选择客户");
  527. return;
  528. }
  529. if (this.calculateTotalCount == 0) {
  530. this.$message.error("请选择商品");
  531. }
  532. this.payOpen = true;
  533. },
  534. // 清空用户数据
  535. clearAppUserInfo() {
  536. this.appUserInfo = null;
  537. },
  538. //搜索用户
  539. searchUser() {
  540. if (this.queryParams.phoneNumber == null || this.queryParams.phoneNumber == '') {
  541. return;
  542. }
  543. findUserByPhoneNumber(this.queryParams).then(res => {
  544. this.appUserInfo = res.data;
  545. })
  546. },
  547. // 获取商品分类列表
  548. getCategoryList() {
  549. return listCategory({ ...this.queryParams2, ...{ goodsType: this.goodsType } }).then(response2 => {
  550. this.categoryList = response2.rows;
  551. });
  552. },
  553. // 获取品牌
  554. getBrandList() {
  555. listBrand({ ...this.queryParams2, ...{ goodsType: this.goodsType } }).then(response1 => {
  556. this.brandList = response1.rows;
  557. });
  558. },
  559. // 已选择列表中,删除商品按钮
  560. deleteGoods(row) {
  561. this.addGoodsList = this.addGoodsList.filter((item) => {
  562. return item.goodsSkuStoreId !== row.goodsSkuStoreId;
  563. })
  564. this.purchaseCountVOList = this.purchaseCountVOList.filter((item) => {
  565. return item.goodsSkuStoreId !== row.goodsSkuStoreId;
  566. })
  567. },
  568. // 未选列表中,添加按钮
  569. addGoods(row) {
  570. if (row.stock <= 0) {
  571. this.$message.warning("该商品已售罄");
  572. return;
  573. }
  574. if (this.addGoodsList.length > 0) {
  575. let match = this.addGoodsList.findIndex(item => item.goodsSkuStoreId == row.goodsSkuStoreId)
  576. if (match !== -1) {
  577. let purchaseVo = this.purchaseCountVOList.find(item => item.goodsSkuStoreId == row.goodsSkuStoreId);
  578. if (purchaseVo.count >= row.stock) {
  579. this.$message.warning("库存不足");
  580. return;
  581. }
  582. purchaseVo.count++;
  583. this.skuOpen = false;
  584. this.$forceUpdate();
  585. return;
  586. }
  587. }
  588. this.addGoodsList.push(row);
  589. this.purchaseCountVOList.push({
  590. 'goodsSkuStoreId': row.goodsSkuStoreId,
  591. 'goodsCategoryId': this.goodsCategoryId,
  592. 'goodsCategoryName': this.categoryList.find(item => item.id == this.goodsCategoryId).categoryName,
  593. 'count': 1
  594. })
  595. this.skuOpen = false;
  596. this.$forceUpdate();
  597. },
  598. // 操作数量增减时,计算价格
  599. countPrice() {
  600. this.totalPrice = 0;
  601. this.totalCount = 0;
  602. this.addGoodsList.forEach(vo => {
  603. let number = this.purchaseCountVOList.find(item => item.goodsSkuStoreId == vo.goodsSkuStoreId).count;
  604. this.totalPrice = this.totalPrice + (number * vo.salePrice);
  605. this.totalCount = this.totalCount + number;
  606. })
  607. },
  608. // 左侧商品分类列表,单击事件
  609. handleNodeClick(data) {
  610. this.goodsCategoryId = data.id;
  611. this.getGoodsList();
  612. },
  613. // 获取商品列表
  614. getGoodsList() {
  615. this.goodsLoading = true;
  616. if (this.goodsCategoryId == null) {
  617. this.goodsList = [];
  618. this.goodsLoading = false;
  619. return;
  620. }
  621. this.queryParamsGoods.goodsCategoryId = this.goodsCategoryId;
  622. getGoodsListToGoodsRetail(this.queryParamsGoods).then(response => {
  623. this.goodsList = response.rows;
  624. this.total = response.total; // 假设后端返回total字段
  625. this.goodsLoading = false;
  626. }).catch(() => {
  627. this.goodsLoading = false;
  628. });
  629. },
  630. // 选择商品规格
  631. selectSpec(row) {
  632. if (row.stock <= 0) {
  633. this.$message.warning("该商品已售罄");
  634. return;
  635. }
  636. this.skuLoading = true;
  637. getGoodsSkuListToGoodsRetail(row.id).then(response => {
  638. this.goodsSkuList = response.data;
  639. this.skuLoading = false;
  640. this.skuOpen = true;
  641. });
  642. },
  643. // 结算
  644. submitSettlement() {
  645. this.$confirm('是否确认结算?').then(() => {
  646. if (this.totalCount == 0) {
  647. this.$message.error("请选择商品");
  648. return;
  649. }
  650. if (this.payFrom.payType == null || this.payFrom.payType == '') {
  651. this.$message.error("请选择支付方式");
  652. return;
  653. }
  654. if (this.payFrom.deductAmount != null || this.payFrom.deductAmount != '') {
  655. if (this.payFrom.deductAmount > this.payMoney) {
  656. this.$message.error("抵扣金额不能大于支付金额");
  657. return;
  658. }
  659. }
  660. if (this.payFrom.payType == '1') {
  661. if (this.appUserInfo.rechargeBalance + this.appUserInfo.giveBalance < this.payMoney) {
  662. this.$message.error("用户余额不足");
  663. return;
  664. }
  665. }
  666. if (this.payFrom.payType == '2') {
  667. if (this.payFrom.thisPayMoney < this.payMoney) {
  668. this.$message.error("现金金额不够支付");
  669. return;
  670. }
  671. }
  672. this.submitGoodsOrderDTO = {};
  673. // 设置订单基础信息
  674. this.submitGoodsOrderDTO.totalPrice = this.totalPrice;
  675. this.submitGoodsOrderDTO.goodsType = this.goodsType;
  676. this.submitGoodsOrderDTO.deductAmount = this.payFrom.deductAmount;
  677. this.submitGoodsOrderDTO.appUserId = this.appUserInfo.id;
  678. this.submitGoodsOrderDTO.payAmount = this.payMoney;
  679. this.submitGoodsOrderDTO.payType = this.payFrom.payType;
  680. // 设置订单商品物料信息
  681. this.submitGoodsOrderDTO.retailGoodsVOList = [];
  682. this.addGoodsList.forEach(vo => {
  683. let purchaseVO = this.purchaseCountVOList.find(item => item.goodsSkuStoreId == vo.goodsSkuStoreId)
  684. let purchaseGoodsVO = {};
  685. purchaseGoodsVO.skuId = vo.id;
  686. purchaseGoodsVO.goodsId = vo.goodsId;
  687. purchaseGoodsVO.goodsName = vo.goodsName;
  688. purchaseGoodsVO.goodsImg = vo.goodsImg;
  689. purchaseGoodsVO.goodsCategoryId = purchaseVO.goodsCategoryId;
  690. purchaseGoodsVO.goodsCategoryName = purchaseVO.goodsCategoryName;
  691. purchaseGoodsVO.marketPrice = vo.salePrice;
  692. purchaseGoodsVO.buyNum = purchaseVO.count;
  693. purchaseGoodsVO.skuName = '';
  694. vo.specVoList.forEach(spec => {
  695. purchaseGoodsVO.skuName = purchaseGoodsVO.skuName + spec.specName + ':' + spec.specValue + ' '
  696. });
  697. this.submitGoodsOrderDTO.retailGoodsVOList.push(purchaseGoodsVO);
  698. });
  699. insertRetailOrderGoods(this.submitGoodsOrderDTO).then(response => {
  700. this.$modal.msgSuccess("结算完成");
  701. this.addGoodsList = [];
  702. this.purchaseCountVOList = [];
  703. this.submitGoodsOrderDTO = {};
  704. this.searchUser();
  705. this.payOpen = false;
  706. this.btn_lodop(response.data.orderId);
  707. });
  708. }).catch(() => { this.payOpen = false; });
  709. },
  710. btn_lodop(id) {
  711. if (!this.LODOP) {
  712. this.$modal.msgError("请安装打印机软件");
  713. return
  714. }
  715. let p_name = '';
  716. this.pointerList.forEach(pointer => {
  717. if (pointer.printType == 0) {
  718. p_name = pointer.printName
  719. }
  720. })
  721. getGoods(id).then((res) => {
  722. if (this.userInfoVO.userType == '02') {
  723. const obj = {
  724. name: this.userInfoVO.storeName,
  725. contactPhone: this.userInfoVO.phonenumber,
  726. user: this.userInfoVO.nickName,
  727. }
  728. res.data.sysOrg = obj
  729. }
  730. res.data.newTime = this.formatDates(new Date(), 1)
  731. this.goodsPrinter(this.LODOP, res.data, p_name)
  732. });
  733. },
  734. // 格式化规格信息
  735. formatSpec(specList) {
  736. if (!specList || !specList.length) return '默认规格';
  737. return specList.join(' ');
  738. },
  739. // 格式化金额
  740. formatMoney(value) {
  741. if (!value) return '0.00';
  742. return Number(value).toFixed(2);
  743. },
  744. // 切换商品分类
  745. handleCategoryChange(tab) {
  746. this.goodsCategoryId = tab.name;
  747. this.queryParamsGoods.pageNum = 1; // 切换分类时重置到第一页
  748. this.getGoodsList();
  749. },
  750. // 清空购物车
  751. clearCart() {
  752. this.$confirm('确认清空购物车?', '提示', {
  753. type: 'warning'
  754. }).then(() => {
  755. this.addGoodsList = [];
  756. this.purchaseCountVOList = [];
  757. });
  758. },
  759. // 获取商品购买数量
  760. getPurchaseCount(goods) {
  761. return this.purchaseCountVOList.find(item => item.goodsSkuStoreId === goods.goodsSkuStoreId) || { count: 0 };
  762. },
  763. // 处理搜索
  764. handleSearch() {
  765. this.queryParamsGoods.keywords = this.searchQuery;
  766. this.queryParamsGoods.searchType = this.searchType;
  767. this.queryParamsGoods.pageNum = 1; // 重置到第一页
  768. this.getGoodsList();
  769. },
  770. // 清除搜索
  771. handleSearchClear() {
  772. this.searchQuery = '';
  773. this.queryParamsGoods.keywords = '';
  774. this.getGoodsList();
  775. },
  776. // 处理分页大小改变
  777. handleSizeChange(val) {
  778. this.queryParamsGoods.pageSize = val;
  779. this.getGoodsList();
  780. },
  781. // 处理页码改变
  782. handleCurrentChange(val) {
  783. this.queryParamsGoods.pageNum = val;
  784. this.getGoodsList();
  785. },
  786. }
  787. };
  788. </script>
  789. <style lang="scss" scoped>
  790. .head-container-two {
  791. height: calc(100vh - 250px);
  792. display: block;
  793. overflow-y: scroll;
  794. }
  795. .head-column1 {
  796. height: calc(50vh - 130px);
  797. display: block;
  798. overflow-y: scroll;
  799. }
  800. .head-goods {
  801. height: auto;
  802. display: block;
  803. overflow-y: scroll;
  804. }
  805. .box-shadow {
  806. font-size: 18px;
  807. }
  808. .goods-grid {
  809. display: grid;
  810. grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); // 减小商品卡片的最小宽度
  811. gap: 10px; // 减小间距
  812. padding: 10px;
  813. .goods-item {
  814. position: relative;
  815. cursor: pointer;
  816. transition: all 0.3s;
  817. &.out-of-stock {
  818. cursor: not-allowed;
  819. opacity: 0.7;
  820. &:hover {
  821. transform: none;
  822. box-shadow: none;
  823. }
  824. }
  825. .el-card__body {
  826. padding: 8px; // 减小内边距
  827. }
  828. .goods-img {
  829. width: 100%;
  830. height: 120px; // 减小图片高度
  831. object-fit: cover;
  832. border-radius: 4px;
  833. background-color: #f5f7fa;
  834. }
  835. .goods-info {
  836. padding: 5px 0;
  837. .goods-name {
  838. font-size: 12px;
  839. margin-bottom: 3px;
  840. overflow: hidden;
  841. text-overflow: ellipsis;
  842. white-space: nowrap;
  843. color: #303133;
  844. }
  845. .goods-price {
  846. color: #f56c6c;
  847. font-size: 14px;
  848. font-weight: bold;
  849. margin-bottom: 3px;
  850. }
  851. .goods-stock {
  852. font-size: 12px;
  853. color: #67c23a;
  854. &.low-stock {
  855. color: #e6a23c;
  856. }
  857. }
  858. }
  859. .stock-overlay {
  860. position: absolute;
  861. top: 0;
  862. left: 0;
  863. right: 0;
  864. bottom: 0;
  865. background: rgba(0, 0, 0, 0.5);
  866. display: flex;
  867. flex-direction: column;
  868. align-items: center;
  869. justify-content: center;
  870. color: white;
  871. font-size: 14px;
  872. i {
  873. font-size: 24px;
  874. margin-bottom: 5px;
  875. }
  876. }
  877. }
  878. }
  879. // 优化右侧面板的滚动
  880. .right-panel {
  881. .el-card {
  882. height: 100%;
  883. .el-card__body {
  884. height: 100%;
  885. padding: 10px;
  886. .el-tabs {
  887. height: 100%;
  888. display: flex;
  889. flex-direction: column;
  890. .el-tabs__content {
  891. flex: 1;
  892. overflow-y: auto;
  893. .el-tab-pane {
  894. height: 100%;
  895. }
  896. }
  897. }
  898. }
  899. }
  900. }
  901. // 添加滚动条样式
  902. .right-panel {
  903. ::-webkit-scrollbar {
  904. width: 6px;
  905. height: 6px;
  906. }
  907. ::-webkit-scrollbar-thumb {
  908. background: #dcdfe6;
  909. border-radius: 3px;
  910. }
  911. ::-webkit-scrollbar-track {
  912. background: #f5f7fa;
  913. }
  914. }
  915. // 优化分类标签样式
  916. .el-tabs__item {
  917. height: 30px;
  918. line-height: 30px;
  919. font-size: 13px;
  920. }
  921. .left-panel {
  922. height: 100%;
  923. .member-card {
  924. height: 100%;
  925. display: flex;
  926. flex-direction: column;
  927. .member-search {
  928. padding: 15px;
  929. border-bottom: 1px solid #ebeef5;
  930. .el-input {
  931. .el-input__inner {
  932. border-radius: 20px 0 0 20px;
  933. }
  934. .el-input-group__append {
  935. border-radius: 0 20px 20px 0;
  936. background-color: #409EFF;
  937. border-color: #409EFF;
  938. color: white;
  939. }
  940. }
  941. }
  942. .member-info {
  943. padding: 15px;
  944. background: #f8f9fa;
  945. border-radius: 8px;
  946. margin: 15px;
  947. .member-header {
  948. display: flex;
  949. align-items: center;
  950. margin-bottom: 15px;
  951. .avatar {
  952. width: 50px;
  953. height: 50px;
  954. border-radius: 25px;
  955. background: #e6f2ff;
  956. display: flex;
  957. align-items: center;
  958. justify-content: center;
  959. margin-right: 15px;
  960. i {
  961. font-size: 24px;
  962. color: #409EFF;
  963. }
  964. }
  965. .basic-info {
  966. .name {
  967. font-size: 16px;
  968. font-weight: bold;
  969. color: #303133;
  970. margin-bottom: 4px;
  971. }
  972. .level {
  973. font-size: 12px;
  974. color: #909399;
  975. }
  976. }
  977. }
  978. .balance-info {
  979. display: grid;
  980. grid-template-columns: repeat(3, 1fr);
  981. gap: 10px;
  982. .balance-item {
  983. text-align: center;
  984. padding: 10px;
  985. background: white;
  986. border-radius: 6px;
  987. .label {
  988. font-size: 12px;
  989. color: #909399;
  990. margin-bottom: 5px;
  991. }
  992. .value {
  993. font-size: 16px;
  994. font-weight: bold;
  995. color: #f56c6c;
  996. }
  997. }
  998. }
  999. }
  1000. .no-member {
  1001. text-align: center;
  1002. padding: 30px 0;
  1003. color: #909399;
  1004. i {
  1005. font-size: 48px;
  1006. margin-bottom: 10px;
  1007. }
  1008. p {
  1009. font-size: 14px;
  1010. }
  1011. }
  1012. .cart-container {
  1013. flex: 1;
  1014. display: flex;
  1015. flex-direction: column;
  1016. margin: 0 15px;
  1017. .cart-header {
  1018. display: flex;
  1019. justify-content: space-between;
  1020. align-items: center;
  1021. padding: 10px 0;
  1022. border-bottom: 1px solid #ebeef5;
  1023. .title {
  1024. display: flex;
  1025. align-items: center;
  1026. i {
  1027. font-size: 18px;
  1028. margin-right: 5px;
  1029. color: #409EFF;
  1030. }
  1031. .count {
  1032. font-size: 12px;
  1033. color: #909399;
  1034. margin-left: 5px;
  1035. }
  1036. }
  1037. }
  1038. .cart-list {
  1039. flex: 1;
  1040. overflow-y: auto;
  1041. &.empty {
  1042. display: flex;
  1043. align-items: center;
  1044. justify-content: center;
  1045. }
  1046. .empty-cart {
  1047. text-align: center;
  1048. color: #909399;
  1049. i {
  1050. font-size: 48px;
  1051. margin-bottom: 10px;
  1052. }
  1053. p {
  1054. font-size: 14px;
  1055. }
  1056. }
  1057. .goods-info {
  1058. .goods-name {
  1059. font-size: 13px;
  1060. color: #303133;
  1061. margin-bottom: 3px;
  1062. }
  1063. .goods-spec {
  1064. font-size: 12px;
  1065. color: #909399;
  1066. }
  1067. }
  1068. .subtotal {
  1069. color: #f56c6c;
  1070. font-weight: bold;
  1071. }
  1072. .delete-btn {
  1073. padding: 0;
  1074. i {
  1075. font-size: 16px;
  1076. color: #909399;
  1077. &:hover {
  1078. color: #f56c6c;
  1079. }
  1080. }
  1081. }
  1082. }
  1083. .settlement-panel {
  1084. border-top: 1px solid #ebeef5;
  1085. padding: 15px 0;
  1086. .amount-info {
  1087. margin-bottom: 15px;
  1088. .total-row {
  1089. display: flex;
  1090. justify-content: space-between;
  1091. align-items: center;
  1092. margin-bottom: 8px;
  1093. &:last-child {
  1094. margin-bottom: 0;
  1095. }
  1096. .number {
  1097. color: #409EFF;
  1098. font-weight: bold;
  1099. }
  1100. .amount {
  1101. color: #f56c6c;
  1102. font-size: 20px;
  1103. font-weight: bold;
  1104. }
  1105. }
  1106. }
  1107. .settle-btn {
  1108. width: 100%;
  1109. height: 40px;
  1110. border-radius: 20px;
  1111. font-size: 16px;
  1112. i {
  1113. margin-right: 5px;
  1114. }
  1115. }
  1116. }
  1117. }
  1118. }
  1119. }
  1120. .settlement-dialog {
  1121. .order-summary {
  1122. background: #f8f9fa;
  1123. border-radius: 8px;
  1124. padding: 20px;
  1125. margin-bottom: 20px;
  1126. .summary-row {
  1127. display: grid;
  1128. grid-template-columns: repeat(3, 1fr);
  1129. gap: 20px;
  1130. .summary-item {
  1131. text-align: center;
  1132. .label {
  1133. font-size: 14px;
  1134. color: #606266;
  1135. margin-bottom: 8px;
  1136. }
  1137. .value {
  1138. font-size: 20px;
  1139. font-weight: bold;
  1140. &.highlight-blue { color: #409EFF; }
  1141. &.highlight-red { color: #f56c6c; }
  1142. &.highlight-green { color: #67c23a; }
  1143. }
  1144. }
  1145. }
  1146. }
  1147. .section-card {
  1148. background: #fff;
  1149. border-radius: 8px;
  1150. padding: 20px;
  1151. margin-bottom: 20px;
  1152. box-shadow: 0 2px 12px 0 rgba(0,0,0,.05);
  1153. .section-title {
  1154. font-size: 16px;
  1155. font-weight: bold;
  1156. color: #303133;
  1157. margin-bottom: 20px;
  1158. display: flex;
  1159. align-items: center;
  1160. i {
  1161. margin-right: 8px;
  1162. font-size: 18px;
  1163. color: #409EFF;
  1164. }
  1165. }
  1166. .form-tip {
  1167. margin-left: 10px;
  1168. color: #909399;
  1169. font-size: 13px;
  1170. }
  1171. .amount-display {
  1172. margin-top: 15px;
  1173. text-align: right;
  1174. font-size: 16px;
  1175. .highlight-amount {
  1176. color: #f56c6c;
  1177. font-size: 24px;
  1178. font-weight: bold;
  1179. margin-left: 10px;
  1180. }
  1181. }
  1182. }
  1183. .payment-methods {
  1184. margin-bottom: 20px;
  1185. .el-radio-group {
  1186. display: grid;
  1187. grid-template-columns: repeat(4, 1fr);
  1188. gap: 10px;
  1189. .el-radio-button {
  1190. display: block;
  1191. width: 100%;
  1192. ::v-deep .el-radio-button__inner {
  1193. width: 100%;
  1194. height: 60px;
  1195. display: flex;
  1196. flex-direction: column;
  1197. align-items: center;
  1198. justify-content: center;
  1199. padding: 0;
  1200. border-radius: 4px;
  1201. i {
  1202. font-size: 24px;
  1203. margin-bottom: 5px;
  1204. }
  1205. }
  1206. }
  1207. }
  1208. }
  1209. .payment-details {
  1210. padding: 20px;
  1211. background: #f8f9fa;
  1212. border-radius: 4px;
  1213. .balance-info {
  1214. .info-item {
  1215. margin-bottom: 10px;
  1216. display: flex;
  1217. align-items: center;
  1218. .label {
  1219. width: 100px;
  1220. color: #606266;
  1221. }
  1222. .value {
  1223. font-weight: bold;
  1224. &.highlight-green { color: #67c23a; }
  1225. }
  1226. }
  1227. }
  1228. .cash-payment {
  1229. .change-amount {
  1230. margin-top: 10px;
  1231. .label {
  1232. color: #606266;
  1233. }
  1234. .value {
  1235. font-size: 20px;
  1236. font-weight: bold;
  1237. }
  1238. }
  1239. }
  1240. }
  1241. }
  1242. .right-panel {
  1243. .search-bar {
  1244. padding: 15px;
  1245. border-bottom: 1px solid #ebeef5;
  1246. .el-input {
  1247. width: 100%;
  1248. max-width: 600px;
  1249. }
  1250. }
  1251. .goods-tabs {
  1252. height: calc(100% - 80px); // 减去搜索栏的高度
  1253. ::v-deep .el-tabs__content {
  1254. height: calc(100% - 40px); // 减去标签页头部的高度
  1255. }
  1256. }
  1257. .goods-container {
  1258. height: 100%;
  1259. display: flex;
  1260. flex-direction: column;
  1261. }
  1262. .goods-grid {
  1263. flex: 1;
  1264. overflow-y: auto;
  1265. padding: 15px;
  1266. display: grid;
  1267. grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  1268. gap: 15px;
  1269. .goods-item {
  1270. cursor: pointer;
  1271. transition: all 0.3s;
  1272. &:hover {
  1273. transform: translateY(-2px);
  1274. box-shadow: 0 2px 12px 0 rgba(0,0,0,.1);
  1275. }
  1276. }
  1277. }
  1278. .pagination-container {
  1279. padding: 15px;
  1280. text-align: right;
  1281. background: #fff;
  1282. border-top: 1px solid #ebeef5;
  1283. height: 35px;
  1284. }
  1285. }
  1286. </style>