index.vue 15.1 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
<!-- 采购上架 -->
<template>
  <div class="purchase">
    <div class="container">
      <GLCombiForm ref="showSearch" :rowNumber="2" :formObj="searchForm" :formData="showFormData" @handleOk="handleSearch" @handleRest="handleReset"></GLCombiForm>
      <div class="table-header">
        <h2>采购上架列表</h2>
        <div>
          <GLButton type="primary" plain size="small" @click="handleEdit('add')" fn="新增上架">新增上架</GLButton>
          <GLButton size="small" @click="exportExcel" fn="导出">导出</GLButton>
        </div>
      </div>

      <!-- 表格区域 开始 -->
      <GLTable ref="orderRef" :getListApi="getListApi" :noDataImg="url" :searchForm="tableSearchForm" :tableParams="tableParams" :pageConf="pageConf" :beforeSearchFn="beforeSearchFn" @setTableFinishFun="setTableFinishFun">
        <div slot="merchantName" slot-scope="scope">
          <el-tooltip v-if="scope.scope.merchantList && scope.scope.merchantList.length > 0" placement="top" effect="light">
            <div slot="content">
              <div class="text-3 font-12 weight-6" style="line-height:24px">上架门店</div>
              <div class="merchant-wrap">
                 <div class="text-6 font-12" style="line-height:24px" v-for="item in scope.scope.merchantList" :key="item">{{ item.merchantName }}</div>
              </div>
             
            </div>
            <div class="use-store">
              <img src="@/assets/store.png" />
              x {{ scope.scope.merchantList.length }}
            </div>
          </el-tooltip>
          <span v-else>--</span>
        </div>
        <template slot="status" slot-scope="scope">
          <div>
            <span :class="Spot[scope.scope.status]"></span>
            <span >{{ scope.scope.status | groundingStatus }}</span>
          </div>
        </template>
        <div class="table-btns" slot="auth-button" slot-scope="scope">
          <GLTableButton :buttonList="tableButtonList" :buttonItem="scope.scope" :buttonNum="3"></GLTableButton>
        </div>
      </GLTable>
      <!-- 表格区域 end -->
    </div>
  </div>
</template>

