index.vue 9.8 KB

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