member-auto-maintenance.vue 34 KB

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