
<template>
  <div class="Feedback ElectricityGoods">
      <ul style="overflow: initial!important">
         <li>
          <span>
            <em>{{$t('MarketingActi.commName')}}</em>
          </span>
          <el-input class='w200' v-model='msg.Name'></el-input>
        </li>

        <li style="float:right;margin-bottom:10px">
          <input
            type="button"
            class="hollowFixedBtn"
            :value="$t('pub.searchBtn')"
            @click="getList()"
          >
          <input v-if="unEdit"
            type="button"
            class="hollowFixedBtn"
            :value="$t('pub.addBtn')"
            @click="addRule"
          >
        </li>
      </ul>
    <table class="singeRowTable" border="0" cellspacing="0" cellpadding="0" v-loading="loading">
      <tr>
        <th>{{$t('hotel.hotel_nameOf')}}</th>
        <th width="100">{{$t('objFill.v101.Rest.zhidanshouru')}}</th>
        <th width="100">{{$t('fnc.shishou')}}</th>
        <th width="100">{{$t('fnc.ptshuijin')}}</th>
        <th width="100">{{$t('fnc.tuikuan')}}</th>
        <th width="100">{{$t('hotel.hotel_cost')}}</th>
        <th>{{$t('system.label_info')}}</th>
        <th>{{$t('admin.admin_czPerson')}}/{{$t('salesModule.Time')}}</th>
        <th  width="250" v-if="unEdit">{{$t('hotel.table_operat')}}</th>
      </tr>
        <tr v-for="(com,i) in dataList" :key="i">
            <td>{{com.Name}}</td>
            <td><span @click="Gourl(com)" style="text-decoration: underline;">{{com.PreferPrice}}</span></td>
            <td><span @click="Gourl(com)" style="text-decoration: underline;">{{com.Income}}</span></td>
            <td><span @click="Gourl(com)" style="text-decoration: underline;">{{com.PlatformTax}}</span></td>
            <td><span @click="Gourl(com)" style="text-decoration: underline;">{{com.Refund}}</span></td>
            <td><span @click="Gourl(com)" style="text-decoration: underline;">{{com.Cost}}</span></td>
            <td>{{com.Description}}</td>
            <td>
                <p>{{com.UpdateByName}}</p>
                <p>{{com.UpdateTime}}</p>
            </td>

            <td v-if="unEdit">
                <el-button v-if="userInfo.EmployeeId==com.UpdateBy" @click="SetRules(com)" style="padding:4px" type="primary" icon="el-icon-edit" circle></el-button>
                <el-button v-if="com.PreferPrice==0 && com.Income==0 &&com.PlatformTax==0 &&com.Refund==0 &&com.Cost==0" @click="Delete(com)" style="padding:4px" type="danger" icon="el-icon-delete" circle></el-button>
                <el-select style="width:100px" size="mini" @change="changeTypeValue(com,typeValue)" v-model="typeValue" :placeholder="$t('rule.skfangshi')">
                    <el-option :label="$t('fnc.shoukuan')" :value="1"></el-option>
                    <el-option :label="$t('fnc.tuikuan')" :value="2"></el-option>
                    <el-option :label="$t('hotel.hotel_cost')" :value="3"></el-option>
                    <el-option :label="$t('objFill.neibujies')" :value="4"></el-option>
                </el-select>
            </td>
        </tr>
      <tr v-if="dataList.length==0">
        <td colspan="12" align="center">{{$t('system.content_noData')}}</td>
      </tr>

    </table>
    <div style="text-align:center">
          <el-pagination
        background
        @current-change="handleCurrentChange"
        v-if="dataList.length>0"
        :current-page.sync="currentPage"
        layout="total,prev, pager, next, jumper"
        :page-size="msg.pageSize"
        :total="total"
        ></el-pagination>
      </div>
        <el-dialog
            :title="$t('objFill.v101.Rest.shangpin')"
            :visible.sync="ruleVisible"
            width="450px">
            <el-form ref="form" :model="form" :rules="rules" label-width="100px">

                <el-form-item :label="$t('system.query_airName')" prop="Name">
                <el-input class='w220' v-model='form.Name'></el-input>
                </el-form-item>
                <el-form-item :label="$t('system.label_info')" prop="Description">
                    <el-input class='w220'
                        type="textarea"
                        :rows="2"
                        :placeholder="$t('fnc.qsrneirong')"
                        v-model="form.Description">
                    </el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button size="small" @click="ruleVisible = false">{{$t('pub.cancelBtn')}}</el-button>
                <el-button size="small" type="danger" @click="RulesOk('form')">{{$t('pub.sureBtn')}}</el-button>
            </span>
        </el-dialog>
        <el-dialog
            :title="$t('objFill.neibujies')"
            :visible.sync="neibuState"
            width="450px">
            <el-form ref="form2" :model="form2" :rules="rules2" label-width="100px">

                <el-form-item :label="$t('visa.v_tuanhao')" prop="TCNUM">
                    <el-input class='w220' v-model='form2.TCNUM'></el-input>
                </el-form-item>

            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button size="small" @click="neibuState = false">{{$t('pub.cancelBtn')}}</el-button>
                <el-button size="small" type="danger" @click="RulesOk2('form2')">{{$t('pub.sureBtn')}}</el-button>
            </span>
        </el-dialog>

  </div>
</template>

