FsGoods.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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-tabs>
  8. <el-tab-pane label="图表">
  9. <el-divider>标准配置 <el-button type="text" icon="el-icon-circle-plus-outline" @click="handleAddBase">添加</el-button></el-divider>
  10. <el-row :gutter="24" type="flex" style="flex-wrap: wrap; flex-direction: row">
  11. <el-col :span="8" v-for="item in baseDevice" :key="item.id">
  12. <el-card shadow="always" :class="item.id?'green-border':''">
  13. <div slot="header" class="clearfix">
  14. <span>{{ item.name }}</span>
  15. <el-button style="float: right; padding: 3px 0;" type="text" icon="el-icon-circle-close" @click="handleItemDelete(item.id)">删除</el-button>
  16. <el-button style="float: right; padding: 3px 0;margin-right: 5px" type="text" icon="el-icon-edit-outline" @click="handleItemSave(item)">保存</el-button>
  17. </div>
  18. <div>
  19. <div class="param-item">
  20. <div class="image">
  21. <el-link
  22. @click="() => { $router.push({ path: `/pj/pj-goods-detail/${item.good_id}` }) }"
  23. >
  24. <img :src="item.image">
  25. </el-link>
  26. </div>
  27. <div class="info">
  28. <div>生产型号:{{ item.code }}</div>
  29. <div>产品编码:{{ item.no }}</div>
  30. <div>建议售价:¥{{ item.price_advise }}</div>
  31. <div>生产周期:{{ item.produce_day }}天</div>
  32. <div><b style="color:red">* </b>数量:<el-input v-model="item.qty" size="small" type="number" style="width: 100px"></el-input></div>
  33. <div><b style="color:red">* </b>价格:<el-input v-model="item.price" size="small" type="number" style="width: 100px"></el-input></div>
  34. </div>
  35. </div>
  36. <div>
  37. <el-input type="textarea" rows="3" placeholder="备注,最大300字" maxlength="300" show-word-limit v-model="item.sales_remark"></el-input>
  38. </div>
  39. </div>
  40. </el-card>
  41. </el-col>
  42. </el-row>
  43. <el-divider>其它选配 <el-button type="text" icon="el-icon-circle-plus-outline" @click="handleAddAddon">添加</el-button></el-divider>
  44. <el-row :gutter="24" type="flex" style="flex-wrap: wrap; flex-direction: row">
  45. <el-col :span="8" v-for="item in addonDevice" :key="item.id">
  46. <el-card shadow="always" :class="item.id?'green-border':''" style="margin-top:15px;">
  47. <div slot="header" class="clearfix">
  48. <span>{{ item.name }}</span>
  49. <el-button style="float: right; padding: 3px 0;" type="text" icon="el-icon-circle-close" @click="handleItemDelete(item.id)">删除</el-button>
  50. <el-button style="float: right; padding: 3px 0;margin-right: 5px" type="text" icon="el-icon-edit-outline" @click="handleItemSave(item)">保存</el-button>
  51. </div>
  52. <div>
  53. <div class="param-item">
  54. <div class="image">
  55. <el-link
  56. @click="() => { $router.push({ path: `/pj/pj-goods-detail/${item.good_id}` }) }"
  57. >
  58. <img :src="item.image">
  59. </el-link>
  60. </div>
  61. <div class="info">
  62. <div>生产型号:{{ item.code }}</div>
  63. <div>产品编码:{{ item.no }}</div>
  64. <div>建议售价:¥{{ item.price_advise }}</div>
  65. <div>生产周期:{{ item.produce_day }}天</div>
  66. <div><b style="color:red">* </b>数量:<el-input v-model="item.qty" size="small" type="number" style="width: 100px"></el-input></div>
  67. <div><b style="color:red">* </b>价格:<el-input v-model="item.price" size="small" type="number" style="width: 100px"></el-input></div>
  68. </div>
  69. </div>
  70. <div>
  71. <el-input type="textarea" rows="3" placeholder="备注,最大300字" maxlength="300" show-word-limit v-model="item.sales_remark"></el-input>
  72. </div>
  73. </div>
  74. </el-card>
  75. </el-col>
  76. </el-row>
  77. </el-tab-pane>
  78. <el-tab-pane label="表格">
  79. <el-table :data="listData" stripe style="width: 100%;">
  80. <el-table-column prop="name" label="名称"></el-table-column>
  81. <el-table-column label="基础件?">
  82. <template slot-scope="scope">
  83. <el-tag type="success" v-if="scope.row.type_base">标准件</el-tag>
  84. <el-tag type="info" v-else>配件</el-tag>
  85. </template>
  86. </el-table-column>
  87. <el-table-column prop="code" label="生产型号"></el-table-column>
  88. <el-table-column prop="no" label="生产编码"></el-table-column>
  89. <el-table-column prop="qty" label="数量"></el-table-column>
  90. <el-table-column prop="price" label="价格"></el-table-column>
  91. <el-table-column prop="sales_remark" label="销售备注"></el-table-column>
  92. </el-table>
  93. <div style="margin-top: 20px">
  94. <el-button type="primary" @click="outExcel">导出Excel</el-button>
  95. </div>
  96. </el-tab-pane>
  97. </el-tabs>
  98. <el-drawer
  99. title="设备"
  100. :visible.sync="goodsSelectVisible"
  101. :append-to-body="true"
  102. size="80%"
  103. >
  104. <goods-select :type="type" :type_base="type_base" @selected="goodsSelect"></goods-select>
  105. </el-drawer>
  106. </div>
  107. </template>
  108. <script>
  109. import * as API_draftGoods from '@/api/pjDraftGoods.js'
  110. import { Foundation } from '~/ui-utils'
  111. import goodsSelect from '../goods/goodsSelect.vue'
  112. export default {
  113. name: 'draftFsGoods',
  114. components: { goodsSelect },
  115. props: {
  116. draftId: {
  117. type: Number,
  118. value: 0
  119. },
  120. type: {
  121. type: String,
  122. value: '服务器版'
  123. }
  124. },
  125. data() {
  126. return {
  127. keyId: '',
  128. params: {
  129. page_no: 1,
  130. page_size: 1000,
  131. sort: 'type_base',
  132. dir: 'desc'
  133. },
  134. listData: [],
  135. baseDevice: [],
  136. addonDevice: [],
  137. goodsSelectVisible: false,
  138. type_base: true
  139. }
  140. },
  141. mounted() {
  142. console.log(this.$route.params)
  143. if (this.$route.params && this.$route.params.id !== 0) {
  144. this.keyId = this.$route.params.id
  145. this.getData()
  146. }
  147. },
  148. activated() {
  149. if (this.$route.params && this.$route.params.id !== 0) {
  150. this.keyId = this.$route.params.id
  151. this.getData()
  152. }
  153. },
  154. methods: {
  155. getData() {
  156. this.params.fixedCondition = 'draft_id=' + this.draftId
  157. API_draftGoods.getList(this.params).then(res => {
  158. this.listData = res.data
  159. this.baseDevice = this.listData.filter(p => p.type_base)
  160. this.addonDevice = this.listData.filter(p => !p.type_base)
  161. })
  162. },
  163. handleAddBase() {
  164. this.type_base = true
  165. this.goodsSelectVisible = true
  166. },
  167. handleAddAddon() {
  168. this.type_base = false
  169. this.goodsSelectVisible = true
  170. },
  171. goodsSelect(list) {
  172. let data = JSON.parse(JSON.stringify(list))
  173. data.forEach(item => {
  174. item.good_id = item.id
  175. item.id = null
  176. if (this.listData.filter(p => p.good_id === item.good_id).length === 0) {
  177. item.qty = 1
  178. item.price = item.price_advise
  179. this.listData.push(item)
  180. }
  181. })
  182. this.baseDevice = this.listData.filter(p => p.type_base)
  183. this.addonDevice = this.listData.filter(p => !p.type_base)
  184. this.goodsSelectVisible = false
  185. },
  186. handleItemDelete(id) {
  187. this.$confirm('确认删除, 是否继续?', '提示', { type: 'warning' }).then(() => {
  188. API_draftGoods.deletes(id).then(() => {
  189. this.getData()
  190. this.$message.success('删除成功!')
  191. })
  192. })
  193. },
  194. handleItemSave(item) {
  195. if (!(item.qty && item.price)) {
  196. this.$message.error('数量和价格不能为空')
  197. return false
  198. }
  199. item.draft_id = this.draftId
  200. if (item.id) {
  201. API_draftGoods.editModel(item).then(res => {
  202. this.$message.success('修改成功!')
  203. })
  204. } else {
  205. API_draftGoods.addModel(item).then(res => {
  206. this.$message.success('添加成功!')
  207. this.listData.forEach(p => {
  208. if (p.good_id === item.good_id) {
  209. p.id = res.data.id
  210. this.baseDevice = this.listData.filter(p => p.type_base)
  211. this.addonDevice = this.listData.filter(p => !p.type_base)
  212. }
  213. })
  214. })
  215. }
  216. },
  217. outExcel() {
  218. const json = {
  219. sheet_name: '产品列表',
  220. sheet_values: this.listData.map(item => ({
  221. '产品名称': item.name,
  222. '生产型号': item.code,
  223. '生产编码': item.no,
  224. '数量': item.qty,
  225. '单价': Foundation.formatPrice(item.price),
  226. '备注': item.sales_remark
  227. }))
  228. }
  229. this.MixinExportJosnToExcel(json, '产品列表')
  230. }
  231. }
  232. }
  233. </script>
  234. <style type="text/scss" lang="scss" scoped>
  235. .param-item {
  236. display: flex;
  237. align-items: center;
  238. justify-content: space-between;
  239. padding: 7px;
  240. font-size: 14px;
  241. .image {
  242. width: 38%;
  243. }
  244. .image img {
  245. width: 100px;
  246. height: 100px;
  247. }
  248. .info div {
  249. margin-bottom: 5px;
  250. }
  251. &.empty {
  252. background-color: #fff
  253. }
  254. }
  255. .green-border {
  256. border-color: #13ce66;
  257. }
  258. /deep/ .el-drawer__body{
  259. overflow-y: scroll;
  260. }
  261. </style>