coupon_select.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. <template>
  2. <view class="dt-page">
  3. <view class="container">
  4. <view class="notUseTopFix"></view>
  5. <view @tap="tapNotUse" class="notUse">
  6. <text>不使用优惠券</text>
  7. <DtCheck :check="notUse" />
  8. </view>
  9. <view class="voucher" v-for="(item, idx) in dataList" :key="idx">
  10. <view class="dt-voucher" @tap="tapChoose(item,idx)">
  11. <!-- border -->
  12. <image class="bg-top-border" src="http://139.9.103.171:1888/img/image/flowerborder.png" mode="widthFix"></image>
  13. <view class="mn-wrap">
  14. <view class="left">
  15. <block v-if="item.voucher_type == 1">
  16. <view class="worth">6.8<text class="suffix">折</text></view>
  17. <view class="type-name">折扣券</view>
  18. </block>
  19. <block v-else>
  20. <view class="worth"><text class="prefix">¥</text>{{item.couponDiscount}}</view>
  21. <view class="type-name">抵价券</view>
  22. </block>
  23. </view>
  24. <view class="mid">
  25. <view class="apply-to-name fn-text-row-two">{{item.name}}</view>
  26. <view v-if="item.minimumPrice>0" class="apply-condition">满 {{item.minimumPrice}} 元可使用</view>
  27. </view>
  28. <view class="right">
  29. <DtCheck :check="item.isSelected" />
  30. </view>
  31. </view>
  32. <view class="ft-wrap">
  33. <view class="ft" @tap.stop="tapVisible(idx)">
  34. <view class="des">
  35. <text>详细信息</text>
  36. <image class="arrow-up" :class="{ 'active':!item.isShowDetail }" src="http://139.9.103.171:1888/img/image/arrow_up.png" mode="widthFix"></image>
  37. </view>
  38. <view class="date">{{ item.beginDate| dateFormat('yyyy-MM-dd') }} 至 {{ item.endDate| dateFormat('yyyy-MM-dd') }}</view>
  39. </view>
  40. </view>
  41. <view v-if="item.isShowDetail" class="ext-wrap"><text v-if="item.minimumPrice>0">满{{item.minimumPrice}}元可使用;</text>不可叠加使用</view>
  42. </view>
  43. </view>
  44. </view>
  45. <FootToolbar bgColor="#fff">
  46. <view slot="main" class="btn-voucher-wrap">
  47. <button @tap="tapBack" class="dt-btn-submit btn-voucher">确认</button>
  48. </view>
  49. </FootToolbar>
  50. </view>
  51. </template>
  52. <script>
  53. import DtCheck from '../comps/dt_check.vue'
  54. import FootToolbar from '../comps/foot_toolbar.vue'
  55. export default {
  56. components: {
  57. DtCheck,
  58. FootToolbar
  59. },
  60. data() {
  61. return {
  62. dataList: [],
  63. selectStoreCouponIndex: -1,
  64. isSelectProduct: false,
  65. notUse: false,
  66. member_id: 0,
  67. // chooseCodes:[]
  68. };
  69. },
  70. methods: {
  71. tapBack() {
  72. let lastPage = this.$util.getPageCtx(1).$vm
  73. let list = this.dataList.slice(0)
  74. let selectCodes = []
  75. list.forEach(item => {
  76. if(item.isSelected){
  77. selectCodes.push(item.code)
  78. }
  79. });
  80. lastPage.isCalculate = true
  81. lastPage.selectCodes = selectCodes
  82. uni.navigateBack()
  83. },
  84. tapChoose(item, idx) {
  85. this.notUse = false
  86. let list = this.dataList.slice(0)
  87. // 一个订单中的商品,最多只能选择一张优惠券 + 参与一个店铺优惠
  88. if (item.isStoreCoupon) {// 店铺优惠券,一个订单只能选择一张
  89. //点中了店铺优惠券
  90. if (this.selectStoreCouponIndex === -1) {
  91. //从未选过店铺优惠券
  92. this.selectStoreCouponIndex = idx
  93. item.isSelected = true
  94. } else {
  95. if (this.selectStoreCouponIndex === idx) {
  96. item.isSelected = !item.isSelected
  97. if (item.isSelected === false) {
  98. this.selectStoreCouponIndex = -1
  99. }
  100. } else {
  101. list[this.selectStoreCouponIndex].isSelected = false
  102. item.isSelected = true
  103. this.selectStoreCouponIndex = idx
  104. }
  105. }
  106. } else {// 商品优惠券,只与单个商品有关,订单中一个商品只能选择一种优惠券
  107. //点中了商品优惠券
  108. if (this.isSelectProduct === false) {
  109. //从未选过商品优惠券
  110. this.isSelectProduct = true
  111. item.isSelected = true
  112. } else {
  113. // 把当前选中的 productIds 与其他选中的 productIds 比较 有交集的不能选中
  114. if (item.isSelected === false) {
  115. // 随时可以选中
  116. list.map((a,aidx) => {
  117. // 对比除自己只外的
  118. if (aidx !== idx) {
  119. if (
  120. item['productIdsArr'] !== undefined &&
  121. a['productIdsArr'] !== undefined
  122. ) {
  123. if (item.productIdsArr.length > 0 && a.productIdsArr.length > 0) {
  124. let intersection = item.productIdsArr.filter((v) => {
  125. return a.isSelected && a.productIdsArr.indexOf(v) !== -1
  126. })
  127. if (intersection.length > 0) {
  128. a.isSelected = false
  129. }
  130. }
  131. }
  132. }
  133. return a
  134. })
  135. item.isSelected = true
  136. this.isSelectProduct = true
  137. } else {
  138. //随时可以取消选中
  139. item.isSelected = false
  140. }
  141. }
  142. }
  143. list[idx] = item
  144. // this.chooseCodes.push({...item})
  145. this.dataList = list
  146. },
  147. //不用优惠券
  148. tapNotUse() {
  149. this.notUse = !this.notUse
  150. if (this.notUse) {
  151. let list = this.dataList.slice(0)
  152. list.map((item) => {
  153. item.isSelected = false
  154. return item
  155. })
  156. this.selectStoreCouponIndex = -1
  157. this.isSelectProduct = false
  158. this.dataList = list
  159. }
  160. },
  161. //查看详情
  162. tapVisible(idx) {
  163. let dataList = this.dataList.slice(0)
  164. dataList[idx].isShowDetail = !dataList[idx].isShowDetail
  165. this.dataList = dataList
  166. },
  167. queryDataList() {
  168. let lastPage = this.$util.getPageCtx(1).$vm
  169. let lastList = lastPage.couponCodes.slice(0)
  170. // this.chooseCodes = lastPage.selectCodes.slice(0)
  171. // 数据预处理
  172. let list = []
  173. lastList.forEach((lastItem, lastIdx) => {
  174. let item = Object.assign({},lastItem)
  175. if (item.isStoreCoupon && item.isSelected) {
  176. //选中店铺优惠券的下标
  177. this.selectStoreCouponIndex = lastIdx
  178. } else if (!item.isStoreCoupon && item.isSelected) {
  179. //是否有选中了产品优惠券
  180. this.isSelectProduct = true
  181. }
  182. if (item.productIds !== undefined && item.productIds.length > 0) {
  183. item.productIdsArr = item.productIds.split(',')
  184. }
  185. list.push(item)
  186. })
  187. this.dataList = list
  188. },
  189. onLoadPage(options) {
  190. wx.hideShareMenu();
  191. this.queryDataList()
  192. }
  193. },
  194. };
  195. </script>
  196. <style lang="scss" scoped>
  197. .dt-page {
  198. min-height: 100vh;
  199. background-color: #f2f2f2;
  200. }
  201. .container {
  202. padding-left: 30upx;
  203. padding-right: 30upx;
  204. color: rgb(51, 51, 51);
  205. font-size: 28upx;
  206. /* margin-bottom: 140upx; */
  207. }
  208. .notUseTopFix {
  209. width: 100%;
  210. height: 30upx;
  211. }
  212. .notUse {
  213. display: flex;
  214. flex-direction: row;
  215. justify-content: space-between;
  216. align-items: center;
  217. background: white;
  218. padding: 24upx 30upx;
  219. border-radius: 10upx;
  220. .select-icon {
  221. width: 40upx;
  222. height: 40upx;
  223. }
  224. }
  225. .voucher {
  226. background: white;
  227. display: flex;
  228. flex-direction: column;
  229. border-radius: 10upx;
  230. margin: 30upx 0;
  231. font-size: 22upx;
  232. color: rgb(153, 153, 153);
  233. position: relative;
  234. }
  235. .fn-text-row-two {
  236. display: -webkit-box !important;
  237. -webkit-box-orient: vertical !important;
  238. -webkit-line-clamp: 2 !important;
  239. overflow: hidden !important;
  240. text-overflow: ellipsis !important;
  241. }
  242. .dt-voucher {
  243. position: relative;
  244. display: flex;
  245. flex-wrap: wrap;
  246. width: 690upx;
  247. // min-height:220upx;
  248. box-sizing: border-box;
  249. border-radius: 10upx;
  250. font-size: 28upx;
  251. background-color: #fff;
  252. .dis-able {
  253. color: #999 !important;
  254. }
  255. .unreceive {
  256. position: absolute;
  257. top: 0;
  258. left: 0;
  259. width: 90upx;
  260. height: 90upx;
  261. }
  262. .outdate,
  263. .used {
  264. position: absolute;
  265. top: 0;
  266. right: 0;
  267. width: 165upx;
  268. height: 86upx;
  269. }
  270. .bg-top-border {
  271. width: 100%;
  272. height: 15upx;
  273. }
  274. .mn-wrap {
  275. display: flex;
  276. width: 100%;
  277. height: 154upx;
  278. margin: 0 30upx;
  279. .left {
  280. display: flex;
  281. flex-direction: column;
  282. justify-content: center;
  283. align-items: center;
  284. min-width: 136upx;
  285. font-size: 22upx;
  286. color: #ff7171;
  287. .worth {
  288. font-size: 60upx;
  289. line-height: 1;
  290. .prefix {
  291. font-size: 30upx;
  292. }
  293. .suffix {
  294. font-size: 24upx;
  295. }
  296. }
  297. .type-name {
  298. text-align: center;
  299. }
  300. }
  301. .mid {
  302. flex: 1;
  303. display: flex;
  304. flex-direction: column;
  305. justify-content: center;
  306. margin: 0 30upx;
  307. .apply-to-name {
  308. max-height: 61upx;
  309. font-size: 26upx;
  310. line-height: 1.2;
  311. color: #333;
  312. }
  313. .apply-condition {
  314. padding-top: 20upx;
  315. color: #666666;
  316. font-size: 22upx;
  317. }
  318. }
  319. .right {
  320. display: flex;
  321. align-items: center;
  322. }
  323. .get-btn {
  324. margin: 47upx 0;
  325. width: 160upx;
  326. height: 60upx;
  327. line-height: 60upx;
  328. border-radius: 6upx;
  329. font-size: 28upx;
  330. font-weight: 400;
  331. padding: 0;
  332. background-color: #ff7171;
  333. color: #fff;
  334. }
  335. }
  336. .ft-wrap {
  337. position: relative;
  338. display: flex;
  339. flex-wrap: wrap;
  340. width: 100%;
  341. margin: 0 30upx;
  342. color: #666;
  343. .ft {
  344. position: relative;
  345. display: flex;
  346. justify-content: space-between;
  347. width: 100%;
  348. height: 50upx;
  349. line-height: 50upx;
  350. font-size: 20upx;
  351. .des {
  352. .arrow-up {
  353. margin-left: 10upx;
  354. width: 18upx;
  355. height: 9upx;
  356. }
  357. .arrow-up.active {
  358. transform: rotate(180deg);
  359. }
  360. }
  361. }
  362. .ft:before {
  363. position: absolute;
  364. top: 0;
  365. left: 0;
  366. width: 100%;
  367. height: 1upx;
  368. border-top: 1upx dashed #cccccc;
  369. content: "";
  370. }
  371. }
  372. .ft-wrap:before,
  373. .ft-wrap:after {
  374. position: absolute;
  375. top: -14upx;
  376. width: 28upx;
  377. height: 28upx;
  378. border-radius: 50%;
  379. background-color: #f2f2f2;
  380. content: "";
  381. }
  382. .ft-wrap:before {
  383. left: -44upx;
  384. }
  385. .ft-wrap:after {
  386. right: -44upx;
  387. }
  388. .ext-wrap {
  389. padding: 0 30upx 20upx;
  390. width: 100%;
  391. color: #999;
  392. font-size: 20upx;
  393. }
  394. }
  395. .btn-voucher-wrap {
  396. display: flex;
  397. justify-content: center;
  398. align-items: center;
  399. width: 100vw;
  400. height: 110upx;
  401. background-color: #fff;
  402. .btn-voucher {
  403. width: 690upx;
  404. height: 80upx;
  405. line-height: 80upx;
  406. color: #fff;
  407. background-color: $dt-color-primary;
  408. font-size: 30upx;
  409. }
  410. }
  411. </style>