AaCommodityForm.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <template>
  2. <a-spin :spinning="confirmLoading">
  3. <j-form-container :disabled="formDisabled">
  4. <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
  5. <a-row>
  6. <a-col :span="24">
  7. <a-form-model-item label="名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="name">
  8. <a-input v-model="model.name" placeholder="请输入名称" ></a-input>
  9. </a-form-model-item>
  10. </a-col>
  11. <a-col :span="24">
  12. <a-form-model-item label="名称英语" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="name">
  13. <a-input v-model="model.nameEnglish" placeholder="请输入名称" ></a-input>
  14. </a-form-model-item>
  15. </a-col>
  16. <!-- <a-col :span="24">
  17. <a-form-model-item label="名称德语" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="name">
  18. <a-input v-model="model.nameGerman" placeholder="请输入名称" ></a-input>
  19. </a-form-model-item>
  20. </a-col>-->
  21. <!-- <a-col :span="24">
  22. <a-form-model-item label="防伪码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="securityCode">
  23. <a-input v-model="model.securityCode" placeholder="请输入防伪码" ></a-input>
  24. </a-form-model-item>
  25. </a-col>-->
  26. <a-col :span="24">
  27. <a-form-model-item label="图片" :labelCol="labelCol" :wrapperCol="wrapperCol" help="图片尺寸:700*700" prop="pic">
  28. <j-image-upload isMultiple v-model="model.pic" ></j-image-upload>
  29. </a-form-model-item>
  30. </a-col>
  31. <a-col :span="24">
  32. <a-form-model-item label="视频" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="video">
  33. <j-upload v-model="model.video" :reNewFile="true" :multiple="false" :beforeUpload="this.beforeUploadHandler" ></j-upload>
  34. </a-form-model-item>
  35. </a-col>
  36. <a-col :span="24">
  37. <a-form-model-item label="价格" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="price">
  38. <a-input-number v-model="model.price" placeholder="请输入价格" style="width: 100%" />
  39. </a-form-model-item>
  40. </a-col>
  41. <a-col :span="24">
  42. <a-form-model-item label="分类" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="typeId">
  43. <j-tree-select
  44. :choose-child="true"
  45. ref="treeSelect"
  46. placeholder="请选择分类"
  47. v-model="model.typeId"
  48. dict="aa_commodity_fl,name,id"
  49. :hasChildField="'has_child'"
  50. pidValue="0"
  51. >
  52. </j-tree-select>
  53. </a-form-model-item>
  54. </a-col>
  55. <a-col :span="24">
  56. <a-form-model-item label="介绍" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="introduce">
  57. <a-textarea v-model="model.introduce" rows="4" placeholder="请输入介绍" />
  58. </a-form-model-item>
  59. </a-col>
  60. <a-col :span="24">
  61. <a-form-model-item label="介绍英语" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="introduce">
  62. <a-textarea v-model="model.introduceEnglish" rows="4" placeholder="请输入介绍" />
  63. </a-form-model-item>
  64. </a-col>
  65. <!-- <a-col :span="24">
  66. <a-form-model-item label="介绍德语" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="introduce">
  67. <a-textarea v-model="model.introduceGerman" rows="4" placeholder="请输入介绍" />
  68. </a-form-model-item>
  69. </a-col>-->
  70. <a-col :span="24">
  71. <a-form-model-item label="介绍图片" :labelCol="labelCol" :wrapperCol="wrapperCol" help="介绍图片尺寸:400*330(推荐png格式)" prop="introducePic">
  72. <j-image-upload isMultiple v-model="model.introducePic" ></j-image-upload>
  73. </a-form-model-item>
  74. </a-col>
  75. <a-col :span="24">
  76. <a-form-model-item label="图片集" :labelCol="labelCol" :wrapperCol="wrapperCol" help="图片集尺寸:400*330(推荐png格式)" prop="pics">
  77. <j-image-upload isMultiple v-model="model.pics" ></j-image-upload>
  78. </a-form-model-item>
  79. </a-col>
  80. <a-col :span="24">
  81. <a-form-model-item label="型号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="modelNumber">
  82. <a-input v-model="model.modelNumber" placeholder="请输入型号" ></a-input>
  83. </a-form-model-item>
  84. </a-col>
  85. <a-col :span="24">
  86. <a-form-model-item label="文案" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="copyWriter">
  87. <j-editor v-model="model.copyWriter" />
  88. </a-form-model-item>
  89. </a-col>
  90. <a-col :span="24">
  91. <a-form-model-item label="文案英语" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="copyWriter">
  92. <j-editor v-model="model.copyWriterEnglish" />
  93. </a-form-model-item>
  94. </a-col>
  95. <!-- <a-col :span="24">
  96. <a-form-model-item label="文案德语" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="copyWriter">
  97. <j-editor v-model="model.copyWriterGerman" />
  98. </a-form-model-item>
  99. </a-col>-->
  100. </a-row>
  101. </a-form-model>
  102. </j-form-container>
  103. </a-spin>
  104. </template>
  105. <script>
  106. import { httpAction, getAction } from '@/api/manage'
  107. import { validateDuplicateValue } from '@/utils/util'
  108. import { duplicateCheck } from '@api/api'
  109. export default {
  110. name: 'AaCommodityForm',
  111. components: {
  112. },
  113. props: {
  114. //表单禁用
  115. disabled: {
  116. type: Boolean,
  117. default: false,
  118. required: false
  119. }
  120. },
  121. data () {
  122. return {
  123. model:{
  124. },
  125. labelCol: {
  126. xs: { span: 24 },
  127. sm: { span: 5 },
  128. },
  129. wrapperCol: {
  130. xs: { span: 24 },
  131. sm: { span: 16 },
  132. },
  133. confirmLoading: false,
  134. validatorRules: {
  135. name: [
  136. { required: true, message: '请输入名称!'},
  137. ],
  138. pic: [
  139. { required: true, message: '请输入图片!'},
  140. ],
  141. price: [
  142. { required: true, message: '请输入价格!'},
  143. ],
  144. introduce: [
  145. { required: true, message: '请输入介绍!'},
  146. ],
  147. // securityCode: [
  148. // { required: true, message: '请输入防伪码!'},{validator: this.validateC,}
  149. // ],
  150. },
  151. url: {
  152. add: "/aa/aaCommodity/add",
  153. edit: "/aa/aaCommodity/edit",
  154. queryById: "/aa/aaCommodity/queryById"
  155. }
  156. }
  157. },
  158. computed: {
  159. formDisabled(){
  160. return this.disabled
  161. },
  162. },
  163. created () {
  164. //备份model原始值
  165. this.modelDefault = JSON.parse(JSON.stringify(this.model));
  166. },
  167. methods: {
  168. validateC(rule, value, callback){
  169. var params = {
  170. tableName: 'aa_commodity',
  171. fieldName: 'security_code',
  172. fieldVal: value
  173. };
  174. duplicateCheck(params).then((res) => {
  175. if (res.success) {
  176. callback()
  177. } else {
  178. callback("防伪码已存在!")
  179. }
  180. })
  181. },
  182. add () {
  183. this.edit(this.modelDefault);
  184. },
  185. edit (record) {
  186. this.model = Object.assign({}, record);
  187. this.visible = true;
  188. },
  189. submitForm () {
  190. const that = this;
  191. // 触发表单验证
  192. this.$refs.form.validate(valid => {
  193. if (valid) {
  194. that.confirmLoading = true;
  195. let httpurl = '';
  196. let method = '';
  197. if(!this.model.id){
  198. httpurl+=this.url.add;
  199. method = 'post';
  200. }else{
  201. httpurl+=this.url.edit;
  202. method = 'put';
  203. }
  204. httpAction(httpurl,this.model,method).then((res)=>{
  205. if(res.success){
  206. that.$message.success(res.message);
  207. that.$emit('ok');
  208. }else{
  209. that.$message.warning(res.message);
  210. }
  211. }).finally(() => {
  212. that.confirmLoading = false;
  213. })
  214. }
  215. })
  216. },
  217. beforeUploadHandler(file) {
  218. let fileType = file.type;
  219. if(fileType.indexOf('video')<0){
  220. this.$message.warning('请上传视频文件');
  221. return false;
  222. }
  223. return true;
  224. },
  225. }
  226. }
  227. </script>