| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347 |
- <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="mini"
- >
- <el-row>
- <el-form-item label="会员ID">
- <el-input v-model="searchData.user_id" placeholder="会员ID"></el-input>
- </el-form-item>
- </el-row>
- <el-row>
- <el-form-item>
- <el-button type="primary" @click="onSubmit">查询</el-button>
- <el-button @click="resetForm">重置</el-button>
- </el-form-item>
- </el-row>
- </el-form> -->
- <!-- 订单信息 -->
- <template>
- <el-row>
- <el-button type="success" size="mini" @click="addAttr">添加规格</el-button>
- </el-row>
- <el-table ref="multipleTable" :data="list" @selection-change="handleSelectionChange">
- <!-- 空数据 -->
- <template slot="empty">
- <el-empty description="暂无规格"></el-empty>
- </template>
- <!-- 数据 -->
- <el-table-column type="selection"></el-table-column>
- <el-table-column prop="id" align="center" label="ID"></el-table-column>
- <el-table-column prop="name" align="center" label="规格名"></el-table-column>
- <el-table-column prop="values" align="center" label="规格值">
- <template slot-scope="scope">
- <el-tag class="tag-item" size="mini" v-for="(value, i) in scope.row.values" v-if="i < tagLimit">
- {{ value }}
- </el-tag>
- <span v-if="tagIsLimit(scope.row.values)">...</span>
- </template>
- </el-table-column>
- <el-table-column prop="created_at" align="center" label="创建时间">
- <template slot-scope="scope">
- {{ scope.row.created_at|dateTimeFormat('Y-m-d H:i:s') }}
- </template>
- </el-table-column>
- <el-table-column prop="right_button" align="center" label="操作">
- <template slot-scope="scope">
- <el-button size="mini" type="primary" @click="editSpecs(scope.row)" v-loading="btnLoading">
- 编辑
- </el-button>
- <el-button size="mini" type="danger" @click="delSpecs(scope.row.id)" v-loading="btnLoading">
- 删除
- </el-button>
- </template>
- </el-table-column>
- </el-table>
- </template>
- <!-- 分页 -->
- <el-row type="flex" class="page" justify="end" style="margin-top: 15px">
- <el-pagination
- @current-change="pagination"
- background
- layout="prev, pager, next"
- :page-count="pageCount"
- v-if="list"
- ></el-pagination>
- </el-row>
- </div>
- </el-card>
- <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="30%" :close-on-click-modal="false">
- <el-form
- :inline="true"
- :model="attr"
- size="mini"
- :rules="rules"
- ref="elForm"
- >
- <el-row>
- <el-form-item label="规格名" prop="name">
- <el-input v-model="attr.name" placeholder="规格名"></el-input>
- </el-form-item>
- </el-row>
- <el-row>
- <el-form-item label="规格值" prop="values">
- <div class="attrs-item" v-for="(item, index) in attr.values">
- <el-input v-model="attr.values[index]" placeholder="规格值"></el-input>
- <div class="item-button">
- <el-button type="danger" @click="delItem(index)" icon="el-icon-delete" v-if="isDel(index)"></el-button>
- <el-button type="success" @click="addItem" icon="el-icon-plus" v-if="isAdd(index)"></el-button>
- </div>
- </div>
- </el-form-item>
- </el-row>
- </el-form>
- <span slot="footer" class="dialog-footer">
- <el-button @click="submit" v-loading="btnLoading">提交</el-button>
- </span>
- </el-dialog>
- </div>
- <script>
- const app = new Vue({
- el: '#app',
- data() {
- var validateAttr = (rule, value, callback) => {
- for (let index = 0; index < value.length; index++) {
- const element = value[index];
- if (element == '') {
- callback(new Error('规格值内容不能为空'));
- }
- }
- callback()
- }
- return {
- dialogTitle: '添加规格',
- // 规格值显示上限
- tagLimit: 5,
- limit: 20,
- searchData: {
- user_id : undefined,
- user_keyword : undefined,
- order_no : undefined,
- time : [],
- },
- list: [],
- pageCount: 0,
- page: 1,
- currentPage: null,
- listLoading: false,
- btnLoading: false,
- dialogVisible: false,
- rules: {
- name: [
- {
- required: true,
- message: '规格名不能为空',
- }
- ],
- values: [
- {
- required: true,
- },
- {
- validator: validateAttr,
- }
- ],
- },
- attr: {
- name: '',
- values: [
- ''
- ],
- },
- };
- },
- methods: {
- handleSelectionChange(val) {
- this.select_order = val
- },
- // 全选
- 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) {
- item.is_select = false
- })
- }
- },
- //搜索
- onSubmit() {
- this.page = 1
- this.getAttrList()
- },
- pagination(currentPage) {
- this.page = currentPage
- this.getAttrList()
- },
- getAttrList() {
- this.listLoading = true;
- request({
- params: {
- r: 'store/client/specs/index',
- page: this.page,
- limit: this.limit
- },
- method: 'get',
- data: this.searchData,
- }).then(e => {
- if (e.data.code === 0) {
- this.list = e.data.data.list
- this.pageCount = e.data.data.page_count
- this.currentPage = e.data.data.pagination.current_page
- } else {
- this.$message.error(e.data.msg)
- }
- this.listLoading = false
- }).catch(e => {
- this.listLoading = false
- })
- },
- //重置
- resetForm() {
- this.searchData = {
- user_id : undefined,
- }
- },
- // 添加规格
- addAttr() {
- this.dialogTitle = '添加规格'
- this.attr = {
- name: '',
- values: [
- ''
- ],
- },
- this.dialogVisible = true
- },
- // 是否删除button
- isDel(i) {
- return this.attr.values.length - 1 != i
- // return true
- // return this.attr.values.length > 1
- },
- // 是否添加button
- isAdd(i) {
- return this.attr.values.length - 1 == i
- },
- // 添加
- addItem() {
- this.attr.values.push(
- ''
- )
- },
- // 删除
- delItem(i) {
- this.attr.values = this.attr.values.filter((item, index) => {
- return index != i
- })
- },
- // 规格提交
- submit() {
- this.$refs['elForm'].validate(valid => {
- if (valid) {
- this.btnLoading = true
- request({
- params: {
- r: 'store/client/specs/add',
- },
- method: 'post',
- data: this.attr,
- }).then(e => {
- if (e.data.code === 0) {
- this.$message.success(e.data.msg)
- setTimeout(() => {
- this.dialogVisible = false
- this.getAttrList()
- }, 1500)
- } else {
- this.$message.error(e.data.msg)
- }
- this.btnLoading = false
- }).catch(e => {
- this.btnLoading = false
- })
- }
- })
- },
- tagIsLimit(values) {
- return values.length > this.tagLimit
- },
- editSpecs(row) {
- this.dialogTitle = '编辑规格'
- // this.btnLoading = true
- this.attr = row
- this.dialogVisible = true
- },
- delSpecs(id) {
- this.$confirm('此操作将永久删除, 是否继续?', '提示', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning'
- }).then(() => {
- this.btnLoading = true
- request({
- params: {
- r: 'store/client/specs/del',
- id: id
- },
- method: 'get',
- }).then(e => {
- if (e.data.code === 0) {
- this.$message.success(e.data.msg)
- setTimeout(() => {
- this.getAttrList()
- }, 1500)
- } else {
- this.$message.error(e.data.msg)
- }
- this.btnLoading = false
- }).catch(e => {
- this.btnLoading = false
- })
- })
- },
- },
- mounted: function() {
- this.page = getQuery('page') ? getQuery('page') : 1
- this.limit = getQuery('limit') ? getQuery('limit') : 20
- this.getAttrList()
- }
- });
- </script>
- <style>
- .el-dialog__body {
- padding: 30px 20px;
- }
- .attrs-item + .attrs-item {
- margin-top: 5px;
- }
- .attrs-item {
- display: flex;
- align-items: center;
- }
- .item-button {
- margin-left: 5px;
- }
- .tag-item + .tag-item {
- margin-left: 3px;
- }
- </style>
|