<script>
import * as dayjs from 'dayjs'
import url from '@/assets/empty.png'
import { purchaseGroundingStatusList, goodsSourceOptions } from '@/utils/constants.js'
export default {
  name: 'purchaseGroundingIndex',
  data() {
    return {
      size: 'small',
      url: url,
      Spot:['yellowSpot','ashSpot','greenSpot'],
      searchForm: {
        upgradeGoodsName: '',
        type: '',
        shopMerchantIdList: '',
        goodsName: '',
        goodsType: '',
        goodsSource: '',
        status: '',
        merchantId: this.$globalState?.session?.merchantId
      },
      tableSearchForm: {},
      paramsObj: {},
      // 查看门店
      detailVisible: false,
      showFormData: [
        {
          label: '商品名称',
          name: 'upgradeGoodsName',
          type: 'input',
          isClear: true
        },
        {
          label: '商品编码',
          name: 'type',
          type: 'input',
          isClear: true
        },
        {
          label: '所属系列',
          name: 'goodsName',
          type: 'input',
          maxlength: 20,
          isClear: true
        },
        {
          label: '所属分类',
          name: 'goodsType',
          type: 'select',
          optionList: [],
          optionId: 'goodsType',
          optionLabel: 'goodsTypeName',
          optionsName: 'classificationOptions' 
        },
        {
          label: '商品来源',
          name: 'goodsSource',
          type: 'select',
          optionList: [],
          optionId: 'id',
          optionLabel: 'label',
          optionsName: 'goodsSourceOptions'
        },
        {
          label: '上架门店',
          name: 'shopMerchantIdList',
          type: 'select',
          optionList: [],
          optionId: 'merchantId',
          optionLabel: 'merchantName',
          optionsName: 'merchantList'
        },
        {
          label: '状态',
          name: 'status',
          type: 'select',
          optionList: [],
          optionId: 'id',
          optionLabel: 'label',
          optionsName: 'purchaseGroundingStatusList'
        }
      ],
      tableButtonList: [
        {
          type: 'GLButton',
          name: '查看',
          attrs: {
            type: 'text',
            fn: '查看'
          },
          condition: row => {
            return row.status == 2 || row.status == 1 // 已上架/已下架
          },
          listeners: {
            click: this.handleDetail
          }
        },
        {
          type: 'GLButton',
          name: '编辑',
          attrs: {
            type: 'text',
            fn: '编辑'
          },
          listeners: {
            click: row => this.handleEdit('edit', row)
          }
        },
        {
          type: 'GLButton',
          name: '下架',
          attrs: {
            type: 'text',
            fn: '上下架'
          },
          condition: row => {
            return row.status == 2
          },
          listeners: {
            click: this.handleUpDown
          }
        },
        {
          type: 'GLButton',
          name: '上架',
          attrs: {
            type: 'text',
            fn: '上下架'
          },
          condition: row => {
            return row.status == 1
          },
          listeners: {
            click: this.handleUpDown
          }
        },
        {
          type: 'GLButton',
          name: '删除',
          attrs: {
            type: 'text',
            fn: '删除'
          },
          condition: row => {
            return row.status == 0 // 草稿状态
          },
          listeners: {
            click: this.handleDelete
          }
        }
      ],
      // 表格
      getListApi: this.$apis.grounding.getPurchaseGroundingList,
      tableParams: {
        listName: 'list',
        tableOption: {
          width: '150px'
        },
        tableColumns: [
          {
            label: '商品来源',
            prop: 'goodsSource',
            width: '200',
            formatter: cellValue => {
              return goodsSourceOptions.findIndex(v => v.id == cellValue.goodsSource) > -1 ? goodsSourceOptions[goodsSourceOptions.findIndex(v => v.id == cellValue.goodsSource)].label : '-'
            }
          },
          {
            label: '商品名称',
            prop: 'createdDate',
            formatter: cellValue => {
              return cellValue?.upgradeGoods?.upgradeGoodsName || cellValue?.upgradeGoodsName
            }
          },
          {
            label: '商品编码',
            prop: 'type',
            formatter: cellValue => {
              return cellValue?.upgradeGoods?.type || cellValue?.type
            }
          },
          {
            label: '系列',
            prop: 'goodsName',
            formatter: cellValue => {
              return cellValue?.goodsInfo?.goodsName || cellValue?.goodsName
            }
          },
          {
            label: '所属分类',
            prop: 'goodsTypeName',
            formatter: cellValue => {
              return cellValue?.goodsInfo?.goodsTypeName || cellValue?.goodsTypeName
            }
          },
          {
            label: '门店采购价/元',
            prop: 'shopPurchasePrice',
            formatter: cellValue => {
              return cellValue.shopPurchasePrice ? '¥' + cellValue.shopPurchasePrice : '-'
            }
          },
          {
            label: '嘀加采购价/元',
            prop: 'purchasePrice',
            formatter: cellValue => {
              return cellValue?.upgradeGoods?.purchasePrice ? '¥' + cellValue?.upgradeGoods?.purchasePrice : '-'
            }
          },
          {
            label: '上架门店',
            prop: '',
            addHtml: 'merchantName'
          },
          {
            label: '状态',
            prop: '',
            addHtml: 'status'
          }
        ]
      },
      pageConf: { pageSize: 'pageSize', pageNum: 'currentPage', totalCount: 'total' },
      // 基本数据
      baseData: {
        purchaseGroundingStatusList: purchaseGroundingStatusList, // 状态
        goodsSourceOptions: goodsSourceOptions, // 商品来源
        merchantList: [], // 上架门店 
        goodsSeriesList: [], // 所属系列
        classificationOptions: [] // 所属分类
      },
      tipsTitleStyle: 'style="font-size: 16px;color: #333333;"',
      tipsContentStyle: 'style="font-size: 14px;color: #666666;"'
    }
  },

  mounted() {
    // 获取所属分类
    this.getPurchaseGroundingSearchSelectData(1)
    // 获取上架门店
    this.getMerchantList()
  },

  methods: {
    getParams() {
      var params = JSON.parse(JSON.stringify(this.searchForm))
      if (params.shopMerchantIdList) params.shopMerchantIdList = [params.shopMerchantIdList]
      return params
    },
    beforeSearchFn() {
      return new Promise(resolve => {
        this.tableSearchForm = this.getParams()
        resolve()
      })
    },
    // 所属系列 所属分类
    getPurchaseGroundingSearchSelectData(num) {
      this.$apis.grounding.getPurchaseGroundingSearchSelectData({ dataType: num }).then(res => {
        this.baseData['classificationOptions'] = res || []
        this.getOptionsList('showFormData')
      })
    },
    // 上架门店
    getMerchantList() {
      this.$apis.grounding.getSimpleMerchantList({scene: 1, merchantId: this.$globalState?.session?.merchantId}).then(res => {
        this.baseData.merchantList = res || []
        this.getOptionsList('showFormData')
      })
    },
    secondConfirm(title, txt, apiModule, apiName, apiParams, fn) {
      this.$confirm(txt, title, {
        confirmButtonText: '是',
        cancelButtonText: '否',
        dangerouslyUseHTMLString: true,
        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()
              }
            })
          }
        }
      })
    },
    // 查看详情
    handleDetail(row) {
      this.$router.push({
        path: '/purchaseGrounding/detail',
        query: row
      })
    },
    //新增-编辑
    handleEdit(editType, row) {
      let params = {
        editType,
        id: row?.id,
        $title: encodeURI(editType == 'add' ? '新增上架' : '编辑上架')
      }
      this.$router.push({
        path: '/purchaseGrounding/add',
        query: params
      })
    },
    //删除
    handleDelete(row) {
      this.secondConfirm('删除', `<p ${this.tipsTitleStyle}>是否确定删除?</p><p ${this.tipsContentStyle}>删除后不可恢复</p>`, 'grounding', 'delPurchaseGrounding', { id: row.id })
    },
    //上下架
    handleUpDown(row) {
      if (row.status == 2) { // 已上架
        this.secondConfirm('下架', `<p ${this.tipsTitleStyle}>是否确定下架?</p><p ${this.tipsContentStyle}>下架后,门店无法再对该商品进行采购</p>`, 'grounding', 'updatePurchaseGroundingStatus', { id: row.id, status: 1 })
      } else if (row.status == 1) { // 已下架
        this.secondConfirm('上架', `<p ${this.tipsTitleStyle}>是否确定上架?</p><p ${this.tipsContentStyle}>上架后,门店可对该商品进行采购</p>`, 'grounding', 'updatePurchaseGroundingStatus', { id: row.id, status: 2 })
      }
    },

    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() {
      //接收到的数据为空
      this.$refs.orderRef.data.length ? (this.$refs.orderRef.tableHeightValues = '') : this.$refs.orderRef.setTableHeightFun()
    },
    // 创建采购上架
    handleCreatePurchase() {
       this.$router.push('/purchaseGrounding/add')
    },
    exportExcel() {
      var params = this.getParams()
      this.$apis.grounding.exportPurchaseGrounding(params).then(res => {
        window.location.href = res
      })
    },
    handleSearch() {
      this.$refs.orderRef.refreshTable()
    },

    handleReset() {
      this.searchForm = {
        upgradeGoodsName: '',
        type: '',
        shopMerchantIdList: '',
        goodsName: '',
        goodsType: '',
        goodsSource: '',
        status: '',
        merchantId: this.$globalState?.session?.merchantId
      }
      this.handleSearch()
    }
  }
}
</script>

