outputValueDialog.vue 8.99 KB
<template>
  <d2-dialog :title="'单店目标产值'"
             :isVisible="outputVisible"
             :width="'880px'"
             @closeDialog="handleImport"
             @confirmDialog="handleConfirmImport">
    <slot>
      <div class="searchWrap">
        <el-col :span="13">
          <el-date-picker v-model="search.targetDate"
                          :clearable="false"
                          type="month"
                          format="yyyy 年 MM 月"
                          value-format="yyyy-MM"
                          :picker-options="pickerOptions"
                          placeholder="选择月">
          </el-date-picker>
        </el-col>
        <el-col :span="9">
          <el-input v-model="search.keyword"
                    clearable
                    placeholder="输入门店名称搜索"></el-input>

        </el-col>
        <el-col :span="2"
                class="btnContainer">
          <el-button type="primary"
                     @click="getList"
                     class="searchBtn">搜索</el-button>
        </el-col>
        <!-- <div class="searchInput">

        </div> -->
      </div>
      <div class="yqdTableContainer">
        <!-- border -->
        <el-table :data="tableData"
                  stripe
                  max-height="450"
                  :header-cell-style="rowClass"
                  style="width: 100%">
          <el-table-column label="序号"
                           type="index"
                           width="50">
          </el-table-column>
          <el-table-column prop="yqMerchantName"
                           label="园区店列表"
                           width="300">
          </el-table-column>
          <el-table-column prop="merchantName"
                           label="门店列表"
                           width="300">
          </el-table-column>
          <!-- <el-table-column prop="outputValue"
                           label="门店列表">
          </el-table-column> -->
          <!--  width="260" -->
          <el-table-column prop="outputValue"
                           label="产值目标">
            <template slot-scope="scope">
              <!-- <div>slot-scope="scope"</div> &&item.isEdit-->
              <span v-if="!scope.row['isEdit']">{{scope.row['outputValue']}}</span>
              <!-- @input="input($event,item)" -->
              <el-input v-else
                        style="width: 140px"
                        @input="handleInput($event,scope)"
                        v-model="scope.row['outputValue']"
                        placeholder=""></el-input>
              <!-- <div></div> -->
            </template>
          </el-table-column>
        </el-table>
        <div class="tips">填写后不支持修改,请谨慎输入。</div>
      </div>
    </slot>
  </d2-dialog>
</template>

