index.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <template>
  2. <view v-if="indexBox" class="indexBox">
  3. <image :src="type ? image[0] : image[1]" mode="widthFix" style="width: 100%;"></image>
  4. <view class="indexBox_introduce">
  5. <view>¥{{ type ? 8 : 20 }}</view>
  6. <view>{{ type ? '【大卫博士健康内裤】专用洗涤皂' : '【大卫博士健康内裤】专用打包胶带' }}</view>
  7. <view>本件商品10{{ type ? '块' : '卷' }}起订</view>
  8. </view>
  9. <view class="indexBox_stepper flexB">
  10. <text>购买数量</text>
  11. <view class="count flexS">
  12. <view class="flexC" @click.stop="down()">-</view>
  13. <input type="number" focus v-model="num" />
  14. <view class="flexC" @click.stop="up()">+</view>
  15. </view>
  16. </view>
  17. <view class="bottom">
  18. <view class="bottom_top">
  19. <text class="text1">共{{ `${num + (type ? '块' : '卷')}` }},</text>
  20. <text>合计;</text>
  21. <text class="text2">¥</text>
  22. <text class="text3">{{ total }}</text>
  23. </view>
  24. <view class="bottom_btn" @click="goBuy">
  25. 立即下单
  26. </view>
  27. </view>
  28. </view>
  29. </template>
  30. <script>
  31. import { getOpenid } from '@/api/good.js'
  32. export default {
  33. data() {
  34. return {
  35. indexBox: false,
  36. type: '',
  37. title: '',
  38. num: 10,
  39. openid: '',
  40. image: [
  41. require('../../static/img/soap.png'),
  42. require('../../static/img/tape.png')
  43. ]
  44. }
  45. },
  46. computed: {
  47. total() {
  48. return this.type ? this.num * 8 : this.num * 20
  49. }
  50. },
  51. onLoad(opt) {
  52. // 已授权
  53. if (opt.wxcode) {
  54. const type = (opt.type == 'soap' ? 1 : 0)
  55. uni.setStorageSync('type', Number(type))
  56. this.type = uni.getStorageSync('type')
  57. this.indexBox = true
  58. getOpenid({
  59. code: opt.wxcode
  60. }).then(res => {
  61. if (res.code == 200) {
  62. this.openid = res.data.openid
  63. } else {
  64. uni.showToast({
  65. title: res.msg || '登录失败',
  66. icon: 'none'
  67. });
  68. }
  69. })
  70. return
  71. }
  72. // 未授权
  73. let wxcode = this.getUrlParam('code')
  74. if (!wxcode) {
  75. const redirect_uri = 'http://api.app.cliu.cc'
  76. const wxURL = 'https://open.weixin.qq.com/connect/oauth2/authorize'
  77. const appid = 'wx5224793b7dc7f7b7'
  78. let uri = encodeURIComponent(
  79. `${redirect_uri}/api/gzh#/pages/to_soap_tape/to_soap_tape?type=${opt.type}`
  80. );
  81. let authURL =
  82. `${wxURL}?appid=${appid}&redirect_uri=${uri}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect`;
  83. window.location.href = authURL;
  84. return false;
  85. }
  86. // if (opt.type) {
  87. // const type = (opt.type == 'soap' ? 1 : 0)
  88. // uni.setStorageSync('type', Number(type))
  89. // }
  90. // this.type = uni.getStorageSync('type')
  91. },
  92. methods: {
  93. //获取code值方法
  94. getUrlParam(name) {
  95. console.log(window.location, 'location');
  96. console.log(window.location.href, 'href');
  97. var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)'); //构造一个含有目标参数的正则表达式对象
  98. var r = window.location.search.substr(1).match(reg); //匹配目标参数
  99. if (r != null) return decodeURIComponent(r[2]);
  100. // return null; //返回参数值
  101. return ''; //返回参数值
  102. },
  103. down() {
  104. if (this.num - 1 === 9) {
  105. uni.showModal({
  106. content: `数量不能再少了`,
  107. showCancel: false
  108. })
  109. } else {
  110. this.num -= 1
  111. }
  112. },
  113. up() {
  114. this.num += 1
  115. },
  116. goBuy() {
  117. if (this.num < 10) {
  118. uni.showModal({
  119. content: `购买数量不能小于10`,
  120. showCancel: false
  121. })
  122. return
  123. }
  124. uni.navigateTo({
  125. url: '../information/information?num=' + this.num + '&openid=' + this.openid
  126. })
  127. }
  128. }
  129. }
  130. </script>
  131. <style lang="scss" scoped>
  132. .indexBox {
  133. padding-bottom: 214rpx;
  134. &_introduce {
  135. margin: 6rpx 0 24rpx 0;
  136. padding: 24rpx 24rpx 24rpx 8rpx;
  137. background-color: #fff;
  138. view:first-child {
  139. font-size: 56rpx;
  140. font-weight: bold;
  141. color: #FB231F;
  142. margin-left: 12rpx;
  143. }
  144. view:nth-child(2) {
  145. font-size: 36rpx;
  146. font-weight: bold;
  147. color: #333333;
  148. margin: 16rpx 0 24rpx 0;
  149. }
  150. view:last-child {
  151. font-size: 28rpx;
  152. font-weight: 400;
  153. color: #FB231F;
  154. margin-left: 16rpx;
  155. }
  156. }
  157. &_stepper {
  158. padding: 24rpx;
  159. background-color: #fff;
  160. text {
  161. font-size: 32rpx;
  162. color: #333333;
  163. }
  164. .count {
  165. margin-left: 20rpx;
  166. width: 224rpx;
  167. height: 68rpx;
  168. background: #fff4f3;
  169. border: 2px solid #FF0000;
  170. border-radius: 16rpx;
  171. overflow: hidden;
  172. input {
  173. border-left: 1rpx solid #FF0000;
  174. border-right: 1rpx solid#FF0000;
  175. height: 100%;
  176. width: 40%;
  177. text-align: center;
  178. }
  179. view {
  180. color: #FB231F;
  181. width: 30%;
  182. font-size: 44rpx;
  183. flex-shrink: 0;
  184. }
  185. }
  186. }
  187. .bottom {
  188. padding: 8rpx 24rpx 6rpx 24rpx;
  189. box-shadow: 0px -4rpx 24rpx 2rpx rgba(0, 0, 0, 0.1);
  190. position: fixed;
  191. left: 0;
  192. bottom: 0;
  193. width: 100%;
  194. background-color: #fff;
  195. &_top {
  196. font-weight: bold;
  197. font-size: 28rpx;
  198. .text1 {
  199. color: #999;
  200. }
  201. .text2 {
  202. color: #FB231F;
  203. }
  204. .text3 {
  205. font-size: 60rpx;
  206. color: #FB231F;
  207. }
  208. }
  209. &_btn {
  210. width: 702rpx;
  211. height: 88rpx;
  212. background: linear-gradient(91deg, #F30000 0%, #FE4815 100%);
  213. border-radius: 44rpx 44rpx 44rpx 44rpx;
  214. text-align: center;
  215. line-height: 88rpx;
  216. font-size: 32rpx;
  217. font-weight: bold;
  218. color: #FFFFFF;
  219. margin-top: 12rpx;
  220. }
  221. }
  222. }
  223. </style>