index.vue 6.8 KB

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