<template>
  <div class="apploval">
    <div class="ls-row">
      <div class="row-header title">
        <span class="icon iconfont icon-shenpi1"></span>
        <span>审批操作</span>
      </div>
    </div>

    <div class="radio-wrap">
      <van-radio-group v-model="result"
                       @change="setResult">
        <van-radio icon-size="25px"
                   name="通过">同意</van-radio>
        <van-radio icon-size="25px"
                   name="驳回">驳回</van-radio>
      </van-radio-group>
    </div>
    <div class="text-content">
      <van-field v-model="msg"
                 rows="5"
                 autosize
                 class="textarea"
                 type="textarea"
                 maxlength="300"
                 placeholder="请输入备注说明"
                 show-word-limit />
    </div>
  </div>
</template>

<script>
  import commonSelect from '@/common/commonSelectList.js'
  export default {
    name: 'c-apploval',
    created () {
      let $this = this
      parent.window.doSubmit = function (param) {
        if (!$this.isProccess) {
            $this.approve(param)
          return false
        } else {
          return true
        }
      }

      this.sid = this.$common.getUrlParams('sid')
    },
    methods: {

      valid (param) {
        var th = this
        if (param.actionName == null || param.actionName == '') {
          this.$toast({ type: 'fail', message: '请选择处理动作' })
          return false
        }
        if (param.actionName != null && param.actionName === '驳回' && !this.msg) {
          this.$toast({ type: 'fail', message: '请填写处理意见' })
          return false
        }
        return true
      },
      approve(param){
        if (!this.valid(param)) {
          return
        }
        param = Object.assign(param,this.processForm);

        this.$axios.post({
          domain: 'crmCmUrl',
          url: 'cmProcess.approve',
          data: param,
          requestType: 'body',
          isShow: true,
          success: function (res) {
            if (res.errorCode === 200) {
              this.isProccess = true
              parent.FormToolBarAction.BTN_TRANSACT()
            } else {
              this.$toast({ type: 'fail', message: res.msg })
            }
          }.bind(this),
          error: function (res) {
            this.$toast({ type: 'fail', message: res.msg })
          }.bind(this)
        })
      },
      setParentValue (id, value) {
        try {
          if (parent) {
            parent.$('#' + id).val(value)
          }
        } catch (err) { }
      },
      setResult (val) {
        parent.setComment(val)
        // this.setParentValue('commentOption', val)
      }
    },
    watch: {
      msg: {
        handler: function (val, oldval) {
          if (val) {
            this.setParentValue('msg', val)
          }
        }
      }
    },
    props: {
      taskRefId: {
        type: String,
        default: '',
        required: false
      },
      moduleId: {
        type: String,
        default: '',
        required: true
      },
      processId: {
        type: String,
        default: '',
        required: false
      }
    },
    data () {
      return {
        isProccess: false,
        sid: '',
        msg: '',
        result: '',
        processForm: {
          moduleId: this.moduleId // 所属模块
        }
      }
    }
  }
</script>

<style type="text/css" scoped lang="scss">
  .apploval {
    background-color: #fff;
    border-top: 20px solid #F9F9F9;
    border-bottom: 20px solid #F9F9F9;
    padding-bottom: 35px;

  .radio-wrap {
    padding: 25px 20px 10px;

  .van-radio-group {
    display: flex;
  }
  .van-radio {
    overflow: visible;
    margin-right: 25px;
  }
  }

  .textarea {
    border: none;
  }
  .row-wrap {
    position: relative;
  .van-button {
    position: absolute;
    right: 10px;
    top: 25px;
    z-index: 999;
    font-size: 14px;
  }
  }
  }
</style>
