index.vue 10 KB

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