OrderCommitDialog.vue 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930
  1. <!--
  2. 开单确认提交面板(常驻在购物车右侧,非弹窗)
  3. 由开单 POS 页四栏布局直接挂载,始终渲染;切换客户时刷新表单。
  4. UI/业务对齐 ghsApp affirm:配送、打折、付款与备注提交。
  5. -->
  6. <template>
  7. <aside class="order-commit-panel">
  8. <!-- 与购物车 .pos-cart-head 同高,保证右栏标题齐平 -->
  9. <div class="panel-head">确认提交</div>
  10. <!-- 中间可滚动:表单内容多,避免挤掉底部提交按钮 -->
  11. <div class="panel-scroll">
  12. <div class="commit-body">
  13. <!-- 当前门店/客户名称已移至顶栏展示,此处不再重复渲染;form.customName 仍用于提交 -->
  14. <!-- 批发商 pfLevel:同城/德邦等 -->
  15. <div class="accounts-list" v-if="currentShop.pfLevel && currentShop.pfLevel == 1">
  16. <span class="accounts-label">配送方式</span>
  17. <div class="accounts-center">
  18. <el-button :type="form.transType == 4 ? 'primary' : ''" size="small" @click="setTransType(4)">同城</el-button>
  19. <el-button :type="form.transType == 0 ? 'primary' : ''" size="small" @click="setTransType(0)">德邦</el-button>
  20. <el-button :type="form.transType == 1 ? 'primary' : ''" size="small" @click="setTransType(1)">顺丰</el-button>
  21. <el-button :type="form.transType == 2 ? 'primary' : ''" size="small" @click="setTransType(2)">冷链</el-button>
  22. <el-button :type="form.transType == 3 ? 'primary' : ''" size="small" @click="setTransType(3)">航空</el-button>
  23. <el-button :type="form.transType == 5 ? 'primary' : ''" size="small" @click="setTransType(5)">自取</el-button>
  24. </div>
  25. </div>
  26. <!-- 普通门店:自配送/自取/物流;跑腿选项暂隐藏,待同城能力稳定后再开 -->
  27. <div class="accounts-list" v-else>
  28. <span class="accounts-label">配送方式</span>
  29. <div class="accounts-center">
  30. <el-button :type="form.sendType == 0 ? 'primary' : ''" size="small" @click="setSendType(0)">自配送</el-button>
  31. <el-button :type="form.sendType == 1 ? 'primary' : ''" size="small" @click="setSendType(1)">自取</el-button>
  32. <el-button :type="form.sendType == 3 ? 'primary' : ''" size="small" @click="setSendType(3)">物流</el-button>
  33. </div>
  34. </div>
  35. <!-- 物流:手填 + 选物流 -->
  36. <div class="accounts-list" v-if="form.sendType == 3 && !(currentShop.pfLevel && currentShop.pfLevel == 1)">
  37. <span class="accounts-label">配送物流</span>
  38. <div class="accounts-center accounts-center--row">
  39. <el-input placeholder="请填写物流" v-model="form.wlName" style="flex:1;" />
  40. <el-button size="small" style="margin-left:8px;" @click="openWlPicker">选物流</el-button>
  41. </div>
  42. </div>
  43. <!-- 跑腿:开通同城则询价,否则仅手填运费 -->
  44. <template v-if="displaySendCost">
  45. <template v-if="form.sendType == 2 && openIntraCity == 1">
  46. <div class="accounts-list accounts-list--top">
  47. <span class="accounts-label">客户地址</span>
  48. <div class="accounts-center">
  49. <template v-if="!customInfo.long || !customInfo.lat || !customInfo.address">
  50. <span class="addr-warn">地址不完善,请先在客户资料中补全经纬度与地址</span>
  51. </template>
  52. <template v-else>
  53. <div>{{ customInfo.address }}</div>
  54. <div class="addr-sub">{{ customInfo.showAddress }}</div>
  55. </template>
  56. </div>
  57. </div>
  58. <div class="accounts-list accounts-list--top">
  59. <span class="accounts-label">跑腿报价</span>
  60. <div class="accounts-center">
  61. <div v-if="quotesLoading" class="quotes-tip">正在获取运费...</div>
  62. <div v-else-if="!deliveryQuotes.length" class="quotes-tip">
  63. <span v-if="!customInfo.long || !customInfo.lat || !customInfo.address">请先完善客户地址</span>
  64. <span v-else>暂无跑腿可用 <el-button type="text" @click="getDeliveryQuotes">重试</el-button></span>
  65. </div>
  66. <div v-else class="quotes-grid">
  67. <div
  68. v-for="(item, index) in deliveryQuotes"
  69. :key="index"
  70. class="quote-item"
  71. :class="{ active: selectedDeliveryIndex === index, disabled: item.isAble === false }"
  72. @click="selectDelivery(item, index)"
  73. >
  74. <div class="platform-name">{{ item.displayName || item.name }}</div>
  75. <div class="platform-price">{{ item.priceText }}元</div>
  76. <div v-if="item.type" class="platform-type">{{ item.type }}</div>
  77. </div>
  78. </div>
  79. </div>
  80. </div>
  81. <div class="accounts-list">
  82. <span class="accounts-label">距离</span>
  83. <div class="accounts-center" style="color:#3385ff;">
  84. <template v-if="showDistance > 100">{{ (showDistance / 1000).toFixed(1) }}公里</template>
  85. <template v-else>{{ showDistance || 0 }} 米</template>
  86. </div>
  87. </div>
  88. <div class="accounts-list">
  89. <span class="accounts-label">满减规则</span>
  90. <div class="accounts-center">
  91. <el-button :type="form.reductionRule == 0 ? 'primary' : ''" size="small" @click="form.reductionRule = 0">没有满减</el-button>
  92. <el-button :type="form.reductionRule == 1 ? 'primary' : ''" size="small" @click="form.reductionRule = 1">花材满减</el-button>
  93. </div>
  94. </div>
  95. <div class="accounts-list">
  96. <span class="accounts-label">运费</span>
  97. <div class="accounts-center">
  98. <el-input
  99. v-if="form.reductionRule == 1 && isHcMapRule()"
  100. placeholder="请填写运费"
  101. v-model="form.customSendCost"
  102. />
  103. <el-input v-else placeholder="请填写运费" v-model="form.sendCost" />
  104. </div>
  105. </div>
  106. <div class="accounts-list">
  107. <span class="accounts-label">叫跑腿</span>
  108. <div class="accounts-center">
  109. <el-checkbox :value="form.callErrand == 1" @change="v => form.callErrand = v ? 1 : 0">
  110. 开单后直接叫跑腿
  111. </el-checkbox>
  112. </div>
  113. </div>
  114. <div class="accounts-list" v-if="form.callErrand == 1">
  115. <span class="accounts-label">取件时间</span>
  116. <div class="accounts-center">
  117. <el-date-picker
  118. v-model="pickupTimeValue"
  119. type="datetime"
  120. value-format="yyyy-MM-dd HH:mm"
  121. placeholder="立即取件可用当前时间"
  122. style="width:100%;"
  123. @change="onPickupTimeChange"
  124. />
  125. </div>
  126. </div>
  127. <div class="accounts-list" v-if="form.callErrand == 1">
  128. <span class="accounts-label">重量</span>
  129. <div class="accounts-center">
  130. <el-input v-model="form.weight" placeholder="公斤" type="number" @change="debounceQuotes" />
  131. </div>
  132. </div>
  133. <div class="accounts-list" v-if="form.callErrand == 1">
  134. <span class="accounts-label">跑腿备注</span>
  135. <div class="accounts-center">
  136. <el-input v-model="form.deliveryRemark" placeholder="跑腿备注" />
  137. </div>
  138. </div>
  139. </template>
  140. <div class="accounts-list" v-else>
  141. <span class="accounts-label">运费</span>
  142. <div class="accounts-center">
  143. <el-input placeholder="请填写运费,留空免运费" v-model="form.sendCost" />
  144. </div>
  145. </div>
  146. </template>
  147. <div class="accounts-list" v-if="displayPackCost">
  148. <span class="accounts-label">打包费</span>
  149. <div class="accounts-center">
  150. <el-input placeholder="打包费" v-model="form.packCost" />
  151. </div>
  152. </div>
  153. <div class="accounts-list">
  154. <span class="accounts-label">付款方式</span>
  155. <div class="accounts-center">
  156. <el-button :type="form.hasPay == 2 ? 'primary' : ''" size="small" @click="form.hasPay = 2">挂账</el-button>
  157. <el-button :type="form.hasPay == 1 ? 'primary' : ''" size="small" @click="form.hasPay = 1">线下</el-button>
  158. <el-button
  159. v-if="Number(customBalance) > 0"
  160. :type="form.hasPay == 4 ? 'primary' : ''"
  161. size="small"
  162. @click="form.hasPay = 4"
  163. >余额</el-button>
  164. <el-button :type="form.hasPay == 0 ? 'primary' : ''" size="small" @click="form.hasPay = 0">扫码</el-button>
  165. </div>
  166. </div>
  167. <div class="accounts-list" v-if="Number(customBalance) > 0">
  168. <span class="accounts-label">客户余额</span>
  169. <div class="accounts-center" style="color:#3385ff;">¥{{ parseFloat(customBalance) }}</div>
  170. </div>
  171. <div class="accounts-list" v-if="form.hasPay == 1">
  172. <span class="accounts-label">线下方式</span>
  173. <div class="accounts-center">
  174. <el-button :type="form.payWay == 0 ? 'primary' : ''" size="small" @click="form.payWay = 0">线下微信</el-button>
  175. <el-button :type="form.payWay == 1 ? 'primary' : ''" size="small" @click="form.payWay = 1">线下支付宝</el-button>
  176. <el-button :type="form.payWay == 4 ? 'primary' : ''" size="small" @click="form.payWay = 4">现金</el-button>
  177. <el-button :type="form.payWay == 5 ? 'primary' : ''" size="small" @click="form.payWay = 5">银行卡</el-button>
  178. </div>
  179. </div>
  180. <div class="accounts-list">
  181. <span class="accounts-label">打印小票</span>
  182. <div class="accounts-center">
  183. <el-button :type="form.needPrint == 1 ? 'primary' : ''" size="small" @click="form.needPrint = 1">需要</el-button>
  184. <el-button :type="form.needPrint == 2 ? 'primary' : ''" size="small" @click="form.needPrint = 2">不要</el-button>
  185. </div>
  186. </div>
  187. <!-- 合计 + 打折(对齐 App) -->
  188. <div class="accounts-list">
  189. <span class="accounts-label">合计金额</span>
  190. <div class="accounts-center accounts-center--row">
  191. <span style="color:#3385ff;font-weight:700;">¥{{ parseFloat(finalPrice) }}</span>
  192. <el-button size="small" style="margin-left:12px;" @click="discountVisible = true">打折</el-button>
  193. <span v-if="discountValue > 0 && discountValue < 1" class="discount-tag">
  194. {{ (Number(discountValue) * 10).toFixed(1) }}折
  195. </span>
  196. </div>
  197. </div>
  198. <div class="accounts-list">
  199. <span class="accounts-label">{{ form.hasPay == 2 ? '应收金额' : '实收金额' }}</span>
  200. <div class="accounts-center">
  201. <el-input v-model="modifyPrice" clearable />
  202. </div>
  203. </div>
  204. <div class="accounts-list" v-if="modifyPrice > 0 && modifyPrice > finalPrice" style="color:red;font-weight:bold;">
  205. <span class="accounts-label">人工资材</span>
  206. <div class="accounts-center">¥{{ parseFloat((modifyPrice - finalPrice).toFixed(2)) }}</div>
  207. </div>
  208. <div class="accounts-list" v-if="modifyPrice > 0 && modifyPrice < finalPrice" style="color:green;font-weight:bold;">
  209. <span class="accounts-label">优惠金额</span>
  210. <div class="accounts-center">¥{{ parseFloat((finalPrice - modifyPrice).toFixed(2)) }}</div>
  211. </div>
  212. <div class="accounts-list">
  213. <span class="accounts-label">送货日期</span>
  214. <div class="accounts-center">
  215. <el-date-picker v-model="form.sendTimeWant" style="width: 100%" type="date" value-format="yyyy-MM-dd" placeholder="默认当天或隔天" />
  216. </div>
  217. </div>
  218. <div class="accounts-list">
  219. <span class="accounts-label">开单人员</span>
  220. <div class="accounts-center">
  221. <el-select style="width:100%" v-model="form.getStaffId" placeholder="请选择" @change="onStaffChange">
  222. <el-option v-for="item in staffList" :key="item.id" :label="item.name" :value="item.id" />
  223. </el-select>
  224. </div>
  225. </div>
  226. <div class="accounts-list">
  227. <span class="accounts-label">账单日期</span>
  228. <div class="accounts-center">
  229. <el-date-picker v-model="form.historyDate" style="width: 100%" type="date" value-format="yyyy-MM-dd" placeholder="默认当天" />
  230. </div>
  231. </div>
  232. <div class="accounts-list accounts-list--top">
  233. <span class="accounts-label">备注信息</span>
  234. <div class="accounts-center">
  235. <el-input type="textarea" :rows="2" placeholder="请输入内容" v-model="form.remark" />
  236. </div>
  237. </div>
  238. <div v-if="!$util.isEmpty(diffList)" class="diff-box">
  239. <div class="diff-title">以下花材开单价与系统售价不一致,确认提交吗?</div>
  240. <el-button type="primary" size="mini" @click="submitOrder(true)">确认差价(Ctrl+Alt+Enter)</el-button>
  241. <div v-for="(item, index) in diffList" :key="index" class="diff-line">
  242. {{ item.name }}
  243. 系统售价 <span class="g">¥{{ item.price ? parseFloat(item.price) : 0 }}</span>
  244. 你开价 <span class="r">¥{{ item.kdPrice ? parseFloat(item.kdPrice) : 0 }}</span>
  245. </div>
  246. </div>
  247. </div>
  248. </div>
  249. <!-- 底部固定提交:始终可见,不随表单滚动 -->
  250. <div class="panel-footer">
  251. <el-button type="primary" :loading="submitting" class="submit-btn" @click="submitOrder(false)">
  252. 确认提交(Ctrl+Enter)
  253. </el-button>
  254. <p class="tip">按 Tab 切到下一个,按空格选中</p>
  255. </div>
  256. <!-- 选物流:嵌套弹窗挂到 body,避免被侧栏裁剪 -->
  257. <el-dialog title="请选择物流" :visible.sync="wlPickerVisible" width="420px" append-to-body>
  258. <div v-loading="wlLoading">
  259. <el-button
  260. v-for="item in wlList"
  261. :key="item.id || item.name"
  262. size="small"
  263. :type="form.wlName === item.name ? 'primary' : 'default'"
  264. style="margin: 0 8px 8px 0;"
  265. @click="selectWl(item)"
  266. >{{ item.name }}</el-button>
  267. <div v-if="!wlLoading && !wlList.length" class="quotes-tip">暂无物流,请手填</div>
  268. </div>
  269. </el-dialog>
  270. <!-- 打折:1–9折 / 不打 / 自定义;append-to-body 保证遮罩盖住整页 -->
  271. <el-dialog title="选择打折" :visible.sync="discountVisible" width="440px" append-to-body>
  272. <div class="discount-box">
  273. <el-button
  274. v-for="(item, index) in discountList"
  275. :key="index"
  276. size="small"
  277. :type="discountValue === item.value ? 'primary' : 'default'"
  278. class="discount-btn"
  279. @click="setDiscount(item.value)"
  280. >{{ item.name }}</el-button>
  281. <div class="discount-custom">
  282. <span>自定义折扣</span>
  283. <el-input v-model="customDiscount" placeholder="85折请填0.85" style="width:160px;margin:0 8px;" />
  284. <el-button type="primary" size="small" @click="setCustomDiscount">确认</el-button>
  285. </div>
  286. </div>
  287. <span slot="footer">
  288. <el-button @click="discountVisible = false">取消</el-button>
  289. </span>
  290. </el-dialog>
  291. </aside>
  292. </template>
  293. <script>
  294. import dayjs from 'dayjs'
  295. export default {
  296. name: 'OrderCommitDialog',
  297. props: {
  298. customId: { type: [Number, String], default: 0 },
  299. customName: { type: String, default: '' },
  300. /** 当前开单门店名,与 POS 页「当前在 xxx」一致 */
  301. shopName: { type: String, default: '' },
  302. /** 当前客户已选花材 */
  303. selectList: { type: Array, default: () => [] },
  304. /** 商品合计(不含运费打包费) */
  305. goodsPrice: { type: [Number, String], default: 0 },
  306. book: { type: [Number, String], default: 0 },
  307. customBalance: { type: [Number, String], default: 0 }
  308. },
  309. data() {
  310. return {
  311. submitting: false,
  312. modifyPrice: 0,
  313. diffList: [],
  314. staffList: [],
  315. currentShop: { pfLevel: 0 },
  316. openIntraCity: 0,
  317. hcFreeKm: 0,
  318. hcMap: [],
  319. customInfo: {},
  320. deliveryQuotes: [],
  321. selectedDeliveryIndex: -1,
  322. selectedDeliveryData: null,
  323. showDistance: 0,
  324. quotesLoading: false,
  325. weightDebounceTimer: null,
  326. pickupTimeValue: '',
  327. wlPickerVisible: false,
  328. wlList: [],
  329. wlLoading: false,
  330. discountVisible: false,
  331. discountValue: 0,
  332. customDiscount: '',
  333. discountList: [
  334. { name: '1折', value: 0.1 },
  335. { name: '2折', value: 0.2 },
  336. { name: '3折', value: 0.3 },
  337. { name: '4折', value: 0.4 },
  338. { name: '5折', value: 0.5 },
  339. { name: '6折', value: 0.6 },
  340. { name: '7折', value: 0.7 },
  341. { name: '8折', value: 0.8 },
  342. { name: '9折', value: 0.9 },
  343. { name: '不打', value: 1 }
  344. ],
  345. form: {
  346. customId: 0,
  347. customName: '',
  348. sendType: 0,
  349. transType: 4,
  350. sendCost: '',
  351. customSendCost: 0,
  352. packCost: '',
  353. wlName: '',
  354. hasPay: 2,
  355. payWay: 0,
  356. needPrint: 1,
  357. getStaffId: 0,
  358. getStaffName: '',
  359. sendTimeWant: '',
  360. historyDate: '',
  361. remark: '',
  362. book: 0,
  363. dealPrice: 0,
  364. reductionRule: 0,
  365. callErrand: 0,
  366. weight: 1,
  367. deliveryRemark: ''
  368. }
  369. }
  370. },
  371. computed: {
  372. // 面板已隐藏「当前门店」行;仍保留计算,避免与 shopName/currentShop 同步逻辑脱节
  373. displayShopName() {
  374. if (this.shopName) return this.shopName
  375. const shop = this.currentShop || {}
  376. return shop.shopName || shop.name || '门店'
  377. },
  378. displayPackCost() {
  379. return this.currentShop.pfLevel && this.currentShop.pfLevel == 1
  380. },
  381. /** 是否展示运费区:跑腿 或 批发商配送(对齐 App displaySendCost) */
  382. displaySendCost() {
  383. if (this.form.sendType == 2) return true
  384. if (this.currentShop.pfLevel && this.currentShop.pfLevel == 1) return true
  385. return false
  386. },
  387. /** 扎数合计,用于花材满减规则 */
  388. totalBigCount() {
  389. let big = 0
  390. if (!this.$util.isEmpty(this.selectList)) {
  391. this.selectList.forEach(ele => {
  392. if (Number(ele.bigCount) > 0) big += Number(ele.bigCount)
  393. })
  394. }
  395. return big
  396. },
  397. /**
  398. * 合计 = 花材 + 运费(+打包费);运费规则对齐 affirm
  399. */
  400. finalPrice() {
  401. let finalPrice = Number(this.goodsPrice) || 0
  402. if (this.form.sendType == 2) {
  403. const sendCost = Number(this.form.sendCost) || 0
  404. if (this.form.reductionRule == 0) {
  405. finalPrice += sendCost
  406. } else if (this.form.reductionRule == 1) {
  407. if (this.isHcMapRule()) {
  408. finalPrice += Number(this.form.customSendCost) || 0
  409. } else {
  410. finalPrice += sendCost
  411. }
  412. }
  413. } else if (this.displaySendCost) {
  414. finalPrice += Number(this.form.sendCost) || 0
  415. }
  416. if (this.displayPackCost) {
  417. finalPrice += Number(this.form.packCost) || 0
  418. }
  419. return parseFloat(finalPrice.toFixed(2))
  420. }
  421. },
  422. watch: {
  423. /** 合计变化时同步应收;已打折则按折扣重算 */
  424. finalPrice(val) {
  425. const d = Number(this.discountValue)
  426. if (d > 0 && d <= 1) {
  427. this.modifyPrice = parseFloat((Number(val) * d).toFixed(2))
  428. } else {
  429. this.modifyPrice = val
  430. }
  431. },
  432. /** 切换客户时重置面板,避免沿用上一客户配送/付款等选项 */
  433. customId() {
  434. this.resetPanel()
  435. },
  436. customName(val) {
  437. this.form.customName = val || ''
  438. }
  439. },
  440. mounted() {
  441. this.resetPanel()
  442. },
  443. methods: {
  444. /**
  445. * 重置面板表单与询价状态
  446. * 用于:进页、切换客户、提交成功后;侧栏常驻,不再关弹窗
  447. */
  448. resetPanel() {
  449. this.diffList = []
  450. this.discountValue = 0
  451. this.customDiscount = ''
  452. this.deliveryQuotes = []
  453. this.selectedDeliveryIndex = -1
  454. this.selectedDeliveryData = null
  455. this.showDistance = 0
  456. this.customInfo = {}
  457. this.form.customId = this.customId
  458. this.form.customName = this.customName
  459. this.form.book = Number(this.book) || 0
  460. this.form.sendType = 0
  461. this.form.transType = 4
  462. this.form.hasPay = 2
  463. this.form.sendCost = ''
  464. this.form.customSendCost = 0
  465. this.form.packCost = ''
  466. this.form.wlName = ''
  467. this.form.remark = ''
  468. this.form.dealPrice = 0
  469. this.form.reductionRule = 0
  470. this.form.callErrand = 0
  471. this.form.weight = 1
  472. this.form.deliveryRemark = ''
  473. this.pickupTimeValue = dayjs().format('YYYY-MM-DD HH:mm')
  474. this.$nextTick(() => {
  475. this.modifyPrice = this.finalPrice
  476. })
  477. this.loadShopAndStaff()
  478. this.loadCustomDetail()
  479. },
  480. loadShopAndStaff() {
  481. const that = this
  482. this.$service.common.shopInfo().then(res => {
  483. that.currentShop = res.shopInfo || res.shop || { pfLevel: 0 }
  484. that.openIntraCity = res.openIntraCity != null ? Number(res.openIntraCity) : 0
  485. that.hcFreeKm = res.hcFreeKm != null ? Number(res.hcFreeKm) : 0
  486. try {
  487. that.hcMap = typeof res.hcMap === 'string' ? JSON.parse(res.hcMap) : (res.hcMap || [])
  488. } catch (e) {
  489. that.hcMap = []
  490. }
  491. const currentStaff = res.staff || {}
  492. that.$service.shopAdmin.getAllStaff().then(staffRes => {
  493. that.staffList = staffRes.list || []
  494. if (!that.$util.isEmpty(that.staffList)) {
  495. for (const ele of that.staffList) {
  496. if (currentStaff.id == ele.id) {
  497. that.form.getStaffId = ele.id
  498. that.form.getStaffName = ele.name
  499. }
  500. }
  501. }
  502. })
  503. })
  504. },
  505. /** 拉客户详情:默认物流名、地址(跑腿询价用) */
  506. loadCustomDetail() {
  507. if (!this.customId) return
  508. this.$service.custom.clientInfo({ id: this.customId }).then(res => {
  509. const info = res.custom || res.data || res || {}
  510. this.customInfo = info
  511. if (info.name) this.form.customName = info.name
  512. if (info.wlName) this.form.wlName = info.wlName
  513. }).catch(() => {})
  514. },
  515. setTransType(type) {
  516. this.form.transType = type
  517. },
  518. /**
  519. * 切换配送方式;选跑腿且开通同城时拉报价
  520. */
  521. setSendType(type) {
  522. this.form.sendType = type
  523. if (type !== 2) {
  524. this.form.sendCost = ''
  525. this.deliveryQuotes = []
  526. this.selectedDeliveryIndex = -1
  527. this.selectedDeliveryData = null
  528. } else if (this.openIntraCity == 1) {
  529. this.getDeliveryQuotes()
  530. }
  531. },
  532. openWlPicker() {
  533. this.wlPickerVisible = true
  534. this.wlLoading = true
  535. this.$service.wl.getAllWl().then(res => {
  536. this.wlList = res.list || (res.data && res.data.list) || []
  537. this.wlLoading = false
  538. }).catch(() => {
  539. this.wlLoading = false
  540. this.$message({ message: '获取物流列表失败', type: 'warning' })
  541. })
  542. },
  543. selectWl(item) {
  544. this.form.wlName = item.name
  545. this.wlPickerVisible = false
  546. },
  547. /** 花材满减是否命中(距离/扎数/金额) */
  548. isHcMapRule() {
  549. const distanceInMeters = Number(this.showDistance) || 0
  550. const freeKmInMeters = (Number(this.hcFreeKm) || 0) * 1000
  551. if (distanceInMeters < freeKmInMeters) return true
  552. const map = Array.isArray(this.hcMap) ? this.hcMap : []
  553. const flowerCount = this.totalBigCount
  554. const flowerPrice = Number(this.goodsPrice) || 0
  555. for (const rule of map) {
  556. const ruleNum = Number(rule.num) || 0
  557. const rulePrice = Number(rule.price) || 0
  558. const ruleDistance = (Number(rule.distance) || 0) * 1000
  559. if (flowerCount >= ruleNum && flowerPrice >= rulePrice && distanceInMeters <= ruleDistance) {
  560. return true
  561. }
  562. }
  563. return false
  564. },
  565. debounceQuotes() {
  566. if (this.weightDebounceTimer) clearTimeout(this.weightDebounceTimer)
  567. this.weightDebounceTimer = setTimeout(() => this.getDeliveryQuotes(), 400)
  568. },
  569. onPickupTimeChange() {
  570. if (this.openIntraCity == 1 && this.form.sendType == 2) {
  571. this.getDeliveryQuotes()
  572. }
  573. },
  574. /** 跑腿多平台询价(对齐 App getDeliveryQuotes) */
  575. getDeliveryQuotes() {
  576. if (!this.customInfo.long || !this.customInfo.lat || !this.customInfo.address) {
  577. return
  578. }
  579. this.quotesLoading = true
  580. this.deliveryQuotes = []
  581. this.selectedDeliveryIndex = -1
  582. this.selectedDeliveryData = null
  583. this.$service.delivery.quickOrderAllDeliveryQuotes({
  584. totalPrice: this.goodsPrice,
  585. weight: this.form.weight,
  586. remark: this.form.deliveryRemark,
  587. customId: this.customId,
  588. pickupTime: this.pickupTimeValue || dayjs().format('YYYY-MM-DD HH:mm')
  589. }).then(res => {
  590. this.quotesLoading = false
  591. const raw = res.deliveryList || (res.data && res.data.deliveryList) || []
  592. this.deliveryQuotes = raw
  593. .filter(item => item.isAble !== false)
  594. .map(item => {
  595. const price = item.price ? (item.price / 100).toFixed(1) : '0.0'
  596. let displayName = item.name || ''
  597. let bracketContent = ''
  598. if (displayName.indexOf('(') !== -1) {
  599. const parts = displayName.split('(')
  600. displayName = parts[0].trim()
  601. bracketContent = (parts[1] || '').replace(')', '')
  602. }
  603. if (item.en_name == 'didi' && bracketContent) {
  604. item.type = bracketContent
  605. }
  606. return {
  607. ...item,
  608. displayName,
  609. priceText: price,
  610. priceNumber: parseFloat(price),
  611. bracketContent
  612. }
  613. })
  614. const first = this.deliveryQuotes.findIndex(i => i.isAble !== false)
  615. if (first !== -1) this.selectDelivery(this.deliveryQuotes[first], first)
  616. }).catch(() => {
  617. this.quotesLoading = false
  618. this.deliveryQuotes = []
  619. this.$message({ message: '获取跑腿平台报价失败', type: 'warning' })
  620. })
  621. },
  622. selectDelivery(item, index) {
  623. if (item.isAble === false) return
  624. this.selectedDeliveryIndex = index
  625. this.selectedDeliveryData = item
  626. this.form.sendCost = item.priceNumber
  627. this.showDistance = item.distance || 0
  628. },
  629. onStaffChange(id) {
  630. const staff = this.staffList.find(s => s.id == id)
  631. if (staff) this.form.getStaffName = staff.name
  632. },
  633. /** 快捷折扣:modifyPrice = 合计 * 折扣 */
  634. setDiscount(num) {
  635. this.discountValue = Number(num)
  636. this.modifyPrice = parseFloat((Number(this.finalPrice) * Number(num)).toFixed(2))
  637. this.customDiscount = ''
  638. this.discountVisible = false
  639. },
  640. setCustomDiscount() {
  641. const value = parseFloat(this.customDiscount)
  642. if (isNaN(value) || value < 0 || value > 1) {
  643. this.$message({ message: '请输入0到1之间的有效折扣值', type: 'warning' })
  644. return
  645. }
  646. this.setDiscount(value)
  647. },
  648. /**
  649. * 提交订单;forceDealPrice 为差价二次确认
  650. * 成功后只重置面板并 emit success,不关侧栏(侧栏始终展示)
  651. * 父页可通过 $refs.commitPanel.submitOrder(false) 走快捷键提交
  652. */
  653. submitOrder(forceDealPrice) {
  654. const that = this
  655. if (!this.form.customId) {
  656. this.$message({ message: '请选择客户', type: 'warning' })
  657. return
  658. }
  659. if (this.$util.isEmpty(this.selectList)) {
  660. this.$message({ message: '请选择花材', type: 'warning' })
  661. return
  662. }
  663. if (this.form.sendType == 3 && this.$util.isEmpty(this.form.wlName)) {
  664. this.$message({ message: '请填写物流', type: 'warning' })
  665. return
  666. }
  667. if (Number(this.modifyPrice) <= 0) {
  668. this.$message({ message: '收款金额必须大于0', type: 'warning' })
  669. return
  670. }
  671. if (this.form.book == 1 && Number(this.form.sendCost) > 0) {
  672. this.$message({ message: '预订单不能填写运费', type: 'warning' })
  673. return
  674. }
  675. if (Number(this.customBalance) >= Number(this.modifyPrice) && this.form.hasPay == 2) {
  676. this.$message({ message: '余额充足,请用余额支付', type: 'warning' })
  677. return
  678. }
  679. if (this.form.hasPay == 4 && Number(this.customBalance) < Number(this.modifyPrice)) {
  680. this.$message({ message: '余额不足,无法余额支付', type: 'warning' })
  681. return
  682. }
  683. if (this.form.book == 1 && this.form.hasPay != 2) {
  684. this.$message({ message: '预订单只能选择挂账', type: 'warning' })
  685. return
  686. }
  687. if (this.form.callErrand == 1) {
  688. if (!this.customInfo.long || !this.customInfo.lat || !this.customInfo.address) {
  689. this.$message({ message: '客户地址不完整,不支持直接发跑腿', type: 'warning' })
  690. return
  691. }
  692. }
  693. const product = this.selectList.map(ele => {
  694. return {
  695. productId: ele.id,
  696. bigNum: ele.bigCount,
  697. smallNum: ele.smallCount || 0,
  698. classId: ele.classId || 0,
  699. itemId: ele.itemId,
  700. price: ele.userPrice,
  701. remark: ele.remark || ''
  702. }
  703. })
  704. const params = {
  705. ...this.form,
  706. product: JSON.stringify(product),
  707. modifyPrice: this.modifyPrice,
  708. newVersion: 1,
  709. dealPrice: forceDealPrice ? 1 : this.form.dealPrice
  710. }
  711. // 跑腿平台参数(对齐 affirm)
  712. if (this.form.sendType == 2 && this.selectedDeliveryData) {
  713. params.deliveryPlatform = this.selectedDeliveryData.en_name
  714. params.deliveryPrice = this.selectedDeliveryData.priceNumber
  715. params.deliveryDistance = this.showDistance
  716. params.deliveryBracketContent = this.selectedDeliveryData.bracketContent
  717. params.deliveryAllParams = this.selectedDeliveryData
  718. if (this.form.callErrand == 1) {
  719. params.pickupTime = this.pickupTimeValue || dayjs().format('YYYY-MM-DD HH:mm')
  720. }
  721. }
  722. let tip = '确认提交'
  723. if (this.form.hasPay == 1) tip = '确认线下付款?'
  724. else if (this.form.hasPay == 2) tip = '确认挂账?'
  725. else if (this.form.hasPay == 4) tip = '确认余额支付?'
  726. else if (this.form.hasPay == 0) tip = '确认扫码收款?'
  727. this.$confirm(tip, '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' }).then(() => {
  728. that.submitting = true
  729. that.$service.order.orderCreate(params).then(data => {
  730. that.submitting = false
  731. if (data.respondType && data.respondType == 'priceError') {
  732. that.diffList = data.diff ? data.diff : []
  733. that.$message({ message: '请确认修改的价格', type: 'warning' })
  734. return
  735. }
  736. that.$notify({ title: '成功', message: '开单成功', type: 'success' })
  737. // 成功后重置表单,面板继续常驻;清车等由父页 onOrderSuccess 处理
  738. that.resetPanel()
  739. that.$emit('success', data)
  740. }).catch(() => {
  741. that.submitting = false
  742. })
  743. }).catch(() => {})
  744. }
  745. }
  746. }
  747. </script>
  748. <style lang="scss">
  749. /* 侧栏内嵌套弹窗无需改 el-dialog 全局高度 */
  750. </style>
  751. <style lang="scss" scoped>
  752. /* 右侧常驻面板:约 360px,与收窄后的购物车并列 */
  753. .order-commit-panel {
  754. flex-shrink: 0;
  755. width: 360px;
  756. max-width: 360px;
  757. background: #fff;
  758. border-left: 1px solid #ebeef5;
  759. display: flex;
  760. flex-direction: column;
  761. min-height: 0;
  762. height: 100%;
  763. box-sizing: border-box;
  764. }
  765. /* 与开单页 .pos-cart-head 统一 48px,避免两侧 header 高低不一 */
  766. .panel-head {
  767. flex-shrink: 0;
  768. box-sizing: border-box;
  769. height: 48px;
  770. min-height: 48px;
  771. display: flex;
  772. align-items: center;
  773. padding: 0 14px;
  774. font-size: 16px;
  775. line-height: 22px;
  776. font-weight: 700;
  777. color: #303133;
  778. border-bottom: 1px solid #ebeef5;
  779. }
  780. .panel-scroll {
  781. flex: 1;
  782. min-height: 0;
  783. overflow-y: auto;
  784. padding: 12px 12px 8px;
  785. }
  786. .panel-footer {
  787. flex-shrink: 0;
  788. padding: 10px 12px 14px;
  789. border-top: 1px solid #ebeef5;
  790. background: #fff;
  791. .submit-btn {
  792. width: 100%;
  793. height: 40px;
  794. font-size: 15px;
  795. }
  796. .tip {
  797. text-align: center;
  798. color: #999;
  799. margin: 8px 0 0;
  800. font-size: 12px;
  801. }
  802. }
  803. .commit-body {
  804. .accounts-list {
  805. display: flex;
  806. align-items: center;
  807. justify-content: flex-start;
  808. margin-bottom: 12px;
  809. font-size: 13px;
  810. color: #666;
  811. }
  812. .accounts-list--top {
  813. align-items: flex-start;
  814. }
  815. .accounts-label {
  816. flex-shrink: 0;
  817. width: 64px;
  818. line-height: 32px;
  819. }
  820. .accounts-center {
  821. flex: 1;
  822. min-width: 0;
  823. margin-left: 8px;
  824. text-align: left;
  825. }
  826. .accounts-center--row {
  827. display: flex;
  828. align-items: center;
  829. }
  830. .shop-name {
  831. font-weight: 700;
  832. color: #303133;
  833. }
  834. .addr-warn {
  835. color: #f56c6c;
  836. font-weight: 700;
  837. }
  838. .addr-sub {
  839. margin-top: 4px;
  840. color: #909399;
  841. font-size: 12px;
  842. }
  843. .discount-tag {
  844. margin-left: 8px;
  845. color: #3385ff;
  846. font-size: 13px;
  847. }
  848. .diff-box {
  849. text-align: left;
  850. margin-top: 12px;
  851. }
  852. .diff-title {
  853. color: red;
  854. font-weight: bold;
  855. margin-bottom: 8px;
  856. }
  857. .diff-line {
  858. color: #3385ff;
  859. margin-top: 4px;
  860. font-size: 12px;
  861. .g { color: green; font-weight: bold; margin-left: 4px; }
  862. .r { color: red; font-weight: bold; margin-left: 4px; }
  863. }
  864. .quotes-tip {
  865. color: #909399;
  866. font-size: 13px;
  867. }
  868. .quotes-grid {
  869. display: flex;
  870. flex-wrap: wrap;
  871. }
  872. .quote-item {
  873. width: calc(50% - 6px);
  874. margin: 0 6px 6px 0;
  875. padding: 8px;
  876. border: 1px solid #dcdfe6;
  877. border-radius: 4px;
  878. cursor: pointer;
  879. box-sizing: border-box;
  880. &.active {
  881. border-color: #3385ff;
  882. background: #ecf5ff;
  883. }
  884. &.disabled {
  885. opacity: 0.5;
  886. pointer-events: none;
  887. }
  888. .platform-name {
  889. font-weight: 600;
  890. color: #303133;
  891. }
  892. .platform-price {
  893. color: #3385ff;
  894. margin-top: 4px;
  895. }
  896. .platform-type {
  897. font-size: 12px;
  898. color: #909399;
  899. }
  900. }
  901. }
  902. .discount-box {
  903. .discount-btn {
  904. margin: 0 8px 8px 0;
  905. }
  906. .discount-custom {
  907. display: flex;
  908. align-items: center;
  909. margin-top: 12px;
  910. }
  911. }
  912. </style>