dialogBar.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. <template>
  2. <view class="all">
  3. <view class="dialogBar">
  4. <view class="top">
  5. <view class="top-img"><image :src="actionImage" mode=""></image></view>
  6. <view class="goods">
  7. <view id="b">
  8. <b>{{ dataList.store_name }}</b>
  9. </view>
  10. <view id="span">¥{{ actionPrice * num }}</view>
  11. </view>
  12. </view>
  13. <scroll-view scroll-y="true" class="scroll-y">
  14. <view class="material clist pd" v-for="(d, int) in specList" :key="int">
  15. <text class="text">{{ d.attr_name }}</text>
  16. <view class="materials-c lists-c">
  17. <view
  18. v-for="(childItem, childIndex) in d.attr_value"
  19. :key="childIndex"
  20. class="tit"
  21. :class="{ selected: childItem.check }"
  22. @click="selectSpec(childItem, d, int)"
  23. >
  24. {{ childItem.attr }}
  25. </view>
  26. </view>
  27. </view>
  28. </scroll-view>
  29. <view class="buy">
  30. <view class="buy-top">
  31. <span>购买数量</span>
  32. <view class="num"><uni-number-box class="step" :isMin="true" :value="num" :min="1" :max="goodsNumberMax" @eventChange="numberChange"></uni-number-box></view>
  33. </view>
  34. <button type="default" class="shop" @click="setShop(dataList)">加入购物车</button>
  35. </view>
  36. <view class="button" @click="del"><image src="../../../static/icon/tc-del.png"></image></view>
  37. </view>
  38. <view class="curtain"></view>
  39. </view>
  40. </template>
  41. <script>
  42. import { goodsDetail, cartAdd } from '@/api/product.js';
  43. import uniNumberBox from '@/components/uni-number-box.vue';
  44. export default {
  45. components: {
  46. uniNumberBox
  47. },
  48. data() {
  49. return {
  50. buys_show: true,
  51. buys_shows: false,
  52. pid: '',
  53. num: 1,
  54. uniqueId: '',
  55. actionPrice: 0, //默认选中商品价格
  56. actionImage: '', //默认选中图片
  57. dataList: [], //商品数据
  58. specList: [], //规格
  59. feeding: '', //加料
  60. goodsNumberMax: 0, //最大可购买数量
  61. goodsNumberMin: 0 //最小可购买数量
  62. };
  63. },
  64. props: {
  65. showItem: {
  66. type: Object,
  67. default() {
  68. return {};
  69. }
  70. }
  71. },
  72. created() {
  73. this.loadData();
  74. },
  75. methods: {
  76. loadData() {
  77. const obj = this;
  78. console.log(this.showItem, 'dangqian duixiang ');
  79. goodsDetail({}, this.showItem.id).then(({ data }) => {
  80. console.log(data);
  81. let goods = data.storeInfo;
  82. this.dataList = goods;
  83. obj.specList = data.productAttr; //保存分类列表
  84. if (Array.isArray(data.productValue) != true) {
  85. obj.many = 2;
  86. obj.specList = data.productAttr; //保存产品属性
  87. obj.productValue = data.productValue; //保存属性值
  88. obj.specSelected = []; //初始化默认选择对象
  89. for (let i = 0; i < obj.specList.length; i++) {
  90. // 设置默认数据
  91. let attrValue = obj.specList[i].attr_value[0];
  92. attrValue.check = true;
  93. obj.specSelected.push(attrValue.attr);
  94. }
  95. let str = obj.specSelected.join(',');
  96. console.log(str, 'str');
  97. // 设置默认值
  98. obj.actionPrice = obj.productValue[str].price;
  99. obj.goodsNumberMax = obj.productValue[str].stock;
  100. obj.actionImage = obj.productValue[str].image;
  101. obj.uniqueId = obj.productValue[str].unique;
  102. obj.goodsStore = obj.productValue[str].stock;
  103. } else {
  104. obj.many = 1;
  105. obj.productValue = data.productValue; //保存分类查询数据
  106. obj.actionPrice = goods.price; //保存默认选中商品价格
  107. obj.actionImage = goods.image_base; //保存默认选中商品图片
  108. obj.goodsNumberMax = goods.stock; //保存默认选中最大可购买商品数量
  109. obj.shopId = data.mer_id; //保存商店id
  110. }
  111. });
  112. },
  113. del() {
  114. this.$emit('tcDel');
  115. },
  116. //选择数量
  117. numberChange(e) {
  118. this.num = e.number;
  119. },
  120. //选择规格
  121. selectSpec(item, arr, ind) {
  122. arr.attr_value.forEach(function(e) {
  123. e.check = false;
  124. });
  125. item.check = true;
  126. let obj = this;
  127. obj.specSelected[ind] = item.attr;
  128. let str = obj.specSelected.join(',');
  129. // 获取当前选中的对象
  130. if (obj.productValue[str]) {
  131. obj.buys_show = true;
  132. obj.buys_shows = false;
  133. obj.actionPrice = obj.productValue[str].price;
  134. // obj.goodsNumberMax = obj.productValue[str].quota;
  135. obj.actionImage = obj.productValue[str].image;
  136. obj.uniqueId = obj.productValue[str].unique;
  137. obj.goodsStore = obj.productValue[str].stock;
  138. } else {
  139. (obj.buys_show = false), (obj.buys_shows = true);
  140. }
  141. if (obj.goodsStore == 0) {
  142. obj.buys_show = false;
  143. obj.buys_shows = true;
  144. }
  145. obj.specSelected[ind] = item.attr;
  146. },
  147. //加入购物车
  148. setShop(item) {
  149. let obj = this;
  150. cartAdd({
  151. cartNum: this.num, //商品数量
  152. uniqueId: this.uniqueId, //商品标签
  153. new: 0, //商品是否新增加到购物车1为不加入0为加入
  154. mer_id: '',
  155. productId: item.id //商品编号
  156. })
  157. .then(function(e) {
  158. uni.showToast({
  159. title: '成功加入购物车',
  160. type: 'top',
  161. duration: 500,
  162. icon: 'none'
  163. });
  164. obj.$emit('setShop');
  165. })
  166. .catch(e => {
  167. console.log(e);
  168. });
  169. }
  170. },
  171. watch: {
  172. num() {
  173. this.num = Math.ceil(this.num);
  174. },
  175. totalPrice() {
  176. this.feedingList();
  177. }
  178. },
  179. computed: {
  180. //总价格(不算倍数)
  181. totalPrice() {
  182. let price = this.price;
  183. for (let i = 0; i < this.dataList.length; i++) {
  184. for (let a = 0; a < this.dataList.length; a++) {
  185. if (this.dataList[i].list[a].isChoose) {
  186. price += this.dataList[i].list[a].price;
  187. }
  188. }
  189. }
  190. return price;
  191. }
  192. }
  193. };
  194. </script>
  195. <style lang="scss" scoped>
  196. page {
  197. height: 100%;
  198. }
  199. #hr {
  200. width: 90%;
  201. height: 1rpx;
  202. margin-top: 10rpx;
  203. background-color: #eeeeee;
  204. margin-bottom: 0;
  205. }
  206. .button {
  207. border-radius: 50%;
  208. width: 83rpx;
  209. height: 83rpx;
  210. position: relative;
  211. z-index: 99;
  212. margin-top: 60rpx;
  213. margin-left: calc(50% - 40rpx);
  214. margin-bottom: -150rpx;
  215. image {
  216. width: 83rpx;
  217. height: 83rpx;
  218. }
  219. }
  220. .dialogBar {
  221. z-index: 99;
  222. width: 670rpx;
  223. position: absolute;
  224. top: calc(50% - 391rpx);
  225. left: calc(50% - 335rpx);
  226. background-color: #ffffff;
  227. border-radius: 20rpx;
  228. display: grid;
  229. .top {
  230. color: #1c2023;
  231. width: 100%;
  232. height: 200rpx;
  233. font-size: 36rpx;
  234. font-family: PingFang-SC-Bold;
  235. display: flex;
  236. .top-img {
  237. margin: auto 30rpx;
  238. }
  239. image {
  240. width: 140rpx;
  241. height: 140rpx;
  242. }
  243. .goods {
  244. display: grid;
  245. margin: auto 10rpx;
  246. #span {
  247. font-size: 45rpx;
  248. color: #ee2f72;
  249. line-height: 70rpx;
  250. }
  251. #b {
  252. line-height: 70rpx;
  253. overflow: hidden;
  254. text-overflow: ellipsis;
  255. display: -webkit-box;
  256. -webkit-box-orient: vertical;
  257. -webkit-line-clamp: 3;
  258. }
  259. }
  260. }
  261. .scroll-y {
  262. width: 100%;
  263. height: calc(100%+15rpx);
  264. }
  265. .clist {
  266. width: 90%;
  267. margin: 0 auto;
  268. color: #333333;
  269. font-size: 28rpx;
  270. padding-bottom: 20rpx;
  271. font-family: PingFang-SC-Medium;
  272. border-bottom: 1px solid #eeeeee;
  273. .text {
  274. margin-top: 30rpx;
  275. font-weight: bold;
  276. }
  277. .lists-c {
  278. display: flex;
  279. flex-flow: row wrap;
  280. }
  281. .tit {
  282. margin-right: 20rpx;
  283. margin-top: 28rpx;
  284. font-size: 28rpx;
  285. background: #f6f6f6;
  286. width: 120rpx;
  287. text-align: center;
  288. flex-shrink: 0;
  289. font-size: 30rpx;
  290. color: #666666;
  291. }
  292. .selected {
  293. background: #ffeff1;
  294. border: 1rpx solid #ff5263;
  295. color: #f3120a;
  296. }
  297. }
  298. .buy {
  299. color: #333333;
  300. font-size: 28rpx;
  301. font-family: PingFang-SC-Medium;
  302. margin-top: 40rpx;
  303. padding-bottom: 30rpx;
  304. .buy-top {
  305. height: 90rpx;
  306. span {
  307. margin-left: 30rpx;
  308. font-weight: bold;
  309. }
  310. }
  311. .shop {
  312. width: 279rpx;
  313. height: 84rpx;
  314. line-height: 84rpx;
  315. background-color: #ee2f72;
  316. text-align: center;
  317. border-radius: 40rpx;
  318. color: #ffffff;
  319. }
  320. .num {
  321. display: flex;
  322. width: 227rpx;
  323. float: right;
  324. margin: -10rpx 40rpx;
  325. $heightAw: 64rpx;
  326. input {
  327. width: 150rpx;
  328. border: solid 1rpx #cfcfcf;
  329. height: $heightAw;
  330. line-height: $heightAw;
  331. text-align: center;
  332. }
  333. .da {
  334. width: 84rpx;
  335. height: $heightAw;
  336. line-height: $heightAw;
  337. border: solid 1rpx #cfcfcf;
  338. text-align: center;
  339. background-color: #f6f6f6;
  340. color: #333333;
  341. }
  342. }
  343. }
  344. }
  345. .curtain {
  346. position: fixed;
  347. top: 0;
  348. left: 0;
  349. right: 0;
  350. width: 100%;
  351. height: 100%;
  352. background-color: rgba(0, 0, 0, 0.4);
  353. z-index: 11;
  354. }
  355. </style>