goods.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  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" 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="adress_bottom">
  25. <navigator :url="`./purchase_history?type=${type}`" class="add-address big-btn new_address">购买记录</navigator>
  26. <view @click="goBuy" class="add-address big-btn bg">立即下单</view>
  27. </view>
  28. <!-- <view class="bottom_btn" @click="goBuy">
  29. 立即下单
  30. </view> -->
  31. </view>
  32. </view>
  33. </template>
  34. <script>
  35. import { wxLogin } from '@/api/index.js'
  36. export default {
  37. data() {
  38. return {
  39. indexBox: false,
  40. type: '',
  41. title: '',
  42. num: 10,
  43. openid: '',
  44. image: ['https://soap.cliu.cc/chumeng/soap.png','https://soap.cliu.cc/chumeng/tape.png']
  45. }
  46. },
  47. computed: {
  48. total() {
  49. return this.type ? this.num * 8 : this.num * 20
  50. }
  51. },
  52. onLoad(e) {
  53. // 从首页、扫码、或登录页进入
  54. if (e.type) {
  55. let type = (e.type == 'soap' ? 1 : 0)
  56. uni.setStorageSync('type', Number(type))
  57. this.type = uni.getStorageSync('type')
  58. let wxcode = this.getUrlParam('code')
  59. // 回调
  60. if (!uni.getStorageSync('token') && wxcode) {
  61. this.getLogin(wxcode)
  62. return
  63. }
  64. // 没有token
  65. if (!uni.getStorageSync('token') || !uni.getStorageSync('userInfo')) {
  66. this.toWxchatLogin(`/pages/Buy_soap_tape/goods?type=${e.type}`, null)
  67. return false;
  68. }
  69. // 经销商无法购买胶带
  70. let userInfo = uni.getStorageSync('userInfo')
  71. if (userInfo.level != 3 && type == 0) {
  72. uni.showModal({
  73. title: '提示',
  74. content: '无法购买',
  75. showCancel: false,
  76. success: res => {
  77. uni.switchTab({
  78. url: '../index/index'
  79. })
  80. }
  81. })
  82. } else {
  83. this.indexBox = true
  84. }
  85. }
  86. },
  87. methods: {
  88. // 跳转微信授权
  89. toWxchatLogin(url, state) {
  90. url = url || '/pages/index/index';
  91. state = state || 'cli';
  92. const redirect_uri = encodeURIComponent(`${this.$config.redirect_uri}/#${url}`);
  93. const auth = () =>
  94. (window.location.href = `${this.$config.wxURL}?appid=${
  95. this.$config.appid
  96. }&redirect_uri=${redirect_uri}&response_type=code&scope=snsapi_userinfo&state=${state}#wechat_redirect`);
  97. auth();
  98. },
  99. // 登录
  100. getLogin(wxcode) {
  101. let _this = this
  102. wxLogin({ code: wxcode }).then(res => {
  103. let data = res.data
  104. if (data.token) {
  105. uni.setStorageSync('token', data.token)
  106. uni.setStorageSync('userInfo', data.user)
  107. } else if (!data.token && data.openid) {
  108. uni.showModal({
  109. title: '提示',
  110. content: data.msg,
  111. showCancel: false,
  112. success: res => {
  113. uni.reLaunch({
  114. url: '../login/login?type=' + _this.type + '&openid=' + data.openid
  115. })
  116. }
  117. })
  118. } else if (!data.token && !data.openid) {
  119. uni.showModal({
  120. title: '错误提示',
  121. content: data.msg,
  122. showCancel: false
  123. })
  124. }
  125. })
  126. },
  127. //获取code值方法
  128. getUrlParam(name) {
  129. console.log(window.location, 'location');
  130. console.log(window.location.href, 'href');
  131. var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)'); //构造一个含有目标参数的正则表达式对象
  132. var r = window.location.search.substr(1).match(reg); //匹配目标参数
  133. if (r != null) return decodeURIComponent(r[2]);
  134. // return null; //返回参数值
  135. return ''; //返回参数值
  136. },
  137. down() {
  138. if (this.num - 1 === 9) {
  139. uni.showModal({
  140. content: `数量不能再少了`,
  141. showCancel: false
  142. })
  143. } else {
  144. this.num -= 1
  145. }
  146. },
  147. up() {
  148. this.num += 1
  149. },
  150. goBuy() {
  151. if (this.num < 10) {
  152. uni.showModal({
  153. content: `购买数量不能小于10`,
  154. showCancel: false
  155. })
  156. return
  157. }
  158. uni.navigateTo({
  159. url: './information?num=' + this.num + '&openid=' + this.openid
  160. })
  161. }
  162. }
  163. }
  164. </script>
  165. <style lang="scss" scoped>
  166. .indexBox {
  167. padding-bottom: 214rpx;
  168. &_introduce {
  169. margin: 6rpx 0 24rpx 0;
  170. padding: 24rpx 24rpx 24rpx 8rpx;
  171. background-color: #fff;
  172. view:first-child {
  173. font-size: 56rpx;
  174. font-weight: bold;
  175. color: #FB231F;
  176. margin-left: 12rpx;
  177. }
  178. view:nth-child(2) {
  179. font-size: 36rpx;
  180. font-weight: bold;
  181. color: #333333;
  182. margin: 16rpx 0 24rpx 0;
  183. }
  184. view:last-child {
  185. font-size: 28rpx;
  186. font-weight: 400;
  187. color: #FB231F;
  188. margin-left: 16rpx;
  189. }
  190. }
  191. &_stepper {
  192. padding: 24rpx;
  193. background-color: #fff;
  194. text {
  195. font-size: 32rpx;
  196. color: #333333;
  197. }
  198. .count {
  199. margin-left: 20rpx;
  200. width: 224rpx;
  201. height: 68rpx;
  202. background: #fff4f3;
  203. border: 2px solid #FF0000;
  204. border-radius: 16rpx;
  205. overflow: hidden;
  206. input {
  207. border-left: 1rpx solid #FF0000;
  208. border-right: 1rpx solid#FF0000;
  209. height: 100%;
  210. width: 40%;
  211. text-align: center;
  212. }
  213. view {
  214. color: #FB231F;
  215. width: 30%;
  216. font-size: 44rpx;
  217. flex-shrink: 0;
  218. }
  219. }
  220. }
  221. .bottom {
  222. box-shadow: 0px -4rpx 24rpx 2rpx rgba(0, 0, 0, 0.1);
  223. position: fixed;
  224. left: 0;
  225. bottom: 0;
  226. width: 100%;
  227. background-color: #fff;
  228. z-index: 999;
  229. &_top {
  230. font-weight: bold;
  231. font-size: 28rpx;
  232. padding: 8rpx 24rpx 12rpx 24rpx;
  233. .text1 {
  234. color: #999;
  235. }
  236. .text2 {
  237. color: #FB231F;
  238. }
  239. .text3 {
  240. font-size: 60rpx;
  241. color: #FB231F;
  242. }
  243. }
  244. .adress_bottom {
  245. width: 100%;
  246. border-radius: 0;
  247. height: 88rpx;
  248. display: flex;
  249. justify-content: space-between;
  250. align-items: center;
  251. .add-address {
  252. text-align: center;
  253. // flex: 1;
  254. width: 65%;
  255. line-height: 88rpx;
  256. position: relative;
  257. background: #FB231F;
  258. color: #fff;
  259. }
  260. .new_address {
  261. flex: 1;
  262. text-align: center;
  263. border: none;
  264. background-color: #FFFFFF;
  265. color: #FB231F;
  266. box-shadow: 0px 0px 24rpx 2rpx rgba(0, 0, 0, 0.1);
  267. // border-top: 1rpx solid #FE4815;
  268. }
  269. }
  270. // &_btn {
  271. // width: 702rpx;
  272. // height: 88rpx;
  273. // background: linear-gradient(91deg, #F30000 0%, #FE4815 100%);
  274. // border-radius: 44rpx 44rpx 44rpx 44rpx;
  275. // text-align: center;
  276. // line-height: 88rpx;
  277. // font-size: 32rpx;
  278. // font-weight: bold;
  279. // color: #FFFFFF;
  280. // margin-top: 12rpx;
  281. // }
  282. }
  283. // .bottom {
  284. // box-shadow: 0px -4rpx 24rpx 2rpx rgba(0, 0, 0, 0.1);
  285. // position: fixed;
  286. // left: 0;
  287. // bottom: 0;
  288. // width: 100%;
  289. // background-color: #fff;
  290. // z-index: 999;
  291. // padding: 8rpx 24rpx 12rpx 24rpx;
  292. // &_top {
  293. // font-weight: bold;
  294. // font-size: 28rpx;
  295. // .text1 {
  296. // color: #999;
  297. // }
  298. // .text2 {
  299. // color: #FB231F;
  300. // }
  301. // .text3 {
  302. // font-size: 60rpx;
  303. // color: #FB231F;
  304. // }
  305. // }
  306. // .adress_bottom {
  307. // width: 100%;
  308. // border-radius: 0;
  309. // height: 88rpx;
  310. // display: flex;
  311. // justify-content: space-between;
  312. // align-items: center;
  313. // .add-address {
  314. // text-align: center;
  315. // // flex: 1;
  316. // width: 65%;
  317. // line-height: 88rpx;
  318. // position: relative;
  319. // background: #FB231F;
  320. // color: #fff;
  321. // }
  322. // .new_address {
  323. // flex: 1;
  324. // text-align: center;
  325. // border: none;
  326. // background-color: #FFFFFF;
  327. // color: #FB231F;
  328. // box-shadow: 0px 0px 24rpx 2rpx rgba(0, 0, 0, 0.1);
  329. // // border-top: 1rpx solid #FE4815;
  330. // }
  331. // }
  332. // &_btn {
  333. // width: 702rpx;
  334. // height: 88rpx;
  335. // background: linear-gradient(91deg, #F30000 0%, #FE4815 100%);
  336. // border-radius: 44rpx 44rpx 44rpx 44rpx;
  337. // text-align: center;
  338. // line-height: 88rpx;
  339. // font-size: 32rpx;
  340. // font-weight: bold;
  341. // color: #FFFFFF;
  342. // margin-top: 12rpx;
  343. // }
  344. // }
  345. }
  346. </style>