<script>
import { limitPrice } from '@/common/constants'
// import moment from 'moment'
import dayjs from 'dayjs'
import { getMerchantOutputValueTarget, setMerchantOutputValueTarget } from '@api/index'
export default {
  props: {
    isShow: {
      // 弹窗是否展示
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      pickerOptions: {
        disabledDate: (time) => {
          const maxMonth = dayjs().subtract(-1, 'months').endOf('month')
          const minMonth = dayjs().subtract(5, 'months').startOf('month')
          // console.log(minMonth.valueOf())
          // console.log(time.getTime())
          // time.getTime() > minMonth.valueOf() ||
          return time.getTime() > maxMonth.valueOf() || time.getTime() < minMonth.valueOf()
        }
      },
      nowMonth: dayjs().subtract(0, 'months').startOf('month').format('YYYY-MM'),
      nextMonth: dayjs().subtract(-1, 'months').startOf('month').format('YYYY-MM'),
      search: {
        keyword: '',
        targetDate: ''
      },
      // tableLabel: [],
      tableData: [
        // {
        //   date: '2016-05-02',
        //   name: '王小虎',
        //   address: '上海市普陀区金沙江路 1518 弄'
        // }
        // , {
        //   date: '2016-05-04',
        //   name: '王小虎',
        //   address: '上海市普陀区金沙江路 1517 弄'
        // }, {
        //   date: '2016-05-04',
        //   name: '王小虎',
        //   address: '上海市普陀区金沙江路 1517 弄'
        // }, {
        //   date: '2016-05-04',
        //   name: '王小虎',
        //   address: '上海市普陀区金沙江路 1517 弄'
        // }, {
        //   date: '2016-05-04',
        //   name: '王小虎',
        //   address: '上海市普陀区金沙江路 1517 弄'
        // }, {
        //   date: '2016-05-04',
        //   name: '王小虎',
        //   address: '上海市普陀区金沙江路 1517 弄'
        // }, {
        //   date: '2016-05-01',
        //   name: '王小虎',
        //   address: '上海市普陀区金沙江路 1519 弄'
        // }, {
        //   date: '2016-05-01',
        //   name: '王小虎',
        //   address: '上海市普陀区金沙江路 1519 弄'
        // }, {
        //   date: '2016-05-01',
        //   name: '王小虎',
        //   address: '上海市普陀区金沙江路 1519 弄'
        // }, {
        //   date: '2016-05-01',
        //   name: '王小虎',
        //   address: '上海市普陀区金沙江路 1519 弄'
        // }, {
        //   date: '2016-05-01',
        //   name: '王小虎',
        //   address: '上海市普陀区金沙江路 1519 弄'
        // }, {
        //   date: '2016-05-03',
        //   name: '王小虎',
        //   address: '上海市普陀区金沙江路 1516 弄'
        // }
      ]
      // outputVisible: true
    }
  },
  computed: {
    outputVisible: {
      get() {
        return this.isShow
      },
      set(val) {
        this.$emit('update:isShow', false)
      }
    }
  },
  mounted() {
    // console.log(this.nowMonth)
    this.search.targetDate = this.nowMonth
    this.getList()
    // console.log(moment().subtract(-1, 'months').endOf('month').format('YYYY-MM-DD'))
    // console.log(moment().subtract(5, 'months').startOf('month').format('YYYY-MM-DD'))
  },
  methods: {
    getList() {
      getMerchantOutputValueTarget(this.search).then((result) => {
        const monthCheck = [this.nowMonth, this.nextMonth].includes(this.search.targetDate)
        // console.log(monthCheck)
        // 处理值能否编辑的问题
        const listFilter = result
        // 要单月或者下月并且值为0才可以编辑
        this.tableData = listFilter.map((item) => {
          item.dataMonth = this.search.targetDate
          item.isEdit = monthCheck && !item.outputValue
          return item
        })
        // console.log(result)
        this.tableData = result
        // console.log(this.tableData)
      }).catch((err) => {
        console.log(err)
      })
    },
    handleInput(newValue, item) {
      // console.log(newValue, item)

      // let limitNum = limitPrice
      // console.log(limitPrice(newValue, item.row.outputValue, 6))
      newValue = newValue.replace(/[^\d.]/g, '') // 清除“数字”和“.”以外的字符
      // console.log(newValue)
      this.tableData[item.$index]['outputValue'] = limitPrice(newValue, item.row.outputValue, 6, 0, 1)
      // console.log(this.tableData[item.$index]['name'])
    },
    // 设置表头的颜色
    rowClass({ row, rowIndex }) {
      // console.log(rowIndex) // 表头行标号为0
      return 'background:#F4F6FC'
    },
    async handleConfirmImport() {
      const filterList = this.tableData.filter((item) => {
        // 删除无需字段 避免后台类型报错
        delete item.createdDate
        delete item.updatedDate
        return item.isEdit && item.outputValue
      })
      if (filterList.length) {
        // console.log('请求修改')
        // const result =
        await setMerchantOutputValueTarget({ list: filterList })
        // console.log(result)
      }
      // else {
      //   console.log('没有能修改的')
      // }
      this.handleImport()
    },
    handleImport() {
      this.outputVisible = false
    }
  }
}
</script>

<style lang="scss" scoped>
::v-deep.searchWrap {
  height: 30px;
  margin-bottom: 10px;
  .el-input__inner {
    height: 30px;
  }
  .el-input__icon {
    line-height: 30px;
  }
  .btnContainer {
    text-align: right;
    padding-right: 10px;
  }
  .searchBtn {
    font-size: 12px;
    padding: 8px 10px;
  }
}
::v-deep.yqdTableContainer {
  .el-table .cell {
    padding: 0 10px;
  }
  // padding-right: 3px;
  .el-table__body-wrapper {
    .el-table__row td:nth-child(1) {
      border-left: 1px solid #ebeef5;
    }
    .el-table__row td:nth-last-child(1) {
      border-right: 1px solid #ebeef5;
    }
  }
}
.tips {
  margin-top: 10px;
  font-size: 12px;
  text-align: right;
  color: #f46967;
}
</style>