index.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <template>
  2. <view>
  3. <u-modal :show="showModal" ref="uModal" :title="editOrAdd === 'edit' ? '编辑' : '新增'" :asyncClose="false" showCancelButton @cancel="closeDialog" cancelColor="#909399" :confirmText="'确定'" confirmColor="#2979ff"@confirm="confirm" @close="closeDialog" :closeOnClickOverlay="false">
  4. <view class="modal_wrap">
  5. <text @click="handleBrandClick" class="item" :class="info.dictLabel ? 'brand' : 'brand placeholder'">{{ info.dictLabel || '品牌' }}</text>
  6. <text class="divider">|</text>
  7. <u--input placeholder="型号" class="item" border="none" v-model="info.model" clearable></u--input>
  8. <text class="divider">|</text>
  9. <u--input class="code-input item" placeholder="编码" border="none" v-model="info.code" clearable></u--input>
  10. </view>
  11. <view class="img_wrap">
  12. <imgs-row-scroll v-if="info.imgsUrl.length > 0" :isShowDeleteIcon="true" @deleteImgInfo="getDeleteImgInfo" imgMode="aspectFill" :totalWidth="400" :images="info.imgsUrl" :previewEnabled="true" :imageWidth="150" :imageHeight="150"></imgs-row-scroll>
  13. <u-upload
  14. @afterRead="afterRead"
  15. name="3"
  16. multiple
  17. :maxCount="10"
  18. ></u-upload>
  19. </view>
  20. <u--input v-if="editOrAdd === 'edit'" class="price" placeholder="价格" border="bottom" v-model="info.price" clearable></u--input>
  21. </u-modal>
  22. <brandList ref="brandListRef" @selectedBrand="handleSelectedBrand"></brandList>
  23. </view>
  24. </template>
  25. <script>
  26. import imgsRowScroll from '@/components/imgs-row-scroll/index.vue'
  27. import brandList from '@/components/brand-list/index.vue'
  28. export default {
  29. name: 'AddInquiryDialog',
  30. components: {
  31. imgsRowScroll,
  32. brandList
  33. },
  34. props: {
  35. clueId: {
  36. type: String,
  37. default: ''
  38. },
  39. show: {
  40. type: Boolean,
  41. default: false
  42. },
  43. editOrAdd: {
  44. type: String,
  45. default: ''
  46. },
  47. editInfo: {
  48. type: Object,
  49. default: () => {}
  50. },
  51. },
  52. data() {
  53. return {
  54. showModal: false,
  55. info: {
  56. model:'',
  57. code:'',
  58. id:'',
  59. price:'',
  60. dictLabel:'',
  61. dictValue:'',
  62. imgsUrl:[]
  63. },
  64. rules: {
  65. brand: [
  66. { required: true, message: '请输入品牌', trigger: 'blur' }
  67. ]
  68. },
  69. }
  70. },
  71. watch: {
  72. show: {
  73. handler(newVal) {
  74. this.showModal = newVal;
  75. },
  76. immediate: true
  77. }
  78. },
  79. methods: {
  80. // 编辑回显
  81. initData() {
  82. if (this.editOrAdd === 'edit') {
  83. this.info = JSON.parse(JSON.stringify(this.editInfo))
  84. }
  85. },
  86. // 获取删除图片信息
  87. getDeleteImgInfo(info) {
  88. this.info.imgsUrl = info.newImages
  89. },
  90. handleBrandClick() {
  91. this.$refs.brandListRef.showBrandList();
  92. },
  93. handleSelectedBrand(info) {
  94. this.info.dictLabel = info.dictLabel
  95. this.info.dictValue = info.dictValue
  96. },
  97. // 上传图片
  98. afterRead(info) {
  99. info.file.forEach(item=>{
  100. uni.$u.api.uploadFile(item.url).then((res) => {
  101. this.info.imgsUrl.push(res.data.url);
  102. uni.$u.toast("文件上传成功");
  103. }).catch(() => {
  104. uni.$u.toast("上传文件失败");
  105. })
  106. })
  107. },
  108. // 确认添加
  109. confirm() {
  110. if (!this.info.dictLabel || !this.info.dictValue) {
  111. uni.showToast({
  112. title: '请选择品牌',
  113. icon: 'none'
  114. })
  115. return
  116. }
  117. if (!this.info.model) {
  118. uni.showToast({
  119. title: '请输入型号',
  120. icon: 'none'
  121. })
  122. return
  123. }
  124. if (!this.info.code) {
  125. uni.showToast({
  126. title: '请输入编码',
  127. icon: 'none'
  128. })
  129. return
  130. }
  131. if(this.info.imgsUrl.length == 0){
  132. uni.showToast({
  133. title: '请上传图片',
  134. icon: 'none'
  135. })
  136. return
  137. }
  138. const data = {
  139. clueId: this.clueId,
  140. dictValue: this.info.dictValue,
  141. dictLabel: this.info.dictLabel,
  142. model: this.info.model,
  143. code: this.info.code,
  144. id: this.editOrAdd === 'edit' ? this.info.id : '',
  145. price: this.editOrAdd === 'edit' ? this.info.price : '',
  146. imgsUrl:this.info.imgsUrl
  147. }
  148. uni.$u.api.addInquiry(data).then(res => {
  149. if (res.code == 200) {
  150. uni.showToast({
  151. title: '添加成功',
  152. icon: 'success'
  153. })
  154. this.closeDialog()
  155. this.$emit('addSuccess')
  156. }
  157. })
  158. },
  159. showDialog() {
  160. this.showModal = true;
  161. if (this.editOrAdd === 'edit') {
  162. this.initData();
  163. }else{
  164. this.clearForm()
  165. }
  166. },
  167. clearForm() {
  168. this.info = {
  169. dictLabel:'',
  170. dictValue:'',
  171. model:'',
  172. code:'',
  173. id:'',
  174. price:'',
  175. imgsUrl:[]
  176. }
  177. },
  178. closeDialog() {
  179. this.showModal = false;
  180. },
  181. }
  182. };
  183. </script>
  184. <style lang="scss" scoped>
  185. @import './index.scss'
  186. </style>