<template>
  <a-card size="small" :bordered="false" class="noticeManagementList-wrap">
    <a-spin :spinning="spinning" tip="Loading...">
      <!-- 设置条件 -->
      <div class="setTit">大屏参数设置</div>
      <div ref="setList" class="table-page-search-wrapper">
        <a-form-model
          layout="inline"
          :model="form"
          ref="ruleForm"
          :rules="rules"
          :label-col="labelCol"
          :wrapper-col="wrapperCol">
          <a-row>
            <a-col :md="13" :sm="24">
              <div class="flexBox">
                <a-form-model-item label="销售系数:" prop="saleNum">
                  <a-input style="width:93%;margin-right: 10px;" v-model.trim="form.saleNum" allowClear placeholder="请输入销售系数" oninput="if(!/^[0-9]+$/.test(value)) value=value.replace(/\D/g,'');if(value>99900)value=99900;if(value<0)value=null"></a-input>
                  <span>%</span>
                </a-form-model-item>
              </div>
            </a-col>
            <a-col :md="13" :sm="24">
              <a-form-model-item label="销售额类型:" prop="saleType">
                <a-select v-model="form.saleType" placeholder="请选择销售额类型">
                  <a-select-option value="sale_price">开单金额</a-select-option>
                  <a-select-option value="real_price">实售金额</a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
          </a-row>
        </a-form-model>
      </div>
      <!-- 操作按钮 -->
      <div class="table-operator">
        <a-button id="noticeManagementList-add" type="primary" class="button-error" @click="handleAdd" :loading="iconLoading">确定</a-button>
      </div>
    </a-spin>
  </a-card>
</template>

<script>
import { commonMixin } from '@/utils/mixin'
import { VSelect } from '@/components'
import { queryList, batchUpdateByCode } from '@/api/sysParamsConfig'
export default {
  name: 'BigScreenSetIndex',
  mixins: [commonMixin],
  components: { VSelect },
  data () {
    return {
      spinning: false,
      form: { //  查询条件
        saleNum: undefined,
        saleType: undefined
      },
      labelCol: { span: 4 },
      wrapperCol: { span: 14 },
      listData: [],
      saleNumPos: null,
      saleTypePos: null,
      rules: {
        saleNum: [{ required: true, message: '销售系数不能为空', trigger: 'blur' }],
        saleType: [{ required: true, message: '销售额类型不能为空', trigger: 'change' }]
      },
      iconLoading: false
    }
  },
  methods: {
    // 获取数据
    getData () {
      this.spinning = true
      queryList({ }).then(res => {
        if (res.status == 200) {
          this.listData = res.data
          if (res.data) {
            this.saleNumPos = res.data.findIndex(con => con.code === 'DATA_SCREEN_DATA_RATIO')
            this.saleTypePos = res.data.findIndex(con => con.code === 'DATA_SCREEN_AMOUNT_TYPE')
          }
          this.form.saleNum = res.data ? res.data[this.saleNumPos].value * 100 : ''
          this.form.saleType = res.data ? res.data[this.saleTypePos].value : ''
          this.spinning = false
        } else {
          this.detailsData = null
        }
      })
    },
    handleAdd () {
      this.iconLoading = true
      const saleNum = this.form.saleNum / 100
      const data = [{ code: this.listData[this.saleTypePos].code, value: this.form.saleType }, { code: this.listData[this.saleNumPos].code, value: saleNum }]
      batchUpdateByCode(data).then(res => {
        if (res.status == 200) {
          this.$message.success('设置成功！')
        }
        this.iconLoading = false
      })
    }
  },
  created () {
    this.getData()
  }
}
</script>
<style lang="less" scoped>
  .setTit{
    font-weight:bold;
    font-size:16px;
    padding:20px 0;
  }
  .flexBox{
    margin-bottom:30px;
  }
  .table-operator{
    margin-top:30px;
    margin-left: 100px;
  }
</style>
