table.ts 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. import type {TableColumnsType} from "ant-design-vue";
  2. import dayjs from "dayjs";
  3. import type {GetComponentProps} from "ant-design-vue/lib/vc-table/interface";
  4. import {reactive, ref} from "vue";
  5. const state = reactive({
  6. dragIndex: 0
  7. });
  8. const dragStart = (e) => {
  9. e.stopPropagation();
  10. state.dragIndex = parseInt(e.srcElement.attributes["colstart"].value);
  11. }
  12. const groupList = ['oil_prod_mon', 'oil_prod_year', 'oil', 'gas_prod_mon', 'gas_prod_year', 'gas', 'water_prod_mon', 'water_prod_year', 'water'];
  13. const dragEnter = (e) => {
  14. e.preventDefault();
  15. console.log(e.srcElement.attributes["colstart"].value);
  16. let index = parseInt(e.srcElement.attributes["colstart"].value);
  17. if (state.dragIndex != -1 && state.dragIndex != index) {
  18. let newItems = [...filterColumns.value];
  19. //鼠标开始拖动的列
  20. const dragItem = filterColumns.value[state.dragIndex];
  21. const dragKey = dragItem.key == undefined ? "" : dragItem.key.toString();
  22. //当前要移动的列
  23. const moveItem = filterColumns.value[index];
  24. const moveKey = moveItem.key == undefined ? "" : moveItem.key.toString();
  25. if (state.dragIndex < index) {//右移
  26. let moveList = groupList;
  27. if (!groupList.includes(moveKey)) {
  28. moveList = [moveKey];
  29. } else {
  30. let star = groupList.indexOf(moveKey);
  31. moveList = groupList.slice(star, star + 3);
  32. }
  33. let group = columns.filter(x => moveList.includes(x.key == undefined ? "" : x.key.toString()));
  34. newItems = newItems.filter(x => !moveList.includes(x.key == undefined ? "" : x.key.toString()));
  35. newItems.splice(state.dragIndex, 0, ...group);
  36. //如果起始为块则需要减两列
  37. //如果放下为块则要加两列
  38. if (!groupList.includes(dragKey)&&!groupList.includes(moveKey)){
  39. index = state.dragIndex+ 1;
  40. }
  41. if (groupList.includes(dragKey)) {
  42. index = index - 2;
  43. }
  44. if (groupList.includes(moveKey)) {
  45. index = index + 2;
  46. }
  47. } else {//=左移
  48. let moveList = groupList;
  49. if (!groupList.includes(dragKey)) {
  50. moveList = [dragKey];
  51. } else {
  52. let star = groupList.indexOf(dragKey);
  53. moveList = groupList.slice(star, star + 3);
  54. }
  55. let group = columns.filter(x => moveList.includes(x.key == undefined ? "" : x.key.toString()));
  56. newItems = newItems.filter(x => !moveList.includes(x.key == undefined ? "" : x.key.toString()));
  57. newItems.splice(index, 0, ...group);
  58. filterColumns.value = newItems;
  59. }
  60. filterColumns.value = newItems;
  61. localStorage.setItem("userColumns",JSON.stringify(filterColumns.value));
  62. state.dragIndex = index;
  63. }
  64. };
  65. const onHeaderCell= () => {
  66. return {
  67. draggable: true,
  68. onDragstart: dragStart,
  69. onDragenter: dragEnter
  70. }
  71. }
  72. const oilHeader = () => {
  73. return {
  74. style: {'border-top': '2px solid red'},
  75. }
  76. }
  77. const oilDragHeader:GetComponentProps<any> = () => {
  78. return {...oilHeader(),...onHeaderCell()}
  79. }
  80. const gasHeader = () => {
  81. return {
  82. style: {'border-top': '2px solid #009900'},
  83. }
  84. }
  85. const gasDragHeader:GetComponentProps<any> = () => {
  86. return {...gasHeader(),...onHeaderCell()}
  87. }
  88. const waterHeader = () => {
  89. return {
  90. style: {'border-top': '2px solid #4472C4'},
  91. }
  92. }
  93. const waterDragHeader:GetComponentProps<any> = () => {
  94. return {...waterHeader(),...onHeaderCell()}
  95. }
  96. export const getTdColor = (water_cut) => {
  97. if (water_cut == null || water_cut <= 2) {
  98. return "";
  99. } else if (water_cut > 2 && water_cut <= 40) {
  100. return "color_level2";
  101. } else if (water_cut > 40 && water_cut <= 8) {
  102. return "color_level3";
  103. } else {
  104. return "color_level4";
  105. }
  106. }
  107. export const filterColumns = ref<TableColumnsType>([]);
  108. export const formState = reactive({
  109. page: 1,
  110. rows: 10,
  111. total: 0,
  112. ref_date: new Date(), //重置查询条件使用
  113. well_common_name: '',
  114. well_id: '',
  115. well_type: '',
  116. well_purpose:'',
  117. spud_date_begin: '',
  118. spud_date_end: '',
  119. completion_date_begin: '',
  120. completion_date_end: '',
  121. oil_prod_begin_date_begin: '',
  122. oil_prod_begin_date_end: '',
  123. oil_prod_recent_date_begin: '',
  124. oil_prod_recent_date_end: '',
  125. org_id_a1: '',
  126. project_id: '',
  127. orgList:[],
  128. unitList:[],
  129. });
  130. export const columns: TableColumnsType = [
  131. {
  132. title: '序号',
  133. width: 60,
  134. dataIndex: 'index',
  135. key: 'index',
  136. align: "center", fixed: 'left',
  137. customRender: item => `${formState.rows * (formState.page - 1) + item.index + 1}`
  138. },
  139. {
  140. title: '井名',
  141. dataIndex: 'well_common_name',
  142. key: 'well_common_name',
  143. width: 120,
  144. fixed: 'left'
  145. },
  146. {title: '组织机构', dataIndex: 'org_name_a1', key: 'org_name_a1', width: 150,ellipsis:true, customHeaderCell: onHeaderCell},
  147. {title: '地质单元', dataIndex: 'project_name', key: 'project_name', width: 120,ellipsis:true, customHeaderCell: onHeaderCell},
  148. {title: '井别', dataIndex: 'well_purpose', key: 'well_purpose', width: 100, customHeaderCell: onHeaderCell},
  149. {title: '井型', dataIndex: 'well_type', key: 'well_type', width: 80, customHeaderCell: onHeaderCell},
  150. {
  151. title: '开钻日期',
  152. dataIndex: 'spud_date',
  153. key: 'spud_date',
  154. width: 120,
  155. customHeaderCell: onHeaderCell,
  156. customRender: ({record}) =>
  157. record.spud_date == null ? "" : (dayjs(record.spud_date).format('YYYY-MM-DD'))
  158. },
  159. {
  160. title: '完钻日期',
  161. dataIndex: 'end_drilling_date',
  162. key: 'end_drilling_date',
  163. width: 120,
  164. customHeaderCell: onHeaderCell,
  165. customRender: ({record}) =>
  166. record.end_drilling_date == null ? "" : (dayjs(record.end_drilling_date).format('YYYY-MM-DD'))
  167. },
  168. {
  169. title: '完井日期',
  170. dataIndex: 'completion_date',
  171. key: 'completion_date',
  172. width: 120,
  173. customHeaderCell: onHeaderCell,
  174. customRender: ({record}) =>
  175. record.end_drilling_date == null ? "" : (dayjs(record.completion_date).format('YYYY-MM-DD'))
  176. },
  177. {
  178. title: '投产日期',
  179. dataIndex: 'oil_prod_begin_date',
  180. key: 'oil_prod_begin_date', width: 120, customHeaderCell: onHeaderCell,
  181. customRender: ({record}) =>
  182. record.oil_prod_begin_date == null ? "" : (dayjs(record.oil_prod_begin_date).format('YYYY-MM-DD'))
  183. },
  184. {
  185. title: '最近采油日期',
  186. dataIndex: 'oil_prod_recent_date',
  187. key: 'oil_prod_recent_date', width: 120, customHeaderCell: onHeaderCell,
  188. customRender: ({record}) =>
  189. record.oil_prod_recent_date == null ? "" : (dayjs(record.oil_prod_recent_date).format('YYYY-MM-DD'))
  190. },
  191. {title: '状态', dataIndex: 'well_state', key: 'well_state', width: 120, customHeaderCell: onHeaderCell},
  192. {title: '设计井深(m)', dataIndex: 'budgeted_md', key: 'tempNo', width: 120, customHeaderCell: onHeaderCell},
  193. {
  194. title: '含水率',
  195. dataIndex: 'water_cut',
  196. key: 'water_cut',
  197. width: 60,
  198. align: 'center',
  199. customHeaderCell: onHeaderCell,
  200. customCell: (record) => {
  201. return {class: getTdColor(record.water_cut)};
  202. }
  203. },
  204. {
  205. title: '最近月产油量(t)',
  206. dataIndex: 'oil_prod_mon',
  207. key: 'oil_prod_mon',
  208. width: 120,
  209. customHeaderCell: oilDragHeader
  210. },
  211. {
  212. title: '累产油量(10kt)',
  213. dataIndex: 'oil_prod_year',
  214. key: 'oil_prod_year',
  215. width: 120,
  216. customHeaderCell: oilHeader
  217. },
  218. {title: '累产油量趋势', dataIndex: 'oil', key: 'oil', width: 100, customHeaderCell: oilHeader},
  219. {
  220. title: '最近月产气量(10^4m³)',
  221. dataIndex: 'gas_prod_mon',
  222. key: 'gas_prod_mon',
  223. width: 170,
  224. customHeaderCell: gasDragHeader
  225. },
  226. {
  227. title: '累产气量(10^8m³)',
  228. dataIndex: 'gas_prod_year',
  229. key: 'gas_prod_year',
  230. width: 150,
  231. customHeaderCell: gasHeader
  232. },
  233. {title: '累产气量趋势', dataIndex: 'gas', key: 'gas', width: 100, customHeaderCell: gasHeader},
  234. {
  235. title: '最近注水量(t)',
  236. dataIndex: 'water_prod_mon',
  237. key: 'water_prod_mon',
  238. width: 110,
  239. customHeaderCell:waterDragHeader
  240. },
  241. {
  242. title: '累注水量(10kt)',
  243. dataIndex: 'water_prod_year',
  244. key: 'water_prod_year',
  245. width: 150,
  246. customHeaderCell: waterHeader
  247. },
  248. {title: '累注水量趋势', dataIndex: 'water', key: 'water', width: 100, customHeaderCell: waterHeader},
  249. {title: '操作列', dataIndex: 'operation', key: 'operation', align: 'center', width: 120}
  250. ];