index_20220719153803.vue 16.3 KB
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 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576
<template>
  <div class="good-page">
    <div class="good-search" v-if="!isShowGoods">
      <div>
        <a-radio-group v-model:value="status">
          <a-radio-button value="0" class="status" @click="onSearch"
            >全部</a-radio-button
          >
          <a-radio-button value="1" class="status" @click="onSearch"
            >正常</a-radio-button
          >
          <a-radio-button value="2" class="status" @click="onSearch"
            >已下架</a-radio-button
          >
        </a-radio-group>
        <a-input-search
          v-model:value="value"
          placeholder="请输入商品名称"
          style="width: 200px; margin-left: 10px"
          @search="onSearch"
        />
      </div>
      <div class="good-cad">
        <a-button type="primary" class="mr10" @click="onGoods(0)"
          >新建商品</a-button
        >
        <a-button type="primary" @click="onGoods(1)">新建商品包</a-button>
      </div>
    </div>
    <div class="goods-list" v-if="!isShowGoods">
      <a-table :columns="columns" :data-source="list">
        <template #bodyCell="{ column, record }">
          <template v-if="column.key === 'tags'">
            <a-button type="primary" @click="onEdit(record)">编辑</a-button>
            <a-button type="primary" style="margin-left: 20px">统计</a-button>
            <a-popconfirm
              title="确定删除这条数据"
              ok-text="确定"
              cancel-text="取消"
              @confirm="onDel(record)"
            >
              <a-button type="primary" style="margin-left: 20px">删除</a-button>
            </a-popconfirm>
          </template>
        </template>
      </a-table>
    </div>
    <div v-if="isShowGoods">
      <div
        style="
          display: flex;
          align-items: center;
          justify-content: space-between;
        "
        v-if="isShowGoods"
      >
        <a-button class="small left" @click="onBack">
          <template #icon>
            <LeftOutlined />
          </template>
        </a-button>
      </div>
      <GoodsBags
        :props="{ propsData }"
        v-if="propsData.isCad == 0"
        @onBack="onBack"
      ></GoodsBags>
      <GoodsBagSubs :props="{ propsData }" v-else @onBack="onBack">
      </GoodsBagSubs>
    </div>
    <a-modal
      v-model:visible="visible"
      title="编辑"
      :confirm-loading="confirmLoading"
      :width="1000"
      @ok="handleOk"
      @Cancel="handleCancel"
    >
      <a-form
          :model="modelRef"
          name="basic"
          :label-col="{ span: 2 }"
          :wrapper-col="{ span: 8 }"
          autocomplete="off"
        >
  
        <a-form-item
          label="商品名称"
          name="商品名称"
          :rules="[{ required: true, message: '请输入商品名称!' }]"
          :label-col="{ span: 2 }"
        >
          <a-input v-model:value="modelRef.subject" />
        </a-form-item>

         <a-form-item
          label="商品简介"
          name="商品简介"
          :rules="[{ required: true, message: '请输入商品简介!' }]"
          :label-col="{ span: 2 }"
        >
          <a-input v-model:value="modelRef.shortname" />
        </a-form-item>

       <a-form-item label=" 商品示图" name="picurl" 
        :wrapper-col="{ offset: 0, span: 8 }" class="Up" labelAlign="left" :label-col="{ span: 2}" >
        <div class="clearfix">
          <a-upload class="clearfix-up" v-model:file-list="fileList" action="/api/file/upload" list-type="picture-card"
            :maxCount="1" @preview="handlePreview" @change="handleChange" :before-upload="beforeUpload">
            <div v-if="fileList.length < 8">
              <plus-outlined />
              <div style="margin-top: 8px">Upload</div>
            </div>
          </a-upload>
            <img alt="example" style="width: 100%" :src="modelRef.picurl" />
          
          <div>
            <p class="warin">
              建议图片比例为4:3,大小不超过200M,图片仅支持JPG、JPEG、PNG格式
            </p>
          </div>
        </div>
      </a-form-item>
       <a-form-item label="商品详情" name="body"  labelAlign="left" :label-col="{ span: 2 }">
          <div style="position: relative;">
                    <div style="position: absolute;right: 26%;height: 30px;width: 30px;">
                        <a-upload class="clearfix-up-1" action="/api/file/upload" list-type="picture-card" :maxCount="1"
                        @preview="onHandlePreview" @change="onEdithandleChange" :before-upload="onBeforeUpload">
                        <div style="width:30px;height:30px;border: none;"><i class="iconfont icon-tupian"
                            style="font-size:28px;"></i> </div>
                        </a-upload>
                    </div>

                    <QuillEditor style="height:200px" ref="myQuillEditor" :options="options" :content="modelRef.body"
                        content-type="html" @update:content="textChange" @focus="onEditorFocus($event)" @blur="onEditorBlur($event)"
                        @change="onEditorChange($event)" />
                    </div>
        <div class="editor-text">
          <p>1、商品描述需符合《中华人民共和国广告法》</p>
          <p>
            2、详情图片宽度750,高度不超过5000,每张图片最大不超过1M,图片仅支持JPG、JPEG、PNG格式。
          </p>
        </div>
      </a-form-item>
      <a-form-item label="选择商品" :wrapper-col="{ offset: 0, span: 8 }" name="sub"  :label-col="{ span: 2}" v-if="modelRef.parent == 0">
                <div style="width:100%;display: flex;align-items: center;">
                    <a-select v-model:value="modelRef.sub" mode="multiple" style="width: 100%" placeholder="请选择商品"  >
                       <a-select-option   v-for="item in optionss" :itemKey="item" :value="item.goodsid" :label="item.goodsid">
                       {{item.subject}}
                        </a-select-option>
                    </a-select>
                    <a-button type="primary"  style="margin-left:20px;">
                        添加
                    </a-button>
                    <div class="please">请添加至少两个商品</div>
                </div>
            </a-form-item>
      <a-form-item name="price" :wrapper-col="{ offset: 0, span: 4 }" label="商品售价"
        :rules="[{ required: true, message: '请输入输入价格' }]" labelAlign="left" :label-col="{ span: 2 }">
        <div>
          <a-radio-group v-model:value="modelRef.sellingmodel" @change="onSelectPlain" >
            <a-radio value="0">免费</a-radio>
            <a-radio value="1">收费</a-radio>
          </a-radio-group>
        </div>
      </a-form-item>

      <a-form-item :wrapper-col="{ offset:2, span: 7 }" >
        <div style="display:flex;">
          <div style="margin-right:20px">划线价</div>
          <a-input-number  style="width: 200px" :min="0" :max="10" :step="0.01"
            string-mode  v-model:value="modelRef.markingprice" />
        </div>
      </a-form-item>
      <a-form-item name="price" :wrapper-col="{ offset: 2, span: 7 }" :rules="[{ required: true, message: '请输入商品价格!' }]">
        <div style="display:flex;">
          <div style="margin-right:20px">售卖价</div>
          <a-input-number style="width: 200px" :min="0" :max="10" :step="0.01"
            string-mode v-model:value="modelRef.price" />
        </div>
      </a-form-item>
      </a-form>
    </a-modal>
  </div>
