index.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. <template>
  2. <div>
  3. <el-form :model="dataForm">
  4. <el-form-item label="快递:"
  5. prop="expressActiveIndex">
  6. <el-radio-group v-model="dataForm.expressActiveIndex">
  7. <el-radio :label="index" v-for="(item, index) in expressList"
  8. :key="index">{{ item.expressName }}
  9. </el-radio>
  10. </el-radio-group>
  11. <el-button class="TT-btn-clear"
  12. type="primary"
  13. size="mini"
  14. @click="resetFormData">清空筛选条件
  15. </el-button>
  16. </el-form-item>
  17. <el-form-item label="仓库:"
  18. prop="warehouseId"
  19. v-if="dataForm.expressActiveIndex >= 0 && dataForm.expressActiveIndex !== ''">
  20. <el-radio-group v-model="dataForm.warehouseId"
  21. @change="getDataList">
  22. <el-radio
  23. :label="item.id"
  24. v-for="(item, index) in expressList[dataForm.expressActiveIndex].warehouse"
  25. :key="index">{{item.warehouseName }}
  26. </el-radio>
  27. </el-radio-group>
  28. </el-form-item>
  29. <el-form-item label="排序:">
  30. <p class="TT-rank-options"
  31. :class="{'active': activeRankIndex === index}"
  32. v-for="(item, index) in rankList"
  33. :key="index"
  34. @click="handleSortList(index)">
  35. <span>{{ item.label === '综合排序' ? item.label : item.label + (item.value ? '从低到高' : '从高到低') }}</span>
  36. <template v-if="item.icon">
  37. <i class="el-icon-arrow-up" v-show="item.value === true"></i>
  38. <i class="el-icon-arrow-down" v-show="item.value === false"></i>
  39. </template>
  40. </p>
  41. </el-form-item>
  42. </el-form>
  43. <el-row v-loading="dataListLoading">
  44. <el-col class="mt-20"
  45. :span="4"
  46. :offset="index % 5 === 0 ? 0 : 1"
  47. v-for="(item, index) in dataList"
  48. :key="item.id">
  49. <el-card class="TT-goods-info" shadow="hover">
  50. <div @mouseenter="activeGoodsInedex = index"
  51. @mouseleave="activeGoodsInedex = -1">
  52. <div class="top">
  53. <div class="photo">
  54. <img :src="item.productImgUrl" alt="">
  55. </div>
  56. <div class="mask"
  57. :class="{'active': activeGoodsInedex === index}">
  58. <el-button @click="funJumpGoodsOrder(item)">立即购买</el-button>
  59. <el-button @click="funJumpGoodsDetail(item)">查看详情</el-button>
  60. </div>
  61. </div>
  62. <div class="middle">
  63. <p class="name">{{ item.productName }}</p>
  64. <p class="store">{{ item.warehouseName }}</p>
  65. <div class="price-wrap">
  66. <p class="price">
  67. <span>¥</span>
  68. <span>{{ item.productPrice.toFixed(2) }}</span>
  69. </p>
  70. </div>
  71. </div>
  72. <div class="bottom">
  73. <p class="stock">
  74. <span>库存</span>
  75. <span>{{ item.productStorageNum }}件</span>
  76. </p>
  77. <p class="sales">
  78. <span>销量</span>
  79. <span>{{ item.productSaleNum }}件</span>
  80. </p>
  81. </div>
  82. </div>
  83. </el-card>
  84. </el-col>
  85. </el-row>
  86. <el-pagination
  87. @size-change="sizeChangeHandle"
  88. @current-change="currentChangeHandle"
  89. :current-page="pageIndex"
  90. :page-sizes="[10, 20, 50, 100]"
  91. :page-size="pageSize"
  92. :total="totalPage"
  93. layout="total, sizes, prev, pager, next, jumper">
  94. </el-pagination>
  95. </div>
  96. </template>
  97. <script>
  98. import Crypto from '@/utils/crypto'
  99. export default {
  100. name: 'index',
  101. data () {
  102. return {
  103. dataListLoading: false,
  104. dataForm: {
  105. expressActiveIndex: '',
  106. warehouseId: ''
  107. },
  108. expressList: [],
  109. rankList: [
  110. {
  111. type: '',
  112. label: '综合排序',
  113. value: true,
  114. icon: false
  115. },
  116. {
  117. type: 'productPrice',
  118. label: '价格',
  119. value: false,
  120. icon: true
  121. }
  122. ],
  123. activeRankIndex: 0,
  124. dataList: [],
  125. pageIndex: 1,
  126. pageSize: 10,
  127. totalPage: 0,
  128. activeGoodsInedex: -1
  129. }
  130. },
  131. created () {
  132. this.fetchExpressList()
  133. this.getDataList()
  134. },
  135. methods: {
  136. resetFormData () {
  137. this.$set(this.dataForm, 'expressActiveIndex', '')
  138. this.$set(this.dataForm, 'warehouseId', '')
  139. this.activeRankIndex = 0
  140. this.getDataList()
  141. },
  142. handleSortList (index) {
  143. const _value = this.rankList[index].value
  144. this.$set(this.rankList[index], 'value', !_value)
  145. this.activeRankIndex = index
  146. const { value, type } = this.rankList[this.activeRankIndex]
  147. this.dataList = this.dataList.sort((a, b) => {
  148. const val1 = a[type]
  149. const val2 = b[type]
  150. return value ? val1 - val2 : val2 - val1
  151. })
  152. },
  153. funJumpGoodsOrder (item = {}) {
  154. const { id } = item
  155. this.$router.push({ name: 'goodsOrder', params: { goodsId: Crypto.encrypt(id.toString()) } })
  156. },
  157. funJumpGoodsDetail (item = {}) {
  158. const { id } = item
  159. this.$router.push({ name: 'goodsDetail', params: { goodsId: Crypto.encrypt(id.toString()) } })
  160. },
  161. fetchExpressList () {
  162. this.$http({
  163. url: this.$http.adornUrl('/gift/express/list'),
  164. method: 'get',
  165. params: this.$http.adornParams({})
  166. }).then(({ data }) => {
  167. if (data.status) {
  168. this.expressList = data.data
  169. } else {
  170. this.$message.error(data.msg)
  171. }
  172. })
  173. },
  174. // 获取数据列表
  175. getDataList () {
  176. this.dataListLoading = true
  177. this.$http({
  178. url: this.$http.adornUrl('/gift/product/list'),
  179. method: 'get',
  180. params: this.$http.adornParams({
  181. 'page': this.pageIndex,
  182. 'pageSize': this.pageSize,
  183. 'warehouseId': this.dataForm.warehouseId
  184. })
  185. }).then(({ data }) => {
  186. if (data.status) {
  187. const { total, list } = data.data
  188. this.dataList = list
  189. this.totalPage = total
  190. } else {
  191. this.dataList = []
  192. this.totalPage = 0
  193. }
  194. this.dataListLoading = false
  195. })
  196. },
  197. // 每页数
  198. sizeChangeHandle (val) {
  199. this.pageSize = val
  200. this.pageIndex = 1
  201. this.getDataList()
  202. },
  203. // 当前页
  204. currentChangeHandle (val) {
  205. this.pageIndex = val
  206. this.getDataList()
  207. }
  208. }
  209. }
  210. </script>
  211. <style lang="scss" scoped>
  212. .mt-20 {
  213. margin-top: 20px;
  214. }
  215. .TT-btn-clear {
  216. position: absolute;
  217. right: 0;
  218. top: 0;
  219. z-index: 1;
  220. }
  221. .TT-rank-options {
  222. display: inline-block;
  223. vertical-align: middle;
  224. margin-left: 10px;
  225. cursor: pointer;
  226. &.active {
  227. color: #409EFF;
  228. }
  229. &:nth-of-type(1) {
  230. margin-left: 0;
  231. }
  232. }
  233. .TT-goods-info {
  234. /deep/ .el-card__body {
  235. padding: 0;
  236. }
  237. .top {
  238. position: relative;
  239. cursor: pointer;
  240. }
  241. .photo {
  242. img {
  243. display: block;
  244. width: 100%;
  245. }
  246. }
  247. .mask {
  248. position: absolute;
  249. left: 0;
  250. top: 0;
  251. z-index: 1;
  252. display: flex;
  253. flex-direction: column;
  254. align-items: center;
  255. justify-content: center;
  256. width: 100%;
  257. height: 100%;
  258. opacity: 0;
  259. background: rgba(0, 0, 0, 0.5);
  260. &.active {
  261. opacity: 1;
  262. }
  263. .el-button + .el-button {
  264. margin-left: 0;
  265. margin-top: 20px;
  266. }
  267. }
  268. .middle {
  269. padding: 0 10px;
  270. margin-top: 10px;
  271. .name {
  272. font-size: 16px;
  273. white-space: nowrap;
  274. overflow: hidden;
  275. text-overflow: ellipsis;
  276. }
  277. .store {
  278. margin-top: 30px;
  279. white-space: nowrap;
  280. overflow: hidden;
  281. text-overflow: ellipsis;
  282. }
  283. }
  284. .price-wrap {
  285. display: flex;
  286. align-items: center;
  287. justify-content: space-between;
  288. margin-top: 6px;
  289. .price {
  290. display: flex;
  291. align-items: flex-end;
  292. span {
  293. color: #f64f6f;
  294. &:nth-of-type(2) {
  295. font-size: 22px;
  296. margin-left: 4px;
  297. }
  298. }
  299. }
  300. .unit {
  301. padding: 0 10px;
  302. line-height: 22px;
  303. font-size: 10px;
  304. color: #f64f6f;
  305. background: #f4f4f5;
  306. }
  307. }
  308. .bottom {
  309. display: flex;
  310. align-items: center;
  311. justify-content: space-between;
  312. padding: 20px 10px;
  313. margin-top: 10px;
  314. border-top: 1px solid #ccc;
  315. p {
  316. display: flex;
  317. align-items: center;
  318. white-space: nowrap;
  319. overflow: hidden;
  320. text-overflow: ellipsis;
  321. }
  322. span {
  323. font-size: 10px;
  324. &:nth-of-type(2) {
  325. color: #f64f6f;
  326. margin-left: 6px;
  327. }
  328. }
  329. }
  330. }
  331. </style>