addCommodity.vue 12 KB

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