reconsume.vue 33 KB

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