dataEdit.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. <!--
  2. * @Description: 新增/编辑弹框
  3. * @Author: Sugar.
  4. * @Date: 2023-11-24 13:55:00
  5. * @LastEditors: Sugar.
  6. * @LastEditTime: 2023-11-24 13:55:00
  7. * @FilePath: \cattle_webui\src\views\otaMr\dialog\dataEdit.vue
  8. * @Copyright: Copyright (c) 2016~2023 by Sugar., All Rights Reserved.
  9. -->
  10. <template>
  11. <el-dialog
  12. :title="title"
  13. :visible.sync="open"
  14. width="70vw"
  15. append-to-body
  16. :close-on-click-modal="false"
  17. @close="cancel"
  18. >
  19. <div class="dialog">
  20. <div>
  21. <el-form :model="form" ref="form" size="small" :rules="rules" :inline="true" label-width="100px">
  22. <el-form-item label="门店POIID" prop="poiId">
  23. <el-input
  24. v-model="form.poiId"
  25. placeholder="请输入门店POIID"
  26. clearable
  27. style="width: 240px"
  28. @keyup.enter.native="handleQuery"
  29. />
  30. </el-form-item>
  31. <el-form-item label="商品类目ID" prop="categoryId">
  32. <el-select
  33. v-model="form.categoryId"
  34. placeholder="商品类目ID"
  35. clearable
  36. style="width: 240px"
  37. >
  38. <el-option
  39. v-for="dict in dict.type.tiktok_category"
  40. :key="dict.value"
  41. :label="dict.label"
  42. :value="dict.value"
  43. />
  44. </el-select>
  45. </el-form-item>
  46. <el-form-item label="投放渠道" prop="showChannel">
  47. <el-select
  48. v-model="form.showChannel"
  49. placeholder="投放渠道"
  50. clearable
  51. style="width: 240px"
  52. >
  53. <el-option
  54. v-for="dict in dict.type.tiktok_showChannel"
  55. :key="dict.value"
  56. :label="dict.label"
  57. :value="dict.value"
  58. />
  59. </el-select>
  60. </el-form-item>
  61. </el-form>
  62. </div>
  63. <el-table
  64. row-key="tableId"
  65. ref="tables"
  66. v-loading="loading"
  67. :data="goodsList"
  68. border
  69. @selection-change="handleSelectionChange">
  70. <el-table-column type="selection" width="55"></el-table-column>
  71. <el-table-column label="序号" align="center" type="index" width="50"></el-table-column>
  72. <el-table-column label="座位类型" align="center" prop="priceName" />
  73. <el-table-column label="开始时间" align="center" prop="timeStart" />
  74. <el-table-column label="结束时间" align="center" prop="timeEnd" />
  75. <el-table-column label="抖音排期状态" align="center" prop="status">
  76. <template slot-scope="scope">
  77. <dict-tag :options="dict.type.tiktok_scheduling_status" :value="scope.row.status"/>
  78. </template>
  79. </el-table-column>
  80. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  81. <template slot-scope="scope">
  82. <el-button
  83. size="mini"
  84. type="text"
  85. v-if="scope.row.status"
  86. @click="openCalendarFun(scope.row)"
  87. >日历价格配置</el-button>
  88. <!-- <el-button
  89. size="mini"
  90. type="text"
  91. @click="submitForm1(scope.row)"
  92. >{{ scope.row.status == 1 ? '下架':'上架' }}</el-button> -->
  93. </template>
  94. </el-table-column>
  95. </el-table>
  96. </div>
  97. <span slot="footer" class="dialog-footer">
  98. <el-button @click="cancel">取消</el-button>
  99. <el-button
  100. type="primary"
  101. @click="submitForm"
  102. :disabled="!multipleSelection || multipleSelection.length == 0"
  103. :loading="loading"
  104. >
  105. <span v-if="loading">提交中...</span>
  106. <span v-else>推送已选</span>
  107. </el-button>
  108. </span>
  109. <!-- 选择日期 价格 -->
  110. <el-dialog
  111. :visible.sync="openCalendar"
  112. width="70%"
  113. class="text-dia-log-class"
  114. append-to-body
  115. :close-on-click-modal="false"
  116. @close="openPrice = false"
  117. >
  118. <div class="dialog calendar-dialog" v-loading="calendarLoading">
  119. <div>
  120. <el-button type="primary" @click="openCalendarPrice()">价格设置</el-button>
  121. <el-button type="primary" @click="clearCalendarPrice()">一键清空</el-button>
  122. </div>
  123. <el-calendar v-model="timeValue">
  124. <template
  125. slot="dateCell"
  126. slot-scope="{date, data}">
  127. <div :class="['calendar_box', selectTime(data)]" @mouseover="mouseoverFun(data)" @click.stop="clickTimeFun(data)">
  128. <span>{{ data.day.split('-').slice(1).join('-') }}</span>
  129. <div style="width: 100%; display: flex;flex-wrap: wrap;" >
  130. <div
  131. :key="index"
  132. v-for="(item,index) in getPerFormList(data)"
  133. >
  134. {{ item.title }}:{{ item.money }}
  135. </div>
  136. </div>
  137. </div>
  138. </template>
  139. </el-calendar>
  140. </div>
  141. <span slot="footer" class="dialog-footer">
  142. <el-button @click="openCalendar = false">返回</el-button>
  143. </span>
  144. </el-dialog>
  145. <!-- 设置价格 -->
  146. <el-dialog
  147. title="价格设置"
  148. :visible.sync="openPrice"
  149. width="400px"
  150. class="text-dia-log-class"
  151. append-to-body
  152. :close-on-click-modal="false"
  153. @close="openPrice = false"
  154. >
  155. <div v-loading="priceLoading">
  156. <el-form :model="formPrice" ref="formPrice" size="small" :rules="rulesPrice" label-width="100px">
  157. <el-form-item label="日期区间">
  158. {{ this.timeValueObj.prev +" - "+ this.timeValueObj.next }}
  159. </el-form-item>
  160. <el-form-item label="市场价" prop="originalAmount">
  161. <el-input-number v-model="formPrice.originalAmount" controls-position="right" :min="0"></el-input-number>
  162. </el-form-item>
  163. <el-form-item label="销售价" prop="saleAmount">
  164. <el-input-number v-model="formPrice.saleAmount" controls-position="right" :min="0"></el-input-number>
  165. </el-form-item>
  166. <el-form-item label="结算价" prop="costAmount">
  167. <el-input-number v-model="formPrice.costAmount" controls-position="right" :min="0"></el-input-number>
  168. </el-form-item>
  169. </el-form>
  170. </div>
  171. <span slot="footer" class="dialog-footer">
  172. <el-button @click="openPrice = false">返回</el-button>
  173. <el-button @click="submitFormPrice('formPrice','calendarPrice')">提交</el-button>
  174. </span>
  175. </el-dialog>
  176. </el-dialog>
  177. </template>
  178. <script>
  179. import {
  180. pushById,
  181. getCalendarPriceApi,
  182. setCalendarPriceApi,
  183. getPushListApi,
  184. deleteCalendarPriceApi
  185. } from "@/api/otaMr/tiktok";
  186. import moment from "moment"
  187. export default {
  188. name: "dataEdit",
  189. dicts: ['tiktok_category','tiktok_scheduling_status','tiktok_showChannel'],
  190. data() {
  191. return {
  192. title: "排期推送设置",
  193. model: "EDIT",
  194. open: false,
  195. loading: false,
  196. goodsList: [],
  197. form: {},
  198. rules: {
  199. poiId: [{ required: true, message: "请输入门店POIID", trigger: ["change","blur"] }],
  200. categoryId: [{ required: true, message: "请选择商品类目ID", trigger: ["change","blur"] }],
  201. showChannel: [{ required: true, message: "请选择投放渠道", trigger: ["change","blur"] }]
  202. },
  203. multipleSelection: [],
  204. openCalendar: false,
  205. timeValue: new Date(),
  206. timeValueObj: {
  207. prev: null,
  208. next: null,
  209. hover: null
  210. },
  211. calendarLoading: false,
  212. perFormList: [],
  213. openPrice: false,
  214. priceLoading: false,
  215. formPrice: {},
  216. rulesPrice: {
  217. originalAmount: [{ required: true, message: "请输入市场价", trigger: ["change","blur"] }],
  218. saleAmount: [{ required: true, message: "请输入销售价", trigger: ["change","blur"] }],
  219. costAmount: [{ required: true, message: "请输入结算价", trigger: ["change","blur"] }],
  220. },
  221. seatTypeId: null,
  222. calendarId: null,
  223. };
  224. },
  225. methods: {
  226. /**
  227. * 打开弹框
  228. * @date 2023-11-22
  229. * @param {any} obj
  230. * @returns {any}
  231. */
  232. async openDialog(title, obj, type) {
  233. this.open = true;
  234. this.goodsList = []
  235. this.multipleSelection = []
  236. this.timeValueObj = {}
  237. if(obj.showChannel || obj.showChannel === 0) {
  238. obj.showChannel = obj.showChannel.toString()
  239. }
  240. this.form = JSON.parse(JSON.stringify(obj))
  241. await this.getPushListFun(obj,type)
  242. this.$nextTick(()=>{
  243. this.goodsList.forEach((item)=>{
  244. if(item.checkFlag == 1) {
  245. this.$refs.tables.toggleRowSelection(item,true)
  246. }
  247. })
  248. this.$refs["form"].clearValidate()
  249. })
  250. },
  251. /** 获取设置的日历价格 */
  252. async getPushListFun(obj,type) {
  253. try {
  254. let res = await getPushListApi({
  255. id: obj.id
  256. })
  257. if(res.code == 200) {
  258. let list = []
  259. if(type == 'yesPush') {
  260. list = res.data
  261. }else {
  262. if( res.data && res.data.length > 0){
  263. obj.sku.forEach((item,index)=>{
  264. let obj1 = JSON.parse(JSON.stringify(item))
  265. res.data.forEach((item1,index1)=>{
  266. if(item1.id == obj1.id){
  267. obj1 = JSON.parse(JSON.stringify(item1))
  268. }
  269. })
  270. list.push({
  271. ...obj1,
  272. tableId: "id_" + index
  273. })
  274. })
  275. this.goodsList = res.data
  276. }else {
  277. obj.sku.forEach((item,index)=>{
  278. list.push({
  279. ...item,
  280. tableId: "id_" + index
  281. })
  282. })
  283. }
  284. }
  285. this.goodsList = JSON.parse(JSON.stringify(list))
  286. }
  287. } catch (error) {
  288. this.loading = false
  289. }
  290. },
  291. /**
  292. * 保存
  293. * @date 2023-11-22
  294. * @returns {any}
  295. */
  296. submitForm() {
  297. this.$refs["form"].validate(async (valid) => {
  298. if (valid) {
  299. try {
  300. if(!this.multipleSelection && this.multipleSelection.length <= 0) {
  301. this.$message.error("请选择上推送的数据!!!");
  302. return
  303. }
  304. let flog = false
  305. let list = []
  306. this.multipleSelection.forEach((item)=>{
  307. list.push({
  308. ...item,
  309. checkFlag: 1
  310. })
  311. // if((!item.actualAmount && item.actualAmount !=0) || (!item.originAmount && item.originAmount !=0)) {
  312. // flog = true
  313. // }
  314. })
  315. // if(flog) {
  316. // this.$message.error("请输入销售价和结算价!!!");
  317. // return
  318. // }
  319. this.loading = true;
  320. const { code } = await pushById({
  321. ...this.form,
  322. sku: list
  323. });
  324. if (code === 200) {
  325. this.$message.success("操作成功!");
  326. this.$emit("getList");
  327. this.cancel();
  328. }
  329. } catch (error) {
  330. console.error("error====",error)
  331. } finally {
  332. this.loading = false;
  333. }
  334. }else {
  335. }
  336. })
  337. },
  338. /**
  339. * 重置
  340. * @date 2023-11-22
  341. * @returns {any}
  342. */
  343. reset() {
  344. this.$refs["form"].clearValidate()
  345. },
  346. /**
  347. * 关闭弹框
  348. * @date 2023-11-22
  349. * @returns {any}
  350. */
  351. cancel() {
  352. this.reset();
  353. this.open = false;
  354. },
  355. isCheck(row){
  356. let flog = false
  357. this.multipleSelection.forEach((item,index)=>{
  358. if(item.tableId == row.tableId) {
  359. flog = true
  360. }
  361. })
  362. return flog
  363. },
  364. handleSelectionChange(val) {
  365. console.log("选中了====", val)
  366. this.multipleSelection = val;
  367. },
  368. getPerFormList(data) {
  369. let list = []
  370. this.perFormList.forEach((item,index)=>{
  371. if(item.priceDate && item.priceDate.indexOf(data.day) != -1) {
  372. list = [
  373. { title: '市场价', money: item.originalAmount + '元' },
  374. { title: '销售价', money: item.saleAmount + '元' },
  375. { title: '结算价', money: item.costAmount + '元' },
  376. ]
  377. }
  378. })
  379. return list
  380. },
  381. /** 打开价格设置 */
  382. openCalendarPrice(){
  383. if( this.timeValueObj.prev && this.timeValueObj.next ) {
  384. this.openPrice = true
  385. this.formPrice = {}
  386. this.$nextTick(()=>{
  387. this.$refs.formPrice.clearValidate()
  388. })
  389. }else {
  390. this.$message.error("请选择时间区间!!!");
  391. }
  392. },
  393. /** 一键清除 */
  394. async clearCalendarPrice() {
  395. try {
  396. if( this.timeValueObj.prev && this.timeValueObj.next ) {
  397. let minTime = moment(this.timeValueObj.prev).valueOf()
  398. let maxTime = moment(this.timeValueObj.next).valueOf()
  399. let startDate = null
  400. let endDate = null
  401. if(minTime > maxTime){
  402. startDate = this.timeValueObj.next
  403. endDate = this.timeValueObj.prev
  404. }else {
  405. startDate = this.timeValueObj.prev
  406. endDate = this.timeValueObj.next
  407. }
  408. let daysList = [];
  409. let SDate = moment(startDate);
  410. let EDate = moment(endDate);
  411. daysList.push({
  412. "priceDate": SDate.startOf('day').format("YYYY-MM-DD HH:mm:ss"),
  413. });
  414. while (SDate.add(1, "days").isBefore(EDate)) { // 注意这里add方法处理后SDate对象已经改变。
  415. daysList.push({
  416. "priceDate": SDate.startOf('day').format("YYYY-MM-DD HH:mm:ss"),
  417. });
  418. }
  419. if(this.timeValueObj.next != this.timeValueObj.prev){
  420. daysList.push({
  421. "priceDate": EDate.startOf('day').format("YYYY-MM-DD HH:mm:ss"),
  422. });
  423. }
  424. let res = await deleteCalendarPriceApi({
  425. "id": this.form.id,
  426. "goodsId": this.form.goodsId,
  427. "seatTypeId": this.seatTypeId,
  428. "data": daysList
  429. })
  430. if(res.code == 200) {
  431. this.openPrice = false
  432. this.getCalendarPrice()
  433. }
  434. }else {
  435. this.$message.error("请选择时间区间!!!");
  436. }
  437. } catch (error) {
  438. }
  439. },
  440. submitFormPrice(formName,funName) {
  441. this.$refs[formName].validate((valid) => {
  442. if (valid) {
  443. this[funName]()
  444. } else {
  445. console.log('error submit!!');
  446. return false;
  447. }
  448. });
  449. },
  450. openCalendarFun(row){
  451. this.seatTypeId = row.seatTypeId
  452. this.calendarId = row.id
  453. this.getCalendarPrice()
  454. },
  455. /** 获取设置的日历价格 */
  456. async getCalendarPrice() {
  457. try {
  458. this.timeValueObj = {}
  459. let res = await getCalendarPriceApi({
  460. "goodsId": this.form.goodsId,
  461. "seatTypeId": this.seatTypeId
  462. })
  463. if(res.code == 200) {
  464. this.openCalendar = true
  465. this.perFormList = res.data
  466. }
  467. } catch (error) {
  468. }
  469. },
  470. /** 设置价格 */
  471. async calendarPrice(type){
  472. try {
  473. if( this.timeValueObj.prev && this.timeValueObj.next ) {
  474. let minTime = moment(this.timeValueObj.prev).valueOf()
  475. let maxTime = moment(this.timeValueObj.next).valueOf()
  476. let startDate = null
  477. let endDate = null
  478. if(minTime > maxTime){
  479. startDate = this.timeValueObj.next
  480. endDate = this.timeValueObj.prev
  481. }else {
  482. startDate = this.timeValueObj.prev
  483. endDate = this.timeValueObj.next
  484. }
  485. let daysList = [];
  486. let SDate = moment(startDate);
  487. let EDate = moment(endDate);
  488. daysList.push({
  489. "id": null,
  490. "priceDate": SDate.startOf('day').format("YYYY-MM-DD HH:mm:ss"),
  491. "originalAmount": this.formPrice.originalAmount,
  492. "saleAmount": this.formPrice.saleAmount,
  493. "costAmount": this.formPrice.costAmount
  494. });
  495. while (SDate.add(1, "days").isBefore(EDate)) { // 注意这里add方法处理后SDate对象已经改变。
  496. daysList.push({
  497. "id": null,
  498. "priceDate": SDate.startOf('day').format("YYYY-MM-DD HH:mm:ss"),
  499. "originalAmount": this.formPrice.originalAmount,
  500. "saleAmount": this.formPrice.saleAmount,
  501. "costAmount": this.formPrice.costAmount
  502. });
  503. }
  504. if(this.timeValueObj.next != this.timeValueObj.prev){
  505. daysList.push({
  506. "id": null,
  507. "priceDate": EDate.startOf('day').format("YYYY-MM-DD HH:mm:ss"),
  508. "originalAmount": this.formPrice.originalAmount,
  509. "saleAmount": this.formPrice.saleAmount,
  510. "costAmount": this.formPrice.costAmount
  511. });
  512. }
  513. console.log("daysList===",daysList)
  514. daysList.forEach((item,index)=>{
  515. this.perFormList.forEach((item1,index1)=>{
  516. if(moment(item.priceDate).format("YYYY-MM-DD") == moment(item1.priceDate).format("YYYY-MM-DD") ) {
  517. daysList[index].id = item1.id
  518. }
  519. })
  520. })
  521. let res = await setCalendarPriceApi({
  522. "id": this.calendarId,
  523. "goodsId": this.form.goodsId,
  524. "seatTypeId": this.seatTypeId,
  525. "data": daysList
  526. })
  527. if(res.code == 200) {
  528. this.openPrice = false
  529. this.getCalendarPrice()
  530. }
  531. }else {
  532. this.$message.error("请选择时间区间!!!");
  533. }
  534. } catch (error) {
  535. }
  536. },
  537. /** 选中得时间 */
  538. selectTime(data) {
  539. let srt = ''
  540. let newTime = moment(data.day).startOf('day').valueOf()
  541. let newTime1 = moment().startOf('day').valueOf()
  542. if(newTime < newTime1 ) {
  543. return "disable_time"
  544. }
  545. if( this.timeValueObj ) {
  546. if( this.timeValueObj.prev && this.timeValueObj.next ) {
  547. let minTime = moment(this.timeValueObj.prev).valueOf()
  548. let maxTime = moment(this.timeValueObj.next).valueOf()
  549. if(minTime > maxTime){
  550. if(minTime >= newTime && maxTime <= newTime){
  551. srt = 'is-select_time'
  552. }
  553. }else {
  554. if(minTime <= newTime && maxTime >= newTime){
  555. srt = 'is-select_time'
  556. }
  557. }
  558. }else if( this.timeValueObj.prev && !this.timeValueObj.next && this.timeValueObj.hover ){
  559. let minTime = moment(this.timeValueObj.prev).valueOf()
  560. let maxTime = moment(this.timeValueObj.hover).valueOf()
  561. if(minTime > maxTime){
  562. if(minTime >= newTime && maxTime <= newTime){
  563. srt = 'is-select_time_hover'
  564. }
  565. }else {
  566. if(minTime <= newTime && maxTime >= newTime){
  567. srt = 'is-select_time_hover'
  568. }
  569. }
  570. }
  571. }
  572. return srt
  573. },
  574. clickTimeFun(data) {
  575. let newTime1 = moment(data.day).startOf('day').valueOf()
  576. let newTime = moment().startOf('day').valueOf()
  577. if(newTime1 < newTime ) {
  578. return
  579. }
  580. if(moment(data.day).format("YYYY-MM") != moment(this.timeValue).format("YYYY-MM") ) {
  581. return
  582. }
  583. if( !this.timeValueObj || !this.timeValueObj.prev ) {
  584. this.timeValueObj.prev = moment(data.day).format("YYYY-MM-DD")
  585. }else if( this.timeValueObj.prev && !this.timeValueObj.next ){
  586. this.timeValueObj.next = moment(data.day).format("YYYY-MM-DD")
  587. }else if( this.timeValueObj.prev && this.timeValueObj.next ) {
  588. this.timeValueObj.prev = moment(data.day).format("YYYY-MM-DD")
  589. this.timeValueObj.next = null
  590. }
  591. },
  592. mouseoverFun(data) {
  593. if(moment(data.day).format("YYYY-MM") != moment(this.timeValue).format("YYYY-MM") ) {
  594. return
  595. }
  596. if( this.timeValueObj.prev && !this.timeValueObj.next ){
  597. this.timeValueObj.hover = moment(data.day).format("YYYY-MM-DD")
  598. this.timeValue = new Date(this.timeValueObj.hover)
  599. }
  600. }
  601. },
  602. };
  603. </script>
  604. <style lang="scss" scoped>
  605. .dialog {
  606. padding: 0 30px;
  607. max-height: 65vh;
  608. overflow-y: auto;
  609. }
  610. .dialog {
  611. padding: 0 30px;
  612. .upload-btn {
  613. width: 100px;
  614. height: 100px;
  615. background-color: #fbfdff;
  616. border: dashed 1px #c0ccda;
  617. border-radius: 5px;
  618. i {
  619. font-size: 30px;
  620. margin-top: 20px;
  621. }
  622. &-text {
  623. margin-top: -10px;
  624. }
  625. }
  626. .avatar {
  627. cursor: pointer;
  628. }
  629. }
  630. .calendar-dialog ::v-deep .el-calendar-table .el-calendar-day {
  631. padding: none !important;
  632. height: auto;
  633. }
  634. .calendar_box {
  635. width: 100%;
  636. min-height: 86px;
  637. }
  638. .disable_time {
  639. user-select: none;
  640. cursor: not-allowed;
  641. }
  642. .is-select_time {
  643. background-color: rgba(30,144,255,0.8);
  644. }
  645. .is-select_time_hover {
  646. background-color: rgba(30,144,255,0.4);
  647. }
  648. </style>