<template>
  <el-container>
    <el-main>
        <el-form
            label-width="auto"
            :model="addForm"
            :rules="rules"
            ref="addForm"
            label-position="left"
            > 
            <el-form-item label="送审稿件标题" prop="title">
                <el-input v-model="addForm.title" clearable :disabled="localMode ==='show'"></el-input>
            </el-form-item>
            <el-form-item label="文件内容">
                <sc-upload-file
                    v-model="addForm.pfile"
                    :multiple="false"
                    :limit="1"
                    :disabled="localMode ==='show'"
                    :accept="['.xlsx', '.xls','.pdf','.docx', '.doc', '.jpg', '.png', '.jpeg']"
                    @success = "fileUPSuccess"
                    >
                <el-button type="primary" icon="el-icon-upload" :disabled="localMode ==='show'"> </el-button>
                </sc-upload-file>
            </el-form-item>
            <el-form-item label="所有撰稿人" prop="participants">
                <el-input v-model="addForm.participants" clearable :disabled="localMode ==='show'"></el-input>
            </el-form-item>
            <el-form-item label="部室/研究院" prop="pub_dept">
                <el-input v-model="addForm.pub_dept" clearable :disabled="localMode ==='show'"></el-input>
            </el-form-item>
            <el-form-item label="第一撰稿人涉密等级" prop="level">
                <el-radio-group v-model="addForm.level" :disabled="localMode ==='show'">
                <el-radio label="重要"></el-radio>
                <el-radio label="一般"></el-radio>
                <el-radio label="非涉密"></el-radio>
                </el-radio-group>
            </el-form-item>
            <el-form-item label="稿件内容涉及" prop="content">
                <el-checkbox-group v-model="addForm.content" :disabled="localMode ==='show'">
                <el-checkbox label="武器装备科研生产综合事项"></el-checkbox>
                <el-checkbox label="其他"></el-checkbox>
                </el-checkbox-group>
                <el-input
                    v-if="(addForm.content || []).includes('其他')"
                    v-model="addForm.other_content"
                    placeholder = "请输入名称"
                    size = "small"
                    style="margin-top: 10;"
                    :disabled="localMode ==='show'"
                ></el-input>
            </el-form-item>
            <el-form-item label="宣传报道目的" prop="report_purpose">
                <el-input v-model="addForm.report_purpose" clearable :disabled="localMode ==='show'"></el-input>
            </el-form-item>
            <el-form-item label="宣传渠道" prop="channel">
                <el-checkbox-group v-model="addForm.channel" :disabled="localMode ==='show'">
                <el-checkbox label="互联网"></el-checkbox>
                <el-checkbox label="信息平台"></el-checkbox>
                <el-checkbox label="官微"></el-checkbox>
                <el-checkbox label="公开发行物"></el-checkbox>
                <el-checkbox label="其他"></el-checkbox>
                </el-checkbox-group>
                <el-input
                    v-if="(addForm.channel || '').includes('其他')"
                    v-model="addForm.other_channel"
                    placeholder = "请输入渠道名称"
                    size = "small"
                    style="margin-top: 10;"
                    :disabled="localMode ==='show'"
                ></el-input>
            </el-form-item>
            <el-form-item label="第一撰稿人自审" prop="review">
                <el-radio-group v-model="addForm.review" :disabled="localMode ==='show'">
                <el-radio label="内容不涉及国家秘密和商业秘密，申请公开"></el-radio>
                <el-radio label="内容不涉及国家秘密、但涉及商业秘密，申请受控公开"></el-radio>
                <el-radio label="内容涉及国家秘密，申请按涉密渠道发布"></el-radio>
                </el-radio-group>
            </el-form-item>
            <el-form-item label="所在部室/研究院定密意见" prop="dept_opinion" v-if="['部门领导审批', '总经理审批', '结束'].includes(addForm.ticket_?.state_?.name)">
                <div class="dept-opinion-wrap">
                  <div>
                    <el-radio-group v-model="addForm.dept_opinion" style="display: inline;" :disabled="addForm.ticket_?.state_?.name === '总经理审批'">
                      <el-radio label="不符合定密要求">不符合定密要求</el-radio>
                      <el-radio label="同意内容为涉密事项">同意内容为涉密事项</el-radio>
                    </el-radio-group>
                  </div>

                  <!-- 根据选择显示不同的选项 -->
                  <div v-if="addForm.dept_opinion === '不符合定密要求'" style="margin-top: 8px;">
                    <span>应做</span>
                    <el-radio-group v-model="disposalMethod" style="display: inline; margin-left: 5px;" :disabled="addForm.ticket_?.state_?.name === '总经理审批'">
                      <el-radio label="公开">公开</el-radio>
                      <el-radio label="受控">受控</el-radio>
                    </el-radio-group>
                    <span>处理。</span>
                  </div>

                  <div v-if="addForm.dept_opinion === '同意内容为涉密事项'" style="margin-top: 8px;">
                    <span>涉密等级为：</span>
                    <el-radio-group v-model="addForm.secret_level" style="display: inline; margin-left: 5px;">
                      <el-radio label="机密">机密</el-radio>
                      <el-radio label="秘密">秘密</el-radio>
                    </el-radio-group>
                    <span>，保密期限（解密时间或解密条件）为：</span>
                    <el-input
                      v-model="addForm.secret_period"
                      placeholder="请输入期限"
                      style="width: 200px; margin-left: 5px;"
                      size="small"
                    />
                    <span>，请按总院管理要求做好保密管理。</span>
                  </div>
                </div>
              </el-form-item>
          <el-form-item label="所在部室/研究院审查意见" prop="dept_opinion_review" v-if="['部门领导审批', '总经理审批', '结束'].includes(addForm.ticket_?.state_?.name)">
                <el-radio-group v-model="addForm.dept_opinion_review" :disabled="addForm.ticket_?.state_?.name === '总经理审批'">
                <el-radio label="内容不涉及国家秘密和商业秘密，同意公开"></el-radio>
                <el-radio label="内容不涉及国家秘密、但涉及商业秘密，同意受控公开"></el-radio>
                <el-radio label="内容涉及国家秘密，同意按涉密渠道发布"></el-radio>
                </el-radio-group>
            </el-form-item>
            <el-form-item label="宣传统战部审查意见" prop="publicity_opinion" v-if="['总经理审批', '结束'].includes(addForm.ticket_?.state_?.name)">
              <el-radio-group v-model="addForm.publicity_opinion">
                  <el-radio label="同意公开宣传报道"></el-radio>
                  <el-radio label="同意受控报道"></el-radio>
                  <el-radio label="同意按涉密渠道宣传报道"></el-radio>
                  <el-radio label="不同意任何渠道的宣传报道"></el-radio>
              </el-radio-group>
