index.vue 28.9 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 7
      <el-form-item :label="$t('商品编码')" prop="productCode">
        <el-input v-model="queryParams.productCode" :placeholder="$t('请输入商品编码')" clearable @keyup.enter.native="handleQuery" />
8 9
      </el-form-item>

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

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

18
      <el-form-item :label="$t('商品类型')" prop="attrId">
19
        <el-select v-model="queryParams.typeId" :placeholder="$t('选择商品类型')" clearable>
20
          <el-option v-for="types in typeList" :key="types.id" :label="$l(types, 'title')" :value="types.id" />
21
        </el-select>
22
      </el-form-item>
23

24 25
      <el-form-item :label="$t('商品特性')" prop="attrId">
        <el-select v-model="queryParams.attrId" :placeholder="$t('选择商品特性')" 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

30 31
      <!-- <el-form-item :label="$t('审核状态')" prop="auditStatus">
        <el-select v-model="queryParams.auditStatus" :placeholder="$t('选择审核状态')" 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="$t('上架状态')" prop="status">
        <el-select v-model="queryParams.status" :placeholder="$t('选择上架状态')" 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
      <el-form-item>
43 44
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">{{$t('搜索')}}</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">{{$t('重置')}}</el-button>
45 46 47 48 49 50
      </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']">{{$t('新增')}}</el-button>
52
      </el-col>
53
      <el-col :span="1.5">
54
        <el-button type="primary" plain icon="el-icon-setting" size="mini" @click="handleEdit" v-hasPermi="['ecw:product:attr']">{{$t('批量设置商品属性')}}</el-button>
55 56
      </el-col>

wanglianghe's avatar
wanglianghe committed
57
      <el-col :span="1.5">
58
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" v-hasPermi="['ecw:product-price:export']" :loading="exportLoading" >{{$t('导出')}}</el-button>
wanglianghe's avatar
wanglianghe committed
59 60
      </el-col>

61 62 63 64
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

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

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

97 98 99 100 101 102 103 104 105 106 107 108
      <el-table-column :label="$t('添加人')" align="center" prop="creatorName" />

      <el-table-column :label="$t('添加时间')" align="center">
        <template slot-scope="scope">
                <span>{{parseTime(scope.row.createTime)}}</span>
          </template>
        </el-table-column>

      <el-table-column :label="$t('修改人')" align="center" prop="updaterName" />

      <el-table-column :label="$t('修改时间')" align="center">
        <template slot-scope="scope">
邓春圆's avatar
邓春圆 committed
109 110 111
          <span>{{parseTime(scope.row.updateTime)}}</span>
        </template>
      </el-table-column>
112

wanglianghe's avatar
wanglianghe committed
113
      <!-- <el-table-column prop="status" align="center" :label="$t('状态')" width="120">
114
        <template slot-scope="scope">
dragondean@qq.com's avatar
dragondean@qq.com committed
115
          <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status"/>
116
        </template>
wanglianghe's avatar
wanglianghe committed
117
      </el-table-column> -->
118

119
      <el-table-column :label="$t('操作')" align="center" class-name="small-padding fixed-width">
120
        <template slot-scope="scope">
wanglianghe's avatar
wanglianghe committed
121

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

124 125
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['ecw:product:update']">{{$t('修改')}}</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['ecw:product:delete']">{{$t('删除')}}</el-button>
126 127 128 129
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
130
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize" @pagination="getList" />
131 132

    <!-- 对话框(添加 / 修改) -->
邓春圆's avatar
邓春圆 committed
133
    <el-dialog :modal-append-to-body="false" :title="title" :visible.sync="open" width="850px" >
134
      <el-form v-if="open"  ref="form" :model="form" :rules="rules" label-width="110px">
135 136
        <el-form-item :label="$t('商品类型')" prop="typeId">
          <el-select v-model="form.typeId" :placeholder="$t('选择商品类型')" clearable>
137
            <el-option v-for="types in typeList" :key="types.id" :label="types.titleZh" :value="types.id" />
138 139 140
          </el-select>
        </el-form-item>

