addHours.vue 12 KB

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