order.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. <template>
  2. <div>
  3. <div v-loading="loading">
  4. <div class="white-box">
  5. <div class="table">
  6. <el-table
  7. :data="goods"
  8. style="width: 100%"
  9. show-summary
  10. :summary-method="getSummaries">
  11. <el-table-column label="Product Name" prop="GOODS_NAME"><!--商品名称-->
  12. </el-table-column>
  13. <el-table-column label="Product Picture" ><!--图片-->
  14. <template slot-scope="scope">
  15. <el-image style="width: 100px; height: 100px" :src="tool.getArImage(scope.row.COVER, '/files/')" :preview-src-list="[tool.getArImage(scope.row.COVER, '/files/')]"></el-image>
  16. </template>
  17. </el-table-column>
  18. <el-table-column label="Product price" prop="member_price"><!--商品价格-->
  19. <template slot-scope="scope">
  20. <span>{{ Math.round(scope.row.member_price * 100) / 100 }}</span>
  21. </template>
  22. </el-table-column>
  23. <el-table-column label="Member BV" prop="member_pv" v-if="category_type === 1"><!--会员PV-->
  24. <template slot-scope="scope">
  25. <span>{{ Math.round(scope.row.member_pv * 100) / 100 }}</span>
  26. </template>
  27. </el-table-column>
  28. <el-table-column label="Tax rate" prop="TAX_RATE"><!--税率-->
  29. <template slot-scope="scope">
  30. <span>{{ Math.round(scope.row.TAX_RATE * 100) / 100 }}</span>
  31. </template>
  32. </el-table-column>
  33. <el-table-column label="Tax" prop="tax_amount_plus"><!--税额-->
  34. <template slot-scope="scope">
  35. <span>{{ Math.round(scope.row.tax_amount_plus * 100) / 100 }}</span>
  36. </template>
  37. </el-table-column>
  38. <!-- <el-table-column label="库存" prop="STORE_NUMS">-->
  39. <!-- </el-table-column>-->
  40. <el-table-column label="Quantity" prop="chose_num"><!--数量-->
  41. </el-table-column>
  42. <el-table-column label="Total Amount" prop="member_price_plus"><!--合计金额-->
  43. <template slot-scope="scope">
  44. <span>{{ Math.round(scope.row.member_price_plus * 100) / 100 }}</span>
  45. </template>
  46. </el-table-column>
  47. <el-table-column label="Total BV" prop="member_pv_plus" v-if="category_type === 1"><!--合计PV-->
  48. <template slot-scope="scope">
  49. <span>{{ Math.round(scope.row.member_pv_plus * 100) / 100 }}</span>
  50. </template>
  51. </el-table-column>
  52. </el-table>
  53. </div>
  54. <div class="address_box">
  55. Please select the shipping address: <!-- 请选择收货地址 -->
  56. <el-radio-group v-model="addressId" @change='choseAddress'>
  57. <div v-for="(item , index) in all_address" :key='index' class="address">
  58. <el-radio :label="item.ID" >
  59. Full address:{{item.ADDRESS}}, {{item.CITY_NAME}}, {{item.LGA_NAME}}, {{item.PROVINCE_NAME}} &nbsp;&nbsp;&nbsp;&nbsp;
  60. <!-- 详细地址 --> &nbsp;&nbsp;
  61. <!-- 收件人姓名 --> Recipient name:{{item.CONSIGNEE}}&nbsp;&nbsp;&nbsp;&nbsp;
  62. <!-- 手机号码 --> Phone Number:{{item.MOBILE}}
  63. </el-radio>
  64. </div>
  65. <div class="address">
  66. <el-radio label="100000000000000000">Self Pick-up</el-radio><!--自提-->
  67. </div>
  68. </el-radio-group>
  69. </div>
  70. <div class="address_box">
  71. Please select payment method:<!-- 请选择支付方式 -->
  72. <el-radio-group v-model="payType" @change='chosePayType'>
  73. <div v-for="(item, index) in payList" :key='index' class="address">
  74. <el-radio :label="item.label">{{ item.name }}</el-radio>
  75. </div>
  76. </el-radio-group>
  77. </div>
  78. <div class="box address_box">
  79. Total orders:<!-- 订单合计 -->
  80. <div class="sum">
  81. <div class="sum_box" v-if="category_type === 1">
  82. <div>Freight</div><!-- 运费 -->
  83. <div>
  84. <span v-if="category_type === 1">{{ prefixSign }}</span>
  85. {{ pointFreight }}
  86. <span v-if="category_type === 1">{{ unit }}</span>
  87. </div>
  88. </div>
  89. <div class="sum_box">
  90. <div>Amount paid</div><!-- 实付金额 -->
  91. <div>
  92. <span v-if="category_type === 1">{{ prefixSign }}</span>
  93. {{ payType === "cash" ? cashSum : pointsSum }}
  94. <span v-if="category_type === 1">{{ unit }}</span>
  95. </div>
  96. </div>
  97. </div>
  98. </div>
  99. <div class="box address_box">
  100. Account Balance: <!-- 账户余额 -->
  101. <div class="sum">
  102. <div v-if="category_type === 1">
  103. <!-- <div class="sum_box">-->
  104. <!-- <div>账户积分</div>-->
  105. <!-- <div>{{ balance.points }}</div>-->
  106. <!-- </div>-->
  107. <div class="sum_box">
  108. <div>Account Balance</div><!-- 账户余额 -->
  109. <div>₦ {{ balance.cash }} NGN</div>
  110. </div>
  111. <!-- <div class="sum_box">-->
  112. <!-- <div>Exchange points</div>&lt;!&ndash; 兑换点数 &ndash;&gt;-->
  113. <!-- <div>{{ balance.exchange }}</div>-->
  114. <!-- </div>-->
  115. </div>
  116. <div v-if="category_type === 4">
  117. <div class="sum_box">
  118. <div>Travel bonus</div><!-- 旅游积分 -->
  119. <div>{{ balance.tourism_points }}</div>
  120. </div>
  121. </div>
  122. <div v-if="category_type === 5">
  123. <div class="sum_box">
  124. <div>Car bonus</div><!-- 名车积分 -->
  125. <div>{{ balance.garage_points }}</div>
  126. </div>
  127. </div>
  128. <div v-if="category_type === 6">
  129. <div class="sum_box">
  130. <div>Villa bonus</div><!-- 豪宅积分 -->
  131. <div>{{ balance.villa_points }}</div>
  132. </div>
  133. </div>
  134. </div>
  135. </div>
  136. <div>
  137. <el-button type="danger" @click="cancelOrder()">Go Back</el-button>
  138. <el-button type="primary" @click="goToAccounts()" :loading="submitButtonStat">Pay</el-button><!--去结算-->
  139. </div>
  140. </div>
  141. </div>
  142. <el-dialog title="Pay" v-if="visible" :visible.sync="visible" width="30%" v-loading="payStackLoading" :before-close="handleClose">
  143. <section>
  144. <!-- <h1>Lorem Ipsum Dolor Sit Amet</h1>-->
  145. <div class="formcontainer">
  146. <el-divider></el-divider>
  147. <div class="container">
  148. <el-form :model="form">
  149. <el-form-item label="Email" label-width="100px" required>
  150. <el-input v-model="form.email" autocomplete="off"></el-input>
  151. </el-form-item>
  152. <el-form-item label="Amount" label-width="100px" required>
  153. <el-input v-model="form.amount" autocomplete="off" readonly></el-input>
  154. </el-form-item>
  155. </el-form>
  156. </div>
  157. </div>
  158. </section>
  159. <paystack
  160. :firstname="form.firstname"
  161. :lastname="form.lastname"
  162. :amount="form.amount * 100"
  163. :email="form.email"
  164. :metadata="form.metadata"
  165. :currency="form.currency"
  166. :paystackkey="form.publicKey"
  167. :reference="reference"
  168. :channels="channels"
  169. :callback="processPayment"
  170. :close="processClose"
  171. >
  172. <el-button type="primary" size="small">Pay</el-button>
  173. </paystack>
  174. <el-button type="danger" size="small" class="cancelButton" @click="handleClose">Cancel</el-button>
  175. </el-dialog>
  176. <el-dialog title="Tips" :visible.sync="payDialog" :show-close="false" width="350px" :close="handleOrderList">
  177. <el-result icon="success" title="the order is successful">
  178. <template slot="extra">
  179. <span style="color: #008efa; font-size: 30px;">{{ countdown }}</span>
  180. </template>
  181. </el-result>
  182. </el-dialog>
  183. </div>
  184. </template>
  185. <script>
  186. import network from '@/utils/network'
  187. import tool from '@/utils/tool'
  188. import userInfo from '@/utils/userInfo'
  189. import { PAY_STACK_PUBLIC_KEY, PAY_STACK_CURRENCY } from '@/utils/config'
  190. import paystack from 'vue-paystack'
  191. export default{
  192. name: 'order',
  193. data: function () {
  194. return {
  195. tool: tool,
  196. loading: true,
  197. goods: [],
  198. payList: [],
  199. all_address: [],
  200. balance: {},
  201. addressId: '',
  202. payType: '',
  203. payTypeId: '',
  204. pointsSum: '',
  205. cashSum: '',
  206. freight: '',
  207. pointFreight: '',
  208. freeShipping: '',
  209. goodsId: '',
  210. goodsNum: '',
  211. payPassword: '',
  212. submitButtonStat: false,
  213. category_type: '',
  214. prefixSign: '₦',
  215. unit: 'NGN',
  216. sn: '',
  217. payDialog: false,
  218. countdown: 5,
  219. visible: false,
  220. payStackLoading: false,
  221. channels: ["card", "bank", "ussd", "qr"], // eft(南非) mobile_money(加纳)
  222. form: {
  223. publicKey: PAY_STACK_PUBLIC_KEY,
  224. currency: PAY_STACK_CURRENCY,
  225. firstname: userInfo.userName(),
  226. lastname: '',
  227. email: userInfo.userEmail(),
  228. amount: 0, // kobo
  229. orderSn: '',
  230. metadata: {
  231. cart_id: this.sn,
  232. custom_fields: [
  233. {
  234. display_name: 'orderSn',
  235. variable_name: 'orderSn',
  236. value: this.sn
  237. },
  238. ]
  239. },
  240. },
  241. }
  242. },
  243. components: {
  244. paystack
  245. },
  246. async created () {
  247. let option = sessionStorage.getItem('order_goods');
  248. this.category_type = parseInt(sessionStorage.getItem('category_type'))
  249. await this.getShowCart();
  250. if (option) {
  251. let pageGoodsList = JSON.parse(option);
  252. // console.log(pageGoodsList);
  253. let pageList;
  254. for (let i in pageGoodsList) {
  255. pageList = pageGoodsList[i];
  256. if (!pageList) continue;
  257. pageList.map((pageData, index) => {
  258. if (Number(pageData.chose_num) > 0) {
  259. let discount = pageData.DISCOUNT / 100;
  260. pageData.member_price = Math.round(pageData.SELL_PRICE * discount * 100) / 100;
  261. pageData.member_price_plus = Math.round(pageData.SELL_PRICE * Number(pageData.chose_num) * discount * 100) / 100;
  262. pageData.member_pv = Math.round(pageData.PRICE_PV * discount * 100) / 100;
  263. pageData.member_pv_plus = Math.round(pageData.PRICE_PV * Number(pageData.chose_num) * discount * 100) / 100;
  264. pageData.tax_amount_plus = Math.round((pageData.member_price - pageData.member_price / (1 + pageData.TAX_RATE / 100)) * pageData.chose_num * 100) / 100;
  265. this.goods.push(pageData)
  266. }
  267. })
  268. }
  269. await this.getSumMoney();
  270. }
  271. },
  272. computed: {
  273. reference () {
  274. let text = '';
  275. let possible =
  276. "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  277. for (let i = 0; i < 10; i++)
  278. text += possible.charAt(Math.floor(Math.random() * possible.length));
  279. return text;
  280. }
  281. },
  282. methods:{
  283. cancelOrder () {
  284. history.go(-1)
  285. },
  286. setFreight () {
  287. // 如果地址为自提,则运费为0
  288. if (this.addressId === '100000000000000000') {
  289. this.pointFreight = Number(0)
  290. } else {
  291. this.pointFreight = Number(this.freight)
  292. }
  293. },
  294. getSummaries (param) {
  295. const { columns, data } = param;
  296. const sums = [];
  297. columns.forEach((column, index) => {
  298. if (index === 0) {
  299. sums[index] = 'Total'; // 合计
  300. return;
  301. }
  302. const values = data.map(item => Number(item[column.property]));
  303. if ((!values.every(value => isNaN(value))) && [5, 6, 7, 8].includes(index)) {
  304. sums[index] = values.reduce((prev, curr) => {
  305. const value = Number(curr);
  306. if (!isNaN(value)) {
  307. return Math.round((prev + curr) * 100) / 100;
  308. } else {
  309. return Math.round(prev * 100) / 100;
  310. }
  311. }, 0);
  312. }
  313. });
  314. return sums;
  315. },
  316. goToAccounts () {
  317. let amountBalance = 0
  318. // 前置判断余额是否够支付
  319. if (this.category_type === 1) {
  320. if (this.payType === 'cash') {
  321. amountBalance = this.balance.cash
  322. } else if (this.payType === 'exchange') {
  323. amountBalance = this.balance.exchange
  324. }
  325. } else if (this.category_type === 4) {
  326. amountBalance = this.balance.tourism_points
  327. } else if (this.category_type === 5) {
  328. amountBalance = this.balance.garage_points
  329. }
  330. // 提示信息
  331. let tips = 'Ecoin' // 余额
  332. if (this.payType !== 'cash' && this.payType !== 'pay_stack') {
  333. let payObj = this.payList.find((item) => {
  334. return item.label === this.payType
  335. })
  336. tips = (payObj.length <= 0) ? '' : payObj.name
  337. }
  338. // 余额是否充足
  339. if ((amountBalance > 0) && (this.payType !== 'pay_stack') && ((amountBalance - this.cashSum) < 0)) {
  340. let tips = this.payList[this.payType] ? this.payList[this.payType].label : 'Ecoin'
  341. this.$message({
  342. message: tips + ' insufficient, unable to buy products', // 不足,无法购买商品
  343. type: 'error'
  344. })
  345. this.submitButtonStat = false
  346. return false
  347. }
  348. this.submitButtonStat = true
  349. // let path = 'sure-order'
  350. this.$prompt('Please enter your payment password', 'Hint', { // '请输入支付密码', '提示'
  351. confirmButtonText: 'Confirm', // 确定
  352. cancelButtonText: 'Cancel', // 取消
  353. inputType: 'password',
  354. inputPattern: /\S+/,
  355. inputErrorMessage: 'Please enter your payment password' // 请输入支付密码
  356. }).then(({value}) => {
  357. this.payPassword = value
  358. let params = {
  359. addressId: this.addressId,
  360. payType: this.payType,
  361. goodsId: this.goodsId,
  362. goodsNum: this.goodsNum,
  363. payPassword: this.payPassword,
  364. email: this.form.email,
  365. }
  366. // PayStack支付
  367. if (this.payType === 'pay_stack') {
  368. return network.postData('shop/sure-approach-order', params).then((response) => {
  369. this.submitButtonStat = false
  370. this.form.orderSn = response.SN
  371. this.form.amount = this.cashSum
  372. this.form.metadata.custom_fields[0].value = response.SN
  373. this.visible = true
  374. }).catch(() => {
  375. this.submitButtonStat = false
  376. })
  377. } else {
  378. // 非PayStack支付
  379. return network.postData('shop/sure-order', params).then(() => {
  380. this.submitButtonStat = false
  381. this.$router.push({path: `/shop/order-list`})
  382. }).catch(() => {
  383. this.submitButtonStat = false
  384. })
  385. }
  386. }).catch(() => {
  387. this.submitButtonStat = false
  388. })
  389. },
  390. getSumMoney () {
  391. // let points_plus_sum=[];
  392. let cash_plus_sum = [];
  393. let goodsId = [];
  394. let goodsNum = [];
  395. let choseNum = 0;
  396. this.goods.map((item,index)=> {
  397. choseNum = Number(item.chose_num);
  398. if (choseNum > 0) {
  399. // points_plus_sum.push(item.SELL_PRICE * choseNum);
  400. cash_plus_sum.push(item.SELL_PRICE * choseNum * (item.DISCOUNT / 100));
  401. goodsId.push(item.ID);
  402. goodsNum.push(choseNum);
  403. }
  404. })
  405. this.goodsNum = goodsNum;
  406. this.goodsId = goodsId;
  407. // 增加运费03-12yuan
  408. let payAmount = tool.sum(cash_plus_sum);
  409. // let payPointAmount = tool.sum(points_plus_sum);
  410. // 只有普通商品有运费
  411. if (this.category_type === 1) {
  412. // 商品自提,免运费
  413. this.setFreight();
  414. // 商品总价大于预定值,免运费
  415. this.pointFreight = (this.pointFreight > 0) ? ((payAmount >= this.freeShipping) ? 0 : this.freight) : 0
  416. } else {
  417. // 非普通商品,没有运费
  418. this.pointFreight = 0
  419. }
  420. // if(payPointAmount>=300){
  421. // this.pointFreight = 0;
  422. // }else{
  423. // this.pointFreight = 15;
  424. // }
  425. // console.log('points_plus_sum',points_plus_sum);
  426. // console.log('cash_plus_sum',cash_plus_sum);
  427. // this.pointsSum=tool.formatPrice(tool.sum(points_plus_sum) + this.pointFreight);
  428. this.pointsSum = this.cashSum = this.form.amount = tool.formatPrice(tool.sum(cash_plus_sum) + this.pointFreight) ;
  429. },
  430. async getShowCart () {
  431. await network.getData('shop/show-cart', {categoryType: this.categoryType}).then(response => {
  432. this.loading = false
  433. // 收货地址
  434. this.all_address = response.allAddress;
  435. this.all_address.map((item, index) => {
  436. if (item.IS_DEFAULT == 1) {
  437. this.addressId = item.ID
  438. }
  439. })
  440. // 账户
  441. this.balance = response.userBalance
  442. // 支付方式
  443. for (let item of response.sellType) {
  444. if (item.id === this.category_type) {
  445. this.payList = item.sell_type
  446. break
  447. }
  448. }
  449. // 支付方式的第一项默认选中
  450. this.payType = Object.values(this.payList)[1]['label']
  451. // 免运费阈值
  452. this.freeShipping = response.freeShipping
  453. // 运费
  454. this.freight = response.freight
  455. })
  456. },
  457. // 切换支付方式
  458. chosePayType (type) {
  459. this.payType = type
  460. },
  461. choseAddress (addressId) {
  462. this.addressId = addressId
  463. this.setFreight()
  464. this.getSumMoney()
  465. },
  466. // 关闭支付回调
  467. handleClose () {
  468. let _this = this
  469. _this.$confirm('Confirm to close?').then(() => {
  470. return network.postData('shop/delete-approach-order', {orderSn: this.form.orderSn}).then(() => {
  471. // 关闭支付模态框
  472. _this.visible = false
  473. // 关闭购物车页面,返回到订单列表页
  474. sessionStorage.setItem('order_goods', null)
  475. sessionStorage.setItem('category_type', null)
  476. this.$router.push({path: `/shop/index`})
  477. })
  478. }).catch(() => {
  479. // 关闭支付模态框
  480. _this.visible = false
  481. // 关闭购物车页面,返回到订单列表页
  482. sessionStorage.setItem('order_goods', null)
  483. sessionStorage.setItem('category_type', null)
  484. this.$router.push({path: `/shop/index`})
  485. })
  486. },
  487. // 支付成功回调
  488. processPayment (response) {
  489. // 关闭支付页面
  490. this.visible = false
  491. this.payStackLoading = false
  492. // 显示支付成功模态框
  493. this.payDialog = true
  494. this.handleCountdown()
  495. },
  496. // 关闭支付回调
  497. processClose () {
  498. // 关闭支付模态框
  499. this.visible = false
  500. // 关闭购物车页面,返回到订单列表页
  501. sessionStorage.removeItem('order_goods')
  502. sessionStorage.removeItem('category_type')
  503. this.$router.push({path: `/shop/index`})
  504. },
  505. handleOrderList () {
  506. this.$router.push({path: `/shop/order-list`})
  507. },
  508. // 启动倒计时
  509. handleCountdown () {
  510. // 创建定时器
  511. setInterval(() => {
  512. // 每隔1秒把time的值减一,赋值给span标签
  513. this.countdown--
  514. if (this.countdown === 0) {
  515. // 倒计时结束,跳转到订单列表
  516. this.$router.push({path: `/shop/order-list`})
  517. }
  518. }, 1000)
  519. },
  520. },
  521. }
  522. </script>
  523. <style scoped>
  524. .address{
  525. /* height: 3rem; */
  526. line-height: 3.5rem;
  527. }
  528. .address_box{
  529. border-bottom: 1px solid #e3e3e3;
  530. }
  531. .sum{
  532. display: inline-block;
  533. }
  534. .box{
  535. margin: 1rem 0;
  536. display: flex;
  537. justify-content: flex-start;
  538. align-items: center;
  539. padding-bottom: 1rem;
  540. }
  541. .sum_box{
  542. display: flex;
  543. margin-left: 1rem;
  544. }
  545. .sum_box > div{
  546. line-height: 2rem;
  547. }
  548. .sum_box > div:nth-child(1){
  549. margin-right: 1rem;
  550. }
  551. .payButton {
  552. border: none;
  553. padding: 0;
  554. }
  555. </style>