index.vue 5.87 KB
<!-- 带货管理 -->
<template>
  <div class="marketing p-t-20">
    <div class="m-b-20">
      <el-button :size="size" type="primary" @click="handleTakeGood()">一键带货</el-button>
    </div>
    <div class="container">
      <div>
        <glsx-combi-form ref="showSearch" :formObj="searchForm" :formData="searchFormData">
          <span slot="footer" class="footer-btns">
            <el-button :size="size" type="default" @click="handleReset">重置</el-button>
            <el-button :size="size" type="primary" @click="handleSearch">查询</el-button>
          </span>
        </glsx-combi-form>
      </div>

      <!-- 表格区域 开始 -->
      <GLTable ref="takeGoodRef" class="table-img" :getListApi="getListApi" :noDataImg="url" :searchForm="tableSearchForm" :tableParams="tableParams" :pageConf="pageConf" :beforeSearchFn="beforeSearchFn" @setTableFinishFun="setTableFinishFun">
        <div slot="goodsImage" class="table-image" slot-scope="scope">
          <img class="img-60" :src="scope.scope.goods.goodsImage" />
        </div>
        <div class="table-btns" slot="auth-button" slot-scope="scope">
          <el-button v-if="!scope.scope.taked" type="text" @click="handleSingleTakeGood(scope.scope)">带货</el-button>
          <el-button type="text" @click="handleDetail(scope.scope)">详情</el-button>
        </div>
      </GLTable>
      <!-- 表格区域 end -->
    </div>
  </div>
</template>

<script>
import * as dayjs from 'dayjs'
import url from "@/assets/empty.png"
export default {
  name: 'takeGood',
  data() {
    return {
      size: 'small',
      url: url,
      searchForm: {
        goodsName: '',
        createDate: []
      },
      tableSearchForm: {},
      // 搜索
      searchFormData: [
        {
          label: '商品名称',
          name: 'goodsName',
          type: 'input',
          maxlength: 20
        },
        {
          label: '创建日期',
          name: 'createDate',
          type: 'datePicker',
          isClear: true,
          pickerOptions: 'beforeRangePickerOptions'
        }
      ],
      // 表格
      getListApi: this.$apis.takeGood.getListApi,
      tableParams: {
        listName: 'list',
        mutiSelectUniqueKey: 'goodsId',
        mutiSelectName: 'takeGood',
        checkSelectKey: 'goodsId',
        checkSelectVal: [],
        tableOption: true,
        tableColumns: [
          {
            label: '商品名称',
            prop: 'goodsName',
            line: 2,
            formatter: cellValue => {
              return cellValue.goods.goodsName
            }
          },
          {
            label: '缩略图',
            prop: 'goodsImage',
            addHtml: 'goodsImage'
          },
          {
            label: '供货价',
            prop: 'supplyPrice',
            formatter: cellValue => {
              return (cellValue.goods.supplyPrice / 100).toFixed(2)
            }
          },
          {
            label: '创建日期',
            prop: 'createdDate',
            width: '180',
            formatter: cellValue => {
              return dayjs(cellValue.goods.createdDate).format('YYYY-MM-DD HH:mm:ss')
            }
          }
        ]
      },
      pageConf: { pageSize: 'pageSize', pageNum: 'currentPage', totalCount: 'total' }
    }
  },

  mounted() {},

  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()
      })
    },

    setTableFinishFun(table) {
      this.tableParams.checkSelectVal = []
      table &&
        table.forEach(item => {
          if (item.taked) {
            this.tableParams.checkSelectVal.push(item.goodsId)
          }
        })
      //接收到的数据为空
      this.$refs.takeGoodRef.data.length ? (this.$refs.takeGoodRef.tableHeightValues = '') : this.$refs.takeGoodRef.setTableHeightFun()
    },

    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()
              }
            })
          }
        }
      })
    },

    handleSingleTakeGood(row) {
      this.secondConfirm('带货', '是否确认带货?', 'takeGood', 'takeGookApi', { takeGoodsIdList: [row.goodsId] })
    },

    handleTakeGood() {
      var selectedList = this.$refs.takeGoodRef.mutiSelectArr[this.tableParams.mutiSelectName]
      if (!selectedList.length) {
        this.$message({
          message: '请勾选要带货的商品',
          type: 'error'
        })
        return true
      }
      this.secondConfirm('带货', '是否确认带货?', 'takeGood', 'takeGookApi', { takeGoodsIdList: selectedList.map(item => item.goodsId) })
    },

    handleDetail(row) {
      this.$router.push('/takeGood/takeGoodDetail/' + row.goodsId)
    },

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

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

<style scoped></style>