addStock.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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\venue\schedulingMr\dialog\AddOrEditDialog.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="900px"
  15. class="text-dia-log-class"
  16. append-to-body
  17. :close-on-click-modal="false"
  18. @close="cancel"
  19. >
  20. <div class="dialog" v-loading="loading">
  21. <div v-for="(item,index) in tableData" :key="index" :style="{display: 'flex',marginBottom: '10px',alignItems:tableId ? 'flex-start' : 'center'}">
  22. <div :style="{display: 'flex',minWidth: '150px',justifyContent: 'flex-end',padding: tableId ? '8px 0 0 0' : '0px'}">
  23. <dict-tag :options="dict.type.order_form_type" :value="item.source"/>:
  24. </div>
  25. <div v-if="!tableId" style="display: flex;margin-left: 20px;align-items: center;">
  26. <span style="margin-right: 10px;">库存</span>
  27. <el-input-number placeholder="请输入库存" v-model="tableData[index].stock" controls-position="right"></el-input-number>
  28. </div>
  29. <div v-if="tableId" style="margin-left: 20px;">
  30. <el-radio-group v-model="tableData[index].status" @change="(value)=>changeRadio(value,index)">
  31. <div>
  32. <el-radio :label="0">在售</el-radio>
  33. <el-input-number placeholder="请输入库存" :disabled="tableData[index].status == 1" v-model="tableData[index].stock" controls-position="right"></el-input-number>
  34. </div>
  35. <div style="margin-top: 10px;">
  36. <el-radio :label="1">售罄</el-radio>
  37. </div>
  38. </el-radio-group>
  39. </div>
  40. </div>
  41. </div>
  42. <span slot="footer" class="dialog-footer">
  43. <el-button v-if="!loading" @click="cancel">取消</el-button>
  44. <el-button
  45. type="primary"
  46. @click="submitForm"
  47. :loading="loading"
  48. >
  49. <span v-if="loading">保存中...</span>
  50. <span v-else>保存</span>
  51. </el-button>
  52. </span>
  53. </el-dialog>
  54. </template>
  55. <script>
  56. import { saveCommonConfigApi,saveCommonConfigSingleApi } from "@/api/schedulingMr/schedulingMr";
  57. export default {
  58. name: "stockAll",
  59. dicts: ['order_form_type'],
  60. data() {
  61. return {
  62. title: "渠道默认库存设置",
  63. model: "EDIT",
  64. open: false,
  65. loading: false,
  66. tableData: [], // 票务
  67. stock: {},
  68. tableId: '',
  69. allData: {}
  70. };
  71. },
  72. methods: {
  73. /**
  74. * 打开弹框
  75. * @date 2023-11-22
  76. * @param {any} obj
  77. * @returns {any}
  78. */
  79. async openDialog(title,data,id,allData) {
  80. console.log("data,id,allData====",data,id)
  81. this.open = true;
  82. this.tableId = id
  83. this.stock = JSON.parse(JSON.stringify(data))
  84. this.tableData = JSON.parse(JSON.stringify(data.chennelStock))
  85. this.allData = JSON.parse(JSON.stringify(allData))
  86. this.title = title
  87. },
  88. /** 票务信息 */
  89. async saveCommonConfigFun(value){
  90. try {
  91. let res = await saveCommonConfigApi()
  92. if(res.code == 200){
  93. this.tableData = res.data.stock
  94. }
  95. } catch (error) {
  96. }
  97. },
  98. /**
  99. * 关闭弹框
  100. * @date 2023-11-22
  101. * @returns {any}
  102. */
  103. cancel() {
  104. this.open = false;
  105. },
  106. /**
  107. * 保存
  108. * @date 2023-11-22
  109. * @returns {any}
  110. */
  111. async submitForm() {
  112. let count = 0
  113. this.tableData.forEach((item,index)=>{
  114. count = count + (item.stock?item.stock:0) + (item.soldNum?item.soldNum:0)
  115. })
  116. console.log("count====",count)
  117. if( this.stock.stock < count ) {
  118. this.$message.error("渠道在售库存和已售数量总合不能大于总库存!");
  119. return
  120. }
  121. let params = JSON.parse(JSON.stringify(this.allData))
  122. this.allData.forEach((item,index)=>{
  123. if(item.seatTypeId == this.stock.seatTypeId) {
  124. params[index] = {
  125. ...this.stock,
  126. chennelStock: this.tableData
  127. }
  128. }
  129. })
  130. this.$emit("getList",params);
  131. this.cancel();
  132. // try {
  133. // this.loading = true;
  134. // let params = JSON.parse(JSON.stringify(this.allData))
  135. // this.allData.forEach((item,index)=>{
  136. // if(item.seatTypeId == this.stock.seatTypeId) {
  137. // params[index] = {
  138. // ...this.stock,
  139. // chennelStock: this.tableData
  140. // }
  141. // }
  142. // })
  143. // let res = null
  144. // if(this.tableId) {
  145. // res = await saveCommonConfigSingleApi({
  146. // stock: params
  147. // });
  148. // }else {
  149. // res = await saveCommonConfigApi({ stock: params });
  150. // }
  151. // if (res.code === 200) {
  152. // this.$message.success("操作成功!");
  153. // this.loading = false;
  154. // this.$emit("getList");
  155. // this.cancel();
  156. // }
  157. // } catch (error) {
  158. // this.loading = false;
  159. // }
  160. },
  161. changeRadio(value,index) {
  162. if(value == 1){
  163. this.$set(this.tableData[index],'stock',0)
  164. }
  165. }
  166. },
  167. };
  168. </script>
  169. <style lang="scss" scoped>
  170. .dialog {
  171. padding: 0 30px;
  172. max-height: 65vh;
  173. overflow-y: auto;
  174. }
  175. .dialog {
  176. padding: 0 30px;
  177. .upload-btn {
  178. width: 100px;
  179. height: 100px;
  180. background-color: #fbfdff;
  181. border: dashed 1px #c0ccda;
  182. border-radius: 5px;
  183. i {
  184. font-size: 30px;
  185. margin-top: 20px;
  186. }
  187. &-text {
  188. margin-top: -10px;
  189. }
  190. }
  191. .avatar {
  192. cursor: pointer;
  193. }
  194. }
  195. </style>