141 142
        <el-form-item :label="$t('中文标题')" prop="titleZh">
          <el-input v-model="form.titleZh" :placeholder="$t('请输入中文标题')" />
143
        </el-form-item>
144

145 146
        <el-form-item :label="$t('英文标题')" prop="titleEn">
          <el-input v-model="form.titleEn" :placeholder="$t('请输入英文标题')" />
147 148
        </el-form-item>

149
        <el-form-item :label="$t('商品图片')" prop="img">
dragondean@qq.com's avatar
dragondean@qq.com committed
150
          <image-upload v-model="form.imgs" />
151 152
        </el-form-item>

我在何方's avatar
我在何方 committed
153 154 155 156 157 158 159
        <el-form-item prop="auditStatus" :label="$t('是否审核')">
          <template slot-scope="scope">
            <el-select v-model="form.auditStatus">
              <el-option v-for="auditStatusItem in auditStatusDictDatas" :key="auditStatusItem.id" :label="$l(auditStatusItem, 'label')" :value="parseInt(auditStatusItem.value)" />
            </el-select>
          </template>
        </el-form-item>
160 161
        <el-form-item :label="$t('商品编码')" prop="productCode">
          <el-input v-model="form.productCode" :placeholder="$t('请输入商品编码')" />
162 163
        </el-form-item>

164 165
        <el-form-item :label="$t('海关编码')" prop="customsCode">
          <el-input v-model="form.customsCode" :placeholder="$t('请输入海关编码')" />
166 167
        </el-form-item>

168 169
        <el-form-item :label="$t('商品特性')" prop="attrArray">
          <el-select v-model="form.attrArray" :placeholder="$t('选择商品特性')" clearable multiple>
170 171
            <el-option v-for="attr in attrList" :key="attr.id" :label="attr.attrName" :value="attr.id" />
          </el-select>
172
        </el-form-item>
173

174 175
        <el-form-item :label="$t('商品材质')" prop="materialType">
          <el-select v-model="form.materialType" :placeholder="$t('选择商品材质')" clearable>
176
            <el-option v-for="materialItem in materialList" :key="materialItem.value" :label="materialItem.label" :value="materialItem.value" />
177 178 179
          </el-select>
        </el-form-item>

180 181
        <el-form-item :label="$t('出运要求')" prop="requirements">
          <el-checkbox v-model="form.requirements" :checked="form.requirements===1? true:false" :true-label="1" :false-label="0">{{$t('证书要求')}}({{$t('支持多证书')}})</el-checkbox>
182 183
        </el-form-item>

184 185
        <el-form-item :label="$t('包装要求')" prop="packaging">
          <el-select v-model="form.packaging" :placeholder="$t('选择包装要求')" clearable>
186
            <el-option v-for="packageItem in packagingList" :key="packageItem.value" :label="packageItem.label" :value="packageItem.value" />
187 188 189
          </el-select>
        </el-form-item>

190 191
        <el-form-item :label="$t('默认货柜位置')" prop="containerLocation">
          <el-select v-model="form.containerLocation" :placeholder="$t('选择货柜位置')" clearable>
192
            <el-option v-for="locationItem in locationList" :key="locationItem.value" :label="locationItem.label" :value="locationItem.value" />
193 194 195
          </el-select>
        </el-form-item>

196
        <el-form-item :label="$t('订单方数上限')" prop="square">
197
          <el-input v-model.number="form.square" type="number">
198
            <!-- <template slot="append">{{$t('立方米')}}</template> -->
199 200 201
          </el-input>
        </el-form-item>

202

203 204 205
        <el-form-item :label="$t('是否预约入仓')" prop="needBook">
          <el-radio v-model.number="form.needBook" :label="1">{{$t('是')}}</el-radio>
          <el-radio v-model.number="form.needBook" :label="0">{{$t('否')}}</el-radio>
206
        </el-form-item>
邓春圆's avatar
邓春圆 committed
207 208 209 210 211
        <!--        <el-form-item :label="$t('可参与优惠活动')" prop="you">
                  <el-select v-model="form.you" :placeholder="$t('可参与优惠活动')" clearable>
                    <el-option v-for="packageItem in packagingList" :key="packageItem.value" :label="packageItem.label" :value="packageItem.value" />
                  </el-select>
                </el-form-item> -->
