index.vue 17.8 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 577 578 579 580 581 582 583 584 585 586 587
<!-- 商品管理-门店 -->
<template>
  <div class="microStore pro-group">
    <div class="m-b-20">
      <GLButton :size="size" type="primary" fn="新建商品" class="el-icon-plus" @click="handleEdit(1)">新建商品</GLButton>
    </div>
    <div class="container">
      <GLCombiForm ref="showSearch" :rowNumber="1" :formObj="searchForm" :formData="searchFormData" @handleOk="handleSearch" @handleRest="handleReset"></GLCombiForm>

      <!-- 表格区域 开始 -->
      <GLTable ref="proGroupRef" class="table-img" :getListApi="getListApi" :noDataImg="url" :searchForm="tableSearchForm" :tableParams="tableParams" :pageConf="pageConf" :beforeSearchFn="beforeSearchFn" @setTableFinishFun="setTableFinishFun">
        <template slot="goodsImage" slot-scope="scope">
          <el-popover placement="top" width="160" trigger="hover" popper-class="table-popover-block">
            <img class="table-popover-img" :src="scope.scope.goodsImage" />
            <img class="img-60 pointer" slot="reference" :src="scope.scope.goodsImage" />
          </el-popover>
        </template>
        <div class="table-btns" slot="auth-button" slot-scope="scope">
          <GLTableButton :buttonList="tableButtonList" :buttonItem="scope.scope" :buttonNum="3"></GLTableButton>
        </div>
      </GLTable>
      <!-- 表格区域 end -->
    </div>
    <!-- 下架 -->
    <!-- <glsx-dialog title="下架" :isVisible.sync="isDownVisible" @confirmDialog="handleDownConfirm" @closeDialog="handleDownClose">
      <el-form ref="downRef" label-width="100px" :rules="downRules" :model="downForm">
        <el-form-item label="下架备注" prop="offReason">
          <el-input :size="size" v-model="downForm.offReason" placeholder="请输入下架备注" maxlength="30"></el-input>
        </el-form-item>
      </el-form>
    </glsx-dialog> -->
    <!-- 分享 -->
    <share-dialog :isShareVisible="isShareVisible" :shareForm="shareForm" @handleShareClose="handleShareClose"></share-dialog>
  </div>
</template>

