contrast-list.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. <template>
  2. <view class="user-setting-box" @click.stop="optionActive = null">
  3. <!-- #ifndef MP-TOUTIAO -->
  4. <Navbar background-color="#fff" color="#333" title="对比" :showBack="false"></Navbar>
  5. <!-- #endif -->
  6. <view class="content">
  7. <view class="top">
  8. <view class="left">
  9. <image :src="staticUrl ? staticUrl + 'vs.png' : ''" class="pic" mode="heightFix"></image>
  10. 我的对比
  11. </view>
  12. <view class="empty-btn" @click="emptyCollection">
  13. 清空
  14. </view>
  15. </view>
  16. <view class="goods-list">
  17. <view class="good-item" v-for="item in goodsList" :key="item.id">
  18. <view class="left">
  19. <IconText class="icon" :code="`\ue842`" v-if="item.checked" size="14" color="#6B95FF"
  20. @click.native="handleChange(item)">
  21. </IconText>
  22. <IconText class="icon" :code="`\ue84e`" size="14" color="#999" v-else
  23. @click.native="handleChange(item)"></IconText>
  24. <image :src="item.masterPic" class="pic" mode="aspectFill"></image>
  25. <view class="info">
  26. <view class="name">{{item.name}}</view>
  27. <view class="price">参考价:<text>¥{{item.price}}</text></view>
  28. </view>
  29. </view>
  30. <view class="right">
  31. <view @click.stop="optionModal(item)" class="option-btn">
  32. ··
  33. </view>
  34. <view class="option-box" v-if="optionActive === item.id">
  35. <view class="arrow"></view>
  36. <view class="option" @click="topCollection(item)">
  37. <IconText class="icon" :code="`\ue61e`" size="14" color="#fff"></IconText>
  38. 顶置
  39. </view>
  40. <view class="option" @click="moveCollection(item, index)">
  41. <IconText class="icon" :code="`\ue8a7`" size="14" color="#fff"></IconText>
  42. 删除
  43. </view>
  44. </view>
  45. </view>
  46. </view>
  47. </view>
  48. </view>
  49. <view class="btn" @click="toContrast">开始对比({{selected.length}})</view>
  50. <TabBar></TabBar>
  51. </view>
  52. </template>
  53. <script lang="ts">
  54. import {
  55. Component,
  56. Mixins
  57. } from 'vue-property-decorator';
  58. import loginMixin from '@/common/mixins/loginMixin.ts';
  59. import {
  60. types
  61. } from '@/common/store/index';
  62. import {
  63. namespace
  64. } from 'vuex-class';
  65. const baseModule = namespace('base');
  66. @Component({})
  67. export default class SelectBaby extends Mixins(loginMixin) {
  68. @baseModule.Getter('_contrastGoodId') _contrastGoodId: any;
  69. @baseModule.Mutation(types.SET_TABBARINDEX) setTabBarIndex : any;
  70. @baseModule.Mutation(types.SET_CONTRAST_GOOD_ID) setContrastGoodId : any;
  71. staticUrl : string = this.$oss_url; //oss地址
  72. goodsList : any = [];
  73. optionActive : any = null;
  74. selected : any = [];
  75. shareInfo : any = {};
  76. onShow() {
  77. this.selected = [];
  78. this.setTabBarIndex(1);
  79. this.getGoodsList();
  80. this.getShareInfo();
  81. }
  82. onShareAppMessage() {
  83. return {
  84. title: '育百通',
  85. path: '/pages/front/front',
  86. imageUrl: this.shareInfo.pic
  87. };
  88. }
  89. onShareTimeline() {
  90. return {
  91. title: '育百通', // 分享标题
  92. imageUrl: this.shareInfo.pic, // 分享的图片路径,可选
  93. };
  94. }
  95. getGoodsList() {
  96. this.$http
  97. .get({
  98. url: this.$api.getGoodsList,
  99. data: {
  100. queryCompared: 1,
  101. status: '3',
  102. }
  103. })
  104. .then((res : any) => {
  105. this.goodsList = res.list.map((item : any) => {
  106. return {
  107. ...item,
  108. checked: this._contrastGoodId.includes(item.id)
  109. }
  110. });
  111. if(this._contrastGoodId.length){
  112. this.selected = this.goodsList.filter((item : any) => {
  113. return item.checked;
  114. });
  115. }
  116. }, (err : any) => {
  117. console.log(err);
  118. });
  119. }
  120. getShareInfo() {
  121. this.$http
  122. .get({
  123. url: this.$api.getShareInfo
  124. })
  125. .then((res : any) => {
  126. this.shareInfo = res;
  127. }, (err : any) => {
  128. console.log(err);
  129. });
  130. }
  131. optionModal(item : any) {
  132. this.optionActive = item.id;
  133. }
  134. handleChange(item : any) {
  135. item.checked = !item.checked;
  136. this.selected = this.goodsList.filter((item : any) => {
  137. return item.checked;
  138. })
  139. }
  140. moveCollection(item : any, index: any) {
  141. this.$http
  142. .post({
  143. url: this.$api.moveCollection,
  144. data: {
  145. types: 3,
  146. rid: item.id
  147. }
  148. })
  149. .then((res : any) => {
  150. uni.showToast({
  151. title: '已取消对比'
  152. });
  153. let arr = [...this._contrastGoodId];
  154. arr.splice(index, 1);
  155. this.setContrastGoodId(arr);
  156. this.getGoodsList();
  157. }, (err : any) => {
  158. console.log(err);
  159. });
  160. }
  161. topCollection(item : any) {
  162. this.$http
  163. .post({
  164. url: this.$api.topCollection,
  165. data: {
  166. types: 3,
  167. rid: item.id
  168. }
  169. })
  170. .then((res : any) => {
  171. // uni.showToast({
  172. // title: '已取消对比'
  173. // });
  174. this.getGoodsList();
  175. }, (err : any) => {
  176. console.log(err);
  177. });
  178. }
  179. emptyCollection() {
  180. this.$http
  181. .post({
  182. url: this.$api.emptyCollection,
  183. data: {
  184. types: 3,
  185. }
  186. })
  187. .then((res : any) => {
  188. // uni.showToast({
  189. // title: '已取消对比'
  190. // });
  191. this.setContrastGoodId([]);
  192. this.getGoodsList();
  193. }, (err : any) => {
  194. console.log(err);
  195. });
  196. }
  197. toContrast(item : any) {
  198. if (!this.selected.length) {
  199. uni.showToast({
  200. title: '请选择需要对比的产品',
  201. icon: 'none'
  202. })
  203. return;
  204. };
  205. // console.log(this.selected.map((item : any) => item.id) )
  206. let ids = this.selected.map((item : any) => item.id);
  207. this.setContrastGoodId(ids);
  208. this.$Router.push({
  209. path: '/pages/contrast/contrast',
  210. query: {
  211. ids
  212. }
  213. })
  214. }
  215. }
  216. </script>
  217. <style lang="scss" scoped>
  218. page {
  219. background: #f5f5f5;
  220. }
  221. .user-setting-box {
  222. // background: #F5F5F5;
  223. height: 100vh;
  224. // @include flex-y(flex-start);
  225. .content {
  226. width: 100%;
  227. // padding: 0 vw(15);
  228. box-sizing: border-box;
  229. @include flex-y(flex-start);
  230. padding-bottom: vw(50);
  231. .top {
  232. width: 100%;
  233. height: vw(42);
  234. @include flex-x();
  235. padding: 0 vw(12);
  236. box-sizing: border-box;
  237. .left {
  238. @include word-vw(14, #333);
  239. @include flex-x(flex-start);
  240. .pic {
  241. height: vw(16);
  242. margin-right: vw(6);
  243. }
  244. }
  245. .empty-btn {
  246. @include word-vw(12, #999);
  247. }
  248. }
  249. .goods-list {
  250. width: 100%;
  251. border-radius: vw(5);
  252. // overflow: hidden;
  253. }
  254. .good-item {
  255. width: 100%;
  256. height: vw(80);
  257. @include flex-x();
  258. padding: 0 vw(18);
  259. box-sizing: border-box;
  260. background: #fff;
  261. margin-top: vw(1);
  262. @include flex-x();
  263. .left {
  264. @include flex-x();
  265. .pic {
  266. @include wh(64, 64);
  267. margin: 0 vw(10);
  268. }
  269. .info {
  270. @include flex-y(center, flex-start);
  271. .name {
  272. @include word-vw(14, #333);
  273. font-weight: bold;
  274. }
  275. .price {
  276. margin-top: vw(6);
  277. @include word-vw(12, #999);
  278. text {
  279. @include word-vw(14, #FF5733);
  280. font-weight: bold;
  281. }
  282. }
  283. }
  284. }
  285. .right {
  286. position: relative;
  287. .option-btn {
  288. @include wh(32, 18);
  289. border-radius: vw(4);
  290. background: #F2F2F2;
  291. @include flex-x(center);
  292. @include word-vw(14, #BDBDBD);
  293. font-weight: bold;
  294. }
  295. .option-box {
  296. width: vw(85);
  297. background: #424242;
  298. position: absolute;
  299. @include flex-y();
  300. right: vw(-8);
  301. border-radius: vw(4);
  302. z-index: 10;
  303. .option {
  304. width: vw(72);
  305. height: vw(36);
  306. @include word-vw(12, #fff);
  307. @include flex-x(center);
  308. .icon {
  309. margin-right: vw(10);
  310. }
  311. &:nth-last-of-type(1) {
  312. border-top: vw(1) solid rgba(232, 232, 232, 0.11);
  313. }
  314. }
  315. .arrow {
  316. width: 0;
  317. height: 0;
  318. border-left: vw(5) solid transparent;
  319. border-right: vw(5) solid transparent;
  320. border-bottom: vw(5) solid #424242;
  321. border-top: vw(5) solid transparent;
  322. margin: 0;
  323. position: absolute;
  324. top: vw(-10);
  325. right: vw(16);
  326. }
  327. }
  328. }
  329. }
  330. }
  331. .btn {
  332. @include wh(150, 50);
  333. border-radius: vw(25);
  334. background: #618EFF;
  335. @include flex-x(center);
  336. @include word-vw(16, #fff);
  337. position: fixed;
  338. bottom: 100px;
  339. right: vw(10);
  340. }
  341. }
  342. </style>