</template>
<script lang="ts" setup>
import { ref, reactive, defineExpose, onMounted } from "vue";
import { LeftOutlined} from "@ant-design/icons-vue";
import GoodsBags from "./components/goods/index.vue";
import GoodsBagSubs from "./components/goodsubs/index.vue";
import { onSelectGoods, onfindby, onUpdateGoods } from "@/api/index";
import { getUid } from "@/utils/userInfo";
import { Form ,message,Upload } from 'ant-design-vue';
import { QuillEditor } from '@vueup/vue-quill'
import '@vueup/vue-quill/dist/vue-quill.snow.css';

const useForm = Form.useForm;
const myQuillEditor = ref(null);
const textarea = ref<any>('')
const columns = [
  {
    title: "商品编号",
    dataIndex: "goodsid",
    key: "goodsid",
  },
  {
    title: "商品名称",
    dataIndex: "subject",
    key: "subject",
  },
  {
    title: "商品类型",
    dataIndex: "sellingmodel",
    key: "sellingmodel",
  },
  {
    title: "商品售卖数",
    key: "markingprice",
    dataIndex: "markingprice",
  },
  {
    title: "默认金额售卖数",
    key: "price",
    dataIndex: "price",
  },
  {
    title: "已售金额",
    key: "price",
    dataIndex: "price",
  },
  {
    title: "商品状态",
    key: "status",
    dataIndex: "status",
  },
  {
    title: "操作",
    key: "tags",
    dataIndex: "tags",
  },
];
interface props {
  isCad: Number;
}
let options = reactive({
    modules: {
        toolbar: {
            container: [
                [{ size: ["small", false, "large"] }],
                ["bold", "italic", "underline"],
                [{ header: 1 }, { header: 2 }],
                [{ list: "ordered" }, { list: "bullet" }],
                ["link", "image"],
                [{ color: [] }, { background: [] }],
                [{ align: [] }],
            ],
            handlers: {
                image: function (value: any) {
                    if (value) {
                        // 调用element图片上传
                        // document.querySelector(".editor-img-uploader>.el-upload").click();
                    } else {
                        Quill.format("image", true);
                    }
                },
            },
        },
        history: {
            delay: 1000,
            maxStack: 50,
            userOnly: false,
        },
    },
});
const optionss = ref([])
const previewTitle = ref("");
const list = ref<Array<Object>>([]);
const value = ref<string>("");
const status = ref<string>("0");
const previewImage = ref("");
const previewVisible = ref(true);
let modelRef = ref<any>({});
const propsData = reactive<props>({
  isCad: 0,
});
let isEditfileList = ref<UploadProps["fileList"]>([
]);
const fileList = ref<UploadProps["fileList"]>([
]);

