index.vue 7.3 KB

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