<template>
  <div class="flexOne">
    <div class="query-box">
      <ul>
        <li>
          <span><em>{{$t('admin.admin_status')}}</em>
            <el-select v-model='msg.ApplyState' :placeholder="$t('pub.unlimitedSel')">
              <el-option :label="$t('pub.unlimitedSel')" value='-1'></el-option>
              <el-option :label="$t('fnc.a_shezhong')" value='0'></el-option>
              <el-option :label="$t('visa.v_tongguo')" value='1'></el-option>
              <el-option :label="$t('visa.v_jujue')" value='2'></el-option>
            </el-select>
          </span>
        </li>
        <li>
          <input type="button" class="hollowFixedBtn" @click="getList()" :value="$t('pub.searchBtn')" />
        </li>
      </ul>
    </div>
    <table class="singeRowTable" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <th width="100">{{$t('visaT.Applicant')}}</th>
        <th width="150">{{$t('salesModule.ApplyTime')}}</th>
        <th width="200">{{$t('hotel.order_Number')}}</th>
        <th>{{$t('salesModule.OriginalOrder')}}</th>
        <th>{{$t('salesModule.ApplyPrice')}}</th>
        <th>{{$t('salesModule.ApplyStatus')}}</th>
        <th>{{$t('salesModule.ReviewReason')}}</th>
        <th>{{$t('salesModule.ApplyReason')}}</th>
        <th width="200">{{$t('system.table_operation')}}</th>
      </tr>
      <tr v-for="(item,index) in dataList">
        <td>{{item.CreateByStr}}</td>
        <td>{{item.CreateDate.replace('T', ' ')}}</td>
        <td>{{item.OrderId}}</td>
        <td>{{item.OrderUnitPrice}}</td>
        <td>{{item.ApplyPrice}}</td>
        <td>{{item.ApplyState == 0 ? '审核中' : (item.ApplyState == 1 ? '通过' : (item.ApplyState == 2 ? '拒绝' : ''))}}</td>
        <td>{{item.Reasons}}</td>
        <td>{{item.ApplyReason}}</td>
        <td>
          <el-row v-if="item.ApplyState === 0">
            <button class="normalBtn" type="primary" @click="outerVisible = true,dialogTitle='审核理由',addMsg.ID=item.ID,addMsg.ApplyState= 1,addMsg.Reasons=item.Reasons, GetApplyLessPrice(item)">{{$t('salesModule.Agree')}}</button>
            <button class="hollowFixedBtn" @click="outerVisible = true,dialogTitle='拒绝理由',addMsg.ID=item.ID,addMsg.ApplyState= 2,addMsg.Reasons=item.ApplyReason, GetApplyLessPrice(item, 1)">{{$t('visa.v_jujue')}}</button>
          </el-row>
        </td>
      </tr>
    </table>
    <div class="noDataNotice" v-if="dataList.length<1">
      <i class="iconfont icon-kong"></i>
      <p>{{$t("active.ld_noData")}}</p>
    </div>
    <el-dialog custom-class='w450' :title="dialogTitle" :visible.sync="outerVisible" center :before-close="closeChangeMachie">
      <el-form  :rules="rules" ref="addMsg" label-width="100px">
        <el-form-item :label="$t('fnc.cjdanjia')" prop="Description">
          <el-input v-if="EmployeeId === 1" class='w217' v-model="addMsg.ApplyPrice"></el-input>
          <el-select v-model='addMsg.ApplyPrice' v-else>
              <el-option v-for="price in Unit_PriceList" :label='price.LessMoney' :value='price.ID' :key='price.ID'></el-option>
            </el-select>
        </el-form-item>
        <el-form-item :label="$t('system.label_info')" prop="Description">
          <el-input maxlength='250' class='w217' type="textarea" v-model="addMsg.Reasons"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <button class="hollowFixedBtn" @click="outerVisible = false">{{$t('pub.cancelBtn')}}</button>
        &nbsp;
        <button class="normalBtn" type="primary" @click="submitForm()">{{$t('pub.sureBtn')}}</button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        switchValue: '1',
        dialogTitle: '',
        outerVisible: false,
        versions: [],
        dataList: [],
        msg: {
          pageIndex: 1,
          pageSize: 15,
          ApplyState: '-1',
        },

        addMsg: {
          Reasons: '',
          ApplyState:"",
          ID:'',
          ApplyPrice: '',
        },
        rules: {
          Name: [{
            required: true,
            message: this.$t('system.ph_name'),
            trigger: 'blur'
          }],
          Status: [{
            required: false,
            message: '',
            trigger: 'change'
          }],
          Description: [{
            required: false,
            message: this.$t('adm.adm_qsrmiaoshu'),
            trigger: 'change'
          }],

        },
        verSionMsg: {
          Status: 0
        },
        EmployeeId: -11,
        Unit_PriceList: []
      }
    },
    mounted() {
      this.getList()
      let userInfo = this.getLocalStorage();
      this.EmployeeId = userInfo.EmployeeId
    },
    methods: {
      GetApplyLessPrice: function (obj ,type) { 
        this.addMsg.ApplyPrice = ''
        this.Unit_PriceList = [];
        if (type) {
          var objk = {
            ID: '',
            LessMoney: ''
          }
          objk.ID = obj.OrderUnitPrice;
          objk.LessMoney = obj.OrderUnitPrice;
          this.Unit_PriceList.push(objk);
          return false
        }
        let msg = {
          ID: obj.OrderId,
          userId: obj.UpdateBy
        }
        this.apipost("lessprice_post_GetApplyLessPrice", msg, res => {
          if (res.data.resultCode == 1) {
            let LessMoney = res.data.data.LessMoney;
            let OrderOldPrice = res.data.data.OrderOldPrice;
            if (parseFloat(LessMoney)>0){
              for (var i = 0; i <= parseInt(LessMoney)/10; i++) {
                var objk = {
                  ID: '',
                  LessMoney: ''
                }
                objk.ID = OrderOldPrice-i*10;
                objk.LessMoney = OrderOldPrice-i*10;
                this.Unit_PriceList.push(objk);
              }
              if(this.Unit_PriceList.findIndex(markers => markers.ID == OrderOldPrice)<0) {
                var objk = {
                  ID: '',
                  LessMoney: ''
                }
                objk.ID = OrderOldPrice;
                objk.LessMoney = OrderOldPrice;
                this.Unit_PriceList.push(objk);
              }
            }
            else{
              var objk = {
                ID: '',
                LessMoney: ''
              }
              objk.ID = OrderOldPrice;
              objk.LessMoney = OrderOldPrice;
              this.Unit_PriceList.push(objk);
            }
          }
        }, err => {})
      },
      getList() { //获取列表数据
        this.apipost("lessprice_get_GetLesspriceOrderPageList", this.msg, res => {
          if (res.data.resultCode == 1) {
            this.dataList = res.data.data.pageData;
          }
        }, err => {})
      },

      getVersion() { //获取版本信息
        this.apipost('admin_get_SysVersionsGetList', this.verSionMsg, res => {
          this.versions = res.data.data;
        }, err => {})
      },
      closeChangeMachie(done) {  //  转交窗口关闭
        done();
      },
      submitForm(){ 
        if (!this.addMsg.ApplyPrice || this.addMsg.ApplyPrice < 0) {
          this.$message.error('请填写大于等于0的金额')
          return
        }
        this.apipost("lessprice_post_UpdateLesspriceOrder", this.addMsg, res => {
          if (res.data.resultCode == 1) {
            this.$message.success(res.data.message)
            this.outerVisible = false;
            this.addMsg.Reasons = '';
            this.addMsg.ApplyPrice = '';
            this.getList()
          }
          else {
            this.$message.error(res.data.message)
            this.outerVisible = false;
            this.addMsg.Reasons = '';
            this.addMsg.ApplyPrice = '';
          }
        }, err => {})
      }
    },

  }
</script>
