index.vue 41 KB

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