bannerAdd.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <template>
  2. <view class="container">
  3. <form @submit="onSubmit">
  4. <view class="page-block">
  5. <view class="content">
  6. <view class="cell flex flex-y-center arr-r">
  7. <view class="title-block required">
  8. <text>显示位置</text>
  9. </view>
  10. <view class="desc">
  11. <picker mode="selector" :range="printerAddrList" @change="onPrinterAddrChange">
  12. <view :class="[printerAddr?'':'desc-placeholder','input-box']">{{printerAddr || '请选择'}}
  13. </view>
  14. </picker>
  15. </view>
  16. </view>
  17. <view class="cell flex flex-y-center">
  18. <view class="title-block requsired">
  19. <text>标题</text>
  20. </view>
  21. <view class="desc">
  22. <input type="num" :value="info.name" name="name" class="input-box" placeholder="请输入"
  23. placeholder-class="desc-placeholder">
  24. </view>
  25. </view>
  26. <view class="cell flex flex-y-center">
  27. <view class="title-block requsired">
  28. <text>跳转小程序appid</text>
  29. </view>
  30. <view class="desc">
  31. <input type="num" :value="info.appid" name="appid" class="input-box" placeholder="请输入"
  32. placeholder-class="desc-placeholder">
  33. </view>
  34. </view>
  35. <view class="cell flex flex-y-center">
  36. <view class="title-block requsired">
  37. <text>跳转小程序名称</text>
  38. </view>
  39. <view class="desc">
  40. <input type="num" :value="info.appid_name" name="appid_name" class="input-box"
  41. placeholder="请输入" placeholder-class="desc-placeholder">
  42. </view>
  43. </view>
  44. <view class="cell flex flex-y-center">
  45. <view class="title-block requsired">
  46. <text>排序</text>
  47. </view>
  48. <view class="desc">
  49. <input type="num" :value="info.num" class="input-box" placeholder="请输入"
  50. placeholder-class="desc-placeholder">
  51. </view>
  52. </view>
  53. </view>
  54. <view class="icon-page" @click="ChooseImage">
  55. <view class="flex-y-center">
  56. 上传广告图<text style="color: red;font-size: 26rpx;">(图片尺寸{{device_type==1?' 750*400':'750*550'}})</text>
  57. </view>
  58. <view class="icon_un flex-center">
  59. <image mode="aspectFit" class="icon_un_icons" :src="URL+thumb" v-if="thumb"></image>
  60. <image mode="aspectFit" class="icon_un_icon" :src="require('./static/images/icon_18.png')" v-else></image>
  61. </view>
  62. </view>
  63. </view>
  64. <view class="footer-bar">
  65. <view class="content flex flex-center" style="background: none;">
  66. <!-- <view class="btn">立即添加</view> -->
  67. <button class="btn" hover-class="none" form-type="submit">
  68. {{info.id?'修改广告':'添加广告'}}
  69. </button>
  70. </view>
  71. </view>
  72. </form>
  73. </view>
  74. </template>
  75. <script>
  76. export default {
  77. data() {
  78. return {
  79. printerAddrList: ['支付后广告', '首页'],
  80. printerAddr: '支付后广告',
  81. device_type: 1,
  82. tableType: "",
  83. store_id: "",
  84. info: {},
  85. id: '',
  86. type_id: 1,
  87. thumb: "",
  88. URL: getApp().globalData.URL,
  89. imgid: "",
  90. }
  91. },
  92. onLoad(e) {
  93. if (e.id) {
  94. this.id = e.id;
  95. this.banner_info();
  96. }
  97. this.store_id = uni.getStorageSync("store_id");
  98. },
  99. methods: {
  100. banner_info() {
  101. this.request({
  102. url: 'Smdcshop/banner_info',
  103. data: {
  104. id: this.id
  105. }
  106. }).then(res => {
  107. if (res.code == 200) {
  108. this.info = res.data
  109. this.thumb = res.data.thumb;
  110. this.device_type = res.data.type_id;
  111. this.printerAddr = res.data.type_id == 1 ? '支付后广告' : '首页'
  112. }
  113. })
  114. },
  115. ChooseImage(e) {
  116. let type = e.currentTarget.dataset.type;
  117. uni.chooseImage({
  118. count: 1,
  119. sizeType: ['original', 'compressed'],
  120. sourceType: ['album'], //从相册选择
  121. success: (res) => {
  122. console.log(res)
  123. res.tempFilePaths.forEach((v, i) => {
  124. this.Upload({
  125. url: "Smdcshop/upload",
  126. data: {
  127. url: v,
  128. type: "",
  129. token: "",
  130. admin_id: uni.getStorageSync("admin_id")
  131. }
  132. }).then(res => {
  133. console.log(res, "res")
  134. this.imgid = res.id;
  135. this.thumb = res.src;
  136. }).catch(err => {
  137. uni.showToast({
  138. title: err.message,
  139. icon: 'none'
  140. })
  141. });
  142. })
  143. },
  144. });
  145. },
  146. onPrinterAddrChange(e) {
  147. this.printerAddr = this.printerAddrList[e.detail.value];
  148. this.device_type = Number(e.detail.value) + 1;
  149. },
  150. onSubmit(e) {
  151. let params = {
  152. admin_id: uni.getStorageSync("admin_id"),
  153. thumb: this.imgid,
  154. num: e.detail.value.num,
  155. name: e.detail.value.name,
  156. type_id: this.device_type,
  157. appid_name: e.detail.value.appid_name,
  158. appid: e.detail.value.appid
  159. },
  160. url;
  161. if (this.id) {
  162. params.id = this.id;
  163. url = "Smdcshop/banner_update"
  164. } else {
  165. url = 'Smdcshop/banner_add'
  166. }
  167. if (params.name == "") {
  168. uni.showToast({
  169. title: "请输入名称",
  170. icon: 'none'
  171. })
  172. return false
  173. }
  174. this.request({
  175. url,
  176. data: params
  177. }).then(res => {
  178. if (res.code == 200) {
  179. uni.showToast({
  180. title: res.message,
  181. icon: 'none'
  182. })
  183. setTimeout(() => {
  184. uni.navigateBack()
  185. }, 2000)
  186. }
  187. }).catch((res) => {
  188. uni.showToast({
  189. title: res.message,
  190. icon: 'none'
  191. })
  192. });
  193. },
  194. }
  195. }
  196. </script>
  197. <style>
  198. @import url("./static/css/common.css");
  199. page {
  200. background-color: #F4F5F7;
  201. }
  202. .icon-page {
  203. padding: 20rpx;
  204. background: #FFFFFF;
  205. }
  206. .icon_un {
  207. width: 100%;
  208. height: 400rpx;
  209. margin-top: 20px;
  210. text-align: center;
  211. }
  212. .icon_un_icons {
  213. width: 100%;
  214. height: 300rpx;
  215. margin-top: 20px;
  216. }
  217. .icon_un_icon {
  218. width: 150rpx;
  219. height: 150rpx;
  220. margin-top: 20px;
  221. }
  222. </style>