index.vue 20.3 KB
Newer Older
1 2 3 4 5
<template>
  <div class="app-container">

    <!-- 搜索工作栏 -->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
6
      <el-form-item label="商品编码" prop="productCode">
7
        <el-input v-model="queryParams.productCode" placeholder="请输入商品编码" clearable @keyup.enter.native="handleQuery" />
8 9 10
      </el-form-item>

      <el-form-item label="海关编码" prop="customsCode">
11
        <el-input v-model="queryParams.customsCode" placeholder="请输入海关编码" clearable @keyup.enter.native="handleQuery" />
12 13 14
      </el-form-item>

      <el-form-item label="商品名称" prop="titleZh">
15
        <el-input v-model="queryParams.titleZh" placeholder="请输入商品名称" clearable @keyup.enter.native="handleQuery" />
16
      </el-form-item>
17

dragondean@qq.com's avatar
dragondean@qq.com committed
18
      <!-- <el-form-item label="商品属性" prop="attrId">
19
        <el-select v-model="queryParams.typeId" placeholder="选择商品类型" clearable>
20
          <el-option v-for="type in typeList" :key="type.id" :label="type.titleZh" :value="type.id" />
21
        </el-select>
dragondean@qq.com's avatar
dragondean@qq.com committed
22
      </el-form-item> -->
23 24 25

      <el-form-item label="商品特性" prop="attrId">
        <el-select v-model="queryParams.attrId" placeholder="选择商品特性" clearable>
26
          <el-option v-for="attr in attrList" :key="attr.id" :label="attr.attrName" :value="attr.id" />
27 28
        </el-select>
      </el-form-item>
29

dragondean@qq.com's avatar
dragondean@qq.com committed
30
      <!-- <el-form-item label="审核状态" prop="auditStatus">
31
        <el-select v-model="queryParams.auditStatus" placeholder="选择审核状态" clearable>
32
          <el-option v-for="auditStatusItem in auditStatusDictDatas" :key="auditStatusItem.id" :label="auditStatusItem.label" :value="auditStatusItem.value" />
33 34
        </el-select>
      </el-form-item>
35

36 37
      <el-form-item label="上架状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="选择上架状态" clearable>
38
          <el-option v-for="statusItem in statusDictDatas" :key="statusItem.id" :label="statusItem.value == CommonStatusEnum.ENABLE ? '已上架' : '已下架'" :value="statusItem.value" />
39
        </el-select>
dragondean@qq.com's avatar
dragondean@qq.com committed
40
      </el-form-item> -->
41

42 43 44 45 46 47 48 49 50
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 操作工具栏 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
51
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['ecw:product:create']">新增</el-button>
52
      </el-col>
53
      <el-col :span="1.5">
dragondean@qq.com's avatar
dragondean@qq.com committed
54
        <el-button type="primary" plain icon="el-icon-setting" size="mini" @click="handleEdit" v-hasPermi="['ecw:product:attr']">批量设置商品属性</el-button>
55 56
      </el-col>

57 58 59 60
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <!-- 列表 -->
61 62 63
    <el-table v-loading="loading" :data="list" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center">
      </el-table-column>
64 65
      <el-table-column label="商品编号" align="center" prop="id" />
      <el-table-column label="商品类型" align="center" prop="typeId">
66 67 68 69
        <template slot-scope="scope">
          <span>{{ getTypeName(scope.row.typeId) }}</span>
        </template>
      </el-table-column>
70
      <el-table-column label="海关编码" align="center" prop="customsCode" />
71 72
      <el-table-column label="中文标题" align="center" prop="titleZh" />
      <el-table-column label="英文标题" align="center" prop="titleEn" />
dragondean@qq.com's avatar
dragondean@qq.com committed
73
      <el-table-column label="商品属性" align="center" prop="attrId">
74 75 76 77
        <template slot-scope="scope">
          <span>{{ getAttrName(scope.row.attrId) }}</span>
        </template>
      </el-table-column>
dragondean@qq.com's avatar
dragondean@qq.com committed
78 79 80 81 82 83 84 85
      <!--商品特性-->
      <el-table-column label="商品图片" align="center" prop="attrId">
        <template slot-scope="scope">
          <el-image :src="firstImg(scope.row.imgs)" style="width:50px; height:50px">

          </el-image>
        </template>
      </el-table-column>
