index.jsx 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. import React,{Component} from 'react';
  2. import {Button, Cascader, message, Popconfirm} from "antd";
  3. import DataTable from "@/components/common/DataTable";
  4. import {getGameState, getprovince, getAddressSelect} from '@/utils/tools';
  5. import AddProject from './components/addProject';
  6. import {ProFormSelect} from "@ant-design/pro-form";
  7. import {getAllCname,deleteProject} from './services/API';
  8. import UpadateProject from './components/upadateProject';
  9. class Project extends Component{
  10. constructor(props) {
  11. super(props);
  12. this.state={
  13. columns: [
  14. {
  15. title: "项目名称",
  16. dataIndex: "bname",
  17. key: "bname",
  18. searchBool: true,
  19. },
  20. {
  21. title: "业务品类",
  22. dataIndex: "cname",
  23. key: "cid",
  24. searchBool: true,
  25. renderFormItem:()=>{
  26. return (
  27. <ProFormSelect
  28. label=''
  29. request={this.getAllCname}/>
  30. )
  31. }
  32. },
  33. {
  34. title: "业务地区",
  35. dataIndex: "country",
  36. key: "country",
  37. render: (text,record) => {
  38. let isCountry = "";
  39. if (text === '1') {
  40. isCountry = "全国";
  41. } else {
  42. if(!isNaN(parseInt(record.province))){
  43. isCountry += getprovince(parseInt(record.province));
  44. }
  45. if(!isNaN(parseInt(record.city))){
  46. isCountry += '-'+getprovince(parseInt(record.city));
  47. }
  48. if(!isNaN(parseInt(record.district))){
  49. isCountry += '-'+getprovince(parseInt(record.district));
  50. }
  51. }
  52. return (
  53. isCountry
  54. );
  55. }
  56. },
  57. {
  58. title: "市场价",
  59. dataIndex: "price",
  60. key: "price",
  61. },
  62. {
  63. title: "最低折扣",
  64. dataIndex: "offset",
  65. key: "offset",
  66. },
  67. {
  68. title: "会员价",
  69. dataIndex: "memberPrice",
  70. key: "memberPrice",
  71. },
  72. {
  73. title: "活动价",
  74. dataIndex: "activityPrice",
  75. key: "activityPrice",
  76. },
  77. {
  78. title: "活动生效标识",
  79. dataIndex: "activityFlag",
  80. key: "activityFlag",
  81. searchBool: true,
  82. valueType: 'select',
  83. valueEnum: {
  84. '0': {
  85. text: '有效',
  86. },
  87. '1': {
  88. text: '无效',
  89. },
  90. },
  91. render: (text,record) => {
  92. return getGameState(record.activityFlag);
  93. },
  94. },
  95. {
  96. title: "业务状态",
  97. dataIndex: "status",
  98. key: "status",
  99. searchBool: true,
  100. valueType: 'select',
  101. valueEnum: {
  102. '0': {
  103. text: '正常',
  104. status: 'Success'
  105. },
  106. '1': {
  107. text: '停用',
  108. status: 'Error'
  109. },
  110. },
  111. },
  112. {
  113. title: "项目分类",
  114. dataIndex: "type",
  115. key: "type",
  116. searchBool: true,
  117. valueType: 'select',
  118. valueEnum: {
  119. 0: {
  120. text: '通用',
  121. },
  122. 1: {
  123. text: '专利',
  124. },
  125. 2: {
  126. text: '软著',
  127. },
  128. 3: {
  129. text: '审计',
  130. },
  131. 4: {
  132. text: '双软',
  133. },
  134. 5: {
  135. text: '高新',
  136. },
  137. 6: {
  138. text: '商标',
  139. },
  140. },
  141. render: (text, record) => {
  142. if (record.type === 0) {
  143. return "通用";
  144. } else if (record.type === 1) {
  145. return "专利";
  146. } else if (record.type === 2) {
  147. return "软著";
  148. } else if (record.type === 3) {
  149. return "审计";
  150. }else if(record.type === 4) {
  151. return "双软"
  152. }else if(record.type === 5) {
  153. return "高新"
  154. }else if(record.type === 6) {
  155. return "商标"
  156. }
  157. },
  158. },
  159. {
  160. title: '省-市-区',
  161. key: 'address',
  162. hideInTable: true,
  163. dataIndex: 'address',
  164. searchBool: true,
  165. search: {
  166. transform: (v)=>{
  167. return {
  168. province: v[0] || '',
  169. city: v[1] || '',
  170. district: v[2] || '',
  171. }
  172. }
  173. },
  174. renderFormItem: (item, props) => {
  175. let addressSelect = getAddressSelect()
  176. addressSelect.unshift({
  177. label: '全国',
  178. value: 0,
  179. })
  180. return (
  181. <Cascader
  182. changeOnSelect
  183. options={addressSelect}
  184. placeholder='请选择省-市-区'/>
  185. );
  186. },
  187. },{
  188. title: '操作',
  189. dataIndex: 'id',
  190. key: 'id',
  191. render: (text,record,key,action) => { return (
  192. <Popconfirm
  193. title="是否删除?"
  194. onConfirm={(e)=>{e.stopPropagation();this.deleteProject(text,action)}}
  195. onCancel={(e)=>{e.stopPropagation();}}
  196. okText="确认"
  197. cancelText="取消"
  198. placement="topLeft">
  199. <Button type='primary' danger onClick={(e)=>e.stopPropagation()}>删除</Button>
  200. </Popconfirm>
  201. ) }
  202. }
  203. ],
  204. visible: false,
  205. projectInfor: {},
  206. }
  207. }
  208. deleteById=async (id,action)=>{
  209. message.loading({content:'删除中...',key:'deleteById'})
  210. const msg = await deleteById(id);
  211. if(msg.error.length === 0){
  212. message.success({content:'删除成功',key:'deleteById',duration:2.5});
  213. action.reload();
  214. }else{
  215. message.error({content:msg.error[0].message,key:'deleteById',duration:2.5});
  216. }
  217. }
  218. deleteProject= async (id,action)=>{
  219. message.loading({content:'删除中...',key:'deleteProject'});
  220. const msg = await deleteProject(id);
  221. if(msg.error.length === 0){
  222. message.success({content:'删除成功',key:'deleteProject',duration:2.5});
  223. action.reload();
  224. }else{
  225. message.error({content:msg.error[0].message,key:'deleteProject',duration:2.5})
  226. }
  227. }
  228. getAllCname=async ()=>{
  229. const msg = await getAllCname();
  230. let theArr = [];
  231. if(msg.error.length === 0){
  232. msg.data.forEach((item) => {
  233. theArr.push({
  234. label: item.cname,
  235. value: item.id,
  236. });
  237. });
  238. }else{
  239. message.error(msg.error[0].message)
  240. }
  241. return theArr;
  242. }
  243. render() {
  244. const ref = React.createRef();
  245. return (
  246. <>
  247. <DataTable
  248. ref={ref}
  249. headerTitle='业务项目管理'
  250. url='/api/admin/ProjectSize/listProject'
  251. method='post'
  252. rowKey='id'
  253. scroll={{x:1100}}
  254. columns={this.state.columns}
  255. search={{
  256. filterType: 'query',
  257. labelWidth: 'auto',
  258. defaultCollapsed: false,
  259. }}
  260. onRow={(record) => ({
  261. onClick: (e) => {
  262. e.stopPropagation();
  263. this.setState({
  264. visible: true,
  265. projectInfor: record,
  266. })
  267. }
  268. })}
  269. toolBarRender={[
  270. <AddProject formRef={ref} key='addProject'/>
  271. ]}
  272. />
  273. {this.state.visible && <UpadateProject
  274. formRef={ref}
  275. visible={this.state.visible}
  276. projectInfor={this.state.projectInfor}
  277. onCancel={()=>{
  278. this.setState({
  279. visible: false,
  280. projectInfor: {}
  281. })
  282. }}
  283. />}
  284. </>
  285. )
  286. }
  287. }
  288. export default Project;