edit.vue 7.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <template>
  2. <div class="subPage">
  3. <form class="mainForm">
  4. <ul>
  5. <li class="flex-h">
  6. <span>选择案场:<em>*</em></span>
  7. <div class="flex-item">
  8. <div style="width:50%">
  9. <el-select v-model="Case" placeholder="请选择">
  10. <el-option
  11. v-for="item in cases"
  12. :key="item.CaseId"
  13. :label="item.CaseName"
  14. :value="item.CaseId">
  15. </el-option>
  16. </el-select>
  17. </div>
  18. </div>
  19. </li>
  20. <li class="flex-h">
  21. <span>商品名称:<em>*</em></span>
  22. <div class="flex-item">
  23. <div style="width:50%">
  24. <el-input
  25. placeholder="请输入商品名称"
  26. v-model="detail.GoodsName"
  27. clearable>
  28. </el-input>
  29. </div>
  30. </div>
  31. </li>
  32. <li class="flex-h">
  33. <span>商品图片:<em>*</em></span>
  34. <div class="flex-item">
  35. <div class="red-hint">建议上传150*150尺寸的图片</div>
  36. <div style="width:50%">
  37. <el-upload
  38. class="avatar-uploader"
  39. action='string'
  40. :before-upload="toolClass.beforeUpload"
  41. :http-request="toolClass.upload"
  42. :show-file-list="false"
  43. :on-success="handleAvatarSuccess">
  44. <img v-if="Image" :src="Image" class="avatar">
  45. <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  46. </el-upload>
  47. </div>
  48. </div>
  49. </li>
  50. <li class="flex-h">
  51. <span>商品价格:<em>*</em></span>
  52. <div class="flex-item">
  53. <div style="width:50%">
  54. <el-input
  55. placeholder="请输入商品价格"
  56. v-model="detail.Price"
  57. clearable>
  58. </el-input>
  59. </div>
  60. </div>
  61. </li>
  62. <li class="flex-h">
  63. <span>商品规格:</span>
  64. <div class="flex-item">
  65. <div style="width:50%">
  66. <el-select v-model="detailSpecs" multiple placeholder="请选择" style="width:100%;">
  67. <el-option
  68. v-for="item in ((Case || '') === '' ? [] : specs.list)"
  69. :key="item.SpecId"
  70. :label="item.SpecName"
  71. :value="item.SpecId">
  72. </el-option>
  73. </el-select>
  74. </div>
  75. </div>
  76. </li>
  77. <li class="flex-h">
  78. <span>商品类别:<em>*</em></span>
  79. <div class="flex-item">
  80. <div style="width:50%">
  81. <el-select v-model="TypeId" placeholder="请选择商品类型">
  82. <el-option
  83. v-for="item in ((Case || '') === '' ? [] : types.list)"
  84. :key="item.TypeId"
  85. :label="item.TypeName"
  86. :value="item.TypeId">
  87. </el-option>
  88. </el-select>
  89. </div>
  90. </div>
  91. </li>
  92. <li style="text-align:center">
  93. <el-button type="primary" size="mini" @click='submit'>保存</el-button>
  94. <el-button type="danger" size="mini" @click="cancel">取消</el-button>
  95. </li>
  96. </ul>
  97. </form>
  98. </div>
  99. </template>
  100. <script>
  101. import { createNamespacedHelpers, mapState, mapActions } from 'vuex'
  102. const { mapState: mapGoodsState, mapActions: mapGoodsActions } = createNamespacedHelpers('goods')
  103. export default {
  104. name: '',
  105. data () {
  106. return {
  107. limit: 1,
  108. dialogVisible: false,
  109. infoSpecs: null,
  110. }
  111. },
  112. components: {},
  113. computed: {
  114. ...mapGoodsState({
  115. detail: x => x.goodsInfo,
  116. types: x => x.goodsTypes,
  117. specs: x => x.goodsSpecs,
  118. }),
  119. ...mapState({
  120. cases: x => x.app.cases.list,
  121. caseid: x => x.app.cases.default,
  122. orgid: x => x.app.user.OrgId,
  123. }),
  124. Case: {
  125. get () {
  126. return this.detail.CaseId
  127. },
  128. set (val) {
  129. this.UpdateInfo({ ...this.detail, CaseId: val })
  130. this.detail.TypeId = ''
  131. this.GetGoodTypes({ pagesize: 1000, caseid: this.Case })
  132. this.GetGoodSpecs({ pagesize: 1000, caseid: this.Case })
  133. }
  134. },
  135. detailSpecs: {
  136. get () {
  137. // console.log(this.infoSpecs || (this.detail.Specs || []).map(x => x.SpecId))
  138. return this.infoSpecs || (this.detail.Specs || []).map(x => x.SpecId)
  139. },
  140. set (val) {
  141. this.infoSpecs = val
  142. },
  143. },
  144. Image () {
  145. return ((this.detail.Images || [])[0] || {}).ImgUrl
  146. },
  147. TypeId: {
  148. get () {
  149. return this.detail.TypeId
  150. },
  151. set (val) {
  152. this.UpdateInfo({ ...this.detail, TypeId: val })
  153. },
  154. },
  155. },
  156. methods: {
  157. ...mapGoodsActions([
  158. 'GetGoodTypes',
  159. 'GetGoodsByID',
  160. 'AddGoods',
  161. 'UpdateGoods',
  162. 'SetNull',
  163. 'UpdateInfo',
  164. 'GetGoodSpecs',
  165. ]),
  166. ...mapActions([
  167. 'picSize'
  168. ]),
  169. submit () {
  170. this.detail.specs = JSON.stringify(this.detailSpecs.map(x => ({ SpecId: x, GoodsPrice: this.detail.Price })))
  171. this.detail.images = (this.detail.Images || []).map(x => {
  172. if (x.response) {
  173. return x.response.result.url
  174. } else {
  175. return x.ImgUrl
  176. }
  177. }).join(',')
  178. if ((this.detail.CaseId || '') === '') {
  179. this.$message({
  180. type: 'error',
  181. message: '案场不能为空'
  182. })
  183. return false
  184. }
  185. if ((this.detail.GoodsName || '') === '') {
  186. this.$message({
  187. type: 'error',
  188. message: '商品名称不能为空'
  189. })
  190. return false
  191. }
  192. if ((this.detail.Images || '') === '') {
  193. this.$message({
  194. type: 'error',
  195. message: '图片不能为空'
  196. })
  197. return false
  198. }
  199. if ((this.detail.Price || '') === '') {
  200. this.$message({
  201. type: 'error',
  202. message: '价格不能为空'
  203. })
  204. return false
  205. }
  206. if ((this.detail.TypeId || '') === '') {
  207. this.$message({
  208. type: 'error',
  209. message: '类别不能为空'
  210. })
  211. return false
  212. }
  213. if ((this.detail.GoodsId || '') === '') {
  214. this.detail.OrgId = this.orgid
  215. this.AddGoods(this.detail)
  216. } else {
  217. if ((this.detail.CaseId || '') === '') {
  218. this.$message({
  219. type: 'error',
  220. message: '案场不能为空'
  221. })
  222. return false
  223. }
  224. this.UpdateGoods(this.detail)
  225. }
  226. this.$message({
  227. type: 'success',
  228. message: '操作成功'
  229. })
  230. this.$router.push({ name: 'goodsInfo' })
  231. },
  232. cancel () {
  233. this.$router.go(-1)
  234. },
  235. handleAvatarSuccess (res, file) {
  236. this.UpdateInfo({ ...this.detail, Images: [{ ImgUrl: res.result.url }] })
  237. },
  238. },
  239. created () {
  240. this.picSize({ w: 150, h: 150 })
  241. const { id } = this.$route.query
  242. if (id && id !== '') {
  243. this.GetGoodTypes({ pagesize: 1000, caseid: this.Case })
  244. this.GetGoodSpecs({ pagesize: 1000, caseid: this.Case })
  245. this.GetGoodsByID({ id: id })
  246. }
  247. }
  248. }
  249. </script>
  250. <!-- Add "scoped" attribute to limit CSS to this component only -->
  251. <style lang="scss" scoped>
  252. </style>