<script>
export default {
    name: 'Feedback',
    data (){
        return{
            typeValue:'',
            currentPage:1,
            total:0,
            dataList:[],
            loading:false,
            ruleVisible:false,
            form:{
                Id:0,
                Name:'',
                Description:'',
            },
            form2:{
               TCNUM:'',
            },

            LineTeamList:[],
            EmployeeList:[],
            rules:{
                Name: [
                    { required: true, message: this.$t('system.ph_name'), trigger: 'blur' }
                ],
                Description: [{ required: true, message: this.$t('objFill.v101.activity.qingshurms'), trigger: 'blur' }],
            },
            rules2:{
                TCNUM: [
                    { required: true, message: this.$t('objFill.v101.activity.rul2.t9'), trigger: 'blur' }
                ],
            },
            msg:{
                pageIndex:1,
                pageSize:15,
                Name:'',
            },
            userInfo:{},
            unEdit:true,
            neibuState:false,
            Handmsg:{},
        }
    },
    created(){
        this.userInfo = this.getLocalStorage();
    },
    mounted(){
       this.getList();
       if(this.$route.query.unEdit){
          this.unEdit =false;
       }
       if(this.$route.query.Id){
          this.msg.Id =this.$route.query.Id;
       }
    },
    methods:{
        changeTypeValue(com,val){
            this.Handmsg={};
            this.Handmsg.ReFinanceId=com.Id;
            this.Handmsg.OtherType=9;
            var msg=JSON.stringify(this.Handmsg);
            if(val==1){//收款
                let routeData = this.$router.resolve({
                name: 'ChoiceAddFinancialDocuments',
                query: {Handmsg:msg,Type: 1,searchTitle:'电商'}
                })
                window.open(routeData.href, '_blank')
            }
            else if(val==2){//退款
                let routeData = this.$router.resolve({
                name: 'ChoiceAddFinancialDocuments',
                query: {czmsg:msg,Type: 2,searchTitle:'电商退款'}
                })
                window.open(routeData.href, '_blank')
            }
            else if(val==3){//成本
                let routeData = this.$router.resolve({
                name: 'ChoiceAddFinancialDocuments',
                query: {czmsg:msg,Type: 2,searchTitle:'电商付款'}
                })
                window.open(routeData.href, '_blank')
            }
            else if(val==4){
                this.neibuState=true;
            }
            this.typeValue="";
        },
        RulesOk2(formName){
             this.$refs[formName].validate((valid) => {
                if (valid) {
                    this.apipost(
                        'Financial_post_ValidataTCTravelInfo', this.form2,
                        res => {
                            if (res.data.resultCode == 1) {
                                this.Handmsg.ReTCID=res.data.data;
                                var msg=JSON.stringify(this.Handmsg);
                                let routeData = this.$router.resolve({
                                name: 'ChoiceAddFinancialDocuments',
                                query: {czmsg:msg,Type: 2,searchTitle:'电商内部结算'}
                                })
                                window.open(routeData.href, '_blank')

                            }else{
                                this.Error(res.data.message)
                            }
                        },
                        err => {
                        }
                        )
                } else {


                }
                });

        },
        Gourl(com){
            this.$router.push({
                name: 'ElectricityGoodsDetails',
                query: {
                    ReFinanceId: com.Id,
                    blank: "y"
                }
            });
        },
        Delete(item) {
            this.$confirm(this.$t('objFill.shifouscbkhf'), this.$t('tips.tips'), {
                confirmButtonText: this.$t('pub.sureBtn'),
                cancelButtonText: this.$t('pub.cancelBtn'),
                type: "warning"
            })
            .then(() => {
                this.apipost('sellorder_post_DelECommerceGoodsInfo', {Id:item.Id}, res => {
                if (res.data.resultCode == 1) {
                    this.Success(res.data.message)
                    this.getList()
                }else{
                    this.Error(res.data.message)

                }
                })
            })
            .catch(() => {});
        },
        addRule(){
            this.ruleVisible=true;
             this.form={
                Name:'',
                Description:'',
                Id:0
            }

        },
        SetRules(item){
            this.ruleVisible=true;
            this.form={
                Name:item.Name,
                Description:item.Description,
                Id:item.Id
            }
        },
        RulesOk(formName){
             this.$refs[formName].validate((valid) => {
                if (valid) {
                    this.apipost(
                        'sellorder_post_SetECommerceGoodsInfo', this.form,
                        res => {
                            if (res.data.resultCode == 1) {
                                this.getList();
                                this.ruleVisible=false;
                                this.Success(res.data.message)

                            }else{
                                this.Error(res.data.message)
                            }
                        },
                        err => {
                        }
                        )
                } else {


                }
                });

        },
        handleCurrentChange(val) {
            this.msg.pageIndex = val;
            this.getList();
        },
        getList(){
            this.loading=true;
            this.apipost("sellorder_get_GetECommerceGoodsPageList", this.msg, res => {
                this.loading=false;
                if (res.data.resultCode == 1) {
                    this.dataList = res.data.data.pageData;
                    this.total=res.data.data.count;
                }
            });
        },
    }
}

</script>
<style>
.ElectricityGoods .singeRowTable tr td span{
    cursor: pointer;
}
.Feedback ul>li{
    display: inline-block;
    font-size: 12px;
    color: #666;
    margin: 20px 30px 0px 0;
}
.Feedback .singeRowTable{
    margin-top: 20px;

}
</style>
