index.vue 29.7 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

    <!-- 对话框(添加 / 修改) -->
133
    <el-dialog :modal="false" :modal-append-to-body="true" :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>
234
           <span @click="toPriceManager(formCopy, true)" style="color: #0a84ff;cursor: pointer;">
邓春圆's avatar
邓春圆 committed
235
             查看《#{{$l(formCopy,'title')}}#》路线价格
236
           </span>
邓春圆's avatar
邓春圆 committed
237
           <el-button style="font-size: 12px;margin-left: 15px;color: red;" type="text" @click="form.priceStepClearanceList = [];lineNum = 0"  >清除路线</el-button>
238
         </p>
239 240
      </el-form>
      <div slot="footer" class="dialog-footer">
241 242
        <el-button type="primary" @click="submitForm">{{$t('确定')}}</el-button>
        <el-button @click="cancel">{{$t('取消')}}</el-button>
243 244
      </div>
    </el-dialog>
邓春圆's avatar
邓春圆 committed
245
    <el-dialog width="60%" :visible.sync="visible" @close="()=>{open = true}" >
246 247
      <product-dialog @copyLine="copyLine"></product-dialog>
    </el-dialog>
248 249 250 251
  </div>
</template>

<script>
邓春圆's avatar
邓春圆 committed
252 253 254
import {
  createProduct,
  deleteProduct,
255
  exportProductExcel,
邓春圆's avatar
邓春圆 committed
256 257
  getProduct,
  getProductPage,
258 259
  product_coupon_newProd,
  updateProduct
邓春圆's avatar
邓春圆 committed
260
} from "@/api/ecw/product";
261 262 263 264 265
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
266
import ImageUpload from '@/components/ImageUpload'
267 268
import PackagingType from "@/views/ecw/channel/componrnts/packaging-type.vue";
import ProductDialog from "@/views/ecw/product/product-dialog.vue";
269

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

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

      },
邓春圆's avatar
邓春圆 committed
327
      formCopy:{},
328 329
      // 表单校验
      rules: {
330 331 332 333
        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
334
        // materialType: [{ required: true, message: this.$t("商品材质不能为空"), trigger: "blur" }],
Marcus's avatar
Marcus committed
335 336 337 338
        // 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" }],
339 340 341 342 343
      },

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

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

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

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

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

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

wanglianghe's avatar
wanglianghe committed
485
    /**跳转价格管理 */
486
    toPriceManager(row, flag = false) {
487 488
      /* localStorage.setItem('product', JSON.stringify(row));
      localStorage.setItem('typeList', JSON.stringify(this.typeList)); */
489 490 491 492 493 494 495 496 497
      let  p
      if (flag){
        p = {
          product_id: row.id,
          product_type: row.typeId,
          transportType:3,
        }
      }else {
        p = {
wanglianghe's avatar
wanglianghe committed
498
          product_id: row.id,
499
          product_type: row.typeId,
500
        }
501 502 503 504
      }
      this.$router.push({
        name: 'ProductPrice',
        query: p
wanglianghe's avatar
wanglianghe committed
505
      })
wanglianghe's avatar
wanglianghe committed
506 507
    },

508 509
    handleStatusChange(row, statusType) {
      updateProduct(row).then(() => {
510
        this.$modal.msgSuccess(this.$t("修改成功"));
511 512
      }).catch(function () {
        if (statusType == 'status') {
513 514 515 516
          row.status = row.status === CommonStatusEnum.ENABLE ? CommonStatusEnum.DISABLE : CommonStatusEnum.ENABLE;
        } else {
          row.auditStatus = row.auditStatus === AuditStatusEnum.PASS ? AuditStatusEnum.NOT_PASS : AuditStatusEnum.PASS;
        }
517

518 519 520 521 522 523 524
      });
    },

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

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

            });
邓春圆's avatar
邓春圆 committed
752
        }else {
邓春圆's avatar
邓春圆 committed
753 754 755 756 757 758
          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)
759
            this.$forceUpdate()
邓春圆's avatar
邓春圆 committed
760 761 762
          }).catch(() => {

          });
邓春圆's avatar
邓春圆 committed
763 764
        }
      }
765
    }
邓春圆's avatar
邓春圆 committed
766
  },
767
};
768
</script>
邓春圆's avatar
邓春圆 committed
769 770 771 772

<style lang="scss" scoped>

</style>