212
        <el-form-item :label="$t('每日入仓上限')" prop="dayLimit" v-if="form.needBook==1">
213
          <el-input v-model.number="form.dayLimit" type="number">
214
            <template slot="append">{{$t('立方米')}}</template>
215 216
          </el-input>
        </el-form-item>
邓春圆's avatar
邓春圆 committed
217 218
        <el-form-item  :label="$t('可参与优惠')">
          <div style="width: 300px;height: 400px;border: 1px solid;overflow-y: auto">
219
            <div @click="selectMoveAbout(item)" style="display: flex;justify-content: space-between; align-items: center;" :style="{'cursor':item.mandatory ? 'no-drop' : 'pointer'  }"  v-for="item in preferentialList" :key="item.couponId" >
邓春圆's avatar
邓春圆 committed
220 221 222
              <div>
                {{$l(item, 'title')}}
              </div>
223
              <i v-if="form.couponIds.includes(item.couponId)"  style="margin-right: 20px;" class="el-icon-check"></i>
邓春圆's avatar
邓春圆 committed
224 225 226
            </div>
          </div>
        </el-form-item>
227 228 229 230 231 232 233
        <packaging-type  key-arr="priceStepClearanceList" v-model="form">
          <el-button @click="visible =  true; open = false;" type="text">选择空运模板</el-button>
        </packaging-type>
         <p v-if="lineNum">
           <span>
             复制模板线路价格:{{lineNum}}个
           </span>
邓春圆's avatar
邓春圆 committed
234
           <span @click="toPriceManager(formCopy)" style="color: #0a84ff;cursor: pointer;">
邓春圆's avatar
邓春圆 committed
235
             查看《#{{$l(formCopy,'title')}}#》路线价格
236 237
           </span>
         </p>
238 239
      </el-form>
      <div slot="footer" class="dialog-footer">
240 241
        <el-button type="primary" @click="submitForm">{{$t('确定')}}</el-button>
        <el-button @click="cancel">{{$t('取消')}}</el-button>
242 243
      </div>
    </el-dialog>
244 245 246
    <el-dialog :visible.sync="visible" >
      <product-dialog @copyLine="copyLine"></product-dialog>
    </el-dialog>
247 248 249 250
  </div>
</template>

<script>
邓春圆's avatar
邓春圆 committed
251 252 253
import {
  createProduct,
  deleteProduct,
254
  exportProductExcel,
邓春圆's avatar
邓春圆 committed
255 256
  getProduct,
  getProductPage,
257 258
  product_coupon_newProd,
  updateProduct
邓春圆's avatar
邓春圆 committed
259
} from "@/api/ecw/product";
260 261 262 263 264
import {getProductAttrList} from "@/api/ecw/productAttr";
import {getProductTypeList} from "@/api/ecw/productType";
import {DICT_TYPE, getDictDatas} from '@/utils/dict';
import {AuditStatusEnum, CommonStatusEnum} from '@/utils/constants';
import {uploadFile} from "@/api/infra/file";
dragondean@qq.com's avatar
dragondean@qq.com committed
265
import ImageUpload from '@/components/ImageUpload'
266 267
import PackagingType from "@/views/ecw/channel/componrnts/packaging-type.vue";
import ProductDialog from "@/views/ecw/product/product-dialog.vue";
268

