  <template slot-scope="scope">
  <div>
    <div v-if="!model[theType+'Flag']"  @click="edit">
    <span>{{model[theType]}}{{typeName}}</span> <i class="el-icon-edit cursor-hover"></i>
    </div>
    <div v-else >
        <el-input-number class="w150" controls-position="right" :precision="0" v-model="model.inputValue" :min="0"></el-input-number>
        <div class="pt10">
        <el-button size="mini" type="primary" @click="submit">确 定</el-button>
        <el-button size="mini"  @click="model[theType+'Flag'] = false">取 消</el-button>
        </div>
    </div>
  </div>
</template>

<script>
import { updateStockService, updateIntegralCostService,updateCashCostService } from '@/service/api/mallApi.js';


export default {
    props: {
        model: {
          type: Object,
          default() {
            return {}
          }
        },
        theType: String,
        typeName: String
    },
    watch: {
    },
    methods:{
        async submit() {
          // try {
            console.log(this.theType)
            let res = null;
            if (this.theType === 'virtualStock') { // 库存
              res = await updateStockService({proId:this.model.integralMallProId,stock:this.model.inputValue});
            } else if (this.theType === 'cashCost') {  // 现金费用
              res = await updateCashCostService({proId:this.model.integralMallProId,cost:this.model.inputValue});
            } else if (this.theType === 'integralCost') {   // 积分费用
              res = await updateIntegralCostService({proId:this.model.integralMallProId,cost:this.model.inputValue});
            }
            if (res.errorCode === 0) {
              this.$tips({type:'success',message: '更新成功'});
              this.$emit('refresh');
            } else {
              this.$tips({type:'error',message: '更新失败'});
            }
          // } catch (err) {
          //   this.$tips({type:'error',message: '更新失败'});
          // }
        },
        edit() {
          this.model[this.theType + 'Flag'] = true;
          this.model.inputValue = this.model[this.theType];
        }
    },

}
</script>
