<template>
    <div>
        <div class="top">
            <Row>
                <Col span="1">
                    <Button type="primary" @click="find">搜索</Button>
                </Col>
            </Row>
        </div>
        <div>
            <template>
                <Form :model="formItem" :label-width="80">
                    <Row>
                        <Col span="1">
                            <Button type="primary" @click="type">选择框架</Button>
                        </Col>
                        <Col span="4">
                            <Form :model="formItemType" :label-width="30">
                                <FormItem>
                                    <Select v-model="formItemType.centerType">
                                        <Option value="0">新</Option>
                                        <Option value="1">旧</Option>
                                    </Select>
                                </FormItem>
                            </Form>
                        </Col>
                        <Col span="8">
                            <FormItem v-if="this.formItemType.centerType===''" label="模块编码">
                                <Select v-model="formItem.select">
                                    <Option :value="''"></Option>
                                </Select>
                            </FormItem>
                            <FormItem v-if="this.formItemType.centerType==='1'" label="模块编码">
                                <Select v-model="formItem.select">
                                    <Option v-for="(item,index) in menuList" :key="index" :value="index">
                                        {{item.label}}
                                    </Option>
                                </Select>
                            </FormItem>
                            <FormItem v-if="this.formItemType.centerType==='0'" label="模块编码">
                                <Select v-model="formItem.select">
                                    <Option v-for="(item,index) in menuList" :key="index" :value="index">
                                        {{item.center_code}}({{item.center_key}})
                                    </Option>
                                </Select>
                            </FormItem>
                        </Col>
                    </Row>
                </Form>
            </template>
        </div>
        <Divider/>
        <div>
            <Table border :columns="columns" :data="dataList" v-if="show" :loading="loading">
                <template slot-scope="{ row}" slot="action">
                    <Button type="primary" size="small" style="margin-right: 5px" @click="synchronization(row)">同步
                    </Button>
                </template>
            </Table>
        </div>
    </div>

</template>
<script>

import { getDictInfoList, getCenterList, sysisSync, updateSysFun } from '../../../api/system/sys-sync-list'

export default {
  name: 'WlSyncListOld',
  data () {
    return {
      columns: [
        {
          title: '接口标识',
          key: 'id'
        },
        {
          title: '接口名称',
          key: 'funName'
        },
        {
          title: '状态',
          key: 'statusCodeCN'
        },
        {
          title: '描述',
          key: 'desc'
        },
        {
          title: '操作',
          slot: 'action',
          width: 150,
          align: 'center'
        }
      ],
      formItem: {
        select: ''
      },
      formItemType: {
        centerType: ''
      },
      menuList: [],
      show: false,
      loading: false
    }
  },
  methods: {
    synchronization (row) {
      let list = []
      list.push(row)
      console.log(list)
      let data = {
        list: list
      }
      updateSysFun(data).then(ret => {
        if (ret.data.errcode === 0) {
          this.$Message.success(ret.data.errmsg)
          this.find()
        } else {
          this.$Message.error(ret.data.errmsg)
        }
      })
    },
    type () {
      if (this.formItemType.centerType === '') {
        this.$Message.info('请选择框架！')
      } else if (this.formItemType.centerType === '0') {
        getCenterList().then(ret => {
          if (ret.data.errcode === 0) {
            this.menuList = ret.data.data
          } else {
            this.$Message.error(ret.data.errmsg)
          }
        })
      } else if (this.formItemType.centerType === '1') {
        getDictInfoList().then(ret => {
          if (ret.data.errcode === 0) {
            this.menuList = ret.data.data
          } else {
            this.$Message.error(ret.data.errmsg)
          }
        })
      }
    },
    find () {
      if (this.formItemType.centerType === '') {
        this.$Message.info('请选择框架！')
      } else if (this.formItemType.centerType === '0') {
        this.new()
      } else if (this.formItemType.centerType === '1') {
        this.old()
      }
    },
    new () {
      this.loading = true
      if (this.formItem.select === '') {
        this.$Message.info('请选择模块！')
      } else {
        let data = {
          structureType: this.formItemType.centerType,
          center_code: this.menuList[this.formItem.select].center_code,
          center_key: this.menuList[this.formItem.select].center_key
        }
        sysisSync(data).then(ret => {
          if (ret.data.errcode === 0) {
            this.dataList = ret.data.data
            this.show = true
            this.loading = false
          } else {
            this.$Message.error(ret.data.errmsg)
          }
        })
      }
    },
    old () {
      this.loading = true
      if (this.formItem.select === '') {
        this.$Message.info('请选择模块！')
      } else {
        let data = {
          structureType: this.formItemType.centerType,
          center_code: this.menuList[this.formItem.select].center_code,
          center_key: this.menuList[this.formItem.select].value
        }
        sysisSync(data).then(ret => {
          if (ret.data.errcode === 0) {
            this.dataList = ret.data.data
            this.show = true
            this.loading = false
          } else {
            this.$Message.error(ret.data.errmsg)
          }
        })
      }
    }

  },
  mounted () {
  }

}
</script>
<style>
    .top {
        margin-bottom: 20px;
    }
</style>
