index.vue 11 KB

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