index.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <template>
  2. <view>
  3. <u-modal :show="showModal" ref="uModal" :title="(editOrAdd === 'add' || editOrAdd === 'receptFormAdd') ? '新增' : '编辑'" :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: ''// edit 编辑(有价格), editForm 编辑询价单(无价格), add 新增询价单, receptFormAdd 新增接收询价单 线索页面:第一次点击是新增(不需要回显),status传1,第二次点击是无价格编辑status传1;接单中心:第一次点击是新增(需要回显)status传1,第二次点击是无价格编辑status传1;只有edit是有价格编辑status传2
  46. },
  47. editInfo: {
  48. type: Object,
  49. default: () => {}
  50. },
  51. type: {
  52. type: Number,
  53. default: 1
  54. },
  55. },
  56. emits: ['submitSuccess'],
  57. inject: ['refreshData'],
  58. data() {
  59. return {
  60. showModal: false,
  61. info: {
  62. model:'',
  63. code:'',
  64. id:'',
  65. price:'',
  66. dictLabel:'',
  67. dictValue:'',
  68. imgsUrl:[]
  69. },
  70. rules: {
  71. brand: [
  72. { required: true, message: '请输入品牌', trigger: 'blur' }
  73. ]
  74. },
  75. }
  76. },
  77. watch: {
  78. show: {
  79. handler(newVal) {
  80. this.showModal = newVal;
  81. },
  82. immediate: true
  83. }
  84. },
  85. methods: {
  86. // 编辑回显
  87. initData() {
  88. this.$nextTick(()=>{
  89. this.info = JSON.parse(JSON.stringify(this.editInfo))
  90. this.showModal = true;
  91. })
  92. },
  93. // 获取删除图片信息
  94. getDeleteImgInfo(info) {
  95. this.info.imgsUrl = info.newImages
  96. },
  97. handleBrandClick() {
  98. this.$refs.brandListRef.showBrandList();
  99. },
  100. handleSelectedBrand(info) {
  101. this.info.dictLabel = info.dictLabel
  102. this.info.dictValue = info.dictValue
  103. },
  104. // 上传图片
  105. afterRead(info) {
  106. info.file.forEach(item=>{
  107. uni.$u.api.uploadFile(item.url).then((res) => {
  108. this.info.imgsUrl.push(res.data.url);
  109. uni.$u.toast("文件上传成功");
  110. }).catch(() => {
  111. uni.$u.toast("上传文件失败");
  112. })
  113. })
  114. },
  115. // 确认添加
  116. confirm() {
  117. if (!this.info.dictLabel || !this.info.dictValue) {
  118. uni.showToast({
  119. title: '请选择品牌',
  120. icon: 'none'
  121. })
  122. return
  123. }
  124. if (!this.info.model) {
  125. uni.showToast({
  126. title: '请输入型号',
  127. icon: 'none'
  128. })
  129. return
  130. }
  131. if (!this.info.code) {
  132. uni.showToast({
  133. title: '请输入编码',
  134. icon: 'none'
  135. })
  136. return
  137. }
  138. if(this.info.imgsUrl.length == 0){
  139. uni.showToast({
  140. title: '请上传图片',
  141. icon: 'none'
  142. })
  143. return
  144. }
  145. if(this.editOrAdd === 'edit' && !this.info.price){
  146. uni.showToast({
  147. title: '请输入价格',
  148. icon: 'none'
  149. })
  150. return
  151. }
  152. const data = {
  153. clueId: this.clueId,
  154. dictValue: this.info.dictValue,
  155. dictLabel: this.info.dictLabel,
  156. model: this.info.model,
  157. code: this.info.code,
  158. id: (this.editOrAdd === 'edit' || this.editOrAdd === 'editForm') ? this.info.id : '',
  159. price: this.editOrAdd === 'edit' ? this.info.price : '',
  160. imgsUrl:this.info.imgsUrl,
  161. status: this.editOrAdd === 'edit' ? '2' : '1',
  162. type: this.type
  163. }
  164. uni.$u.api.addInquiry(data).then(res => {
  165. uni.$u.toast(this.type == 1 ? "询价成功" : "核价成功")
  166. this.closeDialog()
  167. this.$emit('submitSuccess')
  168. if(this.type == 1 && this.clueId !== '') this.refreshData.resetData(); //线索公海页面需要刷新列表
  169. }).catch((err) => {
  170. uni.$u.toast(err)
  171. })
  172. },
  173. showDialog() {
  174. if (this.editOrAdd === 'edit' || this.editOrAdd === 'editForm' || this.editOrAdd === 'receptFormAdd') {
  175. this.initData();
  176. }else if(this.editOrAdd === 'add'){
  177. this.clearForm()
  178. this.showModal = true;
  179. }
  180. },
  181. clearForm() {
  182. this.info = {
  183. dictLabel:'',
  184. dictValue:'',
  185. model:'',
  186. code:'',
  187. id:'',
  188. price:'',
  189. imgsUrl:[]
  190. }
  191. },
  192. closeDialog() {
  193. this.showModal = false;
  194. },
  195. }
  196. };
  197. </script>
  198. <style lang="scss" scoped>
  199. @import './index.scss'
  200. </style>