index.vue 7.1 KB

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