| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616 |
- <div id="app" v-cloak>
- <el-card shadow="never" style="border:0;" body-style="background-color: #f3f3f3;padding: 10px 0 0;">
- <div slot="header">
- <div>
- <span>精选好货</span>
- </div>
- </div>
- <div class="table-body">
- <el-form
- :inline="true"
- :model="searchData"
- size="small"
- >
- <el-row>
- <el-form-item label="选品时间">
- <el-date-picker
- v-model="searchData.data"
- type="datetimerange"
- range-separator="至"
- start-placeholder="开始日期"
- end-placeholder="结束日期"
- value-format="yyyy-MM-dd HH:mm:ss"
- >
- </el-date-picker>
- </el-form-item>
- <el-form-item label="商品状态">
- <el-select size="small" v-model="searchData.status" placeholder="商品状态">
- <el-option :label="item.label" :value="item.value" v-for="(item, index) in goodsStatus"></el-option>
- </el-select>
- </el-form-item>
- </el-row>
- <el-row>
- <el-form-item label="一级分类">
- <el-select v-model="searchData.firstCategoryId" @change='searchCategory(1)'>
- <el-option :key="cate.id" v-for="(cate, key) in category_1" :label="cate.name" :value="cate.id"></el-option>
- </el-select>
- </el-form-item>
- <el-form-item label="二级分类">
- <el-select v-model="searchData.secondCategoryId" @change='searchCategory(2)'>
- <el-option :key="cate.id" v-for="(cate, key) in category_2" :label="cate.name" :value="cate.id"></el-option>
- </el-select>
- </el-form-item>
- <el-form-item label="三级分类">
- <el-select v-model="searchData.thirdCategoryId" @change='searchCategory(3)'>
- <el-option :key="cate.id" v-for="(cate, key) in category_3" :label="cate.name" :value="cate.id"></el-option>
- </el-select>
- </el-form-item>
- </el-row>
- <el-row>
- <el-form-item>
- <el-button type="primary" @click="onSearch">查询</el-button>
- <el-button type="primary" @click="onReset">重置</el-button>
- </el-form-item>
- </el-row>
- </el-form>
- </div>
- <div class="table-body">
- <div class="list-header">
- <div class="list-header-left">
- <el-checkbox v-model="checked" @change="allSelect">全选</el-checkbox>
- </div>
- <div class="list-header-right">
- <span style="margin-right: 20px;">已选{{ countIsSelect() }}件</span>
- <el-button size="mini" type="primary" @click="batchAdd">批量加入</el-button>
- </div>
- </div>
- <!--商品信息-->
- <el-row class="goods-list"
- v-if="goods_list"
- :gutter="10"
- v-loading="listLoading"
- >
- <template v-for="(goods, index) in goods_list">
- <el-col :sm="4" :span="8" class="goods-item">
- <div @click="selectGoods(index)">
- <el-card :body-style="{ padding: '0px'}" shadow="always" :class="goods.is_select == true ? 'goods-select' : ''">
- <!-- <img :src="getCover(goods.carouselImgList)" style="height: 200px; width: 100%;"> -->
- <el-image
- style="width: 100%; height: 200px"
- :src="getCover(goods.carouselImgList)"
- fit="cover"
- ></el-image>
- <div style="padding: 10px;" class="goods-infos">
- <div class="goods-name">
- <span>{{ goods.name }}</span>
- </div>
- <div class="goods-prices">
- <div class="goods-prices-item">
- <div class="title">采购价</div>
- <div class="price">{{ getPrice(goods.skuAttr, 'basePrice') }}</div>
- </div>
- <div class="goods-prices-item">
- <div class="title">官方销售价</div>
- <div class="price">{{ getPrice(goods.skuAttr, 'officialDistriPrice') }}</div>
- </div>
- </div>
- <div class="goods-prices">
- <div class="goods-prices-item">
- <div class="title">建议零售价</div>
- <div class="price">{{ getPrice(goods.skuAttr, 'suggestPrice') }}</div>
- </div>
- <div class="goods-prices-item">
- <div class="title">是否包邮</div>
- <div class="price">{{ goods.freeExpress == 1 ? '包邮' : '不包邮'}}</div>
- </div>
- </div>
-
- <div class="goods-btns">
- <div>
- <el-button @click="skuDetail(goods)" type="primary" plain size="mini" :disabled="goods.detail_url == '' ? true : false">查看详情</el-button>
- <!-- <el-button @click="detailUrl(goods)" type="primary" plain size="mini">查看详情</el-button> -->
- </div>
- <div>
- <el-button type="info" disabled plain size="mini" v-if="goods.storage">已加入</el-button>
- <el-button v-else type="primary" plain @click="oneAdd(goods)" size="mini">加入商品库</el-button>
- </div>
- </div>
- </div>
- </el-card>
- </div>
- </el-col>
- </template>
- </el-row>
- <!-- 无数据 -->
- <el-row v-if="goods_list.length == 0">
- <el-empty description="暂无数据"></el-empty>
- </el-row>
- <!-- 分页 -->
- <el-row type="flex" class="page" justify="end" v-if="goods_list.length > 0">
- <el-pagination @current-change="pagination" background layout="prev, pager, next" :page-count="pageCount" v-if="goods_list"></el-pagination>
- </el-row>
- </div>
- <el-dialog title="查看商品" :visible.sync="dialogVisible" width="50%" :before-close="handleClose">
- <template>
- <el-table :data="attrData" style="width: 100%">
- <el-table-column prop="attr" label="规格">
- <template slot-scope="scope">
- <span>
- {{ attrName(scope.row.skuPropertyList) }}
- </span>
- </template>
- </el-table-column>
- <el-table-column prop="status" label="状态">
- <template slot-scope="scope">
- <span v-if="scope.row.status == 1">已下架</span>
- <span v-else>已上架</span>
- </template>
- </el-table-column>
- <el-table-column prop="buyStartQty" label="起购数量">
- <template slot-scope="scope">
- <span v-if="scope.row.buyStartQty > 0">{{ scope.row.buyStartQty }}</span>
- <span v-else>--</span>
- </template>
- </el-table-column>
- <el-table-column prop="basePrice" label="采购价">
- </el-table-column>
- <el-table-column prop="officialDistriPrice" label="官方销售价">
- </el-table-column>
- <el-table-column prop="suggestPrice" label="建议零售价">
- </el-table-column>
- </el-table>
- </template>
- <span slot="footer" class="dialog-footer">
- <el-button @click="dialogVisible = false">取 消</el-button>
- <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
- </span>
- </el-dialog>
- </el-card>
- </div>
- <script>
- // 是否包邮
- const goodsStatus = [{
- value: -1,
- label: '全部',
- },
- {
- value: 1,
- label: '已上架',
- },
- {
- value: 2,
- label: '已下架',
- },
- {
- value: 3,
- label: '已失效',
- },
- ];
- const app = new Vue({
- el: '#app',
- filters: {
- addZero: function(data) {
- return Math.round((data / 100) * 100) / 100 + '元';
- },
- },
- data() {
- return {
- goodsStatus: goodsStatus,
- searchData: {
- data: '',
- firstCategoryId: '',
- secondCategoryId: '',
- thirdCategoryId: '',
- status: '',
- },
- goods_list: [],
- category_1: [],
- category_2: [],
- category_3: [],
- level: 0,
- pid: 0,
- pageCount: 0,
- page: 1,
- currentPage: null,
- listLoading: false,
- btnLoading: false,
- checked: false,
- dialogVisible: false,
- attrData: [],
- };
- },
- methods: {
- /**
- * 跳转详情
- */
- skuDetail(goods) {
- this.attrData = goods.skuAttr
- this.attrTab = goods.skuAttr[0].skuPropertyList
- this.dialogVisible = true
- },
- handleClose() {
- this.dialogVisible = false
- },
- /**
- * 选择商品
- */
- selectGoods(index) {
- if (this.goods_list[index].storage) {
- return false
- }
- if (this.goods_list[index].is_select) {
- Vue.set(this.goods_list[index], 'is_select', false)
- } else {
- Vue.set(this.goods_list[index], 'is_select', true)
- }
- },
- /**
- * 计算已选择
- */
- countIsSelect() {
- let count = 0
- this.goods_list.forEach(item => {
- if (item.is_select == true) {
- count++
- }
- })
- return count
- },
- /**
- * 单个加入
- */
- oneAdd(goods) {
- this.addStorage([goods.spuId])
- goods.storage = 1
- },
- /**
- * 批量加入
- */
- batchAdd() {
- let num = 0
- let goods_id = new Array()
- this.goods_list.forEach(function(item, index) {
- if (item.is_select && !item.storage) {
- num++
- goods_id.push(item.spuId)
- }
- })
- if (num <= 0) {
- this.$message.error('请选择商品')
- return false
- }
- this.addStorage(goods_id)
- },
- /**
- * 全选
- */
- allSelect() {
- if (this.checked) {
- this.goods_list.forEach(function(item, index) {
- if (!item.storage) {
- item.is_select = true
- }
- })
- } else {
- this.goods_list.forEach(function(item, index) {
- if (!item.storage) {
- item.is_select = false
- }
- })
- }
- },
- /**
- * 分类选择
- */
- searchCategory(level) {
- this.level = level
- if (level == 1) {
- this.pid = this.searchData.firstCategoryId
- this.category_2 = []
- this.category_3 = []
- this.searchData.secondCategoryId = ''
- this.searchData.thirdCategoryId = ''
- }
- if (level == 2) {
- this.pid = this.searchData.secondCategoryId == 0 ? this.searchData.firstCategoryId : this.searchData.secondCategoryId
- this.category_3 = []
- this.searchData.thirdCategoryId = ''
- }
- if (level == 3) {
- this.pid = this.searchData.thirdCategoryId == 0 ? this.searchData.secondCategoryId : this.searchData.thirdCategoryId
- return true
- }
- this.getCategoryList()
- },
- /**
- * 搜索
- */
- onSearch() {
- this.page = 1
- this.getGoodsList()
- },
- /**
- * 分页
- */
- pagination(currentPage) {
- this.page = currentPage
- this.getGoodsList()
- },
- /**
- * 获取商品列表
- */
- getGoodsList() {
- this.listLoading = true
- let params = {
- r: 'star-chain/goods/index',
- }
- let data = {
- ...{
- pageIndex: this.page,
- },
- ...this.searchData
- }
- request({
- method: 'post',
- params: params,
- data: data,
- }).then(e => {
- if (e.data.code === 0) {
- this.goods_list = e.data.data.list
- this.pageCount = e.data.data.page_count
- this.currentPage = e.data.data.current_page
- } else {
- this.$message.error(e.data.msg)
- }
- this.listLoading = false
- }).catch(e => {
- this.listLoading = false
- })
- },
- /**
- * 获取分类
- */
- getCategoryList() {
- let self = this
- request({
- params: {
- r: 'star-chain/goods/category',
- pid: this.pid,
- },
- }).then(e => {
- if (e.data.code === 0) {
- let data = e.data
- if (this.level == 0) {
- self.category_1 = data.data
- }
- if (this.level == 1) {
- self.category_2 = data.data
- }
- if (this.level == 2) {
- self.category_3 = data.data
- }
- } else {
- this.$message.error(e.data.msg)
- }
- }).catch(e => {})
- },
- /**
- * 添加到商品
- */
- addStorage(goods_id) {
- if (this.listLoading) return true
- this.listLoading = true
- request({
- method: 'post',
- data: {
- ids: goods_id,
- },
- params: {
- r: 'star-chain/goods/storage-add',
- },
- }).then(e => {
- if (e.data.code === 0) {
- this.$message.success(e.data.msg)
- this.goods_list.forEach(function(item, key) {
- index = goods_id.indexOf(item.id)
- if (index >= 0) {
- Vue.set(item, 'storage', true)
- Vue.set(item, 'is_select', false)
- }
- })
- this.listLoading = false
- } else {
- this.$message.error(e.data.msg)
- this.listLoading = false
- }
- }).catch(e => {
- this.listLoading = false
- })
- },
- /**
- * 获取商品主图
- */
- getCover(list) {
- return list[0]
- },
- /**
- * 获取价格
- */
- getPrice(attr, type) {
- let min = 0
- let max = 0
- if (attr) {
- attr.forEach((v, index) => {
- let price = v[type]
- if (index == 0) {
- min = max = price
- } else {
- min = min < price ? price : min
- max = max > price ? price : max
- }
- })
- }
- return min == max ? min : min + '~' + max
- },
- /**
- * 重置
- */
- onReset() {
- this.searchData = {
- name: '',
- import: '',
- firstCategoryId: '',
- secondCategoryId: '',
- thirdCategoryId: '',
- }
- },
- /**
- * 规格名称
- */
- attrName(attr) {
- let name = []
- attr.forEach((v) => {
- name.push(v.specValueName)
- })
- return name.join(' / ')
- },
- },
- mounted: function() {
- this.page = getQuery('page') ? getQuery('page') : 1
- this.getGoodsList()
- this.getCategoryList()
- }
- })
- </script>
- <style lang="scss">
- .table-body {
- padding: 20px;
- background-color: #fff;
- }
- .table-body + .table-body {
- padding-top: 0;
- }
- .list-header {
- display: flex;
- align-items: center;
- justify-content: space-between;
- padding: 5px 0;
- }
- .list-header-left {
- display: flex;
- align-items: center;
- }
- .list-header-sort {
- display: flex;
- margin-left: 10px;
- }
- .list-header-sort div + div {
- margin-left: 15px;
- }
- .goods-item {
- margin-bottom: 10px;
- }
- .goods-name {
- height: 40px;
- overflow: hidden;
- font-size: 12px;
- font-weight: normal;
- }
- .goods-infos {
- padding: 10px;
- }
- .goods-infos .title {
- font-weight: 100;
- }
-
- .goods-rates {
- margin-top: 3px;
- display: flex;
- justify-content: space-around;
- }
- .goods-prices {
- display: flex;
- justify-content: space-around;
- }
- .goods-prices-item + .goods-prices-item {
- margin-left: 5px;
- }
- .goods-prices-item .price {
- margin-top: 2px;
- color: #F56C6C;
- text-align: center;
- }
- .goods-rates-item + .goods-rates-item {
- margin-left: 5px;
- }
- .goods-rates-item .rate {
- margin-top: 2px;
- color: #E6A23C;
- text-align: center;
- }
- .goods-btns {
- display: flex;
- justify-content: space-between;
- margin-top: 5px;
- }
- .goods-select {
- border-color: #F56C6C;
- }
- .caret-top {
- border: 5px solid transparent;
- margin: 1px 0;
- border-bottom-color: rgb(51, 51, 51);
- }
- .caret-bottom {
- border: 5px solid transparent;
- margin: 1px 0;
- border-top-color: rgb(51, 51, 51);
- }
- .bottom-active {
- border-bottom-color: rgb(186, 41, 92);
- }
- .top-active {
- border-top-color: rgb(186, 41, 92);
- }
- .caret-wrapper {
- display: inline-flex;
- flex-direction: column;
- align-items: center;
- height: 25px;
- width: 11px;
- vertical-align: middle;
- cursor: pointer;
- overflow: initial;
- position: relative;
- }
- </style>
|