xcPriceCalendar.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. <template>
  2. <el-dialog
  3. :visible.sync="visible"
  4. title="价格方案"
  5. width="780px"
  6. append-to-body
  7. @close="handleCancel"
  8. >
  9. <div
  10. class="wrap"
  11. v-loading="loading">
  12. <div>
  13. <div class="block-title">
  14. 日期类型
  15. </div>
  16. <!-- <el-input
  17. placeholder="请输入内容"
  18. v-model="basic_price"
  19. style="width: 160px">
  20. </el-input> -->
  21. <el-select
  22. v-model="form.dateType">
  23. <el-option
  24. v-for="item in dateTypes"
  25. :key="item.value"
  26. :label="item.key"
  27. :value="item.value"></el-option>
  28. </el-select>
  29. <template v-if="form.dateType==='DATE_NOT_REQUIRED'">
  30. 卖价:
  31. <el-input-number
  32. label="卖价"
  33. placeholder="卖价"
  34. class="priceInput"
  35. :precision="2"
  36. v-model="form.prices[0].salePrice"
  37. />
  38. 结算价:
  39. <el-input-number
  40. placeholder="结算价"
  41. class="priceInput"
  42. :precision="2"
  43. v-model="form.prices[0].costPrice"
  44. />
  45. </template>
  46. </div>
  47. <div v-if="form.dateType==='DATE_REQUIRED'">
  48. <div
  49. class="block-title"
  50. >
  51. 日期段价格(时间不可重叠)
  52. <el-button
  53. class="addBtn"
  54. type="primary"
  55. icon="el-icon-plus"
  56. @click="handleAdd"
  57. size="small"
  58. >
  59. 新增
  60. </el-button>
  61. </div>
  62. <div
  63. class="noData"
  64. v-if="priceList.length===0"
  65. >
  66. 暂无
  67. </div>
  68. <ul class="priceList">
  69. <li
  70. v-for="(item,index) in priceList"
  71. :key="index"
  72. >
  73. <el-date-picker
  74. class="calendarPicker"
  75. type="daterange"
  76. v-model="item.dateRange"
  77. @change="handleChange($event,item)"
  78. />
  79. <el-input-number
  80. placeholder="卖价"
  81. class="priceInput"
  82. :controls="false"
  83. :precision="2"
  84. v-model="item.salePrice"
  85. />
  86. <el-input-number
  87. placeholder="结算价"
  88. class="priceInput"
  89. :controls="false"
  90. :precision="2"
  91. v-model="item.costPrice"
  92. />
  93. <el-button
  94. type="danger"
  95. icon="el-icon-close"
  96. size="small"
  97. @click="handleDelete(index)"
  98. ></el-button>
  99. </li>
  100. </ul>
  101. </div>
  102. <div
  103. class="btn-wrap"
  104. slot="footer">
  105. <el-button
  106. size="small"
  107. @click="visible=false">
  108. 取 消
  109. </el-button>
  110. <el-button
  111. :loading="confirmLoading"
  112. size="small"
  113. type="primary"
  114. @click="handleOk">
  115. 保 存
  116. </el-button>
  117. </div>
  118. </div>
  119. </el-dialog>
  120. </template>
  121. <script>
  122. import moment from 'moment'
  123. import { getPricePlan, syncDatePriceModify } from '@/api/otaTicketSale'
  124. const stragegiesMap = {
  125. PERIOD: '日期段价格',
  126. WEEKDAY: '周价格',
  127. BASIC: '日常价格'
  128. }
  129. export default {
  130. data () {
  131. return {
  132. dateTypes:
  133. [{ key: '指定日期', value: 'DATE_REQUIRED' },
  134. {key: '无需指定日期', value: 'DATE_NOT_REQUIRED'}
  135. ],
  136. stragegiesMap,
  137. pricecode: '',
  138. loading: false,
  139. visible: false,
  140. confirmLoading: false,
  141. basic_price: '',
  142. priceList: [],
  143. form: {
  144. dateType: 'DATE_NOT_REQUIRED',
  145. prices: [
  146. {
  147. costPrice: 0.00,
  148. salePrice: 0.00
  149. }
  150. ]
  151. }
  152. }
  153. },
  154. methods: {
  155. moment,
  156. show (id) {
  157. Object.assign(this.$data, this.$options.data())
  158. this.visible = true
  159. this.pricecode = id
  160. this.getPricePlan()
  161. },
  162. getPricePlan (e) {
  163. let params = { 'pricecode': this.pricecode }
  164. this.loading = true
  165. getPricePlan(params).then(res => {
  166. try {
  167. let basicPrice = res.find(v => v.type === 'basic')
  168. basicPrice && (this.basic_price = basicPrice.price_content)
  169. let priceList = res.find(v => v.type === 'period')
  170. priceList && (priceList = JSON.parse(priceList.price_content))
  171. priceList && priceList.forEach(item => {
  172. item.dateRange = [new Date(item.start), new Date(item.end)]
  173. })
  174. this.priceList = priceList || []
  175. } catch (e) {
  176. console.log(e)
  177. }
  178. }).finally(() => {
  179. this.loading = false
  180. })
  181. },
  182. handleCancel () {
  183. this.visible = false
  184. },
  185. handleChange (event, item) {
  186. this.$set(item, 'start', moment(event[0]).format('YYYY-MM-DD'))
  187. this.$set(item, 'end', moment(event[1]).format('YYYY-MM-DD'))
  188. },
  189. handleDelete (index) {
  190. this.$confirm('确定删除吗', '提示', {
  191. confirmButtonText: '确定',
  192. cancelButtonText: '取消',
  193. type: 'warning'
  194. }).then(() => {
  195. this.priceList.splice(index, 1)
  196. }).catch(() => {})
  197. },
  198. handleAdd () {
  199. let lastPrice
  200. if (this.priceList.length > 0) {
  201. lastPrice = JSON.parse(JSON.stringify(this.priceList[this.priceList.length - 1]))
  202. } else {
  203. lastPrice = { start: new Date(), end: new Date(), price: '' }
  204. }
  205. lastPrice.dateRange = [moment(lastPrice.start), moment(lastPrice.end)]
  206. this.priceList.push({
  207. ...lastPrice,
  208. isEdit: true
  209. })
  210. },
  211. setDate () {
  212. const dateList = []
  213. console.log('%c [ this.priceList ]-220', 'font-size:13px; background:pink; color:#bf2c9f;', this.priceList)
  214. this.priceList.forEach(item => {
  215. let startDate = item.start
  216. console.log('%c [ startDate ]-223', 'font-size:13px; background:pink; color:#bf2c9f;', startDate)
  217. let period = moment(item.end, 'YYYY-MM-DD').diff(item.start, 'days') + 1
  218. console.log('%c [ period ]-224', 'font-size:13px; background:pink; color:#bf2c9f;', period)
  219. for (let i = 0; i < period; i++) {
  220. dateList.push({
  221. date: moment(startDate, 'YYYY-MM-DD').add(i, 'days').format('YYYY-MM-DD'),
  222. costPrice: item.costPrice,
  223. salePrice: item.salePrice
  224. })
  225. }
  226. })
  227. this.form.prices = dateList
  228. console.log('%c [ dateList ]-233', 'font-size:13px; background:pink; color:#bf2c9f;', dateList)
  229. },
  230. handleOk () {
  231. this.confirmLoading = true
  232. if (this.form.dateType === 'DATE_REQUIRED') {
  233. this.setDate()
  234. }
  235. // if (this.form.dateType === 'DATE_NOT_REQUIRED') {
  236. // this.form.prices[0].costPrice = this.form.prices[0].costPrice
  237. // this.form.prices[0].salePrice = this.form.prices[0].salePrice
  238. // }
  239. // let params = {}
  240. // params = JSON.parse(JSON.stringify(this.form))
  241. this.form.supplierOptionId = this.pricecode + ''
  242. console.log('%c [ this.form ]-248', 'font-size:13px; background:pink; color:#bf2c9f;', this.form)
  243. syncDatePriceModify(this.form).then(res => {
  244. this.$message.success('设置成功')
  245. this.handleCancel()
  246. }).finally(() => {
  247. this.confirmLoading = false
  248. })
  249. }
  250. }
  251. }
  252. </script>
  253. <style lang="scss" scoped>
  254. .wrap{
  255. padding: 20px;
  256. }
  257. .btn-wrap{
  258. text-align: right; margin-top: 20px;
  259. }
  260. .priceList {
  261. font-variant: tabular-nums;
  262. li {
  263. margin-bottom: 15px;
  264. }
  265. .calendarTxt {
  266. display: inline-block; width: 332px; box-sizing: border-box; padding-right: 30px;margin-right: 20px;text-align: center;
  267. span {
  268. display: inline-block; width: 135px;
  269. }
  270. }
  271. .priceTxt {
  272. display: inline-block; width: 200px; box-sizing: border-box; padding-left: 10px;margin-right: 20px;
  273. span {
  274. margin-right: 5px;
  275. }
  276. }
  277. .calendarPicker {
  278. margin-right: 20px;
  279. }
  280. .priceInput {
  281. display: inline-block; width: 100px; margin-right: 20px;
  282. }
  283. }
  284. .weekWrap {
  285. display: flex; justify-content: space-between;
  286. .weekItem{
  287. label{
  288. display: block; text-align: center; margin-bottom: 5px; font-weight: bold;
  289. }
  290. }
  291. .weekItem + .weekItem {
  292. margin-left: 10px;
  293. }
  294. .priceTxt{
  295. width: 88px; padding: 0 11px; display: inline-block;
  296. i{
  297. font-style: normal;
  298. }
  299. }
  300. }
  301. .addBtn {
  302. float: right; margin-bottom: 5px;
  303. }
  304. .noData {padding: 10px;
  305. text-align: center; border: 1px dashed #ddd;
  306. }
  307. </style>