table.ts 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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. state.dragIndex = index;
  62. }
  63. };
  64. const onHeaderCell= () => {
  65. return {
  66. draggable: true,
  67. onDragstart: dragStart,
  68. onDragenter: dragEnter
  69. }
  70. }
  71. const oilHeader = () => {
  72. return {
  73. style: {'border-top': '2px solid red'},
  74. }
  75. }
  76. const oilDragHeader:GetComponentProps<any> = () => {
  77. return {...oilHeader(),...onHeaderCell()}
  78. }
  79. const gasHeader = () => {
  80. return {
  81. style: {'border-top': '2px solid #009900'},
  82. }
  83. }
  84. const gasDragHeader:GetComponentProps<any> = () => {
  85. return {...gasHeader(),...onHeaderCell()}
  86. }
  87. const waterHeader = () => {
  88. return {
  89. style: {'border-top': '2px solid #4472C4'},
  90. }
  91. }
  92. const waterDragHeader:GetComponentProps<any> = () => {
  93. return {...waterHeader(),...onHeaderCell()}
  94. }
  95. export const getTdColor = (water_cut) => {
  96. if (water_cut == null || water_cut <= 2) {
  97. return "";
  98. } else if (water_cut > 2 && water_cut <= 40) {
  99. return "color_level2";
  100. } else if (water_cut > 40 && water_cut <= 8) {
  101. return "color_level3";
  102. } else {
  103. return "color_level4";
  104. }
  105. }
  106. export const filterColumns = ref<TableColumnsType>([]);
  107. export const formState = reactive({
  108. page: 1,
  109. rows: 10,
  110. total: 0,
  111. ref_date: new Date(), //重置查询条件使用
  112. well_common_name: '',
  113. well_id: '',
  114. well_type: '',
  115. spud_date_begin: '',
  116. spud_date_end: '',
  117. completion_date_begin: '',
  118. completion_date_end: '',
  119. oil_prod_begin_date_begin: '',
  120. oil_prod_begin_date_end: '',
  121. oil_prod_recent_date_begin: '',
  122. oil_prod_recent_date_end: '',
  123. org_id_a1: '',
  124. project_id: ''
  125. });
  126. export const columns: TableColumnsType = [
  127. {
  128. title: '序号',
  129. width: 60,
  130. dataIndex: 'index',
  131. key: 'index',
  132. align: "center", fixed: 'left',
  133. customRender: item => `${formState.rows * (formState.page - 1) + item.index + 1}`
  134. },
  135. {
  136. title: '井名',
  137. dataIndex: 'well_common_name',
  138. key: 'well_common_name',
  139. width: 120,
  140. fixed: 'left'
  141. },
  142. {title: '采油厂机构', dataIndex: 'org_name_a1', key: 'org_name_a1', width: 120, customHeaderCell: onHeaderCell},
  143. {title: '地质单元', dataIndex: 'project_name', key: 'project_name', width: 120, customHeaderCell: onHeaderCell},
  144. {title: '井型', dataIndex: 'well_type', key: 'well_type', width: 120, customHeaderCell: onHeaderCell},
  145. {
  146. title: '开钻日期',
  147. dataIndex: 'spud_date',
  148. key: 'spud_date',
  149. width: 120,
  150. customHeaderCell: onHeaderCell,
  151. customRender: ({record}) =>
  152. record.spud_date == null ? "" : (dayjs(record.spud_date).format('YYYY-MM-DD'))
  153. },
  154. {
  155. title: '完钻日期',
  156. dataIndex: 'end_drilling_date',
  157. key: 'end_drilling_date',
  158. width: 120,
  159. customHeaderCell: onHeaderCell,
  160. customRender: ({record}) =>
  161. record.end_drilling_date == null ? "" : (dayjs(record.end_drilling_date).format('YYYY-MM-DD'))
  162. },
  163. {
  164. title: '完井日期',
  165. dataIndex: 'completion_date',
  166. key: 'completion_date',
  167. width: 120,
  168. customHeaderCell: onHeaderCell,
  169. customRender: ({record}) =>
  170. record.end_drilling_date == null ? "" : (dayjs(record.completion_date).format('YYYY-MM-DD'))
  171. },
  172. {
  173. title: '开始采油日期',
  174. dataIndex: 'oil_prod_begin_date',
  175. key: 'oil_prod_begin_date', width: 120, customHeaderCell: onHeaderCell,
  176. customRender: ({record}) =>
  177. record.oil_prod_begin_date == null ? "" : (dayjs(record.oil_prod_begin_date).format('YYYY-MM-DD'))
  178. },
  179. {
  180. title: '最近采油日期',
  181. dataIndex: 'oil_prod_recent_date',
  182. key: 'oil_prod_recent_date', width: 120, customHeaderCell: onHeaderCell,
  183. customRender: ({record}) =>
  184. record.oil_prod_recent_date == null ? "" : (dayjs(record.oil_prod_recent_date).format('YYYY-MM-DD'))
  185. },
  186. {title: '状态', dataIndex: 'current_state_name', key: 'current_state', width: 120, customHeaderCell: onHeaderCell},
  187. {title: '设计井深(m)', dataIndex: 'budgeted_md', key: 'tempNo', width: 120, customHeaderCell: onHeaderCell},
  188. {
  189. title: '含水率',
  190. dataIndex: 'water_cut',
  191. key: 'water_cut',
  192. width: 60,
  193. align: 'center',
  194. customHeaderCell: onHeaderCell,
  195. customCell: (record) => {
  196. return {class: getTdColor(record.water_cut)};
  197. }
  198. },
  199. {
  200. title: '最近月产油量(t)',
  201. dataIndex: 'oil_prod_mon',
  202. key: 'oil_prod_mon',
  203. width: 120,
  204. customHeaderCell: oilDragHeader
  205. },
  206. {
  207. title: '累产油量(10kt)',
  208. dataIndex: 'oil_prod_year',
  209. key: 'oil_prod_year',
  210. width: 120,
  211. customHeaderCell: oilHeader
  212. },
  213. {title: '累产油量趋势', dataIndex: 'oil', key: 'oil', width: 100, customHeaderCell: oilHeader},
  214. {
  215. title: '最近月产气量(10^4m³)',
  216. dataIndex: 'gas_prod_mon',
  217. key: 'gas_prod_mon',
  218. width: 170,
  219. customHeaderCell: gasDragHeader
  220. },
  221. {
  222. title: '累产气量(10^8m³)',
  223. dataIndex: 'gas_prod_year',
  224. key: 'gas_prod_year',
  225. width: 150,
  226. customHeaderCell: gasHeader
  227. },
  228. {title: '累产气量趋势', dataIndex: 'gas', key: 'gas', width: 100, customHeaderCell: gasHeader},
  229. {
  230. title: '最近注水量(t)',
  231. dataIndex: 'water_prod_mon',
  232. key: 'water_prod_mon',
  233. width: 110,
  234. customHeaderCell:waterDragHeader
  235. },
  236. {
  237. title: '累注水量(10kt)',
  238. dataIndex: 'water_prod_year',
  239. key: 'water_prod_year',
  240. width: 150,
  241. customHeaderCell: waterHeader
  242. },
  243. {title: '累注水量趋势', dataIndex: 'water', key: 'water', width: 100, customHeaderCell: waterHeader},
  244. {title: '操作列', dataIndex: 'operation', key: 'operation', align: 'center', width: 120}
  245. ];