| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303 |
- <?php
- use common\helpers\ComponentHelper;
- ComponentHelper::loadComponentView('com-dialog-select');
- ?>
- <div id="app" v-cloak>
- <el-card class="box-card" shadow="never" style="border:0;min-width: 1000px;" body-style="background-color: #f3f3f3;padding: 10px 0 0;">
- <div slot="header">
- <div>
- <span>商品设置</span>
- </div>
- </div>
- <div class="form_box">
- <el-form :model="formData" :rules="rules" size="small" ref="ruleForm" label-width="160px" v-loading="loading">
- <el-card shadow="never">
- <div>
- <el-row>
- <el-col :span="16">
- <el-form-item label="选择商品:" required label-width="160px">
- <com-dialog-select :multiple="true" :extra-search="{from:'lucky_group'}" @selected="goodsSelect" title="商品选择">
- <el-button type="primary">选择商品</el-button>
- </com-dialog-select>
- <el-table max-height="400" :data="goods_list" size="small" stripe border style="width: 100%;margin-top: 20px;">
- <el-table-column type="index" label="序号" align="center" width="60">
- </el-table-column>
- <el-table-column prop="goods_id" label="商品id" align="center" min-width="80">
- </el-table-column>
- <el-table-column label="商品信息" min-width="150">
- <template slot-scope="scope">
- <div style="display: flex;align-items: center;">
- <el-image fit="cover" :src="scope.row.cover_pic" style="width: 40px;height: 40px;display: block;margin-right: 5px;flex-shrink: 0;"></el-image>
- <div>
- <div>{{scope.row.goods_name}}</div>
- </div>
- </div>
- </template>
- </el-table-column>
- <el-table-column prop="price" label="售价(元)" align="center" min-width="80">
- </el-table-column>
- <el-table-column label="商品状态" align="center" min-width="80">
- <template slot-scope="scope">
- <el-tag type="success" effect="dark" v-if="scope.row.status == 1">销售中</el-tag>
- <el-tag type="danger" effect="dark" v-else>下架</el-tag>
- </template>
- </el-table-column>
- <el-table-column prop="goods_stock" label="库存" align="center" min-width="80">
- </el-table-column>
- <el-table-column prop="num" label="操作" align="center" min-width="80">
- <template slot-scope="scope">
- <el-button type="danger" @click="delFun(scope.$index)">删除</el-button>
- </template>
- </el-table-column>
- </el-table>
- </el-form-item>
- <el-form-item label="抽取交易额:" required label-width="160px">
- <el-input placeholder="请输入百分比" style="width: 200px;" v-model="formData.price" onkeyup="value=value.replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1')">
- <template slot="append">%</template>
- </el-input>
- </el-form-item>
- </el-col>
- </el-row>
- </div>
- </el-card>
- </el-form>
- <el-button :loading="btnLoading" class="button-item" type="primary" style="margin-top: 24px;" @click="save" size="small">
- 保存
- </el-button>
- </div>
- </el-card>
- </div>
- <script>
- const app = new Vue({
- el: '#app',
- data() {
- return {
- formData: {
- goods_ids: '',
- price:0
- },
- loading: false,
- btnLoading: false,
- goods_list: [],
- rules: {},
- cateLists: [{
- id: 1,
- sort: 1,
- title: '分类1'
- }],
- }
- },
- created() {
- this.id = getQuery('id');
- },
- mounted: function() {
- this.loadData(this.id);
- },
- methods: {
- // 选中商品处理
- goodsSelect(param) {
- for (let j in param) {
- let item = param[j];
- let flag = true;
- for (let i in this.goods_list) {
- if (this.goods_list[i].goods_id == item.id) {
- flag = false;
- break;
- }
- }
- if (flag) {
- this.goods_list.push({
- goods_id: item.id,
- price: item.price,
- status: item.status,
- goods_stock: item.stock,
- goods_name: item.goods_name,
- cover_pic: item.cover_pic,
- });
- }
- }
- },
- // 删除商品
- delFun(index) {
- this.goods_list.splice(index, 1)
- },
- save() {
- let arr = []
- let arrs = []
- let forNum = this.goods_list.length;
- for (let i = 0; i < forNum; i++) {
- let item = this.goods_list[i];
- arr.push(item.goods_id)
- }
- this.formData.goods_ids = arr.join(',');
- this.formData.percent = Math.abs(this.formData.percent);
- // console.log(this.formData);return null;
- this.$refs['ruleForm'].validate((valid) => {
- if (valid) {
- if (!this.formData.goods_ids) return this.$message.error("请选择商品");
- if (this.btnLoading) return;
- this.btnLoading = true;
- request({
- params: {
- r: 'boss-three/default/goods',
- id: this.id
- },
- method: 'post',
- data: this.formData
- }).then(e => {
- this.btnLoading = false;
- if (e.data.code == 0) {
- this.$navigate({
- r: 'boss-three/default/goods',
- id: this.id
- })
- this.$message.success(e.data.msg);
- } else {
- this.btnLoading = false;
- this.$message.error(e.data.msg);
- }
- }).catch(e => {
- console.log(e);
- this.$message.error('网络错误');
- this.btnLoading = false;
- })
- } else {
- this.$message.error('请填写必要的参数!');
- return false;
- }
- });
- },
- loadData(id) {
- if (this.loading === true) return;
- this.loading = true;
- request({
- params: {
- r: 'boss-three/default/goods',
- id: id
- },
- method: 'get'
- }).then(e => {
- // console.log('======== loadData result: ', e);
- this.loading = false;
- if (e.data.code == 0) {
- this.goods_list = e.data.data.goods_list;
- this.formData.price = e.data.data.data.price;
- }
- }).catch(e => {
- this.loading = false;
- })
- },
- },
- });
- </script>
- <style>
- .form_box {
- /* background-color: #f3f3f3;
- padding: 0 0 20px; */
- background-color: #fff;
- padding: 20px;
- }
- .button-item {
- margin-top: 12px;
- padding: 9px 25px;
- }
- .el-input-group__append {
- background-color: #fff;
- color: #353535;
- }
- .el-card__body {
- padding: 0;
- }
- .el-card {
- border: none;
- }
- .el-table thead {
- font-size: 14px;
- color: #333;
- }
- /* .el-table__footer-wrapper, .el-table__header-wrapper{
- border-bottom: 1.4px solid #D6D6D6;
- } */
- .dialogClass .el-dialog__body {
- padding-bottom: 0;
- }
- .el-date-editor .el-range-separator {
- /* 设置选择日期框的中间的 ‘至’ 的宽度 */
- width: 8%;
- }
- .el-textarea__inner {
- display: block;
- resize: vertical;
- padding: 5px 15px !important;
- }
- .el-input-number .el-input__inner {
- text-align: left;
- }
- /* .edui-default .edui-editor{
- height: 250px;
- } */
- </style>
|