standard-products.vue 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825
  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 :rules="rules" ref="payForm" :model="payForm">
  105. <el-form-item :label="$t('shop.declarationCenterNumber')" prop="recUserName">
  106. <el-input v-model="payForm.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. rules: {
  348. recUserName: [
  349. {required: true, message: this.$t('shop.declarationCenterNumberTips'), trigger: 'blur'},
  350. ],
  351. },
  352. payForm: {
  353. recUserName: null
  354. }
  355. }
  356. },
  357. computed: {
  358. // PayStack混淆串
  359. reference() {
  360. let text = ''
  361. const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
  362. for (let i = 0; i < 10; i++) {
  363. text += possible.charAt(Math.floor(Math.random() * possible.length))
  364. }
  365. return text
  366. }
  367. },
  368. watch: {
  369. isDec: {
  370. handler(newValue, old) {
  371. if (newValue == '1') {
  372. this.payForm.recUserName = usersInfo.userName();
  373. }
  374. },
  375. }
  376. },
  377. created() {
  378. this.getList()
  379. },
  380. mounted() {
  381. // 支付方式、账户信息、余额
  382. this.getShoppingCart()
  383. },
  384. methods: {
  385. // 商品列表
  386. getList() {
  387. this.listLoading = true
  388. fetchProductList(this.listQuery).then(response => {
  389. this.list = response.data.list
  390. this.total = response.data.totalCount
  391. setTimeout(() => {
  392. this.listLoading = false
  393. }, 1.5 * 1000)
  394. const settingObj = this.list
  395. for (const i in this.list) {
  396. this.storeNums[i] = 1
  397. settingObj[i].chose_num = 0
  398. }
  399. this.tableData = Object.values(settingObj)
  400. const pageList = this.multipleSelection[this.currentPage]
  401. this.$nextTick(function() {
  402. for (const i in this.tableData) {
  403. for (const j in pageList) {
  404. if (pageList[j].ID === this.tableData[i].ID) {
  405. this.$data.storeNums[i] = pageList[j].chose_num
  406. this.tableData[i].chose_num = pageList[j].chose_num
  407. break
  408. }
  409. }
  410. }
  411. })
  412. })
  413. },
  414. // 选择商品计数
  415. handleInputNumber(current, row) {
  416. const pageList = this.multipleSelection[this.listQuery.page]
  417. let selectStatus = false
  418. for (const i in pageList) {
  419. if (pageList[i].ID === row.ID) {
  420. pageList[i].chose_num = current
  421. selectStatus = true
  422. break
  423. }
  424. }
  425. if (selectStatus) {
  426. this.multipleSelection[this.listQuery.page] = pageList
  427. this.handleSureChange()
  428. }
  429. },
  430. // 统计商品
  431. handleSureChange() {
  432. if (this.multipleSelection.length > 0) {
  433. let accumulatorSellPrice = 0; let accumulatorPricePv = 0; let accumulatorTax = 0
  434. this.multipleSelection.forEach(item => {
  435. item.forEach(accumulator => { accumulatorSellPrice += accumulator.SELL_PRICE * accumulator.chose_num * accumulator.DISCOUNT / 100 })
  436. item.forEach(accumulator => { accumulatorPricePv += Number(accumulator.PRICE_PV) * Number(accumulator.chose_num) * (Number(accumulator.DISCOUNT) / 100) })
  437. item.forEach(accumulator => { accumulatorTax += tool.calculateTax(Number(accumulator.SELL_PRICE), Number(accumulator.TAX_RATE), Number(accumulator.chose_num)) })
  438. })
  439. this.sellPriceSum = tool.formatPrice(accumulatorSellPrice)
  440. this.pricePvSum = tool.formatPrice(accumulatorPricePv)
  441. this.taxSum = tool.formatPrice(accumulatorTax)
  442. this.display = true
  443. } else {
  444. this.sellPriceSum = this.pricePvSum = this.taxSum = 0.00
  445. this.display = true
  446. }
  447. },
  448. // 选择商品
  449. handleSelectionChange(val) {
  450. let idx = -1; let num
  451. for (const i in this.tableData) {
  452. for (const v in val) {
  453. if (val[v].ID === this.tableData[i].ID) {
  454. idx = i
  455. num = this.storeNums[idx]
  456. val[v]['chose_num'] = num
  457. break
  458. }
  459. }
  460. }
  461. this.multipleSelection[this.listQuery.page] = val
  462. // 计算统计
  463. this.handleSureChange()
  464. },
  465. // 结算商品
  466. settlement() {
  467. if (this.multipleSelection.length <= 0) {
  468. this.$message.error(this.$t('shop.chooseTips'))
  469. return false
  470. }
  471. // 弹出购物车
  472. this.visibleShoppingCart = true
  473. // 展示购物车商品数据
  474. this.getShowCart()
  475. },
  476. // 设置运费
  477. setFreight() {
  478. // 如果地址为自提,则运费为0
  479. this.pointFreight = (this.addressId === this.selfPickUpAddressId) ? Number(0) : Number(this.freight)
  480. },
  481. // 表格合并
  482. getSummaries(param) {
  483. const { columns, data } = param
  484. const sums = []
  485. columns.forEach((column, index) => {
  486. if (index === 0) {
  487. sums[index] = this.$t('shop.total')
  488. return
  489. }
  490. const values = data.map(item => Number(item[column.property]))
  491. if ((!values.every(value => isNaN(value))) && [2, 3, 4, 6].includes(index)) {
  492. sums[index] = values.reduce((prev, curr) => {
  493. const value = Number(curr)
  494. if (!isNaN(value)) {
  495. return Math.round((prev + curr) * 100) / 100
  496. } else {
  497. return Math.round(prev * 100) / 100
  498. }
  499. }, 0)
  500. if (index !== 2) {
  501. sums[index] = sums[index]
  502. }
  503. }
  504. })
  505. return sums
  506. },
  507. // 支付方式、账户信息、余额
  508. getShoppingCart() {
  509. fetchShoppingCart({ categoryType: this.listQuery.categoryType }).then(response => {
  510. // 收货地址
  511. this.shippingAddressList = response.data.allAddress
  512. this.shippingAddressList.map(item => {
  513. if (item.IS_DEFAULT === '1') {
  514. this.addressId = item.ID
  515. }
  516. })
  517. // 账户
  518. this.userBalance = response.data.userBalance
  519. // 支付方式处理
  520. this.currency = response.data.payList
  521. this.cashCurrency = response.data.payList[this.payType].name
  522. // 支付方式
  523. for (const item of response.data.sellType) {
  524. if (item.id === this.listQuery.categoryType) {
  525. this.payList = item.sell_type
  526. break
  527. }
  528. }
  529. // 支付方式的第一项默认选中
  530. this.payType = Object.values(this.payList)[0]['label']
  531. // 免运费阈值
  532. this.freeShipping = response.data.freeShipping
  533. // 运费
  534. this.freight = response.data.freight
  535. //是否是报单中心
  536. this.isDec = response.data.isDec
  537. //货币单位
  538. this.currencyUnitCode = response.data.coin
  539. })
  540. },
  541. // 支付
  542. orderSubmit() {
  543. this.$refs['payForm'].validate((valid) => {
  544. if (valid) {
  545. // 账户余额
  546. const amountBalance = this.userBalance[this.payType]
  547. // 账户类型提示信息
  548. let accountType = this.currency[this.payType].name
  549. // if (amountBalance < 0 || !accountType) {
  550. // this.$message({
  551. // message: this.$t('shop.paymentError'),
  552. // type: 'error'
  553. // })
  554. // return false
  555. // }
  556. // 支付方式处理
  557. if (['cash', 'pay_stack'].includes(this.payType)) {
  558. const payObj = this.payList.find((item) => {
  559. return item.label === this.payType
  560. })
  561. accountType = (payObj.length <= 0) ? '' : payObj.name
  562. }
  563. // 余额是否充足
  564. if ((this.payType !== 'pay_stack') && ((amountBalance - this.cashSum) < 0)) {
  565. this.$message({
  566. message: accountType + this.$t('shop.balanceNotAllow'),
  567. type: 'error'
  568. })
  569. this.submitButtonStat = false
  570. return false
  571. }
  572. this.submitButtonStat = true
  573. this.$prompt(this.$t('shop.inputPasswordTips'), this.$t('common.hint'), {
  574. confirmButtonText: this.$t('common.confirm'),
  575. cancelButtonText: this.$t('common.cancel'),
  576. customClass: 'csClass',
  577. type: 'info',
  578. inputType: 'password',
  579. inputPattern: /\S+/,
  580. inputErrorMessage: this.$t('shop.inputPasswordTips')
  581. }).then(({value}) => {
  582. this.payPassword = value
  583. const params = {
  584. goodsId: this.goodsId,
  585. goodsNum: this.goodsNum,
  586. payPassword: this.payPassword,
  587. email: this.form.email,
  588. addressId: this.addressId,
  589. address: this.address,
  590. payType: this.payType,
  591. userName: this.payForm.recUserName
  592. }
  593. if (this.payType === 'pay_stack') {
  594. // PayStack支付
  595. createApproachOrder(params).then(response => {
  596. this.visibleShoppingCart = false
  597. this.submitButtonStat = false
  598. this.visible = true
  599. this.form.orderSn = response.data.SN
  600. this.form.amount = this.cashSum
  601. this.form.metadata.cart_id = response.data.SN
  602. this.form.metadata.custom_fields[0].value = response.data.SN
  603. }).catch(err => {
  604. this.$message({
  605. message: err,
  606. type: 'error',
  607. duration: 5 * 1000
  608. })
  609. this.submitButtonStat = false
  610. })
  611. } else {
  612. // 非PayStack支付
  613. createOrder(params).then(() => {
  614. this.submitButtonStat = false
  615. this.$message({
  616. message: this.$t('common.successfully'),
  617. type: 'success',
  618. duration: 5 * 1000
  619. })
  620. this.$router.push({path: `/shop/own-order`})
  621. }).catch(err => {
  622. this.$message({
  623. message: err,
  624. type: 'warning',
  625. duration: 5 * 1000
  626. })
  627. this.submitButtonStat = false
  628. })
  629. }
  630. }).catch(() => {
  631. this.submitButtonStat = false
  632. })
  633. } else {
  634. console.log('error submit!!');
  635. return false;
  636. }
  637. });
  638. },
  639. // 计算价格
  640. getSumMoney() {
  641. const cash_plus_sum = []
  642. const goodsId = []
  643. const goodsNum = []
  644. let choseNum = 0
  645. this.goods.map(item => {
  646. choseNum = Number(item.chose_num)
  647. if (choseNum > 0) {
  648. cash_plus_sum.push(item.SELL_PRICE * choseNum * (item.DISCOUNT / 100))
  649. goodsId.push(item.ID)
  650. goodsNum.push(choseNum)
  651. }
  652. })
  653. this.goodsNum = goodsNum
  654. this.goodsId = goodsId
  655. // 增加运费
  656. const payAmount = tool.sum(cash_plus_sum)
  657. // 设置运费
  658. this.setFreight()
  659. // 商品总价大于预定值,免运费
  660. this.pointFreight = (this.pointFreight > 0) ? ((payAmount >= this.freeShipping) ? 0 : this.freight) : 0
  661. // 计算总价
  662. this.pointsSum = this.cashSum = this.form.amount = tool.formatPrice(tool.sum(cash_plus_sum) + this.pointFreight)
  663. },
  664. // 展示购物车信息
  665. getShowCart() {
  666. const orderGoods = this.multipleSelection
  667. let cartGoods = []
  668. for (const i in orderGoods) {
  669. cartGoods = orderGoods[i]
  670. if (!cartGoods) continue
  671. cartGoods.map(item => {
  672. if (Number(item.chose_num) > 0) {
  673. const discount = item.DISCOUNT / 100
  674. item.member_price = Math.round(item.SELL_PRICE * discount * 100) / 100
  675. item.member_price_plus = Math.round(item.SELL_PRICE * Number(item.chose_num) * discount * 100) / 100
  676. item.tax_amount_plus = Math.round((item.member_price - item.member_price / (1 + item.TAX_RATE / 100)) * item.chose_num * 100) / 100
  677. this.goods.push(item)
  678. this.totalAmount += item.member_price_plus
  679. }
  680. })
  681. }
  682. this.goods = cartGoods
  683. // 计算价格
  684. this.getSumMoney()
  685. },
  686. // 关闭时清空购物车等信息
  687. cleanShowCart() {
  688. this.visibleShoppingCart = false
  689. this.goods = []
  690. this.totalAmount = 0.00
  691. this.goodsNum = ''
  692. this.goodsId = ''
  693. this.pointFreight = 0
  694. this.pointsSum = 0
  695. },
  696. // 选择收货地址
  697. choseAddress(addressId) {
  698. this.addressId = addressId
  699. // 设置运费
  700. this.setFreight()
  701. // 计算价格
  702. this.getSumMoney()
  703. },
  704. // 切换支付方式
  705. chosePayType(type) {
  706. this.payType = type
  707. },
  708. // 关闭支付回调
  709. handleClose() {
  710. this.$confirm(this.$t('shop.confirmClose')).then(_ => {
  711. deleteApproachOrder({ orderSn: this.form.orderSn }).then(() => {
  712. // 关闭支付模态框
  713. this.visible = false
  714. // 关闭购物车
  715. this.visibleShoppingCart = false
  716. this.submitButtonStat = false
  717. })
  718. })
  719. },
  720. // 支付成功回调
  721. processPayment() {
  722. // 关闭支付页面
  723. this.visible = false
  724. this.payStackLoading = false
  725. // 显示支付成功模态框
  726. this.payDialog = true
  727. // 启动支付成功倒计时
  728. this.handleCountdown()
  729. },
  730. // 倒计时结束跳转
  731. handleOrderList() {
  732. this.$router.push({ path: `/shop/own-order` })
  733. },
  734. // 启动倒计时
  735. handleCountdown() {
  736. // 创建定时器
  737. setInterval(() => {
  738. // 每隔1秒把time的值减一,赋值给span标签
  739. this.countdown--
  740. if (this.countdown === 0) {
  741. // 倒计时结束,跳转到订单列表
  742. this.$router.push({ path: `/shop/own-order` })
  743. }
  744. }, 1000)
  745. },
  746. // 商品详情
  747. handleProduct(row) {
  748. this.product = row
  749. this.product.taxAmount = tool.calculateTax(row.SELL_PRICE, row.TAX_RATE)
  750. this.visibleProduct = true
  751. }
  752. }
  753. }
  754. </script>
  755. <style>
  756. .el-table--medium .el-table__cell {
  757. padding: 3px 0;
  758. }
  759. .csClass{
  760. width: 360px;
  761. }
  762. .address{
  763. line-height: 2.5rem;
  764. }
  765. .address_box{
  766. border-bottom: 1px solid #e3e3e3;
  767. }
  768. .sum{
  769. display: inline-block;
  770. }
  771. .box{
  772. margin: 1rem 0;
  773. display: flex;
  774. justify-content: flex-start;
  775. align-items: center;
  776. padding-bottom: 1rem;
  777. }
  778. .sum_box{
  779. display: flex;
  780. margin-left: 1rem;
  781. }
  782. .sum_box > div{
  783. line-height: 2rem;
  784. }
  785. .sum_box > div:nth-child(1){
  786. margin-right: 1rem;
  787. }
  788. .payButton {
  789. border: none;
  790. padding: 0;
  791. }
  792. </style>