<script>
import * as dayjs from 'dayjs'
import url from '@/assets/empty.png'
import shareDialog from '../productGroup/components/shareDialog'
export default {
  name: 'productGroup',
  data() {
    return {
      size: 'small',
      url: url,
      // 下架
      isDownVisible: false,
      downForm: {
        id: '',
        offReason: '',
        goodsStatus: 0
      },
      downRules: {
        offReason: [{ required: true, message: '请输入下架备注', trigger: 'change' }]
      },
      // 分享
      isShareVisible: false,
      shareForm: {},
      // 表格
      searchForm: {
        goodsName: '',
        createDate: [],
        goodsStatus: ''
      },
      tableSearchForm: {},
      // 搜索
      searchFormData: [
        {
          label: '商品名称',
          name: 'goodsName',
          type: 'input',
          maxlength: 20
        },
        {
          label: '创建日期',
          name: 'createDate',
          type: 'datePicker',
          isClear: true,
          pickerOptions: 'beforeRangePickerOptions'
        },
        {
          label: '商品状态',
          name: 'goodsStatus',
          type: 'select',
          optionList: [],
          optionId: 'confId',
          optionLabel: 'confName',
          optionsName: 'goodsStatusList'
        }
      ],
      // 表格按钮
      tableButtonList: [
        {
          type: 'GLButton',
          name: '编辑',
          attrs: {
            type: 'text',
            fn: '自建编辑'
          },
          condition: row => {
            return !row.goodsStatus && (row.goodsSource == 1 || row.goodsSource == 3)
          },
          listeners: {
            click: row => this.handleEdit(2, row)
          }
        },
        {
          type: 'GLButton',
          name: '编辑',
          attrs: {
            type: 'text',
            fn: '带货编辑'
          },
          condition: row => {
            return !row.goodsStatus && row.goodsSource == 2 && row.takeType == '1'
          },
          listeners: {
            click: row => this.handleEditDh(2, row)
          }
        },
        {
          type: 'el-button',
          name: '上架',
          attrs: {
            type: 'text'
          },
          condition: row => {
            return !row.goodsStatus && (row.goodsSource == 1 || row.goodsSource == 3 || (row.goodsSource == 2 && row.originGoodsStatus))
          },
          listeners: {
            click: this.handleUpOrDown
          }
        },
        {
          type: 'el-button',
          name: '下架通知',
          attrs: {
            type: 'text'
          },
          condition: row => {
            return !row.goodsStatus && row.goodsSource == 2 && !row.originGoodsStatus && row.offReason
          },
          listeners: {
            click: this.handleDwonNotice
          }
        },
        {
          type: 'el-button',
          name: '下架',
          attrs: {
            type: 'text'
          },
          condition: row => {
            return row.goodsStatus
          },
          listeners: {
            click: this.handleUpOrDown
          }
        },
        {
          type: 'el-button',
          name: '取消带货',
          attrs: {
            type: 'text'
          },
          condition: row => {
            return !row.goodsStatus && row.goodsSource == 2
          },
          listeners: {
            click: this.handleTakeGood
          }
        },
        {
          type: 'el-button',
          name: '置顶',
          attrs: {
            type: 'text'
          },
          condition: row => {
            return !row.goodsStatus && row.goodsSource == 1
          },
          listeners: {
            click: this.handleTop
          }
        },
        {
          type: 'GLButton',
          name: '查看',
          attrs: {
            type: 'text',
            fn: '自建查看'
          },
          condition: row => {
            return row.goodsStatus && (row.goodsSource == 1 || row.goodsSource == 3 || row.goodsSource == 4)
          },
          listeners: {
            click: row => this.handleEdit(3, row)
          }
        },
        {
          type: 'GLButton',
          name: '查看',
          attrs: {
            type: 'text',
            fn: '带货查看'
          },
          condition: row => {
            return row.goodsStatus && row.goodsSource == 2
          },
          listeners: {
            click: row => this.handleEditDh(3, row)
          }
        },
        {
          type: 'GLButton',
          name: '删除',
          attrs: {
            type: 'text',
            fn: '删除'
          },
          condition: row => {
            return !row.goodsStatus
          },
          listeners: {
            click: this.del
          }
        },
        {
          type: 'el-button',
          name: '分享',
          attrs: {
            type: 'text'
          },
          condition: row => {
            return row.goodsStatus
          },
          listeners: {
            click: this.handleShare
          }
        }
      ],
      // 表格
      getListApi: this.$apis.proManage.getListApi,
      tableParams: {
        listName: 'list',
        tableOption: true,
        tableColumns: [
          {
            label: '商品名称',
            prop: 'goodsName',
            width: 220,
            line: 2
          },
          {
            label: '缩略图',
            prop: 'goodsImage',
            addHtml: 'goodsImage'
          },
          {
            label: '浏览量(次)',
            name: 'goodsStatistics',
            width: '180',
            formatter: cellValue => {
              return cellValue.goodsStatistics ? cellValue.goodsStatistics.viewAmount || '0' : '0'
            }
          },
          {
            label: '销量',
            name: 'goodsStatistics',
            formatter: cellValue => {
              return cellValue.goodsStatistics ? cellValue.goodsStatistics.saleAmount || '0' : '0'
            }
          },
          {
            label: '零售价(元)',
            name: 'retailPrice',
            width: '180',
            formatter: cellValue => {
              return cellValue.retailPrice
            }
          },
          {
            label: '库存',
            name: 'goodsStock',
            formatter: cellValue => {
              return cellValue.goodsStock || '0'
            }
          },
          {
            label: '创建日期',
            prop: 'createdDate',
            width: '180',
            formatter: cellValue => {
              return dayjs(cellValue.createdDate).format('YYYY-MM-DD HH:mm:ss')
            }
          },
          {
            label: '商品状态',
            name: 'goodsStatus',
            formatter: cellValue => {
              return this.baseData.goodsStatusList.find(item => item.confId == cellValue.goodsStatus).confName
            }
          },
          {
            label: '带货来源',
            name: 'goodsSource',
            formatter: cellValue => {
              return this.baseData.goodsSourceList.find(item => item.confId == cellValue.goodsSource).confName
            }
          }
        ]
      },
      pageConf: { pageSize: 'pageSize', pageNum: 'pageNum', totalCount: 'total' },
      baseData: {
        goodsStatusList: [
          {
            confId: '0',
            confName: '已下架'
          },
          {
            confId: '1',
            confName: '已上架'
          }
        ],
        goodsSourceList: [
          {
            confId: '1',
            confName: '门店'
          },
          {
            confId: '2',
            confName: '带货'
          },
          {
            confId: '3',
            confName: '总部商品'
          },
          {
            confId: '4',
            confName: '配置升级商品'
          },
          {
            confId: '5',
            confName: '车主优选商品'
          }
        ]
      }
    }
  },

  components: {
    shareDialog
  },
  created() {},
  mounted() {
    this.getOptionsList('searchFormData')
  },

  methods: {
    getParams() {
      var params = JSON.parse(JSON.stringify(this.searchForm))
      if (this.searchForm.createDate.length) {
        params.startTime = new Date(this.searchForm.createDate[0]).toLocaleDateString().replace(/\//g, '-') + ' 00:00:00'
        params.endTime = new Date(this.searchForm.createDate[1]).toLocaleDateString().replace(/\//g, '-') + ' 23:59:59'
      }
      delete params.createDate
      return params
    },
    beforeSearchFn() {
      return new Promise(resolve => {
        this.tableSearchForm = this.getParams()
        delete this.tableSearchForm.createDate
        resolve()
      })
    },

    secondConfirm(title, txt, apiModule, apiName, apiParams, fn) {
      this.$confirm(txt, title, {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        callback: action => {
          if (action == 'confirm') {
            this.$apis[apiModule][apiName](apiParams).then(res => {
              this.$message({
                message: res.code == '0' ? '操作成功' : res.message,
                type: res.code == '0' ? 'success' : 'error'
              })
              if (res.code == '0') {
                fn && fn()
                this.handleSearch()
              }
            })
          }
        }
      })
    },
    // addOrEdit:1-新增;2-编辑;3-查看
    // groupOrStore:1-集团;2-门店
    // goodsSource: 1-门店;2-带货
    handleEdit(addOrEdit, row) {
      var titleObj = {
        1: '新建商品',
        2: '编辑商品',
        3: '查看商品'
      }
      var params = {
        addOrEdit: addOrEdit,
        groupOrStore: 2,
        $title: encodeURI(titleObj[addOrEdit])
      }
      addOrEdit != 1 && (params.id = row.id)
      this.$router.push({
        path: '/productGroup/editProduct',
        query: params
      })
    },
    handleEditDh(addOrEdit, row) {
      var titleObj = {
        2: '编辑商品',
        3: '查看商品'
      }
      var params = {
        addOrEdit: addOrEdit,
        id: row.id,
        $title: encodeURI(titleObj[addOrEdit])
      }
      this.$router.push({
        path: '/productStore/editProductDh',
        query: params
      })
    },
    // 下架通知
    handleDwonNotice(row) {
      this.$alert('你带货的' + row.goodsName + '商品现已下架,下架原因:' + row.offReason, '商品下架通知', {
        confirmButtonText: '确定',
        callback: action => {}
      })
    },
    handleUpOrDown(row) {
      var title = row.goodsStatus == 0 ? '上架' : '下架'
      this.secondConfirm(title, '是否确认' + title + '该商品?', 'proManage', 'updateStatusProApi', { id: row.id, goodsStatus: row.goodsStatus == 0 ? 1 : 0 })
    },
    // 取消带货
    handleTakeGood(row) {
      this.secondConfirm('取消带货', '是否确认取消带货该商品?', 'proManage', 'deleteTakeProApi', { id: row.id })
    },
    // 删除
    del(row) {
      this.secondConfirm('删除', '确定删除此商品?', 'proManage', 'deleteGoodsApi', { id: row.id })
    },
    dwonVisibleChange() {
      this.$refs.downRef && this.$refs.downRef.clearValidate()
      this.isDownVisible = !this.isDownVisible
    },
    handleDownClose() {
      this.dwonVisibleChange()
      this.downForm = {
        id: '',
        offReason: '',
        goodsStatus: 0
      }
    },
    handleDownConfirm() {
      this.$refs.downRef.validate(valid => {
        if (valid) {
          this.$apis.proManage.updateStatusProApi(this.downForm).then(res => {
            this.$message({
              message: res.code == '0' ? '操作成功' : res.message,
              type: res.code == '0' ? 'success' : 'error'
            })
            if (res.code == '0') {
              this.handleDownClose()
              this.handleSearch()
            }
          })
        }
      })
    },
    // 置顶
    handleTop(row) {
      this.secondConfirm('置顶', '是否确认置顶该商品?', 'proManage', 'topProApi', { id: row.id })
    },

    handleShare(row) {
      this.$apis.proManage.getProShareApi({ id: row.id }).then(res => {
        this.shareForm = res
        this.handleShareClose()
      })
    },

    handleShareClose() {
      this.isShareVisible = !this.isShareVisible
    },

    getOptionsList(formName, hasAll = true, refreshSigle) {
      if (refreshSigle) {
        var item = this[formName].find(k => k.name == refreshSigle)
        var index = this[formName].findIndex(k => k.name == refreshSigle)
        this.$set(this[formName][index], 'optionList', this.$common.utils.deepClone(this.baseData[item.optionsName]))
        if (hasAll && this.baseData[item.optionsName].length && this.baseData[item.optionsName][0][this[formName][index].optionLabel] !== '全部') {
          const temp = {}
          temp[this[formName][index].optionId] = ''
          temp[this[formName][index].optionLabel] = '全部'
          this[formName][index].optionList.unshift(temp)
        }
      } else {
        this[formName].forEach((item, index) => {
          if (item.type === 'select' && this.baseData[item.optionsName].length) {
            this.$set(this[formName][index], 'optionList', this.$common.utils.deepClone(this.baseData[item.optionsName]))
            if (hasAll && this.baseData[item.optionsName].length && this.baseData[item.optionsName][0][this[formName][index].optionLabel] !== '全部') {
              const temp = {}
              temp[this[formName][index].optionId] = ''
              temp[this[formName][index].optionLabel] = '全部'
              this[formName][index].optionList.unshift(temp)
            }
          }
        })
      }
    },

    setTableFinishFun() {
      //接收到的数据为空
      if (!this.$refs.proGroupRef.data.length) {
        this.$refs.proGroupRef.setTableHeightFun()
      } else {
        this.$refs.proGroupRef.tableHeightValues = ''
        this.$refs.proGroupRef.data.forEach(item => {
          item.saleAmount = item.goodsStatistics&&item.goodsStatistics.saleAmount
          if (item.specificationDetailList && item.specificationDetailList.length > 1) {
            let retailPriceList = JSON.parse(JSON.stringify(item.specificationDetailList))
            retailPriceList.sort((a, b) => {
              return a.retailPrice - b.retailPrice
            })
            let stockeList = JSON.parse(JSON.stringify(item.specificationDetailList))
            stockeList.sort((a, b) => {
              return a.stock - b.stock
            })
            let minRatilPrice = retailPriceList[0].retailPrice / 100
            let maxRatilPrice = retailPriceList[retailPriceList.length - 1].retailPrice / 100
            let minStock = stockeList[0].stock
            let maxStock = stockeList[stockeList.length - 1].stock
            item.retailPrice = minRatilPrice == maxRatilPrice ? minRatilPrice.toFixed(2) : minRatilPrice.toFixed(2) + '-' + maxRatilPrice.toFixed(2)
            item.minRatilPrice = minRatilPrice.toFixed(2)
            item.goodsStock = minStock == maxStock ? minStock : minStock + '-' + maxStock
          } else if (item.specificationDetailList && item.specificationDetailList.length == 1) {
            item.retailPrice = (item.specificationDetailList[0].retailPrice / 100).toFixed(2)
            item.minRatilPrice = item.retailPrice
            item.goodsStock = item.specificationDetailList[0].stock
          } else {
            item.retailPrice = (item.retailPrice / 100).toFixed(2)
            item.minRatilPrice = item.retailPrice
          }
        })
      }
    },

    handleSearch() {
      this.$refs.proGroupRef.refreshTable()
    },

    handleReset() {
      this.searchForm = {
        goodsName: '',
        createDate: [],
        goodsStatus: ''
      }
      this.handleSearch()
    }
  }
}
</script>

<style scoped>
.gold-sign {
  width: 48px;
  height: 20px;
  background: #fee9cc;
  border-radius: 2px;
  white-space: nowrap;
  font-size: 12px;
  color: #fdb757;
  text-align: center;
  line-height: 20px;
}
</style>