productColumns.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. import { required, mobileRequired, mobile, httpUrl, email } from '@/components/template/rules_verify.js'
  2. export default {
  3. data() {
  4. return {
  5. isEditIndex: -1,
  6. serviceProvider: null,
  7. specificationList: [],
  8. hezuoshangjiaList: [],
  9. }
  10. },
  11. watch: {
  12. },
  13. computed: {
  14. product() {
  15. return [{
  16. name: 'slot-component',
  17. md: 24,
  18. formItemAttributes: {
  19. 'label-width': '0px',
  20. label: '',
  21. prop: 'items',
  22. rules: [...required]
  23. },
  24. render: (h, { props }) => {
  25. return this.convertTableJson(this.formData?.items || [], [
  26. {
  27. columnAttributes: {
  28. label: '商品',
  29. prop: 'goodsId',
  30. propName: 'goodsName',
  31. },
  32. editRender: (h, { row, column, index }) => {
  33. return <div class="redbordererr">
  34. <el-form-item label="" label-width="0px" prop={`items.${index}.${column.columnAttributes.prop}`} rules={required}>
  35. <el-select
  36. value={row[column.columnAttributes.prop]}
  37. onInput={(val) => { row[column.columnAttributes.prop] = val }}
  38. onChange={(val) => {
  39. row[column.columnAttributes.propName] = ""
  40. row.categoryName = ""
  41. row.unit = ""
  42. row.goodsSpecification = ""
  43. row.marketPrice = ""
  44. row.qty = ""
  45. row.amount = ""
  46. row.goodsCode = ""
  47. if (val) {
  48. var data = this.goodsList.find(item => item.goodsId == val)
  49. if (data) {
  50. row[column.columnAttributes.propName] = data.goodsName
  51. row.categoryName = data.categoryName
  52. row.goodsCode = data.goodsCode
  53. row.unit = data.goodsStockUnit
  54. row.goodsSpecification = data.goodsSpecification
  55. row.marketPrice = data.marketPrice
  56. row.qty = ""
  57. }
  58. }
  59. }}
  60. placeholder="请选择">
  61. {this.goodsList.filter(item => item.goodsId == row.goodsId || !(this.formData?.items || []).find(data => data.goodsId == item.goodsId)).map((item, index_) => <el-option key={index_} label={item.goodsName} value={item.goodsId}></el-option>)}
  62. </el-select>
  63. </el-form-item>
  64. </div>
  65. },
  66. viewRender: (h, { row, column, index }) => {
  67. return <div style="padding-left:10px">{row[column.columnAttributes.propName]}</div>
  68. },
  69. },
  70. {
  71. columnAttributes: {
  72. label: '分类',
  73. prop: 'categoryName'
  74. }
  75. },
  76. {
  77. columnAttributes: {
  78. label: '单位',
  79. prop: 'unit'
  80. }
  81. },
  82. {
  83. columnAttributes: {
  84. label: '商品代码',
  85. prop: 'goodsCode'
  86. }
  87. },
  88. {
  89. columnAttributes: {
  90. label: '规格型号',
  91. prop: 'goodsSpecification'
  92. }
  93. },
  94. {
  95. columnAttributes: {
  96. label: '销售价格',
  97. prop: 'marketPrice',
  98. },
  99. editRender: (h, { row, column, index }) => {
  100. return <div class="redbordererr">
  101. <el-form-item label="" label-width="0px" prop={`items.${index}.${column.columnAttributes.prop}`} rules={required}>
  102. <el-input
  103. value={row[column.columnAttributes.prop]}
  104. onInput={(val) => { row[column.columnAttributes.prop] = val }}
  105. placeholder="请输入内容"
  106. type="number"
  107. >
  108. </el-input>
  109. </el-form-item>
  110. </div>
  111. },
  112. viewRender: (h, { row, column, index }) => {
  113. return <div style="padding-left:10px">{row[column.columnAttributes.prop]}</div>
  114. },
  115. },
  116. {
  117. columnAttributes: {
  118. label: '数量',
  119. prop: 'qty',
  120. },
  121. editRender: (h, { row, column, index }) => {
  122. return <div class="redbordererr">
  123. <el-form-item label="" label-width="0px" prop={`items.${index}.${column.columnAttributes.prop}`} rules={required}>
  124. <el-input
  125. value={row[column.columnAttributes.prop]}
  126. onInput={(val) => { row[column.columnAttributes.prop] = val }}
  127. placeholder="请输入内容"
  128. type="number"
  129. >
  130. </el-input>
  131. </el-form-item>
  132. </div>
  133. },
  134. viewRender: (h, { row, column, index }) => {
  135. return <div style="padding-left:10px">{row[column.columnAttributes.prop]}</div>
  136. },
  137. },
  138. {
  139. columnAttributes: {
  140. label: '金额(元)',
  141. prop: 'amount',
  142. },
  143. render: (h, { row, column, index }) => {
  144. return <div style="padding-left:10px">{
  145. (Number(row.marketPrice) * Number(row.qty)).toFixed(2)
  146. }</div>
  147. },
  148. },
  149. ], {
  150. isEdit: !this.id,
  151. isAdd: !this.id,
  152. isDel: !this.id,
  153. }, {
  154. // 点击添加触发
  155. add: () => {
  156. this.formData.items.unshift({
  157. "goodsId": "",
  158. "goodsCode": "",
  159. "goodsName": "",
  160. "categoryName": "",
  161. "unit": "",
  162. "goodsSpecification": "",
  163. "marketPrice": "",
  164. "qty": "",
  165. "amount": ""
  166. })
  167. this.isEditTableIndex = 0
  168. },
  169. verify: ({ row, column, index }, isEditTableIndex) => {
  170. return new Promise(r => {
  171. if (isEditTableIndex > -1) {
  172. this.appointVerify([
  173. `items.${isEditTableIndex}.goodsId`,
  174. `items.${isEditTableIndex}.marketPrice`,
  175. `items.${isEditTableIndex}.qty`,
  176. ], (v) => {
  177. if (v) {
  178. r(true)
  179. } else {
  180. r(false)
  181. }
  182. })
  183. } else {
  184. r(true)
  185. }
  186. })
  187. },
  188. })
  189. }
  190. }]
  191. },
  192. },
  193. }