86 87 88

      <el-table-column prop="auditStatus" align="center" label="是否审核" width="120">
        <template slot-scope="scope">
89 90 91
          <el-select v-model="scope.row.auditStatus" @change="handleStatusChange(scope.row, 'auditStatus')">
            <el-option v-for="auditStatusItem in auditStatusDictDatas" :key="auditStatusItem.id" :label="auditStatusItem.label" :value="parseInt(auditStatusItem.value)" />
          </el-select>
92 93
        </template>
      </el-table-column>
94

95 96
      <el-table-column prop="status" align="center" label="状态" width="120">
        <template slot-scope="scope">
dragondean@qq.com's avatar
dragondean@qq.com committed
97 98
          <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status"/>
          <!-- <el-select v-model="scope.row.status" @change="handleStatusChange(scope.row, 'status')">
99
            <el-option v-for="statusItem in statusDictDatas" :key="statusItem.id" :label="statusItem.value == CommonStatusEnum.ENABLE + '' ? '已上架' : '已下架'" :value="parseInt(statusItem.value)" />
dragondean@qq.com's avatar
dragondean@qq.com committed
100
          </el-select> -->
101 102 103 104 105
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
wanglianghe's avatar
wanglianghe committed
106

107
          <el-button size="mini" type="text" @click="toPriceManager(scope.row)" v-hasPermi="['ecw:product-price:query']">路线价格</el-button>
wanglianghe's avatar
wanglianghe committed
108

109 110
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['ecw:product:update']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['ecw:product:delete']">删除</el-button>
111 112 113 114
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
115
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize" @pagination="getList" />
116 117

    <!-- 对话框(添加 / 修改) -->
118
    <el-dialog :title="title" :visible.sync="open" width="550px" append-to-body>
119
      <el-form ref="form" :model="form" :rules="rules" label-width="110px">
120 121
        <el-form-item label="商品类型" prop="typeId">
          <el-select v-model="form.typeId" placeholder="选择商品类型" clearable>
122
            <el-option v-for="type in typeList" :key="type.id" :label="type.titleZh" :value="type.id" />
123 124 125 126 127 128
          </el-select>
        </el-form-item>

        <el-form-item label="中文标题" prop="titleZh">
          <el-input v-model="form.titleZh" placeholder="请输入中文标题" />
        </el-form-item>
129

130 131 132 133
        <el-form-item label="英文标题" prop="titleEn">
          <el-input v-model="form.titleEn" placeholder="请输入英文标题" />
        </el-form-item>

134
        <el-form-item label="商品图片" prop="img">
dragondean@qq.com's avatar
dragondean@qq.com committed
135 136
          <image-upload v-model="form.imgs" />
          <!-- <el-col :span="8">
137
            <el-input v-model="form.imgs" placeholder="请上传图片" disabled />
dragondean@qq.com's avatar
dragondean@qq.com committed
138
          </el-col> -->
139

dragondean@qq.com's avatar
dragondean@qq.com committed
140
          <!-- <el-upload action="#" :http-request="requestUpload" :show-file-list="false" :before-upload="beforeUpload">
141 142 143 144
            <el-button size="small">
              上传图片
              <i class="el-icon-upload el-icon--right"></i>
            </el-button>
dragondean@qq.com's avatar
dragondean@qq.com committed
145
          </el-upload> -->
146 147 148 149 150 151 152 153 154 155 156 157 158

        </el-form-item>

        <el-form-item label="商品编码" prop="productCode">
          <el-input v-model="form.productCode" placeholder="请输入商品编码" />
        </el-form-item>

        <el-form-item label="海关编码" prop="customsCode">
          <el-input v-model="form.customsCode" placeholder="请输入海关编码" />
        </el-form-item>

        <el-form-item label="商品特性" prop="attrArray">
          <el-select v-model="form.attrArray" placeholder="选择商品特性" clearable multiple>
159 160
            <el-option v-for="attr in attrList" :key="attr.id" :label="attr.attrName" :value="attr.id" />
          </el-select>