</el-form-item>
        </el-form>
    <el-footer>
          <ticketd_b
            :workflow_key="'wf_publicity'"
            :title="ticketTitle"
            :t_id="addForm.id"
            :ticket_="addForm.ticket_"
            :ticket_data="ticket_data"
            :submit_b_func="submit_b_func"
            ref="ticketd_b"
            @success="$emit('success', localMode)"
            />    
    </el-footer>
    </el-main>
        <el-aside v-if="addForm.ticket">
            <ticketd
              :ticket_="addForm.ticket_"
              :ticket_data="ticket_data"
              @success="$emit('success')"
              style="margin-top: 20px;"
              />
        </el-aside>
  </el-container>
</template>
<script>
import ticketd_b from "@/views/wf/ticketd_b.vue";
import ticketd from '@/views/wf/ticketd.vue'

export default {
  name: "index",
  props: {
    mode: { 
        type: String, default: "show" 
          }, // add / edit / show
    t_id: {
      type: String, default: null
    },
        },
  components: {
      ticketd, ticketd_b
  },
  data(){
    return {
        ticketTitle: "宣传报道",
        ticket_data: {},
        addForm:{},
        localMode : this.mode,
        rules: {
        file_name: [
          { required: true, message: "请选择档案", trigger: "blur" },
        ],
      },
    }
  },
  mounted() {
    let that = this;
    if (that.t_id) {
      that.getTid();
      }else {
      that.localMode = "add";
      that.addForm.belong_dept = that.$TOOL.data.get("USER_INFO").belong_dept;
    }
    },
  watch: {
        'addForm.dept_opinion'(val) {
          this.ticket_data.dept_opinion = val
        },
        'addForm.secret_period'(val) {
          this.ticket_data.secret_period = val
        },
        'addForm.secret_level'(val) {
          this.ticket_data.secret_level = val
        },
        'addForm.disposal_method'(val) {
          this.ticket_data.disposal_method = val
        },
        'addForm.dept_opinion_review'(val) {
          this.ticket_data.dept_opinion_review = val
        },
        'addForm.publicity_opinion'(val) {
          this.ticket_data.publicity_opinion = val
        },
        deep:true
    },
  computed: {
    disposalMethod: {
      get() {
        return this.addForm.disposal_method || '';
      },
      set(value) {
        this.addForm.disposal_method = value;
      }
    }
  },
  methods: {
    async submit_b_func() {
    let that = this;
    if (that.localMode === "add") {
       let res = await that.$API.ofm.publicity.create.req(that.addForm);
        that.addForm.id = res.id;
    } else if (that.localMode === "edit"){
        await that.$API.ofm.publicity.update.req(
        that.addForm.id,
        that.addForm
        ); 
      }
    },
    getTid (){
			var that = this;
		    if (that.t_id) {
				that.$API.ofm.publicity.item.req(that.t_id).then(res=>{
          that.addForm = res;
					if(res.ticket_.state_.type == 1 && res.create_by == that.$TOOL.data.get("USER_INFO").id ) {
						that.localMode = "edit";
					}else{
						that.localMode = "show";
					}
        })
			}
		},
  },
  
};
</script>


