| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- <template>
- <div class="clearfix">
- <a-row>
- <a-col>商品大图</a-col>
- <a-col>
- <a-upload
- action="/rooms/cesGoods/modify"
- list-type="picture-card"
- :file-list="fileList"
- @preview="handlePreview"
- @change="handleChange"
- >
- <div v-if="fileList.length < 1">
- <a-icon type="plus" />
- <!-- <div class="ant-upload-text">Upload</div> -->
- </div>
- </a-upload>
- </a-col>
- </a-row>
- <a-row>
- <a-col>图片</a-col>
- <a-col>
- <a-upload
- action="#"
- list-type="picture-card"
- :file-list="fileListImgs"
- @preview="handlePreview"
- @change="handleChangeImgs"
- >
- <div v-if="fileList.length < 8">
- <a-icon type="plus" />
- <!-- <div class="ant-upload-text">Upload</div> -->
- </div>
- </a-upload>
- </a-col>
- </a-row>
- <a-button @click="submitImg">确认</a-button>
- <a-modal :visible="previewVisible" :footer="null" @cancel="handleCancel">
- <img alt="example" style="width: 100%" :src="previewImage" />
- </a-modal>
- </div>
- </template>
- <script>
- function getBase64(file) {
- return new Promise((resolve, reject) => {
- const reader = new FileReader();
- reader.readAsDataURL(file);
- reader.onload = () => resolve(reader.result);
- reader.onerror = (error) => reject(error);
- });
- }
- import { httpAction, getAction } from "@/api/manage";
- export default {
- inject:['modelData'],
- data() {
- return {
- previewVisible: false,
- previewImage: "",
- fileList: [],
- fileListImgs: [],
- model: {
- id: "",
- hotelId: 0,
- goodType: "",
- goodUnit: "",
- barCode: "",
- bid: null,
- name: "",
- sellingPrice: "",
- purchases: null,
- salesVolume: null,
- inventory: null,
- appState: false,
- canStoreCard: false,
- canIntegralPay: false,
- },
- url: {
- edit: "/rooms/cesGoods/modify",
- },
- };
- },
- created(){
- console.log(this.model);
- },
- methods: {
- getStartData(){
- this.model = this.modelData
- if (this.model.cover) {
- this.fileList.push(this.model.cover);
- }
- if (this.model.images) {
- this.fileListImgs = this.model.images.split(",");
- }
- },
- handleCancel() {
- this.previewVisible = false;
- },
- async handlePreview(file) {
- if (!file.url && !file.preview) {
- file.preview = await getBase64(file.originFileObj);
- }
- this.previewImage = file.url || file.preview;
- this.previewVisible = true;
- },
- handleChange({ fileList }) {
- console.log(fileList);
- this.fileList = fileList;
- },
- handleChangeImgs({ fileList }) {
- console.log(fileList);
- this.fileListImgs = fileList;
- },
- edit(record) {
- console.log(22222222, record);
- this.model = JSON.parse(JSON.stringify(record));
- if (this.model.cover) {
- this.fileList.push(this.model.cover);
- }
- if (this.model.images) {
- this.fileListImgs = this.model.images.split(",");
- }
- // console.log(this.filterType(this.treeData, record.goodType));
- // console.log(this.arr);
- this.visible = true;
- // getSelectList({
- // id: this.model.id,
- // }).then((res) => {
- // if (res.success) {
- // this.members = res.result;
- // }
- // });
- },
- //修改图片
- submitImg() {
- const that = this;
- that.confirmLoading = true;
- let httpurl = "";
- let method = "";
- httpurl += this.url.edit;
- method = "put";
- if (this.model.payFlag == 0) {
- this.model.payAmount = 0;
- }
- this.model.cover = this.fileList[0].thumbUrl;
- let arr=[]
- this.fileListImgs.forEach(ele=>{
- arr.push(ele.thumbUrl)
- })
- this.model.images = arr.toString()
- httpAction(httpurl, this.model, method)
- .then((res) => {
- if (res.success) {
- that.$message.success(res.message);
- that.$emit("ok");
- } else {
- that.$message.warning(res.message);
- }
- })
- .finally(() => {
- that.confirmLoading = false;
- });
- },
- submitForm() {
- const that = this;
- // 触发表单验证
- debugger;
- this.$refs.form.validate((valid) => {
- if (valid) {
- that.confirmLoading = true;
- let httpurl = "";
- let method = "";
- if (!this.model.id) {
- httpurl += this.url.add;
- method = "post";
- } else {
- httpurl += this.url.edit;
- method = "put";
- }
- if (this.model.payFlag == 0) {
- this.model.payAmount = 0;
- }
- httpAction(httpurl, this.model, method)
- .then((res) => {
- if (res.success) {
- that.$message.success(res.message);
- that.$emit("ok");
- } else {
- that.$message.warning(res.message);
- }
- })
- .finally(() => {
- that.confirmLoading = false;
- });
- }
- });
- },
- },
- };
- </script>
- <style>
- /* you can make up upload button and sample style by using stylesheets */
- .ant-upload-select-picture-card i {
- font-size: 32px;
- color: #999;
- }
- .ant-upload-select-picture-card .ant-upload-text {
- margin-top: 8px;
- color: #666;
- }
- </style>
|