index.vue 41 KB

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