index.jsx 12.8 KB
Newer Older
TZW's avatar
TZW committed
1 2 3 4
/* 设备供应商
 * @Author: Li Hanlin
 * @Date: 2022-11-09 14:44:44
 * @Last Modified by: Li Hanlin
TZW's avatar
TZW committed
5
 * @Last Modified time: 2023-01-18 15:25:43
TZW's avatar
TZW committed
6 7
 */

wuhao's avatar
wuhao committed
8
import * as React from 'react';
TZW's avatar
TZW committed
9
import { useState, useMemo, useEffect, useRef } from 'react';
wuhao's avatar
wuhao committed
10 11 12 13
import DrawerPro from '@/components/DrawerPro';
import AutoTable from '@/components/AutoTable';
import PremButton from '@/components/PremButton';
import getcolumns from './columns';
TZW's avatar
TZW committed
14 15
import InitForm from '@/components/InitForm';
import ExtendField from '@/components/ExtendField';
TZW's avatar
TZW committed
16
import { doFetch } from '@/utils/doFetch';
TZW's avatar
TZW committed
17 18
import { Image, message, Divider } from 'antd';
import { ProDescriptions } from '@ant-design/pro-components';
wuhao's avatar
wuhao committed
19 20 21 22

function Supplier(props) {
  const actionRef = useRef(),
    formRef = useRef();
TZW's avatar
TZW committed
23
  const [drawer, setDrawer] = useState({
wuhao's avatar
wuhao committed
24 25 26
    visible: false,
  });

TZW's avatar
TZW committed
27 28 29 30 31 32 33 34
  const urlParams = {
    save: '/asset/equipmentSupplier/save',
    remove: '/asset/equipmentSupplier/deleteById',
    list: '/asset/equipmentSupplier/queryList',
    detail: '/asset/equipmentSupplier/query/detail',
    detail_nocp: '/asset/equipmentSupplier/queryById',
  };

wuhao's avatar
wuhao committed
35 36 37 38 39 40
  const edit = (text, row, _, action) => {
    return (
      <PremButton
        btn={{
          size: 'small',
          onClick: () => {
TZW's avatar
TZW committed
41
            setDrawer((s) => ({
wuhao's avatar
wuhao committed
42 43
              ...s,
              visible: true,
TZW's avatar
TZW committed
44 45
              // detailpath: urlParams.detail,
              // params: { id: row?.id },
wuhao's avatar
wuhao committed
46
              title: '编辑',
TZW's avatar
TZW committed
47
              val: 'only',
TZW's avatar
TZW committed
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
              type: 'edit',
              item: row,
              // onFinish: async (vals) => {
              //   let equipmentSupplierCharReqList = [];
              //   //console.log('id:', row.id);
              //   for (let i in vals) {
              //     if (!isNaN(Number(i))) {
              //       equipmentSupplierCharReqList.push({
              //         fieldId: i,
              //         fieldRealValue: vals[i],
              //       });
              //       delete vals[i];
              //     }
              //   }
              //   let params = {
              //     ...vals,
              //     id: row?.id,
              //     shopIdList: vals.shopId,
              //     equipmentSupplierCharReqList,
              //   };
              //   delete params.shopId;
              //   let res = await doFetch({
              //     url: urlParams.save,
              //     params,
              //   });
              //   if (res.code === '0000') {
              //     message.success('编辑成功!');
              //     setDrawer((s) => ({
              //       ...s,
              //       visible: false,
              //     }));
              //     actionRef.current.reload();
              //   }
              // },
wuhao's avatar
wuhao committed
82 83 84 85 86 87 88 89 90 91 92 93 94
            }));
          },
        }}
      >
        编辑
      </PremButton>
    );
  };

  const remove = (text, row, _, action) => {
    return (
      <PremButton
        pop={{
TZW's avatar
TZW committed
95
          title: '是否删除该供应商?',
wuhao's avatar
wuhao committed
96 97
          okText: '确认',
          cancelText: '取消',
TZW's avatar
TZW committed
98 99 100 101 102 103 104 105 106 107
          onConfirm: async () => {
            let res = await doFetch({ url: urlParams.remove, params: { id: row.id } });
            if (res.code === '0000') {
              message.success('删除成功!');
              setDrawer((s) => ({
                ...s,
                visible: false,
              }));
              actionRef.current.reload();
            }
wuhao's avatar
wuhao committed
108 109 110 111 112 113 114 115 116 117 118
          },
        }}
        btn={{
          size: 'small',
          type: 'danger',
        }}
      >
        删除
      </PremButton>
    );
  };
TZW's avatar
TZW committed
119

TZW's avatar
TZW committed
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
  const Details = () => {
    const columns = [
      {
        title: '供应商编号',
        dataIndex: 'supplierNo',
        key: 'supplierNo',
      },
      {
        title: '供应商名称',
        dataIndex: 'supplierName',
        key: 'supplierName',
      },
      { title: '公司官网', dataIndex: 'officialWebsite', key: 'officialWebsite' },
      {
        title: '联系电话',
        dataIndex: 'telephone',
        key: 'telephone',
      },
      {
        title: '公司邮箱',
        dataIndex: 'email',
        key: 'email',
      },
      {
        title: '地址',
        dataIndex: 'address',
        key: 'address',
      },
      {
        title: '状态',
TZW's avatar
TZW committed
150
        dataIndex: 'statusName',
TZW's avatar
TZW committed
151 152 153 154 155 156 157 158 159 160 161 162 163
        key: 'status',
      },
      {
        title: '评分',
        dataIndex: 'score',
        key: 'score',
      },
      {
        title: '备注',
        dataIndex: 'remark',
        key: 'remark',
      },
    ];
wuhao's avatar
wuhao committed
164

TZW's avatar
TZW committed
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
    const [newfieldscolumns, setnewfieldscolumns] = useState([]);
    const selectValueType = (type, options) => {
      switch (type) {
        case 1:
          return {
            valueType: 'input',
          };
        case 2:
          return {
            valueType: 'select',
            options,
          };
        case 3:
          return {
            valueType: 'radio',
            options,
          };
        case 4:
          return {
            valueType: 'select',
            options,
          };
        default:
          break;
      }
    };
    const [request, setrequest] = useState();
    useEffect(() => {
      const fn = async () => {
          let res = await doFetch({
            url: '/base/paFormField/queryList',
            params: {
              formId: '3',
            },
          });
          if (res?.data?.dataList) {
            let column = [];
wuhao's avatar
wuhao committed
202
            res?.data?.dataList?.forEach?.((el) => {
TZW's avatar
TZW committed
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
              column.push({
                ...selectValueType(el.fieldChar, el.valueList),
                title: el.fieldName,
                dataIndex: el.id,
                key: el.id,
              });
            });
            setnewfieldscolumns(column);
          }
        },
        fn2 = async () => {
          const res = await doFetch({
            url: urlParams.detail,
            params: { id: drawer?.item?.id },
          });
          let obj = {};
wuhao's avatar
wuhao committed
219
          res?.data?.data['equipmentSupplierCharList']?.forEach?.((it) => {
TZW's avatar
TZW committed
220
            obj[it?.fieldId] = it?.fieldRealValue;
TZW's avatar
TZW committed
221
          });
TZW's avatar
TZW committed
222

TZW's avatar
TZW committed
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
          setrequest(
            {
              ...(res?.data?.data ?? {}),
              ...obj,
            } ?? {},
          );
        };
      fn();
      fn2();
    }, []);
    return (
      <>
        <ProDescriptions dataSource={request} columns={columns} />
        <AutoTable
          pagetitle="联系信息"
          columns={[
            {
              title: '联系人',
              dataIndex: 'userName',
              key: 'userName',
TZW's avatar
TZW committed
243
              search: false,
TZW's avatar
TZW committed
244 245 246 247 248 249 250 251 252 253 254
              formItemProps: {
                rules: [
                  {
                    required: true,
                    message: '此项为必填项',
                  },
                ],
              },
            },
            {
              title: '手机号码',
TZW's avatar
TZW committed
255
              search: false,
TZW's avatar
TZW committed
256 257 258 259 260
              dataIndex: 'telephone',
              key: 'telephone',
            },
            {
              title: '邮箱',
TZW's avatar
TZW committed
261
              search: false,
TZW's avatar
TZW committed
262 263 264 265 266
              dataIndex: 'email',
              key: 'email',
            },
            {
              title: '职务',
TZW's avatar
TZW committed
267
              search: false,
TZW's avatar
TZW committed
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
              dataIndex: 'title',
              key: 'title',
              fieldProps: {
                placeholder: '请选择',
              },
              formItemProps: {
                rules: [
                  {
                    required: false,
                    message: '此项为必填项',
                  },
                ],
              },
            },
          ]}
          dataSource={request?.supplierUserList}
          resizeable={false}
          pagination={false}
        />
        <Divider />
        <h3 className="page-title" style={{ marginBottom: 16 }}>
          扩展字段
        </h3>
        <ProDescriptions dataSource={request} columns={newfieldscolumns} />
      </>
    );
  };
wuhao's avatar
wuhao committed
295
  const columns = useMemo(() => {
TZW's avatar
TZW committed
296
    let defcolumn = getcolumns(setDrawer);
TZW's avatar
TZW committed
297 298 299 300 301 302 303
    defcolumn[1].render = (text, row) => {
      return (
        <a
          onClick={() => {
            setDrawer((s) => ({
              ...s,
              visible: true,
TZW's avatar
TZW committed
304 305 306 307
              type: 'detail',
              item: row,
              val: 'only',
              title: row.supplierName + '的详细信息',
TZW's avatar
TZW committed
308 309 310 311 312 313 314
            }));
          }}
        >
          {row.supplierName}
        </a>
      );
    };
wuhao's avatar
wuhao committed
315 316 317 318
    return defcolumn.concat({
      title: '操作',
      valueType: 'option',
      width: 150,
TZW's avatar
TZW committed
319
      render: (text, row, _, action) => [edit(text, row, _, action), remove(text, row, _, action)],
wuhao's avatar
wuhao committed
320 321 322
    });
  }, []);

TZW's avatar
TZW committed
323 324 325 326 327 328 329
  const selectMoreDrawerType = (type) => {
    switch (type) {
      case 'detail':
        return <Details />;
      case 'add':
        return (
          <ExtendField
TZW's avatar
TZW committed
330 331 332 333 334 335 336 337 338 339 340 341 342
            defaultFormValue={drawer?.item}
            setDrawer={setDrawer}
            drawer={drawer}
            actionRef={actionRef}
            columns={columns}
            formId={'3'}
            // urlParams={urlParams}
            onFinish={async (vals) => {
              let equipmentSupplierCharReqList = [];
              for (let i in vals) {
                if (!isNaN(Number(i))) {
                  equipmentSupplierCharReqList.push({
                    fieldId: i,
TZW's avatar
TZW committed
343
                    fieldRealValue: vals[i],
TZW's avatar
TZW committed
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375
                  });
                  delete vals[i];
                }
              }
              let params = {
                ...vals,
                id: drawer?.title == '编辑' ? drawer?.item?.id : '',
                equipmentSupplierCharReqList,
              };
              delete params.shopId;
              let res = await doFetch({
                url: urlParams.save,
                params,
              });
              if (res.code === '0000') {
                if (drawer?.title == '编辑') {
                  message.success('编辑成功!');
                } else {
                  message.success('新增成功!');
                }
                setDrawer((s) => ({
                  ...s,
                  visible: false,
                }));
                actionRef.current.reload();
              }
            }}
          />
        );
      case 'edit':
        return (
          <ExtendField
TZW's avatar
TZW committed
376 377 378
            setDrawer={setDrawer}
            drawer={drawer}
            actionRef={actionRef}
TZW's avatar
TZW committed
379
            columns={drawer?.item?.statusChangeable == 1 ? getcolumns(false) : getcolumns(true)}
TZW's avatar
TZW committed
380 381 382 383 384 385 386 387
            formId={'3'}
            urlParams={urlParams}
            onFinish={async (vals) => {
              let equipmentSupplierCharReqList = [];
              for (let i in vals) {
                if (!isNaN(Number(i))) {
                  equipmentSupplierCharReqList.push({
                    fieldId: i,
TZW's avatar
TZW committed
388
                    fieldRealValue: vals[i],
TZW's avatar
TZW committed
389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421
                  });
                  delete vals[i];
                }
              }
              let params = {
                ...vals,
                id: drawer?.title == '编辑' ? drawer?.item?.id : '',
                equipmentSupplierCharReqList,
              };
              delete params.shopId;
              let res = await doFetch({
                url: urlParams.save,
                params,
              });
              if (res.code === '0000') {
                if (drawer?.title == '编辑') {
                  message.success('编辑成功!');
                } else {
                  message.success('新增成功!');
                }
                setDrawer((s) => ({
                  ...s,
                  visible: false,
                }));
                actionRef.current.reload();
              }
            }}
          />
        );
      default:
        return null;
    }
  };
wuhao's avatar
wuhao committed
422 423 424
  return (
    <div style={{ position: 'relative' }}>
      <AutoTable
TZW's avatar
TZW committed
425
        pagetitle={<h3 className="page-title">设备供应商</h3>}
wuhao's avatar
wuhao committed
426
        columns={columns}
TZW's avatar
TZW committed
427
        path={urlParams.list}
wuhao's avatar
wuhao committed
428 429
        actionRef={actionRef}
        pageextra={'add'}
TZW's avatar
TZW committed
430
        resizeable={false}
wuhao's avatar
wuhao committed
431 432 433 434
        addconfig={{
          // access: 'sysDepartment_save',
          btn: {
            disabled: false,
TZW's avatar
TZW committed
435
            type: 'primary',
wuhao's avatar
wuhao committed
436
            onClick: () => {
TZW's avatar
TZW committed
437
              setDrawer((s) => ({
wuhao's avatar
wuhao committed
438 439
                ...s,
                visible: true,
TZW's avatar
TZW committed
440 441
                item: {
                  status: 1,
TZW's avatar
TZW committed
442
                  score: 0,
TZW's avatar
TZW committed
443
                },
wuhao's avatar
wuhao committed
444
                title: '新增',
TZW's avatar
TZW committed
445
                detailpath: null,
TZW's avatar
TZW committed
446 447
                type: 'add',
                val: 'only',
wuhao's avatar
wuhao committed
448 449 450 451 452 453 454 455
              }));
            },
          },
        }}
      />

      <DrawerPro
        fields={columns}
TZW's avatar
TZW committed
456
        defaultFormValue={drawer?.item ?? {}}
wuhao's avatar
wuhao committed
457 458 459
        formRef={formRef}
        placement="right"
        onClose={() => {
TZW's avatar
TZW committed
460
          setDrawer((s) => ({
wuhao's avatar
wuhao committed
461 462 463
            ...s,
            visible: false,
          }));
TZW's avatar
TZW committed
464
          actionRef.current.reload();
wuhao's avatar
wuhao committed
465 466
        }}
        {...drawer}
TZW's avatar
TZW committed
467 468 469
      >
        {selectMoreDrawerType(drawer?.type)}
      </DrawerPro>
wuhao's avatar
wuhao committed
470 471 472 473
    </div>
  );
}

TZW's avatar
TZW committed
474
export default Supplier;