161
        </el-form-item>
162

163 164
        <el-form-item label="商品材质" prop="materialType">
          <el-select v-model="form.materialType" placeholder="选择商品材质" clearable>
165
            <el-option v-for="materialItem in materialList" :key="materialItem.value" :label="materialItem.label" :value="materialItem.value" />
166 167 168 169
          </el-select>
        </el-form-item>

        <el-form-item label="出运要求" prop="requirements">
170
          <el-checkbox v-model="form.requirements" :checked="form.requirements===1? true:false" :true-label="1" :false-label="0">证书要求(支持多证书)</el-checkbox>
171 172 173 174
        </el-form-item>

        <el-form-item label="包装要求" prop="packaging">
          <el-select v-model="form.packaging" placeholder="选择包装要求" clearable>
175
            <el-option v-for="packageItem in packagingList" :key="packageItem.value" :label="packageItem.label" :value="packageItem.value" />
176 177 178 179 180
          </el-select>
        </el-form-item>

        <el-form-item label="默认货柜位置" prop="containerLocation">
          <el-select v-model="form.containerLocation" placeholder="选择货柜位置" clearable>
181
            <el-option v-for="locationItem in locationList" :key="locationItem.value" :label="locationItem.label" :value="locationItem.value" />
182 183 184
          </el-select>
        </el-form-item>

185
        <el-form-item label="订单方数上限" prop="square">
186 187 188 189 190
          <el-input v-model.number="form.square" type="number">
            <!-- <template slot="append">立方米</template> -->
          </el-input>
        </el-form-item>

191

wanglianghe's avatar
wanglianghe committed
192
        <el-form-item label="是否预约入仓" prop="needBook">
193 194 195 196
          <el-radio v-model.number="form.needBook" :label="1"></el-radio>
          <el-radio v-model.number="form.needBook" :label="0"></el-radio>
        </el-form-item>

wanglianghe's avatar
wanglianghe committed
197
        <el-form-item label="每日入仓上限" prop="dayLimit" v-if="form.needBook==1">
198 199 200 201
          <el-input v-model.number="form.dayLimit" type="number">
            <template slot="append">立方米</template>
          </el-input>
        </el-form-item>
202

