adSet.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. <template>
  2. <!-- 广告管理 - 新增|修改 -->
  3. <div class="advertPage flex-col">
  4. <s-header :name="pageTitle" :noback="false"></s-header>
  5. <div class="advertBox flex-col">
  6. <van-form @submit="updateAdFun">
  7. <van-field required v-model="adInfo.name" name="name" :label="`${$t('advertManage.advertisingNameLabel')}:`"
  8. :placeholder="$t('advertManage.advertisingNamePlaceholder')" :rules="[
  9. {
  10. required: true,
  11. message: $t('advertManage.advertisingNamePlaceholder'),
  12. },
  13. ]" />
  14. <van-field v-model="adInfo.adminId" name="adminId" :label="`${$t('advertManage.affiliatedMerchantsLabel')}:`"
  15. :placeholder="$t('advertManage.affiliatedMerchantsPlaceholder')" />
  16. <van-field v-model="adInfo.orders" name="orders" type="number"
  17. :label="`${$t('advertManage.advertisingOrderLabel')}:`"
  18. :placeholder="$t('advertManage.advertisingOrderPlaceholder')" />
  19. <van-field required clearable @click-input="busiInpClk" v-model="adInfo.equipmentType" name="equipmentType"
  20. :label="`${$t('advertManage.machineType')}:`" :placeholder="$t('advertManage.machineTypePlace')" :rules="[
  21. {
  22. required: true,
  23. message: $t('advertManage.machineTypePlace'),
  24. },
  25. ]">
  26. <template #right-icon>
  27. <div class="l-flex-RC">
  28. <van-icon v-if="adInfo.equipmentType" @click="adInfo.equipmentType = ''" class="o-mr-6" name="clear" />
  29. <van-icon @click="busiInpClk" name="arrow-down" />
  30. </div>
  31. </template>
  32. </van-field>
  33. <van-field v-model="adInfo.duration" name="duration" type="number"
  34. :label="`${$t('advertManage.advertisingDurationLabel')}:`"
  35. :placeholder="$t('advertManage.advertisingDurationPlaceholder')" />
  36. <van-field v-model="adInfo.plays" name="plays" type="number" :label="`${$t('advertManage.playbackTimesLabel')}:`"
  37. :placeholder="$t('advertManage.playbackTimesPlaceholder')" />
  38. <div class="van-cell van-field">
  39. <div class="van-cell__title van-field__label">
  40. <span>{{ $t("advertManage.advertisingPosition") }}:</span>
  41. </div>
  42. <div class="van-cell__value van-field__value radioBox">
  43. <van-radio-group v-model="adInfo.screenType" direction="horizontal">
  44. <van-radio name="0" icon-size="18px">{{
  45. $t("advertManage.screenA")
  46. }}</van-radio>
  47. <van-radio name="1" icon-size="18px">{{
  48. $t("advertManage.screenB")
  49. }}</van-radio>
  50. </van-radio-group>
  51. </div>
  52. </div>
  53. <div class="van-cell van-field">
  54. <div class="van-cell__title van-field__label">
  55. <span>{{ $t("advertManage.locationType") }}:</span>
  56. </div>
  57. <div class="van-cell__value van-field__value radioBox">
  58. <van-radio-group v-model="adInfo.locationType" direction="horizontal">
  59. <van-radio name="0" icon-size="18px">{{
  60. $t("advertManage.advertising")
  61. }}</van-radio>
  62. <van-radio name="1" icon-size="18px">{{
  63. $t("advertManage.externalAdvertising")
  64. }}</van-radio>
  65. </van-radio-group>
  66. </div>
  67. </div>
  68. <div class="van-cell van-field">
  69. <div class="van-cell__title van-field__label">
  70. <span>{{ $t("advertManage.defaultDownload") }}:</span>
  71. </div>
  72. <div class="van-cell__value van-field__value radioBox">
  73. <van-radio-group v-model="adInfo.type" direction="horizontal">
  74. <van-radio name="0" icon-size="18px">{{
  75. $t("advertManage.defaultDownload")
  76. }}</van-radio>
  77. <van-radio name="1" icon-size="18px">{{
  78. $t("advertManage.doNotDownloadByDefault")
  79. }}</van-radio>
  80. </van-radio-group>
  81. </div>
  82. </div>
  83. <div class="van-cell van-field">
  84. <div class="van-cell__title van-field__label">
  85. <span>{{ $t("advertManage.advertisingType") }}:</span>
  86. </div>
  87. <div class="van-cell__value van-field__value radioBox">
  88. <van-radio-group v-model="adInfo.adType" direction="horizontal">
  89. <van-radio name="0" icon-size="18px">{{
  90. $t("advertManage.picture")
  91. }}</van-radio>
  92. <van-radio name="1" icon-size="18px">{{
  93. $t("advertManage.video")
  94. }}</van-radio>
  95. </van-radio-group>
  96. </div>
  97. </div>
  98. <div v-if="adInfo.adType === '0'">
  99. <van-field required v-model="adInfo.url" name="url" :label="`${$t('advertManage.pictureAddressLabel')}:`"
  100. :placeholder="$t('advertManage.pictureAddressPlaceholder')" :rules="[
  101. {
  102. required: true,
  103. message: $t('advertManage.pictureAddressPlaceholder'),
  104. },
  105. ]" />
  106. </div>
  107. <div v-if="adInfo.adType === '1'">
  108. <van-field v-model="adInfo.mediaPreview" name="mediaPreview"
  109. :label="`${$t('advertManage.thumbnailAddressLabel')}:`"
  110. :placeholder="$t('advertManage.thumbnailAddressPlaceholder')" />
  111. <van-field required v-model="adInfo.url" name="url" :label="`${$t('advertManage.videoLinkLabel')}:`"
  112. :placeholder="$t('advertManage.videoLinkPlaceholder')" :rules="[
  113. {
  114. required: true,
  115. message: $t('advertManage.videoLinkPlaceholder'),
  116. },
  117. ]" />
  118. </div>
  119. <van-row justify="space-around" style="padding: 1em">
  120. <van-button span="5" round type="primary" style="height: 2em; padding: 0 2em" native-type="submit">
  121. {{ $t("advertManage.submit") }}
  122. </van-button>
  123. </van-row>
  124. </van-form>
  125. </div>
  126. <!-- 机器类型选择框 -->
  127. <van-popup v-model:show="busiPopShow" position="bottom">
  128. <van-picker v-model="busiDefaIdx" :title="$t('advertManage.machineTypePlace')" :columns="busiPopList"
  129. :columns-field-names="busiPopFieldName" @confirm="busiPopConfirm" @cancel="busiPopShow = false" />
  130. </van-popup>
  131. </div>
  132. </template>
  133. <script>
  134. import { onMounted, ref, reactive } from "vue";
  135. import sHeader from "../../components/SimpleHeader";
  136. import { addAdInfo, updateAdInfo } from "../../service/advertManage";
  137. import { useRouter } from "vue-router";
  138. import { showFailToast, showSuccessToast } from 'vant';
  139. import { useI18n } from "vue-i18n";
  140. import { styleUrl } from "../../common/js/utils";
  141. export default {
  142. components: { sHeader },
  143. setup() {
  144. // 点击机器类型
  145. const busiInpClk = () => {
  146. busiPopShow.value = true;
  147. };
  148. // 机器类型
  149. const busiPopShow = ref(false);
  150. const busiDefaIdx = ref(["280"]);
  151. const busiPopList = reactive([
  152. {
  153. name: "280",
  154. id: "280",
  155. },
  156. {
  157. name: "280en",
  158. id: "280en",
  159. },
  160. {
  161. name: "301",
  162. id: "301",
  163. },
  164. {
  165. name: "301en",
  166. id: "301en",
  167. },
  168. {
  169. name: "320",
  170. id: "320",
  171. },
  172. {
  173. name: "320en",
  174. id: "320en",
  175. },
  176. {
  177. name: "330",
  178. id: "330",
  179. },
  180. {
  181. name: "330en",
  182. id: "330en",
  183. },
  184. {
  185. name: "P30",
  186. id: "P30",
  187. },
  188. {
  189. name: "P30en",
  190. id: "P30en",
  191. },
  192. {
  193. name: "SI320",
  194. id: "SI320",
  195. },
  196. {
  197. name: "SI320en",
  198. id: "SI320en",
  199. },
  200. {
  201. name: "SBC320",
  202. id: "SBC320",
  203. },
  204. {
  205. name: "SBC320en",
  206. id: "SBC320en",
  207. },
  208. ]);
  209. const busiPopFieldName = reactive({
  210. text: "name",
  211. value: "id",
  212. });
  213. // 点击机器类型的弹窗确定
  214. const busiPopConfirm = ({ selectedOptions }) => {
  215. adInfo.value.equipmentType = selectedOptions[0].id;
  216. busiPopShow.value = false;
  217. };
  218. const { t } = useI18n();
  219. const router = useRouter();
  220. const adInfo = ref({
  221. adminId: "",
  222. username: null,
  223. name: "",
  224. orders: "",
  225. duration: "",
  226. plays: "",
  227. status: "推送中",
  228. screenType: "0",
  229. locationType: "0",
  230. type: "0",
  231. adType: "0",
  232. url: "",
  233. mediaPreview: "",
  234. equipmentType: "",
  235. });
  236. const pageTitle = ref("");
  237. onMounted(async () => {
  238. // 加载样式
  239. styleUrl('advertManage');
  240. let adverInfo = localStorage.getItem("adverInfo");
  241. if (adverInfo) {
  242. pageTitle.value = t("advertManage.modifyAdvertisement");
  243. adverInfo = JSON.parse(adverInfo);
  244. adInfo.value.id = adverInfo.id;
  245. adInfo.value.adminId = adverInfo.adminId;
  246. adInfo.value.username = adverInfo.username;
  247. adInfo.value.name = adverInfo.name;
  248. adInfo.value.orders = adverInfo.orders;
  249. adInfo.value.duration = adverInfo.duration;
  250. adInfo.value.plays = adverInfo.plays;
  251. adInfo.value.screenType =
  252. typeof adverInfo.screenType === "object"
  253. ? "0"
  254. : adverInfo.screenType.toString();
  255. adInfo.value.locationType =
  256. typeof adverInfo.locationType === "object"
  257. ? "0"
  258. : adverInfo.locationType.toString();
  259. adInfo.value.type =
  260. typeof adverInfo.type === "object" ? "0" : adverInfo.type.toString();
  261. adInfo.value.adType =
  262. typeof adverInfo.adType === "object"
  263. ? "0"
  264. : adverInfo.adType.toString();
  265. adInfo.value.url = adverInfo.url;
  266. adInfo.value.mediaPreview = adverInfo.mediaPreview;
  267. adInfo.value.equipmentType = adverInfo.equipmentType;
  268. // 找到机器类型的下标
  269. // busiPopList.forEach((item, index) => {
  270. // console.log(item, index);
  271. // console.log(adverInfo.equipmentType);
  272. // if (item.id == adverInfo.equipmentType) {
  273. // busiDefaIdx.value = index;
  274. // }
  275. // });
  276. busiDefaIdx.value = [adverInfo.equipmentType];
  277. // console.log(adInfo.value);
  278. } else {
  279. pageTitle.value = t("advertManage.addAds");
  280. }
  281. });
  282. const updateAdFun = async () => {
  283. if (pageTitle.value === t("advertManage.modifyAdvertisement")) {
  284. const params = Object.assign({}, adInfo.value);
  285. const { data } = await updateAdInfo(params);
  286. if (data.code === "00000") {
  287. showSuccessToast(t("advertManage.successfullyModifiedTheAdvertisement"));
  288. router.push({ path: "advertManage" });
  289. } else {
  290. showFailToast(data.message);
  291. }
  292. console.log("updateAdFun", data);
  293. } else {
  294. const params = Object.assign({}, adInfo.value);
  295. const { data } = await addAdInfo(params);
  296. if (data.code === "00000") {
  297. showSuccessToast(t("advertManage.advertisementAddedSuccessfully"));
  298. router.push({ path: "advertManage" });
  299. } else {
  300. showFailToast(data.message);
  301. }
  302. }
  303. };
  304. return {
  305. pageTitle,
  306. adInfo,
  307. updateAdFun,
  308. busiPopShow,
  309. busiDefaIdx,
  310. busiPopList,
  311. busiPopFieldName,
  312. busiPopConfirm,
  313. busiInpClk,
  314. };
  315. },
  316. };
  317. </script>
  318. <style lang="less" scoped>
  319. @import "../../common/style/common.less";
  320. </style>