add.html 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. {extend name="../../admin/view/main"}
  2. {block name='content'}
  3. <style>
  4. .layui-card-body{
  5. background: white;
  6. }
  7. #newForm{
  8. width: 80%;
  9. }
  10. .image{
  11. width: 100px;
  12. height: 100px;
  13. }
  14. .video{
  15. width: 200px;
  16. height: 200px;
  17. }
  18. .child-form{
  19. width: 500px;
  20. background: #f4f4f4;
  21. padding: 10px;
  22. display: inline-block;
  23. }
  24. </style>
  25. <div id="newForm">
  26. <el-form :model="form" label-width="140px" ref="form" size="medium">
  27. <el-form-item label="联系人" prop="real_name" :rules="{message:'此项必须',required:true}">
  28. <el-input v-model="form.real_name"></el-input>
  29. </el-form-item>
  30. <el-form-item label="联系电话" prop="mobile" :rules="{message:'此项必须',required:true}">
  31. <el-input v-model="form.mobile"></el-input>
  32. </el-form-item>
  33. <el-form-item label="生产技术标准" prop="standard_tech" :rules="{message:'此项必须',required:true}">
  34. <el-input v-model="form.standard_tech"></el-input>
  35. </el-form-item>
  36. <el-form-item label="生产验收标准" prop="standard_check" :rules="{message:'此项必须',required:true}">
  37. <el-input v-model="form.standard_check"></el-input>
  38. </el-form-item>
  39. <el-form-item label="商品信息:" prop="item" :rules="[{message:'此项必须',required:true},{type:'array',min:1,message:'需要商品信息'}]">
  40. <div><el-button @click="addItem">添加</el-button></div>
  41. <div v-for="(item,idx) in form.item" class="child-form">
  42. <i class="el-icon-delete" @click="deleteItem(idx)"></i>
  43. <el-form-item label="商品名称">
  44. <el-input v-model="item.name"></el-input>
  45. </el-form-item>
  46. <el-form-item label="规格">
  47. <el-input v-model="item.spec"></el-input>
  48. </el-form-item>
  49. <el-form-item label="数量">
  50. <el-input v-model="item.number"></el-input>
  51. </el-form-item>
  52. <!-- <el-form-item label="质量标准">-->
  53. <!-- <el-input v-model="item.standard"></el-input>-->
  54. <!-- </el-form-item>-->
  55. <!-- <el-form-item label="采购价">-->
  56. <!-- <el-input v-model="item.price"></el-input>-->
  57. <!-- </el-form-item>-->
  58. <el-form-item label="文件" prop="enclosure">
  59. <el-button @click="addFiles(null,item.enclosure)">增加</el-button>
  60. <div>
  61. <span v-for="(val,idx) in item.enclosure" :key="idx">
  62. <el-tag type="text" @close="item.enclosure.splice(idx,1)" closable>{{val.filename}}</el-tag>
  63. </span>
  64. </div>
  65. </el-form-item>
  66. </div>
  67. </el-form-item>
  68. <el-form-item label="图片视频" prop="files">
  69. <el-button @click="addFile('image')">增加图片/视频</el-button>
  70. <div>
  71. <div v-for="(item,idx) in form.file" :key="idx" style="display: inline-block;">
  72. <el-image v-if="item.type==='image'" :src="item.src" class="video"></el-image>
  73. <video controls v-else :src="item.src" class="video"></video>
  74. <a @click="form.file.splice(idx,1)">删除</a>
  75. </div>
  76. </div>
  77. </el-form-item>
  78. <el-form-item label="交货地址" :rules="{message:'此项必须',required:true}" prop="post_address">
  79. <el-input v-model="form.post_address"></el-input>
  80. </el-form-item>
  81. <el-form-item label="交货时间" :rules="{message:'此项必须',required:true}" prop="post_time">
  82. <el-date-picker type="datetime" v-model="form.post_time" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
  83. </el-form-item>
  84. <el-form-item>
  85. <el-button type="primary" @click="save" :loading="saving">保存</el-button>
  86. <el-button @click="history.back()">取消</el-button>
  87. </el-form-item>
  88. </el-form>
  89. <div style="display: none;">
  90. <button data-type="zip" data-file id="fileUpload"></button>
  91. </div>
  92. </div>
  93. <script>
  94. let editorContent;
  95. let vo={:json_encode($vo?:null,256)};
  96. new Vue({
  97. el:'#newForm',
  98. data:()=>({
  99. form:vo||{
  100. real_name:null,
  101. mobile:null,
  102. standard_tech:null,
  103. standard_check:null,
  104. item:[],
  105. file:[],
  106. },
  107. saving:false,
  108. }),
  109. methods:{
  110. addItem(){
  111. this.form.item.push({
  112. name:null,
  113. spec:null,
  114. number:null,
  115. // standard:null,
  116. // price:null,
  117. enclosure:[]
  118. })
  119. },
  120. deleteItem (key) {
  121. this.form.item.splice(key, 1)
  122. },
  123. addFile(){
  124. $('#fileUpload').unbind('upload.done')
  125. $('#fileUpload').on('upload.done', (e,obj) => {
  126. let type=obj.file.type.split('/')[0]
  127. if(['image','video'].indexOf(type)===-1){
  128. this.$message.error('请上传正确的格式')
  129. return
  130. }
  131. console.log(form)
  132. //form.push({fileurl:obj.data.url,filename:obj.data.url.split('/')[obj.data.url.split('/').length-1]})
  133. this.form.file.push({
  134. type:type,
  135. src:obj.data.url
  136. })
  137. });
  138. $('#fileUpload').trigger('click')
  139. },
  140. addFiles(ext,form){
  141. $('#fileUpload').unbind('upload.done')
  142. $('#fileUpload').on('upload.done', (e,obj) => {
  143. if(ext && obj.file.type.indexOf(ext)===-1){
  144. this.$message.error('请上传正确的格式')
  145. return
  146. }
  147. form.push({fileurl:obj.data.url,filename:obj.data.url.split('/')[obj.data.url.split('/').length-1]})
  148. // form.push(obj.data.url)
  149. });
  150. $('#fileUpload').trigger('click')
  151. },
  152. save(){
  153. let _this=this,
  154. form=this.form
  155. this.$refs.form.validate(v=>{
  156. if(!v){
  157. return
  158. }
  159. $.ajax('{:sysuri()}',{
  160. data:form,
  161. type:'post',
  162. beforeSend(){
  163. _this.saving=true
  164. },
  165. success({code,info}){
  166. if(code){
  167. _this.$message.success('保存成功')
  168. window.history.back()
  169. }else{
  170. _this.$message.error(info)
  171. }
  172. },
  173. complete(){
  174. _this.saving=false
  175. }
  176. })
  177. })
  178. }
  179. }
  180. })
  181. </script>
  182. {/block}