setSku.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. <template>
  2. <div class="app-container">
  3. <!-- 查询 -->
  4. <el-row :gutter="10" class="mb8">
  5. <el-col :span="1.5">
  6. <el-button type="primary" plain icon="el-icon-plus" @click="handleAdd" v-hasPermi="['commonGoods:commonGoods:add']" v-if="userInfoVO.userType == '00'">新增</el-button>
  7. </el-col>
  8. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  9. </el-row>
  10. <!-- 列表 -->
  11. <Page uri="/mapi/core/sku/list" :request-params="queryParams" ref="pagination">
  12. <el-table-column type="selection" width="55" align="center" />
  13. <el-table-column label="规格编号" align="center" prop="id" />
  14. <el-table-column label="规格详情" align="center" width="200" :show-overflow-tooltip="true">
  15. <template slot-scope="scope">
  16. <span v-for="spec in scope.row.specVoList" :key="spec.id">
  17. <p>{{ spec.specName }}:{{ spec.specValue }}</p>
  18. </span>
  19. </template>
  20. </el-table-column>
  21. <el-table-column label="零售价(元)" align="center" prop="salePrice" />
  22. <el-table-column label="批发价(元)" align="center" prop="wholesalePrice" v-if="userInfoVO.userType != '02'" />
  23. <el-table-column label="进货价(元)" align="center" prop="purchasePrice" />
  24. <el-table-column label="库存" align="center" prop="stock" />
  25. <el-table-column label="启用状态" align="center" prop="status">
  26. <template slot-scope="scope">
  27. <el-switch v-model="scope.row.status" active-value="0" inactive-value="1" @change="handleStatusChange(scope.row)"></el-switch>
  28. </template>
  29. </el-table-column>
  30. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  31. <template slot-scope="scope">
  32. <el-button type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['goods:commonGoods:edit']">修改</el-button>
  33. <!-- <el-button type="text" icon="el-icon-edit" @click="stockRecord(scope.row)" v-hasPermi="['goods:commonGoods:edit']">库存记录</el-button>-->
  34. <el-button type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['goods:commonGoods:remove']" v-if="userInfoVO.userType == '00'">删除</el-button>
  35. </template>
  36. </el-table-column>
  37. </Page>
  38. <!-- 分页 -->
  39. <!-- 添加或修改商品管理对话框 -->
  40. <el-dialog :title="title" :visible.sync="open" width="50%" append-to-body size="50%">
  41. <el-form ref="form" :model="form" :rules="rules" label-width="120px" v-if="Object.keys(form).length > 0">
  42. <div class="specvo_content">
  43. <div class="list_specvo">
  44. <div class="title">物料规格</div>
  45. <div v-for="(item, index) in specVoList" :key="index">
  46. <el-row :gutter="15">
  47. <el-col :span="10">
  48. <el-form-item label="规格名称" required>
  49. <el-input v-model="item.specName" placeholder="请输入名称" :disabled="userInfoVO.userType != '00' ? true : false" />
  50. </el-form-item>
  51. </el-col>
  52. <el-col :span="10">
  53. <el-form-item label="规格内容" required>
  54. <el-input v-model="item.specValue" placeholder="请输入内容" :disabled="userInfoVO.userType != '00' ? true : false" />
  55. </el-form-item>
  56. </el-col>
  57. <el-col :span="4" v-if="index == '0' && specVoList.length == 1 && userInfoVO.userType == '00'">
  58. <el-button @click="addSpecList" style="width: 100px" type="primary">新增规格</el-button>
  59. </el-col>
  60. <el-col :span="4" v-if="index != '0' && userInfoVO.userType == '00'">
  61. <el-button @click="deleteSpecList(index)" type="danger">删除</el-button>
  62. </el-col>
  63. </el-row>
  64. </div>
  65. </div>
  66. <el-row :gutter="20">
  67. <el-col :span="12">
  68. <el-form-item label="零售价(元)" prop="salePrice">
  69. <el-input-number v-model="form.salePrice" placeholder="请输入零售价" :precision="2" :step="0.1" :min="0" :max="9999999" style="width: 100%" />
  70. </el-form-item>
  71. </el-col>
  72. <el-col :span="12">
  73. <el-form-item label="批发价(元)" prop="wholesalePrice" v-if="userInfoVO.userType != '02'">
  74. <el-input-number v-model="form.wholesalePrice" placeholder="请输入批发价" :precision="2" :step="0.1" :min="0" :max="9999999" style="width: 100%" />
  75. </el-form-item>
  76. </el-col>
  77. <el-col :span="12">
  78. <el-form-item label="进货价(元)" prop="purchasePrice">
  79. <el-input-number v-model="form.purchasePrice" placeholder="请输入进货价" :precision="2" :step="0.1" :min="0" :max="9999999" :disabled="userInfoVO.userType != '00' ? true : false" style="width: 100%" />
  80. </el-form-item>
  81. </el-col>
  82. </el-row>
  83. <div class="remark">* 物料规格最多两条 使用同一价格体系 *</div>
  84. </div>
  85. </el-form>
  86. <div slot="footer" class="dialog-footer">
  87. <el-button type="primary" @click="submitForm" style="margin-left: 5%">提交</el-button>
  88. <el-button @click="cancel">取 消</el-button>
  89. </div>
  90. </el-dialog>
  91. </div>
  92. </template>
  93. <script>
  94. import { listSku, addSku, getSku, delSku, updateSku } from '@/api/core/sku'
  95. import { listRecord } from '@/api/core/stockRecord'
  96. export default {
  97. name: 'setGoodsSku',
  98. dicts: ['goods_type', 'sys_yes_no'],
  99. data() {
  100. return {
  101. userInfoVO: null,
  102. specVO: null,
  103. goodsId: '',
  104. // 遮罩层
  105. loading: true,
  106. stockLoading: true,
  107. // 选中数组
  108. ids: [],
  109. // 非单个禁用
  110. single: true,
  111. // 非多个禁用
  112. multiple: true,
  113. // 显示搜索条件
  114. showSearch: true,
  115. // 总条数
  116. total: 0,
  117. // 商品管理表格数据
  118. skuList: [],
  119. // 弹出层标题
  120. title: '',
  121. // 是否显示弹出层
  122. open: false,
  123. // 查询参数
  124. queryParams: {},
  125. // 表单参数
  126. form: {
  127. salePrice: 0,
  128. wholesalePrice: 0,
  129. purchasePrice: 0
  130. },
  131. // 表单校验
  132. rules: {
  133. salePrice: [{ required: true, message: '零售价不能为空', trigger: 'blur' }],
  134. wholesalePrice: [{ required: true, message: '批发价不能为空', trigger: 'blur' }],
  135. purchasePrice: [{ required: true, message: '进货价不能为空', trigger: 'blur' }]
  136. },
  137. specVoList: [
  138. {
  139. specName: '',
  140. specValue: ''
  141. }
  142. ]
  143. }
  144. },
  145. created() {
  146. this.handleUser()
  147. this.goodsId = this.$route.params.goodsId
  148. this.queryParams.goodsId = this.goodsId
  149. this.getList()
  150. },
  151. methods: {
  152. handleUser() {
  153. this.userInfoVO = this.getUserInfo()
  154. },
  155. addSpecList() {
  156. if (this.specVoList.length < 2) {
  157. this.specVoList.push({
  158. specName: '',
  159. specValue: ''
  160. })
  161. } else {
  162. this.$modal.msgSuccess('最多添加2种规格')
  163. }
  164. },
  165. deleteSpecList(index) {
  166. this.specVoList.splice(index, 1)
  167. },
  168. /** 查询商品管理列表 */
  169. getList() {
  170. this.$nextTick(() => {
  171. this.$refs.pagination.handleSearch(true)
  172. })
  173. },
  174. // 取消按钮
  175. cancel() {
  176. this.open = false
  177. this.reset()
  178. },
  179. // 表单重置
  180. reset() {
  181. this.form = {
  182. id: null,
  183. sort: null,
  184. status: null,
  185. salePrice: null,
  186. wholesalePrice: null,
  187. purchasePrice: null,
  188. specVoList: [
  189. {
  190. specName: null,
  191. specValue: null
  192. }
  193. ],
  194. createBy: null,
  195. createById: null,
  196. createTime: null,
  197. updateBy: null,
  198. updateById: null,
  199. updateTime: null,
  200. remark: null
  201. }
  202. this.specVoList = [
  203. {
  204. specName: '',
  205. specValue: ''
  206. }
  207. ]
  208. this.resetForm('form')
  209. },
  210. /** 搜索按钮操作 */
  211. handleQuery() {
  212. this.queryParams.pageNum = 1
  213. this.getList()
  214. },
  215. /** 重置按钮操作 */
  216. resetQuery() {
  217. this.resetForm('queryForm')
  218. this.handleQuery()
  219. },
  220. // 多选框选中数据
  221. handleSelectionChange(selection) {
  222. this.ids = selection.map((item) => item.id)
  223. this.single = selection.length !== 1
  224. this.multiple = !selection.length
  225. },
  226. /** 新增按钮操作 */
  227. handleAdd() {
  228. this.reset()
  229. this.open = true
  230. this.title = '添加物料明细'
  231. },
  232. /** 修改按钮操作 */
  233. handleUpdate(row) {
  234. this.reset()
  235. const id = row.id || this.ids
  236. getSku(id).then((response) => {
  237. this.form = response.data
  238. this.specVoList = this.form.specVoList
  239. this.open = true
  240. this.title = '修改物料明细'
  241. })
  242. },
  243. stockRecord(row) {
  244. this.$tab.openPage('库存记录', '/goods/stockRecord/' + row.id)
  245. },
  246. /** 提交按钮 */
  247. submitForm() {
  248. this.$refs['form'].validate((valid) => {
  249. for (let i = 0; i < this.specVoList.length; i++) {
  250. if (this.specVoList[i].specName == '') {
  251. this.$message.error('规格名称不能为空')
  252. return
  253. }
  254. }
  255. if (valid) {
  256. this.form.goodsId = this.goodsId
  257. this.handleSpecVOList()
  258. if (this.form.id != null) {
  259. // 处理工厂/门店传参
  260. updateSku(this.handleUpdateParams(this.form)).then((response) => {
  261. this.$modal.msgSuccess('修改成功')
  262. this.open = false
  263. this.getList()
  264. })
  265. } else {
  266. addSku(this.form).then((response) => {
  267. this.$modal.msgSuccess('新增成功')
  268. this.open = false
  269. this.getList()
  270. })
  271. }
  272. }
  273. })
  274. },
  275. handleUpdateParams(data) {
  276. if (this.userInfoVO.userType == '00') {
  277. return data
  278. }
  279. if (this.userInfoVO.userType == '01') {
  280. data.purchasePrice = null
  281. return data
  282. }
  283. if (this.userInfoVO.userType == '02') {
  284. data.wholesalePrice = null
  285. data.purchasePrice = null
  286. return data
  287. }
  288. },
  289. handleSpecVOList() {
  290. this.form.specVoList = this.specVoList
  291. },
  292. /** 删除按钮操作 */
  293. handleDelete(row) {
  294. const ids = row.id || this.ids
  295. this.$modal
  296. .confirm('是否确认删除商品管理编号为"' + ids + '"的数据项?')
  297. .then(function () {
  298. return delSku(ids)
  299. })
  300. .then(() => {
  301. this.getList()
  302. this.$modal.msgSuccess('删除成功')
  303. })
  304. .catch(() => {})
  305. },
  306. /** 导出按钮操作 */
  307. handleExport() {
  308. this.download(
  309. 'commonGoods/commonGoods/export',
  310. {
  311. ...this.queryParams
  312. },
  313. `goods_${new Date().getTime()}.xlsx`
  314. )
  315. },
  316. checkClose(done) {
  317. this.$confirm('是否关闭表单,关闭后数据将丢失?')
  318. .then(function () {
  319. done()
  320. })
  321. .then(() => {})
  322. .catch(() => {})
  323. },
  324. handleStatusChange(row) {
  325. let text = row.status === '0' ? '启用' : '停用'
  326. this.$confirm('确认要' + text + '吗?')
  327. .then(function () {
  328. return updateGoodsStatus(row.id, row.status)
  329. })
  330. .then(() => {
  331. this.$modal.msgSuccess(text + '成功')
  332. })
  333. .catch(function () {
  334. row.status = row.status === '0' ? '1' : '0'
  335. })
  336. }
  337. }
  338. }
  339. </script>
  340. <style lang="scss" scoped>
  341. .specvo_content {
  342. padding: 5px 20px 20px;
  343. .list_specvo {
  344. padding: 0px 0px 10px;
  345. margin-bottom: 40px;
  346. box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  347. border-radius: 5px;
  348. .title {
  349. color: #606266;
  350. padding: 10px 20px;
  351. border-bottom: 1px #f4f4f4 solid;
  352. font-size: 14px;
  353. margin-bottom: 20px;
  354. }
  355. }
  356. .remark {
  357. margin-top: 30px;
  358. background-color: rgba(255, 228, 74, 0.1);
  359. border: 1px dashed #ffe44a;
  360. font-size: 14px;
  361. color: #e6a23c;
  362. width: 100%;
  363. padding: 20px;
  364. border-radius: 5px;
  365. }
  366. }
  367. </style>