<style scoped lang="scss">
@import '@/assets/css/mixin.scss';
.purchase {
  .table-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
    margin-top: 20px;
    h2 {
      font-weight: 600;
      font-size: 16px;
      color: #333;
    }
    .glbtn {
      left: 46px;
      position: absolute;
    }
    .btn {
      right: 47px;
      position: absolute;
    }
  }
  .greenSpot {
    @include dot;
    background: $color-green;
  }
  .yellowSpot {
    @include dot;
    background: $color-yellow;
  }
  .ashSpot {
    @include dot;
    background: $color-gray;
  }
  .redSpot {
    @include dot;
    background: $color-red;
  }
  .table-btns /deep/.el-button--text {
    min-width: 0 !important;
    padding: 0;
  }
  .use-store{
    display: flex;
    font-size: 14px;
    color: #5850ff;
    align-items: center;
    img {
      width: 14px;
      height: 12.98px;
      margin-right: 8px;
    }
  }
}
.merchant-wrap{
  max-height:200px;
  overflow: scroll;
}
</style>
<style>
.el-tooltip__popper.is-light {
  background: #ffffff;
  box-shadow: 0px 4px 12px 0px rgba(0, 0, 0, 0.08);
  border: 1px solid #e4e7ed !important;
  width: 177px;
  box-sizing: border-box;
}
.el-tooltip__popper[x-placement^='top'] .popper__arrow {
  border-color: #e4e7ed !important;
}

.el-tooltip__popper[x-placement^='top'] .popper__arrow:after {
  border-bottom-color: #e4e7ed !important;
}
</style>