addCommodity.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. <template>
  2. <view class="page" :style="{'height':(h)+'px','padding-top':mt+'px'}">
  3. <c-nav-bar title="添加商品" :showIcon="true"></c-nav-bar>
  4. <view class="body">
  5. <view class="typeInfo">
  6. <view class="cellBox">
  7. <text style="font-size: 32rpx; font-weight: 700;">商品名称</text>
  8. <input v-model="fromData.comboName" type="text" placeholder="请输入商品名称"
  9. style="width: 210rpx;height: 42rpx; font-size: 30rpx;flex:1" />
  10. </view>
  11. <view class="cellBox">
  12. <text style="font-size: 32rpx; font-weight: 700;">价格</text>
  13. <input v-model="fromData.price" type="text" placeholder="请输入价格"
  14. style="width: 210rpx;height: 42rpx; font-size: 30rpx;flex:1" />
  15. </view>
  16. <!-- <view class="cellBox">
  17. <text style="font-size: 32rpx; font-weight: 700;">库存</text>
  18. <input v-model="fromData.shortName" type="text" placeholder="请输入库存"
  19. style="width: 210rpx;height: 42rpx; font-size: 30rpx;flex:1" />
  20. </view> -->
  21. <view class="cellBox">
  22. <text style="font-size: 32rpx; font-weight: 700;">类型</text>
  23. <input v-model="fromData.comboType" type="text" placeholder="请输入类型"
  24. style="width: 210rpx;height: 42rpx; font-size: 30rpx;flex:1" />
  25. </view>
  26. <view class="uploadPic">
  27. <view style=" margin-left: 16rpx; margin-bottom: 22rpx;">
  28. <text style="font-size: 32rpx; font-weight: 700; ">套餐内容</text>
  29. </view>
  30. <view class="textarea">
  31. <u--textarea v-model="fromData.comboExplain" height='310' placeholder="最多输入60个汉字"
  32. count></u--textarea>
  33. </view>
  34. </view>
  35. <view class="uploadPic">
  36. <view style=" margin-left: 16rpx;">
  37. <text style="font-size: 32rpx; font-weight: 700; "> 主图/封面</text>
  38. </view>
  39. <view class="pic">
  40. <!-- 图片 -->
  41. <u-upload :fileList="cover" multiple :maxCount="1" :maxSize="1 * 1024 * 1024"
  42. @afterRead="afterReadcover" @oversize="overSize" width="180" height="180"
  43. @delete="deletePic">
  44. </u-upload>
  45. </view>
  46. </view>
  47. <view class="uploadPic">
  48. <view style=" margin-left: 16rpx;">
  49. <text style="font-size: 32rpx; font-weight: 700; ">套餐照片</text>
  50. </view>
  51. <view class="pic">
  52. <!-- 图片 -->
  53. <u-upload :fileList="introduction" multiple :maxCount="5" :maxSize="5 * 1024 * 1024"
  54. @afterRead="afterRead" @oversize="overSize" width="180" height="180" @delete="deletePic">
  55. </u-upload>
  56. </view>
  57. </view>
  58. </view>
  59. <!-- 图片上传
  60. -->
  61. </view>
  62. <view class="btn-btn">
  63. <view class="hander-two">
  64. <view class="pop-btn-del" @click="Shelves(0)">
  65. 保存
  66. </view>
  67. <view class="pop-btn-add" @click="Shelves(1)">
  68. 立即上架
  69. </view>
  70. </view>
  71. </view>
  72. </view>
  73. </view>
  74. </template>
  75. <script>
  76. export default {
  77. data() {
  78. return {
  79. checked: false,
  80. weekedChecked: false,
  81. action: '', //图片服务器地址
  82. value2: '统计字数',
  83. introduction: [],
  84. introductioned: [],
  85. cover: [],
  86. covered: [],
  87. fromData: {
  88. comboName: "", //套餐名称
  89. comboType: '1', //套餐类型: 1包桌 2按人头
  90. cover: '', //主图/封面
  91. introduction: '', //图片 多个以,分割
  92. price: '', //价格
  93. status: '0', //是否上下架: 1是0否
  94. comboExplain: '', //说明
  95. homestayId: uni.getStorageSync('homestayId'),
  96. }
  97. }
  98. },
  99. onLoad() {},
  100. methods: {
  101. // 保存 上架
  102. Shelves(status) {
  103. if (!this.fromData.comboName) return this.$showToast("请添商品名称");
  104. if (!this.fromData.price) return this.$showToast("请填写价格");
  105. if (!this.fromData.comboType) return this.$showToast("请选择套餐类型");
  106. if (!this.fromData.comboExplain) return this.$showToast("请填写套餐内容");
  107. if (!this.fromData.cover) return this.$showToast("请上传主图/封面");
  108. if (!this.fromData.introduction) return this.$showToast("请上传套餐照片");
  109. this.$api.post('/merchant/hotel/repast', this.fromData).then(res => {
  110. console.log(res.data);
  111. })
  112. },
  113. // 删除图片
  114. deletePic(event) {
  115. this.introduction.splice(event.index, 1)
  116. },
  117. // 新增图片
  118. async afterReadcover(event) {
  119. const result = await this.uploadFilePromisecover(event.file[0].url);
  120. //图片路径
  121. },
  122. // 新增图片
  123. async afterRead(event) {
  124. // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
  125. let Lists = [].concat(event.file)
  126. for (let i = 0; i < Lists.length; i++) {
  127. const result = await this.uploadFilePromise(Lists[i].url)
  128. wx.getImageInfo({
  129. src: Lists[i].url,
  130. success: res => {
  131. }
  132. })
  133. }
  134. },
  135. //上传图片
  136. uploadFilePromisecover(url) {
  137. return new Promise((resolve, reject) => {
  138. let a = uni.uploadFile({
  139. url: 'https://i.ringzle.com/island-cloud-server/oss/file/upload',
  140. filePath: url,
  141. name: 'file',
  142. header: {
  143. token: wx.getStorageSync('access_token')
  144. },
  145. success: (res) => {
  146. let data = JSON.parse(res.data) //最终传给的是字符串,这里需要转换格式
  147. this.cover.push({
  148. url: data.data.url
  149. })
  150. this.covered.push(data.data.url)
  151. this.fromData.cover = this.covered.toString()
  152. console.log(this.covered);
  153. console.log(this.fromData.cover);
  154. resolve(data.data.url)
  155. }
  156. });
  157. })
  158. },
  159. //上传图片
  160. uploadFilePromise(url) {
  161. return new Promise((resolve, reject) => {
  162. let a = uni.uploadFile({
  163. url: 'https://i.ringzle.com/island-cloud-server/oss/file/upload',
  164. filePath: url,
  165. name: 'file',
  166. header: {
  167. token: wx.getStorageSync('access_token')
  168. },
  169. success: (res) => {
  170. let data = JSON.parse(res.data) //最终传给的是字符串,这里需要转换格式
  171. this.introduction.push({
  172. url: data.data.url
  173. })
  174. this.introductioned.push(data.data.url)
  175. this.fromData.introduction = this.introductioned.toString()
  176. console.log(this.introductioned);
  177. console.log(this.fromData.introduction);
  178. resolve(data.data.url)
  179. }
  180. });
  181. })
  182. },
  183. // 图片大小超出最大允许大小
  184. overSize(e) {
  185. uni.$u.toast('上传图片大小不能超过10MB!')
  186. },
  187. }
  188. }
  189. </script>
  190. <style lang="scss">
  191. .uicon-camera-fill {
  192. font-size: 50rpx !important;
  193. }
  194. .btn-btn {
  195. width: 100%;
  196. height: 136rpx;
  197. background-color: #fff;
  198. position: fixed;
  199. bottom: 0;
  200. // margin: 0 auto;
  201. z-index: 999999;
  202. // margin-top: 30rpx;
  203. // margin-left: 30rpx;
  204. .hander-two {
  205. display: flex;
  206. justify-content: space-between;
  207. align-items: center;
  208. margin: 30rpx 0;
  209. .pop-btn-del {
  210. margin: 0 15rpx;
  211. padding: 22rpx 136rpx;
  212. font-size: 32rpx;
  213. color: #111111;
  214. font-weight: Regular;
  215. background-color: #F0F2F5;
  216. border-radius: 50rpx;
  217. }
  218. .pop-btn-add {
  219. border-radius: 50rpx;
  220. margin: 0 15rpx;
  221. background-color: #1372FF;
  222. padding: 22rpx 100rpx;
  223. font-size: 32rpx;
  224. color: #FFFFFF;
  225. font-weight: Regular;
  226. }
  227. }
  228. }
  229. .btn {
  230. margin: 0 auto;
  231. width: 690rpx;
  232. height: 96rpx;
  233. background-color: #1372FF;
  234. color: #fff;
  235. display: flex;
  236. justify-content: center;
  237. align-items: center;
  238. font-size: 34rpx;
  239. border-radius: 48rpx;
  240. }
  241. .uicon-close {
  242. font-size: 30rpx !important;
  243. top: 8rpx !important;
  244. }
  245. .page {
  246. background: #F3F4F4;
  247. padding-bottom: 260rpx;
  248. box-sizing: border-box;
  249. overflow-y: auto;
  250. overflow-x: auto;
  251. }
  252. .body {
  253. padding-top: 20rpx;
  254. padding-left: 30rpx;
  255. padding-right: 30rpx;
  256. }
  257. .typeInfo {
  258. background-color: #fff;
  259. width: 100%;
  260. // height: 145px;
  261. border-radius: 5px;
  262. padding-top: 15px;
  263. padding-left: 7px;
  264. padding-right: 15px;
  265. box-sizing: border-box;
  266. }
  267. .titleInfo {
  268. // margin-top: 30rpx;
  269. margin-left: 20rpx;
  270. margin-bottom: 40rpx;
  271. }
  272. .cellBox {
  273. margin-left: 20rpx;
  274. display: flex;
  275. padding: 20rpx 0 30rpx;
  276. border-bottom: 1rpx solid #E1E1E1;
  277. text {
  278. margin-top: 10rpx;
  279. width: 170rpx;
  280. }
  281. }
  282. .bigRoom {
  283. margin-left: 20rpx;
  284. width: 100%;
  285. height: 102rpx;
  286. display: flex;
  287. // justify-content: center;
  288. align-items: center;
  289. }
  290. .shelves {
  291. width: 695rpx;
  292. height: 102rpx;
  293. background-color: #fff;
  294. margin-top: 20rpx;
  295. border-radius: 10rpx;
  296. display: flex;
  297. justify-content: space-between;
  298. align-items: center;
  299. // padding-left: 30rpx;
  300. // padding-right: 30rpx;
  301. }
  302. .uploadPic {
  303. padding-top: 28rpx;
  304. // width: 690rpx;
  305. // height: 293rpx;
  306. background-color: #fff;
  307. border-radius: 10rpx;
  308. margin-top: 20rpx;
  309. }
  310. .pic {
  311. // margin-left: 30rpx;
  312. // margin-top: 20rpx;
  313. // width: 190rpx;
  314. // height: 120rpx;
  315. margin: 20rpx 26rpx;
  316. padding-bottom: 20rpx;
  317. }
  318. // .custom-upload-button{
  319. // width: 190rpx;
  320. // height: 120rpx;
  321. // }
  322. .priceInfo {
  323. width: 690rpx;
  324. // height: 908rpx;
  325. background-color: #fff;
  326. border-radius: 10rpx;
  327. margin-top: 20rpx;
  328. padding-top: 30rpx;
  329. }
  330. .week {
  331. padding-left: 30rpx;
  332. padding-right: 30rpx;
  333. margin-bottom: 20rpx;
  334. }
  335. .weekend {
  336. display: flex;
  337. justify-content: space-between;
  338. border-bottom: 1rpx solid #E1E1E1;
  339. padding-bottom: 30rpx;
  340. }
  341. .everyDay {
  342. padding-left: 30rpx;
  343. padding-right: 30rpx;
  344. width: 100%;
  345. // background-color: pink;
  346. height: 102rpx;
  347. display: flex;
  348. align-items: center;
  349. }
  350. .days {
  351. display: flex;
  352. align-items: center;
  353. border-bottom: 1rpx solid #E1E1E1;
  354. padding-bottom: 30rpx;
  355. }
  356. .priceBoxWeek {
  357. display: flex;
  358. align-items: center;
  359. padding-left: 30rpx;
  360. padding-right: 30rpx;
  361. }
  362. .weekendBox {
  363. width: 630rpx;
  364. display: flex;
  365. align-items: center;
  366. // margin-right: 90rpx;
  367. // justify-content: space-between;
  368. border-bottom: 1rpx solid #E1E1E1;
  369. height: 102rpx;
  370. overflow: hidden;
  371. box-sizing: border-box;
  372. }
  373. .everyHouseList {
  374. // padding-right: 30rpx;
  375. width: 690rpx;
  376. // height: 908rpx;
  377. background-color: #fff;
  378. border-radius: 10rpx;
  379. margin-top: 20rpx;
  380. // padding-top: 30rpx;
  381. }
  382. .HouseListTitleInfo {
  383. margin-right: 30rpx;
  384. margin-left: 20rpx;
  385. margin-bottom: 40rpx;
  386. display: flex;
  387. justify-content: space-between;
  388. }
  389. .submit {
  390. margin-top: 20rpx;
  391. border-radius: 10rpx;
  392. width: 690rpx;
  393. height: 102rpx;
  394. background-color: #fff;
  395. display: flex;
  396. justify-content: center;
  397. align-items: center;
  398. }
  399. .addSubmit {
  400. width: 100%;
  401. position: fixed;
  402. /* 固定定位 */
  403. bottom: 20rpx;
  404. /* 底部对齐 */
  405. left: 0;
  406. /* 可选:左对齐 */
  407. // width: 690rpx;
  408. /* 可选:宽度为 100% */
  409. height: 96rpx;
  410. margin-left: 30rpx;
  411. // padding-top: 20rpx;
  412. margin-top: 30rpx;
  413. background-color: #1372FF;
  414. border-radius: 48rpx;
  415. }
  416. .uploadPicPic {
  417. position: relative;
  418. top: -96rpx;
  419. }
  420. .u-upload__deletable[data-v-69e2a36e] {
  421. width: 0 !important;
  422. }
  423. </style>