203 204 205 206 207 208 209 210 211 212 213 214 215 216
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { createProduct, updateProduct, deleteProduct, getProduct, getProductPage, exportProductExcel } from "@/api/ecw/product";
import { getProductAttrList } from "@/api/ecw/productAttr";
import { getProductTypeList } from "@/api/ecw/productType";
import { getDictDatas, DICT_TYPE } from '@/utils/dict';
217 218
import { CommonStatusEnum, AuditStatusEnum } from '@/utils/constants';
import { uploadFile } from "@/api/infra/file";
dragondean@qq.com's avatar
dragondean@qq.com committed
219
import ImageUpload from '@/components/ImageUpload'
220
export default {
wanglianghe's avatar
wanglianghe committed
221
  name: "ProductList",
222
  components: {
dragondean@qq.com's avatar
dragondean@qq.com committed
223
    ImageUpload
224 225 226
  },
  data() {
    return {
227 228 229 230 231 232
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
233
      //特性列表
234
      attrList: [],
235
      //类型列表
236
      typeList: [],
237
      //材质列表
238
      materialList: [],
239
      //包装列表
240
      packagingList: [],
241
      //货柜位置
242
      locationList: [],
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

      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 产品列表
      list: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      dateRangeCreateTime: [],
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        typeId: null,
        attrId: null,
        titleZh: null,
        titleEn: null,
        auditStatus: null,
        status: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
274 275
        typeId: [{ required: true, message: "商品类型不能为空", trigger: "change" }],
        attrArray: [{ required: true, message: "商品特性不能为空", trigger: "change" }],
276 277
        titleZh: [{ required: true, message: "中文标题不能为空", trigger: "blur" }],
        titleEn: [{ required: true, message: "英文标题不能为空", trigger: "blur" }],
278
        materialType: [{ required: true, message: "商品材质不能为空", trigger: "blur" }],
wanglianghe's avatar
wanglianghe committed
279 280 281 282
        // packaging: [{ required: true, message: "包装要求不能为空", trigger: "blur" }],
        // containerLocation: [{ required: true, message: "默认货柜位置不能为空", trigger: "blur" }],
        // square: [{ required: true, message: "订单方数上线不能为空", trigger: "blur" }],
        // needBook: [{ required: true, message: "是否预约入仓不能为空", trigger: "blur" }],
283 284 285 286 287
      },

      CommonStatusEnum: CommonStatusEnum,
      AuditStatusEnum: AuditStatusEnum,
      statusDictDatas: getDictDatas(DICT_TYPE.COMMON_STATUS),
288 289 290 291
      auditStatusDictDatas: getDictDatas(DICT_TYPE.AUDIT_STATUS),
      materialList: getDictDatas(DICT_TYPE.ECW_PRODUCT_MATERIAL),
      packagingList: getDictDatas(DICT_TYPE.ECW_PACKAGING_TYPE),
      locationList: getDictDatas(DICT_TYPE.ECW_CONTAINER_LOCATION)
292 293 294 295 296 297
    };
  },

  computed: {
    getTypeName() {
      return typeId => {
298
        for (let index in this.typeList) {
299
          let typeItem = this.typeList[index];
300
          if (typeItem.id == typeId) {
301 302 303 304 305 306 307
            return typeItem.titleZh;
          }
        }
      }
    },

    getAttrName() {
308 309 310
      return attrIds => {
        let productAttrArray = [];
        let attrArray = attrIds.split(',');
311
        for (let attrIndex in attrArray) {
312
          let attrId = attrArray[attrIndex];
313
          for (let index in this.attrList) {
314
            let attrItem = this.attrList[index];
315
            if (attrItem.id == attrId) {
316 317
              productAttrArray.push(attrItem.attrName);
            }
318 319
          }
        }
320
        return productAttrArray.join(',');
321 322
      }
    },
dragondean@qq.com's avatar
dragondean@qq.com committed
323 324 325 326 327 328 329
    firstImg(){
      return imgString => {
        if(!imgString || imgString == '') return imgString
        let imgs = imgString.split(',')
        return imgs.length ? imgs[0] : null
      }
    }
330 331
  },

wanglianghe's avatar
wanglianghe committed
332

