index.vue 11 KB

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