<template>
	<view class="mission-action-page">
		<!-- 指派改善任务 -->
		<component
		  :is="currentComponet"
      :disabled="disabled"
      :values="values"
      :btnInfo="btnInfo"
      :missionDetails="missionDetails"
      @comRequest="comTaskCirculation"
		/>
	</view>
</template>

<script>
  import { mapState } from "vuex";
	import assignMission from './components/assign-mission.vue';
	import disagree from './components/disagree.vue'
	import personnel from './components/personnel.vue'
	import writeBack from './components/write-back.vue'
  import pdca from './components/pdca.vue'

	export default {
    computed: {
      ...mapState({
        missionDetails: state => state.mission.missionDetails
      })
    },
		data() {
			return {
				// 当前显示的组件
        currentComponet: 'assign-mission',
        // 查看详情回显的数据
        values: {},
        // 按钮信息
        btnInfo: {},
				compoentList: [
					{type: 1, name: '指派改善任务', component: 'assign-mission'},
					{type: 2, name: '原因', component: 'disagree'},
					{type: 3, name: '人员架构', component: 'personnel'},
					{type: 4, name: '改善回复', component: 'write-back'},
					{type: 5, name: 'PDCA', component: 'pdca'},
        ],
        // pdca类型
        pdcaSetting: 'p'
			}
    },
    onLoad({ details }){
      this.getComponentInfo(details ? JSON.parse(details) : {});
    },
		methods: {
      // 获取组件信息
      getComponentInfo(details) {
        console.log(7, details)
        const {
          nextPermission,
          nextPermissionName,
          componentName,
          disabled,
          hasAnyData,
          isOutvalueKey,
          key,
          labelKey,
          dataKey,
          pdcaSetting
        } = details;
        this.currentComponet = componentName;
        this.disabled = disabled;
        if(disabled) { // 查看xx详情
        let values = {};
          if(hasAnyData){ // 回显数据由多个key组成
            dataKey.map(item => {
              values[item.labelKey] = (item.isOutvalueKey ? this.missionDetails : details)[item.key];
            });
          }else {
            values[labelKey] = (isOutvalueKey ? this.missionDetails : details)[key]
          }
          this.values = values;
          this.pdcaSetting = pdcaSetting;
        }else { // 编辑流程
          this.btnInfo = details;
        }
      },
      // 公共改善任务接口
      comTaskCirculation(data) {
        this.$store.dispatch({
					type: 'mission/commActions',
					payload: {
						key: "comTaskCirculation",
						data
					}
				}).then(data1 => {
          if(!data1){
            let taskId = uni.getStorageSync('taskId');
            uni.redirectTo({
              url: `/pages/mission-details/mission-details?taskId=${taskId}`
            });
          }
				});
      }
		},
		components: {
			assignMission,
			disagree,
			personnel,
			writeBack,
			pdca
		}
	}
</script>

<style lang="less">
	.mission-action-page {
		height: 100%;
	}
</style>
