addCommodity.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  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.fromData.status = status
  110. this.$api.post('/merchant/hotel/repast', this.fromData).then(res => {
  111. console.log(res.data);
  112. if (res.data.code == 0) {
  113. if (status == 0) {
  114. this.$showToast('保存成功');
  115. setTimeout(() => {
  116. uni.redirectTo({
  117. url: '/pages/HotelMerchandise/index'
  118. })
  119. // uni.navigateBack(1)
  120. }, 1000);
  121. } else {
  122. this.$showToast('上架成功');
  123. setTimeout(() => {
  124. uni.redirectTo({
  125. url: '/pages/HotelMerchandise/index'
  126. })
  127. // uni.navigateBack(1)
  128. }, 1000);
  129. }
  130. } else this.$showToast(res.data.msg);
  131. })
  132. },
  133. // 删除图片
  134. deletePic(event) {
  135. this.introduction.splice(event.index, 1)
  136. },
  137. // 新增图片
  138. async afterReadcover(event) {
  139. const result = await this.uploadFilePromisecover(event.file[0].url);
  140. //图片路径
  141. },
  142. // 新增图片
  143. async afterRead(event) {
  144. // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
  145. let Lists = [].concat(event.file)
  146. for (let i = 0; i < Lists.length; i++) {
  147. const result = await this.uploadFilePromise(Lists[i].url)
  148. wx.getImageInfo({
  149. src: Lists[i].url,
  150. success: res => {
  151. }
  152. })
  153. }
  154. },
  155. //上传图片
  156. uploadFilePromisecover(url) {
  157. return new Promise((resolve, reject) => {
  158. let a = uni.uploadFile({
  159. url: 'https://i.ringzle.com/island-cloud-server/oss/file/upload',
  160. filePath: url,
  161. name: 'file',
  162. header: {
  163. token: wx.getStorageSync('access_token')
  164. },
  165. success: (res) => {
  166. let data = JSON.parse(res.data) //最终传给的是字符串,这里需要转换格式
  167. this.cover.push({
  168. url: data.data.url
  169. })
  170. this.covered.push(data.data.url)
  171. this.fromData.cover = this.covered.toString()
  172. console.log(this.covered);
  173. console.log(this.fromData.cover);
  174. resolve(data.data.url)
  175. }
  176. });
  177. })
  178. },
  179. //上传图片
  180. uploadFilePromise(url) {
  181. return new Promise((resolve, reject) => {
  182. let a = uni.uploadFile({
  183. url: 'https://i.ringzle.com/island-cloud-server/oss/file/upload',
  184. filePath: url,
  185. name: 'file',
  186. header: {
  187. token: wx.getStorageSync('access_token')
  188. },
  189. success: (res) => {
  190. let data = JSON.parse(res.data) //最终传给的是字符串,这里需要转换格式
  191. this.introduction.push({
  192. url: data.data.url
  193. })
  194. this.introductioned.push(data.data.url)
  195. this.fromData.introduction = this.introductioned.toString()
  196. console.log(this.introductioned);
  197. console.log(this.fromData.introduction);
  198. resolve(data.data.url)
  199. }
  200. });
  201. })
  202. },
  203. // 图片大小超出最大允许大小
  204. overSize(e) {
  205. uni.$u.toast('上传图片大小不能超过10MB!')
  206. },
  207. }
  208. }
  209. </script>
  210. <style lang="scss">
  211. .uicon-camera-fill {
  212. font-size: 50rpx !important;
  213. }
  214. .btn-btn {
  215. width: 100%;
  216. height: 136rpx;
  217. background-color: #fff;
  218. position: fixed;
  219. bottom: 0;
  220. // margin: 0 auto;
  221. z-index: 999999;
  222. // margin-top: 30rpx;
  223. // margin-left: 30rpx;
  224. .hander-two {
  225. display: flex;
  226. justify-content: space-between;
  227. align-items: center;
  228. margin: 30rpx 0;
  229. .pop-btn-del {
  230. margin: 0 15rpx;
  231. padding: 22rpx 136rpx;
  232. font-size: 32rpx;
  233. color: #111111;
  234. font-weight: Regular;
  235. background-color: #F0F2F5;
  236. border-radius: 50rpx;
  237. }
  238. .pop-btn-add {
  239. border-radius: 50rpx;
  240. margin: 0 15rpx;
  241. background-color: #1372FF;
  242. padding: 22rpx 100rpx;
  243. font-size: 32rpx;
  244. color: #FFFFFF;
  245. font-weight: Regular;
  246. }
  247. }
  248. }
  249. .btn {
  250. margin: 0 auto;
  251. width: 690rpx;
  252. height: 96rpx;
  253. background-color: #1372FF;
  254. color: #fff;
  255. display: flex;
  256. justify-content: center;
  257. align-items: center;
  258. font-size: 34rpx;
  259. border-radius: 48rpx;
  260. }
  261. .uicon-close {
  262. font-size: 30rpx !important;
  263. top: 8rpx !important;
  264. }
  265. .page {
  266. background: #F3F4F4;
  267. padding-bottom: 260rpx;
  268. box-sizing: border-box;
  269. overflow-y: auto;
  270. overflow-x: auto;
  271. }
  272. .body {
  273. padding-top: 20rpx;
  274. padding-left: 30rpx;
  275. padding-right: 30rpx;
  276. }
  277. .typeInfo {
  278. background-color: #fff;
  279. width: 100%;
  280. // height: 145px;
  281. border-radius: 5px;
  282. padding-top: 15px;
  283. padding-left: 7px;
  284. padding-right: 15px;
  285. box-sizing: border-box;
  286. }
  287. .titleInfo {
  288. // margin-top: 30rpx;
  289. margin-left: 20rpx;
  290. margin-bottom: 40rpx;
  291. }
  292. .cellBox {
  293. margin-left: 20rpx;
  294. display: flex;
  295. padding: 20rpx 0 30rpx;
  296. border-bottom: 1rpx solid #E1E1E1;
  297. text {
  298. margin-top: 10rpx;
  299. width: 170rpx;
  300. }
  301. }
  302. .bigRoom {
  303. margin-left: 20rpx;
  304. width: 100%;
  305. height: 102rpx;
  306. display: flex;
  307. // justify-content: center;
  308. align-items: center;
  309. }
  310. .shelves {
  311. width: 695rpx;
  312. height: 102rpx;
  313. background-color: #fff;
  314. margin-top: 20rpx;
  315. border-radius: 10rpx;
  316. display: flex;
  317. justify-content: space-between;
  318. align-items: center;
  319. // padding-left: 30rpx;
  320. // padding-right: 30rpx;
  321. }
  322. .uploadPic {
  323. padding-top: 28rpx;
  324. // width: 690rpx;
  325. // height: 293rpx;
  326. background-color: #fff;
  327. border-radius: 10rpx;
  328. margin-top: 20rpx;
  329. }
  330. .pic {
  331. // margin-left: 30rpx;
  332. // margin-top: 20rpx;
  333. // width: 190rpx;
  334. // height: 120rpx;
  335. margin: 20rpx 26rpx;
  336. padding-bottom: 20rpx;
  337. }
  338. // .custom-upload-button{
  339. // width: 190rpx;
  340. // height: 120rpx;
  341. // }
  342. .priceInfo {
  343. width: 690rpx;
  344. // height: 908rpx;
  345. background-color: #fff;
  346. border-radius: 10rpx;
  347. margin-top: 20rpx;
  348. padding-top: 30rpx;
  349. }
  350. .week {
  351. padding-left: 30rpx;
  352. padding-right: 30rpx;
  353. margin-bottom: 20rpx;
  354. }
  355. .weekend {
  356. display: flex;
  357. justify-content: space-between;
  358. border-bottom: 1rpx solid #E1E1E1;
  359. padding-bottom: 30rpx;
  360. }
  361. .everyDay {
  362. padding-left: 30rpx;
  363. padding-right: 30rpx;
  364. width: 100%;
  365. // background-color: pink;
  366. height: 102rpx;
  367. display: flex;
  368. align-items: center;
  369. }
  370. .days {
  371. display: flex;
  372. align-items: center;
  373. border-bottom: 1rpx solid #E1E1E1;
  374. padding-bottom: 30rpx;
  375. }
  376. .priceBoxWeek {
  377. display: flex;
  378. align-items: center;
  379. padding-left: 30rpx;
  380. padding-right: 30rpx;
  381. }
  382. .weekendBox {
  383. width: 630rpx;
  384. display: flex;
  385. align-items: center;
  386. // margin-right: 90rpx;
  387. // justify-content: space-between;
  388. border-bottom: 1rpx solid #E1E1E1;
  389. height: 102rpx;
  390. overflow: hidden;
  391. box-sizing: border-box;
  392. }
  393. .everyHouseList {
  394. // padding-right: 30rpx;
  395. width: 690rpx;
  396. // height: 908rpx;
  397. background-color: #fff;
  398. border-radius: 10rpx;
  399. margin-top: 20rpx;
  400. // padding-top: 30rpx;
  401. }
  402. .HouseListTitleInfo {
  403. margin-right: 30rpx;
  404. margin-left: 20rpx;
  405. margin-bottom: 40rpx;
  406. display: flex;
  407. justify-content: space-between;
  408. }
  409. .submit {
  410. margin-top: 20rpx;
  411. border-radius: 10rpx;
  412. width: 690rpx;
  413. height: 102rpx;
  414. background-color: #fff;
  415. display: flex;
  416. justify-content: center;
  417. align-items: center;
  418. }
  419. .addSubmit {
  420. width: 100%;
  421. position: fixed;
  422. /* 固定定位 */
  423. bottom: 20rpx;
  424. /* 底部对齐 */
  425. left: 0;
  426. /* 可选:左对齐 */
  427. // width: 690rpx;
  428. /* 可选:宽度为 100% */
  429. height: 96rpx;
  430. margin-left: 30rpx;
  431. // padding-top: 20rpx;
  432. margin-top: 30rpx;
  433. background-color: #1372FF;
  434. border-radius: 48rpx;
  435. }
  436. .uploadPicPic {
  437. position: relative;
  438. top: -96rpx;
  439. }
  440. .u-upload__deletable[data-v-69e2a36e] {
  441. width: 0 !important;
  442. }
  443. </style>