index.jsx 5.03 KB
Newer Older
左玲玲's avatar
左玲玲 committed
1 2 3 4 5 6 7 8 9
import React, { useEffect, useRef, useState } from 'react';
import { Card, Modal, Button, Divider, message } from 'antd';
import { connect, useRequest } from "umi";
import AutoTable from '@/components/AutoTable';
import getPrem from '@/utils/getPrem';//权限判断fn
import InitForm from '@/components/InitForm';
import defaultFields from './fields'
import { doFetch } from '@/utils/doFetch';
import { bmNoType } from '@/services/system';
wuhao's avatar
wuhao committed
10 11

let Rule = (props) => {
左玲玲's avatar
左玲玲 committed
12 13 14 15
  const actionRef = useRef();
  const [vs, cvs] = useState(false),//表单显/隐
    [fields, cf] = useState(defaultFields),
    [iftype, ciftype] = useState({});
wuhao's avatar
wuhao committed
16

左玲玲's avatar
左玲玲 committed
17 18 19 20 21 22 23
  const { run, loading } = useRequest(doFetch, {
    manual: true,
    formatResult: (res) => res,
    onSuccess: (result, params) => {
      if (result.code == "0000") {
        actionRef.current.reload();
        cvs(false);
wuhao's avatar
wuhao committed
24
      }
左玲玲's avatar
左玲玲 committed
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
    }
  })

  const columns = [
    {
      "title": "单号类型",
      "dataIndex": "noTypeName",
      "key": "noTypeId",
      "options": {
        "database": bmNoType,
        "params": {}
      },
      valueType: "select"
    },
    {
      "title": "预览",
      "dataIndex": "ruleNames",
      "key": "ruleNames",
      "search": false
    },
    {
      title: '操作',
      valueType: 'option',
      width: 155,
      render: (text, row, s, action) => extraAction(text, row, s, action)
    },
  ];
wuhao's avatar
wuhao committed
52

左玲玲's avatar
左玲玲 committed
53
  function extraAction(text, record, s, action) {
wuhao's avatar
wuhao committed
54 55
    return [
      getPrem("bmNumberRule_save", action, "修改", () => {
左玲玲's avatar
左玲玲 committed
56
        doFetch({ url: "/ngic-base-business/bmNumberRule/queryByNoTypeId", params: { noTypeId: record.id } }).then(res => {
wuhao's avatar
wuhao committed
57
          let row = res?.data?.data;
左玲玲's avatar
左玲玲 committed
58 59 60 61 62 63 64 65 66 67 68 69 70 71
          ciftype({
            val: "edit",
            id: record.id,
            title: "修改编号规则"
          })
          cf((fields) => {
            for (let i in fields) {
              fields[i].value = row[i];
              fields.noTypeId.options.database = bmNoType;
              fields.noTypeId.disabled = true;
              if (i == "nrList") {
                let reshow = {
                  value: row[i].filter(it => it.noRuleCode != "increasing_order"),
                  other: row[i].filter(it => it.noRuleCode == "increasing_order")[0] || {}
wuhao's avatar
wuhao committed
72
                }
左玲玲's avatar
左玲玲 committed
73 74 75 76
                reshow.other.increaseList = reshow.other.increaseList.map(it => {
                  return reshow.value.filter(item => item.sort == it)[0].id
                })
                reshow.other.sort = reshow.other.sort == 1 ? reshow.other.sort : reshow.other.sort - 1;
wuhao's avatar
wuhao committed
77

左玲玲's avatar
左玲玲 committed
78
                fields[i].value = reshow
wuhao's avatar
wuhao committed
79 80
              }
            }
左玲玲's avatar
左玲玲 committed
81 82 83 84 85
            return { ...fields }
          });
          cvs(true);
        })

wuhao's avatar
wuhao committed
86
      }),
左玲玲's avatar
左玲玲 committed
87
      getPrem('bmNumberRule_deleteByNoTypeId', action, "删除", null, {
wuhao's avatar
wuhao committed
88 89
        title: "确认删除该编号规则?",
        onConfirm: () => {
左玲玲's avatar
左玲玲 committed
90 91 92 93
          run({ url: "/ngic-base-business/bmNumberRule/deleteByNoTypeId", params: { noTypeId: record.id } });
        }
      })
    ]
wuhao's avatar
wuhao committed
94 95 96 97 98 99 100 101 102 103 104 105 106 107
  }

  let saveData = (values, fn) => {
    let newvalues = JSON.parse(JSON.stringify(values));
    let nrList = newvalues.nrList;
    let submitnolist = nrList.value,
      other = nrList.other;

    if (other.sort) {
      submitnolist.splice(other.sort, 0, other);
    } else {
      submitnolist.push(other);
    }

左玲玲's avatar
左玲玲 committed
108

wuhao's avatar
wuhao committed
109 110 111
    submitnolist = submitnolist.map((it, i) => {
      return {
        ...it,
左玲玲's avatar
左玲玲 committed
112 113 114 115
        sort: i + 1
      }
    })

wuhao's avatar
wuhao committed
116 117 118

    submitnolist = submitnolist.map((it, i) => {
      if (it.noRuleCode == "increasing_order") {
左玲玲's avatar
左玲玲 committed
119 120 121
        it.increaseList = it.increaseList.map(item => {
          return submitnolist.filter(itemz => itemz.id == item)[0].sort
        })
wuhao's avatar
wuhao committed
122 123
      }
      return {
左玲玲's avatar
左玲玲 committed
124 125 126 127
        ...it
      }
    })

wuhao's avatar
wuhao committed
128 129 130

    let newfields = {
      ...newvalues,
左玲玲's avatar
左玲玲 committed
131 132 133 134 135 136 137
      nrList: submitnolist
    }

    let difrid = iftype.val == "edit" ? { id: iftype.id } : {};
    run({ url: "/ngic-base-business/bmNumberRule/save", params: { ...newfields, ...difrid } });

  }
wuhao's avatar
wuhao committed
138

左玲玲's avatar
左玲玲 committed
139 140 141 142 143 144 145 146 147 148

  let extra = (<Button disabled={!getPrem("bmNumberRule_save", "ifs")} type="primary" onClick={() => {
    cvs(true);
    cf(fields => {
      for (let i in fields) {
        fields[i].value = null;
        fields[i].disabled = false;

      }
      return { ...fields }
wuhao's avatar
wuhao committed
149
    });
左玲玲's avatar
左玲玲 committed
150 151 152 153 154
    ciftype({
      val: "add",
      title: "新增编号规则"
    })
  }}>新增</Button>)
wuhao's avatar
wuhao committed
155 156 157 158 159 160 161 162

  return (
    <div>
      <AutoTable
        columns={columns}
        actionRef={actionRef}
        pagetitle={props.route.name}
        pageextra={extra}
左玲玲's avatar
左玲玲 committed
163 164
        path="/ngic-base-business/bmNumberRule/queryList"
        pagination="false"
wuhao's avatar
wuhao committed
165 166
      ></AutoTable>

左玲玲's avatar
左玲玲 committed
167 168 169

      <Modal
        maskClosable={false}
wuhao's avatar
wuhao committed
170 171
        title={iftype.title}
        visible={vs}
左玲玲's avatar
左玲玲 committed
172
        onCancel={() => cvs(false)}
wuhao's avatar
wuhao committed
173 174
        footer={false}
        destroyOnClose={true}
左玲玲's avatar
左玲玲 committed
175 176 177 178 179 180 181 182 183 184 185
        width={1200}
      >
        <InitForm
          fields={fields}
          submitData={(values, fn) => {
            saveData(values, fn)
          }}
          onChange={(changedValues, allValues) => {
          }}
          submitting={
            loading || !vs
wuhao's avatar
wuhao committed
186
          }
左玲玲's avatar
左玲玲 committed
187 188 189
        >
        </InitForm>
      </Modal>
wuhao's avatar
wuhao committed
190
    </div>
左玲玲's avatar
左玲玲 committed
191 192
  )
}
wuhao's avatar
wuhao committed
193

左玲玲's avatar
左玲玲 committed
194
export default Rule;