standard-products.vue 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810
  1. <template>
  2. <div class="app-container">
  3. <el-table :key="tableKey" ref="multipleTable" v-loading="listLoading" :data="tableData" :show-header="false" fit @selection-change="handleSelectionChange">
  4. <el-table-column type="selection" width="30" align="center" />
  5. <!-- <el-table-column align="center" type="index" width="50"></el-table-column>-->
  6. <el-table-column align="center">
  7. <template slot-scope="{row, $index}">
  8. <el-container>
  9. <el-aside width="80px" style="background-color: #ffffff; padding: 0; margin-bottom: 0;">
  10. <el-image style="width: 80px; height: 80px" :src="tool.getArImage(row.COVER, '/files/')" @click="handleProduct(row)" />
  11. </el-aside>
  12. <el-main style="padding: 5px 5px; text-align: left;">
  13. <el-row :gutter="10">
  14. <el-col :xs="24" :sm="24" :lg="6">
  15. <span style="cursor: pointer;" @click="handleProduct(row)">{{ row.GOODS_NAME }}</span>
  16. </el-col>
  17. <el-col :xs="24" :sm="24" :lg="3">
  18. <span style="color: #9c9c9c; cursor: pointer;">{{ row.GOODS_NO }}</span>
  19. </el-col>
  20. <el-col :xs="24" :sm="24" :lg="4">
  21. <span style="font-size: 13px;">
  22. <span style="font-weight: bold; color: tomato;">
  23. DP:{{row.COIN}} {{ row.SELL_PRICE | toThousandFilter }}
  24. <span style="font-weight:normal; color: #606266;">({{ row.PRICE_PV | toThousandFilter }}{{ $t('shop.productBV') }})</span>
  25. </span>
  26. </span>
  27. </el-col>
  28. <el-col :xs="24" :sm="24" :lg="3">
  29. <span style="font-size: 13px;">RP:{{row.COIN}} {{ row.MARKET_PRICE }}</span>
  30. </el-col>
  31. <el-col :xs="24" :sm="24" :lg="3">
  32. <span style="font-size: 13px;">{{ $t('shop.inventory') }}:{{ row.STORE_NUMS }}</span>
  33. </el-col>
  34. <el-col :xs="24" :sm="24" :lg="5">
  35. <el-input-number v-model="storeNums[$index]" size="mini" :min="1" :max="Number(row.STORE_NUMS)" @change="handleInputNumber($event, row)" />
  36. </el-col>
  37. </el-row>
  38. </el-main>
  39. </el-container>
  40. </template>
  41. </el-table-column>
  42. </el-table>
  43. <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
  44. <div v-show="total>0" class="white-box-footer" style="margin-top: 15px;">
  45. <div class="flex data" style="float: left; display: inline-block; margin-top: 20px;">
  46. <el-button type="primary" size="small" style="float: left;" @click="settlement()">{{ $t('shop.checkOut') }}</el-button>
  47. </div>
  48. <div class="flex data" style="float: right; display: inline-block; line-height: 28px; font-size: 14px; margin-top: 10px; border: 1px solid #dcdfe6; border-radius: 4px; padding: 0 5px;">
  49. <div style="margin-right: 2rem; display: inline-block;">{{ $t('shop.productPrice') }}: {{currencyUnitCode}} {{ sellPriceSum | toThousandFilter }}</div>
  50. <div style="margin-right: 2rem; display: inline-block;">{{ $t('shop.productBV') }}:{{ pricePvSum | toThousandFilter }}</div>
  51. <div style="display: inline-block;">{{ $t('shop.taxAmount') }}:{{currencyUnitCode}} {{ taxSum | toThousandFilter }}</div>
  52. </div>
  53. </div>
  54. <!-- 购物车 -->
  55. <el-dialog v-loading="shoppingCartLoading" :title="$t('shop.productsSettlement')" :visible.sync="visibleShoppingCart" :width="screenWidth" style="margin-top: -95px;" :close="cleanShowCart" :show-close="false" :close-on-click-modal="false" :close-on-press-escape="false">
  56. <div v-loading="loading">
  57. <div class="white-box">
  58. <el-table :data="goods" :show-header="false">
  59. <el-table-column align="center">
  60. <template slot-scope="{row}">
  61. <el-container>
  62. <el-aside width="100px" style="background-color: #ffffff; padding: 0; margin-bottom: 0;">
  63. <el-image style="width: 100px; height: 100px" :src="tool.getArImage(row.COVER, '/files/')" @click="handleProduct(row)" />
  64. </el-aside>
  65. <el-main style="padding: 10px 5px; text-align: left;">
  66. <el-row :gutter="10">
  67. <el-col :xs="24" :sm="8" :lg="8">
  68. <span style="cursor: pointer;" @click="handleProduct(row)">{{ row.GOODS_NAME }}</span>
  69. </el-col>
  70. <el-col :xs="24" :sm="4" :lg="4">
  71. <span style="color: #9c9c9c; cursor: pointer;">{{ row.GOODS_NO }}</span>
  72. </el-col>
  73. <el-col :xs="16" :sm="4" :lg="4">
  74. <span style="font-weight: bold;"> {{currencyUnitCode}} {{ row.member_price | toThousandFilter }}</span>
  75. <span>({{ row.PRICE_PV | toThousandFilter }}{{ $t('shop.productBV') }})</span><br>
  76. </el-col>
  77. <el-col :xs="8" :sm="3" :lg="3">
  78. <span style="">x {{ row.chose_num }}</span>
  79. </el-col>
  80. <el-col :xs="24" :sm="5" :lg="5">
  81. <span style="color: tomato; font-weight: bold;">{{currencyUnitCode}} {{ row.member_price_plus | toThousandFilter }}</span>
  82. <span style="color: tomato;">({{ row.PRICE_PV | toThousandFilter }}{{ $t('shop.productBV') }})</span><br>
  83. </el-col>
  84. </el-row>
  85. </el-main>
  86. </el-container>
  87. </template>
  88. </el-table-column>
  89. </el-table>
  90. <div class="white-box-footer">
  91. <!-- 订单合计 -->
  92. <div class="" style="margin: 15px 0;">
  93. <el-row :gutter="20">
  94. <el-col :xs="24" :sm="24" :lg="3">
  95. <span style="font-weight: bold; word-break: normal; white-space: normal; line-height: 28px;">{{ $t('shop.totalOrders') }}:</span>
  96. </el-col>
  97. <el-col :xs="24" :sm="24" :lg="21" style="word-break: normal; white-space: nowrap; line-height: 28px;">
  98. <span>{{ $t('shop.total') }}:{{currencyUnitCode}} {{ parseFloat(cashSum) | toThousandFilter }}({{ pricePvSum | toThousandFilter }}{{ $t('shop.productBV') }})</span><br>
  99. <span>{{ $t('shop.freight') }}:{{currencyUnitCode}} {{ pointFreight }}</span>
  100. </el-col>
  101. </el-row>
  102. </div>
  103. <el-divider />
  104. <el-form>
  105. <el-form-item :label="$t('shop.declarationCenterNumber')">
  106. <el-input v-model="recUserName" :disabled="isDec == '1'" />
  107. </el-form-item>
  108. </el-form>
  109. <!-- 支付方式/账户余额 {{ cashCurrency }}: -->
  110. <div class="" style="margin: 15px 0;">
  111. <el-row :gutter="20" type="flex" style="flex-wrap: wrap;">
  112. <el-col :xs="24" :sm="24" :lg="3">
  113. <span style="font-weight: bold; word-break: normal; white-space: normal; line-height: 28px;">{{ $t('shop.selectPayment') }}:</span>
  114. </el-col>
  115. <el-col :xs="24" :sm="24" :lg="21" style="word-break: normal; white-space: nowrap;">
  116. <el-radio-group v-model="payType" @change="chosePayType">
  117. <div v-for="(item, index) in payList" :key="index" class="address">
  118. <el-radio :label="item.label" border>
  119. {{ item.name }}<span v-if="item.label === 'cash'" style="color: tomato;">( {{currencyUnitCode}} {{ userBalance.cash | toThousandFilter }})</span>
  120. <span v-if="item.label === 'prp'" style="color: tomato;">( {{currencyUnitCode}} {{ userBalance.prp | toThousandFilter }})</span>
  121. </el-radio>
  122. </div>
  123. </el-radio-group>
  124. </el-col>
  125. </el-row>
  126. </div>
  127. <el-divider />
  128. <!-- 收货地址 -->
  129. <div class="" style="margin: 15px 0;">
  130. <el-row :gutter="10" type="flex" style="flex-wrap: wrap;">
  131. <el-col :xs="24" :sm="24" :lg="3">
  132. <span style="font-weight: bold; word-break: normal; white-space: normal; line-height: 28px;">{{ $t('shop.selectAddress') }}:</span>
  133. </el-col>
  134. <el-col :xs="24" :sm="24" :lg="21" style="word-break: normal; white-space: nowrap;">
  135. <el-radio-group v-model="addressId" @change="choseAddress">
  136. <div class="address">
  137. <el-radio :label="selfPickUpAddressId">{{ $t('shop.selfPickUp') }}</el-radio>
  138. </div>
  139. <div v-for="(item, index) in shippingAddressList" :key="index" class="address">
  140. <el-radio :label="item.ID" style="word-break: break-all; white-space: normal;">
  141. <span>{{ item.ADDRESS }}, {{ item.LGA_NAME }}, {{ item.PROVINCE_NAME }}</span>
  142. <el-divider direction="vertical" />
  143. <span>{{ item.MOBILE }}</span>
  144. <el-divider direction="vertical" />
  145. <span>{{ item.CONSIGNEE }}</span>
  146. </el-radio>
  147. </div>
  148. </el-radio-group>
  149. </el-col>
  150. </el-row>
  151. </div>
  152. </div>
  153. <div class="white-box-footer">
  154. <el-row :gutter="40">
  155. <el-col :xs="24" :sm="24" :lg="24" align="left">
  156. <el-button type="warning" size="small" @click="cleanShowCart">{{ $t('shop.goBack') }}</el-button>
  157. <el-button type="primary" size="small" :loading="submitButtonStat" @click="orderSubmit">{{ $t('shop.goPay') }}</el-button>
  158. </el-col>
  159. </el-row>
  160. </div>
  161. </div>
  162. </div>
  163. </el-dialog>
  164. <!-- payStack模态框 -->
  165. <el-dialog v-loading="payStackLoading" :title="$t('shop.goPay')" :visible.sync="visible" :width="payStackScreenWidth" :before-close="handleClose">
  166. <section>
  167. <el-form :model="form">
  168. <el-form-item :label="$t('user.email')" label-width="100px" required>
  169. <el-input v-model="form.email" autocomplete="off" />
  170. </el-form-item>
  171. <el-form-item :label="$t('shop.amount')" label-width="100px" required>
  172. <el-input v-model="form.amount" autocomplete="off" readonly />
  173. </el-form-item>
  174. </el-form>
  175. </section>
  176. <paystack
  177. :firstname="form.firstname"
  178. :lastname="form.lastname"
  179. :amount="form.amount * 100"
  180. :email="form.email"
  181. :metadata="form.metadata"
  182. :currency="form.currency"
  183. :paystackkey="form.publicKey"
  184. :reference="reference"
  185. :channels="channels"
  186. :callback="processPayment"
  187. :close="handleClose"
  188. >
  189. <el-button type="primary" size="small">{{ $t('shop.goPay') }}</el-button>
  190. </paystack>
  191. <el-button type="danger" size="small" class="cancelButton" style="margin-left: 10px;" @click="handleClose">{{ $t('common.cancel') }}</el-button>
  192. </el-dialog>
  193. <!-- 倒计时页面 -->
  194. <el-dialog :title="$t('common.hint')" :visible.sync="payDialog" :width="payStackScreenWidth" :show-close="false" :close="handleOrderList">
  195. <el-card shadow="always">
  196. <el-result icon="success" :title="$t('common.successfully')" :sub-title="$t('shop.successOrderTips')">
  197. <template slot="extra">
  198. <el-button type="primary" size="medium" @click="handleOrderList">{{ $t('shop.goBack') }}({{ countdown }})</el-button>
  199. </template>
  200. </el-result>
  201. </el-card>
  202. </el-dialog>
  203. <!-- 商品详情 -->
  204. <el-dialog :title="product.GOODS_NO" :visible.sync="visibleProduct" :width="screenWidth" style="margin-top: -95px;">
  205. <el-row :gutter="20">
  206. <el-col :xs="24" :sm="12" :lg="12">
  207. <el-image style="width: 100%; height: 100%" :style="imageStyle" :src="tool.getArImage(product.COVER, '/files/')" />
  208. </el-col>
  209. <el-col :xs="24" :sm="12" :lg="12">
  210. <div style="text-align: left; line-height: 50px; font-size: 16px;">
  211. <span style="font-weight: bold; font-size: 20px;">{{ product.GOODS_NAME }}</span><br>
  212. <span style="font-weight: bold; font-size: 15px;">{{ $t('shop.productCode') }}:{{ product.GOODS_NO }}</span><br>
  213. <span style="color: tomato;">{{ $t('shop.salesPrice') }}:{{currencyUnitCode}} {{ product.SELL_PRICE }}</span><br>
  214. <span>{{ $t('shop.marketPrice') }}:{{currencyUnitCode}} {{ product.MARKET_PRICE }}</span><br>
  215. <span>{{ $t('shop.productBV') }}:{{ product.PRICE_PV | toThousandFilter }}</span><br>
  216. <span>{{ $t('shop.taxRate') }}:{{ product.TAX_RATE / 100 }}</span><br>
  217. <span>{{ $t('shop.taxAmount') }}:{{ product.taxAmount | toThousandFilter }}</span><br>
  218. <span>{{ $t('shop.inventory') }}:{{ product.STORE_NUMS }}</span>
  219. </div>
  220. </el-col>
  221. </el-row>
  222. </el-dialog>
  223. </div>
  224. </template>
  225. <script>
  226. import { createApproachOrder, createOrder, deleteApproachOrder, fetchProductList, fetchShoppingCart } from '@/api/shop'
  227. import Pagination from '@/components/Pagination'
  228. import waves from '@/directive/waves'
  229. import { getScreenWidth } from '@/utils'
  230. import tool from '@/utils/tool'
  231. import usersInfo from '@/utils/usersInfo'
  232. import paystack from 'vue-paystack'
  233. export default {
  234. name: 'StandardProducts',
  235. components: { Pagination, paystack },
  236. directives: { waves },
  237. filters: {
  238. priceFilter(price) {
  239. return tool.formatPrice(price)
  240. },
  241. taxAmountFilter(row) {
  242. return tool.calculateTax(row.SELL_PRICE, row.TAX_RATE)
  243. },
  244. statusFilter(status) {
  245. const statusMap = {
  246. Unpaid: 'info',
  247. Paid: 'success'
  248. }
  249. return statusMap[status]
  250. }
  251. },
  252. data() {
  253. return {
  254. tableKey: 0,
  255. list: [],
  256. total: 0,
  257. tableData: [],
  258. listLoading: true,
  259. listQuery: {
  260. categoryType: 1,
  261. page: 1,
  262. limit: 50
  263. },
  264. tool: tool,
  265. multipleSelection: [],
  266. sellPriceSum: 0.00,
  267. pricePvSum: 0.00,
  268. taxSum: 0.00,
  269. storeNums: [],
  270. display: false,
  271. currentPage: 1,
  272. shoppingCartGoods: [],
  273. shoppingCartLoading: false,
  274. visibleShoppingCart: false,
  275. loading: false,
  276. goods: [],
  277. payList: [],
  278. cashCurrency: '',
  279. currency: {},
  280. pointsSum: 0,
  281. cashSum: 0,
  282. pointFreight: 0,
  283. freeShipping: '',
  284. goodsId: '',
  285. goodsNum: '',
  286. payPassword: '',
  287. submitButtonStat: false,
  288. sn: '',
  289. orderType: '',
  290. payDialog: false,
  291. countdown: 5,
  292. visible: false,
  293. totalAmount: 0.00,
  294. freight: 0.00,
  295. userBalance: {},
  296. payType: 'cash',
  297. payStackLoading: false,
  298. channels: ['card', 'bank', 'ussd', 'qr'],
  299. form: {
  300. publicKey: process.env.VUE_APP_BASE_PAY_STACK_PUBLIC_KEY,
  301. currency: 'NGN',
  302. firstname: usersInfo.userName(),
  303. lastname: '',
  304. email: usersInfo.userEmail(),
  305. amount: 0,
  306. orderSn: '',
  307. metadata: {
  308. cart_id: '',
  309. custom_fields: [
  310. {
  311. display_name: 'orderSn',
  312. variable_name: 'orderSn',
  313. value: this.sn
  314. },
  315. {
  316. display_name: 'orderType',
  317. variable_name: 'orderType',
  318. value: 'userOrder'
  319. }
  320. ]
  321. },
  322. },
  323. payStackScreenWidth: getScreenWidth() > 500 ? '450px' : getScreenWidth() + 'px',
  324. addressId: '',
  325. selfPickUpAddressId: '100000000000000000',
  326. shippingAddressList: [],
  327. screenWidth: getScreenWidth() > 600 ? '50%' : getScreenWidth() + 'px',
  328. labelPosition: getScreenWidth() > 600 ? 'right' : 'top',
  329. dialog: false,
  330. dialogLoading: false,
  331. visibleProduct: false,
  332. product: {
  333. GOODS_NAME: '',
  334. GOODS_NO: '',
  335. COVER: '',
  336. SELL_PRICE: 0,
  337. PRICE_PV: 0,
  338. TAX_RATE: 0,
  339. taxAmount: 0
  340. },
  341. imageStyle: 'margin-top: -50px;',
  342. recRealName:null,
  343. // recUserName:usersInfo.userName(),
  344. recUserName:null,
  345. isDec:null,
  346. currencyUnitCode: ""
  347. }
  348. },
  349. computed: {
  350. // PayStack混淆串
  351. reference() {
  352. let text = ''
  353. const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
  354. for (let i = 0; i < 10; i++) {
  355. text += possible.charAt(Math.floor(Math.random() * possible.length))
  356. }
  357. return text
  358. }
  359. },
  360. watch: {
  361. isDec: {
  362. handler(newValue, old) {
  363. if (newValue == '1') {
  364. this.recUserName = usersInfo.userName();
  365. }
  366. },
  367. }
  368. },
  369. created() {
  370. this.getList()
  371. },
  372. mounted() {
  373. // 支付方式、账户信息、余额
  374. this.getShoppingCart()
  375. },
  376. methods: {
  377. // 商品列表
  378. getList() {
  379. this.listLoading = true
  380. fetchProductList(this.listQuery).then(response => {
  381. this.list = response.data.list
  382. this.total = response.data.totalCount
  383. setTimeout(() => {
  384. this.listLoading = false
  385. }, 1.5 * 1000)
  386. const settingObj = this.list
  387. for (const i in this.list) {
  388. this.storeNums[i] = 1
  389. settingObj[i].chose_num = 0
  390. }
  391. this.tableData = Object.values(settingObj)
  392. const pageList = this.multipleSelection[this.currentPage]
  393. this.$nextTick(function() {
  394. for (const i in this.tableData) {
  395. for (const j in pageList) {
  396. if (pageList[j].ID === this.tableData[i].ID) {
  397. this.$data.storeNums[i] = pageList[j].chose_num
  398. this.tableData[i].chose_num = pageList[j].chose_num
  399. break
  400. }
  401. }
  402. }
  403. })
  404. })
  405. },
  406. // 选择商品计数
  407. handleInputNumber(current, row) {
  408. const pageList = this.multipleSelection[this.listQuery.page]
  409. let selectStatus = false
  410. for (const i in pageList) {
  411. if (pageList[i].ID === row.ID) {
  412. pageList[i].chose_num = current
  413. selectStatus = true
  414. break
  415. }
  416. }
  417. if (selectStatus) {
  418. this.multipleSelection[this.listQuery.page] = pageList
  419. this.handleSureChange()
  420. }
  421. },
  422. // 统计商品
  423. handleSureChange() {
  424. if (this.multipleSelection.length > 0) {
  425. let accumulatorSellPrice = 0; let accumulatorPricePv = 0; let accumulatorTax = 0
  426. this.multipleSelection.forEach(item => {
  427. item.forEach(accumulator => { accumulatorSellPrice += accumulator.SELL_PRICE * accumulator.chose_num * accumulator.DISCOUNT / 100 })
  428. item.forEach(accumulator => { accumulatorPricePv += Number(accumulator.PRICE_PV) * Number(accumulator.chose_num) * (Number(accumulator.DISCOUNT) / 100) })
  429. item.forEach(accumulator => { accumulatorTax += tool.calculateTax(Number(accumulator.SELL_PRICE), Number(accumulator.TAX_RATE), Number(accumulator.chose_num)) })
  430. })
  431. this.sellPriceSum = tool.formatPrice(accumulatorSellPrice)
  432. this.pricePvSum = tool.formatPrice(accumulatorPricePv)
  433. this.taxSum = tool.formatPrice(accumulatorTax)
  434. this.display = true
  435. } else {
  436. this.sellPriceSum = this.pricePvSum = this.taxSum = 0.00
  437. this.display = true
  438. }
  439. },
  440. // 选择商品
  441. handleSelectionChange(val) {
  442. let idx = -1; let num
  443. for (const i in this.tableData) {
  444. for (const v in val) {
  445. if (val[v].ID === this.tableData[i].ID) {
  446. idx = i
  447. num = this.storeNums[idx]
  448. val[v]['chose_num'] = num
  449. break
  450. }
  451. }
  452. }
  453. this.multipleSelection[this.listQuery.page] = val
  454. // 计算统计
  455. this.handleSureChange()
  456. },
  457. // 结算商品
  458. settlement() {
  459. if (this.multipleSelection.length <= 0) {
  460. this.$message.error(this.$t('shop.chooseTips'))
  461. return false
  462. }
  463. // 弹出购物车
  464. this.visibleShoppingCart = true
  465. // 展示购物车商品数据
  466. this.getShowCart()
  467. },
  468. // 设置运费
  469. setFreight() {
  470. // 如果地址为自提,则运费为0
  471. this.pointFreight = (this.addressId === this.selfPickUpAddressId) ? Number(0) : Number(this.freight)
  472. },
  473. // 表格合并
  474. getSummaries(param) {
  475. const { columns, data } = param
  476. const sums = []
  477. columns.forEach((column, index) => {
  478. if (index === 0) {
  479. sums[index] = this.$t('shop.total')
  480. return
  481. }
  482. const values = data.map(item => Number(item[column.property]))
  483. if ((!values.every(value => isNaN(value))) && [2, 3, 4, 6].includes(index)) {
  484. sums[index] = values.reduce((prev, curr) => {
  485. const value = Number(curr)
  486. if (!isNaN(value)) {
  487. return Math.round((prev + curr) * 100) / 100
  488. } else {
  489. return Math.round(prev * 100) / 100
  490. }
  491. }, 0)
  492. if (index !== 2) {
  493. sums[index] = sums[index]
  494. }
  495. }
  496. })
  497. return sums
  498. },
  499. // 支付方式、账户信息、余额
  500. getShoppingCart() {
  501. fetchShoppingCart({ categoryType: this.listQuery.categoryType }).then(response => {
  502. // 收货地址
  503. this.shippingAddressList = response.data.allAddress
  504. this.shippingAddressList.map(item => {
  505. if (item.IS_DEFAULT === '1') {
  506. this.addressId = item.ID
  507. }
  508. })
  509. // 账户
  510. this.userBalance = response.data.userBalance
  511. // 支付方式处理
  512. this.currency = response.data.payList
  513. this.cashCurrency = response.data.payList[this.payType].name
  514. // 支付方式
  515. for (const item of response.data.sellType) {
  516. if (item.id === this.listQuery.categoryType) {
  517. this.payList = item.sell_type
  518. break
  519. }
  520. }
  521. // 支付方式的第一项默认选中
  522. this.payType = Object.values(this.payList)[0]['label']
  523. // 免运费阈值
  524. this.freeShipping = response.data.freeShipping
  525. // 运费
  526. this.freight = response.data.freight
  527. //是否是报单中心
  528. this.isDec = response.data.isDec
  529. //货币单位
  530. this.currencyUnitCode = response.data.coin
  531. })
  532. },
  533. // 支付
  534. orderSubmit() {
  535. // 账户余额
  536. const amountBalance = this.userBalance[this.payType]
  537. // 账户类型提示信息
  538. let accountType = this.currency[this.payType].name
  539. // if (amountBalance < 0 || !accountType) {
  540. // this.$message({
  541. // message: this.$t('shop.paymentError'),
  542. // type: 'error'
  543. // })
  544. // return false
  545. // }
  546. // 支付方式处理
  547. if (['cash', 'pay_stack'].includes(this.payType)) {
  548. const payObj = this.payList.find((item) => {
  549. return item.label === this.payType
  550. })
  551. accountType = (payObj.length <= 0) ? '' : payObj.name
  552. }
  553. // 余额是否充足
  554. if ((this.payType !== 'pay_stack') && ((amountBalance - this.cashSum) < 0)) {
  555. this.$message({
  556. message: accountType + this.$t('shop.balanceNotAllow'),
  557. type: 'error'
  558. })
  559. this.submitButtonStat = false
  560. return false
  561. }
  562. this.submitButtonStat = true
  563. this.$prompt(this.$t('shop.inputPasswordTips'), this.$t('common.hint'), {
  564. confirmButtonText: this.$t('common.confirm'),
  565. cancelButtonText: this.$t('common.cancel'),
  566. customClass: 'csClass',
  567. type: 'info',
  568. inputType: 'password',
  569. inputPattern: /\S+/,
  570. inputErrorMessage: this.$t('shop.inputPasswordTips')
  571. }).then(({ value }) => {
  572. this.payPassword = value
  573. const params = {
  574. goodsId: this.goodsId,
  575. goodsNum: this.goodsNum,
  576. payPassword: this.payPassword,
  577. email: this.form.email,
  578. addressId: this.addressId,
  579. address: this.address,
  580. payType: this.payType,
  581. userName:this.recUserName
  582. }
  583. if (this.payType === 'pay_stack') {
  584. // PayStack支付
  585. createApproachOrder(params).then(response => {
  586. this.visibleShoppingCart = false
  587. this.submitButtonStat = false
  588. this.visible = true
  589. this.form.orderSn = response.data.SN
  590. this.form.amount = this.cashSum
  591. this.form.metadata.cart_id = response.data.SN
  592. this.form.metadata.custom_fields[0].value = response.data.SN
  593. }).catch(err => {
  594. this.$message({
  595. message: err,
  596. type: 'error',
  597. duration: 5 * 1000
  598. })
  599. this.submitButtonStat = false
  600. })
  601. } else {
  602. // 非PayStack支付
  603. createOrder(params).then(() => {
  604. this.submitButtonStat = false
  605. this.$message({
  606. message: this.$t('common.successfully'),
  607. type: 'success',
  608. duration: 5 * 1000
  609. })
  610. this.$router.push({ path: `/shop/own-order` })
  611. }).catch(err => {
  612. this.$message({
  613. message: err,
  614. type: 'warning',
  615. duration: 5 * 1000
  616. })
  617. this.submitButtonStat = false
  618. })
  619. }
  620. }).catch(() => {
  621. this.submitButtonStat = false
  622. })
  623. },
  624. // 计算价格
  625. getSumMoney() {
  626. const cash_plus_sum = []
  627. const goodsId = []
  628. const goodsNum = []
  629. let choseNum = 0
  630. this.goods.map(item => {
  631. choseNum = Number(item.chose_num)
  632. if (choseNum > 0) {
  633. cash_plus_sum.push(item.SELL_PRICE * choseNum * (item.DISCOUNT / 100))
  634. goodsId.push(item.ID)
  635. goodsNum.push(choseNum)
  636. }
  637. })
  638. this.goodsNum = goodsNum
  639. this.goodsId = goodsId
  640. // 增加运费
  641. const payAmount = tool.sum(cash_plus_sum)
  642. // 设置运费
  643. this.setFreight()
  644. // 商品总价大于预定值,免运费
  645. this.pointFreight = (this.pointFreight > 0) ? ((payAmount >= this.freeShipping) ? 0 : this.freight) : 0
  646. // 计算总价
  647. this.pointsSum = this.cashSum = this.form.amount = tool.formatPrice(tool.sum(cash_plus_sum) + this.pointFreight)
  648. },
  649. // 展示购物车信息
  650. getShowCart() {
  651. const orderGoods = this.multipleSelection
  652. let cartGoods = []
  653. for (const i in orderGoods) {
  654. cartGoods = orderGoods[i]
  655. if (!cartGoods) continue
  656. cartGoods.map(item => {
  657. if (Number(item.chose_num) > 0) {
  658. const discount = item.DISCOUNT / 100
  659. item.member_price = Math.round(item.SELL_PRICE * discount * 100) / 100
  660. item.member_price_plus = Math.round(item.SELL_PRICE * Number(item.chose_num) * discount * 100) / 100
  661. item.tax_amount_plus = Math.round((item.member_price - item.member_price / (1 + item.TAX_RATE / 100)) * item.chose_num * 100) / 100
  662. this.goods.push(item)
  663. this.totalAmount += item.member_price_plus
  664. }
  665. })
  666. }
  667. this.goods = cartGoods
  668. // 计算价格
  669. this.getSumMoney()
  670. },
  671. // 关闭时清空购物车等信息
  672. cleanShowCart() {
  673. this.visibleShoppingCart = false
  674. this.goods = []
  675. this.totalAmount = 0.00
  676. this.goodsNum = ''
  677. this.goodsId = ''
  678. this.pointFreight = 0
  679. this.pointsSum = 0
  680. },
  681. // 选择收货地址
  682. choseAddress(addressId) {
  683. this.addressId = addressId
  684. // 设置运费
  685. this.setFreight()
  686. // 计算价格
  687. this.getSumMoney()
  688. },
  689. // 切换支付方式
  690. chosePayType(type) {
  691. this.payType = type
  692. },
  693. // 关闭支付回调
  694. handleClose() {
  695. this.$confirm(this.$t('shop.confirmClose')).then(_ => {
  696. deleteApproachOrder({ orderSn: this.form.orderSn }).then(() => {
  697. // 关闭支付模态框
  698. this.visible = false
  699. // 关闭购物车
  700. this.visibleShoppingCart = false
  701. this.submitButtonStat = false
  702. })
  703. })
  704. },
  705. // 支付成功回调
  706. processPayment() {
  707. // 关闭支付页面
  708. this.visible = false
  709. this.payStackLoading = false
  710. // 显示支付成功模态框
  711. this.payDialog = true
  712. // 启动支付成功倒计时
  713. this.handleCountdown()
  714. },
  715. // 倒计时结束跳转
  716. handleOrderList() {
  717. this.$router.push({ path: `/shop/own-order` })
  718. },
  719. // 启动倒计时
  720. handleCountdown() {
  721. // 创建定时器
  722. setInterval(() => {
  723. // 每隔1秒把time的值减一,赋值给span标签
  724. this.countdown--
  725. if (this.countdown === 0) {
  726. // 倒计时结束,跳转到订单列表
  727. this.$router.push({ path: `/shop/own-order` })
  728. }
  729. }, 1000)
  730. },
  731. // 商品详情
  732. handleProduct(row) {
  733. this.product = row
  734. this.product.taxAmount = tool.calculateTax(row.SELL_PRICE, row.TAX_RATE)
  735. this.visibleProduct = true
  736. }
  737. }
  738. }
  739. </script>
  740. <style>
  741. .el-table--medium .el-table__cell {
  742. padding: 3px 0;
  743. }
  744. .csClass{
  745. width: 360px;
  746. }
  747. .address{
  748. line-height: 2.5rem;
  749. }
  750. .address_box{
  751. border-bottom: 1px solid #e3e3e3;
  752. }
  753. .sum{
  754. display: inline-block;
  755. }
  756. .box{
  757. margin: 1rem 0;
  758. display: flex;
  759. justify-content: flex-start;
  760. align-items: center;
  761. padding-bottom: 1rem;
  762. }
  763. .sum_box{
  764. display: flex;
  765. margin-left: 1rem;
  766. }
  767. .sum_box > div{
  768. line-height: 2rem;
  769. }
  770. .sum_box > div:nth-child(1){
  771. margin-right: 1rem;
  772. }
  773. .payButton {
  774. border: none;
  775. padding: 0;
  776. }
  777. </style>