com-price-set.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. <style>
  2. .com-time-select {
  3. width: 760px;
  4. margin-top: 12px;
  5. border: 1px solid #cccccc;
  6. }
  7. .item-box {
  8. display: flex;
  9. }
  10. .top-box {
  11. height: 50px;
  12. border-bottom: 1px solid #cccccc;
  13. }
  14. .bottom-box {
  15. height: 250px;
  16. }
  17. .left-box {
  18. width: 23%;
  19. min-width: 22%;
  20. background-color: #f5f6fa;
  21. border-right: 1px solid #cccccc;
  22. }
  23. .right-box {
  24. width: 77%;
  25. }
  26. .not-scroll {
  27. padding: 0 12px;
  28. display: flex;
  29. justify-content: space-between;
  30. align-items: center;
  31. }
  32. .scroll-box {
  33. overflow-y: scroll;
  34. }
  35. .date-item {
  36. padding: 10px 4px;
  37. text-align: center;
  38. border-bottom: 1px solid #cccccc;
  39. cursor: pointer;
  40. }
  41. .selected {
  42. background-color: #ffffff;
  43. font-weight: bold;
  44. }
  45. .date-item:last-child {
  46. border-bottom: none;
  47. }
  48. .top-right {
  49. display: flex;
  50. justify-content: space-between;
  51. align-items: center;
  52. }
  53. .bottom-right {
  54. }
  55. .top-right-item {
  56. width: 25%;
  57. padding: 0 6px;
  58. border-left: 1px solid #cccccc;
  59. }
  60. .top-right-item:first-child {
  61. border-left: none;
  62. }
  63. .f-between {
  64. display: flex;
  65. justify-content: space-between;
  66. align-items: center;
  67. }
  68. .time-item {
  69. margin: 6px 0;
  70. padding-bottom: 6px;
  71. display: flex;
  72. border-bottom: 1px solid #eeeeee;
  73. }
  74. .time-item:last-child {
  75. border-bottom: none;
  76. }
  77. .bottom-right-item {
  78. width: 25%;
  79. padding: 0 6px;
  80. }
  81. .pop-box {
  82. display: flex;
  83. justify-content: space-between;
  84. align-items: center;
  85. }
  86. </style>
  87. <template id="com-price-set">
  88. <div class="com-time-select">
  89. <div class="item-box top-box">
  90. <div class="left-box not-scroll">
  91. <span>日期</span>
  92. <el-popover placement="top" width="1020" trigger="click" v-model="popover_batch">
  93. <div class="pop-box">
  94. <span>售价(元)</span>
  95. <el-input placeholder="请输入售价" type="number" v-model="unifyPrice" style="width: 200px;"><template slot="append">元</template></el-input>
  96. <span>划线价(元)</span>
  97. <el-input placeholder="请输入划线价" type="number" v-model="unifyLinePrice" style="width: 200px;"><template slot="append">元</template></el-input>
  98. <span>可预约数量</span>
  99. <el-input placeholder="请输入可预约数量" type="number" v-model="unifyReservationNum" style="width: 200px;"></el-input>
  100. <el-button @click="popover_batch = false">取消</el-button>
  101. <el-button type="primary" @click="unifyConfirm">确认</el-button>
  102. </div>
  103. <el-button type="text" slot="reference"><span style="color: #409EFF;">批量设置</span></el-button>
  104. </el-popover>
  105. </div>
  106. <div class="right-box top-right">
  107. <div class="top-right-item">时间段</div>
  108. <div class="top-right-item f-between">
  109. <span>售价(元)</span>
  110. <el-popover placement="top" width="460" trigger="click" v-model="popover_price">
  111. <div class="pop-box">
  112. <span>售价(元)</span>
  113. <el-input placeholder="请输入售价" type="number" v-model="unifyPrice" style="width: 200px;"><template slot="append">元</template></el-input>
  114. <el-button @click="popover_price = false">取消</el-button>
  115. <el-button type="primary" @click="unifyPriceConfirm">确认</el-button>
  116. </div>
  117. <el-button type="text" slot="reference"><i class="el-icon-s-unfold" style="color: #409EFF;font-size: 20px;"></i></el-button>
  118. </el-popover>
  119. </div>
  120. <div class="top-right-item f-between">
  121. <span>划线价(元)</span>
  122. <el-popover placement="top" width="460" trigger="click" v-model="popover_m_price">
  123. <div class="pop-box">
  124. <span>划线价(元)</span>
  125. <el-input placeholder="请输入划线价" type="number" v-model="unifyLinePrice" style="width: 200px;"><template slot="append">元</template></el-input>
  126. <el-button @click="popover_m_price = false">取消</el-button>
  127. <el-button type="primary" @click="unifyLinePriceConfirm">确认</el-button>
  128. </div>
  129. <el-button type="text" slot="reference"><i class="el-icon-s-unfold" style="color: #409EFF;font-size: 20px;"></i></el-button>
  130. </el-popover>
  131. </div>
  132. <div class="top-right-item f-between">
  133. <span>可预约数量</span>
  134. <el-popover placement="top" width="460" trigger="click" v-model="popover_num">
  135. <div class="pop-box">
  136. <span>可预约数量</span>
  137. <el-input placeholder="请输入可预约数量" type="number" v-model="unifyReservationNum" style="width: 200px;"></el-input>
  138. <el-button @click="popover_num = false">取消</el-button>
  139. <el-button type="primary" @click="unifyReservationNumConfirm">确认</el-button>
  140. </div>
  141. <el-button type="text" slot="reference"><i class="el-icon-s-unfold" style="color: #409EFF;font-size: 20px;"></i></el-button>
  142. </el-popover>
  143. </div>
  144. </div>
  145. </div>
  146. <div class="item-box bottom-box">
  147. <div class="left-box scroll-box">
  148. <div v-for="(item,index) in selectedDates" :key="index" class="date-item" :class="item.isSelect ? 'selected' : ''" @click="onDate(index)">{{item.date}}</div>
  149. </div>
  150. <div class="right-box scroll-box">
  151. <div v-for="(item,index) in currentTime.selectTimes" :key="index" class="time-item">
  152. <div class="bottom-right-item">{{item.time}}</div>
  153. <div class="bottom-right-item">
  154. <el-input placeholder="请输入..." type="number" v-model="item.price" clearable @input="onUpdateValue"></el-input>
  155. </div>
  156. <div class="bottom-right-item">
  157. <el-input placeholder="请输入..." type="number" v-model="item.linePrice" clearable @input="onUpdateValue"></el-input>
  158. </div>
  159. <div class="bottom-right-item">
  160. <el-input placeholder="请输入..." type="number" v-model="item.reservationNum" clearable @input="onUpdateValue"></el-input>
  161. </div>
  162. </div>
  163. </div>
  164. </div>
  165. </div>
  166. </template>
  167. <script>
  168. Vue.component('com-price-set', {
  169. template: '#com-price-set',
  170. props: {
  171. dateList: {
  172. type: Array,
  173. default: () => {
  174. return []
  175. }
  176. }
  177. },
  178. data() {
  179. return {
  180. selectedDates: [],
  181. currentTime: {},
  182. unifyReservationNum: 0,//统一可预约数量
  183. unifyPrice: 0,//统一售价
  184. unifyLinePrice: 0,//统一划线价
  185. input: 0,
  186. popover_batch: false,
  187. popover_price: false,
  188. popover_m_price: false,
  189. popover_num: false,
  190. }
  191. },
  192. watch: {
  193. dateList: {
  194. handler(newvalue, oldvalue) {
  195. this.$nextTick(() => {
  196. // this.initData();
  197. });
  198. },
  199. immediate: true,
  200. deep: true
  201. },
  202. },
  203. methods: {
  204. initData(list) {
  205. this.selectedDates = [];
  206. this.selectedDates = JSON.parse(JSON.stringify(list));
  207. console.log('com-price-set initData', this.selectedDates)
  208. this.selectedDates.forEach(item => {
  209. if(!(item.selectTimes && item.selectTimes.length)){
  210. item.selectTimes = [];
  211. item.times.forEach(it => {
  212. item.selectTimes.push({
  213. time: it,
  214. price: 0,
  215. linePrice: 0,
  216. reservationNum: 0
  217. });
  218. });
  219. }else{
  220. let rarr = [];
  221. item.selectTimes.forEach(it => {
  222. if(item.times.indexOf(it.time) > -1){
  223. rarr.push(it);
  224. }
  225. });
  226. item.selectTimes = JSON.parse(JSON.stringify(rarr));
  227. let oldTimes = [];
  228. item.selectTimes.forEach(it => {
  229. oldTimes.push(it.time);
  230. });
  231. for(let i = 0;i < item.times.length;i++){
  232. if(oldTimes.indexOf(item.times[i]) < 0){
  233. item.selectTimes.push({
  234. time: item.times[i],
  235. price: 0,
  236. linePrice: 0,
  237. reservationNum: 0
  238. });
  239. }
  240. }
  241. }
  242. });
  243. let forData = [];
  244. for (let i = 0; i < this.selectedDates.length; i++) {
  245. if (!forData.some(e => e.date == this.selectedDates[i].date)) {
  246. forData.push(this.selectedDates[i]);
  247. }
  248. }
  249. this.selectedDates = JSON.parse(JSON.stringify(forData));
  250. if(this.selectedDates.length){
  251. this.selectedDates.forEach(item => {
  252. item.isSelect = false;
  253. });
  254. this.selectedDates[0].isSelect = true;
  255. this.currentTime = this.selectedDates[0];
  256. this.$forceUpdate();
  257. }
  258. // this.emit()
  259. },
  260. onDate(index) {
  261. this.selectedDates.forEach(item => {
  262. item.isSelect = false;
  263. });
  264. this.selectedDates[index].isSelect = true;
  265. this.currentTime = this.selectedDates[index];
  266. },
  267. unifyConfirm() {
  268. this.selectedDates.forEach(item => {
  269. if(item.isSelect){
  270. item.selectTimes.forEach(it => {
  271. it.price = this.unifyPrice;
  272. it.linePrice = this.unifyLinePrice;
  273. it.reservationNum = this.unifyReservationNum;
  274. });
  275. this.currentTime = item;
  276. this.$forceUpdate();
  277. }
  278. });
  279. this.emit()
  280. this.popover_batch = false
  281. },
  282. unifyPriceConfirm() {
  283. this.selectedDates.forEach(item => {
  284. if(item.isSelect){
  285. item.selectTimes.forEach(it => {
  286. it.price = this.unifyPrice;
  287. });
  288. this.currentTime = item;
  289. this.$forceUpdate();
  290. }
  291. });
  292. this.emit()
  293. this.popover_price = false
  294. },
  295. unifyLinePriceConfirm() {
  296. this.selectedDates.forEach(item => {
  297. if(item.isSelect){
  298. item.selectTimes.forEach(it => {
  299. it.linePrice = this.unifyLinePrice;
  300. });
  301. this.currentTime = item;
  302. this.$forceUpdate();
  303. }
  304. });
  305. this.emit()
  306. this.popover_m_price = false
  307. },
  308. unifyReservationNumConfirm() {
  309. this.selectedDates.forEach(item => {
  310. if(item.isSelect){
  311. item.selectTimes.forEach(it => {
  312. it.reservationNum = this.unifyReservationNum;
  313. });
  314. this.currentTime = item;
  315. this.$forceUpdate();
  316. }
  317. });
  318. this.emit()
  319. this.popover_num = false
  320. },
  321. emit() {
  322. this.$emit("on-update-selected-date", this.selectedDates)
  323. },
  324. onUpdateValue() {
  325. this.$forceUpdate()
  326. this.emit()
  327. }
  328. }
  329. })
  330. </script>