calculator.vue 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264
  1. <template>
  2. <view class="calc-page">
  3. <scroll-view class="calc-scroll" scroll-y :enable-back-to-top="false">
  4. <view class="calc-sheet">
  5. <view class="calc-card-wrap">
  6. <view
  7. class="calc-section"
  8. :class="{ 'calc-section-active': keyboardTarget === 'calc' }"
  9. @tap="focusCalc"
  10. >
  11. <view class="calc-actions-top">
  12. <view class="discount-entry" @tap.stop="openDiscountPopup" hover-class="discount-entry-hover">
  13. <text class="discount-entry-glyph">折</text>
  14. </view>
  15. <text class="calc-section-title">计算器</text>
  16. <view class="history-entry" @tap.stop="openCalcHistory" hover-class="history-entry-hover">
  17. <text class="iconfont iconmingxi1 history-entry-icon"></text>
  18. </view>
  19. </view>
  20. <view class="calc-formula">
  21. <block v-if="tokens.length === 0 && isEmptyCalcInput">
  22. <text class="calc-placeholder">输入数字</text>
  23. </block>
  24. <view v-else class="calc-formula-inner">
  25. <block v-for="(t, idx) in tokens" :key="'tok-' + idx">
  26. <text v-if="t.type === 'num'" class="calc-num">{{ t.s }}</text>
  27. <text v-else class="calc-op">{{ t.o }}</text>
  28. </block>
  29. <text v-if="!isEmptyCalcInput" class="calc-num">{{ calcInput }}</text>
  30. </view>
  31. </view>
  32. <view class="calc-total-row">
  33. <text class="calc-total-label">应收金额</text>
  34. <text class="calc-total-val">{{ formatMoney(stackDiscountedAmount) }}</text>
  35. </view>
  36. <view v-if="isDiscountActive" class="calc-discount-row">
  37. <text class="calc-discount-label">{{ formatDiscountZheLabel(discountZhe) }}后</text>
  38. <text class="calc-discount-val">{{ formatMoney(stackDiscountedAmount) }}</text>
  39. </view>
  40. </view>
  41. <view class="customer-strip" @tap.stop="pickCustomer">
  42. <text class="customer-strip-label">客户</text>
  43. <text class="customer-strip-name">{{ customerDisplayName }}</text>
  44. <text class="customer-strip-action">修改客户</text>
  45. </view>
  46. <view v-if="showBalanceRow" class="balance-strip">
  47. <text class="balance-strip-label">余额</text>
  48. <text class="balance-strip-val">¥{{ formatMoney(customInfo.balance) }}</text>
  49. <text v-if="balanceCoversDue && selHasPay === 4" class="balance-strip-hint balance-strip-hint-ok">余额充足</text>
  50. <text v-else-if="balanceCoversDue && selHasPay !== 4" class="balance-strip-hint balance-strip-hint-tip">可选用「余额」收款</text>
  51. </view>
  52. <view class="rcv-pay-block">
  53. <view class="rcv-pay-title">收款方式</view>
  54. <view class="rcv-item-row">
  55. <view
  56. v-for="item in optHasPayList"
  57. :key="'hp-' + item.id"
  58. class="rcv-item-chip"
  59. :data-hpid="String(item.id)"
  60. :class="{ active: selHasPay === item.id }"
  61. @tap.stop="onHasPayChipTap"
  62. >
  63. {{ item.name }}
  64. </view>
  65. </view>
  66. <view v-if="selHasPay === 0" class="rcv-pay-hint">
  67. <text class="rcv-pay-hint-text">扫码付款、分享小程序付款</text>
  68. </view>
  69. <view v-if="selHasPay === 2" class="rcv-pay-hint">
  70. <text class="rcv-pay-hint-text">客户赊账欠款请选挂账</text>
  71. </view>
  72. <view v-if="selHasPay === 4" class="rcv-pay-hint">
  73. <text class="rcv-pay-hint-text">使用客户余额扣款</text>
  74. </view>
  75. <view v-if="selHasPay === 1" class="rcv-sub-block">
  76. <view class="rcv-pay-title rcv-pay-title-sub">线下渠道</view>
  77. <view class="rcv-item-row">
  78. <view
  79. v-for="item in optPayWayList"
  80. :key="'pw-' + item.id"
  81. class="rcv-item-chip"
  82. :data-pwid="String(item.id)"
  83. :class="{ active: selPayWay === item.id }"
  84. @tap.stop="onPayWayChipTap"
  85. >
  86. {{ item.name }}
  87. </view>
  88. </view>
  89. </view>
  90. </view>
  91. <view v-if="showCashPayCols" class="pay-cash-panel">
  92. <view class="pay-cash-item" @tap="checkCurrent(2)">
  93. <text class="pay-cash-desc">收到现金</text>
  94. <text
  95. class="pay-cash-amt"
  96. :class="{ 'pay-cash-amt-selected': keyboardTarget !== 'calc' && checkType == 2 }"
  97. >
  98. {{ formatMoney(cash) }}
  99. </text>
  100. </view>
  101. <view class="pay-cash-item pay-cash-item-change">
  102. <view class="pay-change-line">
  103. <text v-if="Number(zl) > 0" class="lbl-ok">找零</text>
  104. <text v-else-if="Number(zl) < 0" class="lbl-bad">还差</text>
  105. <text v-else class="lbl-neu">找零</text>
  106. </view>
  107. <text v-if="Number(zl) > 0" class="amt-ok">{{ formatChangeAmount(zl) }}</text>
  108. <text v-else-if="Number(zl) < 0" class="amt-bad">{{ formatChangeAmount(-zl) }}</text>
  109. <text v-else class="amt-neu">—</text>
  110. </view>
  111. </view>
  112. <view class="pay-submit-row">
  113. <view class="pay-submit-btn pay-submit-btn-outline" @tap.stop="stashCurrent">暂存</view>
  114. <view class="pay-submit-btn" @tap.stop="submitCashierPay">提交</view>
  115. </view>
  116. <view class="safe-bottom-spacer" />
  117. </view>
  118. </view>
  119. </scroll-view>
  120. <view class="numpad-dock safe-area-padding">
  121. <view class="numpad">
  122. <view class="numpad-grid-wrap">
  123. <view class="numpad-cell"><view class="numpad-key" data-char="1" @tap="onNumpadTap">1</view></view>
  124. <view class="numpad-cell"><view class="numpad-key" data-char="2" @tap="onNumpadTap">2</view></view>
  125. <view class="numpad-cell"><view class="numpad-key" data-char="3" @tap="onNumpadTap">3</view></view>
  126. <view class="numpad-cell numpad-cell-op numpad-cell-mul">
  127. <view class="numpad-key numpad-key-op" data-action="calc-mul" @tap="onNumpadTap">×</view>
  128. </view>
  129. <view class="numpad-cell"><view class="numpad-key" data-char="4" @tap="onNumpadTap">4</view></view>
  130. <view class="numpad-cell"><view class="numpad-key" data-char="5" @tap="onNumpadTap">5</view></view>
  131. <view class="numpad-cell"><view class="numpad-key" data-char="6" @tap="onNumpadTap">6</view></view>
  132. <view class="numpad-cell numpad-cell-op numpad-cell-add">
  133. <view class="numpad-key numpad-key-op numpad-key-op-add" data-action="calc-add" @tap="onNumpadTap">
  134. +
  135. </view>
  136. </view>
  137. <view class="numpad-cell"><view class="numpad-key" data-char="7" @tap="onNumpadTap">7</view></view>
  138. <view class="numpad-cell"><view class="numpad-key" data-char="8" @tap="onNumpadTap">8</view></view>
  139. <view class="numpad-cell"><view class="numpad-key" data-char="9" @tap="onNumpadTap">9</view></view>
  140. <view class="numpad-cell"><view class="numpad-key numpad-key-muted" data-char="." @tap="onNumpadTap">.</view></view>
  141. <view class="numpad-cell"><view class="numpad-key" data-char="0" @tap="onNumpadTap">0</view></view>
  142. <view class="numpad-cell"><view class="numpad-key" data-char="00" @tap="onNumpadTap">00</view></view>
  143. <view class="numpad-cell numpad-cell-op numpad-cell-sub">
  144. <view class="numpad-key numpad-key-op" data-action="calc-sub" @tap="onNumpadTap">−</view>
  145. </view>
  146. <view class="numpad-cell numpad-cell-actions-row">
  147. <view
  148. class="numpad-key numpad-key-action-dual numpad-key-action-muted"
  149. @tap.stop="tapClearCalculator"
  150. >
  151. <text class="numpad-key-text">清空</text>
  152. </view>
  153. <view
  154. class="numpad-key numpad-key-danger numpad-key-action-dual"
  155. data-action="backspace"
  156. @tap="onNumpadTap"
  157. >
  158. <text class="numpad-key-text">删除</text>
  159. </view>
  160. </view>
  161. <view class="numpad-cell numpad-cell-op numpad-cell-div">
  162. <view class="numpad-key numpad-key-op" data-action="calc-div" @tap="onNumpadTap">÷</view>
  163. </view>
  164. </view>
  165. </view>
  166. </view>
  167. <uni-popup ref="calcHistoryPopup" type="center" background-color="#ffffff" @change="onCalcHistoryPopupChange">
  168. <view class="mob-popup-wrap mob-popup-history">
  169. <view class="mob-popup-hd">
  170. <text class="mob-popup-title">暂存记录</text>
  171. <text class="mob-popup-close" @tap.stop="onHistoryPopupCloseTap">关闭</text>
  172. </view>
  173. <scroll-view scroll-y class="mob-popup-body">
  174. <view v-for="(row, idx) in calcHistory" :key="row.id || 'hist-' + idx" class="history-item">
  175. <view class="history-item-body" :data-idx="idx" @tap.stop="onHistoryRowTap">
  176. <view class="history-line">
  177. <text class="history-time">{{ row.timeLabel }}</text>
  178. <text class="history-total">合计 {{ formatMoney(row.total) }}</text>
  179. </view>
  180. <text class="history-detail">{{ row.detailText }}</text>
  181. </view>
  182. <text class="history-del" :data-idx="idx" @tap.stop="onHistoryDeleteTap">删除</text>
  183. </view>
  184. <view v-if="calcHistory.length === 0" class="history-empty">暂无记录</view>
  185. </scroll-view>
  186. </view>
  187. </uni-popup>
  188. <uni-popup ref="discountPopup" type="center" background-color="#ffffff" @change="onDiscountPopupChange">
  189. <view class="mob-popup-wrap mob-popup-discount">
  190. <view class="mob-popup-hd">
  191. <text class="mob-popup-title">折扣</text>
  192. <text class="mob-popup-close" @tap.stop="onDiscountPopupCloseTap">关闭</text>
  193. </view>
  194. <view class="discount-toolbar">
  195. <view class="discount-custom-row">
  196. <input
  197. class="discount-custom-input"
  198. v-model="customZheInput"
  199. type="digit"
  200. placeholder="如 8.8 折"
  201. confirm-type="done"
  202. />
  203. <view class="discount-custom-add-btn" @tap.stop="addCustomDiscountZhe">添加</view>
  204. </view>
  205. <text v-if="customDiscountZheList.length > 0" class="discount-toolbar-hint">
  206. 已存 {{ customDiscountZheList.length }} 条,点下方选用
  207. </text>
  208. <text v-else class="discount-toolbar-hint discount-toolbar-hint-muted">先输入折扣数字再点添加</text>
  209. </view>
  210. <scroll-view scroll-y class="mob-popup-body discount-options-scroll">
  211. <view
  212. class="discount-option"
  213. :class="{ 'discount-option-active': isZheActive(10) }"
  214. data-zhe="10"
  215. @tap.stop="onDiscountRowPickTap"
  216. >
  217. <text class="discount-option-text">无折扣</text>
  218. <text v-if="isZheActive(10)" class="discount-option-check">✓</text>
  219. </view>
  220. <view
  221. v-for="(z, cidx) in customDiscountZheList"
  222. :key="'d-' + cidx + '-' + z"
  223. class="discount-option discount-option-with-del"
  224. :class="{ 'discount-option-active': isZheActive(z) }"
  225. >
  226. <view class="discount-option-main" :data-zhe="String(z)" @tap.stop="onDiscountRowPickTap">
  227. <text class="discount-option-text">{{ formatDiscountRowLabel(z) }}</text>
  228. <text v-if="isZheActive(z)" class="discount-option-check">✓</text>
  229. </view>
  230. <text class="discount-option-del" :data-cidx="String(cidx)" @tap.stop="onCustomDiscountDeleteTap">
  231. 删除
  232. </text>
  233. </view>
  234. </scroll-view>
  235. </view>
  236. </uni-popup>
  237. <uni-popup ref="cashShortPopup" type="center" background-color="#ffffff" @change="onCashShortPopupChange">
  238. <view class="mob-popup-wrap mob-popup-cash-short">
  239. <view class="mob-popup-hd">
  240. <text class="mob-popup-title">现金不足</text>
  241. </view>
  242. <text class="cash-short-desc">实收现金不足,还可以再用微信和支付宝付款</text>
  243. <view class="cash-short-way-row">
  244. <view
  245. class="cash-short-way-chip"
  246. :class="{ 'cash-short-way-chip-on': cashShortPick === 0 }"
  247. @tap.stop="setCashShortPick(0)"
  248. >
  249. 微信
  250. </view>
  251. <view
  252. class="cash-short-way-chip"
  253. :class="{ 'cash-short-way-chip-on': cashShortPick === 1 }"
  254. @tap.stop="setCashShortPick(1)"
  255. >
  256. 支付宝
  257. </view>
  258. </view>
  259. <view class="cash-short-actions">
  260. <view class="cash-short-btn cash-short-btn-cancel" @tap.stop="closeCashShortPopupByCancel">取消</view>
  261. <view class="cash-short-btn cash-short-btn-ok" @tap.stop="confirmCashShortWay">确认并提交</view>
  262. </view>
  263. </view>
  264. </uni-popup>
  265. </view>
  266. </template>
  267. <script>
  268. import { createOrder } from '@/api/order/index'
  269. import { getCustomInfo } from '@/api/custom'
  270. import { mapActions, mapGetters } from 'vuex'
  271. const CALC_HISTORY_STORAGE_KEY = 'hdApp_calculator_calcHistory'
  272. const DISCOUNT_CUSTOM_STORAGE_KEY = 'hdApp_calculator_customDiscountZhe'
  273. const DISCOUNT_SELECTED_STORAGE_KEY = 'hdApp_calculator_discountZhe'
  274. /** 计算器选客回填:hdApp 零售 selectCustom 使用 style=6(style=3 为花束开单) */
  275. const CALCULATOR_PICK_CUSTOMER_KEY = 'hdApp_calculator_pick_customer'
  276. /** 与首页「快捷开单」一致:取自 loginInfo.skCustomId,界面展示名固定 */
  277. const SHORTCUT_CUSTOM_DISPLAY_NAME = '快捷开单'
  278. const SETTLE_FORM_DEFAULTS = {
  279. sendType: 1,
  280. hasPay: 0,
  281. payWay: 0,
  282. needPrint: 2,
  283. freight: '',
  284. groupName: '',
  285. remark: '',
  286. sendCost: 0,
  287. customSendCost: 0,
  288. labourCost: 0,
  289. modifyPrice: 0,
  290. getStaffId: 0,
  291. getStaffName: '',
  292. shopAdminId: 0,
  293. shopAdminName: '',
  294. cash: 0,
  295. dealPrice: 1,
  296. fromType: 1,
  297. reductionRule: 0,
  298. callErrand: 0,
  299. weight: 1,
  300. deliveryRemark: '',
  301. }
  302. export default {
  303. name: 'ToolsCalculator',
  304. data() {
  305. return {
  306. customId: 0,
  307. customName: '',
  308. price: 0,
  309. checkType: 3,
  310. keyboardTarget: 'calc',
  311. name: '',
  312. cash: 0,
  313. tokens: [],
  314. calcInput: '',
  315. calcHistory: [],
  316. maxHistory: 20,
  317. _historyPopupCloseByApi: false,
  318. discountZhe: 10,
  319. customDiscountZheList: [],
  320. customZheInput: '',
  321. _discountPopupCloseByApi: false,
  322. selHasPay: 0,
  323. selPayWay: 0,
  324. optHasPayList: [
  325. { name: '扫码', id: 0 },
  326. { name: '余额', id: 4 },
  327. { name: '线下', id: 1 },
  328. { name: '挂账', id: 2 },
  329. ],
  330. optPayWayList: [
  331. { name: '微信', id: 0 },
  332. { name: '支付宝', id: 1 },
  333. { name: '现金', id: 4 },
  334. { name: '银行卡', id: 5 },
  335. ],
  336. customInfo: { discount: 1, balance: 0 },
  337. cashShortPick: 0,
  338. _cashShortPopupCloseByApi: false,
  339. }
  340. },
  341. computed: {
  342. ...mapGetters({
  343. loginInfo: 'getLoginInfo',
  344. getMerchantInfo: 'getMerchantInfo',
  345. }),
  346. /** 工作台「快捷开单」客户 id,与 workbench skKd 使用的 loginInfo.skCustomId 一致 */
  347. shortcutCustomerId() {
  348. const login = this.loginInfo || {}
  349. const sid = login.skCustomId
  350. if (this.$util.isEmpty(sid) || Number(sid) <= 0) return 0
  351. return Number(sid)
  352. },
  353. customerDisplayName() {
  354. const n = (this.customName || '').trim()
  355. if (n) return n
  356. const skid = this.shortcutCustomerId
  357. if (Number(this.customId) > 0 && skid > 0 && Number(this.customId) === skid) {
  358. return SHORTCUT_CUSTOM_DISPLAY_NAME
  359. }
  360. if (Number(this.customId) > 0) return '—'
  361. return '未选择'
  362. },
  363. isEmptyCalcInput() {
  364. return this.$util.isEmpty(this.calcInput)
  365. },
  366. stackTotal() {
  367. const { nums, ops } = this.buildEvalState()
  368. if (!nums.length) return 0
  369. const r = this.evalExpr(nums, ops)
  370. return isNaN(r) ? 0 : r
  371. },
  372. discountRate() {
  373. const z = Number(this.discountZhe)
  374. if (isNaN(z) || z <= 0) return 1
  375. return Math.min(10, Math.max(0.01, z)) / 10
  376. },
  377. stackDiscountedAmount() {
  378. const raw = Number(this.stackTotal)
  379. if (isNaN(raw)) return 0
  380. return parseFloat((raw * this.discountRate).toFixed(2))
  381. },
  382. isDiscountActive() {
  383. return Number(this.discountZhe) < 10 - 1e-6
  384. },
  385. zl() {
  386. if (!(this.selHasPay === 1 && this.selPayWay === 4)) return 0
  387. let amount = 0
  388. if (Number(this.cash) > 0 && Number(this.price) > 0) {
  389. amount = Number(this.cash) - Number(this.price)
  390. amount = parseFloat(amount.toFixed(2))
  391. }
  392. return Number(amount)
  393. },
  394. showCashPayCols() {
  395. return this.selHasPay === 1 && this.selPayWay === 4
  396. },
  397. showBalanceRow() {
  398. const b = Number(this.customInfo && this.customInfo.balance)
  399. return Number.isFinite(b) && b > 0 && Number(this.customId) > 0
  400. },
  401. balanceCoversDue() {
  402. const b = Number(this.customInfo && this.customInfo.balance) || 0
  403. const due =
  404. this.keyboardTarget === 'calc'
  405. ? Number(this.stackDiscountedAmount)
  406. : Number(this.price)
  407. const p = Number(due)
  408. if (!Number.isFinite(p) || p <= 0) return false
  409. return b + 1e-6 >= p
  410. },
  411. },
  412. watch: {
  413. shortcutCustomerId(n) {
  414. if (n > 0 && Number(this.customId) <= 0) this.applyDefaultShortcutCustomer()
  415. },
  416. stackDiscountedAmount: {
  417. handler(v) {
  418. if (this.keyboardTarget === 'calc') {
  419. const n = parseFloat(Number(v).toFixed(2))
  420. this.price = isNaN(n) ? 0 : n
  421. }
  422. },
  423. immediate: true,
  424. },
  425. },
  426. onLoad(options) {
  427. if (options && options.customId) {
  428. const id = Number(options.customId)
  429. if (!isNaN(id) && id > 0) this.customId = id
  430. }
  431. if (options && options.customName) {
  432. this.customName = decodeURIComponent(String(options.customName))
  433. }
  434. this.applyDefaultShortcutCustomer()
  435. this.refreshCustomerBalance()
  436. },
  437. onShow() {
  438. this.applyPickCustomerFromStorage()
  439. this.applyDefaultShortcutCustomer()
  440. this.refreshCustomerBalance()
  441. },
  442. mounted() {
  443. this.loadCalcHistoryFromStorage()
  444. this.loadDiscountFromStorage()
  445. this.initMerchantInfo().catch(() => {})
  446. },
  447. methods: {
  448. ...mapActions(['initMerchantInfo']),
  449. init(){
  450. },
  451. pickCustomer() {
  452. this.tapVoice()
  453. this.$util.pageTo({url: '/admin/custom/selectCustom?style=6'})
  454. },
  455. applyPickCustomerFromStorage() {
  456. try {
  457. const raw = uni.getStorageSync(CALCULATOR_PICK_CUSTOMER_KEY)
  458. if (!raw) return
  459. const obj = typeof raw === 'string' ? JSON.parse(raw) : raw
  460. if (obj && obj.id != null) {
  461. this.customId = Number(obj.id) || 0
  462. this.customName = obj.name != null ? String(obj.name) : ''
  463. }
  464. uni.removeStorageSync(CALCULATOR_PICK_CUSTOMER_KEY)
  465. } catch (e) {}
  466. },
  467. /** 未选客且无路由参数带入时,默认工作台设置的快捷客户 */
  468. applyDefaultShortcutCustomer() {
  469. if (Number(this.customId) > 0) return
  470. const skid = this.shortcutCustomerId
  471. if (!skid || skid <= 0) return
  472. this.customId = skid
  473. this.customName = SHORTCUT_CUSTOM_DISPLAY_NAME
  474. },
  475. /** 对齐 affirm:拉取客户余额;余额大于应收且未手动选收款方式时再自动切换到余额收款 */
  476. refreshCustomerBalance() {
  477. const cid = Number(this.customId) || 0
  478. if (cid <= 0) {
  479. this.customInfo = { discount: 1, balance: 0 }
  480. return
  481. }
  482. getCustomInfo({ id: cid })
  483. .then((res) => {
  484. if (!res || res.code !== 1 || !res.data || !res.data.custom) return
  485. const prevHasPay = this.selHasPay
  486. this.customInfo = res.data.custom
  487. const bal = Number(this.customInfo.balance) || 0
  488. const due =
  489. this.keyboardTarget === 'calc'
  490. ? Number(this.stackDiscountedAmount)
  491. : Number(this.price)
  492. const amt = Number(due)
  493. if (
  494. prevHasPay !== 4 &&
  495. Number.isFinite(amt) &&
  496. amt > 0 &&
  497. bal > amt + 1e-6
  498. ) {
  499. this.selHasPay = 4
  500. this.cash = 0
  501. this.selPayWay = 0
  502. this.blurCashIfNoColumn()
  503. }
  504. this.$forceUpdate()
  505. })
  506. .catch(() => {})
  507. },
  508. loadCalcHistoryFromStorage() {
  509. try {
  510. const raw = uni.getStorageSync(CALC_HISTORY_STORAGE_KEY)
  511. if (raw === undefined || raw === null || raw === '') return
  512. const list = typeof raw === 'string' ? JSON.parse(raw) : raw
  513. if (!Array.isArray(list) || !list.length) return
  514. this.calcHistory = list.slice(0, this.maxHistory).map((row, i) => this.normalizeHistoryRow(row, i))
  515. } catch (e) {
  516. console.warn('[calculator] loadCalcHistoryFromStorage', e)
  517. }
  518. },
  519. normalizeHistoryRow(row, idx) {
  520. const r = row && typeof row === 'object' ? row : {}
  521. const id = r.id != null && String(r.id) !== '' ? String(r.id) : 'hist-' + Date.now() + '-' + idx
  522. return {
  523. id,
  524. tokens: Array.isArray(r.tokens) ? r.tokens : null,
  525. addends: Array.isArray(r.addends) ? r.addends : null,
  526. calcInput: r.calcInput != null ? String(r.calcInput) : '',
  527. total: r.total,
  528. timeLabel: r.timeLabel != null ? String(r.timeLabel) : '--:--',
  529. detailText: r.detailText != null ? String(r.detailText) : '',
  530. cashSnapshot: r.cashSnapshot,
  531. priceSnapshot: r.priceSnapshot,
  532. orderOnly: !!r.orderOnly,
  533. source: r.source === 'stash' ? 'stash' : 'submit',
  534. discountZhe:
  535. r.discountZhe != null && r.discountZhe !== '' && !isNaN(Number(r.discountZhe))
  536. ? parseFloat(Number(r.discountZhe).toFixed(2))
  537. : undefined,
  538. }
  539. },
  540. persistCalcHistoryToStorage() {
  541. try {
  542. uni.setStorageSync(CALC_HISTORY_STORAGE_KEY, JSON.stringify(this.calcHistory))
  543. } catch (e) {
  544. console.warn('[calculator] persistCalcHistoryToStorage', e)
  545. }
  546. },
  547. loadDiscountFromStorage() {
  548. try {
  549. const customRaw = uni.getStorageSync(DISCOUNT_CUSTOM_STORAGE_KEY)
  550. if (customRaw !== undefined && customRaw !== null && customRaw !== '') {
  551. const parsed = typeof customRaw === 'string' ? JSON.parse(customRaw) : customRaw
  552. if (Array.isArray(parsed)) {
  553. this.customDiscountZheList = parsed
  554. .map((x) => Number(x))
  555. .filter((n) => !isNaN(n) && n > 0 && n < 10 - 1e-6)
  556. .map((n) => parseFloat(n.toFixed(2)))
  557. }
  558. }
  559. const sel = uni.getStorageSync(DISCOUNT_SELECTED_STORAGE_KEY)
  560. if (sel !== undefined && sel !== null && sel !== '') {
  561. const z = Number(sel)
  562. if (!isNaN(z) && z > 0 && z <= 10) this.discountZhe = parseFloat(z.toFixed(2))
  563. }
  564. this.normalizeDiscountSelectionToCustomOrNone()
  565. } catch (e) {
  566. console.warn('[calculator] loadDiscountFromStorage', e)
  567. }
  568. },
  569. normalizeDiscountSelectionToCustomOrNone() {
  570. const z = Number(this.discountZhe)
  571. if (isNaN(z)) {
  572. this.discountZhe = 10
  573. this.persistDiscountSelected()
  574. return
  575. }
  576. if (z >= 10 - 1e-6) {
  577. this.discountZhe = 10
  578. return
  579. }
  580. const ok = this.customDiscountZheList.some((x) => Math.abs(Number(x) - z) < 1e-4)
  581. if (!ok) {
  582. this.discountZhe = 10
  583. this.persistDiscountSelected()
  584. }
  585. },
  586. persistDiscountSelected() {
  587. try {
  588. uni.setStorageSync(DISCOUNT_SELECTED_STORAGE_KEY, String(this.discountZhe))
  589. } catch (e) {
  590. console.warn('[calculator] persistDiscountSelected', e)
  591. }
  592. },
  593. persistCustomDiscountList() {
  594. try {
  595. uni.setStorageSync(DISCOUNT_CUSTOM_STORAGE_KEY, JSON.stringify(this.customDiscountZheList))
  596. } catch (e) {
  597. console.warn('[calculator] persistCustomDiscountList', e)
  598. }
  599. },
  600. resetActiveDiscountToNone() {
  601. this.discountZhe = 10
  602. this.persistDiscountSelected()
  603. },
  604. formatDiscountZheLabel(z) {
  605. const n = Number(z)
  606. if (isNaN(n) || n >= 10 - 1e-6) return ''
  607. return parseFloat(n.toFixed(2)) + '折'
  608. },
  609. formatDiscountRowLabel(z) {
  610. const n = Number(z)
  611. if (isNaN(n)) return '—'
  612. return parseFloat(n.toFixed(2)) + '折'
  613. },
  614. isZheActive(z) {
  615. const a = Number(this.discountZhe)
  616. const b = Number(z)
  617. if (isNaN(a) || isNaN(b)) return false
  618. return Math.abs(a - b) < 1e-4
  619. },
  620. openDiscountPopup() {
  621. this.tapVoice()
  622. this.$refs.discountPopup && this.$refs.discountPopup.open()
  623. },
  624. onDiscountPopupCloseTap() {
  625. this.tapVoice()
  626. this.closeDiscountPopup()
  627. },
  628. closeDiscountPopup() {
  629. this._discountPopupCloseByApi = true
  630. this.$refs.discountPopup && this.$refs.discountPopup.close()
  631. },
  632. onDiscountPopupChange(e) {
  633. if (!e || e.show !== false) return
  634. if (this._discountPopupCloseByApi) {
  635. this._discountPopupCloseByApi = false
  636. return
  637. }
  638. this.tapVoice()
  639. },
  640. onDiscountRowPickTap(e) {
  641. const ds = e.currentTarget.dataset || {}
  642. const z = Number(ds.zhe)
  643. if (isNaN(z)) return
  644. this.pickDiscountZhe(z)
  645. },
  646. onCustomDiscountDeleteTap(e) {
  647. const ds = e.currentTarget.dataset || {}
  648. const idx = Number(ds.cidx)
  649. if (isNaN(idx)) return
  650. this.removeCustomDiscountByIndex(idx)
  651. },
  652. pickDiscountZhe(z) {
  653. this.tapVoice()
  654. const n = Number(z)
  655. if (isNaN(n) || n <= 0 || n > 10) {
  656. this.$msg('折扣无效')
  657. return
  658. }
  659. if (n < 10 - 1e-6) {
  660. const ok = this.customDiscountZheList.some((x) => Math.abs(Number(x) - n) < 1e-4)
  661. if (!ok) {
  662. this.$msg('请先从列表选择或添加')
  663. return
  664. }
  665. }
  666. this.discountZhe = parseFloat(n.toFixed(2))
  667. this.persistDiscountSelected()
  668. this.closeDiscountPopup()
  669. },
  670. addCustomDiscountZhe() {
  671. this.tapVoice()
  672. const raw = String(this.customZheInput || '').trim()
  673. if (!raw) {
  674. this.$msg('请输入折扣')
  675. return
  676. }
  677. const n = parseFloat(raw)
  678. if (isNaN(n) || n <= 0 || n > 10) {
  679. this.$msg('请输入 0.1~10(如 8.8)')
  680. return
  681. }
  682. const rounded = parseFloat(n.toFixed(2))
  683. if (rounded >= 10 - 1e-6) {
  684. this.$msg('不打折请选「无折扣」')
  685. return
  686. }
  687. if (this.customDiscountZheList.some((x) => Math.abs(x - rounded) < 1e-4)) {
  688. this.$msg('已在列表中')
  689. return
  690. }
  691. this.customDiscountZheList = [rounded].concat(this.customDiscountZheList)
  692. this.persistCustomDiscountList()
  693. this.customZheInput = ''
  694. this.$msg('已添加')
  695. },
  696. removeCustomDiscountByIndex(cidx) {
  697. const idx = Number(cidx)
  698. if (isNaN(idx) || idx < 0 || idx >= this.customDiscountZheList.length) return
  699. this.tapVoice()
  700. const removed = this.customDiscountZheList[idx]
  701. this.customDiscountZheList = this.customDiscountZheList.filter((_, i) => i !== idx)
  702. this.persistCustomDiscountList()
  703. if (this.isZheActive(removed)) {
  704. this.discountZhe = 10
  705. this.persistDiscountSelected()
  706. }
  707. },
  708. tapVoice() {
  709. this.$util.hitRemind()
  710. },
  711. buildEvalState() {
  712. const nums = []
  713. const ops = []
  714. for (let i = 0; i < this.tokens.length; i++) {
  715. const t = this.tokens[i]
  716. if (t.type === 'num') {
  717. const v = Number(t.s)
  718. if (!isNaN(v)) nums.push(v)
  719. } else {
  720. ops.push(t.o)
  721. }
  722. }
  723. const hasTrailingOp = this.tokens.length > 0 && this.tokens[this.tokens.length - 1].type === 'op'
  724. const ci = this.calcInput
  725. const hasPartial =
  726. ci &&
  727. !this.$util.isEmpty(ci) &&
  728. ci !== '.' &&
  729. !isNaN(parseFloat(ci))
  730. let evalNums = nums.slice()
  731. let evalOps = ops.slice()
  732. if (hasPartial) {
  733. const c = parseFloat(ci)
  734. if (!isNaN(c) && c > 0) evalNums.push(parseFloat(c.toFixed(2)))
  735. } else if (hasTrailingOp && evalOps.length > 0) {
  736. evalOps = evalOps.slice(0, -1)
  737. }
  738. while (evalOps.length > 0 && evalNums.length <= evalOps.length) {
  739. evalOps.pop()
  740. }
  741. return { nums: evalNums, ops: evalOps }
  742. },
  743. opToInternal(o) {
  744. if (o === '×') return '*'
  745. if (o === '÷') return '/'
  746. if (o === '−') return '-'
  747. return '+'
  748. },
  749. evalExpr(nums, ops) {
  750. if (!nums.length) return 0
  751. const nArr = nums.map((x) => Number(x))
  752. const oArr = ops.map((o) => this.opToInternal(o))
  753. while (oArr.length > nArr.length - 1) oArr.pop()
  754. if (nArr.length === 1) return parseFloat(nArr[0].toFixed(2))
  755. if (oArr.length !== nArr.length - 1) return nArr[0] || 0
  756. let i = 0
  757. while (i < oArr.length) {
  758. if (oArr[i] === '*' || oArr[i] === '/') {
  759. const a = nArr[i]
  760. const b = nArr[i + 1]
  761. if (oArr[i] === '/' && b === 0) return NaN
  762. const r = oArr[i] === '*' ? a * b : a / b
  763. nArr.splice(i, 2, r)
  764. oArr.splice(i, 1)
  765. } else {
  766. i++
  767. }
  768. }
  769. let s = nArr[0]
  770. for (let k = 0; k < oArr.length; k++) {
  771. const b = nArr[k + 1]
  772. if (oArr[k] === '+') s += b
  773. else s -= b
  774. }
  775. return parseFloat(s.toFixed(2))
  776. },
  777. cloneTokens(arr) {
  778. return arr.map((t) => (t.type === 'num' ? { type: 'num', s: t.s } : { type: 'op', o: t.o }))
  779. },
  780. getExprDisplayString(includePartial) {
  781. let s = ''
  782. this.tokens.forEach((t) => {
  783. s += t.type === 'num' ? t.s : t.o
  784. })
  785. if (includePartial && !this.$util.isEmpty(this.calcInput)) {
  786. s += this.calcInput
  787. }
  788. return s
  789. },
  790. legacyAddendsToTokens(addends) {
  791. const tokens = []
  792. if (!addends || !addends.length) return tokens
  793. addends.forEach((raw, i) => {
  794. const v = Number(raw)
  795. if (i === 0) {
  796. tokens.push({ type: 'num', s: String(Math.abs(v)) })
  797. } else {
  798. tokens.push({ type: 'op', o: v >= 0 ? '+' : '−' })
  799. tokens.push({ type: 'num', s: String(Math.abs(v)) })
  800. }
  801. })
  802. return tokens
  803. },
  804. pressCalcOp(displayOp) {
  805. if (!this.ensureCalcModeForOps()) return
  806. if (!this.$util.isEmpty(this.calcInput) && this.calcInput !== '.') {
  807. const n = Number(this.calcInput)
  808. if (isNaN(n) || n <= 0) {
  809. this.$msg('请输入有效金额')
  810. return
  811. }
  812. const fs = parseFloat(n.toFixed(2))
  813. this.tokens.push({ type: 'num', s: String(fs) })
  814. this.calcInput = ''
  815. }
  816. const last = this.tokens.length > 0 ? this.tokens[this.tokens.length - 1] : null
  817. if (last && last.type === 'op') {
  818. last.o = displayOp
  819. return
  820. }
  821. if (last && last.type === 'num') {
  822. this.tokens.push({ type: 'op', o: displayOp })
  823. return
  824. }
  825. this.$msg('请先输入数字')
  826. },
  827. ensureCalcModeForOps() {
  828. if (this.keyboardTarget !== 'calc') {
  829. this.$msg('请先点击上方计算器区域')
  830. return false
  831. }
  832. return true
  833. },
  834. /** 金额展示:最多两位小数,不保留小数末尾多余的 0 */
  835. formatMoney(n) {
  836. const x = Number(n)
  837. if (isNaN(x)) return '0'
  838. return parseFloat(x.toFixed(2)).toString()
  839. },
  840. formatChangeAmount(n) {
  841. const x = Number(n)
  842. if (isNaN(x)) return '0'
  843. const s = (Math.round(x * 100) / 100).toFixed(2)
  844. return parseFloat(s).toString()
  845. },
  846. focusCalc() {
  847. this.tapVoice()
  848. this.keyboardTarget = 'calc'
  849. this.checkType = 3
  850. },
  851. checkCurrent(n) {
  852. this.tapVoice()
  853. this.checkType = n
  854. this.keyboardTarget = n === 1 ? 'order' : 'cash'
  855. },
  856. onHasPayChipTap(e) {
  857. const ds = e.currentTarget.dataset || {}
  858. const val = ds.hpid !== undefined ? Number(ds.hpid) : NaN
  859. if (isNaN(val)) return
  860. this.applySelHasPay(val)
  861. },
  862. onPayWayChipTap(e) {
  863. const ds = e.currentTarget.dataset || {}
  864. const val = ds.pwid !== undefined ? Number(ds.pwid) : NaN
  865. if (isNaN(val)) return
  866. this.applySelPayWay(val)
  867. },
  868. applySelHasPay(val) {
  869. this.tapVoice()
  870. this.selHasPay = val
  871. this.cash = 0
  872. if (Number(val) !== 1) this.selPayWay = 0
  873. this.blurCashIfNoColumn()
  874. },
  875. applySelPayWay(val) {
  876. this.tapVoice()
  877. this.selPayWay = val
  878. if (Number(val) !== 4) {
  879. this.cash = 0
  880. } else {
  881. this.checkCurrent(2)
  882. }
  883. this.blurCashIfNoColumn()
  884. },
  885. blurCashIfNoColumn() {
  886. if (this.keyboardTarget === 'cash' && !this.showCashPayCols) this.focusCalc()
  887. },
  888. setCashShortPick(v) {
  889. this.tapVoice()
  890. this.cashShortPick = Number(v) === 1 ? 1 : 0
  891. },
  892. closeCashShortPopupByCancel() {
  893. this.tapVoice()
  894. this._cashShortPopupCloseByApi = true
  895. this.$refs.cashShortPopup && this.$refs.cashShortPopup.close()
  896. },
  897. onCashShortPopupChange(e) {
  898. if (!e || e.show !== false) return
  899. if (this._cashShortPopupCloseByApi) {
  900. this._cashShortPopupCloseByApi = false
  901. return
  902. }
  903. this.tapVoice()
  904. },
  905. confirmCashShortWay() {
  906. this.tapVoice()
  907. const way = Number(this.cashShortPick) === 1 ? 1 : 0
  908. this.applySelPayWay(way)
  909. this._cashShortPopupCloseByApi = true
  910. this.$refs.cashShortPopup && this.$refs.cashShortPopup.close()
  911. this.$nextTick(() => {
  912. this._submitCashierPayCore()
  913. })
  914. },
  915. openCalcHistory() {
  916. this.tapVoice()
  917. this.$refs.calcHistoryPopup && this.$refs.calcHistoryPopup.open()
  918. },
  919. onHistoryPopupCloseTap() {
  920. this.tapVoice()
  921. this.closeCalcHistory()
  922. },
  923. closeCalcHistory() {
  924. this._historyPopupCloseByApi = true
  925. this.$refs.calcHistoryPopup && this.$refs.calcHistoryPopup.close()
  926. },
  927. onCalcHistoryPopupChange(e) {
  928. if (!e || e.show !== false) return
  929. if (this._historyPopupCloseByApi) {
  930. this._historyPopupCloseByApi = false
  931. return
  932. }
  933. this.tapVoice()
  934. },
  935. onHistoryRowTap(e) {
  936. this.tapVoice()
  937. const idx = Number(e.currentTarget.dataset.idx)
  938. if (isNaN(idx) || idx < 0) return
  939. const row = this.calcHistory[idx]
  940. this.applyHistoryRow(row)
  941. this.closeCalcHistory()
  942. },
  943. onHistoryDeleteTap(e) {
  944. this.tapVoice()
  945. const idx = Number(e.currentTarget.dataset.idx)
  946. if (isNaN(idx) || idx < 0 || idx >= this.calcHistory.length) return
  947. this.calcHistory.splice(idx, 1)
  948. this.persistCalcHistoryToStorage()
  949. },
  950. pushHistorySnapshot(total, opts) {
  951. opts = opts || {}
  952. const now = new Date()
  953. const hh = String(now.getHours())
  954. const m = now.getMinutes() < 10 ? '0' + now.getMinutes() : String(now.getMinutes())
  955. const timeLabel = hh + ':' + m
  956. const hasCalc =
  957. this.tokens.length > 0 ||
  958. (this.calcInput != null && !this.$util.isEmpty(this.calcInput))
  959. const orderOnly =
  960. opts.orderOnly !== undefined ? !!opts.orderOnly : !hasCalc
  961. const expr = this.getExprDisplayString(true)
  962. let detailText = orderOnly
  963. ? '订单 ' + this.formatMoney(total)
  964. : expr || '订单 ' + this.formatMoney(total)
  965. if (!orderOnly && hasCalc && this.isDiscountActive && expr) {
  966. detailText =
  967. expr +
  968. '(原价' +
  969. this.formatMoney(this.stackTotal) +
  970. ' ' +
  971. this.formatDiscountZheLabel(this.discountZhe) +
  972. '→' +
  973. this.formatMoney(total) +
  974. ')'
  975. }
  976. const row = this.normalizeHistoryRow(
  977. {
  978. id: Date.now() + '-' + Math.random().toString(16).slice(2, 10),
  979. tokens: this.cloneTokens(this.tokens),
  980. calcInput: this.calcInput != null ? String(this.calcInput) : '',
  981. total,
  982. timeLabel,
  983. detailText,
  984. cashSnapshot: Number(this.cash) || 0,
  985. priceSnapshot: Number(this.price) || 0,
  986. orderOnly,
  987. source: opts.source === 'stash' ? 'stash' : 'submit',
  988. discountZhe: parseFloat(Number(this.discountZhe).toFixed(2)),
  989. },
  990. 0
  991. )
  992. this.calcHistory.unshift(row)
  993. if (this.calcHistory.length > this.maxHistory) this.calcHistory.pop()
  994. this.persistCalcHistoryToStorage()
  995. },
  996. stashCurrent() {
  997. this.tapVoice()
  998. const hasCalc =
  999. this.tokens.length > 0 ||
  1000. (this.calcInput != null && !this.$util.isEmpty(this.calcInput))
  1001. const st = this.stackTotal
  1002. const orderP = Number(this.price)
  1003. let total = null
  1004. let orderOnly = false
  1005. if (hasCalc) {
  1006. if (!Number.isFinite(st) || isNaN(st) || st <= 0) {
  1007. this.$msg('请先完成有效算式')
  1008. return
  1009. }
  1010. const payable = this.stackDiscountedAmount
  1011. if (!Number.isFinite(payable) || isNaN(payable) || payable <= 0) {
  1012. this.$msg('请先完成有效算式')
  1013. return
  1014. }
  1015. total = payable
  1016. orderOnly = false
  1017. } else if (!isNaN(orderP) && orderP > 0) {
  1018. total = orderP
  1019. orderOnly = true
  1020. } else {
  1021. this.$msg('没有可暂存的内容')
  1022. return
  1023. }
  1024. this.pushHistorySnapshot(total, { source: 'stash', orderOnly })
  1025. this.$msg('已暂存')
  1026. this.clearStack()
  1027. this.keyboardTarget = 'calc'
  1028. this.checkType = 3
  1029. },
  1030. clearStack() {
  1031. this.tokens = []
  1032. this.calcInput = ''
  1033. this.resetActiveDiscountToNone()
  1034. },
  1035. tapClearCalculator() {
  1036. this.tapVoice()
  1037. this.clearStack()
  1038. this.keyboardTarget = 'calc'
  1039. this.checkType = 3
  1040. this.price = 0
  1041. },
  1042. restoreHistoryDiscountFromRow(row) {
  1043. let z = 10
  1044. const raw = row && row.discountZhe
  1045. if (raw != null && raw !== '' && !isNaN(Number(raw))) {
  1046. const n = Number(raw)
  1047. if (n > 0 && n <= 10) z = parseFloat(n.toFixed(2))
  1048. }
  1049. if (z >= 10 - 1e-6) {
  1050. this.discountZhe = 10
  1051. return
  1052. }
  1053. const ok = this.customDiscountZheList.some((x) => Math.abs(Number(x) - z) < 1e-4)
  1054. this.discountZhe = ok ? z : 10
  1055. },
  1056. applyHistoryRow(row) {
  1057. if (!row) return
  1058. this.restoreHistoryDiscountFromRow(row)
  1059. const ci = row.calcInput != null ? String(row.calcInput) : ''
  1060. const hasTok = row.tokens && row.tokens.length > 0
  1061. const hasLegacy = row.addends && row.addends.length
  1062. const restoreCash = () => {
  1063. this.$nextTick(() => {
  1064. if (row.cashSnapshot != null && !isNaN(Number(row.cashSnapshot))) {
  1065. this.cash = Number(row.cashSnapshot)
  1066. }
  1067. })
  1068. }
  1069. if (hasLegacy) {
  1070. this.tokens = this.legacyAddendsToTokens(row.addends)
  1071. this.calcInput = ci
  1072. this.keyboardTarget = 'calc'
  1073. this.checkType = 3
  1074. restoreCash()
  1075. return
  1076. }
  1077. if (hasTok) {
  1078. this.tokens = this.cloneTokens(row.tokens)
  1079. this.calcInput = ci
  1080. this.keyboardTarget = 'calc'
  1081. this.checkType = 3
  1082. restoreCash()
  1083. return
  1084. }
  1085. if (!this.$util.isEmpty(ci)) {
  1086. this.tokens = []
  1087. this.calcInput = ci
  1088. this.keyboardTarget = 'calc'
  1089. this.checkType = 3
  1090. restoreCash()
  1091. return
  1092. }
  1093. const orderAmt =
  1094. row.priceSnapshot != null &&
  1095. !isNaN(Number(row.priceSnapshot)) &&
  1096. Number(row.priceSnapshot) > 0
  1097. ? Number(row.priceSnapshot)
  1098. : Number(row.total)
  1099. if (!isNaN(orderAmt) && orderAmt > 0) {
  1100. this.tokens = []
  1101. this.calcInput = ''
  1102. this.price = orderAmt
  1103. this.cash =
  1104. row.cashSnapshot != null && !isNaN(Number(row.cashSnapshot))
  1105. ? Number(row.cashSnapshot)
  1106. : 0
  1107. this.keyboardTarget = 'order'
  1108. this.checkType = 1
  1109. return
  1110. }
  1111. },
  1112. onNumpadTap(e) {
  1113. this.tapVoice()
  1114. const ds = e.currentTarget.dataset || {}
  1115. const action = ds.action
  1116. const char = ds.char
  1117. if (action === 'calc-add') {
  1118. this.pressCalcOp('+')
  1119. return
  1120. }
  1121. if (action === 'calc-sub') {
  1122. this.pressCalcOp('−')
  1123. return
  1124. }
  1125. if (action === 'calc-mul') {
  1126. this.pressCalcOp('×')
  1127. return
  1128. }
  1129. if (action === 'calc-div') {
  1130. this.pressCalcOp('÷')
  1131. return
  1132. }
  1133. if (action === 'backspace') {
  1134. this.typing({ backspace: true })
  1135. } else if (char !== undefined && char !== null && char !== '') {
  1136. this.typing({ backspace: false, char: String(char) })
  1137. }
  1138. },
  1139. typing(e) {
  1140. const field = this.keyboardTarget
  1141. if (e.backspace) {
  1142. if (field === 'calc') {
  1143. if (this.calcInput && String(this.calcInput).length > 0) {
  1144. this.calcInput = String(this.calcInput).substring(0, String(this.calcInput).length - 1)
  1145. } else if (this.tokens.length > 0) {
  1146. const last = this.tokens[this.tokens.length - 1]
  1147. if (last.type === 'op') this.tokens.pop()
  1148. else if (last.s.length > 1)
  1149. last.s = String(last.s).substring(0, String(last.s).length - 1)
  1150. else this.tokens.pop()
  1151. }
  1152. } else if (field === 'order') {
  1153. if (this.checkType === 1) this.price = ''
  1154. else if (String(this.price).length > 0)
  1155. this.price = String(this.price).substring(0, String(this.price).length - 1)
  1156. } else if (field === 'cash') {
  1157. if (!this.showCashPayCols) return
  1158. if (this.checkType === 2) this.cash = ''
  1159. else if (String(this.cash).length > 0)
  1160. this.cash = String(this.cash).substring(0, String(this.cash).length - 1)
  1161. }
  1162. } else {
  1163. const ch = e.char
  1164. if (field === 'calc') {
  1165. if (this.$util.isEmpty(this.calcInput) || this.checkType === 3) this.calcInput = ch
  1166. else {
  1167. if (ch === '.' && String(this.calcInput).indexOf('.') >= 0) return
  1168. this.calcInput += ch
  1169. }
  1170. } else if (field === 'order') {
  1171. if (this.$util.isEmpty(this.price) || this.checkType === 1) this.price = ch
  1172. else {
  1173. if (ch === '.' && String(this.price).indexOf('.') >= 0) return
  1174. this.price += ch
  1175. }
  1176. } else if (field === 'cash') {
  1177. if (!this.showCashPayCols) return
  1178. if (this.$util.isEmpty(this.cash) || this.checkType === 2) this.cash = ch
  1179. else {
  1180. if (ch === '.' && String(this.cash).indexOf('.') >= 0) return
  1181. this.cash += ch
  1182. }
  1183. }
  1184. }
  1185. this.checkType = 0
  1186. },
  1187. submitCashierPay() {
  1188. this._submitCashierPayCore()
  1189. },
  1190. _resolveXjPayload() {
  1191. try {
  1192. if (Number(this.customId) > 0) {
  1193. return uni.getStorageSync('xj' + this.customId)
  1194. }
  1195. } catch (e) {}
  1196. try {
  1197. return uni.getStorageSync('xj')
  1198. } catch (e2) {}
  1199. return null
  1200. },
  1201. _submitCashierPayCore() {
  1202. this.tapVoice()
  1203. if (this.keyboardTarget === 'calc') {
  1204. const st = this.stackTotal
  1205. if (!Number.isFinite(st) || isNaN(st)) {
  1206. this.$msg('算式无效')
  1207. return
  1208. }
  1209. this.price = this.stackDiscountedAmount
  1210. }
  1211. const p = Number(this.price)
  1212. if (isNaN(p) || p <= 0) {
  1213. this.$msg('金额须大于 0')
  1214. return
  1215. }
  1216. if (this.selHasPay === 2 && (!this.customId || Number(this.customId) <= 0)) {
  1217. this.$msg('请先选择客户')
  1218. return
  1219. }
  1220. if (this.selHasPay === 4) {
  1221. if (!this.customId || Number(this.customId) <= 0) {
  1222. this.$msg('请先选择客户')
  1223. return
  1224. }
  1225. const bal = Number(this.customInfo.balance) || 0
  1226. if (bal + 1e-6 < p) {
  1227. this.$msg('客户余额不足')
  1228. return
  1229. }
  1230. }
  1231. if (this.showCashPayCols) {
  1232. const cx = Number(this.cash) || 0
  1233. if (cx <= 0) {
  1234. this.$msg('请输入收到的现金')
  1235. return
  1236. }
  1237. if (Number(this.zl) < 0) {
  1238. this.cashShortPick = 0
  1239. this.$refs.cashShortPopup && this.$refs.cashShortPopup.open()
  1240. return
  1241. }
  1242. }
  1243. const hasCalc =
  1244. this.tokens.length > 0 ||
  1245. (this.calcInput != null && !this.$util.isEmpty(this.calcInput))
  1246. const cashSubmit = this.showCashPayCols ? (Number(this.cash) || 0) : 0
  1247. const emitHasPay = this.selHasPay
  1248. const emitPayWay = this.selHasPay === 1 ? this.selPayWay : 0
  1249. this.pushHistorySnapshot(p, {
  1250. source: 'submit',
  1251. orderOnly: !hasCalc,
  1252. })
  1253. const orderName = (this.name != null ? String(this.name) : '').trim()
  1254. const formPayload = {
  1255. ...SETTLE_FORM_DEFAULTS,
  1256. hasPay: emitHasPay,
  1257. payWay: emitPayWay,
  1258. modifyPrice: p,
  1259. cash: cashSubmit,
  1260. orderName,
  1261. gatheringPrice: p,
  1262. }
  1263. const xjRaw = this._resolveXjPayload()
  1264. const payload = {
  1265. ...formPayload,
  1266. isCashier: 1,
  1267. customId: Number(this.customId) || 0,
  1268. xj: JSON.stringify(xjRaw),
  1269. version: 3,
  1270. zjGathering: 1,
  1271. dealPrice: 1,
  1272. getGoods: 1,
  1273. product: '',
  1274. orderType: 2,
  1275. payWay: Number(formPayload.hasPay) === 1 ? (formPayload.payWay != null ? formPayload.payWay : 0) : 0,
  1276. }
  1277. const sendCreate = () => {
  1278. if (!this.getMerchantInfo || !this.getMerchantInfo.id) {
  1279. this.$msg('未获取到店铺信息')
  1280. return
  1281. }
  1282. const shopPayload = {
  1283. ...payload,
  1284. shopId: this.getMerchantInfo.id,
  1285. }
  1286. uni.showLoading({ mask: true })
  1287. createOrder(shopPayload)
  1288. .then((res) => {
  1289. uni.hideLoading()
  1290. if (res.code != 1) {
  1291. return
  1292. }
  1293. if (res.data && res.data.diff && !this.$util.isEmpty(res.data.diff)) {
  1294. this.$msg('存在价差条目,请到开单页处理')
  1295. return
  1296. }
  1297. let navigatedPay = false
  1298. if (res.data && res.data.status == 1) {
  1299. const id = res.data.id
  1300. const orderSn = res.data.orderSn
  1301. const actPrice = res.data.actPrice != null ? res.data.actPrice : p
  1302. if (formPayload.hasPay == 0) {
  1303. navigatedPay = true
  1304. this.$util.pageTo({
  1305. url: '/admin/billing/toPay',
  1306. type: 2,
  1307. query: { orderId: id, orderSn: orderSn, actPrice: actPrice },
  1308. })
  1309. } else {
  1310. navigatedPay = true
  1311. this.$util.pageTo({
  1312. url: '/admin/billing/result',
  1313. type: 2,
  1314. query: { orderId: id, orderSn: orderSn, title: '收款成功' },
  1315. })
  1316. }
  1317. } else if (!navigatedPay) {
  1318. uni.showToast({ title: '操作成功', icon: 'success' })
  1319. }
  1320. this.price = 0
  1321. this.checkType = 3
  1322. this.keyboardTarget = 'calc'
  1323. this.cash = 0
  1324. this.selHasPay = 0
  1325. this.selPayWay = 0
  1326. this.tokens = []
  1327. this.calcInput = ''
  1328. this.resetActiveDiscountToNone()
  1329. this.refreshCustomerBalance()
  1330. })
  1331. .catch(() => {
  1332. uni.hideLoading()
  1333. })
  1334. }
  1335. if (!this.getMerchantInfo || !this.getMerchantInfo.id) {
  1336. this.initMerchantInfo()
  1337. .then(() => {
  1338. sendCreate()
  1339. })
  1340. .catch(() => {
  1341. this.$msg('店铺信息加载失败')
  1342. })
  1343. return
  1344. }
  1345. sendCreate()
  1346. },
  1347. },
  1348. }
  1349. </script>
  1350. <style lang="scss" scoped>
  1351. .calc-page {
  1352. height: 100%;
  1353. background: #f4f6f8;
  1354. box-sizing: border-box;
  1355. display: flex;
  1356. flex-direction: column;
  1357. overflow: hidden;
  1358. }
  1359. /* 上 4/7 内容区,下 3/7 数字键区(随屏高同比伸缩) */
  1360. .calc-scroll {
  1361. flex: 4;
  1362. flex-basis: 0;
  1363. min-height: 0;
  1364. width: 100%;
  1365. }
  1366. .calc-sheet {
  1367. padding: 20upx 24upx 0;
  1368. box-sizing: border-box;
  1369. }
  1370. .calc-card-wrap {
  1371. background: transparent;
  1372. }
  1373. .calc-section {
  1374. position: relative;
  1375. border: 2upx solid #e5e9ef;
  1376. border-radius: 16upx;
  1377. padding: 20upx 20upx 24upx;
  1378. background: #fff;
  1379. box-shadow: 0 4upx 20upx rgba(0, 0, 0, 0.04);
  1380. }
  1381. .calc-section-active {
  1382. border-color: #09c567;
  1383. background: linear-gradient(180deg, #f6fff9 0%, #fff 52%);
  1384. }
  1385. .calc-actions-top {
  1386. display: flex;
  1387. flex-direction: row;
  1388. align-items: center;
  1389. justify-content: space-between;
  1390. margin-bottom: 16upx;
  1391. }
  1392. .calc-section-title {
  1393. font-size: 28upx;
  1394. font-weight: 600;
  1395. color: #1a1a1a;
  1396. }
  1397. .discount-entry {
  1398. width: 64upx;
  1399. height: 64upx;
  1400. border-radius: 12upx;
  1401. background: rgba(255, 251, 245, 0.98);
  1402. border: 2upx solid #f0dcc8;
  1403. display: flex;
  1404. align-items: center;
  1405. justify-content: center;
  1406. }
  1407. .discount-entry-hover {
  1408. opacity: 0.82;
  1409. }
  1410. .discount-entry-glyph {
  1411. font-size: 26upx;
  1412. font-weight: 700;
  1413. color: #d97706;
  1414. }
  1415. .history-entry {
  1416. width: 64upx;
  1417. height: 64upx;
  1418. border-radius: 12upx;
  1419. background: rgba(248, 255, 248, 0.95);
  1420. border: 2upx solid #c8ecd8;
  1421. display: flex;
  1422. align-items: center;
  1423. justify-content: center;
  1424. }
  1425. .history-entry-hover {
  1426. opacity: 0.82;
  1427. }
  1428. .history-entry-icon {
  1429. font-size: 34upx;
  1430. color: #09c567;
  1431. }
  1432. .calc-formula {
  1433. min-height: 88upx;
  1434. font-size: 38upx;
  1435. color: #333;
  1436. text-align: center;
  1437. line-height: 1.45;
  1438. word-break: break-all;
  1439. padding: 0 8upx;
  1440. }
  1441. .calc-formula-inner {
  1442. display: flex;
  1443. flex-direction: row;
  1444. flex-wrap: wrap;
  1445. align-items: center;
  1446. justify-content: center;
  1447. }
  1448. .calc-placeholder {
  1449. font-size: 32upx;
  1450. color: #9aa4b2;
  1451. }
  1452. .calc-num {
  1453. font-size: 42upx;
  1454. font-weight: 600;
  1455. color: #1a1a1a;
  1456. }
  1457. .calc-op {
  1458. font-size: 42upx;
  1459. font-weight: 700;
  1460. color: #09c567;
  1461. }
  1462. .calc-total-row {
  1463. display: flex;
  1464. flex-direction: row;
  1465. align-items: baseline;
  1466. justify-content: center;
  1467. margin-top: 20upx;
  1468. }
  1469. .calc-total-label {
  1470. font-size: 26upx;
  1471. color: #9aa4b2;
  1472. margin-right: 12upx;
  1473. }
  1474. .calc-total-val {
  1475. font-size: 44upx;
  1476. font-weight: 700;
  1477. color: #09c567;
  1478. line-height: 1.2;
  1479. }
  1480. .calc-discount-row {
  1481. display: flex;
  1482. flex-direction: row;
  1483. align-items: center;
  1484. justify-content: center;
  1485. margin-top: 12upx;
  1486. }
  1487. .calc-discount-label {
  1488. font-size: 24upx;
  1489. color: #d97706;
  1490. margin-right: 10upx;
  1491. }
  1492. .calc-discount-val {
  1493. font-size: 34upx;
  1494. font-weight: 700;
  1495. color: #d97706;
  1496. }
  1497. .customer-strip {
  1498. display: flex;
  1499. flex-direction: row;
  1500. align-items: center;
  1501. background: #fff;
  1502. border-radius: 14upx;
  1503. padding: 32upx 28upx;
  1504. min-height: 94upx;
  1505. box-sizing: border-box;
  1506. margin-top: 12upx;
  1507. border: 2upx solid #e5e9ef;
  1508. }
  1509. .customer-strip-label {
  1510. font-size: 34upx;
  1511. color: #9aa4b2;
  1512. flex-shrink: 0;
  1513. }
  1514. .customer-strip-name {
  1515. flex: 1;
  1516. min-width: 0;
  1517. font-size: 34upx;
  1518. font-weight: 600;
  1519. color: #1a1a1a;
  1520. margin-left: 16upx;
  1521. overflow: hidden;
  1522. text-overflow: ellipsis;
  1523. white-space: nowrap;
  1524. }
  1525. .customer-strip-action {
  1526. font-size: 32upx;
  1527. color: #09c567;
  1528. flex-shrink: 0;
  1529. margin-left: 12upx;
  1530. }
  1531. .balance-strip {
  1532. display: flex;
  1533. flex-direction: row;
  1534. align-items: center;
  1535. flex-wrap: wrap;
  1536. background: #fff;
  1537. border-radius: 14upx;
  1538. padding: 24upx 28upx;
  1539. margin-top: 12upx;
  1540. border: 2upx solid #e5e9ef;
  1541. box-sizing: border-box;
  1542. }
  1543. .balance-strip-label {
  1544. font-size: 30upx;
  1545. color: #9aa4b2;
  1546. flex-shrink: 0;
  1547. margin-right: 12upx;
  1548. }
  1549. .balance-strip-val {
  1550. font-size: 34upx;
  1551. font-weight: 700;
  1552. color: #3385ff;
  1553. }
  1554. .balance-strip-hint {
  1555. margin-left: 16upx;
  1556. font-size: 24upx;
  1557. line-height: 1.35;
  1558. flex: 1;
  1559. min-width: 200upx;
  1560. }
  1561. .balance-strip-hint-ok {
  1562. color: #09c567;
  1563. }
  1564. .balance-strip-hint-tip {
  1565. color: #876500;
  1566. }
  1567. .rcv-pay-block {
  1568. margin-top: 12upx;
  1569. padding: 22upx 20upx;
  1570. background: #fff;
  1571. border-radius: 14upx;
  1572. border: 2upx solid #e8edf3;
  1573. box-sizing: border-box;
  1574. }
  1575. .rcv-pay-title {
  1576. font-size: 30upx;
  1577. color: #5c6573;
  1578. text-align: left;
  1579. margin-bottom: 12upx;
  1580. font-weight: 500;
  1581. }
  1582. .rcv-pay-title-sub {
  1583. margin-top: 16upx;
  1584. }
  1585. .rcv-pay-hint {
  1586. margin-bottom: 4upx;
  1587. }
  1588. .rcv-pay-hint-text {
  1589. display: block;
  1590. font-size: 24upx;
  1591. color: #3385ff;
  1592. line-height: 1.35;
  1593. }
  1594. .rcv-sub-block {
  1595. margin-top: 4upx;
  1596. }
  1597. .rcv-item-row {
  1598. display: flex;
  1599. flex-direction: row;
  1600. flex-wrap: wrap;
  1601. align-items: center;
  1602. }
  1603. .rcv-item-chip {
  1604. min-width: 140upx;
  1605. padding: 0 20upx;
  1606. height: 68upx;
  1607. line-height: 68upx;
  1608. text-align: center;
  1609. font-size: 28upx;
  1610. border: 2upx solid #e8edf3;
  1611. color: #3d4654;
  1612. border-radius: 10upx;
  1613. background: #fafbfc;
  1614. box-sizing: border-box;
  1615. display: inline-flex;
  1616. align-items: center;
  1617. justify-content: center;
  1618. }
  1619. .rcv-item-chip {
  1620. margin-right: 18upx;
  1621. margin-bottom: 12upx;
  1622. }
  1623. .rcv-item-chip.active {
  1624. background: #09c567;
  1625. color: #fff;
  1626. border-color: #09c567;
  1627. }
  1628. .pay-cash-panel {
  1629. display: flex;
  1630. flex-direction: row;
  1631. align-items: stretch;
  1632. margin-top: 16upx;
  1633. }
  1634. .pay-cash-item {
  1635. flex: 1;
  1636. min-width: 0;
  1637. background: #fff;
  1638. border: 2upx solid #e8edf3;
  1639. border-radius: 14upx;
  1640. padding: 22upx 16upx;
  1641. box-sizing: border-box;
  1642. text-align: center;
  1643. }
  1644. .pay-cash-item.pay-cash-item-change {
  1645. border-style: dashed;
  1646. }
  1647. .pay-cash-item.pay-cash-item-change {
  1648. margin-left: 12upx;
  1649. }
  1650. .pay-cash-desc {
  1651. display: block;
  1652. font-size: 24upx;
  1653. color: #9aa4b2;
  1654. margin-bottom: 10upx;
  1655. }
  1656. .pay-cash-amt {
  1657. font-size: 32upx;
  1658. font-weight: 600;
  1659. color: #1a1a1a;
  1660. }
  1661. .pay-cash-amt-selected {
  1662. color: #fff;
  1663. background: #09c567;
  1664. padding: 8upx 16upx;
  1665. border-radius: 10upx;
  1666. display: inline-block;
  1667. }
  1668. .pay-change-line {
  1669. display: flex;
  1670. justify-content: center;
  1671. margin-bottom: 8upx;
  1672. }
  1673. .lbl-ok {
  1674. font-size: 24upx;
  1675. color: #09c567;
  1676. }
  1677. .lbl-bad {
  1678. font-size: 24upx;
  1679. color: #e54545;
  1680. }
  1681. .lbl-neu {
  1682. font-size: 24upx;
  1683. color: #c5ccd6;
  1684. }
  1685. .amt-ok {
  1686. font-size: 34upx;
  1687. font-weight: 700;
  1688. color: #09c567;
  1689. display: block;
  1690. }
  1691. .amt-bad {
  1692. font-size: 34upx;
  1693. font-weight: 700;
  1694. color: #e54545;
  1695. display: block;
  1696. }
  1697. .amt-neu {
  1698. font-size: 30upx;
  1699. color: #c5ccd6;
  1700. display: block;
  1701. }
  1702. .pay-submit-row {
  1703. display: flex;
  1704. flex-direction: row;
  1705. margin-top: 20upx;
  1706. margin-bottom: 8upx;
  1707. }
  1708. .pay-submit-btn {
  1709. flex: 1;
  1710. text-align: center;
  1711. font-size: 30upx;
  1712. padding: 30upx 22upx;
  1713. background: #09c567;
  1714. color: #fff;
  1715. border-radius: 12upx;
  1716. font-weight: 600;
  1717. box-sizing: border-box;
  1718. border: 2upx solid #09c567;
  1719. }
  1720. .pay-submit-btn-outline {
  1721. flex: 1;
  1722. background: #fff;
  1723. color: #09c567;
  1724. border: 2upx solid #09c567;
  1725. font-weight: 600;
  1726. border-radius: 12upx;
  1727. text-align: center;
  1728. font-size: 30upx;
  1729. padding: 30upx 22upx;
  1730. box-sizing: border-box;
  1731. margin-right: 12upx;
  1732. }
  1733. .safe-bottom-spacer {
  1734. height: 24upx;
  1735. }
  1736. .numpad-dock {
  1737. flex: 3;
  1738. flex-basis: 0;
  1739. min-height: 0;
  1740. width: 100%;
  1741. display: flex;
  1742. flex-direction: column;
  1743. box-sizing: border-box;
  1744. background: linear-gradient(180deg, transparent 0%, #eceef1 22%, #dcdfe4 100%);
  1745. padding: 12upx 16upx 10upx;
  1746. box-shadow: 0 -4upx 24upx rgba(0, 0, 0, 0.06);
  1747. }
  1748. .safe-area-padding {
  1749. padding-bottom: calc(10upx + constant(safe-area-inset-bottom));
  1750. padding-bottom: calc(10upx + env(safe-area-inset-bottom));
  1751. }
  1752. .numpad {
  1753. width: 100%;
  1754. flex: 1;
  1755. min-height: 0;
  1756. display: flex;
  1757. flex-direction: column;
  1758. background: #e2e5ea;
  1759. border-radius: 14upx;
  1760. padding: 10upx;
  1761. box-sizing: border-box;
  1762. }
  1763. .numpad-grid-wrap {
  1764. flex: 1;
  1765. min-width: 0;
  1766. min-height: 0;
  1767. display: grid;
  1768. grid-template-columns: 1fr 1fr 1fr 25%;
  1769. grid-template-rows: repeat(5, minmax(0, 1fr));
  1770. box-sizing: border-box;
  1771. align-items: stretch;
  1772. justify-items: stretch;
  1773. width: 100%;
  1774. }
  1775. /* 小程序端 grid 子项 margin 常与 100% 宽高组合失效 → 用 cell 的内边距留白,不配 gap,兼容微信与 App */
  1776. .numpad-cell {
  1777. box-sizing: border-box;
  1778. min-width: 0;
  1779. min-height: 0;
  1780. overflow: visible;
  1781. display: flex;
  1782. flex-direction: column;
  1783. align-items: stretch;
  1784. padding-right: 10upx;
  1785. padding-bottom: 8upx;
  1786. }
  1787. .numpad-cell-op {
  1788. padding-right: 0;
  1789. }
  1790. .numpad-cell-mul {
  1791. grid-column: 4;
  1792. grid-row: 1;
  1793. }
  1794. .numpad-cell-add {
  1795. grid-column: 4;
  1796. grid-row: 2 / span 2;
  1797. }
  1798. .numpad-cell-sub {
  1799. grid-column: 4;
  1800. grid-row: 4;
  1801. }
  1802. .numpad-cell-div {
  1803. grid-column: 4;
  1804. grid-row: 5;
  1805. }
  1806. .numpad-cell-actions-row {
  1807. grid-column: 1 / span 3;
  1808. grid-row: 5;
  1809. flex-direction: row;
  1810. align-items: stretch;
  1811. }
  1812. .numpad-grid-wrap .numpad-cell-actions-row > .numpad-key {
  1813. flex: 1;
  1814. width: auto;
  1815. min-width: 0;
  1816. min-height: 0;
  1817. align-self: stretch;
  1818. }
  1819. .numpad-grid-wrap .numpad-cell-actions-row > .numpad-key + .numpad-key {
  1820. margin-left: 10upx;
  1821. }
  1822. .numpad-key {
  1823. min-width: 0;
  1824. min-height: 0;
  1825. display: flex;
  1826. align-items: center;
  1827. justify-content: center;
  1828. text-align: center;
  1829. font-size: 46upx;
  1830. font-weight: 600;
  1831. margin-left: 0;
  1832. color: #1a2430;
  1833. background: linear-gradient(180deg, #fff 0%, #f5f7fa 100%);
  1834. border-radius: 12upx;
  1835. box-shadow: 0 3upx 0 #bdc3c9;
  1836. }
  1837. .numpad-grid-wrap .numpad-cell > .numpad-key {
  1838. flex: 1;
  1839. width: 100%;
  1840. min-width: 0;
  1841. min-height: 0;
  1842. align-self: stretch;
  1843. }
  1844. .numpad-key:active {
  1845. opacity: 0.88;
  1846. transform: translateY(1px);
  1847. box-shadow: 0 1upx 0 #a8afb8;
  1848. }
  1849. .numpad-grid-wrap .numpad-key.numpad-key-op:not(.numpad-key-op-add) {
  1850. font-size: 46upx;
  1851. font-weight: 600;
  1852. background: linear-gradient(180deg, #fff 0%, #f0f2f5 100%);
  1853. color: #1a2430;
  1854. box-shadow: 0 3upx 0 #bdc3c9;
  1855. }
  1856. .numpad-grid-wrap .numpad-key.numpad-key-op-add {
  1857. font-size: 48upx;
  1858. font-weight: 700;
  1859. background: #52b384;
  1860. color: #063d2b;
  1861. box-shadow: 0 4upx 0 #388f65;
  1862. }
  1863. .numpad-key-muted {
  1864. color: #4a5666;
  1865. font-size: 50upx;
  1866. }
  1867. .numpad-key-text {
  1868. font-size: 34upx;
  1869. font-weight: 600;
  1870. }
  1871. .numpad-key-action-muted {
  1872. font-size: 32upx !important;
  1873. color: #c0392b !important;
  1874. background: #eac997;
  1875. box-shadow: 0 3upx 0 #b9c2cf !important;
  1876. }
  1877. .numpad-key-danger {
  1878. background: #eac997;
  1879. color: black !important;
  1880. box-shadow: 0 3upx 0 #e0abab !important;
  1881. }
  1882. .mob-popup-wrap {
  1883. width: 86vw;
  1884. max-width: 640upx;
  1885. max-height: 70vh;
  1886. display: flex;
  1887. flex-direction: column;
  1888. border-radius: 16upx;
  1889. overflow: hidden;
  1890. background: #fff;
  1891. }
  1892. .mob-popup-hd {
  1893. display: flex;
  1894. flex-direction: row;
  1895. align-items: center;
  1896. justify-content: space-between;
  1897. padding: 24upx 28upx;
  1898. border-bottom: 2upx solid #eef1f6;
  1899. flex-shrink: 0;
  1900. }
  1901. .mob-popup-title {
  1902. font-size: 32upx;
  1903. font-weight: bold;
  1904. color: #1a1a1a;
  1905. }
  1906. .mob-popup-close {
  1907. font-size: 28upx;
  1908. color: #09c567;
  1909. padding: 8upx 16upx;
  1910. }
  1911. .mob-popup-body {
  1912. max-height: 46vh;
  1913. box-sizing: border-box;
  1914. padding: 0 12upx 12upx;
  1915. }
  1916. .mob-popup-cash-short {
  1917. max-height: none;
  1918. }
  1919. .cash-short-desc {
  1920. display: block;
  1921. font-size: 26upx;
  1922. color: #3d4654;
  1923. line-height: 1.45;
  1924. padding: 12upx 28upx 8upx;
  1925. box-sizing: border-box;
  1926. }
  1927. .cash-short-way-row {
  1928. display: flex;
  1929. flex-direction: row;
  1930. align-items: center;
  1931. padding: 12upx 28upx 8upx;
  1932. box-sizing: border-box;
  1933. }
  1934. .cash-short-way-chip {
  1935. flex: 1;
  1936. text-align: center;
  1937. font-size: 28upx;
  1938. padding: 20upx 12upx;
  1939. border-radius: 12upx;
  1940. border: 2upx solid #e8edf3;
  1941. background: #fafbfc;
  1942. color: #3d4654;
  1943. box-sizing: border-box;
  1944. margin-right: 16upx;
  1945. font-weight: 500;
  1946. }
  1947. .cash-short-way-chip:last-child {
  1948. margin-right: 0;
  1949. }
  1950. .cash-short-way-chip-on {
  1951. border-color: #09c567;
  1952. background: #effff4;
  1953. color: #09c567;
  1954. }
  1955. .cash-short-actions {
  1956. display: flex;
  1957. flex-direction: row;
  1958. align-items: center;
  1959. padding: 22upx 28upx 26upx;
  1960. border-top: 2upx solid #eef1f6;
  1961. box-sizing: border-box;
  1962. margin-top: 8upx;
  1963. }
  1964. .cash-short-btn {
  1965. flex: 1;
  1966. text-align: center;
  1967. font-size: 30upx;
  1968. padding: 22upx 12upx;
  1969. border-radius: 12upx;
  1970. box-sizing: border-box;
  1971. font-weight: 600;
  1972. }
  1973. .cash-short-btn-cancel {
  1974. margin-right: 16upx;
  1975. background: #f2f4f7;
  1976. color: #3d4654;
  1977. }
  1978. .cash-short-btn-ok {
  1979. background: #09c567;
  1980. color: #fff;
  1981. }
  1982. .discount-toolbar {
  1983. flex-shrink: 0;
  1984. padding: 20upx 24upx 22upx;
  1985. border-bottom: 2upx solid #f0f2f5;
  1986. box-sizing: border-box;
  1987. }
  1988. .discount-custom-row {
  1989. display: flex;
  1990. flex-direction: row;
  1991. align-items: center;
  1992. }
  1993. .discount-custom-input {
  1994. flex: 1;
  1995. min-width: 0;
  1996. height: 72upx;
  1997. line-height: 72upx;
  1998. padding: 0 20upx;
  1999. font-size: 28upx;
  2000. border: 2upx solid #e8edf3;
  2001. border-radius: 10upx;
  2002. background: #fff;
  2003. box-sizing: border-box;
  2004. }
  2005. .discount-custom-add-btn {
  2006. flex-shrink: 0;
  2007. margin-left: 14upx;
  2008. padding: 0 28upx;
  2009. height: 72upx;
  2010. line-height: 72upx;
  2011. font-size: 28upx;
  2012. color: #fff;
  2013. background: #09c567;
  2014. border-radius: 10upx;
  2015. text-align: center;
  2016. box-sizing: border-box;
  2017. font-weight: 500;
  2018. }
  2019. .discount-toolbar-hint {
  2020. display: block;
  2021. font-size: 24upx;
  2022. color: #09c567;
  2023. line-height: 1.45;
  2024. padding: 14upx 6upx 0;
  2025. }
  2026. .discount-toolbar-hint-muted {
  2027. color: #9aa4b2;
  2028. }
  2029. .discount-options-scroll {
  2030. padding: 20upx 20upx 28upx;
  2031. box-sizing: border-box;
  2032. max-height: 44vh;
  2033. }
  2034. .discount-option {
  2035. display: flex;
  2036. flex-direction: row;
  2037. align-items: center;
  2038. justify-content: space-between;
  2039. padding: 24upx 20upx;
  2040. border: 2upx solid #e8edf3;
  2041. border-radius: 12upx;
  2042. margin-bottom: 12upx;
  2043. background: #fafbfc;
  2044. box-sizing: border-box;
  2045. }
  2046. .discount-option:last-child {
  2047. margin-bottom: 0;
  2048. }
  2049. .discount-option-active {
  2050. border-color: #09c567;
  2051. background: #f0fff5;
  2052. }
  2053. .discount-option-text {
  2054. font-size: 30upx;
  2055. color: #1a2430;
  2056. }
  2057. .discount-option-check {
  2058. font-size: 30upx;
  2059. color: #09c567;
  2060. font-weight: bold;
  2061. }
  2062. .discount-option-with-del {
  2063. padding-right: 12upx;
  2064. }
  2065. .discount-option-main {
  2066. flex: 1;
  2067. min-width: 0;
  2068. display: flex;
  2069. flex-direction: row;
  2070. align-items: center;
  2071. justify-content: space-between;
  2072. padding-right: 12upx;
  2073. box-sizing: border-box;
  2074. }
  2075. .discount-option-del {
  2076. flex-shrink: 0;
  2077. font-size: 26upx;
  2078. color: #e54545;
  2079. padding: 8upx 12upx;
  2080. }
  2081. .history-item {
  2082. display: flex;
  2083. flex-direction: row;
  2084. align-items: center;
  2085. padding: 18upx 12upx;
  2086. border-bottom: 2upx solid #f0f3f8;
  2087. }
  2088. .history-item-body {
  2089. flex: 1;
  2090. min-width: 0;
  2091. }
  2092. .history-del {
  2093. flex-shrink: 0;
  2094. font-size: 26upx;
  2095. color: #e54545;
  2096. padding: 10upx 16upx;
  2097. margin-left: 12upx;
  2098. }
  2099. .history-line {
  2100. display: flex;
  2101. flex-direction: row;
  2102. justify-content: space-between;
  2103. margin-bottom: 8upx;
  2104. }
  2105. .history-time {
  2106. font-size: 24upx;
  2107. color: #9aa4b2;
  2108. }
  2109. .history-total {
  2110. font-size: 24upx;
  2111. color: #09c567;
  2112. font-weight: 600;
  2113. }
  2114. .history-detail {
  2115. font-size: 24upx;
  2116. color: #5c6573;
  2117. word-break: break-all;
  2118. line-height: 1.35;
  2119. }
  2120. .history-empty {
  2121. text-align: center;
  2122. font-size: 26upx;
  2123. color: #c5ccd6;
  2124. padding: 60upx 0;
  2125. }
  2126. </style>