index.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <template>
  2. <div class="table-box">
  3. <LjVxeTable
  4. ref="VxeTableRef"
  5. row-key="areaid"
  6. :columns="columns"
  7. :request-api="getData"
  8. :data-callback="dataCallback"
  9. :dwname="dwname"
  10. :table-props="tableProps"
  11. :table-events="tableEvents"
  12. :auto-load-layout="false"
  13. pagination
  14. >
  15. <!-- 表格 header 按钮 -->
  16. <template #tableHeader>
  17. <el-button-group>
  18. <el-button @click="handleOpenNewTable">{{ $t("common.add") }}</el-button>
  19. <el-button @click="fDelete">{{ $t("common.delText") }}</el-button>
  20. </el-button-group>
  21. </template>
  22. </LjVxeTable>
  23. </div>
  24. <LjDialog
  25. ref="LjDrawerRef"
  26. class="is-selector"
  27. v-bind="{
  28. ...drawerDefineProp
  29. }"
  30. :style="{ padding: 0 }"
  31. >
  32. <template #header>
  33. <div class="flx-1">
  34. <span class="text-h5-b">多维度定价</span>
  35. </div>
  36. </template>
  37. <div class="flx-1 h-full">
  38. <LjHeaderMenu :action="orderStatus ? orderEditAction : orderDefaultAction" />
  39. <Detail class="flx-1" :data="mainData" :status="orderStatus" :enum="enumMap" />
  40. </div>
  41. </LjDialog>
  42. </template>
  43. <script setup lang="ts" name="baseinfo_bednetarealist">
  44. import { ref, onMounted, provide } from "vue";
  45. import { getBedNetAreaList } from "@/api/modules/basicinfo";
  46. import { ColumnProps } from "@/components/LjVxeTable/interface";
  47. import LjDrawer from "@/components/LjDrawer/index.vue";
  48. import Detail from "./detail.vue";
  49. import { useHooks } from "./hooks/index";
  50. import LjDialog from "@/components/LjDialog/index.vue";
  51. import LjHeaderMenu from "@/components/LjHeaderMenu/index.vue";
  52. import { useI18n } from "vue-i18n";
  53. import { useAuthButtons } from "@/hooks/useAuthButtons";
  54. import { cloneDeep } from "lodash-es";
  55. import { ElButton, ElMessage } from "element-plus";
  56. const dwname = "web_bednet_arealist";
  57. const mainData = ref({});
  58. const tableProps = {
  59. height: "auto",
  60. editConfig: { trigger: "click", mode: "cell" }
  61. // rowClassName: rowClsNameFunc
  62. // exportConfig: {
  63. // filename: t("menu.saletaskmx") + formatToDate(new Date(), "YYYY-MM-DD HH:mm:ss")
  64. // }
  65. };
  66. const { t } = useI18n();
  67. const { VxeTableRef, LjDetailRef, columns, fDelete, fSave } = useHooks(t);
  68. const { CheckPower, CheckOption, buttonNew, buttonDefault } = useAuthButtons(t);
  69. const orderStatus = ref("");
  70. const enumMap = ref(new Map());
  71. const orderDefaultAction = [
  72. buttonDefault({
  73. label: t("common.cancelText"),
  74. icon: "iconchevron-left"
  75. }),
  76. buttonNew({
  77. label: t("common.saveText"),
  78. icon: "iconsave-01",
  79. clickFunc: item => {
  80. const save_data = LjDetailRef.value?._mainData;
  81. fSave({ area: save_data }).then(() => {
  82. LjDrawerRef.value.hide();
  83. });
  84. }
  85. })
  86. ];
  87. const orderEditAction = [
  88. buttonNew({
  89. label: t("common.saveText"),
  90. icon: "iconsave-01",
  91. clickFunc: async item => {
  92. const save_data = LjDetailRef.value?._mainData;
  93. await LjDetailRef.value.toValidateForm();
  94. let arr = [];
  95. for (const key in save_data) {
  96. if (key.indexOf("area_") > -1) {
  97. arr.push(Number(save_data[key]));
  98. }
  99. }
  100. // 判断数值连续填写,中间不能有0
  101. if (hasZerosBetweenNonZeroNumbers(arr) > 0) {
  102. ElMessage.error(`分区比例应连续不间断填写,${hasZerosBetweenNonZeroNumbers(arr)}区不能为0`);
  103. return false;
  104. }
  105. fSave({ area: save_data }).then(() => {
  106. LjDrawerRef.value.hide();
  107. });
  108. }
  109. })
  110. ];
  111. /**
  112. * @description 判断数值连续填写,中间不能有0
  113. * @param arr 数值数组
  114. * @param {number} 存在0的位置
  115. */
  116. function hasZerosBetweenNonZeroNumbers(arr) {
  117. let foundNonZero = false;
  118. let hasZeros = false;
  119. for (let i = 0; i < arr.length; i++) {
  120. if (Number(arr[i]) !== 0) {
  121. if (foundNonZero && hasZeros) {
  122. return i;
  123. }
  124. foundNonZero = true;
  125. hasZeros = true;
  126. } else if (foundNonZero) {
  127. hasZeros = true;
  128. }
  129. }
  130. return 0;
  131. }
  132. /*
  133. * @description 抽屉默认属性
  134. */
  135. const drawerDefineProp = {
  136. draggable: true,
  137. overflow: true,
  138. width: "40%"
  139. // modalClass: "lj-file-dialog"
  140. };
  141. const getData = (params: any) => {
  142. return getBedNetAreaList(params);
  143. };
  144. const dataCallback = (data: any) => {
  145. if (data.tableinfo?.columns) {
  146. data.tableinfo?.columns.map((item: any) => {
  147. if (item?.enum) {
  148. enumMap.value.set(item.field, item.enum);
  149. }
  150. });
  151. }
  152. return {
  153. list: data.datatable,
  154. tableinfo: data.tableinfo,
  155. total: data.totalcnt,
  156. pageNum: data.pageindex,
  157. pageSize: data.pagesize
  158. };
  159. };
  160. const LjDrawerRef = ref();
  161. const handleDBlClickTable = ({ row, rowIndex, $rowIndex, column, columnIndex, $columnIndex, $event }: any) => {
  162. // 弹窗
  163. mainData.value = cloneDeep(row);
  164. orderStatus.value = "edit";
  165. LjDrawerRef.value.show();
  166. };
  167. const handleOpenNewTable = () => {
  168. mainData.value = {};
  169. orderStatus.value = "new";
  170. LjDrawerRef.value.show();
  171. };
  172. // 返回绑定的事件
  173. const tableEvents = {
  174. "cell-dblclick": handleDBlClickTable
  175. // "cell-click": handleClickTable
  176. };
  177. </script>