addHours.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. <template>
  2. <view>
  3. <cu-custom bgColor="bg-fff" :isBack="true">
  4. <block slot="content">添加营业时间</block>
  5. </cu-custom>
  6. <view class="tab-top bg-fff">
  7. <view class="title ">营业日</view>
  8. <view style="padding-bottom:20upx;border-bottom: 1px solid #EEEEEE;overflow: hidden;">
  9. <view v-for="(tag, index) in tags" :key="index" class="tag-type" :class="{
  10. 'disable-background': isDisable(tag),
  11. 'selected-background': isSelected(tag)
  12. }" :style="tag == '周四' || tag == '整周' ? 'margin-right:0' : ''" @click="toggleSelection(tag)">
  13. {{ tag }}
  14. </view>
  15. </view>
  16. <view class="" style="display: flex;justify-content: space-between;align-items: center;">
  17. <view style="padding-top:18upx">营业时段</view>
  18. <view @click="add()" class="add-style">添加</view>
  19. </view>
  20. <view class="cu-form-group" style="border-bottom: 1upx solid #eee;margin:0" v-if="timeType.length > 0">
  21. <input v-model="time" name="input"></input>
  22. </view>
  23. <view style="border-bottom: 1upx solid #eee;margin:0" v-for="(tim, timInd) in timeArr" :key="timInd" v-else>
  24. <view class="cu-form-group" style="margin:0" v-if="timInd == 0 && timeArr.length < 3">
  25. <input placeholder="添加营业时段(1/3)" v-model="tim.value" name="input" @click="open(timInd)" disabled="true"></input>
  26. <text class='cuIcon-right' style="color: #C7C6CA ;" @click="open(timInd)"></text>
  27. </view>
  28. <view v-else>
  29. <uni-swipe-action>
  30. <uni-swipe-action-item :right-options="options2" :show="timInd.show" :auto-close="false">
  31. <view class="cu-form-group" style="margin:0">
  32. <input :placeholder='"添加营业时段(" + (timInd + 1) + "/3)"' v-model="tim.value" name="input" disabled="true"
  33. @click="open(timInd)"></input>
  34. <text class='cuIcon-right' style="color: #C7C6CA ;" @click="open(timInd)"></text>
  35. </view>
  36. <template v-slot:right>
  37. <view>
  38. <view @click="bindClick" class="add-style" style="background: #FF6067;">删除</view>
  39. </view>
  40. </template>
  41. </uni-swipe-action-item>
  42. </uni-swipe-action>
  43. </view>
  44. </view>
  45. <view class="flex align-center justify-between date24">
  46. <view>24小时营业</view>
  47. <uni-data-checkbox multiple :localdata="sex" v-model="timeType"
  48. active-color="#FF852D "></uni-data-checkbox>
  49. </view>
  50. </view>
  51. <rangTime ref="rangTime" :mode="mode" @onSubmit="onEndTimeChange" />
  52. <view class="padding flex flex-direction sub-bottom">
  53. <button class="cu-btn bg-blue round " @click="sumbit">提交</button>
  54. </view>
  55. </view>
  56. </template>
  57. <script>
  58. import rangTime from '../../components/dengrq-datetime-picker/dateSelector/index.vue'
  59. import { USER_INFO } from "@/common/util/constants"
  60. export default {
  61. components: {
  62. rangTime
  63. },
  64. data() {
  65. return {
  66. time: '00:00-24:00',
  67. options2: [{
  68. text: '删除',
  69. style: {
  70. backgroundColor: '#FF6067',
  71. fontSize: '28upx',
  72. }
  73. },
  74. ],
  75. timeArr: [{
  76. value: '',
  77. show: false,
  78. }],
  79. timeType: [],
  80. sex: [{
  81. text: '',
  82. value: 1
  83. }],
  84. mode: 6,
  85. corporateName: '',
  86. tags: ['周一', '周二', '周三', '周四', '周五', '周六', '周日', '整周'], // 标签数组
  87. selectedIndices: [], // 用于存储被选中的标签索引
  88. disableIndices: [], // 用于存储被禁用的标签索引
  89. timeIndex: '',
  90. merchantId: '',
  91. arrData:[],//传参进来的数组
  92. }
  93. },
  94. async onLoad(data) {
  95. this.merchantId = uni.getStorageSync(USER_INFO).merchantId;
  96. if (data.params) {
  97. let obj = JSON.parse(decodeURIComponent(data.params));
  98. this.arrData=obj
  99. if ( obj.arr.length>0) {
  100. this.otherProhibitions(obj.arr,obj.index)
  101. obj.arr.forEach((val, index1) => {
  102. if (index1 == obj.index) {
  103. this.selectedIndices = val.period ? val.period.split('、').filter(id => id !== '') : []
  104. }
  105. this.timeType = val.timeType == '1' ? [1] : []
  106. if (val.middleTime) {
  107. this.timeArr = [
  108. {
  109. value: val.middleTime,
  110. show: false,
  111. }
  112. ]
  113. }
  114. if (val.beginTime) {
  115. this.timeArr = [
  116. {
  117. value: val.middleTime,
  118. show: false,
  119. },
  120. {
  121. value: val.beginTime,
  122. show: false,
  123. }
  124. ]
  125. }
  126. if (val.endTime) {
  127. this.timeArr = [
  128. {
  129. value: val.middleTime,
  130. show: false,
  131. },
  132. {
  133. value: val.beginTime,
  134. show: false,
  135. },
  136. {
  137. value: val.endTime,
  138. show: false,
  139. }
  140. ]
  141. }
  142. })
  143. }
  144. }
  145. },
  146. methods: {
  147. open(index) {
  148. this.timeIndex = index
  149. this.$refs.rangTime.open()
  150. },
  151. // 选择整周其他所有禁用
  152. otherProhibitions(arr,index){
  153. if(arr.length==2){
  154. let adjacentObj=arr.find((_, i) => i !== index)
  155. this.disableIndices = adjacentObj.period? adjacentObj.period.split('、').filter(id => id !== ''):
  156. adjacentObj.period==['整周']?this.tags: []
  157. }
  158. else if(arr.length==1){
  159. this.disableIndices = arr[0].period=='整周'?
  160. this.tags:arr[0].period?
  161. arr[0].period.split('、').filter(id => id !== '')
  162. : []
  163. console.log(this.disableIndices,22222222);
  164. }
  165. else{
  166. this.disableIndices=[]
  167. }
  168. },
  169. bindClick(e) {
  170. this.timeArr.splice(this.timeIndex, 1);
  171. },
  172. // 检查一个标签是否被选中
  173. isSelected(index) {
  174. return this.selectedIndices.includes(index);
  175. },
  176. // 检查一个标签是否被禁用
  177. isDisable(index) {
  178. return this.disableIndices.includes(index);
  179. },
  180. // 切换标签的选中状态
  181. toggleSelection(index) {
  182. const indexIndex = this.selectedIndices.indexOf(index);
  183. console.log(indexIndex,89999);
  184. if (indexIndex > -1) {
  185. if (index == '整周') {
  186. if(this.arrData.arr.length==1 && this.arrData.arr[0].period=='整周'){
  187. this.disableIndices=[];
  188. }
  189. else{
  190. this.otherProhibitions(this.arrData.arr,this.arrData.index)
  191. }
  192. }
  193. // 如果标签已经被选中,则移除它
  194. this.selectedIndices.splice(indexIndex, 1);
  195. } else {
  196. if (!this.disableIndices.includes(index)) {
  197. if (index == '整周') {
  198. this.selectedIndices = []
  199. this.disableIndices.push('周一', '周二', '周三', '周四', '周五', '周六', '周日');
  200. }
  201. // 如果标签没有被选中,则添加它
  202. this.selectedIndices.push(index);
  203. }
  204. }
  205. },
  206. add() {
  207. if( this.timeArr.length<3){
  208. this.timeArr.push({
  209. value: '',
  210. show: false,
  211. })
  212. }
  213. },
  214. onEndTimeChange(val) {
  215. this.timeArr[this.timeIndex].value = val.startDate + '-' + val.endDate
  216. this.$refs.rangTime.startDate = ''
  217. this.$refs.rangTime.endDate = ''
  218. },
  219. sumbit() {
  220. let data = {
  221. merchantId: this.merchantId,
  222. timeType: this.timeType.length > 0 ? 1 : 2,
  223. period: this.selectedIndices.length > 0 ? this.selectedIndices.join('、') : null,
  224. middleTime: this.timeArr.length >= 1 ? this.timeArr[0].value : null,
  225. beginTime: this.timeArr.length >= 2 ? this.timeArr[1].value : null,
  226. endTime: this.timeArr.length >= 3 ? this.timeArr[2].value : null,
  227. id:this.arrData.index==1 || this.arrData.index==0?this.arrData.arr[this.arrData.index].id:null
  228. }
  229. if(this.selectedIndices.length==0){
  230. this.$tip.toast('请选择营业日');
  231. return
  232. }
  233. if(this.timeArr.length==0 && this.timeType.length==0){
  234. this.$tip.toast('请选择营业s时段');
  235. return
  236. }
  237. let interfaceData = data.id ? "/merchant/localMerchantTime/edit" : "/merchant/localMerchantTime/add"
  238. this.$http.post(interfaceData, data).then(res => {
  239. if (res.data.success) {
  240. this.$tip.success(res.data.result || '成功')
  241. uni.navigateBack({
  242. delta: 1, // 返回的页面数,默认为1
  243. success: () => {
  244. const pages = getCurrentPages();
  245. pages[pages.length-1].$vm.$forceUpdate();
  246. }
  247. })
  248. }
  249. else {
  250. this.$tip.error(res.data.message);
  251. }
  252. })
  253. },
  254. }
  255. }
  256. </script>
  257. <style scoped lang="scss">
  258. page {
  259. background: #F8F8FA;
  260. }
  261. .tab-top {
  262. margin: 24upx 30upx;
  263. padding: 14upx 18upx;
  264. }
  265. .tag-type {
  266. // display: inline-block;
  267. // display: flex;
  268. float: left;
  269. font-size: 26upx;
  270. width: 146upx;
  271. height: 54upx;
  272. color: #333333;
  273. margin: 18upx 23upx 0 0;
  274. border-radius: 4px 4px 4px 4px;
  275. border: 1px solid #C2C2C2;
  276. text-align: center;
  277. line-height: 54upx;
  278. }
  279. .disable-background {
  280. background: #F2F3F5;
  281. border: 1px solid #D2D9DC;
  282. color: #C0C0C0;
  283. }
  284. .selected-background {
  285. color: #2983EC;
  286. position: relative;
  287. background: rgba(68, 154, 255, 0.1);
  288. border: 1px solid #449AFF;
  289. }
  290. .selected-background ::after {
  291. content: '';
  292. position: absolute;
  293. top: -1px;
  294. right: -1px;
  295. width: 22upx;
  296. height: 22upx;
  297. background-image: url('/static/store/xuanzhong.png');
  298. background-size: cover;
  299. background-repeat: no-repeat;
  300. border-radius: 0 5px 0 0;
  301. }
  302. .sub-bottom {
  303. position: fixed;
  304. width: 100%;
  305. bottom: 0;
  306. background: #FFFFFF;
  307. border-top: 1px solid #EEEEEE;
  308. }
  309. .add-style {
  310. padding: 0 30upx;
  311. background: #449AFF;
  312. color: #fff;
  313. line-height: 58upx;
  314. margin-top: 22upx;
  315. border-radius: 4px 4px 4px 4px;
  316. }
  317. .date24 {
  318. line-height: 80upx;
  319. ::v-deep .uni-data-checklist {
  320. flex: none;
  321. .checklist-group .checklist-box {
  322. margin-right: 0;
  323. }
  324. }
  325. }
  326. </style>