index.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. <template>
  2. <div class="advertRuleIdx">
  3. <s-header :name="$t('advertManage.advertRule.sysTitle')" :noback="false"></s-header>
  4. <div v-if="isDelete" class="headCon l-flex-between o-plr-20 o-pt-15 o-pb-12 kBordBott">
  5. <div class="l-flex-RC c-text-15 c-text-color c-text-b">
  6. {{ $t("advertManage.advertRule.selected") }}
  7. {{ selectTotals }}
  8. {{ $t("advertManage.advertRule.individual") }}
  9. </div>
  10. <div class="l-flex-RC">
  11. <div @click="cancelClk" class="c-text-c c-text-13 c-color">
  12. {{ $t("advertManage.advertRule.cancel") }}
  13. </div>
  14. <div @click="noticeClk" class="c-text-c o-ml-24 c-text-13" style="color: #df5e4c">
  15. {{ $t("advertManage.advertRule.confirmDel") }}
  16. </div>
  17. </div>
  18. </div>
  19. <div v-else class="headCon l-flex-between o-plr-20 o-pt-26 o-pb-12 kBordBott">
  20. <div class="l-flex-RC">
  21. <img class="ruleIcon o-mr-10" src="../../../assets/advertManage/ruleIcon.png" alt="" />
  22. <div class="c-text-color c-text-b c-text-15">
  23. {{ $t("advertManage.advertRule.total")
  24. }}<span class="c-text-20" style="color: #df5e4c">{{
  25. ruleTotal
  26. }}</span>
  27. {{ $t("advertManage.advertRule.rules") }}
  28. </div>
  29. </div>
  30. <div class="l-flex-RC">
  31. <div @click="toAdd" class="c-text-c">
  32. <div>
  33. <van-icon size="18" name="add-o" />
  34. </div>
  35. <div class="c-text-color c-text-12">
  36. {{ $t("advertManage.advertRule.add") }}
  37. </div>
  38. </div>
  39. <div @click="isDelete = true" class="c-text-c o-ml-24">
  40. <div>
  41. <van-icon size="18" name="close" />
  42. </div>
  43. <div class="c-text-color c-text-12">
  44. {{ $t("advertManage.advertRule.delete") }}
  45. </div>
  46. </div>
  47. </div>
  48. </div>
  49. <div class="contentCon">
  50. <van-pull-refresh disabled v-model="refreshing" @refresh="onRefresh">
  51. <van-list v-model="loading" :finished="finished" :finished-text="$t('common.noMoreTxt')" @load="onLoad"
  52. :offset="20" :immediate-check="false">
  53. <div @click.self="toEdit(item)" v-for="item in tableData" :key="item.id"
  54. class="o-plr-20 o-pt-24 o-pb-12 l-flex-between kBordBott content">
  55. <div>
  56. <div class="c-text-b c-text-color c-text-15">{{ item.name }}</div>
  57. <div class="l-flex-RC o-mt-14">
  58. <span class="c-color c-text-12">{{ $t("advertManage.advertRule.createTime") }}:</span>
  59. <span class="c-text-color c-text-12">{{
  60. Format_time(item.createDate)
  61. }}</span>
  62. </div>
  63. </div>
  64. <div class="rightCon">
  65. <template v-if="isDelete">
  66. <van-checkbox v-model="item.checked">{{ " " }}</van-checkbox>
  67. </template>
  68. <template v-else>
  69. <div @click="pushRuleClk(item.id)" class="pushBtn o-mb-10 c-text-14">
  70. {{ $t("advertManage.advertRule.push") }}
  71. </div>
  72. <div @click="toEdit(item)" class="editBtn c-text-14">
  73. {{ $t("advertManage.advertRule.edit") }}
  74. </div>
  75. </template>
  76. </div>
  77. </div>
  78. </van-list>
  79. </van-pull-refresh>
  80. </div>
  81. <!-- 删除确认弹窗 -->
  82. <kDialog :dialogTitle="$t('advertManage.delPopTitle')" :cancelBtnTxt="$t('advertManage.cancelTxt')"
  83. :confirmBtnTxt="$t('advertManage.confirmDel')" ref="kDialogRef" :dialogContent="$t('advertManage.delPopContent')"
  84. @confirmclk="confirmClk">
  85. </kDialog>
  86. </div>
  87. </template>
  88. <script>
  89. import { useStore } from "vuex";
  90. import { Format_time, styleUrl } from "../../../common/js/utils";
  91. import kDialog from "../../../components/commom/kDialog/index.vue";
  92. // 导入接口
  93. import {
  94. Api_postPageTimeRule,
  95. Api_getPushAdRule,
  96. Api_getDelAdRule,
  97. } from "../../../service/advertManage";
  98. import { computed, onMounted, reactive, ref, toRefs } from "vue";
  99. import sHeader from "../../../components/SimpleHeader";
  100. import { useRouter } from "vue-router";
  101. import { Toast } from "vant";
  102. import { useI18n } from "vue-i18n";
  103. export default {
  104. components: { sHeader, kDialog },
  105. setup() {
  106. const { t } = useI18n();
  107. // 删除确认弹窗
  108. const kDialogRef = ref(null);
  109. // 点击确认删除
  110. const noticeClk = () => {
  111. if (selectTotals.value < 1) {
  112. Toast(t("advertManage.delTips"));
  113. return;
  114. }
  115. kDialogRef.value.openDialog();
  116. };
  117. // 点击右侧按钮
  118. const confirmClk = () => {
  119. const ids = [];
  120. ruleData.tableData.forEach((item) => {
  121. if (item.checked) {
  122. ids.push(item.id);
  123. }
  124. });
  125. let param = {
  126. ids,
  127. };
  128. Api_getDelAdRule(param).then((res) => {
  129. console.log(res);
  130. if (res.data.code === '00000') {
  131. isDelete.value = false;
  132. Toast(res.data.message);
  133. setTimeout(() => {
  134. onRefresh();
  135. }, 500);
  136. }
  137. });
  138. };
  139. // 是否删除状态
  140. const isDelete = ref(false);
  141. // 选中
  142. const selectTotals = computed(() => {
  143. let nums = 0;
  144. if (ruleData.tableData.length > 0) {
  145. ruleData.tableData.forEach((item) => {
  146. if (item.checked) {
  147. nums++;
  148. }
  149. });
  150. }
  151. return nums;
  152. });
  153. // 点击取消删除
  154. const cancelClk = () => {
  155. // 把选中状态去掉
  156. if (ruleData.tableData.length > 0) {
  157. ruleData.tableData.forEach((item) => {
  158. if (item.checked) {
  159. item.checked = false;
  160. }
  161. });
  162. }
  163. isDelete.value = false;
  164. };
  165. // 多少条规则
  166. const ruleTotal = ref(0);
  167. // 分页
  168. const pageNo = ref(1);
  169. const pageSize = ref(20);
  170. let ruleData = reactive({
  171. tableData: [],
  172. });
  173. // 上拉刷新
  174. const loading = ref(true);
  175. const finished = ref(false);
  176. // 下拉刷新
  177. const refreshing = ref(false);
  178. // 导入vuex
  179. const store = useStore();
  180. onMounted(() => {
  181. // 加载样式
  182. styleUrl('advertManage');
  183. onRefresh();
  184. // 初始化
  185. init();
  186. });
  187. const init = () => {
  188. // 储存数据到vuex
  189. store.commit("MUTA_A_ADVERTLIST", []);
  190. store.commit("MUTA_B_ADVERTLIST", []);
  191. localStorage.removeItem("advertManage-A-advertList");
  192. localStorage.removeItem("advertManage-B-advertList");
  193. };
  194. // 下拉刷新
  195. const onRefresh = () => {
  196. ruleData.tableData = [];
  197. finished.value = false;
  198. loading.value = true;
  199. // 初始化分页
  200. pageNo.value = 1;
  201. pageSize.value = 20;
  202. getList();
  203. };
  204. // 上拉加载
  205. const onLoad = () => {
  206. pageNo.value++;
  207. getList();
  208. };
  209. const getList = () => {
  210. let param = {
  211. current: pageNo.value,
  212. size: pageSize.value,
  213. };
  214. Api_postPageTimeRule(param).then((res) => {
  215. const { data } = res.data;
  216. refreshing.value = false;
  217. // 加入删除选中状态
  218. if (data.records.length > 0) {
  219. data.records.forEach((item) => {
  220. item.checked = false;
  221. });
  222. }
  223. ruleData.tableData.push(...data.records);
  224. // 加载状态结束
  225. loading.value = false;
  226. // 总共
  227. ruleTotal.value = data.total;
  228. if (ruleData.tableData.length >= data.total) {
  229. finished.value = true;
  230. }
  231. });
  232. };
  233. const router = useRouter();
  234. // 点击添加按钮
  235. const toAdd = () => {
  236. router.push("/advertRuleAdd");
  237. };
  238. // 点击推送按钮
  239. const pushRuleClk = (id) => {
  240. Api_getPushAdRule({ id }).then((res) => {
  241. if (res.data.code === "00000") {
  242. Toast("推送成功");
  243. }
  244. });
  245. };
  246. // 点击编辑
  247. const toEdit = (row) => {
  248. // 如果是删除模式,则是选中和取消状态
  249. if (isDelete.value) {
  250. ruleData.tableData.forEach((item) => {
  251. if (item.id === row.id) {
  252. item.checked = !item.checked;
  253. }
  254. });
  255. } else {
  256. router.push(`/advertRuleAdd?id=${row.id}`);
  257. }
  258. };
  259. return {
  260. pageNo,
  261. pageSize,
  262. loading,
  263. finished,
  264. refreshing,
  265. onRefresh,
  266. onLoad,
  267. getList,
  268. ...toRefs(ruleData),
  269. isDelete,
  270. selectTotals,
  271. cancelClk,
  272. ruleTotal,
  273. toAdd,
  274. pushRuleClk,
  275. confirmClk,
  276. kDialogRef,
  277. noticeClk,
  278. toEdit,
  279. Format_time,
  280. };
  281. },
  282. };
  283. </script>
  284. <style lang="less" scoped></style>