const isShowGoods = ref<Boolean>(false);
const modalText = ref<string>("Content of the modal");
const visible = ref<boolean>(false);
const confirmLoading = ref<boolean>(false);

const showModal = () => {
  visible.value = true;
};
const handleOk = async() => {
  const uid =getUid()
  const prarms = {
    uid:uid,
    goodsid:modelRef.value.goodsid,
    tenantid:modelRef.value.tenantid,
    goods_package_id:modelRef.value.parent,
    subject: modelRef.value.subject,
    shortname: modelRef.value.shortname,
    picurl:modelRef.value.picurl,
    body:modelRef.value.body,
    price: modelRef.value.price,
    markingprice:modelRef.value.markingprice,
    status: modelRef.value.status,
    parent: modelRef.value.parent,
    free:modelRef.value.sellingmodel,
    sub: [0]
  }
  const data = await onUpdateGoods(prarms);
  console.log(data);
  if(data.state === 1){
    visible.value = false;
    modelRef.value = {}
   await init();
  }
};
const handleCancel = ()=>{
 visible.value = false;
  modelRef.value = {}
}
const onSearch = async () => {
  const params = {
    status: status.value,
    name: value.value,
    uid: getUid(),
  };
  const data = await onfindby(params);
  list.value = data.data;
};
const onGoods = (e: Number) => {
  propsData.isCad = e;
  isShowGoods.value = true;
};
const onBack = async (e: Number) => {
  isShowGoods.value = !isShowGoods.value;
  const uid = getUid();
  const data = await onSelectGoods(uid);
  list.value = data.data;
};
const onEdit =(e: any) => {
  visible.value = !visible.value;
  modelRef.value = e
};
const { resetFields, validate, validateInfos } = useForm(
  modelRef,
  reactive({
    subject: [
      {
        required: true,
        message: "请输入商品名称",
      },
    ],
  })
);
const onSelectPlain = (e: any) => {
  if(e.target.value === '0'){
    modelRef.value.price = "0"
    // free 0
    modelRef.value.sellingmodel= e.target.value;
  }


};
const onSubmit = () => {
  validate()
    .then((res) => {
      console.log(res, toRaw(modelRef));
    })
    .catch((err) => {
      console.log("error", err);
    });
};
const reset = () => {
  resetFields();
};
const onDel = async (e: any) => {
  const uid = getUid();
  e.status = "1";
  e.uid = uid
  const data = await onUpdateGoods(e);
  await init();
};
const init = async () => {
  const uid = getUid();
  const data = await onSelectGoods(uid);
   const datas = await onSelectGoods(uid)
    optionss.value = datas.data
  list.value = data.data;
};
const textChange = (e: any) => {
  textarea.value = e
  console.log(e, '98', textarea.value);
}
const onEditorFocus = (e: any) => {

}
const onEditorBlur = (e: any) => {

}
const onEditorChange = (e: any) => {
  console.log(e.html, 'e');
}
const onHandlePreview = async (file: any) => {
  if (!file.url && !file.preview) {
    file.preview = (await getBase64(file.originFileObj)) as string;
  }
  previewImage.value = file.url || file.preview;
  previewVisible.value = true;
  previewTitle.value =
    file.name || file.url.substring(file.url.lastIndexOf("/") + 1);
};
const onEdithandleChange = (info: any) => {
  let resFileList = [...info.fileList];
  resFileList = resFileList.slice(-2);
  resFileList = resFileList.map((file) => {
    if (file.response) {
      return file;
    }
  });
  if (!!resFileList) {
    isEditfileList.value = resFileList;
  }
};
const onBeforeUpload: UploadProps['beforeUpload'] = file => {
  if (!(file.type.includes('png') || file.type.includes('jpeg') || file.type.includes('jpg'))) {
    message.error(`${file.name}不是png/jpef/jpg格式`);
    return Upload.LIST_IGNORE;
  }
};
const handlePreview = async (file: any) => {
  if (!file.url && !file.preview) {
    file.preview = (await getBase64(file.originFileObj)) as string;
  }
  previewImage.value = file.url || file.preview;
  previewVisible.value = true;
  previewTitle.value =
    file.name || file.url.substring(file.url.lastIndexOf("/") + 1);
};
const beforeUpload: UploadProps['beforeUpload'] = file => {
  if (!(file.type.includes('png') || file.type.includes('jpeg') || file.type.includes('jpg'))) {
    message.error(`${file.name}不是png/jpef/jpg格式`);
    return Upload.LIST_IGNORE;
  }
};
const handleChange = (info: any) => {
  let resFileList = [...info.fileList];

  // 1. Limit the number of uploaded files
  //    Only to show two recent uploaded files, and old ones will be replaced by the new
  resFileList = resFileList.slice(-2);

  // 2. read from response and show file link
  resFileList = resFileList.map((file) => {
    if (file.response) {
      console.log(123132);
      
      // Component will show file.url as link
      modelRef.picurl = file.response.data;
    }

    return file;
  });

  fileList.value = resFileList;
};
onMounted(async () => {
  await init();
});
defineExpose({
  status,
  value,
  columns,
  previewImage,
  isShowGoods,
  propsData,
  modalText,
  visible,
  confirmLoading,
  validateInfos,
  modelRef,
  optionss,
  options,
  isEditfileList,
  previewVisible,
  textarea,
  textChange,
  onEditorFocus,
  beforeUpload,
  onEditorChange,
  onEditorBlur,
  onSelectPlain,
  reset,
  onSubmit,
  showModal,
  handleOk,
  handleCancel,
  onBack,
  onSearch,
  onGoods,
  onEdit,
  onDel,
  init,
  handlePreview,
  onHandlePreview,
  onEdithandleChange,
  onBeforeUpload,
  handleChange,

});
</script>
<style lang="less" scoped>
.good-page {
  .good-search {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    .status {
      margin-right: 20px;
      width: 80px;
      border-radius: 5px;
      border: 1px solid rgba(0, 0, 0, 0.65);
    }
    .status::before {
      display: none;
    }
    .ant-radio-button-wrapper-checked {
      border: 1px solid @primary-color;
    }
    .ood-cad {
      width: 100%;
    }

    .ml10 {
      margin-left: 10px;
    }

    .mr10 {
      margin-right: 10px;
    }
  }

  .goods-list {
    margin-top: 10px;
  }

  .small {
    border: none;
    height: 30px;
    width: 50px;
  }

  .left {
    border-left: 1px solid rgb(236, 236, 236);
    border-top: 1px solid rgb(236, 236, 236);
    border-bottom: 1px solid rgb(236, 236, 236);
    border-right-width: 80%;
    border-right: 1px solid rgb(236, 236, 236);
    border-bottom-left-radius: 25px;
    border-top-left-radius: 25px;
  }
}
</style>
<style lang="less">
.ant-layout-content {
  overflow-y: scroll;
}
</style>