333
  created() {
334
    let typeId = this.$route.query.typeId;
335
    if (typeId) {
336 337
      this.queryParams.typeId = parseInt(typeId);
    }
338 339 340 341 342 343 344 345
    this.getAttrList();
    this.getTypeList();
    this.getList();
  },
  methods: {
    /** 获取产品属性列表 */
    getAttrList() {
      getProductAttrList().then(response => {
346
        this.attrList = response.data;
347 348 349 350 351 352 353 354 355 356
      })
    },

    /** 获取产品类型列表 */
    getTypeList() {
      getProductTypeList().then(response => {
        this.typeList = response.data;
      })
    },

wanglianghe's avatar
wanglianghe committed
357 358
    /**跳转价格管理 */
    toPriceManager(row) {
359 360
      /* localStorage.setItem('product', JSON.stringify(row));
      localStorage.setItem('typeList', JSON.stringify(this.typeList)); */
wanglianghe's avatar
wanglianghe committed
361
      this.$router.push({
362
        name: 'ProductPrice',
363
        query: {
wanglianghe's avatar
wanglianghe committed
364 365
          product_id: row.id,
          product_type: row.typeId
366
        }
wanglianghe's avatar
wanglianghe committed
367
      })
wanglianghe's avatar
wanglianghe committed
368 369
    },

370 371 372
    handleStatusChange(row, statusType) {
      updateProduct(row).then(() => {
        this.$modal.msgSuccess("修改成功");
373 374
      }).catch(function () {
        if (statusType == 'status') {
375 376 377 378
          row.status = row.status === CommonStatusEnum.ENABLE ? CommonStatusEnum.DISABLE : CommonStatusEnum.ENABLE;
        } else {
          row.auditStatus = row.auditStatus === AuditStatusEnum.PASS ? AuditStatusEnum.NOT_PASS : AuditStatusEnum.PASS;
        }
379

380 381 382 383 384 385 386
      });
    },

    /** 查询列表 */
    getList() {
      this.loading = true;
      // 处理查询参数
387
      let params = { ...this.queryParams };
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405
      this.addBeginAndEndTime(params, this.dateRangeCreateTime, 'createTime');
      // 执行查询
      getProductPage(params).then(response => {
        this.list = response.data.list;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    /** 取消按钮 */
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 表单重置 */
    reset() {
      this.form = {
        id: undefined,
        typeId: undefined,
406
        attrArray: undefined,
407 408 409 410 411
        attrId: undefined,
        titleZh: undefined,
        titleEn: undefined,
        auditStatus: undefined,
        status: undefined,
412
        requirements: 0,
wanglianghe's avatar
wanglianghe committed
413
        needBook: 0
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRangeCreateTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
432
      this.title = "添加商品";
433
      if (this.queryParams.typeId) {
434 435
        this.form.typeId = this.queryParams.typeId;
      }
436 437 438 439 440 441 442
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id;
      getProduct(id).then(response => {
        this.form = response.data;
443
        let attrArray = this.form.attrId.split(',');
444
        for (let index in attrArray) {
445 446 447 448
          let value = attrArray[index];
          attrArray[index] = parseInt(value);
        }
        this.form.attrArray = attrArray;
449
        this.open = true;
450
        this.title = "修改商品";
451 452
      });
    },
453

454 455 456 457 458 459 460
    /** 提交按钮 */
    submitForm() {
      console.log(this.form);
      this.$refs["form"].validate(valid => {
        if (!valid) {
          return;
        }
461 462 463
        //商品特性转字符串
        this.form.attrId = this.form.attrArray.join(',');

464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483
        // 修改的提交
        if (this.form.id != null) {
          updateProduct(this.form).then(response => {
            this.$modal.msgSuccess("修改成功");
            this.open = false;
            this.getList();
          });
          return;
        }
        // 添加的提交
        createProduct(this.form).then(response => {
          this.$modal.msgSuccess("新增成功");
          this.open = false;
          this.getList();
        });
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const id = row.id;
484 485 486 487 488 489
      this.$modal.confirm('是否确认删除商品编号为"' + id + '"的数据项?').then(function () {
        return deleteProduct(id);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
490 491 492 493
    },
    /** 导出按钮操作 */
    handleExport() {
      // 处理查询参数
494
      let params = { ...this.queryParams };
495 496 497 498
      params.pageNo = undefined;
      params.pageSize = undefined;
      this.addBeginAndEndTime(params, this.dateRangeCreateTime, 'createTime');
      // 执行导出
499
      this.$modal.confirm('是否确认导出所有商品数据项?').then(() => {
500 501 502 503 504 505
        this.exportLoading = true;
        return exportProductExcel(params);
      }).then(response => {
        this.$download.excel(response, '${table.classComment}.xls');
        this.exportLoading = false;
      }).catch(() => { });
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
    },

    // 覆盖默认的上传行为
    requestUpload() {
    },
    // 上传预处理
    beforeUpload(file) {
      if (file.type.indexOf("image/") == -1) {
        this.$modal.msgError("文件格式错误,请上传图片类型,如:JPG,PNG后缀的文件。");
      } else {
        //上传
        let formData = new FormData();
        formData.append("file", file);
        formData.append("path", this.uuid());
        uploadFile(formData).then(response => {
          this.$set(this.form, 'imgs', response.data);
          // this.form.img = response.data;
        })
      }
    },

    uuid() {
      var s = [];
      var hexDigits = "0123456789abcdef";
      for (var i = 0; i < 36; i++) {
531
        s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
532 533 534 535 536 537 538 539
      }
      s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
      s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
      s[8] = s[13] = s[18] = s[23] = "-";

      var uuid = s.join("");
      return uuid;
    },
540 541 542 543 544 545 546 547 548 549 550 551 552 553 554
    // 表格多选
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    // 批量设置商品属性
    handleEdit() {
      this.$router.push({
        path: "product-attr/edit",
        query: {
          ids: this.ids
        }
      });
    }
555 556 557
  }
};
</script>
558