index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. <template>
  2. <el-card class="box-card">
  3. <el-form ref="ruleForm" :model="form" :rules="formRules" label-width="0">
  4. <el-table :data="form.tableList" :cell-style="{ padding: '0' }" :row-style="{ height: '35px' }" v-loading="loading" header-row-class-name="tableHeader">
  5. <el-table-column :render-header="(h, obj) => renderHeader(h, obj, item)" min-width="260">
  6. <template slot-scope="scope">
  7. <el-form-item :prop="'tableList.' + scope.$index + '.chargeName'" :rules="formRules.chargeName" :inline-message="true">
  8. <el-select v-model="scope.row.chargeName" placeholder="请选择收费项目" size="small" style="width: 100%">
  9. <el-option v-for="item in chargeName" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey" />
  10. </el-select>
  11. </el-form-item>
  12. </template>
  13. </el-table-column>
  14. <el-table-column label="收费模式" width="140">
  15. <template slot-scope="scope">
  16. <el-form-item :prop="'tableList.' + scope.$index + '.chargeType'" :rules="formRules.chargeType" :inline-message="true">
  17. <el-select v-model="scope.row.chargeType" placeholder="请选择收费模式" size="small" style="width: 100%">
  18. <el-option v-for="item in chargeType" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey" />
  19. </el-select>
  20. </el-form-item>
  21. </template>
  22. </el-table-column>
  23. <el-table-column label="收费模式数值区间" min-width="260">
  24. <template slot-scope="scope">
  25. <el-row>
  26. <el-col :span="11">
  27. <el-form-item :prop="'tableList.' + scope.$index + '.valueRangeBegin'" :rules="formRules.valueRangeBegin" :inline-message="true">
  28. <el-input-number
  29. v-model="scope.row.valueRangeBegin"
  30. placeholder="请输入区间起始值"
  31. size="small"
  32. style="width: 100%"
  33. :controls="false"
  34. :min="0"
  35. :max="999999999"
  36. :precision="0"
  37. />
  38. </el-form-item>
  39. </el-col>
  40. <el-col :span="2" style="text-align: center; line-height: 40px">-</el-col>
  41. <el-col :span="11">
  42. <el-form-item :prop="'tableList.' + scope.$index + '.valueRangeEnd'" :rules="formRules.valueRangeEnd" :inline-message="true">
  43. <el-input-number
  44. v-model="scope.row.valueRangeEnd"
  45. placeholder="请输入区间结束值"
  46. size="small"
  47. style="width: 100%"
  48. :controls="false"
  49. :min="0"
  50. :max="999999999"
  51. :precision="0"
  52. />
  53. </el-form-item>
  54. </el-col>
  55. </el-row>
  56. </template>
  57. </el-table-column>
  58. <el-table-column label="收费价格/元/件" width="140">
  59. <template slot-scope="scope">
  60. <el-form-item :prop="'tableList.' + scope.$index + '.price'" :rules="formRules.price" :inline-message="true">
  61. <el-input-number
  62. v-model="scope.row.price"
  63. placeholder="请输入收费价格"
  64. size="small"
  65. style="width: 100%"
  66. :controls="false"
  67. :min="0"
  68. :max="999999999"
  69. :precision="2"
  70. />
  71. </el-form-item>
  72. </template>
  73. </el-table-column>
  74. <el-table-column label="成本价/元/件" width="140">
  75. <template slot-scope="scope">
  76. <el-form-item :prop="'tableList.' + scope.$index + '.costPrice'" :rules="formRules.costPrice" :inline-message="true">
  77. <el-input-number
  78. v-model="scope.row.costPrice"
  79. placeholder="请输入成本价"
  80. size="small"
  81. style="width: 100%"
  82. :controls="false"
  83. :min="0"
  84. :max="999999999"
  85. :precision="2"
  86. />
  87. </el-form-item>
  88. </template>
  89. </el-table-column>
  90. <el-table-column label="排序" width="120">
  91. <template slot-scope="scope">
  92. <el-form-item :prop="'tableList.' + scope.$index + '.start'" :rules="formRules.start" :inline-message="true">
  93. <el-input-number
  94. v-model="scope.row.start"
  95. placeholder="请输入排序"
  96. size="small"
  97. style="width: 100%"
  98. :controls="false"
  99. :min="0"
  100. :max="999999999"
  101. :precision="0"
  102. />
  103. </el-form-item>
  104. </template>
  105. </el-table-column>
  106. <el-table-column label="操作" align="center" width="80" fixed="right">
  107. <template slot-scope="scope">
  108. <el-button type="text" @click="clickRemove(scope.row, scope.$index)">删除</el-button>
  109. </template>
  110. </el-table-column>
  111. </el-table>
  112. <br />
  113. <el-row :gutter="10" style="margin-bottom: 10px">
  114. <el-col :span="1.5">
  115. <el-button type="primary" size="mini" @click="clickSubmit" v-db-click>保存</el-button>
  116. </el-col>
  117. </el-row>
  118. </el-form>
  119. </el-card>
  120. </template>
  121. <script>
  122. import { mapGetters } from 'vuex'
  123. import * as API from '@/api/shengde/group/offer/sellQuote'
  124. export default {
  125. name: 'SellQuote',
  126. data() {
  127. return {
  128. loading: false,
  129. form: {
  130. tableList: [],
  131. },
  132. formRules: {
  133. chargeName: [{ required: true, message: '请选择收费项目', trigger: 'change' }],
  134. chargeType: [{ required: true, message: '请选择收费模式', trigger: 'change' }],
  135. valueRangeBegin: [{ required: true, message: '请输入区间起始值', trigger: 'blur' }],
  136. valueRangeEnd: [{ required: true, message: '请输入区间结束值', trigger: 'blur' }],
  137. price: [{ required: true, message: '请输入收费价格', trigger: 'blur' }],
  138. costPrice: [{ required: true, message: '请输入成本价', trigger: 'blur' }],
  139. start: [{ required: true, message: '请输入排序', trigger: 'blur' }],
  140. },
  141. chargeName: [],
  142. chargeType: [],
  143. }
  144. },
  145. created() {
  146. this.chargeName = this.dictData.filter((item) => item.code === 'charge_name')[0].children
  147. this.chargeType = this.dictData.filter((item) => item.code === 'sd_charge_type')[0].children
  148. },
  149. mounted() {
  150. this.getList()
  151. },
  152. computed: mapGetters(['dictData']),
  153. methods: {
  154. renderHeader(h) {
  155. return h(
  156. 'div',
  157. {
  158. style: {
  159. display: 'flex',
  160. width: '100%',
  161. },
  162. },
  163. [
  164. h('div', {}, [
  165. h(
  166. 'span',
  167. {
  168. style: { 'line-height': '40px', 'padding-right': '16px' },
  169. },
  170. '收费项目'
  171. ),
  172. ]),
  173. h('div', {}, [
  174. <el-button type="text" on-click={() => this.clickAdd()}>
  175. +添加收费项目
  176. </el-button>,
  177. ]),
  178. ]
  179. )
  180. },
  181. getList() {
  182. this.loading = true
  183. API.salesQuotationList({}).then(
  184. (res) => {
  185. this.form.tableList = res.data.data
  186. this.loading = false
  187. },
  188. (err) => {
  189. console.log('salesQuotationList: ' + err)
  190. this.loading = false
  191. }
  192. )
  193. },
  194. clickRemove(row, index) {
  195. if (row.id) {
  196. this.$confirm('是否确认删除数据?', '警告', {
  197. confirmButtonText: '确定',
  198. cancelButtonText: '取消',
  199. type: 'warning',
  200. })
  201. .then(() => {
  202. API.salesQuotationDelete({ id: row.id }).then(() => {
  203. this.msgSuccess('删除成功!')
  204. this.getList()
  205. })
  206. })
  207. .catch(() => {})
  208. } else {
  209. this.form.tableList.splice(index, 1)
  210. }
  211. },
  212. clickSubmit() {
  213. this.$refs.ruleForm.validate((valid) => {
  214. if (valid) {
  215. if (this.form.tableList && this.form.tableList.length > 0) {
  216. let data = this.form.tableList.filter((item) => ['10', '20'].includes(item.chargeName))
  217. if (data && data.length > 1) {
  218. let chargeType = data[0].chargeType
  219. for (let i = 0; i < data.length; i++) {
  220. if (chargeType !== data[i].chargeType) {
  221. return this.msgInfo('配置异常')
  222. }
  223. }
  224. }
  225. for (let j = 0; j < this.chargeName.length; j++) {
  226. let dataTwo = this.form.tableList.filter((item) => item.chargeName === this.chargeName[j].dictKey)
  227. if (dataTwo && dataTwo.length > 1) {
  228. let chargeTypeTwo = dataTwo[0].chargeType
  229. for (let x = 0; x < dataTwo.length; x++) {
  230. if (chargeTypeTwo !== dataTwo[x].chargeType) {
  231. return this.msgInfo('配置异常')
  232. } else {
  233. for (let y = 0; y < dataTwo.length; y++) {
  234. if (x !== y) {
  235. if (
  236. dataTwo[x].valueRangeEnd >= dataTwo[x].valueRangeBegin &&
  237. ([dataTwo[y].valueRangeBegin, dataTwo[y].valueRangeEnd].includes(dataTwo[x].valueRangeBegin) ||
  238. [dataTwo[y].valueRangeBegin, dataTwo[y].valueRangeEnd].includes(dataTwo[x].valueRangeEnd))
  239. ) {
  240. return this.msgInfo('区间重叠')
  241. } else {
  242. if (dataTwo[x].valueRangeEnd > dataTwo[y].valueRangeEnd) {
  243. if (dataTwo[x].valueRangeBegin < dataTwo[y].valueRangeEnd) {
  244. return this.msgInfo('区间重叠')
  245. }
  246. } else {
  247. if (dataTwo[x].valueRangeEnd > dataTwo[y].valueRangeBegin) {
  248. return this.msgInfo('区间重叠')
  249. }
  250. }
  251. }
  252. }
  253. }
  254. }
  255. }
  256. }
  257. }
  258. API.salesQuotationSave(this.form.tableList).then(() => {
  259. this.msgSuccess('保存完成')
  260. this.getList()
  261. })
  262. } else {
  263. this.msgInfo('请添加收费项目')
  264. }
  265. }
  266. })
  267. },
  268. clickAdd() {
  269. this.form.tableList.push({
  270. chargeName: '',
  271. chargeType: '',
  272. valueRangeBegin: undefined,
  273. valueRangeEnd: undefined,
  274. price: undefined,
  275. costPrice: undefined,
  276. start: undefined,
  277. })
  278. },
  279. },
  280. }
  281. </script>
  282. <style lang="scss" scoped>
  283. * {
  284. font-size: 12px;
  285. }
  286. .box-card {
  287. height: calc(100vh - 110px);
  288. overflow-y: auto;
  289. }
  290. ::v-deep {
  291. .el-input__inner {
  292. border-radius: 1px;
  293. }
  294. .el-button--small {
  295. border-radius: 1px;
  296. }
  297. .tableHeader th {
  298. background-color: #edf0f5;
  299. height: 35px;
  300. padding: 0;
  301. }
  302. .el-input-number {
  303. .el-input__inner {
  304. text-align: left !important;
  305. }
  306. }
  307. }
  308. </style>