index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. <template>
  2. <view class="cart-pages">
  3. <view v-if="!userInfo.receiveAddress" @click="editAddress" class="noAddress">
  4. <view>请输入收货地址</view>
  5. <u-icon name="arrow-right" size="36"></u-icon>
  6. </view>
  7. <view v-else class="cart-bar">
  8. <view>
  9. <u-image height="40rpx" width="40rpx" src="/static/position.png"></u-image>
  10. </view>
  11. <view class="position">
  12. <view class="address">{{receiveAddress}}</view>
  13. <view>{{userInfo.receiverName +'&nbsp;&nbsp;&nbsp;' + userInfo.receiverPhone}}</view>
  14. </view>
  15. <view @click="editAddress">
  16. <u-image height="50rpx" width="50rpx" src="/static/edit.png"></u-image>
  17. </view>
  18. </view>
  19. <view class="goods-list">
  20. <!-- 商品列表 -->
  21. <view class="goods-item" v-for="(item,index) in goodsList" :key="item.id">
  22. <view class="goods-imgs">
  23. <u-image border-radius="12" width="158rpx" height="140rpx" :src="item.goods.homeImage"></u-image>
  24. </view>
  25. <view class="goods-info">
  26. <view class="good-name">{{item.goods.name}}</view>
  27. <view class="goods-price">
  28. <view>
  29. <text>{{item.goods.sellGold}}</text>
  30. <u-image mode="scaleToFill" width="30rpx" height="30rpx" src="/static/ledou.png"></u-image>
  31. </view>
  32. <view>×{{item.buyQty}}</view>
  33. </view>
  34. </view>
  35. </view>
  36. <!-- 总计 -->
  37. <view class="goods-heji">
  38. <view>
  39. <view>商品合计:</view>
  40. <view class="heji">
  41. <text>{{totalPrice}}</text>
  42. <u-image mode="scaleToFill" width="35rpx" height="35rpx" src="/static/ledou.png"></u-image>
  43. </view>
  44. </view>
  45. <view>
  46. <view>运费:</view>
  47. <view>免运费</view>
  48. </view>
  49. </view>
  50. </view>
  51. <view class="cart-submit">
  52. <view>
  53. <view>总计:<text>{{totalPrice}}</text></view>
  54. <u-image mode="scaleToFill" width="40rpx" height="40rpx" src="/static/ledou.png"></u-image>
  55. </view>
  56. <view>
  57. <u-button size="mini" :loading="btnLoading" :custom-style="toOrderButton" type="success" @click="toSaveOrder">确认支付</u-button>
  58. </view>
  59. </view>
  60. <!-- 提示用户设置支付密码 -->
  61. <u-modal v-model="showSetPswModal"
  62. content="请先设置支付密码,才能使用乐豆"
  63. show-cancel-button
  64. confirm-text="去设置"
  65. cancel-text="暂时放弃"
  66. @confirm="toSetPwd"
  67. @cancel="showSetPswModal=false"
  68. ></u-modal>
  69. <!-- 确认取消弹窗 -->
  70. <u-modal v-model="showLeavePsw"
  71. title="确认放弃支付吗?"
  72. content="您的订单在30分钟内未支付将被取消"
  73. show-cancel-button
  74. confirm-text="确认放弃"
  75. cancel-text="继续支付"
  76. @confirm="canclePay"
  77. @cancel="payAgain"
  78. ></u-modal>
  79. <!-- 确认支付弹窗 -->
  80. <u-popup mode="center" :mask-close-able="false" negative-top="300" closeable @close="showLeavePsw=true" v-model="showInputPsw" width="500rpx" >
  81. <view class="slot-content">
  82. <view>确认支付</view>
  83. <view class="text-cont">
  84. <text class="num-big">{{totalPrice}}</text>
  85. <u-image mode="scaleToFill" width="40rpx" height="40rpx" src="/static/ledou.png"></u-image>
  86. </view>
  87. <view class="footer">
  88. <input
  89. v-model="password"
  90. maxlength="30"
  91. :focus="focus"
  92. style="text-align: center;"
  93. type="password"
  94. @confirm="toPay"
  95. placeholder="请输入支付密码" />
  96. </view>
  97. <view class="fot-btn">
  98. <u-button :loading="payBtn" @click="toPay" type="success" >确认支付</u-button>
  99. </view>
  100. </view>
  101. </u-popup>
  102. </view>
  103. </template>
  104. <script>
  105. import { saveOrder, signPay, existPayPwd} from '@/api/order.js'
  106. import {
  107. findAddressBycustomerNo
  108. } from '@/api/receiveAddress.js'
  109. export default {
  110. data() {
  111. return {
  112. toOrderButton: {
  113. borderRadius:'100rpx',
  114. fontSize:'30rpx',
  115. width: '200rpx',
  116. height: '80rpx'
  117. },
  118. goodsList: [], // 商品列表
  119. // 用户信息
  120. userInfo: {},
  121. btnLoading: false, // 提交按钮加载圈
  122. orderId: '', // 订单id
  123. password: '', // 支付密码
  124. showSetPswModal: false, // 设置支付密码弹窗
  125. showInputPsw: false, // 打开输入密码弹窗
  126. showLeavePsw: false, // 打开确定放弃弹窗
  127. payBtn: false,
  128. orderForm: '', // 商品下单来源,商品详情或购物车
  129. focus: false
  130. };
  131. },
  132. onShow() {
  133. this.getLocation()
  134. },
  135. onLoad(opts) {
  136. this.orderForm = opts.orderForm
  137. this.goodsList = this.$store.state.vuex_toOrderList
  138. // 监听设置密码是否成功
  139. uni.$once('setPswSuccess', this.setPsw)
  140. // 开启分享
  141. uni.showShareMenu({
  142. withShareTicket: true,
  143. menus: ['shareAppMessage', 'shareTimeline']
  144. })
  145. },
  146. computed: {
  147. // 总计
  148. totalPrice() {
  149. let total = 0
  150. this.goodsList.map(item => {
  151. total = total + item.buyQty * item.goods.sellGold
  152. })
  153. return total
  154. },
  155. // 收货地址
  156. receiveAddress() {
  157. if (this.userInfo.receiveAreasName) {
  158. let area = this.userInfo.receiveAreasName.split(',')
  159. return area[0]+area[1]+area[2]+this.userInfo.receiveAddress
  160. }
  161. }
  162. },
  163. methods: {
  164. // 获取用户位置
  165. getLocation() {
  166. findAddressBycustomerNo({}).then(res => {
  167. console.log(res)
  168. if (res.status == 200) {
  169. this.userInfo = res.data[0] || {}
  170. } else {
  171. this.userInfo = {}
  172. }
  173. })
  174. },
  175. //新增/修改收货地址信息
  176. editAddress(){
  177. this.$u.vuex("vuex_OrderAddress",this.userInfo)
  178. uni.navigateTo({
  179. url:"/pagesA/toOrder/editAddress"
  180. })
  181. },
  182. // 跳转到设置支付密码页
  183. toSetPwd () {
  184. uni.navigateTo({
  185. url:"/pages/userCenter/userInfo/smsVerification"
  186. })
  187. },
  188. // 设置密码成功, 打开输入密码弹窗
  189. setPsw (e) {
  190. if (e.success) {
  191. this.showInputPsw = true
  192. setTimeout(()=>{
  193. this.focus = true
  194. },300)
  195. }
  196. },
  197. //确认放弃
  198. canclePay() {
  199. this.showLeavePsw = false
  200. this.showInputPsw = false
  201. this.focus = false
  202. this.password = ''
  203. // 跳转到订单列表
  204. uni.redirectTo({
  205. url:"/pagesA/order/order"
  206. })
  207. },
  208. // 继续支付
  209. payAgain () {
  210. this.focus = false
  211. this.showLeavePsw = false
  212. this.showInputPsw = true
  213. setTimeout(()=>{
  214. this.focus = true
  215. },300)
  216. },
  217. // 支付 校验用户是否设置过支付密码
  218. toCheckPwd(){
  219. // 判断用户是否设置过支付密码
  220. existPayPwd().then(res=>{
  221. console.log(res,'rrrrrr')
  222. if(res.status == 200) {
  223. // 设置过支付密码,输入密码
  224. if(res.data) {
  225. this.showInputPsw = true
  226. setTimeout(()=>{
  227. this.focus = true
  228. },300)
  229. } else {
  230. // 没设置过支付密码,提示设置密码
  231. this.showSetPswModal = true
  232. }
  233. }
  234. })
  235. },
  236. // 支付 保存订单
  237. toSaveOrder () {
  238. if (!this.userInfo.receiveAddress) {
  239. uni.showToast({
  240. title: '请先输入收货地址',
  241. icon: 'none'
  242. })
  243. return false
  244. }
  245. // 已生成订单
  246. if(this.orderId) {
  247. // 校验用户是否设置过支付密码
  248. this.toCheckPwd()
  249. } else {
  250. this.btnLoading = true
  251. let orderGoodsList = []
  252. this.goodsList.map((item,index)=>{
  253. orderGoodsList[index] = {
  254. goodsNo: item.goodsNo,
  255. buyQty: item.buyQty
  256. }
  257. })
  258. let params = {
  259. receiveAddress: this.receiveAddress,
  260. receiverName: this.userInfo.receiverName,
  261. receiverPhone: this.userInfo.receiverPhone,
  262. orderGoodsList: orderGoodsList,
  263. orderForm: this.orderForm,
  264. payGold: this.totalPrice
  265. }
  266. saveOrder(params).then(res=>{
  267. console.log(res,'rrrrrrr')
  268. this.btnLoading = false
  269. if(res.status==200) {
  270. this.orderId = res.data.id
  271. // 校验用户是否设置过支付密码
  272. this.toCheckPwd()
  273. // 刷新购物车
  274. uni.$emit('getCartList')
  275. }
  276. })
  277. }
  278. },
  279. // 支付
  280. toPay() {
  281. if (this.password === '') {
  282. uni.showToast({
  283. title: '请先输入支付密码',
  284. icon: 'none'
  285. })
  286. return false
  287. }
  288. let params = {
  289. payPwd: this.password,
  290. id: this.orderId
  291. }
  292. this.payBtn = true
  293. signPay(params).then(res=>{
  294. this.payBtn = false
  295. if(res.status == 200) {
  296. // 跳转到支付完成界面
  297. uni.redirectTo({
  298. url:"/pagesA/toOrder/payFinish?id=" + this.orderId
  299. })
  300. } else{
  301. this.password = ''
  302. }
  303. })
  304. }
  305. },
  306. }
  307. </script>
  308. <style lang="scss">
  309. page{
  310. height: 100%;
  311. }
  312. .cart-pages{
  313. width: 100%;
  314. height: 100%;
  315. display: flex;
  316. flex-direction: column;
  317. .cart-bar{
  318. background: #FFFFFF;
  319. border-bottom: 1px solid #F8F8F8;
  320. border-top: 10upx solid #F8F8F8;
  321. display: flex;
  322. align-items: center;
  323. padding:15upx 20upx;
  324. .position{
  325. flex-grow: 1;
  326. }
  327. > view{
  328. padding: 10upx;
  329. .address{
  330. padding: 5upx 0;
  331. word-break: break-all;
  332. }
  333. &:last-child{
  334. padding: 0 20upx;
  335. }
  336. }
  337. }
  338. .noAddress{
  339. background: #FFFFFF;
  340. border-bottom: 1px solid #F8F8F8;
  341. border-top: 10upx solid #F8F8F8;
  342. display: flex;
  343. align-items: center;
  344. justify-content: space-between;
  345. padding:30upx 20upx;
  346. font-size: 30upx;
  347. }
  348. .goods-list{
  349. padding: 20upx 0;
  350. flex-grow: 1;
  351. overflow: auto;
  352. .goods-class-box{
  353. background: #FFFFFF;
  354. box-shadow: 1px 1px 3px #eee;
  355. margin-bottom: 20upx;
  356. }
  357. .goods-item{
  358. padding: 20upx 40upx;
  359. display: flex;
  360. align-items: center;
  361. border-bottom: 1px solid #F8F8F8;
  362. background: #fff;
  363. &:last-child{
  364. border: 0;
  365. }
  366. .goods-imgs{
  367. position: relative;
  368. }
  369. .goods-info{
  370. flex-grow: 1;
  371. padding-left: 20upx;
  372. .good-name{
  373. font-weight: bold;
  374. word-break: break-all;
  375. }
  376. }
  377. .goods-price{
  378. display: flex;
  379. align-items: center;
  380. justify-content: space-between;
  381. padding-top: 20upx;
  382. >view{
  383. &:first-child{
  384. display: flex;
  385. align-items: center;
  386. text{
  387. color: red;
  388. font-size: 35upx;
  389. margin-right: 6upx;
  390. font-weight: bold;
  391. }
  392. }
  393. }
  394. }
  395. }
  396. }
  397. .goods-heji{
  398. padding: 20upx 40upx;
  399. background: #FFFFFF;
  400. box-shadow: 1px 1px 3px #eee;
  401. margin-top: 20upx;
  402. >view{
  403. display: flex;
  404. align-items: center;
  405. justify-content: space-between;
  406. padding: 10upx 0;
  407. .heji{
  408. display: flex;
  409. align-items: center;
  410. text{
  411. color: red;
  412. margin-right: 6upx;
  413. font-size: 35upx;
  414. font-weight: bold;
  415. }
  416. }
  417. }
  418. }
  419. .cart-submit{
  420. padding: 20upx 30upx;
  421. background: #FFFFFF;
  422. box-shadow: 1px 1px 3px #eee;
  423. border-top: 1px solid #eee;
  424. display: flex;
  425. align-items: center;
  426. justify-content: space-between;
  427. > view{
  428. &:first-child{
  429. display: flex;
  430. align-items: center;
  431. text{
  432. color: red;
  433. font-size: 40upx;
  434. margin-right: 6upx;
  435. font-weight: bold;
  436. }
  437. }
  438. }
  439. }
  440. // 支付密码弹窗
  441. .slot-content{
  442. padding: 30upx 0;
  443. display: flex;
  444. flex-direction: column;
  445. align-items: center;
  446. justify-content: space-between;
  447. .text-cont{
  448. width: 100%;
  449. padding: 60upx 0;
  450. display: flex;
  451. align-items: center;
  452. justify-content: center;
  453. .num-big{
  454. font-size: 40upx;
  455. color: red;
  456. font-weight: 600;
  457. margin-right: 6rpx;
  458. }
  459. }
  460. .footer{
  461. width: 80%;
  462. border-bottom: 1px solid #b1b1b1;
  463. margin-bottom: 30upx;
  464. }
  465. }
  466. }
  467. </style>