adSet.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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 class="van-cell van-field">
  99. <div class="van-cell__title van-field__label">
  100. <span>{{ $t("advertManage.playTimeStatus") }}:</span>
  101. </div>
  102. <div class="van-cell__value van-field__value radioBox">
  103. <van-radio-group v-model="adInfo.playTimeStatus" direction="horizontal">
  104. <van-radio name="0" icon-size="18px">{{
  105. $t("advertManage.acquiesce")
  106. }}</van-radio>
  107. <van-radio name="1" icon-size="18px">{{
  108. $t("advertManage.standby")
  109. }}</van-radio>
  110. <van-radio name="2" icon-size="18px">{{
  111. $t("advertManage.work")
  112. }}</van-radio>
  113. </van-radio-group>
  114. </div>
  115. </div>
  116. <div v-if="adInfo.adType === '0'">
  117. <van-field required v-model="adInfo.url" name="url" :label="`${$t('advertManage.pictureAddressLabel')}:`"
  118. :placeholder="$t('advertManage.pictureAddressPlaceholder')" :rules="[
  119. {
  120. required: true,
  121. message: $t('advertManage.pictureAddressPlaceholder'),
  122. },
  123. ]" />
  124. </div>
  125. <div v-if="adInfo.adType === '1'">
  126. <van-field v-model="adInfo.mediaPreview" name="mediaPreview"
  127. :label="`${$t('advertManage.thumbnailAddressLabel')}:`"
  128. :placeholder="$t('advertManage.thumbnailAddressPlaceholder')" />
  129. <van-field required v-model="adInfo.url" name="url" :label="`${$t('advertManage.videoLinkLabel')}:`"
  130. :placeholder="$t('advertManage.videoLinkPlaceholder')" :rules="[
  131. {
  132. required: true,
  133. message: $t('advertManage.videoLinkPlaceholder'),
  134. },
  135. ]" />
  136. </div>
  137. <van-row justify="space-around" style="padding: 1em">
  138. <van-button span="5" round type="primary" style="height: 2em; padding: 0 2em" native-type="submit">
  139. {{ $t("advertManage.submit") }}
  140. </van-button>
  141. </van-row>
  142. </van-form>
  143. </div>
  144. <!-- 机器类型选择框 -->
  145. <van-popup v-model:show="busiPopShow" position="bottom">
  146. <van-picker v-model="busiDefaIdx" :title="$t('advertManage.machineTypePlace')" :columns="busiPopList"
  147. :columns-field-names="busiPopFieldName" @confirm="busiPopConfirm" @cancel="busiPopShow = false" />
  148. </van-popup>
  149. </div>
  150. </template>
  151. <script>
  152. import { onMounted, ref, reactive } from "vue";
  153. import sHeader from "../../components/SimpleHeader";
  154. import { addAdInfo, updateAdInfo } from "../../service/advertManage";
  155. import { useRouter } from "vue-router";
  156. import { showFailToast, showSuccessToast } from 'vant';
  157. import { useI18n } from "vue-i18n";
  158. import { styleUrl } from "../../common/js/utils";
  159. export default {
  160. components: { sHeader },
  161. setup() {
  162. // 点击机器类型
  163. const busiInpClk = () => {
  164. busiPopShow.value = true;
  165. };
  166. // 机器类型
  167. const busiPopShow = ref(false);
  168. const busiDefaIdx = ref(["280"]);
  169. const busiPopList = reactive([
  170. {
  171. name: "280",
  172. id: "280",
  173. },
  174. {
  175. name: "280en",
  176. id: "280en",
  177. },
  178. {
  179. name: "301",
  180. id: "301",
  181. },
  182. {
  183. name: "301en",
  184. id: "301en",
  185. },
  186. {
  187. name: "320",
  188. id: "320",
  189. },
  190. {
  191. name: "320en",
  192. id: "320en",
  193. },
  194. {
  195. name: "330",
  196. id: "330",
  197. },
  198. {
  199. name: "330en",
  200. id: "330en",
  201. },
  202. {
  203. name: "P10",
  204. id: "P10",
  205. },
  206. {
  207. name: "P10en",
  208. id: "P10en",
  209. },
  210. {
  211. name: "P20",
  212. id: "P20",
  213. },
  214. {
  215. name: "P20en",
  216. id: "P20en",
  217. },
  218. {
  219. name: "P30",
  220. id: "P30",
  221. },
  222. {
  223. name: "P30en",
  224. id: "P30en",
  225. },
  226. {
  227. name: "SI320",
  228. id: "SI320",
  229. },
  230. {
  231. name: "SI320en",
  232. id: "SI320en",
  233. },
  234. {
  235. name: "SBC320",
  236. id: "SBC320",
  237. },
  238. {
  239. name: "SBC320en",
  240. id: "SBC320en",
  241. },
  242. {
  243. name: "SBM10ch",
  244. id: "SBM10ch",
  245. },
  246. {
  247. name: "SBM10en",
  248. id: "SBM10en",
  249. },
  250. {
  251. name: "EF210ch",
  252. id: "EF210ch",
  253. },
  254. {
  255. name: "EF210en",
  256. id: "EF210en",
  257. },
  258. ]);
  259. const busiPopFieldName = reactive({
  260. text: "name",
  261. value: "id",
  262. });
  263. // 点击机器类型的弹窗确定
  264. const busiPopConfirm = ({ selectedOptions }) => {
  265. adInfo.value.equipmentType = selectedOptions[0].id;
  266. busiPopShow.value = false;
  267. };
  268. const { t } = useI18n();
  269. const router = useRouter();
  270. const adInfo = ref({
  271. adminId: "",
  272. username: null,
  273. name: "",
  274. orders: "",
  275. duration: "",
  276. plays: "",
  277. status: "推送中",
  278. screenType: "0",
  279. locationType: "0",
  280. type: "0",
  281. adType: "0",
  282. url: "",
  283. mediaPreview: "",
  284. equipmentType: "",
  285. playTimeStatus: "0",
  286. });
  287. const pageTitle = ref("");
  288. onMounted(async () => {
  289. // 加载样式
  290. styleUrl('advertManage');
  291. let adverInfo = localStorage.getItem("adverInfo");
  292. if (adverInfo) {
  293. pageTitle.value = t("advertManage.modifyAdvertisement");
  294. adverInfo = JSON.parse(adverInfo);
  295. adInfo.value.id = adverInfo.id;
  296. adInfo.value.adminId = adverInfo.adminId;
  297. adInfo.value.username = adverInfo.username;
  298. adInfo.value.name = adverInfo.name;
  299. adInfo.value.orders = adverInfo.orders;
  300. adInfo.value.duration = adverInfo.duration;
  301. adInfo.value.plays = adverInfo.plays;
  302. adInfo.value.screenType =
  303. typeof adverInfo.screenType === "object"
  304. ? "0"
  305. : adverInfo.screenType.toString();
  306. adInfo.value.locationType =
  307. typeof adverInfo.locationType === "object"
  308. ? "0"
  309. : adverInfo.locationType.toString();
  310. adInfo.value.type =
  311. typeof adverInfo.type === "object" ? "0" : adverInfo.type.toString();
  312. adInfo.value.adType =
  313. typeof adverInfo.adType === "object"
  314. ? "0"
  315. : adverInfo.adType.toString();
  316. adInfo.value.url = adverInfo.url;
  317. adInfo.value.mediaPreview = adverInfo.mediaPreview;
  318. adInfo.value.equipmentType = adverInfo.equipmentType;
  319. // 找到机器类型的下标
  320. // busiPopList.forEach((item, index) => {
  321. // console.log(item, index);
  322. // console.log(adverInfo.equipmentType);
  323. // if (item.id == adverInfo.equipmentType) {
  324. // busiDefaIdx.value = index;
  325. // }
  326. // });
  327. busiDefaIdx.value = [adverInfo.equipmentType];
  328. // console.log(adInfo.value);
  329. } else {
  330. pageTitle.value = t("advertManage.addAds");
  331. }
  332. });
  333. const updateAdFun = async () => {
  334. if (pageTitle.value === t("advertManage.modifyAdvertisement")) {
  335. const params = Object.assign({}, adInfo.value);
  336. const { data } = await updateAdInfo(params);
  337. if (data.code === "00000") {
  338. showSuccessToast(t("advertManage.successfullyModifiedTheAdvertisement"));
  339. router.push({ path: "advertManage" });
  340. } else {
  341. showFailToast(data.message);
  342. }
  343. console.log("updateAdFun", data);
  344. } else {
  345. const params = Object.assign({}, adInfo.value);
  346. const { data } = await addAdInfo(params);
  347. if (data.code === "00000") {
  348. showSuccessToast(t("advertManage.advertisementAddedSuccessfully"));
  349. router.push({ path: "advertManage" });
  350. } else {
  351. showFailToast(data.message);
  352. }
  353. }
  354. };
  355. return {
  356. pageTitle,
  357. adInfo,
  358. updateAdFun,
  359. busiPopShow,
  360. busiDefaIdx,
  361. busiPopList,
  362. busiPopFieldName,
  363. busiPopConfirm,
  364. busiInpClk,
  365. };
  366. },
  367. };
  368. </script>
  369. <style lang="less" scoped>
  370. @import "../../common/style/common.less";
  371. </style>