123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- <template>
- <el-form :model="form" ref="queryForm" size="small" :rules="rules" :inline="true" label-width="120px">
- <el-row>
- <el-col :span="24">
- <el-form-item prop="spuDesc">
- <span slot="label">商品介绍</span>
- <el-input
- style="width: 700px"
- type="textarea"
- :rows="3"
- placeholder="请输入商品介绍"
- v-model="form.spuDesc"
- @input="passValue"
- >
- </el-input>
- </el-form-item>
- </el-col>
- <el-col :span="24">
- <el-form-item label="商品详情图" prop="spuName">
- <span class="tips">最多可上传10张</span>
- <el-upload
- list-type="picture-card"
- :file-list="spuDetailList"
- :before-remove="requestRemove"
- :http-request="(data) => requestUpload(data, 'detail')"
- :show-file-list="true"
- :limit="10"
- action="#"
- :multiple="true"
- accept=".png,.jpg,.jpeg"
- ref="files"
- >
- <i class="el-icon-plus avatar-uploader-icon"></i>
- </el-upload>
- </el-form-item>
- </el-col>
- <el-col :span="24">
- <el-form-item label="特殊资质图" prop="spuName">
- <span class="tips">例如农残检测报告等,最多可上传10张</span>
- <el-upload
- list-type="picture-card"
- :file-list="specialList"
- :before-remove="requestRemove1"
- :http-request="(data) => requestUpload(data, 'zz')"
- :show-file-list="true"
- :limit="10"
- action="#"
- :multiple="true"
- accept=".png,.jpg,.jpeg"
- ref="files"
- >
- <i class="el-icon-plus avatar-uploader-icon"></i>
- </el-upload>
- </el-form-item>
- </el-col>
- <el-col :span="24">
- <el-form-item prop="spuStatus">
- <span slot="label"> 发布状态</span>
- <el-radio-group v-model="form.spuStatus">
- <el-radio :label="0" :value="0">上架</el-radio>
- <el-radio :label="1" :value="1">下架</el-radio>
- </el-radio-group>
- </el-form-item>
- </el-col>
- </el-row>
- </el-form>
- </template>
- <script>
- import { getToken } from "@/utils/auth";
- import axios from "axios";
- export default {
- props: ["data"],
- data() {
- return {
- form: {
- spuDetailList: [],
- specialList: [],
- spuDesc: "",
- spuStatus: 0,
- },
- headers: { Auth: "Bearer " + getToken(), "Content-type": "multipart/form-data" },
- spuDetailList: [],
- specialList: [],
- index: 0,
- index1: 0,
- rules: {
- spuDesc: [{ required: true, message: "商品介绍不能为空", trigger: "blur" }],
- spuStatus: [{ required: true, message: "发布状态不能为空", trigger: "blur" }],
- },
- };
- },
- watch: {
- //监听info对象
- data: {
- handler(newVal, oldVal) {
- //监听info对象变化
- if (newVal) {
- this.form.spuDesc = newVal.spuDesc;
- this.spuDetailList = [];
- this.specialList = [];
- if (newVal.spuDetailList) {
- newVal.spuDetailList.forEach((e) => {
- this.spuDetailList.push({
- url: e.fileUrl,
- id: e.id,
- sort: e.sort,
- });
- });
- }
- if (newVal.specialList) {
- newVal.specialList.forEach((e) => {
- this.specialList.push({
- url: e.fileUrl,
- id: e.id,
- sort: e.sort,
- });
- });
- }
- }
- },
- deep: true, //深度监听
- immediate: true,
- },
- },
- methods: {
- formvalidate() {
- let that=this
- return new Promise((resolve) => {
- that.$refs.queryForm.validate((valid) => {
- console.log(valid);
- if (valid) {
- resolve(valid);
- } else {
- resolve(valid);
- }
- });
- });
- },
- passValue() {
- if (this.specialList) {
- this.form.specialList = [];
- for (let index = 0; index < this.specialList.length; index++) {
- this.form.specialList.push({
- fileUrl: this.specialList[index].url,
- sort: this.specialList[index].name,
- });
- }
- }
- if (this.spuDetailList) {
- this.form.spuDetailList = [];
- for (let index = 0; index < this.spuDetailList.length; index++) {
- this.form.spuDetailList.push({
- fileUrl: this.spuDetailList[index].url,
- sort: this.spuDetailList[index].name,
- });
- }
- }
- this.$emit("updateValue", this.form);
- },
- requestRemove1(val) {
- this.specialList.forEach((e, index) => {
- if (e.uid == val.uid) {
- this.specialList.splice(index, 1);
- }
- });
- this.passValue();
- },
- requestRemove(val) {
- this.spuDetailList.forEach((e, index) => {
- if (e.uid == val.uid) {
- this.spuDetailList.splice(index, 1);
- }
- });
- this.passValue();
- },
- // 可以获取图片参数
- async requestUpload(data, type) {
- const formdata = new FormData();
- formdata.append("file", data.file);
- const res = await axios.post(
- `${process.env.VUE_APP_NSY_UPLOAD_API}/api/third/op/v1/third/uploadPic`,
- formdata,
- {
- headers: this.headers,
- }
- );
- if (res.data.data) {
- if (type == "detail") {
- this.spuDetailList.push({
- name: this.index,
- url: res.data.data,
- });
- this.index++;
- } else if (type == "zz") {
- this.specialList.push({
- name: this.index1,
- url: res.data.data,
- });
- this.index1++;
- }
- this.passValue();
- this.$forceUpdate();
- }
- },
- },
- };
- </script>
- <style></style>
|