FsGoods.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <template>
  2. <div class="container">
  3. <el-alert type="warning"
  4. :title="type+'项目条目'"
  5. description="选择主机,选择从设备,再其它可选"
  6. :closable="false" show-icon style="margin-bottom: 15px"></el-alert>
  7. <el-divider>标准配置 <el-button type="text" icon="el-icon-circle-plus-outline" @click="handleAddBase">添加</el-button></el-divider>
  8. <el-row :gutter="24">
  9. <el-col :span="8" v-for="item in baseDevice" :key="item.id">
  10. <el-card shadow="always" :class="item.id?'green-border':''">
  11. <div slot="header" class="clearfix">
  12. <span>{{ item.name }}</span>
  13. <el-button style="float: right; padding: 3px 0;" type="text" icon="el-icon-circle-close" @click="handleItemDelete(item.id)">删除</el-button>
  14. <el-button style="float: right; padding: 3px 0;margin-right: 5px" type="text" icon="el-icon-edit-outline" @click="handleItemSave(item)">保存</el-button>
  15. </div>
  16. <div>
  17. <div class="param-item">
  18. <div class="image">
  19. <img :src="item.image">
  20. </div>
  21. <div class="info">
  22. <div>生产型号:{{ item.code }}</div>
  23. <div>产品编码:{{ item.no }}</div>
  24. <div>建议售价:¥{{ item.price_advise }}</div>
  25. <div>生产周期:{{ item.produce_day }}天</div>
  26. <div><b style="color:red">* </b>数量:<el-input v-model="item.qty" size="small" type="number" style="width: 100px"></el-input></div>
  27. <div><b style="color:red">* </b>价格:<el-input v-model="item.price" size="small" type="number" style="width: 100px"></el-input></div>
  28. </div>
  29. </div>
  30. <div>
  31. <el-input type="textarea" rows="3" placeholder="备注,最大300字" maxlength="300" show-word-limit v-model="item.sales_remark"></el-input>
  32. </div>
  33. </div>
  34. </el-card>
  35. </el-col>
  36. </el-row>
  37. <el-divider>其它选配 <el-button type="text" icon="el-icon-circle-plus-outline" @click="handleAddAddon">添加</el-button></el-divider>
  38. <el-row :gutter="24">
  39. <el-col :span="8" v-for="item in addonDevice" :key="item.id">
  40. <el-card shadow="always" :class="item.id?'green-border':''">
  41. <div slot="header" class="clearfix">
  42. <span>{{ item.name }}</span>
  43. <el-button style="float: right; padding: 3px 0;" type="text" icon="el-icon-circle-close" @click="handleItemDelete(item.id)">删除</el-button>
  44. <el-button style="float: right; padding: 3px 0;margin-right: 5px" type="text" icon="el-icon-edit-outline" @click="handleItemSave(item)">保存</el-button>
  45. </div>
  46. <div>
  47. <div class="param-item">
  48. <div class="image">
  49. <img :src="item.image">
  50. </div>
  51. <div class="info">
  52. <div>生产型号:{{ item.code }}</div>
  53. <div>产品编码:{{ item.no }}</div>
  54. <div>建议售价:¥{{ item.price_advise }}</div>
  55. <div>生产周期:{{ item.produce_day }}天</div>
  56. <div><b style="color:red">* </b>数量:<el-input v-model="item.qty" size="small" type="number" style="width: 100px"></el-input></div>
  57. <div><b style="color:red">* </b>价格:<el-input v-model="item.price" size="small" type="number" style="width: 100px"></el-input></div>
  58. </div>
  59. </div>
  60. <div>
  61. <el-input type="textarea" rows="3" placeholder="备注,最大300字" maxlength="300" show-word-limit v-model="item.sales_remark"></el-input>
  62. </div>
  63. </div>
  64. </el-card>
  65. </el-col>
  66. </el-row>
  67. <el-drawer
  68. title="设备"
  69. :visible.sync="goodsSelectVisible"
  70. :append-to-body="true"
  71. size="80%"
  72. >
  73. <goods-select :type="type" :type_base="type_base" @selected="goodsSelect"></goods-select>
  74. </el-drawer>
  75. </div>
  76. </template>
  77. <script>
  78. import * as API_draftGoods from '@/api/pjDraftGoods.js'
  79. import { Foundation } from '~/ui-utils'
  80. import goodsSelect from '../goods/goodsSelect.vue'
  81. export default {
  82. name: 'draftFsGoods',
  83. components: { goodsSelect },
  84. props: {
  85. draftId: {
  86. type: Number,
  87. value: 0
  88. },
  89. type: {
  90. type: String,
  91. value: '服务器版'
  92. }
  93. },
  94. data() {
  95. return {
  96. keyId: '',
  97. params: {
  98. page_no: 1,
  99. page_size: 1000
  100. },
  101. listData: [],
  102. baseDevice: [],
  103. addonDevice: [],
  104. goodsSelectVisible: false,
  105. type_base: true
  106. }
  107. },
  108. mounted() {
  109. console.log(this.$route.params)
  110. if (this.$route.params && this.$route.params.id !== 0) {
  111. this.keyId = this.$route.params.id
  112. this.getData()
  113. }
  114. },
  115. activated() {
  116. if (this.$route.params && this.$route.params.id !== 0) {
  117. this.keyId = this.$route.params.id
  118. this.getData()
  119. }
  120. },
  121. methods: {
  122. getData() {
  123. this.params.fixedCondition = 'draft_id=' + this.draftId
  124. API_draftGoods.getList(this.params).then(res => {
  125. this.listData = res.data
  126. this.baseDevice = this.listData.filter(p => p.type_base)
  127. this.addonDevice = this.listData.filter(p => !p.type_base)
  128. })
  129. },
  130. handleAddBase() {
  131. this.type_base = true
  132. this.goodsSelectVisible = true
  133. },
  134. handleAddAddon() {
  135. this.type_base = false
  136. this.goodsSelectVisible = true
  137. },
  138. goodsSelect(list) {
  139. console.log(list)
  140. list.forEach(item => {
  141. item.id = null
  142. if (this.listData.filter(p => p.code === item.code).length === 0) {
  143. item.qty = 1
  144. item.price = item.price_advise
  145. this.listData.push(item)
  146. }
  147. })
  148. this.baseDevice = this.listData.filter(p => p.type_base)
  149. this.addonDevice = this.listData.filter(p => !p.type_base)
  150. this.goodsSelectVisible = false
  151. },
  152. handleItemDelete(id) {
  153. this.$confirm('确认删除, 是否继续?', '提示', { type: 'warning' }).then(() => {
  154. API_draftGoods.deletes(id).then(() => {
  155. this.getData()
  156. this.$message.success('删除成功!')
  157. })
  158. })
  159. },
  160. handleItemSave(item) {
  161. if (!(item.qty && item.price)) {
  162. this.$message.error('数量和价格不能为空')
  163. return false
  164. }
  165. item.draft_id = this.draftId
  166. if (item.id) {
  167. API_draftGoods.editModel(item).then(res => {
  168. this.$message.success('修改成功!')
  169. })
  170. } else {
  171. API_draftGoods.addModel(item).then(res => {
  172. this.$message.success('添加成功!')
  173. this.listData.forEach(p => {
  174. if (p.code === item.code) {
  175. p.id = res.data.id
  176. this.baseDevice = this.listData.filter(p => p.type_base)
  177. this.addonDevice = this.listData.filter(p => !p.type_base)
  178. }
  179. })
  180. })
  181. }
  182. }
  183. }
  184. }
  185. </script>
  186. <style type="text/scss" lang="scss" scoped>
  187. .param-item {
  188. display: flex;
  189. align-items: center;
  190. justify-content: space-between;
  191. padding: 7px;
  192. font-size: 14px;
  193. .image {
  194. width: 35%;
  195. }
  196. .image img {
  197. width: 120px;
  198. height: 120px;
  199. }
  200. .info div {
  201. margin-bottom: 5px;
  202. }
  203. &.empty {
  204. background-color: #fff
  205. }
  206. }
  207. .green-border {
  208. border-color: #13ce66;
  209. }
  210. </style>