addStock.vue 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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. <el-button type="primary" v-if="tableData.length == 0 " @click="addTable()">添加</el-button>
  22. <div v-for="(item,index) in tableData" :key="index" :style="{display: 'flex',marginBottom: '10px',alignItems:tableId ? 'flex-start' : 'center'}">
  23. <div :style="{display: 'flex',minWidth: '150px',justifyContent: 'flex-end',padding: tableId ? '8px 0 0 0' : '0px'}">
  24. <dict-tag v-if="useStock == 1 || !tableId" :options="dict.type.order_form_type" :value="item.source"/>
  25. <el-select
  26. v-model="tableData[index].source"
  27. placeholder="请选择渠道"
  28. style="width: 100%"
  29. clearable
  30. v-if="useStock == 0 && tableId"
  31. @change="(value)=>selectSource(value,index)"
  32. >
  33. <el-option
  34. v-for="dict in dict.type.order_form_type"
  35. :key="dict.value"
  36. :label="dict.label"
  37. :disabled="sourceList.includes(Number(dict.value))"
  38. :value="Number(dict.value)"
  39. />
  40. </el-select>
  41. </div>
  42. <div v-if="!tableId" style="display: flex;margin-left: 20px;align-items: center;">
  43. <span style="margin-right: 10px;">库存</span>
  44. <el-input-number placeholder="请输入库存" v-model="tableData[index].stock" controls-position="right"></el-input-number>
  45. </div>
  46. <div v-if="tableId" style="margin-left: 20px;">
  47. <el-radio-group v-model="tableData[index].status" @change="(value)=>changeRadio(value,index)">
  48. <div style="display: flex;align-items: center;">
  49. <el-radio :label="0">在售</el-radio>
  50. <el-input-number placeholder="请输入库存" :disabled="tableData[index].status == 1" v-model="tableData[index].stock" controls-position="right"></el-input-number>
  51. <div style="display: flex;width: 100px;color: #333;font-size: 16px;align-items: center;justify-content: center;">已售:{{ item.soldNum }}</div>
  52. </div>
  53. <div style="margin-top: 10px;">
  54. <el-radio :label="1">售罄</el-radio>
  55. </div>
  56. </el-radio-group>
  57. </div>
  58. <div v-if="tableId && useStock==0" style="margin-left: 20px;">
  59. <el-button type="primary" v-if="index == tableData.length-1" @click="addTable(index)">添加</el-button>
  60. <el-button type="danger" @click="clearTable(index)">移除</el-button>
  61. </div>
  62. </div>
  63. </div>
  64. <span slot="footer" class="dialog-footer">
  65. <el-button v-if="!loading" @click="cancel">取消</el-button>
  66. <el-button
  67. v-if="status"
  68. type="primary"
  69. @click="submitForm"
  70. :loading="loading"
  71. >
  72. <span v-if="loading">保存中...</span>
  73. <span v-else>保存</span>
  74. </el-button>
  75. </span>
  76. </el-dialog>
  77. </template>
  78. <script>
  79. import {
  80. saveCommonConfigApi,
  81. saveCommonConfigSingleApi,
  82. countSoldNumApi } from "@/api/schedulingMr/schedulingMr";
  83. import { status } from "nprogress";
  84. export default {
  85. name: "stockAll",
  86. dicts: ['order_form_type'],
  87. data() {
  88. return {
  89. title: "渠道默认库存设置",
  90. model: "EDIT",
  91. open: false,
  92. loading: false,
  93. status: 0, // 0 初始加载 1 加载后
  94. tableData: [], // 票务
  95. stock: {},
  96. tableId: '',
  97. allData: {},
  98. useStock: 0,
  99. chennelStock: [],
  100. sourceList: [],
  101. stockAllNum: 0,
  102. performTimeId: null,
  103. seatTypeId: null,
  104. };
  105. },
  106. methods: {
  107. /**
  108. * 打开弹框
  109. * @date 2023-11-22
  110. * @param {any} obj
  111. * @returns {any}
  112. */
  113. async openDialog(title,data,id,allData,useStock) {
  114. console.log("data,id,allData====",data,id,useStock)
  115. this.open = true;
  116. this.status = 0
  117. this.loading = true
  118. this.tableId = id
  119. this.useStock = useStock
  120. this.performTimeId = data.performTimeId
  121. this.seatTypeId = data.seatTypeId
  122. this.stock = JSON.parse(JSON.stringify(data))
  123. this.tableData = JSON.parse(JSON.stringify(data.chennelStock))
  124. this.chennelStock = JSON.parse(JSON.stringify(data.chennelStock))
  125. this.sourceList = [];
  126. if(id) {
  127. await this.countSoldNumFun()
  128. }else {
  129. this.stockAllNum = 0
  130. // let stockAllNum = 0
  131. this.stockAllNum = this.stock.stock
  132. }
  133. this.allData = JSON.parse(JSON.stringify(allData))
  134. this.title = title + `(可分配库存:${ this.stockAllNum })`
  135. this.loading = false
  136. this.status = 1
  137. },
  138. /** 票务信息 */
  139. async saveCommonConfigFun(value){
  140. try {
  141. let res = await saveCommonConfigApi()
  142. if(res.code == 200){
  143. this.tableData = res.data.stock
  144. }
  145. } catch (error) {
  146. }
  147. },
  148. /**
  149. * 关闭弹框
  150. * @date 2023-11-22
  151. * @returns {any}
  152. */
  153. cancel() {
  154. this.open = false;
  155. },
  156. /**
  157. * 保存
  158. * @date 2023-11-22
  159. * @returns {any}
  160. */
  161. async submitForm() {
  162. let count = 0
  163. let flog = false
  164. this.tableData.forEach((item,index)=>{
  165. count = count + (item.stock?item.stock:0) // + (item.soldNum?item.soldNum:0)
  166. if((!item.source && item.source !== 0) || (!item.stock && item.stock !=0)) {
  167. flog = true
  168. }
  169. })
  170. if( flog ) {
  171. this.$message.error("渠道和在售库存不能为空!");
  172. return
  173. }
  174. console.log("count====",count)
  175. if( this.stockAllNum < count ) {
  176. this.$message.error("渠道在售库存和已售数量总合不能大于总库存!");
  177. return
  178. }
  179. let params = JSON.parse(JSON.stringify(this.allData))
  180. this.allData.forEach((item,index)=>{
  181. if(item.seatTypeId == this.stock.seatTypeId) {
  182. params[index] = {
  183. ...this.stock,
  184. chennelStock: this.tableData
  185. }
  186. }
  187. })
  188. this.$emit("getList",params);
  189. this.cancel();
  190. // try {
  191. // this.loading = true;
  192. // let params = JSON.parse(JSON.stringify(this.allData))
  193. // this.allData.forEach((item,index)=>{
  194. // if(item.seatTypeId == this.stock.seatTypeId) {
  195. // params[index] = {
  196. // ...this.stock,
  197. // chennelStock: this.tableData
  198. // }
  199. // }
  200. // })
  201. // let res = null
  202. // if(this.tableId) {
  203. // res = await saveCommonConfigSingleApi({
  204. // stock: params
  205. // });
  206. // }else {
  207. // res = await saveCommonConfigApi({ stock: params });
  208. // }
  209. // if (res.code === 200) {
  210. // this.$message.success("操作成功!");
  211. // this.loading = false;
  212. // this.$emit("getList");
  213. // this.cancel();
  214. // }
  215. // } catch (error) {
  216. // this.loading = false;
  217. // }
  218. },
  219. // 在售 已售
  220. changeRadio(value,index) {
  221. if(value == 1){
  222. this.$set(this.tableData[index],'stock',0)
  223. }
  224. },
  225. /** 我是谁 */
  226. addTable(){
  227. this.tableData.push({
  228. "stockId": null,
  229. "source": null,
  230. "stock": 0,
  231. "soldNum": 0,
  232. "status": 0
  233. })
  234. this.sourceList.push('')
  235. console.log("value===",this.sourceList)
  236. },
  237. /** 谁是我 */
  238. clearTable(index){
  239. let list = JSON.parse(JSON.stringify(this.sourceList))
  240. // list.forEach((item,i)=>{
  241. // if(this.tableData[index].source == item) {
  242. // this.sourceList.splice(i,1)
  243. // }
  244. // })
  245. this.tableData.splice(index,1)
  246. this.sourceList.splice(index,1)
  247. console.log("value===",index,this.sourceList)
  248. this.$forceUpdate()
  249. },
  250. /** */
  251. async selectSource(value,i) {
  252. console.log("value===",value,i,this.sourceList)
  253. this.$set(this.sourceList,i,value)
  254. //this.sourceList.push(value)
  255. this.$set(this.tableData[i],'soldNum',0)
  256. if(value || value === 0){
  257. this.chennelStock.forEach((item,index)=>{
  258. if(value == item.source) {
  259. this.$set(this.tableData[i],'soldNum',item.soldNum)
  260. }
  261. })
  262. }
  263. this.$forceUpdate()
  264. },
  265. async countSoldNumFun(){
  266. try {
  267. this.stockAllNum = 0
  268. let stockAllNum = 0
  269. let res = await countSoldNumApi({
  270. performTimeId: this.performTimeId,
  271. seatTypeId: this.seatTypeId
  272. })
  273. if(res.code) {
  274. stockAllNum = res.data
  275. }
  276. this.stockAllNum = this.stock.stock - stockAllNum
  277. } catch (error) {
  278. }
  279. }
  280. },
  281. };
  282. </script>
  283. <style lang="scss" scoped>
  284. .dialog {
  285. padding: 0 30px;
  286. max-height: 65vh;
  287. overflow-y: auto;
  288. }
  289. .dialog {
  290. padding: 0 30px;
  291. .upload-btn {
  292. width: 100px;
  293. height: 100px;
  294. background-color: #fbfdff;
  295. border: dashed 1px #c0ccda;
  296. border-radius: 5px;
  297. i {
  298. font-size: 30px;
  299. margin-top: 20px;
  300. }
  301. &-text {
  302. margin-top: -10px;
  303. }
  304. }
  305. .avatar {
  306. cursor: pointer;
  307. }
  308. }
  309. </style>