addGroupBuying.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. <template>
  2. <view class='content'>
  3. <view class='wrap'>
  4. <u--form :model="form" ref="uForm">
  5. <u-form-item labelWidth='120' labelPosition='left' label="店铺名称">
  6. <view style='text-align:right'>{{form.shopNames}}</view>
  7. </u-form-item>
  8. <u-form-item labelWidth='120' labelPosition='left' label="团购标题">
  9. <u-input inputAlign='right' border='none' placeholder='输入团购标题,不超过20个字' v-model="form.groupTitle" />
  10. </u-form-item>
  11. <u-form-item labelWidth='120' labelPosition='left' label="可供用餐人数">
  12. <view class='flex align-item-center'>
  13. <u-input inputAlign='right' border='none' placeholder='最少人数' v-model="form.leastPeople" />
  14. <view>人~</view>
  15. <u-input inputAlign='right' border='none' placeholder='最多人数' v-model="form.mostPeople" />
  16. </view>
  17. </u-form-item>
  18. <u-form-item labelWidth='120' labelPosition='left' label="下单后随时退单">
  19. <u-radio-group
  20. v-model="form.chargeableFlag"
  21. placement="row">
  22. <u-radio activeColor="#5F7DE9" label="不接受" name='1' ></u-radio>
  23. <u-radio activeColor="#5F7DE9" label="接受" name='0' ></u-radio>
  24. </u-radio-group>
  25. </u-form-item>
  26. <u-form-item labelWidth='140' labelPosition='left' label="活动结束后自动退单">
  27. <u-radio-group
  28. v-model="form.endChargeable"
  29. placement="row">
  30. <u-radio activeColor="#5F7DE9" label="不接受" name='1'></u-radio>
  31. <u-radio activeColor="#5F7DE9" label="接受" name='0'></u-radio>
  32. </u-radio-group>
  33. </u-form-item>
  34. <u-form-item labelWidth='120' labelPosition='left' label="可团购总数量">
  35. <u-input inputAlign='right' border='none' placeholder='输入团购套餐总数' v-model="form.totalQuantity" />
  36. </u-form-item>
  37. <u-form-item labelWidth='120' labelPosition='left' label="单人可团数量">
  38. <u-radio-group
  39. v-model="form.quantityLimited"
  40. placement="row">
  41. <u-radio activeColor="#5F7DE9" label="限量" name='1'></u-radio>
  42. <u-radio activeColor="#5F7DE9" label="不限量" name='0'></u-radio>
  43. </u-radio-group>
  44. </u-form-item>
  45. <u-form-item v-if='form.quantityLimited==1' labelWidth='120' labelPosition='left' label="单人团购上限">
  46. <u-input inputAlign='right' border='none' placeholder='输入单个用户最多可团购的数量' v-model="form.groupLimit" />
  47. </u-form-item>
  48. <u-form-item labelWidth='120' labelPosition='left' label="提前预约时间">
  49. <view class='flex align-item-center'>
  50. <u-input inputAlign='right' border='none' placeholder='提前预约时间' v-model="form.reservationTime" />小时
  51. </view>
  52. </u-form-item>
  53. <u-form-item labelWidth='120' labelPosition='left' label="活动开始日期">
  54. <view style='text-align:right;' @click='selectTime(0)'>{{form.startDate?form.startDate:'活动开始日期'}}<image src="@/static/image/yjt.png" mode=""
  55. style="margin-left:10rpx;width:12rpx;height: 21rpx;"></image></view>
  56. </u-form-item>
  57. <u-form-item labelWidth='120' labelPosition='left' label="活动结束日期">
  58. <view style='text-align:right;' @click='selectTime1(1)'>{{form.endDate?form.endDate:'活动结束日期'}}<image src="@/static/image/yjt.png" mode=""
  59. style="margin-left:10rpx;width:12rpx;height: 21rpx;"></image></view>
  60. </u-form-item>
  61. <u-form-item labelWidth='120' labelPosition='top' label="不可用日期">
  62. <view class='flex'>
  63. <view v-for='item in weekList' class='week_item' :class='item.select?"active":""' @click='selectweek(item)'>{{item.value}}</view>
  64. </view>
  65. </u-form-item>
  66. <u-form-item labelWidth='120' labelPosition='left' label="指定不可用日期">
  67. <view style='text-align:right;' @click='show2 = true'>{{form.unavailableDay?'已选'+form.unavailableDay.length+'天':'已选0天'}}</view>
  68. <!-- <view class='flex align-item-center'>
  69. <u-input inputAlign='right' border='none' placeholder='提前预约时间' v-model="form.unavailableDay" />小时
  70. </view> -->
  71. </u-form-item>
  72. <u-form-item labelWidth='120' labelPosition='left' label="餐位费">
  73. <view class='flex align-item-center'>
  74. <u-input inputAlign='right' border='none' placeholder='输入餐位费' v-model="form.spaceFee" />元/人
  75. </view>
  76. </u-form-item>
  77. <u-form-item labelWidth='120' labelPosition='left' label="商品打包外带">
  78. <u-radio-group
  79. v-model="form.packFlag"
  80. placement="row">
  81. <u-radio activeColor="#5F7DE9" label="不支持" name='1'></u-radio>
  82. <u-radio activeColor="#5F7DE9" label="支持" name='0'></u-radio>
  83. </u-radio-group>
  84. </u-form-item>
  85. <u-form-item labelWidth='120' labelPosition='left' label="包间消费使用">
  86. <u-radio-group
  87. v-model="form.roomUsage"
  88. placement="row">
  89. <u-radio activeColor="#5F7DE9" label="不支持" name='1'></u-radio>
  90. <u-radio activeColor="#5F7DE9" label="支持" name='0'></u-radio>
  91. </u-radio-group>
  92. </u-form-item>
  93. <u-form-item labelWidth='140' labelPosition='left' label="与店内其他优惠共享">
  94. <u-radio-group
  95. v-model="form.discountSharing"
  96. placement="row">
  97. <u-radio activeColor="#5F7DE9" label="不支持" name='1'></u-radio>
  98. <u-radio activeColor="#5F7DE9" label="支持" name='0'></u-radio>
  99. </u-radio-group>
  100. </u-form-item>
  101. <u-form-item labelWidth='120' labelPosition='left' label="免费打包">
  102. <u-radio-group
  103. v-model="form.freePackaging"
  104. placement="row">
  105. <u-radio activeColor="#5F7DE9" label="不支持" name='1'></u-radio>
  106. <u-radio activeColor="#5F7DE9" label="支持" name='0'></u-radio>
  107. </u-radio-group>
  108. </u-form-item>
  109. <u-form-item labelWidth='120' labelPosition='left' label="发票">
  110. <u-radio-group
  111. v-model="form.invoice"
  112. placement="row">
  113. <u-radio activeColor="#5F7DE9" label="不支持" name='1'></u-radio>
  114. <u-radio activeColor="#5F7DE9" label="支持" name='0'></u-radio>
  115. </u-radio-group>
  116. </u-form-item>
  117. </u--form>
  118. <view>备注:如部分菜品因时令或其他不可抗因素导致无法提供,商家可用等价菜品替换,具体事宜与顾客协商决定。</view>
  119. <view class="mercharts_footer">
  120. <button @click='next' class="submit">下一步</button>
  121. </view>
  122. <u-calendar @close='show = false' @confirm="confirm" :show="show"></u-calendar>
  123. <u-calendar :minDate='minDate' @close='show1 = false' @confirm="confirm" :show="show1"></u-calendar>
  124. <u-calendar :show="show2" mode="multiple" monthNum='12' :maxDate='maxDate' @close='show2 = false' @confirm="confirm1"></u-calendar>
  125. </view>
  126. </view>
  127. </template>
  128. <script>
  129. var that
  130. export default {
  131. data() {
  132. return {
  133. value:'',
  134. show:false,
  135. show1:false,
  136. show2:false,
  137. status:'',
  138. minDate:'',
  139. maxDate:'',
  140. sortDate:[],
  141. weekList:[
  142. {value:'周一',select:false},
  143. {value:'周二',select:false},
  144. {value:'周三',select:false},
  145. {value:'周四',select:false},
  146. {value:'周五',select:false},
  147. {value:'周六',select:false},
  148. {value:'周日',select:false}],
  149. form:{
  150. chargeableFlag:"0",
  151. endChargeable:"0",
  152. quantityLimited:"0",
  153. packFlag:"0",
  154. roomUsage:"0",
  155. discountSharing:"0",
  156. freePackaging:"0",
  157. invoice:"0",
  158. },
  159. }
  160. },
  161. onLoad(options) {
  162. console.log(options)
  163. that = this
  164. var date = new Date().toISOString().slice(0, 10)
  165. this.minDate=date
  166. this.form.foodId=options.foodId
  167. this.form.shopNames=options.shopNames
  168. this.getTime()
  169. },
  170. onShow(){
  171. },
  172. methods: {
  173. getTime(){
  174. var time = new Date();
  175. time.setTime(time.getTime());
  176. var s2 = time.getFullYear()+"-" + (time.getMonth()+1) + "-" + time.getDate();
  177. var monthNum=6; //要减的月数(6)自己定义
  178. var dateArr = s2.split('-'); //s2当前时间
  179. var year = dateArr[0]; //获取当前日期的年份
  180. var month = dateArr[1]; //获取当前日期的月份
  181. var day = dateArr[2]; //获取当前日期的日
  182. var days = new Date(year, month, 0);
  183. days = days.getDate(); //获取当前日期中月的天数
  184. var year2 = year;
  185. var month2 = parseInt(month) + monthNum;
  186. if (month2 <=0) {
  187. year2 = parseInt(year2) - parseInt(month2 / 12 == 0 ? 1 : parseInt(month2) / 12);
  188. month2 = 12 - (Math.abs(month2) % 12);
  189. }
  190. var day2 = day;
  191. var days2 = new Date(year2, month2, 0);
  192. days2 = days2.getDate();
  193. if (day2 > days2) {
  194. day2 = days2;
  195. }
  196. if (month2 < 10) {
  197. month2 = '0' + month2;
  198. }
  199. var t2 = year2 + '-' + month2 + '-' + day2;
  200. this.maxDate = t2
  201. console.log(t2)
  202. },
  203. selectweek(item){
  204. console.log(item)
  205. item.select = !item.select
  206. this.$forceUpdate()
  207. var arr = this.weekList.filter((item)=>{return item.select == true})
  208. console.log(arr)
  209. var arr2=[]
  210. for(var i=0;i<arr.length;i++){
  211. arr2.push(arr[i].value)
  212. }
  213. this.form.unavailableDate=arr2.toString()
  214. },
  215. confirm1(e){
  216. console.log(e)
  217. console.log(e.sort( (a, b)=> {return a.localeCompare(b) // 按照升序排列
  218. }))
  219. this.sortDate=e.sort( (a, b)=> {return a.localeCompare(b)})
  220. this.form.unavailableDay=this.sortDate.toString() // 按照升序排列
  221. this.show2 = false
  222. },
  223. confirm(e){
  224. if(this.status==0){
  225. this.form.startDate =e[0]
  226. this.show = false
  227. }else{
  228. this.form.endDate =e[0]
  229. this.show1 = false
  230. }
  231. console.log(e)
  232. },
  233. selectTime(status){
  234. this.status=status
  235. this.show = true
  236. },
  237. selectTime1(status){
  238. this.status=status
  239. this.show1 = true
  240. },
  241. next(){
  242. var time = new Date();
  243. var date=time.getFullYear()+"-" + ((time.getMonth()+1)>=10?(time.getMonth()+1):'0'+(time.getMonth()+1)) + "-" + time.getDate()
  244. var s2 = new Date(date).getTime();
  245. console.log(s2,date,this.form.startDate,new Date(this.form.startDate).getTime(),1111)
  246. if(new Date(this.form.endDate).getTime()==s2){
  247. uni.showToast({
  248. icon: "none",
  249. title: '结束日期不可晚于当天!',
  250. duration: 3000
  251. });
  252. return
  253. }
  254. if(new Date(this.form.startDate).getTime()>new Date(this.form.endDate).getTime()){
  255. uni.showToast({
  256. icon: "none",
  257. title: '开始日期不可晚于结束日期!',
  258. duration: 3000
  259. });
  260. return
  261. }
  262. uni.setStorageSync('groupBuying',JSON.stringify(this.form))
  263. uni.navigateTo({
  264. url:'/pageA/enter/myCateringdustry/addGroupBuyingNext?foodId='+this.form.foodId
  265. })
  266. },
  267. // 删除图片
  268. deletePic(event,status) {
  269. this[`fileList${event.name}`].splice(event.index, 1)
  270. },
  271. // 新增图片
  272. async afterRead(event,status) {
  273. // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
  274. let lists = [].concat(event.file)
  275. let fileListLen = this[`fileList${event.name}`].length
  276. lists.map((item) => {
  277. this[`fileList${event.name}`].push({
  278. ...item,
  279. status: 'uploading',
  280. message: '上传中'
  281. })
  282. })
  283. for (let i = 0; i < lists.length; i++) {
  284. const result = await this.uploadFilePromise(lists[i].url,status)
  285. let item = this[`fileList${event.name}`][fileListLen]
  286. this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
  287. status: 'success',
  288. message: '',
  289. url: result
  290. }))
  291. fileListLen++
  292. console.log(that.form, this[`fileList${event.name}`])
  293. }
  294. },
  295. uploadFilePromise(res,status) {
  296. return new Promise((resolve, reject) => {
  297. uploadImage(res, 'cardImages/',
  298. result => {
  299. that.form.dishImage = result
  300. resolve(res)
  301. }
  302. )
  303. })
  304. },
  305. }
  306. }
  307. </script>
  308. <style lang='scss' scoped>
  309. /deep/.u-radio-group,/deep/.u-radio-group--row {
  310. flex-direction: row-reverse !important;
  311. .u-radio{
  312. margin-left:10rpx;
  313. }
  314. }
  315. .week_item{
  316. border:1px solid #999;
  317. padding: 5rpx 10rpx;
  318. margin: 10rpx;
  319. border-radius: 10rpx;
  320. }
  321. .week_item.active{
  322. background:#5F7DE9;
  323. border: 1px solid #5F7DE9;
  324. color:#fff;
  325. }
  326. </style>