269
export default {
270
  name: "EcwProductIndex",
271
  components: {
272 273
    ProductDialog,
    PackagingType,
dragondean@qq.com's avatar
dragondean@qq.com committed
274
    ImageUpload
275 276 277
  },
  data() {
    return {
278
      visible:false,
279 280 281 282 283 284
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
285
      //特性列表
286
      attrList: [],
287
      //类型列表
288
      typeList: [],
289
      //材质列表
290
      materialList: [],
291
      //包装列表
292
      packagingList: [],
293
      //货柜位置
294
      locationList: [],
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

      // 遮罩层
      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,
      },
      // 表单参数
323 324 325
      form: {

      },
邓春圆's avatar
邓春圆 committed
326
      formCopy:{},
327 328
      // 表单校验
      rules: {
329 330 331 332
        typeId: [{ required: true, message: this.$t("商品类型不能为空"), trigger: "change" }],
        attrArray: [{ required: true, message: this.$t("商品特性不能为空"), trigger: "change" }],
        titleZh: [{ required: true, message: this.$t("中文标题不能为空"), trigger: "blur" }],
        titleEn: [{ required: true, message: this.$t("英文标题不能为空"), trigger: "blur" }],
wanglianghe's avatar
wanglianghe committed
333
        // materialType: [{ required: true, message: this.$t("商品材质不能为空"), trigger: "blur" }],
Marcus's avatar
Marcus committed
334 335 336 337
        // packaging: [{ required: true, message: this.$t("包装要求不能为空"), trigger: "blur" }],
        // containerLocation: [{ required: true, message: this.$t("默认货柜位置不能为空"), trigger: "blur" }],
        // square: [{ required: true, message: this.$t("订单方数上线不能为空"), trigger: "blur" }],
        // needBook: [{ required: true, message: this.$t("是否预约入仓不能为空"), trigger: "blur" }],
338 339 340 341 342
      },

      CommonStatusEnum: CommonStatusEnum,
      AuditStatusEnum: AuditStatusEnum,
      statusDictDatas: getDictDatas(DICT_TYPE.COMMON_STATUS),
343 344 345
      auditStatusDictDatas: getDictDatas(DICT_TYPE.AUDIT_STATUS),
      materialList: getDictDatas(DICT_TYPE.ECW_PRODUCT_MATERIAL),
      packagingList: getDictDatas(DICT_TYPE.ECW_PACKAGING_TYPE),
邓春圆's avatar
邓春圆 committed
346 347
      locationList: getDictDatas(DICT_TYPE.ECW_CONTAINER_LOCATION),
      preferentialList:[],
348 349
      exceptionProductId:0,//新增商品异常传的id
      lineNum:0
350 351 352 353 354 355
    };
  },

  computed: {
    getTypeName() {
      return typeId => {
356
        for (let index in this.typeList) {
357
          let typeItem = this.typeList[index];
358
          if (typeItem.id == typeId) {
359
            return this.$l(typeItem, 'title');
360 361 362 363 364 365
          }
        }
      }
    },

    getAttrName() {
366 367 368
      return attrIds => {
        let productAttrArray = [];
        let attrArray = attrIds.split(',');
369
        for (let attrIndex in attrArray) {
370
          let attrId = attrArray[attrIndex];
371
          for (let index in this.attrList) {
372
            let attrItem = this.attrList[index];
373
            if (attrItem.id == attrId) {
dragondean@qq.com's avatar
dragondean@qq.com committed
374
              productAttrArray.push(this.$l(attrItem, 'attrName'));
375
            }
376 377
          }
        }
378
        return productAttrArray.join(',');
379 380
      }
    },
dragondean@qq.com's avatar
dragondean@qq.com committed
381 382 383 384 385 386 387
    firstImg(){
      return imgString => {
        if(!imgString || imgString == '') return imgString
        let imgs = imgString.split(',')
        return imgs.length ? imgs[0] : null
      }
    }
388 389
  },

390 391
  activated(){
    if(this.$route.query.typeId != this.queryParams.typeId){
392
      this.queryParams.typeId = +this.$route.query.typeId || null
393
    }
394
    //新增商品异常跳转商品修改
395
    if(this.$route.query.prodId){
396 397
      this.exceptionProductId = this.$route.query.prodId
      this.handleUpdate({id:this.$route.query.prodId})
398
    }
399 400
    this.getList()
  },
