doum
15 小时以前 25538c1063d1e9a2d8dac1b813d43e7d8fb18e3f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<template>
  <GlobalAlertWindow
    v-loading="isUploading"
    :title="title"
    :visible.sync="visible"
    :confirm-working="isWorking"
    @confirm="confirm"
  >
    <el-form :model="form" ref="form" :rules="rules" label-width="120px" label-suffix=":"   >
      <el-form-item label="名称" prop="name">
        <el-input v-model="form.name" placeholder="请输入名称" :maxlength="5" v-trim/>
      </el-form-item>
      <el-form-item label="展示图" prop="imgurlfull">
        <UploadAvatarImage
          :file="{ 'imgurlfull': form.imgFullurl, 'imgurl': form.imgurl }"
          :upload-data="{folder:'labels'}"
          @uploadSuccess="uploadAvatarSuccess"
          @uploadEnd="isUploading=false"
          @uploadBegin="isUploading = true"
        />
      </el-form-item>
      <el-form-item label="选中商品" prop="applyIdList" >
        <span style="font-size: 12px;color: #216EEE"   @click="selectGoods">已指定【 {{applyDataList.length}} 】件商品</span>
        <el-button style="margin-left:30px;display: inline-block;width: 80px;" type="primary"  @click="selectGoods">去选择 </el-button>
      </el-form-item>
      <el-form-item label="排序码" prop="sortnum">
        <el-input type="number" v-model="form.sortnum" placeholder="请输入排序码" v-trim/>
      </el-form-item>
      <el-form-item label="备注" prop="info">
        <el-input type="textarea" v-model="form.info" placeholder="请输入备注" :maxlength="200" v-trim/>
      </el-form-item>
    </el-form>
    <OperaCouponGoodsWindow ref="OperaCouponGoodsWindow" @success="doSelect"/>
  </GlobalAlertWindow>
</template>
 
<script>
import BaseOpera from '@/components/base/BaseOpera'
import GlobalAlertWindow from '@/components/common/GlobalAlertWindow'
import UploadAvatarImage from '@/components/common/UploadAvatarImage'
import OperaCouponGoodsWindow from '@/components/business/OperaCouponGoodsWindow'
import {allList as goodsList} from "@/api/business/goods";
export default {
  name: 'OperaLabelsWindow',
  extends: BaseOpera,
  components: { GlobalAlertWindow, UploadAvatarImage ,OperaCouponGoodsWindow},
  data () {
    return {
      isUploading: false,
      // 表单数据
      form: {
        id: null,
        name: '',
        info: '',
        type: null,
        status: '',
        parentId: null,
        sortnum: null,
        imgFullurl: null,
        applyIdList:[],
        imgurl: ''
      },
      applyDataList:[],
      // 验证规则
      rules: {
        parentId: [{ required: true, message: '请选择所属品牌'  }],
        name: [{ required: true, message: '请输入名称', tigger: 'blur' }]
      }
    }
  },
  inject: ['labels'],
  created () {
    this.config({
      api: '/business/labels',
      'field.id': 'id'
    })
  },
  methods: {
    selectGoods () {
      this.$refs.OperaCouponGoodsWindow.open('选择商品', this.applyDataList)
    },
    doSelect (rows) {
      console.log(rows, this.applyDataList)
      this.applyDataList = []
      this.form.applyIdList = []
      if (rows && rows.length) {
        rows.forEach(item => {
          this.applyDataList.push(item)
          this.form.applyIdList.push(item.id)
        })
      }
      this.$refs.form.clearValidate();
    },
    open (title, target, type) {
      this.title = title
      this.visible = true
      this.applyDataList = []
      this.form.applyIdList = []
      this.form.imgFullurl =null
      this.form.imgurl =null
      this.goods = []
      // 新建
      if (target == null) {
        this.$nextTick(() => {
          this.$refs.form.resetFields()
          this.form.provinceId = ''
          this.form[this.configData['field.id']] = null
          this.form.type = type
        })
        return
      }
      // 编辑
      this.$nextTick(() => {
        for (const key in this.form) {
          this.form[key] = target[key]
        }
        this.form.type = type
        this.loadSelectGoods()
      })
    },
    loadSelectGoods () {
      goodsList({
        zhuanquId: this.form.id // 商品分类
      }).then(res => {
        this.applyDataList = res || []
        this.applyDataList.forEach(t => {
          this.form.applyIdList.push(t.id)
        })
      })
    },
    // 上传图片
    uploadAvatarSuccess (file) {
      this.form.imgurl = file.imgurl
      this.form.imgFullurl = file.imgurlfull
    }
  }
}
</script>
 
<style lang="scss" scoped>
@import "@/assets/style/alertstyle.scss";
$image-width: 100px;
 
::v-deep .el-select {
    width: 100%;
    .el-input__inner {
      width: 100%;
    }
  }
.avatar-uploader {
  width: $image-width;
  height: $image-width;
}
::v-deep .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  width: $image-width;
  height: $image-width;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409EFF;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: $image-width;
  height: $image-width;
  line-height: $image-width;
  text-align: center;
}
.avatar {
  width: $image-width;
  height: $image-width;
  display: block;
}
</style>