order.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  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. <img :src="scope.row.COVER" alt="" style="width:100%">
  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="库存" prop="STORE_NUMS">-->
  29. <!-- </el-table-column>-->
  30. <el-table-column label="Quantity" prop="chose_num"><!--数量-->
  31. </el-table-column>
  32. <el-table-column label="Total Amount" prop="member_price_plus"><!--合计金额-->
  33. <template slot-scope="scope">
  34. <span>{{ Math.round(scope.row.member_price_plus * 100) / 100 }}</span>
  35. </template>
  36. </el-table-column>
  37. <el-table-column label="Total BV" prop="member_pv_plus" v-if="category_type === 1"><!--合计PV-->
  38. <template slot-scope="scope">
  39. <span>{{ Math.round(scope.row.member_pv_plus * 100) / 100 }}</span>
  40. </template>
  41. </el-table-column>
  42. </el-table>
  43. </div>
  44. <div class="address_box">
  45. Please select the shipping address: <!-- 请选择收货地址 -->
  46. <el-radio-group v-model="addressId" @change='choseAddress'>
  47. <div v-for="(item , index) in all_address" :key='index' class="address">
  48. <el-radio :label="item.ID" >
  49. Full address:{{item.ADDRESS}} {{item.CITY_NAME}} {{item.LGA_NAME}} {{item.PROVINCE_NAME}} &nbsp;&nbsp;&nbsp;&nbsp;
  50. <!-- 详细地址 --> &nbsp;&nbsp;
  51. <!-- 收件人姓名 --> Recipient name:{{item.CONSIGNEE}}&nbsp;&nbsp;&nbsp;&nbsp;
  52. <!-- 手机号码 --> Phone number:{{item.MOBILE}}
  53. </el-radio>
  54. </div>
  55. <div class="address">
  56. <el-radio label="100000000000000000">Self Pick-up</el-radio><!--自提-->
  57. </div>
  58. </el-radio-group>
  59. </div>
  60. <div class="address_box">
  61. Please select payment method:<!-- 请选择支付方式 -->
  62. <el-radio-group v-model="payType" @change='chosePayType'>
  63. <div v-for="(item, index) in payList" :key='index' class="address">
  64. <el-radio :label="item.label">{{ item.name }}</el-radio>
  65. </div>
  66. </el-radio-group>
  67. </div>
  68. <div class="box address_box">
  69. Total orders:<!-- 订单合计 -->
  70. <div class="sum">
  71. <div class="sum_box" v-if="category_type === 1">
  72. <div>Freight</div><!-- 运费 -->
  73. <div><span v-if="category_type === 1">{{ prefixSign }}</span> {{ payType === "cash" ? freight : pointFreight }} <span v-if="category_type === 1">{{ unit }}</span></div>
  74. </div>
  75. <div class="sum_box">
  76. <div>Amount paid</div><!-- 实付金额 -->
  77. <div><span v-if="category_type === 1">{{ prefixSign }}</span> {{ payType === "cash" ? cashSum : pointsSum }} <span v-if="category_type === 1">{{ unit }}</span></div>
  78. </div>
  79. </div>
  80. </div>
  81. <div class="box address_box">
  82. Account Balance: <!-- 账户余额 -->
  83. <div class="sum">
  84. <div v-if="category_type === 1">
  85. <!-- <div class="sum_box">-->
  86. <!-- <div>账户积分</div>-->
  87. <!-- <div>{{ balance.points }}</div>-->
  88. <!-- </div>-->
  89. <div class="sum_box">
  90. <div>Account Balance</div><!-- 账户余额 -->
  91. <div>$ {{ balance.cash }} US</div>
  92. </div>
  93. <div class="sum_box">
  94. <div>Exchange points</div><!-- 兑换点数 -->
  95. <div>{{ balance.exchange }}</div>
  96. </div>
  97. </div>
  98. <div v-if="category_type === 4">
  99. <div class="sum_box">
  100. <div>Travel bonus</div><!-- 旅游积分 -->
  101. <div>{{ balance.travel_points }}</div>
  102. </div>
  103. </div>
  104. <div v-if="category_type === 5">
  105. <div class="sum_box">
  106. <div>Car bonus</div><!-- 名车积分 -->
  107. <div>{{ balance.car_points }}</div>
  108. </div>
  109. </div>
  110. <div v-if="category_type === 6">
  111. <div class="sum_box">
  112. <div>House bonus</div><!-- 豪宅积分 -->
  113. <div>{{ balance.house_points }}</div>
  114. </div>
  115. </div>
  116. </div>
  117. </div>
  118. <div>
  119. <el-button type="primary" @click="goToAccounts()" :loading="submitButtonStat">Settle accounts</el-button><!--去结算-->
  120. </div>
  121. </div>
  122. </div>
  123. <el-dialog title="订单支付" v-if="visible" :visible.sync="visible" width="30%" v-loading="payStackLoading" :before-close="handleClose">
  124. <section>
  125. <h1>Lorem Ipsum Dolor Sit Amet</h1>
  126. <div class="formcontainer">
  127. <el-divider></el-divider>
  128. <div class="container">
  129. <el-form :model="form">
  130. <el-form-item label="Email" label-width="120px">
  131. <el-input v-model="form.email" autocomplete="off" readonly></el-input>
  132. </el-form-item>
  133. <el-form-item label="Amount" label-width="120px">
  134. <el-input v-model="form.amount" autocomplete="off" readonly></el-input>
  135. </el-form-item>
  136. </el-form>
  137. </div>
  138. </div>
  139. </section>
  140. <paystack
  141. :firstname="form.firstname"
  142. :lastname="form.lastname"
  143. :amount="form.amount * 100"
  144. :email="form.email"
  145. :currency="form.currency"
  146. :paystackkey="form.publicKey"
  147. :reference="reference"
  148. :callback="processPayment"
  149. :close="processClose"
  150. >
  151. <el-button type="primary" size="small">支 付</el-button>
  152. </paystack>
  153. </el-dialog>
  154. </div>
  155. </template>
  156. <script>
  157. import network from '@/utils/network'
  158. import tool from '@/utils/tool'
  159. import userInfo from '@/utils/userInfo'
  160. import { PAY_STACK_PUBLIC_KEY, PAY_STACK_CURRENCY } from '@/utils/config'
  161. import paystack from 'vue-paystack'
  162. export default{
  163. name:'order',
  164. data(){
  165. return{
  166. loading: true,
  167. goods:[],
  168. payList:[],
  169. all_address:[],
  170. balance:{},
  171. addressId:'',
  172. payType:'',
  173. payTypeId: '',
  174. pointsSum:'',
  175. cashSum:'',
  176. freight:'',
  177. pointFreight:'',
  178. goodsId:'',
  179. goodsNum:'',
  180. payPassword:'',
  181. submitButtonStat:false,
  182. category_type: '',
  183. prefixSign: '$',
  184. unit: 'US',
  185. visible: false,
  186. payStackLoading: false,
  187. form: {
  188. publicKey: PAY_STACK_PUBLIC_KEY,
  189. currency: PAY_STACK_CURRENCY,
  190. firstname: userInfo.userName(),
  191. lastname: '',
  192. email: userInfo.userEmail(),
  193. amount: 0, // kobo
  194. orderSn: '',
  195. },
  196. }
  197. },
  198. components: {
  199. paystack
  200. },
  201. created(){
  202. let option= sessionStorage.getItem('order_goods');
  203. this.category_type = parseInt(sessionStorage.getItem('category_type'))
  204. this.getShowCart();
  205. if(option){
  206. let pageGoodsList=JSON.parse(option);
  207. // console.log(pageGoodsList);
  208. let pageList;
  209. for( let i in pageGoodsList ) {
  210. pageList = pageGoodsList[i];
  211. if (!pageList) continue;
  212. pageList.map((pageData, index)=>{
  213. if( Number(pageData.chose_num) > 0 ) {
  214. let discount = pageData.DISCOUNT / 100;
  215. pageData.member_price = Math.round(pageData.SELL_PRICE * discount * 100) / 100;
  216. pageData.member_price_plus = Math.round(pageData.SELL_PRICE * Number(pageData.chose_num) * discount * 100) / 100;
  217. pageData.member_pv = Math.round(pageData.PRICE_PV * discount * 100) / 100;
  218. pageData.member_pv_plus = Math.round(pageData.PRICE_PV * Number(pageData.chose_num) * discount * 100) / 100;
  219. this.goods.push(pageData)
  220. }
  221. })
  222. }
  223. this.getSumMoney();
  224. }
  225. },
  226. computed: {
  227. reference() {
  228. let text = "";
  229. let possible =
  230. "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  231. for (let i = 0; i < 10; i++)
  232. text += possible.charAt(Math.floor(Math.random() * possible.length));
  233. return text;
  234. }
  235. },
  236. methods:{
  237. setFreight(){
  238. if(this.addressId=='100000000000000000'){//如果地址为自提,则运费为0
  239. this.pointFreight = this.freight = 0;
  240. }
  241. },
  242. getSummaries(param) {
  243. const { columns, data } = param;
  244. const sums = [];
  245. columns.forEach((column, index) => {
  246. if (index === 0) {
  247. sums[index] = 'Total';// 合计
  248. return;
  249. }
  250. const values = data.map(item => Number(item[column.property]));
  251. if ((!values.every(value => isNaN(value))) && [4, 5, 6].includes(index)) {
  252. sums[index] = values.reduce((prev, curr) => {
  253. const value = Number(curr);
  254. if (!isNaN(value)) {
  255. return Math.round((prev + curr) * 100) / 100;
  256. } else {
  257. return Math.round(prev * 100) / 100;
  258. }
  259. }, 0);
  260. }
  261. });
  262. return sums;
  263. },
  264. goToAccounts(){
  265. let amountBalance = 0
  266. // 前置判断余额是否够支付
  267. if (this.category_type === 1) {
  268. if (this.payType === 'cash') {
  269. amountBalance = this.balance.cash
  270. } else if (this.payType === 'exchange') {
  271. amountBalance = this.balance.exchange
  272. }
  273. // amountBalance = (this.payType === 'cash') ? this.balance.cash : this.balance.exchange
  274. } else if (this.category_type === 4) {
  275. amountBalance = this.balance.travel_points
  276. } else if (this.category_type === 5) {
  277. amountBalance = this.balance.car_points
  278. } else if (this.category_type === 6) {
  279. amountBalance = this.balance.house_points
  280. }
  281. // 提示信息
  282. let tips = 'Balance' //余额
  283. if (this.payType !== 'cash' && this.payType !== 'pay_stack') {
  284. let payObj = this.payList.find((item) => {
  285. return item.label === this.payType
  286. })
  287. tips = (payObj.length <= 0) ? '' : payObj.name
  288. }
  289. // 余额是否充足
  290. if ((amountBalance > 0) && (this.payType !== 'pay_stack') && ((amountBalance - this.cashSum) < 0)) {
  291. let tips = this.payList[this.payType] ? this.payList[this.payType].label : 'Balance'
  292. this.$message({
  293. message: tips + ' insufficient, unable to buy products', // 不足,无法购买商品
  294. type: 'error'
  295. })
  296. this.submitButtonStat = false
  297. return false
  298. }
  299. this.submitButtonStat = true
  300. // let path = 'sure-order'
  301. this.$prompt('Please enter your payment password', 'Hint', {//'请输入支付密码', '提示'
  302. confirmButtonText: 'Confirm',//确定
  303. cancelButtonText: 'Cancel',//取消
  304. inputType: 'password',
  305. inputPattern: /\S+/,
  306. inputErrorMessage: 'Please enter your payment password'//请输入支付密码
  307. }).then(({value}) => {
  308. this.payPassword = value
  309. let params = {
  310. addressId: this.addressId,
  311. payType: this.payType,
  312. goodsId: this.goodsId,
  313. goodsNum: this.goodsNum,
  314. payPassword: this.payPassword,
  315. email: this.form.email,
  316. }
  317. return network.postData('shop/sure-order', params).then((response) => {
  318. this.submitButtonStat = false
  319. // PayStack支付
  320. if (this.payType === 'pay_stack') {
  321. this.form.orderSn = response.SN
  322. this.form.amount = this.cashSum
  323. this.visible = true
  324. } else {
  325. // 非PayStack支付
  326. this.$router.go(-1)
  327. this.$router.push({path: `/shop/order-list`})
  328. }
  329. }).catch((response) => {
  330. this.submitButtonStat = true
  331. })
  332. }).catch(() => {
  333. this.submitButtonStat = false
  334. })
  335. },
  336. getSumMoney(){
  337. // let points_plus_sum=[];
  338. let cash_plus_sum=[];
  339. let goodsId=[];
  340. let goodsNum=[];
  341. let choseNum = 0;
  342. this.goods.map((item,index)=>{
  343. choseNum = Number(item.chose_num);
  344. if( choseNum > 0 ) {
  345. // points_plus_sum.push(item.SELL_PRICE * choseNum);
  346. cash_plus_sum.push(item.SELL_PRICE * choseNum*(item.DISCOUNT/100));
  347. goodsId.push(item.ID);
  348. goodsNum.push(choseNum);
  349. }
  350. })
  351. this.goodsNum=goodsNum;
  352. this.goodsId=goodsId;
  353. //增加运费03-12yuan
  354. let payAmount = tool.sum(cash_plus_sum);
  355. // let payPointAmount = tool.sum(points_plus_sum);
  356. // 只有普通商品有运费
  357. if (this.category_type === 1) {
  358. if(payAmount>=300){
  359. this.pointFreight = this.freight = 0;
  360. }else{
  361. this.pointFreight = this.freight = 15;
  362. }
  363. this.setFreight();
  364. }
  365. // if(payPointAmount>=300){
  366. // this.pointFreight = 0;
  367. // }else{
  368. // this.pointFreight = 15;
  369. // }
  370. //console.log('points_plus_sum',points_plus_sum);
  371. //console.log('cash_plus_sum',cash_plus_sum);
  372. // this.pointsSum=tool.formatPrice(tool.sum(points_plus_sum) + this.pointFreight);
  373. this.pointsSum = this.cashSum = this.form.amount = tool.formatPrice(tool.sum(cash_plus_sum) + this.freight) ;
  374. },
  375. getShowCart(){
  376. network.getData('shop/show-cart', { categoryType: this.categoryType })
  377. .then(response => {
  378. this.loading = false
  379. // 收货地址
  380. this.all_address = response.allAddress;
  381. this.all_address.map((item,index)=>{
  382. if(item.IS_DEFAULT==1){
  383. this.addressId = item.ID
  384. }
  385. })
  386. // 账户
  387. this.balance = response.userBalance
  388. // 支付方式
  389. for (let item of response.sellType) {
  390. if (item.id === this.category_type) {
  391. this.payList = item.sell_type
  392. break
  393. }
  394. }
  395. // 支付方式的第一项默认选中
  396. this.payType = this.payList[0]
  397. })
  398. },
  399. // 切换支付方式
  400. chosePayType(type) {
  401. this.payType = type
  402. },
  403. choseAddress(addressId){
  404. this.getSumMoney()
  405. },
  406. // 关闭支付回调
  407. handleClose(done) {
  408. this.$confirm('确认关闭?').then(_ => done()).catch(_ => {});
  409. },
  410. // 支付成功回调
  411. processPayment(response) {
  412. // 支付失败
  413. if (response.status !== 'success') {
  414. this.$message({
  415. message: 'Success!',
  416. type: 'error'
  417. })
  418. return false
  419. }
  420. this.payStackLoading = true
  421. // 支付成功,更新订单
  422. return network.postData('shop/verify-order', { sn: this.form.orderSn, remark: response }).then(_ => {
  423. this.$message({
  424. message: 'Success!',
  425. type: 'success'
  426. })
  427. this.visible = false
  428. this.payStackLoading = false
  429. this.$router.go(-1)
  430. this.$router.push({path: `/shop/order-list`})
  431. }).catch((err) => {
  432. this.$message({
  433. message: err,
  434. type: 'error'
  435. })
  436. this.payStackLoading = false
  437. return false
  438. })
  439. },
  440. // 关闭支付回调
  441. processClose() {
  442. this.visible = false
  443. }
  444. }
  445. }
  446. </script>
  447. <style scoped>
  448. .address{
  449. /* height: 3rem; */
  450. line-height: 3.5rem;
  451. }
  452. .address_box{
  453. border-bottom: 1px solid #e3e3e3;
  454. }
  455. .sum{
  456. display: inline-block;
  457. }
  458. .box{
  459. margin: 1rem 0;
  460. display: flex;
  461. justify-content: flex-start;
  462. align-items: center;
  463. padding-bottom: 1rem;
  464. }
  465. .sum_box{
  466. display: flex;
  467. margin-left: 1rem;
  468. }
  469. .sum_box > div{
  470. line-height: 2rem;
  471. }
  472. .sum_box > div:nth-child(1){
  473. margin-right: 1rem;
  474. }
  475. .payButton {
  476. border: none;
  477. padding: 0;
  478. }
  479. </style>