401
  created() {
我在何方's avatar
我在何方 committed
402 403
    //新增商品异常跳转商品修改
    if(this.$route.query.prodId){
404 405
      this.exceptionProductId = this.$route.query.prodId
      this.handleUpdate({id:this.$route.query.prodId})
我在何方's avatar
我在何方 committed
406
    }
407
    let typeId = this.$route.query.typeId;
408
    if (typeId) {
409 410
      this.queryParams.typeId = parseInt(typeId);
    }
411 412 413
    this.getAttrList();
    this.getTypeList();
    this.getList();
我在何方's avatar
我在何方 committed
414

415 416
  },
  methods: {
417
    copyLine(val , bol){
邓春圆's avatar
邓春圆 committed
418
      this.formCopy = val;
419
      let copy = ()=>{
邓春圆's avatar
邓春圆 committed
420
        if(val.priceStepClearanceList.length === 0) return  this.form.priceStepClearanceList = []
421 422 423 424 425 426
        this.form.airWeightLimit = val.airWeightLimit;
        val.priceStepClearanceList.forEach((item ,index) =>{
          if(this.form.priceStepClearanceList[index]){
            this.form.priceStepClearanceList[index].clearancePrice = item.clearancePrice
            this.form.priceStepClearanceList[index].clearancePriceUnit = item.clearancePriceUnit
            this.form.priceStepClearanceList[index].clearanceVolumeUnit = item.clearanceVolumeUnit
邓春圆's avatar
邓春圆 committed
427 428 429
            this.form.priceStepClearanceList[index].endNum = item.endNum
            this.form.priceStepClearanceList[index].startNum = item.startNum
            this.form.priceStepClearanceList[index].weightUnit = item.weightUnit
430 431
          }else {
            let p = {
邓春圆's avatar
邓春圆 committed
432
              "channelId":undefined,
433 434 435
              "clearancePrice":item.clearancePrice,
              "clearancePriceUnit":item.clearancePriceUnit,
              "clearanceVolumeUnit":item.clearanceVolumeUnit,
邓春圆's avatar
邓春圆 committed
436
              "endNum":item.endNum,
邓春圆's avatar
邓春圆 committed
437
              "packagingId":undefined,
邓春圆's avatar
邓春圆 committed
438 439
              "startNum":item.startNum,
              "weightUnit":item.weightUnit
440 441 442 443 444 445 446 447 448 449 450 451
            }
            this.form.priceStepClearanceList.push(p)
          }
        })
      }
      this.visible = false;
      if(bol){
        this.$confirm(`请确认是否要将#${this.$l(val,'title')}#的所有路线价格复制到当前商品#${this.$l(this.form,'title')}#中?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
邓春圆's avatar
邓春圆 committed
452 453 454
          // this.form.priceLineCount = val.id;
          this.lineNum = val.priceLineCount;
          this.form.productTemplateId = val.id;
455 456 457 458 459 460 461 462 463 464 465 466
          this.isCopyProductPriceTemplate = true;
          copy()
          this.open = true;
        }).catch(() => {
          this.open = true;
        });
      }else {
        this.open = true;
        copy()
      }
      this.$forceUpdate()
    },
467 468 469
    /** 获取产品属性列表 */
    getAttrList() {
      getProductAttrList().then(response => {
470
        this.attrList = response.data;
471 472 473 474 475 476 477 478 479 480
      })
    },

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

wanglianghe's avatar
wanglianghe committed
481 482
    /**跳转价格管理 */
    toPriceManager(row) {
483 484
      /* localStorage.setItem('product', JSON.stringify(row));
      localStorage.setItem('typeList', JSON.stringify(this.typeList)); */
wanglianghe's avatar
wanglianghe committed
485
      this.$router.push({
486
        name: 'ProductPrice',
487
        query: {
wanglianghe's avatar
wanglianghe committed
488 489
          product_id: row.id,
          product_type: row.typeId
490
        }
wanglianghe's avatar
wanglianghe committed
491
      })
wanglianghe's avatar
wanglianghe committed
492 493
    },

494 495
    handleStatusChange(row, statusType) {
      updateProduct(row).then(() => {
496
        this.$modal.msgSuccess(this.$t("修改成功"));
497 498
      }).catch(function () {
        if (statusType == 'status') {
499 500 501 502
          row.status = row.status === CommonStatusEnum.ENABLE ? CommonStatusEnum.DISABLE : CommonStatusEnum.ENABLE;
        } else {
          row.auditStatus = row.auditStatus === AuditStatusEnum.PASS ? AuditStatusEnum.NOT_PASS : AuditStatusEnum.PASS;
        }
503

504 505 506 507 508 509 510
      });
    },

    /** 查询列表 */
    getList() {
      this.loading = true;
      // 处理查询参数
511
      let params = { ...this.queryParams };
wanglianghe's avatar
wanglianghe committed
512
	  params.filter=false;
513 514
      this.addBeginAndEndTime(params, this.dateRangeCreateTime, 'createTime');
      // 执行查询
wanglianghe's avatar
wanglianghe committed
515
	  params.status = 0;
516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531
      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,
532
        attrArray: undefined,
533 534 535 536 537
        attrId: undefined,
        titleZh: undefined,
        titleEn: undefined,
        auditStatus: undefined,
        status: undefined,
538
        requirements: 0,
邓春圆's avatar
邓春圆 committed
539 540
        needBook: 0,
        couponIds:[],
541 542 543 544
        airWeightLimit:undefined,
        priceStepClearanceList:[],
        isCopyProductPriceTemplate:false,
        productTemplateId:undefined,
545
      };
546
      this.lineNum = 0
547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRangeCreateTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
564
      this.title = this.$t("添加商品");
565 566 567 568
      product_coupon_newProd().then(r => {
        this.preferentialList = r.data
        this.form.couponIds = this.preferentialList.filter(i => i.isDefault).map(i => i.couponId)
      })
569
      if (this.queryParams.typeId) {
570 571
        this.form.typeId = this.queryParams.typeId;
      }
572 573 574
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
dragondean@qq.com's avatar
dragondean@qq.com committed
575
      // this.reset();
我在何方's avatar
我在何方 committed
576
      console.log(row);
577 578
      const id = row.id;
      getProduct(id).then(response => {
579
        this.form = {...response.data,couponIds:[]};
580
        this.form.channelPriceStepClearanceList = this.form.priceStepClearanceList;
我在何方's avatar
我在何方 committed
581
        let attrArray = this.form.attrId?this.form.attrId.split(','):[];
582
        for (let index in attrArray) {
583 584 585
          let value = attrArray[index];
          attrArray[index] = parseInt(value);
        }
dragondean@qq.com's avatar
dragondean@qq.com committed
586
        this.$nextTick(() =>{
dragondean@qq.com's avatar
dragondean@qq.com committed
587
          this.$set(this.form, 'attrArray', attrArray)
dragondean@qq.com's avatar
dragondean@qq.com committed
588
        })
589
        this.open = true;
dragondean@qq.com's avatar
dragondean@qq.com committed
590
        this.title = this.$t("修改商品");
591
        product_coupon_newProd({prodId:id}).then(r => {
592 593 594 595
          this.preferentialList = r.data
          this.form.couponIds = this.preferentialList.filter(i => i.isDefault).map(i => i.couponId)
          // this.reset()
        })
596 597
      });
    },
邓春圆's avatar
邓春圆 committed
598 599 600
    verify(row){
       return (row.startNum !== '' && row.endNum !== '' && row.clearancePrice !== '' && row.clearancePriceUnit !== '' && row.clearanceVolumeUnit !== '')
        },
601 602 603 604 605 606
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (!valid) {
          return;
        }
邓春圆's avatar
邓春圆 committed
607 608 609 610 611 612 613 614 615 616 617 618
        if(!this.form.airWeightLimit){
          return this.$message.warning('请输入空运订单重量上限')
        }
        if(this.form.priceStepClearanceList.length === 0){
          return this.$message.warning('阶梯定价输入不完整!')
        }else {
           let bol = this.form.priceStepClearanceList.every(this.verify)
          if(!bol){
            return this.$message.warning('阶梯定价输入不完整!')
          }

        }
619 620
        //商品特性转字符串
        this.form.attrId = this.form.attrArray.join(',');
621 622
        // 修改的提交
        if (this.form.id != null) {
623 624 625
          this.form.priceStepClearanceList.forEach(i =>{
            i.productId = this.form.id
          })
626 627
          if(this.exceptionProductId){
            this.form.productId = this.exceptionProductId
我在何方's avatar
我在何方 committed
628
            this.form.status = 0
629 630
          }else {
            this.form.productId = this.form.id
631
          }
632
          updateProduct(this.form).then(response => {
633
            this.$modal.msgSuccess(this.$t("修改成功"));
634
            this.open = false;
635
             if(this.exceptionProductId){
我在何方's avatar
我在何方 committed
636
                this.exceptionProductId = null
637 638
                this.$router.replace({ path: '/product/product-list'})
              }
639 640 641 642 643 644
            this.getList();
          });
          return;
        }
        // 添加的提交
        createProduct(this.form).then(response => {
645
          this.$modal.msgSuccess(this.$t("新增成功"));
646 647 648 649 650 651 652 653
          this.open = false;
          this.getList();
        });
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const id = row.id;
654
      this.$modal.confirm(this.$t('是否确认删除商品编号为{id}的数据项?', {id})).then(function () {
655 656 657
        return deleteProduct(id);
      }).then(() => {
        this.getList();
658
        this.$modal.msgSuccess(this.$t("删除成功"));
659
      }).catch(() => { });
660 661 662 663
    },
    /** 导出按钮操作 */
    handleExport() {
      // 处理查询参数
664
      let params = { ...this.queryParams };
665 666 667 668
      params.pageNo = undefined;
      params.pageSize = undefined;
      this.addBeginAndEndTime(params, this.dateRangeCreateTime, 'createTime');
      // 执行导出
669
      this.$modal.confirm(this.$t('是否确认导出所有商品数据项?')).then(() => {
670 671 672
        this.exportLoading = true;
        return exportProductExcel(params);
      }).then(response => {
wanglianghe's avatar
wanglianghe committed
673
        this.$download.excel(response, '商品.xlsx');
674 675
        this.exportLoading = false;
      }).catch(() => { });
676 677 678 679
    },
    // 上传预处理
    beforeUpload(file) {
      if (file.type.indexOf("image/") == -1) {
680
        this.$modal.msgError(this.$t("文件格式错误,请上传图片类型,如:JPG,PNG后缀的文件。"));
681 682 683 684
      } else {
        //上传
        let formData = new FormData();
        formData.append("file", file);
wanglianghe's avatar
wanglianghe committed
685
        // formData.append("path", this.uuid());
686 687 688 689 690 691 692 693 694 695 696
        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++) {
697
        s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
698 699 700 701 702 703 704 705
      }
      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;
    },
706 707 708 709 710 711 712 713 714 715 716 717 718 719
    // 表格多选
    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
        }
      });
邓春圆's avatar
邓春圆 committed
720 721 722
    },
    selectMoveAbout(val){
      if(!val.mandatory){
723
       let index = this.form.couponIds.findIndex(i => val.couponId == i)
邓春圆's avatar
邓春圆 committed
724
        if(index >= 0){
邓春圆's avatar
邓春圆 committed
725 726 727 728 729 730
          this.$confirm(this.$t(`您确定要将商品从优惠活动${this.$l(val,'title')}中移出吗?`), this.$t('提示'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText:this.$t('取消') ,
            type: 'warning'
          }).then(() => {
            this.form.couponIds.splice(index,1)
731
            this.$forceUpdate()
邓春圆's avatar
邓春圆 committed
732 733 734
          }).catch(() => {

            });
邓春圆's avatar
邓春圆 committed
735
        }else {
邓春圆's avatar
邓春圆 committed
736 737 738 739 740 741
          this.$confirm(this.$t(`您确定要将商品加入到优惠活动${this.$l(val,'title')}中吗?`), this.$t('提示'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText:this.$t('取消') ,
            type: 'warning'
          }).then(() => {
            this.form.couponIds.push(val.couponId)
742
            this.$forceUpdate()
邓春圆's avatar
邓春圆 committed
743 744 745
          }).catch(() => {

          });
邓春圆's avatar
邓春圆 committed
746 747
        }
      }
748
    }
邓春圆's avatar
邓春圆 committed
749
  },
750
};
751
</script>
邓春圆's avatar
邓春圆 committed
752 753 754 755

<style lang="scss" scoped>

</style>